Changeset 32597 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2016-07-07T01:32:55+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32567 r32597 194 194 } 195 195 196 196 197 @Override 197 198 public void layerRemoving(LayerRemoveEvent event) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32557 r32597 10 10 import java.util.HashMap; 11 11 import java.util.List; 12 13 import javax.swing.JOptionPane; 12 14 13 15 import org.openstreetmap.josm.data.osm.Node; … … 202 204 double cosTriangle = 6 * Math.cos(t); 203 205 double sinTriangle = 6 * Math.sin(t); 204 g.setColor( new Color(50, 50, 50));206 g.setColor(Color.WHITE); 205 207 206 208 if (oneway > 0) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32585 r32597 1 1 package org.openstreetmap.josm.plugins.pt_assistant.utils; 2 2 3 import org.openstreetmap.josm.data.osm.Node; 3 4 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 5 import org.openstreetmap.josm.data.osm.OsmUtils; 4 6 import org.openstreetmap.josm.data.osm.Relation; 5 7 import org.openstreetmap.josm.data.osm.RelationMember; 8 import org.openstreetmap.josm.data.osm.Way; 6 9 7 10 /** … … 114 117 } 115 118 119 /** 120 * Checks if the given way has tags that make it oneway for public 121 * transport. The test does not check whether the way violates those 122 * restrictions. 123 * 124 * @return 0 if the way is not oneway for public transport, 1 if the way is 125 * oneway for public transport, -1 if the way is reversely oneway 126 * for public transport 127 */ 128 public static int isOnewayForPublicTransport(Way way) { 129 130 if (OsmUtils.isTrue(way.get("oneway")) || OsmUtils.isReversed(way.get("oneway")) 131 || way.hasTag("junction", "roundabout") || way.hasTag("highway", "motorway")) { 132 133 if (!way.hasTag("busway", "lane") && !way.hasTag("busway:left", "lane") 134 && !way.hasTag("busway:right", "lane") && !way.hasTag("oneway:bus", "no") 135 && !way.hasTag("busway", "opposite_lane") && !way.hasTag("oneway:psv", "no") 136 && !way.hasTag("trolley_wire", "backward")) { 137 138 if (OsmUtils.isReversed(way.get("oneway"))) { 139 return -1; 140 } 141 142 return 1; 143 144 } 145 146 } 147 148 return 0; 149 } 150 151 public static boolean waysTouch(Way w1, Way w2) { 152 153 if (w1 == null || w2 == null) { 154 return false; 155 } 156 157 Node w1FirstNode = w1.firstNode(); 158 Node w1LastNode = w1.lastNode(); 159 Node w2FirstNode = w2.firstNode(); 160 Node w2LastNode = w2.lastNode(); 161 162 if (w1FirstNode == w2FirstNode || w1FirstNode == w2LastNode || w1LastNode == w2FirstNode 163 || w1LastNode == w2LastNode) { 164 return true; 165 } 166 167 return false; 168 } 169 116 170 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/Checker.java
r32587 r32597 57 57 58 58 if (rm.getMember().hasTag("public_transport", "stop_position")) { 59 //if (!rm.hasRole("stop") && !rm.hasRole("stop_entry_only") && !rm.hasRole("stop_exit_only")) {60 //RelationMember newMember = new RelationMember("stop", rm.getMember());61 //resultList.add(newMember);62 //} else {59 if (!rm.hasRole("stop") && !rm.hasRole("stop_entry_only") && !rm.hasRole("stop_exit_only")) { 60 RelationMember newMember = new RelationMember("stop", rm.getMember()); 61 resultList.add(newMember); 62 } else { 63 63 resultList.add(rm); 64 //}64 } 65 65 } else { // if platform 66 //if (!rm.hasRole("platform") && !rm.hasRole("platform_entry_only")67 //&& !rm.hasRole("platform_exit_only")) {68 //RelationMember newMember = new RelationMember("platform", rm.getMember());69 //resultList.add(newMember);70 //} else {66 if (!rm.hasRole("platform") && !rm.hasRole("platform_entry_only") 67 && !rm.hasRole("platform_exit_only")) { 68 RelationMember newMember = new RelationMember("platform", rm.getMember()); 69 resultList.add(newMember); 70 } else { 71 71 resultList.add(rm); 72 //}72 } 73 73 } 74 74 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32587 r32597 7 7 import java.util.List; 8 8 9 import javax.swing.JOptionPane;10 9 import javax.swing.SwingUtilities; 11 10 … … 16 15 import org.openstreetmap.josm.command.SelectCommand; 17 16 import org.openstreetmap.josm.command.SequenceCommand; 17 import org.openstreetmap.josm.data.osm.Node; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 20 import org.openstreetmap.josm.data.osm.OsmUtils;21 20 import org.openstreetmap.josm.data.osm.Relation; 22 21 import org.openstreetmap.josm.data.osm.RelationMember; … … 25 24 import org.openstreetmap.josm.data.validation.Test; 26 25 import org.openstreetmap.josm.data.validation.TestError; 27 import org.openstreetmap.josm.gui.dialogs.relation. RelationDialogManager;26 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 28 27 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 29 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;30 import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator;31 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 32 29 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; … … 40 37 */ 41 38 public class WayChecker extends Checker { 42 39 43 40 public WayChecker(Relation relation, Test test) { 44 41 … … 143 140 protected void performDirectionTest() { 144 141 145 List< RelationMember> waysToCheck = new ArrayList<>();142 List<Way> waysToCheck = new ArrayList<>(); 146 143 147 144 for (RelationMember rm : relation.getMembers()) { 148 if (RouteUtils.isPTWay(rm) && rm.getType().equals(OsmPrimitiveType.WAY)) { 149 waysToCheck.add(rm); 150 } 151 } 152 153 if (waysToCheck.isEmpty()) { 145 if (RouteUtils.isPTWay(rm)) { 146 if (rm.isWay()) { 147 waysToCheck.add(rm.getWay()); 148 } else { 149 Relation nestedRelation = rm.getRelation(); 150 for (RelationMember nestedRelationMember : nestedRelation.getMembers()) { 151 waysToCheck.add(nestedRelationMember.getWay()); 152 } 153 } 154 } 155 } 156 157 if (waysToCheck.size() <= 1) { 154 158 return; 155 159 } 156 160 157 WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator(); 158 final List<WayConnectionType> links = connectionTypeCalculator.updateLinks(waysToCheck); 159 160 for (int i = 0; i < links.size(); i++) { 161 if ((OsmUtils.isTrue(waysToCheck.get(i).getWay().get("oneway")) 162 && links.get(i).direction.equals(WayConnectionType.Direction.BACKWARD)) 163 || (OsmUtils.isReversed(waysToCheck.get(i).getWay().get("oneway")) 164 && links.get(i).direction.equals(WayConnectionType.Direction.FORWARD))) { 165 166 // At this point, the PTWay is going against the oneway 167 // direction. Check if this road allows buses to disregard 168 // the oneway restriction: 169 170 if (!waysToCheck.get(i).getWay().hasTag("busway", "lane") 171 && !waysToCheck.get(i).getWay().hasTag("busway:left", "lane") 172 && !waysToCheck.get(i).getWay().hasTag("busway:right", "lane") 173 && !waysToCheck.get(i).getWay().hasTag("oneway:bus", "no") 174 && !waysToCheck.get(i).getWay().hasTag("busway", "opposite_lane") 175 && !waysToCheck.get(i).getWay().hasTag("oneway:psv", "no") 176 && !waysToCheck.get(i).getWay().hasTag("trolley_wire", "backward")) { 177 List<Relation> primitives = new ArrayList<>(1); 178 primitives.add(relation); 179 List<Way> highlighted = new ArrayList<>(1); 180 highlighted.add(waysToCheck.get(i).getWay()); 181 TestError e = new TestError(this.test, Severity.WARNING, 182 tr("PT: Route passes a oneway road in the wrong direction"), 183 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted); 184 this.errors.add(e); 185 return; 186 } 187 188 } 161 List<Way> problematicWays = new ArrayList<>(); 162 163 for (int i = 0; i < waysToCheck.size(); i++) { 164 165 Way curr = waysToCheck.get(i); 166 167 if (i == 0) { 168 // first way: 169 Way next = waysToCheck.get(i + 1); 170 if (!touchCorrectly(null, curr, next)) { 171 problematicWays.add(curr); 172 } 173 174 } else if (i == waysToCheck.size() - 1) { 175 // last way: 176 Way prev = waysToCheck.get(i - 1); 177 if (!touchCorrectly(prev, curr, null)) { 178 problematicWays.add(curr); 179 } 180 181 } else { 182 // all other ways: 183 Way prev = waysToCheck.get(i - 1); 184 Way next = waysToCheck.get(i + 1); 185 if (!touchCorrectly(prev, curr, next)) { 186 problematicWays.add(curr); 187 } 188 } 189 } 190 191 for (Way problematicWay : problematicWays) { 192 193 List<Relation> primitives = new ArrayList<>(1); 194 primitives.add(relation); 195 List<Way> highlighted = new ArrayList<>(1); 196 highlighted.add(problematicWay); 197 TestError e = new TestError(this.test, Severity.WARNING, 198 tr("PT: Route passes a oneway road in the wrong direction"), 199 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted); 200 this.errors.add(e); 189 201 } 190 202 … … 283 295 return null; 284 296 } 285 297 286 298 ArrayList<Command> commands = new ArrayList<>(); 287 299 … … 299 311 SelectCommand command2 = new SelectCommand(primitivesToZoom); 300 312 commands.add(command2); 301 // 302 // List<RelationMember> sortedRelationMembers = listStopMembers(originalRelation); 303 // sortedRelationMembers.addAll(listNotStopMembers(originalRelation)); 304 // originalRelation.setMembers(sortedRelationMembers); 305 313 306 314 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); 307 315 for (OsmDataLayer osmDataLayer : listOfLayers) { … … 309 317 310 318 final OsmDataLayer layerParameter = osmDataLayer; 311 // final Relation relationParameter = new Relation(originalRelation);312 // relationParameter.setMembers(sortedRelationMembers);313 319 final Relation relationParameter = originalRelation; 314 320 final Collection<OsmPrimitive> zoomParameter = primitivesToZoom; … … 341 347 private static void showRelationEditorAndZoom(OsmDataLayer layer, Relation r, Collection<OsmPrimitive> primitives) { 342 348 349 // zoom to problem: 343 350 AutoScaleAction.zoomTo(primitives); 344 RelationEditor editor = RelationEditor.getEditor(layer, r, r.getMembersFor(primitives)); 351 352 // create editor: 353 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r, 354 r.getMembersFor(primitives)); 355 356 // put stop-related members to the front and edit roles if necessary: 357 List<RelationMember> sortedRelationMembers = listStopMembers(r); 358 sortedRelationMembers.addAll(listNotStopMembers(r)); 359 r.setMembers(sortedRelationMembers); 360 editor.reloadDataFromRelation(); 361 362 // open editor: 345 363 editor.setVisible(true); 346 347 364 365 } 366 367 /** 368 * Checks if the current way touches its neighbouring was correctly 369 * 370 * @param prev 371 * can be null 372 * @param curr 373 * cannot be null 374 * @param next 375 * can be null 376 * @return 377 */ 378 private boolean touchCorrectly(Way prev, Way curr, Way next) { 379 380 if (RouteUtils.isOnewayForPublicTransport(curr) == 0) { 381 return true; 382 } 383 384 if (prev != null) { 385 386 if (RouteUtils.waysTouch(curr, prev)) { 387 Node nodeInQuestion; 388 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) { 389 nodeInQuestion = curr.firstNode(); 390 } else { 391 nodeInQuestion = curr.lastNode(); 392 } 393 394 if (nodeInQuestion != prev.firstNode() && nodeInQuestion != prev.lastNode()) { 395 return false; 396 } 397 } 398 } 399 400 if (next != null) { 401 402 if (RouteUtils.waysTouch(curr, next)) { 403 Node nodeInQuestion; 404 if (RouteUtils.isOnewayForPublicTransport(curr) == 1) { 405 nodeInQuestion = curr.lastNode(); 406 } else { 407 nodeInQuestion = curr.firstNode(); 408 } 409 410 if (nodeInQuestion != next.firstNode() && nodeInQuestion != next.lastNode()) { 411 return false; 412 } 413 } 414 } 415 416 return true; 348 417 349 418 }
Note:
See TracChangeset
for help on using the changeset viewer.