Changeset 32855 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-08-20T18:26:00+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r32823 r32855 2 2 package org.openstreetmap.josm.plugins.pt_assistant; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import javax.swing.JMenuItem; 7 import javax.swing.SwingUtilities; 5 8 6 9 import org.openstreetmap.josm.Main; … … 8 11 import org.openstreetmap.josm.gui.MainMenu; 9 12 import org.openstreetmap.josm.gui.MapFrame; 13 import org.openstreetmap.josm.gui.Notification; 10 14 import org.openstreetmap.josm.plugins.Plugin; 11 15 import org.openstreetmap.josm.plugins.PluginInformation; 12 16 import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; 13 17 import org.openstreetmap.josm.plugins.pt_assistant.actions.RepeatLastFixAction; 18 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; 14 19 import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; 15 20 … … 22 27 public class PTAssistantPlugin extends Plugin { 23 28 29 /* 30 * last fix that was can be re-applied to all similar route segments, can be 31 * null if unavailable 32 */ 33 private static PTRouteSegment lastFix; 34 24 35 private JMenuItem addStopPositionMenu; 25 private JMenuItem repeatLastFixMenu;36 private static JMenuItem repeatLastFixMenu; 26 37 27 38 /** … … 36 47 37 48 OsmValidator.addTest(PTAssistantValidatorTest.class); 38 49 39 50 AddStopPositionAction addStopPositionAction = new AddStopPositionAction(); 40 51 addStopPositionMenu = MainMenu.add(Main.main.menu.toolsMenu, addStopPositionAction, false); 41 52 RepeatLastFixAction repeatLastFixAction = new RepeatLastFixAction(); 42 53 repeatLastFixMenu = MainMenu.add(Main.main.menu.toolsMenu, repeatLastFixAction, false); 43 54 44 55 } 45 56 … … 51 62 if (oldFrame == null && newFrame != null) { 52 63 addStopPositionMenu.setEnabled(true); 64 repeatLastFixMenu.setEnabled(false); 53 65 } else if (oldFrame != null && newFrame == null) { 54 66 addStopPositionMenu.setEnabled(false); 67 repeatLastFixMenu.setEnabled(false); 55 68 } 69 } 70 71 public static PTRouteSegment getLastFix() { 72 return lastFix; 73 } 74 75 /** 76 * Remembers the last fix and enables/disables the Repeat last fix menu 77 * 78 * @param segment 79 * The last fix, call be null to disable the Repeat last fix menu 80 */ 81 public static void setLastFix(PTRouteSegment segment) { 82 lastFix = segment; 83 84 SwingUtilities.invokeLater(new Runnable() { 85 @Override 86 public void run() { 87 repeatLastFixMenu.setEnabled(segment != null); 88 } 89 }); 56 90 } 57 91 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java
r32763 r32855 37 37 false, "addStopPosition", false); 38 38 39 this.setEnabled(true);40 39 } 41 40 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/RepeatLastFixAction.java
r32823 r32855 1 1 package org.openstreetmap.josm.plugins.pt_assistant.actions; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 3 5 import java.awt.event.ActionEvent; 6 import java.awt.event.KeyEvent; 4 7 8 import org.openstreetmap.josm.Main; 5 9 import org.openstreetmap.josm.actions.JosmAction; 10 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 11 import org.openstreetmap.josm.plugins.pt_assistant.validation.SegmentChecker; 12 import org.openstreetmap.josm.tools.ImageProvider; 13 import org.openstreetmap.josm.tools.Shortcut; 6 14 7 15 public class RepeatLastFixAction extends JosmAction { 8 16 9 17 private static final long serialVersionUID = 2681464946469047054L; 18 19 public RepeatLastFixAction() { 20 super(tr("Repeat last fix"), new ImageProvider("presets/transport", "bus.svg"), tr("Repeat last fix"), 21 Shortcut.registerShortcut("Repeat last fix", tr("Repeat last fix"), KeyEvent.VK_E, Shortcut.NONE), 22 false, "repeatLastFix", false); 23 24 } 10 25 11 26 @Override 12 27 public void actionPerformed(ActionEvent e) { 13 // TODO Auto-generated method stub 28 29 System.out.println("in actionPerformed"); 30 31 if (!isEnabled() || !Main.isDisplayingMapView()) { 32 return; 33 } 34 35 System.out.println("performing action"); 36 37 SegmentChecker.carryOutRepeatLastFix(PTAssistantPlugin.getLastFix()); 38 39 PTAssistantPlugin.setLastFix(null); 14 40 15 41 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteSegment.java
r32801 r32855 4 4 import java.util.List; 5 5 6 import org.openstreetmap.josm.data.osm.Relation; 6 7 import org.openstreetmap.josm.data.osm.Way; 7 8 … … 22 23 private List<PTWay> ptways; 23 24 private List<List<PTWay>> fixVariants; 25 private Relation relation; 24 26 25 public PTRouteSegment(PTStop firstStop, PTStop lastStop, List<PTWay> ways ) {27 public PTRouteSegment(PTStop firstStop, PTStop lastStop, List<PTWay> ways, Relation relation) { 26 28 this.firstStop = firstStop; 27 29 this.lastStop = lastStop; … … 29 31 ptways.addAll(ways); 30 32 fixVariants = new ArrayList<>(); 33 this.relation = relation; 31 34 } 32 35 … … 114 117 return this.fixVariants; 115 118 } 119 120 public Relation getRelation() { 121 return this.relation; 122 } 116 123 117 124 /** -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java
r32822 r32855 5 5 import java.lang.reflect.InvocationTargetException; 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.List; 8 9 … … 10 11 import javax.swing.SwingUtilities; 11 12 12 import org.openstreetmap.josm. Main;13 import org.openstreetmap.josm.actions.AutoScaleAction; 13 14 import org.openstreetmap.josm.command.ChangeCommand; 14 15 import org.openstreetmap.josm.command.Command; 15 import org.openstreetmap.josm.command.SelectCommand;16 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 19 import org.openstreetmap.josm.data.osm.Relation;20 import org.openstreetmap.josm.data.osm.RelationMember;21 19 import org.openstreetmap.josm.data.osm.Way; 22 20 import org.openstreetmap.josm.data.validation.Severity; … … 103 101 } 104 102 105 106 103 /** 107 104 * Fixes errors: solitary stop position and platform which is part of a way. … … 119 116 120 117 Node problematicNode = (Node) testError.getPrimitives().iterator().next(); 121 ArrayList<OsmPrimitive> primitivesToSelect = new ArrayList<>(1);122 primitivesToSelect.add(problematicNode);123 SelectCommand selectCommand = new SelectCommand(primitivesToSelect);124 selectCommand.executeCommand();125 118 126 119 final int[] userSelection = { JOptionPane.YES_OPTION }; … … 165 158 private static int showFixNodeTagDialog(TestError e) { 166 159 Node problematicNode = (Node) e.getPrimitives().iterator().next(); 167 Main.map.mapView.zoomTo(problematicNode.getCoor()); 160 // Main.map.mapView.zoomTo(problematicNode.getCoor()); 161 // zoom to problem: 162 Collection<OsmPrimitive> primitives = new ArrayList<>(1); 163 primitives.add(problematicNode); 164 AutoScaleAction.zoomTo(primitives); 168 165 169 166 String[] options = { tr("Yes"), tr("No") }; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32822 r32855 5 5 import java.lang.reflect.InvocationTargetException; 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.List; 8 9 … … 11 12 12 13 import org.openstreetmap.josm.command.Command; 14 import org.openstreetmap.josm.command.SelectCommand; 13 15 import org.openstreetmap.josm.command.SequenceCommand; 14 16 import org.openstreetmap.josm.data.osm.DataSet; 15 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 20 import org.openstreetmap.josm.data.osm.Relation; … … 20 23 import org.openstreetmap.josm.data.validation.Test; 21 24 import org.openstreetmap.josm.data.validation.TestError; 25 import org.openstreetmap.josm.gui.Notification; 26 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 22 27 import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask; 23 28 import org.openstreetmap.josm.plugins.pt_assistant.actions.IncompleteMembersDownloadThread; … … 51 56 public static final int ERROR_CODE_STOP_AREA_COMPARE_RELATIONS = 3764; 52 57 53 54 55 58 private PTAssistantLayer layer; 56 59 … … 75 78 // select only stop_positions 76 79 if (n.hasTag("public_transport", "stop_position")) { 77 80 78 81 // check if stop positions are on a way: 79 82 nodeChecker.performSolitaryStopPositionTest(); 80 83 81 84 // check if stop positions are in any stop_area relation: 82 85 nodeChecker.performNodePartOfStopAreaTest(); … … 86 89 // select only platforms 87 90 if (n.hasTag("public_transport", "platform")) { 88 91 89 92 // check that platforms are not part of any way: 90 93 nodeChecker.performPlatformPartOfWayTest(); 91 94 92 95 // check if platforms are in any stop_area relation: 93 96 nodeChecker.performNodePartOfStopAreaTest(); 94 97 } 95 98 96 99 this.errors.addAll(nodeChecker.getErrors()); 97 100 … … 100 103 @Override 101 104 public void visit(Relation r) { 102 105 103 106 // Do some testing on stop area relations 104 107 if (StopUtils.isStopArea(r)) { 105 108 106 109 StopChecker stopChecker = new StopChecker(r, this); 107 108 // Check if stop area relation has one stop position. 110 111 // Check if stop area relation has one stop position. 109 112 stopChecker.performStopAreaStopPositionTest(); 110 113 111 // Check if stop area relation has one platform. 114 // Check if stop area relation has one platform. 112 115 stopChecker.performStopAreaPlatformTest(); 113 114 // Check if stop position(s) belong the same route relation as related platform(s) 116 117 // Check if stop position(s) belong the same route relation as 118 // related platform(s) 115 119 stopChecker.performStopAreaRelationsTest(); 116 120 … … 381 385 Way segmentEndWay = assigner.get(segmentEndStop); 382 386 List<PTWay> waysBetweenStops = manager.getPTWaysBetween(segmentStartWay, segmentEndWay); 383 PTRouteSegment routeSegment = new PTRouteSegment(segmentStartStop, segmentEndStop, waysBetweenStops );387 PTRouteSegment routeSegment = new PTRouteSegment(segmentStartStop, segmentEndStop, waysBetweenStops, r); 384 388 SegmentChecker.addCorrectSegment(routeSegment); 385 389 } … … 408 412 @Override 409 413 public Command fixError(TestError testError) { 410 414 411 415 // repaint the relation in the pt_assistant layer: 412 416 if (testError.getPrimitives().iterator().next().getType().equals(OsmPrimitiveType.RELATION)) { … … 415 419 } 416 420 421 // reset the last fix: 422 PTAssistantPlugin.setLastFix(null); 423 417 424 List<Command> commands = new ArrayList<>(); 418 425 … … 437 444 if (testError.getCode() == ERROR_CODE_STOP_BY_STOP) { 438 445 commands.add(SegmentChecker.fixError(testError)); 446 // make sure the primitives of this testError are selected: 447 Collection<OsmPrimitive> primitivesToSelect = new ArrayList<>(); 448 for (Object obj : testError.getPrimitives()) { 449 primitivesToSelect.add((OsmPrimitive) obj); 450 } 451 SelectCommand selectCommand = new SelectCommand(primitivesToSelect); 452 SwingUtilities.invokeLater(new Runnable() { 453 @Override 454 public void run() { 455 selectCommand.executeCommand(); 456 } 457 }); 439 458 } 440 459 … … 474 493 475 494 } 476 495 477 496 public void addFixVariants(List<List<PTWay>> fixVariants) { 478 497 layer.addFixVariants(fixVariants); 479 498 } 480 499 481 500 public void clearFixVariants() { 482 501 layer.clearFixVariants(); 483 502 } 484 503 485 504 public List<PTWay> getFixVariant(Character c) { 486 505 return layer.getFixVariant(c); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32819 r32855 29 29 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 30 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 31 32 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager; 32 33 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; … … 57 58 private StopToWayAssigner assigner; 58 59 59 private List<PTWay> unusedWays = new ArrayList<>();60 61 private HashMap<TestError, PTWay> erroneousPTWays = new HashMap<>();62 63 private HashMap<TestError, Node> firstNodeOfErroneousPTWay = new HashMap<>();64 65 60 public SegmentChecker(Relation relation, Test test) { 66 61 … … 80 75 81 76 this.assigner = new StopToWayAssigner(manager.getPTWays()); 82 83 unusedWays.addAll(manager.getPTWays());84 77 85 78 } … … 284 277 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 285 278 this.errors.add(e); 286 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays );279 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation); 287 280 wrongSegments.put(e, routeSegment); 288 erroneousPTWays.put(e, manager.getPTWay(startWay));289 firstNodeOfErroneousPTWay.put(e, null);290 281 } 291 282 continue; … … 295 286 segmentWays.get(segmentWays.size() - 1)); 296 287 if (sortingCorrect) { 297 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays );288 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation); 298 289 addCorrectSegment(routeSegment); 299 unusedWays.removeAll(segmentWays);300 290 } else { 301 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays );291 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation); 302 292 TestError error = this.errors.get(this.errors.size() - 1); 303 293 wrongSegments.put(error, routeSegment); … … 452 442 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 453 443 this.errors.add(e); 454 erroneousPTWays.put(e, current);455 444 return false; 456 445 } … … 649 638 } else { 650 639 error.setMessage("PT: Problem in the route segment with several automatic fixes"); 651 } 640 } 652 641 } 653 642 … … 789 778 } 790 779 780 PTAssistantPlugin.setLastFix(correctSegmentsForThisError.get(0)); 791 781 return carryOutSingleFix(testError, correctSegmentsForThisError.get(0).getPTWays()); 792 782 … … 799 789 } 800 790 791 PTAssistantPlugin.setLastFix(new PTRouteSegment(wrongSegment.getFirstStop(), 792 wrongSegment.getLastStop(), wrongSegment.getFixVariants().get(0), (Relation) testError.getPrimitives().iterator().next())); 801 793 return carryOutSingleFix(testError, wrongSegment.getFixVariants().get(0)); 802 794 } … … 904 896 * the fix variant to be adopted 905 897 */ 906 private static void carryOutSelectedFix(TestError testError, List<PTWay> fix) 898 private static void carryOutSelectedFix(TestError testError, List<PTWay> fix){ 907 899 // modify the route: 908 Relation route = (Relation) testError.getPrimitives().iterator().next(); 909 route.setMembers(getModifiedRelationMembers(testError, fix)); 900 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 901 Relation modifiedRelation = new Relation(originalRelation); 902 modifiedRelation.setMembers(getModifiedRelationMembers(testError, fix)); 903 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 904 Main.main.undoRedo.addNoRedraw(changeCommand); 905 Main.main.undoRedo.afterAdd(); 910 906 PTRouteSegment wrongSegment = wrongSegments.get(testError); 911 907 wrongSegments.remove(testError); 912 908 wrongSegment.setPTWays(fix); 913 909 addCorrectSegment(wrongSegment); 910 PTAssistantPlugin.setLastFix(wrongSegment); 914 911 915 912 // get ways for the fix: … … 923 920 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); 924 921 for (OsmDataLayer osmDataLayer : listOfLayers) { 925 if (osmDataLayer.data == route.getDataSet()) {922 if (osmDataLayer.data == originalRelation.getDataSet()) { 926 923 layer = osmDataLayer; 927 924 break; … … 930 927 931 928 // create editor: 932 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, route,933 route.getMembersFor(primitives));929 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, originalRelation, 930 originalRelation.getMembersFor(primitives)); 934 931 935 932 // open editor: … … 977 974 modifiedRelation.setMembers(getModifiedRelationMembers(testError, fix)); 978 975 wrongSegments.remove(testError); 979 returnnew ChangeCommand(originalRelation, modifiedRelation);980 976 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 977 return changeCommand; 981 978 } 982 979 … … 1014 1011 return modifiedRelationMembers; 1015 1012 } 1013 1014 public static void carryOutRepeatLastFix(PTRouteSegment segment) { 1015 1016 System.out.println("last fix relation: " + segment.getRelation().getId()); 1017 List<TestError> wrongSegmentsToRemove = new ArrayList<>(); 1018 1019 int counter = 0; 1020 // find all wrong ways that have the same segment: 1021 for (TestError testError: wrongSegments.keySet()) { 1022 PTRouteSegment wrongSegment = wrongSegments.get(testError); 1023 if (wrongSegment.getFirstWay() == segment.getFirstWay() && wrongSegment.getLastWay() == segment.getLastWay()) { 1024 counter++; 1025 System.out.println("wrong segment: " + wrongSegment.getRelation().getId()); 1026 // modify the route: 1027 Relation originalRelation = wrongSegment.getRelation(); 1028 Relation modifiedRelation = new Relation(originalRelation); 1029 modifiedRelation.setMembers(getModifiedRelationMembers(testError, segment.getPTWays())); 1030 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 1031 Main.main.undoRedo.addNoRedraw(changeCommand); 1032 Main.main.undoRedo.afterAdd(); 1033 wrongSegmentsToRemove.add(testError); 1034 } 1035 } 1036 1037 // update the errors displayed in the validator dialog: 1038 List<TestError> modifiedValidatorTestErrors = new ArrayList<>(); 1039 for (TestError validatorTestError: Main.map.validatorDialog.tree.getErrors()) { 1040 if (!wrongSegmentsToRemove.contains(validatorTestError)) { 1041 modifiedValidatorTestErrors.add(validatorTestError); 1042 } 1043 } 1044 Main.map.validatorDialog.tree.setErrors(modifiedValidatorTestErrors); 1045 1046 // update wrong segments: 1047 for (TestError testError: wrongSegmentsToRemove) { 1048 wrongSegments.remove(testError); 1049 } 1050 1051 System.out.println("wrong segments found: " + counter); 1052 System.out.println(); 1053 1054 1055 1056 1057 } 1016 1058 1017 1059 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/StopChecker.java
r32822 r32855 4 4 5 5 import java.util.ArrayList; 6 import java.util.HashMap; 6 7 import java.util.List; 7 8 import java.util.Set; 8 import java.util.HashMap;9 9 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 11 import org.openstreetmap.josm.data.osm.Relation; 12 import org.openstreetmap.josm.data.osm.RelationMember;13 12 import org.openstreetmap.josm.data.validation.Severity; 14 13 import org.openstreetmap.josm.data.validation.Test; … … 129 128 primitives.add(relation); 130 129 TestError e = new TestError(this.test, Severity.WARNING, 131 tr("PT: Route relations of stop position(s) and platform(s) of stop area mem ebrs diverge"),130 tr("PT: Route relations of stop position(s) and platform(s) of stop area members diverge"), 132 131 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_COMPARE_RELATIONS, primitives); 133 132 errors.add(e);
Note:
See TracChangeset
for help on using the changeset viewer.