Changeset 32567 in osm for applications
- Timestamp:
- 2016-07-05T00:28:27+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 4 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r32522 r32567 2 2 package org.openstreetmap.josm.plugins.pt_assistant; 3 3 4 import javax.swing.JMenuItem; 5 6 import org.openstreetmap.josm.Main; 4 7 import org.openstreetmap.josm.data.validation.OsmValidator; 8 import org.openstreetmap.josm.gui.MainMenu; 9 import org.openstreetmap.josm.gui.MapFrame; 5 10 import org.openstreetmap.josm.plugins.Plugin; 6 11 import org.openstreetmap.josm.plugins.PluginInformation; 7 import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssitantValidatorTest; 12 import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; 13 import org.openstreetmap.josm.plugins.pt_assistant.validation.PTAssistantValidatorTest; 14 import org.openstreetmap.josm.tools.ImageProvider; 8 15 9 16 /** … … 14 21 */ 15 22 public class PTAssistantPlugin extends Plugin { 16 23 24 private JMenuItem addStopPositionMenu; 25 17 26 /** 18 27 * Main constructor. … … 25 34 super(info); 26 35 27 // OsmValidator.addTest(PlatformsFirstTest.class); 28 // OsmValidator.addTest(RoadTypeTest.class); 29 // OsmValidator.addTest(DirectionTest.class); 30 // OsmValidator.addTest(GapTest.class); 36 OsmValidator.addTest(PTAssistantValidatorTest.class); 31 37 32 OsmValidator.addTest(PTAssitantValidatorTest.class);33 38 AddStopPositionAction addStopPositionAction = new AddStopPositionAction(); 39 addStopPositionMenu = MainMenu.add(Main.main.menu.toolsMenu, addStopPositionAction, false); 34 40 35 41 } 42 43 /** 44 * Called when the JOSM map frame is created or destroyed. 45 */ 46 @Override 47 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 48 if (oldFrame == null && newFrame != null) { 49 addStopPositionMenu.setEnabled(true); 50 } else if (oldFrame != null && newFrame == null) { 51 addStopPositionMenu.setEnabled(false); 52 } 53 } 36 54 37 38 39 55 /** 56 * Returns a ImageProvider for the given string or null if in headless mode. 57 * 58 * @param s 59 * The name of the file where the picture is. 60 * @return A ImageProvider object for the given string or null if in 61 * headless mode. 62 */ 63 public static ImageProvider getProvider(String s) { 64 if (Main.main == null) { 65 return null; 66 } 67 return new ImageProvider(s); 68 } 40 69 41 70 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32540 r32567 176 176 } 177 177 178 Main.map.repaint(); 178 Main.map.mapView.repaint(); 179 179 } 180 180 … … 200 200 201 201 this.primitives.clear(); 202 Main.map.repaint(); 202 Main.map.mapView.repaint(); 203 203 } 204 204 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32415 r32567 4 4 import org.openstreetmap.josm.data.osm.Relation; 5 5 import org.openstreetmap.josm.data.osm.RelationMember; 6 import org.openstreetmap.josm.data.osm.Way;7 6 8 7 /** … … 114 113 } 115 114 116 /**117 * Checks if the type of the way is suitable for buses to go on it. The118 * direction of the way (i.e. one-way roads) is irrelevant for this test.119 *120 * TODO: this test is duplicated in WayChecker, remove it here when the old121 * implementation is not needed anymore.122 *123 * @deprecated124 *125 * @param way126 * to be checked127 * @return true if the way is suitable for buses, false otherwise.128 */129 public static boolean isWaySuitableForBuses(Way way) {130 if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary")131 || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary")132 || way.hasTag("highway", "unclassified") || way.hasTag("highway", "road")133 || way.hasTag("highway", "residential") || way.hasTag("highway", "service")134 || way.hasTag("highway", "motorway_link") || way.hasTag("highway", "trunk_link")135 || way.hasTag("highway", "primary_link") || way.hasTag("highway", "secondary_link")136 || way.hasTag("highway", "tertiary_link") || way.hasTag("highway", "living_street")137 || way.hasTag("highway", "bus_guideway") || way.hasTag("highway", "road")138 || way.hasTag("cycleway", "share_busway") || way.hasTag("cycleway", "shared_lane")) {139 return true;140 }141 142 if (way.hasTag("highway", "pedestrian") && (way.hasTag("bus", "yes") || way.hasTag("psv", "yes")143 || way.hasTag("bus", "designated") || way.hasTag("psv", "designated"))) {144 return true;145 }146 147 return false;148 }149 150 public static boolean hasIncompleteMembers(Relation r) {151 if (r == null) {152 return true;153 }154 for (RelationMember rm : r.getMembers()) {155 if ((rm.isNode() && rm.getNode().isIncomplete()) || (rm.isWay() && rm.getWay().isIncomplete())156 || (rm.isRelation() && rm.getRelation().isIncomplete())) {157 return true;158 }159 }160 161 return false;162 }163 164 115 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java
r32497 r32567 65 65 TestError e = new TestError(this.test, Severity.WARNING, 66 66 tr("PT: Route contains a gap that can be fixed by sorting"), 67 PTAssitantValidatorTest.ERROR_CODE_SORTING, relation); 67 PTAssistantValidatorTest.ERROR_CODE_SORTING, relation); 68 68 this.errors.add(e); 69 69 … … 112 112 113 113 protected static Command fixSortingError(TestError testError) { 114 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_SORTING) { 114 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_SORTING) { 115 115 return null; 116 116 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32522 r32567 52 52 highlighted.add(rm.getMember()); 53 53 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Relation member roles do not match tags"), 54 PTAssitantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES, primitives, highlighted); 54 PTAssistantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES, primitives, highlighted); 55 55 this.errors.add(e); 56 56 } … … 112 112 TestError e = new TestError(this.test, Severity.WARNING, 113 113 tr("PT: Route should start and end with a stop_position"), 114 PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted); 114 PTAssistantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted); 115 115 this.errors.add(e); 116 116 return; … … 130 130 131 131 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 132 PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 132 PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 133 133 this.errors.add(e); 134 134 } … … 146 146 highlighted.add(endStop.getStopPosition()); 147 147 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 148 PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 148 PTAssistantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 149 149 this.errors.add(e); 150 150 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32557 r32567 121 121 TestError e = new TestError(this.test, Severity.WARNING, 122 122 tr("PT: Route type does not match the type of the road it passes on"), 123 PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE, primitives, highlighted); 123 PTAssistantValidatorTest.ERROR_CODE_ROAD_TYPE, primitives, highlighted); 124 124 errors.add(e); 125 125 … … 132 132 highlighted.add(way); 133 133 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Road is under construction"), 134 PTAssitantValidatorTest.ERROR_CODE_CONSTRUCTION, primitives, highlighted); 134 PTAssistantValidatorTest.ERROR_CODE_CONSTRUCTION, primitives, highlighted); 135 135 errors.add(e); 136 136 } … … 180 180 TestError e = new TestError(this.test, Severity.WARNING, 181 181 tr("PT: Route passes a oneway road in the wrong direction"), 182 PTAssitantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted); 182 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted); 183 183 this.errors.add(e); 184 184 return; … … 221 221 protected static Command fixErrorByRemovingWay(TestError testError) { 222 222 223 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE 224 && testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 223 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_ROAD_TYPE 224 && testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 225 225 return null; 226 226 } … … 279 279 protected static Command fixErrorByZooming(TestError testError) { 280 280 281 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 281 if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 282 282 return null; 283 283 } … … 337 337 GenericRelationEditor editor = new GenericRelationEditor(layer, r, r.getMembersFor(primitives)); 338 338 RelationDialogManager.getRelationDialogManager().register(layer, r, editor); 339 340 341 339 editor.setVisible(true); 342 // editor.requestFocus(); 343 // editor.requestFocusInWindow(); 344 345 // editor.firePropertyChange("focusedWindow", editor, editor); 346 // editor.setRelation(r); 340 347 341 348 342 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/data/RouteRepresentationTest.java
r32506 r32567 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue;5 4 6 5 import java.util.ArrayList; … … 31 30 * stop2(platform, Way) 32 31 * way2 (Way) 33 * stop3 ( stop_area)32 * stop3 (platform) 34 33 * way3 (Relation that consists of Ways only) 35 34 * stop4 (stop_position) … … 45 44 Node n1 = new Node(); 46 45 n1.put("name", "Stop1"); 46 n1.put("public_transport", "stop_position"); 47 47 RelationMember rm1 = new RelationMember("stop", n1); 48 48 members.add(rm1); … … 52 52 RelationMember rm2 = new RelationMember("platform", w1); 53 53 members.add(rm2); 54 Relation r1 = new Relation(); 55 r1.put("name", "Stop3"); 56 RelationMember rm3 = new RelationMember("stop_area", r1); 54 Node n2 = new Node(); 55 n2.put("name", "Stop3"); 56 n2.put("public_transport", "platform"); 57 RelationMember rm3 = new RelationMember("platform", n2); 57 58 members.add(rm3); 58 Node n2 = new Node();59 n2.put("name", "Stop4");60 RelationMember rm4 = new RelationMember("stop", n2);61 members.add(rm4);62 59 Node n3 = new Node(); 63 60 n3.put("name", "Stop4"); 64 RelationMember rm5 = new RelationMember("platform", n3); 61 n3.put("public_transport", "stop_position"); 62 RelationMember rm4 = new RelationMember("stop", n3); 63 members.add(rm4); 64 Node n4 = new Node(); 65 n4.put("name", "Stop4"); 66 n4.put("public_transport", "platform"); 67 RelationMember rm5 = new RelationMember("platform", n4); 65 68 members.add(rm5); 66 Relation r2= newRelation();67 r2.put("name", "Stop5");68 r2.put("highway", "platform_exit_only");69 RelationMember rm6 = new RelationMember("platform_exit_only", r2);69 Node n5 = new Node(); 70 n5.put("name", "Stop5"); 71 n5.put("highway", "platform"); 72 RelationMember rm6 = new RelationMember("platform_exit_only", n5); 70 73 members.add(rm6); 71 74 … … 90 93 members.add(rm10); 91 94 92 93 94 95 Relation route = new Relation(); 95 96 route.setMembers(members); … … 112 113 Node n1 = new Node(); 113 114 n1.put("name", "Stop1"); 115 n1.put("public_transport", "stop_position"); 114 116 RelationMember rm1 = new RelationMember("stop", n1); 115 117 members.add(rm1); … … 119 121 RelationMember rm2 = new RelationMember("platform", w1); 120 122 members.add(rm2); 121 Relation r1 = new Relation(); 122 r1.put("name", "Stop3"); 123 RelationMember rm3 = new RelationMember("stop_area", r1); 123 Node n2 = new Node(); 124 n2.put("name", "Stop3"); 125 n2.put("public_transport", "platform"); 126 RelationMember rm3 = new RelationMember("platform", n2); 124 127 members.add(rm3); 125 Node n2 = new Node();126 n2.put("name", "Stop4");127 RelationMember rm4 = new RelationMember("stop", n2);128 members.add(rm4);129 128 Node n3 = new Node(); 130 129 n3.put("name", "Stop4"); 131 RelationMember rm5 = new RelationMember("platform", n3); 130 n3.put("public_transport", "stop_position"); 131 RelationMember rm4 = new RelationMember("stop", n3); 132 members.add(rm4); 133 Node n4 = new Node(); 134 n4.put("name", "Stop4"); 135 n4.put("public_transport", "platform"); 136 RelationMember rm5 = new RelationMember("platform", n4); 132 137 members.add(rm5); 133 Relation r2= newRelation();134 r2.put("name", "Stop5");135 r2.put("highway", "platform_exit_only");136 RelationMember rm6 = new RelationMember("platform_exit_only", r2);138 Node n5 = new Node(); 139 n5.put("name", "Stop5"); 140 n5.put("highway", "platform"); 141 RelationMember rm6 = new RelationMember("platform_exit_only", n5); 137 142 members.add(rm6); 138 143 … … 146 151 Relation r3 = new Relation(); // nested relation 147 152 Way w4 = new Way(); 148 Node wrongNode = new Node(); // CHANGED COMPARED TO PREVIOUS TEST153 Node wrongNode = new Node(); 149 154 Way w6 = new Way(); 150 155 r3.addMember(new RelationMember("", w4)); 151 r3.addMember(new RelationMember(" platform", wrongNode));156 r3.addMember(new RelationMember("", wrongNode)); 152 157 r3.addMember(new RelationMember("", w6)); 153 158 RelationMember rm9 = new RelationMember("", r3); … … 161 166 route.setMembers(members); 162 167 163 boolean thrown = false; 164 String message = ""; 165 try { 166 /*PTRouteDataManager manager =*/ new PTRouteDataManager(route); 167 } catch(IllegalArgumentException e) { 168 thrown = true; 169 message = e.getMessage(); 170 } 168 PTRouteDataManager manager = new PTRouteDataManager(route); 171 169 172 assertTrue(thrown); 173 assertEquals(message, "A route relation member of OsmPrimitiveType.RELATION can only have ways as members"); 170 assertEquals(manager.getFailedMembers().size(), 1); 171 assertEquals(manager.getPTStopCount(), 5); 172 assertEquals(manager.getPTWayCount(), 3); 174 173 175 174 } 176 175 177 178 @Test179 public void multipleStopElementTest() {180 181 // Same as correctRouteTest(), but182 183 ArrayList<RelationMember> members = new ArrayList<>();184 185 // Create stops:186 Node n1 = new Node();187 n1.put("name", "Stop1");188 RelationMember rm1 = new RelationMember("stop", n1);189 members.add(rm1);190 Way w1 = new Way();191 w1.put("name", "Stop2");192 w1.put("highway", "platform");193 RelationMember rm2 = new RelationMember("platform", w1);194 members.add(rm2);195 Relation r1 = new Relation();196 r1.put("name", "Stop3");197 RelationMember rm3 = new RelationMember("stop_area", r1);198 members.add(rm3);199 Node n2 = new Node();200 n2.put("name", "Stop4");201 RelationMember rm4 = new RelationMember("stop", n2);202 members.add(rm4);203 Node n3 = new Node();204 n3.put("name", "Stop4");205 RelationMember rm5 = new RelationMember("platform", n3);206 members.add(rm5);207 Relation r2 = new Relation();208 r2.put("name", "Stop5");209 r2.put("highway", "platform_exit_only");210 RelationMember rm6 = new RelationMember("platform_exit_only", r2);211 members.add(rm6);212 213 // Create ways:214 Way w2 = new Way();215 RelationMember rm7 = new RelationMember("", w2);216 members.add(rm7);217 Way w3 = new Way();218 RelationMember rm8 = new RelationMember("", w3);219 members.add(rm8);220 Relation r3 = new Relation(); // nested relation221 Way w4 = new Way();222 Way w5 = new Way();223 Way w6 = new Way();224 r3.addMember(new RelationMember("", w4));225 r3.addMember(new RelationMember("", w5));226 r3.addMember(new RelationMember("", w6));227 RelationMember rm9 = new RelationMember("", r3);228 members.add(rm9);229 Way w7 = new Way();230 RelationMember rm10 = new RelationMember("", w7);231 members.add(rm10);232 233 234 235 Relation route = new Relation();236 route.setMembers(members);237 238 PTRouteDataManager manager = new PTRouteDataManager(route);239 240 assertEquals(manager.getPTStopCount(), 5);241 assertEquals(manager.getPTWayCount(), 4);242 243 }244 245 246 176 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java
r32506 r32567 5 5 6 6 import java.io.File; 7 import java.util.ArrayList; 7 8 import java.util.List; 8 9 … … 19 20 @Test 20 21 public void test() { 21 // this file has:22 // Way23 24 22 25 23 File file = new File(AbstractTest.PATH_TO_ROUNDABOUT_ONEWAY); 26 24 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 PTAssitantValidatorTest test = new PTAssitantValidatorTest(); 27 27 28 28 Relation route = null; … … 35 35 assertEquals(route.getMembersCount(), 213); 36 36 37 DirectionTest directionTest = new DirectionTest(); 37 List<TestError> errors = new ArrayList<>(); 38 38 39 for (Relation r: ds.getRelations()) { 39 directionTest.visit(r); 40 WayChecker wayChecker = new WayChecker(r, test); 41 wayChecker.performDirectionTest(); 42 errors.addAll(wayChecker.getErrors()); 40 43 } 41 44 42 List<TestError> errors = directionTest.getErrors();43 45 assertEquals(errors.size(), 1); 44 46 int onewayErrorCaught = 0; 45 47 for (TestError e: errors ) { 46 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) {48 if (e.getCode() == PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 47 49 onewayErrorCaught++; 48 50 } … … 55 57 boolean detectedErrorsAreCorrect = true; 56 58 for (TestError e: errors) { 57 if (e.getCode() == DirectionTest.ERROR_CODE_DIRECTION) {59 if (e.getCode() == PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 58 60 @SuppressWarnings("unchecked") 59 61 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted(); -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/PlatformAsWayTest.java
r32506 r32567 4 4 5 5 import java.io.File; 6 import java.util.ArrayList; 6 7 import java.util.List; 7 8 … … 20 21 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 21 22 22 GapTest gapTest = new GapTest(); 23 PTAssitantValidatorTest test = new PTAssitantValidatorTest(); 24 25 List<TestError> errors = new ArrayList<>(); 26 23 27 for (Relation r: ds.getRelations()) { 24 gapTest.visit(r); 28 WayChecker wayChecker = new WayChecker(r, test); 29 wayChecker.performDirectionTest(); 30 wayChecker.performRoadTypeTest(); 31 errors.addAll(wayChecker.getErrors()); 32 RouteChecker routeChecker = new RouteChecker(r, test); 33 routeChecker.performSortingTest(); 34 errors.addAll(routeChecker.getErrors()); 25 35 } 26 27 List<TestError> errors = gapTest.getErrors();28 36 29 37 assertEquals(errors.size(), 0); -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/RoadTypeTestTest.java
r32506 r32567 5 5 6 6 import java.io.File; 7 import java.util.ArrayList; 7 8 import java.util.List; 8 9 … … 24 25 DataSet ds = ImportUtils.importOsmFile(file, "testLayer"); 25 26 26 RoadTypeTest roadTypeTest = new RoadTypeTest(); 27 PTAssitantValidatorTest test = new PTAssitantValidatorTest(); 28 List<TestError> errors = new ArrayList<>(); 29 27 30 for (Relation r: ds.getRelations()) { 28 roadTypeTest.visit(r); 31 WayChecker wayChecker = new WayChecker(r, test); 32 wayChecker.performRoadTypeTest(); 33 errors.addAll(wayChecker.getErrors()); 29 34 } 30 35 31 List<TestError> errors = roadTypeTest.getErrors();32 36 assertEquals(errors.size(), 2); 33 37 34 38 for (TestError e: errors) { 35 assertEquals(e.getCode(), RoadTypeTest.ERROR_CODE_ROAD_TYPE);39 assertEquals(e.getCode(), PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE); 36 40 @SuppressWarnings("unchecked") 37 41 List<OsmPrimitive> highlighted = (List<OsmPrimitive>) e.getHighlighted();
Note:
See TracChangeset
for help on using the changeset viewer.