Changeset 33082 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2016-11-25T22:57:10+01:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r33055 r33082 285 285 @Override 286 286 protected void drawNode(Node n, Color color) { 287 287 if (mv == null || g == null) { 288 return; 289 } 288 290 Point p = mv.getPoint(n); 289 291 if (p == null) { 292 return; 293 } 290 294 g.setColor(color); 291 295 g.drawOval(p.x - 5, p.y - 5, 10, 10); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java
r33055 r33082 22 22 import org.openstreetmap.josm.data.validation.Test; 23 23 import org.openstreetmap.josm.data.validation.TestError; 24 import org.openstreetmap.josm.data.validation.TestError.Builder; 24 25 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 25 26 import org.openstreetmap.josm.plugins.pt_assistant.utils.StopUtils; … … 27 28 public class NodeChecker extends Checker { 28 29 29 30 30 protected NodeChecker(Node node, Test test) { 31 super(node, test); 31 32 32 33 } 33 34 34 35 36 37 35 /** 36 * Checks if the given stop_position node belongs to any way 37 */ 38 protected void performSolitaryStopPositionTest() { 38 39 39 40 List<OsmPrimitive> referrers = node.getReferrers(); 40 41 41 42 43 44 45 46 42 for (OsmPrimitive referrer : referrers) { 43 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 44 Way referrerWay = (Way) referrer; 45 if (RouteUtils.isWaySuitableForPublicTransport(referrerWay)) { 46 return; 47 } 47 48 48 49 49 } 50 } 50 51 51 List<OsmPrimitive> primitives = new ArrayList<>(1); 52 primitives.add(node); 53 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop_position is not part of a way"), 54 PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION, primitives); 55 errors.add(e); 52 List<OsmPrimitive> primitives = new ArrayList<>(1); 53 primitives.add(node); 54 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION); 55 builder.message(tr("PT: Stop_position is not part of a way")); 56 builder.primitives(primitives); 57 TestError e = builder.build(); 58 errors.add(e); 56 59 57 60 } 58 61 59 60 61 62 62 /** 63 * Checks if the given platform node belongs to any way 64 */ 65 protected void performPlatformPartOfWayTest() { 63 66 64 67 List<OsmPrimitive> referrers = node.getReferrers(); 65 68 66 for (OsmPrimitive referrer : referrers) { 67 List<Node> primitives = new ArrayList<>(1); 68 primitives.add(node); 69 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 70 Way referringWay = (Way) referrer; 71 if (RouteUtils.isWaySuitableForPublicTransport(referringWay)) { 72 TestError e = new TestError(this.test, Severity.WARNING, 73 tr("PT: Platform should not be part of a way"), 74 PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY, primitives); 75 errors.add(e); 76 return; 77 } 78 } 79 } 80 } 69 for (OsmPrimitive referrer : referrers) { 70 List<Node> primitives = new ArrayList<>(1); 71 primitives.add(node); 72 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 73 Way referringWay = (Way) referrer; 74 if (RouteUtils.isWaySuitableForPublicTransport(referringWay)) { 75 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY); 76 builder.message(tr("PT: Platform should not be part of a way")); 77 builder.primitives(primitives); 78 TestError e = builder.build(); 79 errors.add(e); 80 return; 81 } 82 } 83 } 84 } 81 85 82 /** 83 * Checks if the given stop_position node belongs to any stop_area relation 84 * @author xamanu 85 */ 86 protected void performNodePartOfStopAreaTest() { 86 /** 87 * Checks if the given stop_position node belongs to any stop_area relation 88 * 89 * @author xamanu 90 */ 91 protected void performNodePartOfStopAreaTest() { 87 92 88 93 if (!StopUtils.verifyIfMemberOfStopArea(node)) { 89 94 90 List<OsmPrimitive> primitives = new ArrayList<>(1); 91 primitives.add(node); 92 TestError e = new TestError(this.test, Severity.WARNING, 93 tr("PT: Stop position or platform is not part of a stop area relation"), 94 PTAssistantValidatorTest.ERROR_CODE_NOT_PART_OF_STOP_AREA, primitives); 95 errors.add(e); 96 } 97 } 95 List<OsmPrimitive> primitives = new ArrayList<>(1); 96 primitives.add(node); 97 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_NOT_PART_OF_STOP_AREA); 98 builder.message(tr("PT: Stop position or platform is not part of a stop area relation")); 99 builder.primitives(primitives); 100 TestError e = builder.build(); 101 errors.add(e); 102 } 103 } 98 104 99 /** 100 * Fixes errors: solitary stop position and platform which is part of a way. 101 * Asks the user first. 102 * 103 * @param testError test error 104 * @return fix command 105 */ 106 protected static Command fixError(TestError testError) { 105 /** 106 * Fixes errors: solitary stop position and platform which is part of a way. 107 * Asks the user first. 108 * 109 * @param testError 110 * test error 111 * @return fix command 112 */ 113 protected static Command fixError(TestError testError) { 107 114 108 109 110 111 115 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION 116 && testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) { 117 return null; 118 } 112 119 113 120 Node problematicNode = (Node) testError.getPrimitives().iterator().next(); 114 121 115 116 117 122 final int[] userSelection = { JOptionPane.YES_OPTION }; 123 final TestError errorParameter = testError; 124 if (SwingUtilities.isEventDispatchThread()) { 118 125 119 126 userSelection[0] = showFixNodeTagDialog(errorParameter); 120 127 121 128 } else { 122 129 123 124 125 126 127 128 129 130 131 132 133 134 130 try { 131 SwingUtilities.invokeAndWait(new Runnable() { 132 @Override 133 public void run() { 134 userSelection[0] = showFixNodeTagDialog(errorParameter); 135 } 136 }); 137 } catch (InvocationTargetException | InterruptedException e) { 138 e.printStackTrace(); 139 return null; 140 } 141 } 135 142 136 143 if (userSelection[0] == JOptionPane.YES_OPTION) { 137 144 138 139 140 141 142 143 144 145 146 147 148 145 Node modifiedNode = new Node(problematicNode); 146 if (testError.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION) { 147 modifiedNode.put("public_transport", "platform"); 148 ChangeCommand command = new ChangeCommand(problematicNode, modifiedNode); 149 return command; 150 } else { 151 modifiedNode.put("public_transport", "stop_position"); 152 ChangeCommand command = new ChangeCommand(problematicNode, modifiedNode); 153 return command; 154 } 155 } 149 156 150 157 return null; 151 158 152 159 } 153 160 154 155 156 157 158 159 160 161 private static int showFixNodeTagDialog(TestError e) { 162 Node problematicNode = (Node) e.getPrimitives().iterator().next(); 163 // Main.map.mapView.zoomTo(problematicNode.getCoor()); 164 // zoom to problem: 165 Collection<OsmPrimitive> primitives = new ArrayList<>(1); 166 primitives.add(problematicNode); 167 AutoScaleAction.zoomTo(primitives); 161 168 162 163 164 165 166 167 168 169 170 171 169 String[] options = { tr("Yes"), tr("No") }; 170 String message; 171 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION) { 172 message = "Do you want to change the tag public_transport=stop_position to public_transport=platform?"; 173 } else { 174 message = "Do you want to change the tag public_transport=platform to public_transport=stop_position?"; 175 } 176 return JOptionPane.showOptionDialog(null, message, tr("PT_Assistant Message"), JOptionPane.YES_NO_OPTION, 177 JOptionPane.QUESTION_MESSAGE, null, options, 0); 178 } 172 179 173 180 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r33055 r33082 25 25 import org.openstreetmap.josm.data.validation.Test; 26 26 import org.openstreetmap.josm.data.validation.TestError; 27 import org.openstreetmap.josm.data.validation.TestError.Builder; 27 28 import org.openstreetmap.josm.plugins.pt_assistant.PTAssistantPlugin; 28 29 import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask; … … 550 551 List<Relation> primitives = new ArrayList<>(1); 551 552 primitives.add(r); 553 Builder builder = TestError.builder(this, Severity.WARNING, ERROR_CODE_DIRECTION); 554 builder.message(tr("PT: dummy test warning")); 555 builder.primitives(primitives); 552 556 errors.add( 553 new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives));557 builder.build()); 554 558 } 555 559 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java
r33055 r33082 17 17 import org.openstreetmap.josm.data.validation.Test; 18 18 import org.openstreetmap.josm.data.validation.TestError; 19 import org.openstreetmap.josm.data.validation.TestError.Builder; 19 20 import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter; 20 21 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType; … … 64 65 65 66 if (!hasGap(sortedMembers)) { 66 TestError e = new TestError(this.test, Severity.WARNING, 67 tr("PT: Route contains a gap that can be fixed by sorting"), 68 PTAssistantValidatorTest.ERROR_CODE_SORTING, relation); 67 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_SORTING); 68 builder.message(tr("PT: Route contains a gap that can be fixed by sorting")); 69 builder.primitives(relation); 70 TestError e = builder.build(); 69 71 this.errors.add(e); 70 72 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r33055 r33082 26 26 import org.openstreetmap.josm.data.validation.Test; 27 27 import org.openstreetmap.josm.data.validation.TestError; 28 import org.openstreetmap.josm.data.validation.TestError.Builder; 28 29 import org.openstreetmap.josm.gui.Notification; 29 30 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; … … 70 71 List<OsmPrimitive> highlighted = new ArrayList<>(1); 71 72 highlighted.add(rm.getMember()); 72 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Relation member roles do not match tags"), 73 PTAssistantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES, primitives, highlighted); 73 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES); 74 builder.message(tr("PT: Relation member roles do not match tags")); 75 builder.primitives(primitives); 76 builder.highlight(highlighted); 77 TestError e = builder.build(); 74 78 this.errors.add(e); 75 79 } … … 162 166 List<OsmPrimitive> highlighted = new ArrayList<>(1); 163 167 highlighted.add(endStop.getPlatform()); 164 TestError e = new TestError(this.test, Severity.WARNING, 165 tr("PT: Route should start and end with a stop_position"), 166 PTAssistantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted); 168 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_END_STOP); 169 builder.message(tr("PT: Route should start and end with a stop_position")); 170 builder.primitives(primitives); 171 builder.highlight(highlighted); 172 TestError e = builder.build(); 167 173 this.errors.add(e); 168 174 return; … … 181 187 highlighted.addAll(stopPositionsOfThisRoute); 182 188 183 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 184 PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 189 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY); 190 builder.message(tr("PT: First or last way needs to be split")); 191 builder.primitives(primitives); 192 builder.highlight(highlighted); 193 TestError e = builder.build(); 185 194 this.errors.add(e); 186 195 } … … 197 206 List<OsmPrimitive> highlighted = new ArrayList<>(); 198 207 highlighted.add(endStop.getStopPosition()); 199 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 200 PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 208 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY); 209 builder.message(tr("PT: First or last way needs to be split")); 210 builder.primitives(primitives); 211 builder.highlight(highlighted); 212 TestError e = builder.build(); 201 213 this.errors.add(e); 202 214 } … … 284 296 List<OsmPrimitive> highlighted = new ArrayList<>(); 285 297 highlighted.add(startWay); 286 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 287 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 298 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP); 299 builder.message(tr("PT: Problem in the route segment")); 300 builder.primitives(primitives); 301 builder.highlight(highlighted); 302 TestError e = builder.build(); 288 303 this.errors.add(e); 289 304 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation); … … 321 336 } 322 337 highlighted.add(stopPrimitive); 323 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop not served"), 324 PTAssistantValidatorTest.ERROR_CODE_STOP_NOT_SERVED, primitives, highlighted); 338 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_NOT_SERVED); 339 builder.message(tr("PT: Stop not served")); 340 builder.primitives(primitives); 341 builder.highlight(highlighted); 342 TestError e = builder.build(); 325 343 this.errors.add(e); 326 344 } … … 444 462 List<OsmPrimitive> highlighted = new ArrayList<>(); 445 463 highlighted.addAll(current.getWays()); 446 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 447 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 464 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP); 465 builder.message(tr("PT: Problem in the route segment")); 466 builder.primitives(primitives); 467 builder.highlight(highlighted); 468 TestError e = builder.build(); 448 469 this.errors.add(e); 449 470 return false; … … 464 485 465 486 highlighted.addAll(current.getWays()); 466 467 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Problem in the route segment"), 468 PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP, primitives, highlighted); 487 488 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP); 489 builder.message(tr("PT: Problem in the route segment")); 490 builder.primitives(primitives); 491 builder.highlight(highlighted); 492 TestError e = builder.build(); 469 493 this.errors.add(e); 470 494 return false; … … 843 867 // prepare the variables for the key listener: 844 868 final TestError testErrorParameter = testError; 845 846 // add the key listener: 869 870 // // add the key listener: 847 871 Main.map.mapView.requestFocus(); 848 Main.map.mapView.addKeyListener(new KeyListener() { 849 850 @Override 872 Main.map.mapView.addKeyListener(new KeyListener() { 873 851 874 public void keyTyped(KeyEvent e) { 852 // TODO Auto-generated method stub 853 } 854 855 @Override 875 //TODO Auto-generated method stub 876 } 877 856 878 public void keyPressed(KeyEvent e) { 857 879 Character typedKey = e.getKeyChar(); … … 869 891 } 870 892 871 @Override872 893 public void keyReleased(KeyEvent e) { 873 894 // TODO Auto-generated method stub … … 939 960 940 961 } 941 962 942 963 /** 943 964 * Carries out the fix (i.e. modifies the route) when there is only one fix … … 963 984 }); 964 985 } 965 986 966 987 // wait: 967 988 synchronized (SegmentChecker.class) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/StopChecker.java
r33055 r33082 14 14 import org.openstreetmap.josm.data.validation.Test; 15 15 import org.openstreetmap.josm.data.validation.TestError; 16 import org.openstreetmap.josm.data.validation.TestError.Builder; 16 17 import org.openstreetmap.josm.plugins.pt_assistant.utils.StopUtils; 17 18 … … 47 48 List<OsmPrimitive> primitives = new ArrayList<>(1); 48 49 primitives.add(relation); 49 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop area relation has no stop position"), 50 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_NO_STOPS, primitives); 50 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_NO_STOPS); 51 builder.message(tr("PT: Stop area relation has no stop position")); 52 builder.primitives(primitives); 53 TestError e = builder.build(); 51 54 errors.add(e); 52 55 } … … 67 70 List<OsmPrimitive> primitives = new ArrayList<>(1); 68 71 primitives.add(relation); 69 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop area relation has no platform"), 70 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_NO_PLATFORM, primitives); 72 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_NO_PLATFORM); 73 builder.message(tr("PT: Stop area relation has no platform")); 74 builder.primitives(primitives); 75 TestError e = builder.build(); 71 76 errors.add(e); 72 77 … … 121 126 List<OsmPrimitive> primitives = new ArrayList<>(1); 122 127 primitives.add(relation); 123 TestError e = new TestError(this.test, Severity.WARNING, 124 tr("PT: Route relations of stop position(s) and platform(s) of stop area members diverge"), 125 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_COMPARE_RELATIONS, primitives); 128 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_COMPARE_RELATIONS); 129 builder.message(tr("PT: Route relations of stop position(s) and platform(s) of stop area members diverge")); 130 builder.primitives(primitives); 131 TestError e = builder.build(); 126 132 errors.add(e); 127 133 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r33055 r33082 21 21 import org.openstreetmap.josm.data.validation.Test; 22 22 import org.openstreetmap.josm.data.validation.TestError; 23 import org.openstreetmap.josm.data.validation.TestError.Builder; 23 24 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 24 25 … … 114 115 List<Way> highlighted = new ArrayList<>(1); 115 116 highlighted.add(way); 116 TestError e = new TestError(this.test, Severity.WARNING, 117 tr("PT: Route type does not match the type of the road it passes on"), 118 PTAssistantValidatorTest.ERROR_CODE_ROAD_TYPE, primitives, highlighted); 117 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_ROAD_TYPE); 118 builder.message(tr("PT: Route type does not match the type of the road it passes on")); 119 builder.primitives(primitives); 120 builder.highlight(highlighted); 121 TestError e = builder.build(); 119 122 errors.add(e); 120 123 … … 126 129 List<Way> highlighted = new ArrayList<>(1); 127 130 highlighted.add(way); 128 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Road is under construction"), 129 PTAssistantValidatorTest.ERROR_CODE_CONSTRUCTION, primitives, highlighted); 131 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_CONSTRUCTION); 132 builder.message(tr("PT: Road is under construction")); 133 builder.primitives(primitives); 134 builder.highlight(highlighted); 135 TestError e = builder.build(); 130 136 errors.add(e); 131 137 } … … 213 219 214 220 for (Set<Way> currentSet : listOfSets) { 215 TestError e = new TestError(this.test, Severity.WARNING, 216 tr("PT: Route passes a oneway road in the wrong direction"), 217 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, currentSet); 221 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_DIRECTION); 222 builder.message(tr("PT: Route passes a oneway road in the wrong direction")); 223 builder.primitives(primitives); 224 builder.highlight(currentSet); 225 TestError e = builder.build(); 218 226 this.errors.add(e); 219 227 }
Note:
See TracChangeset
for help on using the changeset viewer.