Changeset 32647 in osm for applications
- Timestamp:
- 2016-07-13T02:49:03+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32597 r32647 38 38 implements SelectionChangedListener, PropertyChangeListener, LayerChangeListener { 39 39 40 private static PTAssistantLayer layer; 40 41 private List<OsmPrimitive> primitives = new ArrayList<>(); 41 42 private PTAssistantPaintVisitor paintVisitor; 42 43 p ublicPTAssistantLayer() {43 44 private PTAssistantLayer() { 44 45 super("pt_assistant layer"); 45 46 KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this); 46 47 Main.getLayerManager().addLayerChangeListener(this); 47 48 layer = this; 49 50 } 51 52 public static PTAssistantLayer getLayer() { 53 if (layer == null) { 54 new PTAssistantLayer(); 55 } 56 return layer; 48 57 } 49 58 … … 159 168 160 169 if (RouteUtils.isTwoDirectionRoute(relation)) { 161 162 this.primitives.clear(); 163 this.primitives.add(relation); 164 if (!Main.getLayerManager().containsLayer(this)) { 165 Main.getLayerManager().addLayer(this); 166 } 167 168 if (paintVisitor == null) { 169 Graphics g = Main.map.mapView.getGraphics(); 170 MapView mv = Main.map.mapView; 171 paintVisitor = new PTAssistantPaintVisitor(g, mv); 172 } 173 174 for (OsmPrimitive primitive : primitives) { 175 paintVisitor.visit(primitive); 176 } 177 178 Main.map.mapView.repaint(); 170 171 this.repaint(relation); 172 179 173 } 180 174 … … 182 176 } 183 177 } 184 178 179 180 181 /** 182 * Repaints the layer in cases when there was no selection change 183 * @param relation 184 */ 185 public void repaint(Relation relation) { 186 this.primitives.clear(); 187 this.primitives.add(relation); 188 if (!Main.getLayerManager().containsLayer(this)) { 189 Main.getLayerManager().addLayer(this); 190 } 191 192 if (paintVisitor == null) { 193 Graphics g = Main.map.mapView.getGraphics(); 194 MapView mv = Main.map.mapView; 195 paintVisitor = new PTAssistantPaintVisitor(g, mv); 196 } 197 198 for (OsmPrimitive primitive : primitives) { 199 paintVisitor.visit(primitive); 200 } 201 202 Main.map.mapView.repaint(); 203 } 204 205 185 206 @Override 186 207 public void layerAdded(LayerAddEvent arg0) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32632 r32647 1 1 package org.openstreetmap.josm.plugins.pt_assistant.utils; 2 3 import java.util.Collection; 2 4 3 5 import org.openstreetmap.josm.data.osm.Node; … … 30 32 */ 31 33 public static boolean isTwoDirectionRoute(Relation r) { 32 34 33 35 if (r == null) { 34 36 return false; 35 37 } 36 38 37 39 if (!r.hasKey("route") || !r.hasTag("public_transport:version", "2")) { 38 40 return false; … … 156 158 /** 157 159 * Checks if the ways have a common node 160 * 158 161 * @param w1 159 162 * @param w2 … … 178 181 return false; 179 182 } 180 183 184 /** 185 * Checks if any way from the first collection touches any way from the 186 * second collection 187 * 188 * @param c1 first collection 189 * @param c2 second collection 190 * @return true if ways touch, false otherwise 191 */ 192 public static boolean waysTouch(Collection<Way> c1, Collection<Way> c2) { 193 194 if (c1 == null || c2 == null) { 195 return false; 196 } 197 198 for (Way w1 : c1) { 199 for (Way w2 : c2) { 200 if (waysTouch(w1, w2)) { 201 return true; 202 } 203 } 204 } 205 206 return false; 207 } 208 181 209 /** 182 210 * Checks if the type of the way is suitable for buses to go on it. The … … 207 235 return false; 208 236 } 209 237 210 238 public static boolean isWaySuitableForPublicTransport(Way way) { 211 212 if (isWaySuitableForBuses(way) || way.hasTag("railway", "tram") 213 || way.hasTag("railway", "subway") || way.hasTag("raiilway", "subway") 214 || way.hasTag("railway", "light_rail") 239 240 if (isWaySuitableForBuses(way) || way.hasTag("railway", "tram") || way.hasTag("railway", "subway") 241 || way.hasTag("raiilway", "subway") || way.hasTag("railway", "light_rail") 215 242 || way.hasTag("railway", "train")) { 216 243 return true; 217 244 } 218 219 return false; 220 245 246 return false; 247 221 248 } 222 249 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java
r32622 r32647 73 73 } 74 74 } 75 76 public static void fixError() { 77 78 } 75 79 76 80 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32632 r32647 44 44 tr("Check if route relations are compatible with public transport version 2")); 45 45 46 layer = new PTAssistantLayer();46 layer = PTAssistantLayer.getLayer(); 47 47 DataSet.addSelectionListener(layer); 48 48 … … 333 333 if (testError.getCode() == ERROR_CODE_DIRECTION) { 334 334 commands.add(WayChecker.fixErrorByZooming(testError)); 335 335 336 336 } 337 337 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32622 r32647 16 16 import org.openstreetmap.josm.command.Command; 17 17 import org.openstreetmap.josm.command.SelectCommand; 18 import org.openstreetmap.josm.command.SequenceCommand;19 18 import org.openstreetmap.josm.data.osm.Node; 20 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 29 28 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 30 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.plugins.pt_assistant.gui.PTAssistantLayer; 31 31 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 32 32 … … 194 194 } 195 195 196 List<Relation> primitives = new ArrayList<>(1); 197 primitives.add(this.relation); 198 199 List<Set<Way>> listOfSets = new ArrayList<>(); 196 200 for (Way problematicWay : problematicWays) { 197 198 List<Relation> primitives = new ArrayList<>(1); 199 primitives.add(relation); 200 List<Way> highlighted = new ArrayList<>(1); 201 // highlighted.add(problematicWay); 202 Set<Way> adjacentWays = checkAdjacentWays(problematicWay, new HashSet<Way>()); 203 adjacentWays.removeAll(problematicWays); 204 highlighted.add(problematicWay); 205 highlighted.addAll(adjacentWays); 201 Set<Way> primitivesToReport = new HashSet<>(); 202 primitivesToReport.add(problematicWay); 203 primitivesToReport.addAll(checkAdjacentWays(problematicWay, new HashSet<Way>())); 204 listOfSets.add(primitivesToReport); 205 } 206 207 boolean changed = true; 208 while (changed) { 209 changed = false; 210 for (int i = 0; i < listOfSets.size(); i++) { 211 for (int j = i; j < listOfSets.size(); j++) { 212 if (i != j && RouteUtils.waysTouch(listOfSets.get(i), listOfSets.get(j))) { 213 listOfSets.get(i).addAll(listOfSets.get(j)); 214 listOfSets.remove(j); 215 j = listOfSets.size(); 216 changed = true; 217 } 218 } 219 } 220 } 221 222 for (Set<Way> currentSet : listOfSets) { 206 223 TestError e = new TestError(this.test, Severity.WARNING, 207 224 tr("PT: Route passes a oneway road in the wrong direction"), 208 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted);225 PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, currentSet); 209 226 this.errors.add(e); 210 227 } 211 228 212 // Set<Way> primitivesToReport = new HashSet<>();213 // primitivesToReport.addAll(problematicWays);214 // for (Way problematicWay : problematicWays) {215 // Set<Way> adjacentWays = checkAdjacentWays(problematicWay, new HashSet<Way>());216 // primitivesToReport.addAll(adjacentWays);217 // }218 //219 // List<Relation> primitives = new ArrayList<>(1);220 // primitives.add(relation);221 // TestError e = new TestError(this.test, Severity.WARNING,222 // tr("PT: Route passes a oneway road in the wrong direction"),223 // PTAssistantValidatorTest.ERROR_CODE_DIRECTION, primitives, primitivesToReport);224 // this.errors.add(e);225 226 229 } 227 230 228 231 /** 229 * Checks if the current way touches its neighbo uring was correctly232 * Checks if the current way touches its neighboring was correctly 230 233 * 231 234 * @param prev … … 454 457 } 455 458 456 ArrayList<Command> commands = new ArrayList<>();457 458 459 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 459 460 Relation originalRelation = (Relation) primitives.iterator().next(); 460 ArrayList<OsmPrimitive> primitivesToSelect = new ArrayList<>(1); 461 primitivesToSelect.add(originalRelation); 462 Collection<?> highlighted = testError.getHighlighted(); 463 Way wayToHighlight = (Way) highlighted.iterator().next(); 464 ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>(1); 465 primitivesToZoom.add(wayToHighlight); 466 467 SelectCommand command1 = new SelectCommand(primitivesToSelect); 468 commands.add(command1); 469 SelectCommand command2 = new SelectCommand(primitivesToZoom); 470 commands.add(command2); 461 ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>(); 462 for (Object primitiveToZoom : testError.getHighlighted()) { 463 primitivesToZoom.add((OsmPrimitive) primitiveToZoom); 464 } 465 466 SelectCommand command = new SelectCommand(primitivesToZoom); 471 467 472 468 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class); … … 495 491 } 496 492 497 return new SequenceCommand(null, commands);493 return command; 498 494 } 499 495 } … … 507 503 // zoom to problem: 508 504 AutoScaleAction.zoomTo(primitives); 509 510 // create editor:511 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r,512 r.getMembersFor(primitives));513 505 514 506 // put stop-related members to the front and edit roles if necessary: … … 516 508 sortedRelationMembers.addAll(listNotStopMembers(r)); 517 509 r.setMembers(sortedRelationMembers); 518 editor.reloadDataFromRelation(); 510 511 // create editor: 512 GenericRelationEditor editor = (GenericRelationEditor) RelationEditor.getEditor(layer, r, 513 r.getMembersFor(primitives)); 519 514 520 515 // open editor: 521 516 editor.setVisible(true); 517 editor.setFocusable(true); 518 editor.requestFocusInWindow(); 519 520 // make the current relation purple in the pt_assistant layer: 521 PTAssistantLayer.getLayer().repaint(r); 522 522 523 523 } -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/DirecionTestTest.java
r32616 r32647 6 6 import java.io.File; 7 7 import java.util.ArrayList; 8 import java.util.Collection; 8 9 import java.util.List; 9 10 … … 44 45 assertEquals(onewayErrorCaught, 2); 45 46 46 // fix the direction errors:47 48 47 boolean detectedErrorsAreCorrect = true; 49 48 for (TestError e : errors) { 50 49 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_DIRECTION) { 51 50 @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; 51 Collection<OsmPrimitive> highlighted = (Collection<OsmPrimitive>) e.getHighlighted(); 52 for (OsmPrimitive highlightedPrimitive: highlighted) { 53 if (highlightedPrimitive.getId() != 225732678 && highlightedPrimitive.getId() != 24215210) { 54 detectedErrorsAreCorrect = false; 55 } 55 56 } 56 57 }
Note:
See TracChangeset
for help on using the changeset viewer.