Changeset 32616 in osm for applications/editors/josm
- Timestamp:
- 2016-07-08T22:37:38+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 5 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32603 r32616 173 173 return false; 174 174 } 175 176 /** 177 * Checks if the type of the way is suitable for buses to go on it. The 178 * direction of the way (i.e. one-way roads) is irrelevant for this test. 179 * 180 * @param way 181 * to be checked 182 * @return true if the way is suitable for buses, false otherwise. 183 */ 184 public static boolean isWaySuitableForBuses(Way way) { 185 if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary") 186 || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary") 187 || way.hasTag("highway", "unclassified") || way.hasTag("highway", "road") 188 || way.hasTag("highway", "residential") || way.hasTag("highway", "service") 189 || way.hasTag("highway", "motorway_link") || way.hasTag("highway", "trunk_link") 190 || way.hasTag("highway", "primary_link") || way.hasTag("highway", "secondary_link") 191 || way.hasTag("highway", "tertiary_link") || way.hasTag("highway", "living_street") 192 || way.hasTag("highway", "bus_guideway") || way.hasTag("highway", "road") 193 || way.hasTag("cycleway", "share_busway") || way.hasTag("cycleway", "shared_lane")) { 194 return true; 195 } 196 197 if (way.hasTag("highway", "pedestrian") && (way.hasTag("bus", "yes") || way.hasTag("psv", "yes") 198 || way.hasTag("bus", "designated") || way.hasTag("psv", "designated"))) { 199 return true; 200 } 201 202 return false; 203 } 175 204 176 205 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java
r32597 r32616 4 4 import java.util.List; 5 5 6 import org.openstreetmap.josm.data.osm.Node; 6 7 import org.openstreetmap.josm.data.osm.Relation; 7 8 import org.openstreetmap.josm.data.osm.RelationMember; … … 20 21 // test which created this WayChecker: 21 22 protected final Test test; 23 24 // node that is checked: 25 protected Node node; 22 26 23 27 // relation that is checked: … … 26 30 // stores all found errors: 27 31 protected ArrayList<TestError> errors = new ArrayList<>(); 32 33 protected Checker(Node node, Test test) { 34 this.node = node; 35 this.test = test; 36 } 28 37 29 38 protected Checker(Relation relation, Test test) { 30 31 39 this.relation = relation; 32 40 this.test = test; 33 34 41 } 35 42 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32567 r32616 13 13 import org.openstreetmap.josm.command.SequenceCommand; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.Relation; 16 17 import org.openstreetmap.josm.data.validation.Severity; 17 18 import org.openstreetmap.josm.data.validation.Test; 18 19 import org.openstreetmap.josm.data.validation.TestError; 20 import org.openstreetmap.josm.plugins.pt_assistant.actions.DownloadReferrersThread; 19 21 import org.openstreetmap.josm.plugins.pt_assistant.actions.FixTask; 20 22 import org.openstreetmap.josm.plugins.pt_assistant.actions.IncompleteMembersDownloadThread; 23 import org.openstreetmap.josm.plugins.pt_assistant.gui.DownloadReferrersDialog; 21 24 import org.openstreetmap.josm.plugins.pt_assistant.gui.IncompleteMembersDownloadDialog; 22 25 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer; … … 30 33 public static final int ERROR_CODE_CONSTRUCTION = 3722; 31 34 public static final int ERROR_CODE_DIRECTION = 3731; 32 public static final int ERROR_CODE_END_STOP = 3141; 33 public static final int ERROR_CODE_SPLIT_WAY = 3142; 34 public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3143; 35 public static final int ERROR_CODE_END_STOP = 3741; 36 public static final int ERROR_CODE_SPLIT_WAY = 3742; 37 public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3743; 38 public static final int ERROR_CODE_SOLITARY_STOP_POSITION = 3751; 39 public static final int ERROR_CODE_PLATFORM_PART_OF_HIGHWAY = 3752; 35 40 36 41 private PTAssistantLayer layer; 42 private static boolean nodeReferrersDownloaded; 43 @SuppressWarnings("unused") 44 private static boolean incompleteRelationsDowloaded; 45 37 46 38 47 public PTAssistantValidatorTest() { … … 42 51 layer = new PTAssistantLayer(); 43 52 DataSet.addSelectionListener(layer); 53 nodeReferrersDownloaded = false; 54 incompleteRelationsDowloaded = false; 55 56 } 57 58 @Override 59 public void visit(Node n) { 60 61 if (n.isIncomplete()) { 62 return; 63 } 64 65 if (!nodeReferrersDownloaded) { 66 this.downloadReferrers(n); 67 nodeReferrersDownloaded = true; 68 } 69 70 NodeChecker nodeChecker = new NodeChecker(n, this); 71 72 // check for solitary stop positions: 73 if (n.hasTag("public_transport", "stop_position")) { 74 nodeChecker.performSolitaryStopPositionTest(); 75 } 76 77 // check that platforms are not part of any way: 78 if (n.hasTag("highway", "bus_stop") || n.hasTag("public_transport", "platform") 79 || n.hasTag("highway", "platform") || n.hasTag("railway", "platform")) { 80 nodeChecker.performPlatformPartOfWayTest(); 81 } 82 83 this.errors.addAll(nodeChecker.getErrors()); 84 85 } 86 87 88 /** 89 * Downloads incomplete relation members in an extra thread (user input 90 * required) 91 * 92 * @return true if successful, false if not successful 93 */ 94 private boolean downloadReferrers(Node n) { 95 96 final int[] userSelection = { 0 }; 97 98 try { 99 100 if (SwingUtilities.isEventDispatchThread()) { 101 102 userSelection[0] = showDownloadReferrersDialog(); 103 104 } else { 105 106 SwingUtilities.invokeAndWait(new Runnable() { 107 @Override 108 public void run() { 109 try { 110 userSelection[0] = showDownloadReferrersDialog(); 111 } catch (InterruptedException e) { 112 e.printStackTrace(); 113 } 114 115 } 116 }); 117 118 } 119 120 } catch (InterruptedException | InvocationTargetException e) { 121 return false; 122 } 123 124 if (userSelection[0] == JOptionPane.YES_OPTION) { 125 126 Thread t = new DownloadReferrersThread(n); 127 t.start(); 128 synchronized (t) { 129 try { 130 t.wait(); 131 } catch (InterruptedException e) { 132 return false; 133 } 134 } 135 136 } 137 138 return true; 139 140 } 141 142 /** 143 * Shows the dialog asking the user about an incomplete member download 144 * 145 * @return user's selection 146 * @throws InterruptedException 147 */ 148 private int showDownloadReferrersDialog() throws InterruptedException { 149 150 DownloadReferrersDialog downloadReferrersDialog = new DownloadReferrersDialog(); 151 return downloadReferrersDialog.getUserSelection(); 44 152 45 153 } … … 55 163 // and do not do any testing. 56 164 if (r.hasIncompleteMembers()) { 57 165 58 166 boolean downloadSuccessful = this.downloadIncompleteMembers(); 59 167 if (!downloadSuccessful) { 60 168 return; 61 169 } 170 incompleteRelationsDowloaded = true; 62 171 63 172 } … … 313 422 } 314 423 424 if (testError.getCode() == ERROR_CODE_SOLITARY_STOP_POSITION) { 425 // TODO 426 } 427 315 428 if (commands.isEmpty()) { 316 429 return null; … … 357 470 new TestError(this, Severity.WARNING, tr("PT: dummy test warning"), ERROR_CODE_DIRECTION, primitives)); 358 471 } 472 473 public void endTest() { 474 super.endTest(); 475 nodeReferrersDownloaded = false; 476 incompleteRelationsDowloaded = false; 477 } 359 478 360 479 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32603 r32616 62 62 boolean isCorrectRoadType = true; 63 63 boolean isUnderConstruction = false; 64 if (way.hasKey("construction")) { 65 isUnderConstruction = true; 66 } 64 67 if (relation.hasTag("route", "bus") || relation.hasTag("route", "share_taxi")) { 65 if (!isWaySuitableForBuses(way)) { 66 isCorrectRoadType = false; 67 } 68 if (way.hasTag("highway", "construction") && way.hasKey("construction")) {68 if (!RouteUtils.isWaySuitableForBuses(way)) { 69 isCorrectRoadType = false; 70 } 71 if (way.hasTag("highway", "construction")) { 69 72 isUnderConstruction = true; 70 73 } 71 74 } else if (relation.hasTag("route", "trolleybus")) { 72 if (!(isWaySuitableForBuses(way) && way.hasTag("trolley_wire", "yes"))) { 73 isCorrectRoadType = false; 74 } 75 if (way.hasTag("highway", "construction") && way.hasKey("construction")) {75 if (!(RouteUtils.isWaySuitableForBuses(way) && way.hasTag("trolley_wire", "yes"))) { 76 isCorrectRoadType = false; 77 } 78 if (way.hasTag("highway", "construction")) { 76 79 isUnderConstruction = true; 77 80 } … … 80 83 isCorrectRoadType = false; 81 84 } 82 if (way.hasTag("railway", "construction") && way.hasKey("construction")) {85 if (way.hasTag("railway", "construction")) { 83 86 isUnderConstruction = true; 84 87 } … … 87 90 isCorrectRoadType = false; 88 91 } 89 if (way.hasTag("railway", "construction") && way.hasKey("construction")) {92 if (way.hasTag("railway", "construction")) { 90 93 isUnderConstruction = true; 91 94 } … … 94 97 isCorrectRoadType = false; 95 98 } 96 if (way.hasTag("railway", "construction") && way.hasKey("construction")) {99 if (way.hasTag("railway", "construction")) { 97 100 isUnderConstruction = true; 98 101 } … … 101 104 isCorrectRoadType = false; 102 105 } 103 if (way.hasTag("railway", "construction") && way.hasKey("construction")) {106 if (way.hasTag("railway", "construction")) { 104 107 isUnderConstruction = true; 105 108 } … … 108 111 isCorrectRoadType = false; 109 112 } 110 if (way.hasTag("railway", "construction") && way.hasKey("construction")) {113 if (way.hasTag("railway", "construction")) { 111 114 isUnderConstruction = true; 112 115 } … … 198 201 // highlighted.add(problematicWay); 199 202 Set<Way> adjacentWays = checkAdjacentWays(problematicWay, new HashSet<Way>()); 203 adjacentWays.removeAll(problematicWays); 204 highlighted.add(problematicWay); 200 205 highlighted.addAll(adjacentWays); 201 206 TestError e = new TestError(this.test, Severity.WARNING, … … 371 376 } 372 377 373 /**374 * Checks if the type of the way is suitable for buses to go on it. The375 * direction of the way (i.e. one-way roads) is irrelevant for this test.376 *377 * @param way378 * to be checked379 * @return true if the way is suitable for buses, false otherwise.380 */381 private boolean isWaySuitableForBuses(Way way) {382 if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary")383 || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary")384 || way.hasTag("highway", "unclassified") || way.hasTag("highway", "road")385 || way.hasTag("highway", "residential") || way.hasTag("highway", "service")386 || way.hasTag("highway", "motorway_link") || way.hasTag("highway", "trunk_link")387 || way.hasTag("highway", "primary_link") || way.hasTag("highway", "secondary_link")388 || way.hasTag("highway", "tertiary_link") || way.hasTag("highway", "living_street")389 || way.hasTag("highway", "bus_guideway") || way.hasTag("highway", "road")390 || way.hasTag("cycleway", "share_busway") || way.hasTag("cycleway", "shared_lane")) {391 return true;392 }393 394 if (way.hasTag("highway", "pedestrian") && (way.hasTag("bus", "yes") || way.hasTag("psv", "yes")395 || way.hasTag("bus", "designated") || way.hasTag("psv", "designated"))) {396 return true;397 }398 399 return false;400 }401 402 378 protected static Command fixErrorByRemovingWay(TestError testError) { 403 379 -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/AbstractTest.java
r32603 r32616 44 44 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION = "test/data/oneway-wrong-direction.osm"; 45 45 public static final String PATH_TO_ONEWAY_WRONG_DIRECTION2 = "test/data/oneway-wrong-direction2.osm"; 46 47 public static final String PATH_TO_SOLITARY_STOP_POSITION = "test/data/solitary-stop-position.osm"; 46 48 47 49 /** -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java
r32603 r32616 17 17 18 18 public class DirecionTestTest extends AbstractTest { 19 20 @Test 21 public void testOnewayTrue() { 22 23 File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION); 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 PTAssistantValidatorTest test = new PTAssistantValidatorTest(); 27 28 Relation route = null; 29 for (Relation r: ds.getRelations()) { 30 if (r.hasKey("route")) { 31 route = r; 32 } 33 } 34 35 36 List<TestError> errors = new ArrayList<>(); 37 38 for (Relation r: ds.getRelations()) { 39 WayChecker wayChecker = new WayChecker(r, test); 40 wayChecker.performDirectionTest(); 41 errors.addAll(wayChecker.getErrors()); 42 } 43 44 assertEquals(errors.size(), 2); 45 int onewayErrorCaught = 0; 46 for (TestError e: errors ) { 47 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 48 onewayErrorCaught++; 49 } 50 } 51 52 assertEquals(onewayErrorCaught, 2); 53 54 // fix the direction errors: 55 56 boolean detectedErrorsAreCorrect = true; 57 for (TestError e: errors) { 58 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 59 @SuppressWarnings("unchecked") 60 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 61 if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210) { 62 detectedErrorsAreCorrect = false; 63 } 64 } 65 } 66 67 assertTrue(detectedErrorsAreCorrect); 68 } 19 20 @Test 21 public void testOnewayTrue() { 22 23 File file = new File(AbstractTest.PATH_TO_ONEWAY_WRONG_DIRECTION); 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 PTAssistantValidatorTest test = new PTAssistantValidatorTest(); 27 28 List<TestError> errors = new ArrayList<>(); 29 30 for (Relation r : ds.getRelations()) { 31 WayChecker wayChecker = new WayChecker(r, test); 32 wayChecker.performDirectionTest(); 33 errors.addAll(wayChecker.getErrors()); 34 } 35 36 assertEquals(errors.size(), 2); 37 int onewayErrorCaught = 0; 38 for (TestError e : errors) { 39 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 40 onewayErrorCaught++; 41 } 42 } 43 44 assertEquals(onewayErrorCaught, 2); 45 46 // fix the direction errors: 47 48 boolean detectedErrorsAreCorrect = true; 49 for (TestError e : errors) { 50 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 51 @SuppressWarnings("unchecked") 52 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); 53 if (highlighted.get(0).getId() != 225732678 && highlighted.get(0).getId() != 24215210) { 54 detectedErrorsAreCorrect = false; 55 } 56 } 57 } 58 59 assertTrue(detectedErrorsAreCorrect); 60 } 69 61 }
Note:
See TracChangeset
for help on using the changeset viewer.