Skip to content

Commit 0095622

Browse files
console/plugins/planning/PlanEditor: Add option to focus on the editing plan center.
1 parent 8b1cc6a commit 0095622

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/java/pt/lsts/neptus/console/plugins/planning/PlanEditor.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,50 @@ public void actionPerformed(ActionEvent e) {
11501150
};
11511151
copy.putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtils.getImage("images/menus/editcopy.png")));
11521152
popup.add(copy);
1153-
1153+
1154+
if (planElem.getPlan() != null && !planElem.getPlan().isEmpty()) {
1155+
AbstractAction focusPlan = new AbstractAction(I18n.text("Focus plan")) {
1156+
@Override
1157+
public void actionPerformed(ActionEvent e) {
1158+
if (planElem.getPlan() == null || planElem.getPlan().isEmpty())
1159+
return;
1160+
1161+
Maneuver[] mansList = planElem.getPlan().getGraph().getAllManeuvers();
1162+
if (mansList.length == 0)
1163+
return;
1164+
1165+
double nlat = 0, slat = 0;
1166+
double wlon = 0, elon = 0;
1167+
1168+
for (Maneuver man : mansList) {
1169+
if (man instanceof LocatedManeuver) {
1170+
Collection<ManeuverLocation> wpslst = ((LocatedManeuver) man).getWaypoints();
1171+
for (ManeuverLocation wp : wpslst) {
1172+
if (wp.getLatitudeDegs() == 0 && wp.getLongitudeDegs() == 0)
1173+
continue;
1174+
LocationType absll = wp.getNewAbsoluteLatLonDepth();
1175+
if (nlat == 0 || absll.getLatitudeDegs() > nlat)
1176+
nlat = absll.getLatitudeDegs();
1177+
if (slat == 0 || absll.getLatitudeDegs() < slat)
1178+
slat = absll.getLatitudeDegs();
1179+
if (wlon == 0 || absll.getLongitudeDegs() < wlon)
1180+
wlon = absll.getLongitudeDegs();
1181+
if (elon == 0 || absll.getLongitudeDegs() > elon)
1182+
elon = absll.getLongitudeDegs();
1183+
}
1184+
}
1185+
}
1186+
double clat = (nlat + slat) / 2.0;
1187+
double clon = (wlon + elon) / 2.0;
1188+
renderer.setCenter(new LocationType(clat, clon));
1189+
1190+
CoordinateUtil.copyToClipboard(renderer.getRealWorldLocation(mousePoint));
1191+
}
1192+
};
1193+
focusPlan.putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtils.getImage("images/menus/zoom.png")));
1194+
popup.add(focusPlan);
1195+
}
1196+
11541197
JCheckBoxMenuItem showSim = new JCheckBoxMenuItem(I18n.text("View Simulation"));
11551198
showSim.setSelected(showSimulation);
11561199

0 commit comments

Comments
 (0)