Changeset 33429 in osm for applications/editors/josm/plugins/pt_assistant
- Timestamp:
- 2017-07-06T13:48:03+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r33417 r33429 123 123 public static void addHighlightedRelation(Relation highlightedRelation) { 124 124 highlightedRelations.add(highlightedRelation); 125 if (!editHighlightedRelationsMenu.isEnabled()) {125 if (!editHighlightedRelationsMenu.isEnabled()) { 126 126 SwingUtilities.invokeLater(() -> 127 127 editHighlightedRelationsMenu.setEnabled(true)); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java
r33417 r33429 57 57 private static Cursor getCursor() { 58 58 Cursor cursor = ImageProvider.getCursor("crosshair", "bus"); 59 if (cursor == null)59 if (cursor == null) 60 60 cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 61 61 return cursor; … … 85 85 86 86 Node n = Main.map.mapView.getNearestNode(e.getPoint(), OsmPrimitive::isUsable); 87 if (n != null) {87 if (n != null) { 88 88 newHighlights.add(n); 89 89 newCurs = cursorJoinNode; … … 92 92 Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive::isSelectable); 93 93 94 if (!wss.isEmpty()) {95 for (WaySegment ws : wss) {94 if (!wss.isEmpty()) { 95 for (WaySegment ws : wss) { 96 96 newHighlights.add(ws.way); 97 97 } … … 124 124 newStopPos.put("public_transport", "stop_position"); 125 125 126 if (newNode) {126 if (newNode) { 127 127 Main.main.undoRedo.add(new AddCommand(newStopPos)); 128 128 } else { … … 134 134 135 135 //join the node to the way only if the node is new 136 if (newNode) {136 if (newNode) { 137 137 JoinNodeWayAction joinNodeWayAction = JoinNodeWayAction.createJoinNodeToWayAction(); 138 138 joinNodeWayAction.actionPerformed(null); … … 145 145 146 146 private void clearNodeTags(Node newStopPos) { 147 for (String key : newStopPos.keySet()) {147 for (String key : newStopPos.keySet()) { 148 148 newStopPos.put(key, null); 149 149 } … … 152 152 153 153 //turn off what has been highlighted on last mouse move and highlight what has to be highlighted now 154 private void updateHighlights() 155 { 156 if(oldHighlights.isEmpty() && newHighlights.isEmpty()) { 154 private void updateHighlights() { 155 if (oldHighlights.isEmpty() && newHighlights.isEmpty()) { 157 156 return; 158 157 } 159 158 160 for (OsmPrimitive osm : oldHighlights) {159 for (OsmPrimitive osm : oldHighlights) { 161 160 osm.setHighlighted(false); 162 161 } 163 162 164 for (OsmPrimitive osm : newHighlights) {163 for (OsmPrimitive osm : newHighlights) { 165 164 osm.setHighlighted(true); 166 165 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/EdgeSelectionAction.java
r33418 r33429 56 56 private List<Way> getEdgeFromWay(Way initial, String modeOfTravel) { 57 57 List<Way> edge = new ArrayList<>(); 58 if (!isWaySuitableForMode(initial, modeOfTravel))58 if (!isWaySuitableForMode(initial, modeOfTravel)) 59 59 return edge; 60 60 61 61 Way curr = initial; 62 while (true) {62 while (true) { 63 63 List<Way> options = curr.firstNode(true).getParentWays(); 64 64 options.remove(curr); 65 65 curr = chooseBestWay(options, modeOfTravel); 66 if (curr == null || edge.contains(curr))66 if (curr == null || edge.contains(curr)) 67 67 break; 68 68 edge.add(curr); … … 70 70 71 71 curr = initial; 72 while (true) {72 while (true) { 73 73 List<Way> options = curr.lastNode(true).getParentWays(); 74 74 options.remove(curr); 75 75 curr = chooseBestWay(options, modeOfTravel); 76 if (curr == null || edge.contains(curr))76 if (curr == null || edge.contains(curr)) 77 77 break; 78 78 edge.add(curr); … … 84 84 85 85 private Boolean isWaySuitableForMode(Way toCheck, String modeOfTravel) { 86 if ("bus".equals(modeOfTravel))86 if ("bus".equals(modeOfTravel)) 87 87 return RouteUtils.isWaySuitableForBuses(toCheck); 88 88 … … 95 95 private Way chooseBestWay(List<Way> ways, String modeOfTravel) { 96 96 ways.removeIf(w -> !isWaySuitableForMode(w, modeOfTravel)); 97 if (ways.isEmpty())97 if (ways.isEmpty()) 98 98 return null; 99 if (ways.size() == 1)99 if (ways.size() == 1) 100 100 return ways.get(0); 101 101 102 102 Way theChoosenOne = null; 103 103 104 if("bus".equals(modeOfTravel)) 105 { 104 if ("bus".equals(modeOfTravel)) { 106 105 107 106 } 108 if("tram".equals(modeOfTravel)) 109 { 107 if ("tram".equals(modeOfTravel)) { 110 108 111 109 } … … 125 123 DataSet ds = Main.getLayerManager().getEditLayer().data; 126 124 Way initial = Main.map.mapView.getNearestWay(e.getPoint(), OsmPrimitive::isUsable); 127 if (initial != null){125 if (initial != null) { 128 126 ds.setSelected(getEdgeFromWay(initial, getModeOfTravel())); 129 } 130 else 127 } else 131 128 ds.clearSelection(); 132 129 } … … 136 133 super.mouseMoved(e); 137 134 138 for (Way way : highlighted)135 for (Way way : highlighted) { 139 136 way.setHighlighted(false); 137 } 140 138 highlighted.clear(); 141 139 142 140 Way initial = Main.map.mapView.getNearestWay(e.getPoint(), OsmPrimitive::isUsable); 143 if (initial == null) {141 if (initial == null) { 144 142 Main.map.mapView.setCursor(selectionCursor); 145 } 146 else { 143 } else { 147 144 Main.map.mapView.setCursor(waySelectCursor); 148 145 highlighted.addAll(getEdgeFromWay(initial, getModeOfTravel())); 149 146 } 150 147 151 for (Way way : highlighted)148 for (Way way : highlighted) { 152 149 way.setHighlighted(true); 150 } 153 151 } 154 152 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/EditHighlightedRelationsAction.java
r33417 r33429 39 39 @Override 40 40 public void actionPerformed(ActionEvent e) { 41 for (Relation relation : PTAssistantPlugin.getHighlightedRelations()) {41 for (Relation relation : PTAssistantPlugin.getHighlightedRelations()) { 42 42 RelationEditor editor = RelationEditor.getEditor( 43 43 Main.getLayerManager().getEditLayer(), relation, null); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java
r33427 r33429 93 93 private void continueAfterDownload(Way roundabout) { 94 94 //make the roundabout round, if requested 95 if (Main.pref.getBoolean("pt_assistant.roundabout-splitter.alignalways") ||95 if (Main.pref.getBoolean("pt_assistant.roundabout-splitter.alignalways") || 96 96 JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(Main.parent, 97 97 tr("Do you want to make the roundabout round?"), tr("Roundabout round"), … … 123 123 List<Relation> parents = getPTRouteParents(roundabout); 124 124 parents.removeIf(r -> !r.hasIncompleteMembers()); 125 if (parents.isEmpty()) {125 if (parents.isEmpty()) { 126 126 continueAfterDownload(roundabout); 127 127 return; 128 128 } 129 129 130 Future <?>future = Main.worker.submit(new DownloadRelationMemberTask(130 Future<?> future = Main.worker.submit(new DownloadRelationMemberTask( 131 131 parents, 132 132 DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(parents), … … 166 166 positions.forEach(i -> { 167 167 168 if (!changingRelation.containsKey(r))168 if (!changingRelation.containsKey(r)) 169 169 changingRelation.put(r, new Relation(r)); 170 170 171 171 Relation c = changingRelation.get(r); 172 172 173 if (!memberOffset.containsKey(r))173 if (!memberOffset.containsKey(r)) 174 174 memberOffset.put(r, 0); 175 175 int offset = memberOffset.get(r); 176 176 177 Pair<Way, Way> entryExitWays = getEntryExitWays(c, i + offset);177 Pair<Way, Way> entryExitWays = getEntryExitWays(c, i + offset); 178 178 Way entryWay = entryExitWays.a; 179 179 Way exitWay = entryExitWays.b; 180 180 181 if (entryWay == null || exitWay == null)181 if (entryWay == null || exitWay == null) 182 182 return; 183 183 … … 186 186 Node exitNode = getNodeInCommon(splitNodes, exitWay); 187 187 188 if (entryNode == null || exitNode == null)188 if (entryNode == null || exitNode == null) 189 189 return; 190 190 … … 197 197 Way curr = parents.get(0); 198 198 199 while (!curr.lastNode().equals(exitNode)) {199 while (!curr.lastNode().equals(exitNode)) { 200 200 c.addMember(i + offset++, new RelationMember(null, curr)); 201 201 parents = curr.lastNode().getParentWays(); … … 211 211 212 212 private Node getNodeInCommon(List<Node> nodes, Way way) { 213 if (nodes.contains(way.lastNode()))213 if (nodes.contains(way.lastNode())) 214 214 return way.lastNode(); 215 else if (nodes.contains(way.firstNode()))215 else if (nodes.contains(way.firstNode())) 216 216 return way.firstNode(); 217 217 … … 227 227 228 228 RelationMember before = r.getMember(position-1); 229 if (before.isWay())229 if (before.isWay()) 230 230 ret.a = before.getWay(); 231 231 232 232 RelationMember after = r.getMember(position); 233 if (after.isWay())233 if (after.isWay()) 234 234 ret.b = after.getWay(); 235 235 … … 245 245 splitNodes.removeIf(n -> { 246 246 List<Way> parents = n.getParentWays(); 247 if (parents.size() == 1)247 if (parents.size() == 1) 248 248 return true; 249 249 parents.remove(roundabout); 250 for (Way parent: parents) {251 if (!getRouteParents(parent).isEmpty()) {250 for (Way parent: parents) { 251 if (!getRouteParents(parent).isEmpty()) { 252 252 return false; 253 253 } … … 276 276 Map<Relation, List<Integer>> savedPositions = new HashMap<>(); 277 277 278 for (Relation curr : getPTRouteParents(roundabout)) {279 for (int j = 0; j < curr.getMembersCount(); j++) {280 if (curr.getMember(j).getUniqueId() == roundabout.getUniqueId()) {281 if (!savedPositions.containsKey(curr))278 for (Relation curr : getPTRouteParents(roundabout)) { 279 for (int j = 0; j < curr.getMembersCount(); j++) { 280 if (curr.getMember(j).getUniqueId() == roundabout.getUniqueId()) { 281 if (!savedPositions.containsKey(curr)) 282 282 savedPositions.put(curr, new ArrayList<>()); 283 283 List<Integer> positions = savedPositions.get(curr); … … 291 291 292 292 private List<Relation> getPTRouteParents(Way roundabout) { 293 List 293 List<Relation> referrers = OsmPrimitive.getFilteredList( 294 294 roundabout.getReferrers(), Relation.class); 295 295 referrers.removeIf(r -> !RouteUtils.isPTRoute(r)); … … 298 298 299 299 private List<Relation> getRouteParents(Way roundabout) { 300 List 300 List<Relation> referrers = OsmPrimitive.getFilteredList( 301 301 roundabout.getReferrers(), Relation.class); 302 302 referrers.removeIf(r -> !RouteUtils.isRoute(r)); … … 311 311 return; 312 312 OsmPrimitive selected = selection.iterator().next(); 313 if (selected.getType() != OsmPrimitiveType.WAY)313 if (selected.getType() != OsmPrimitiveType.WAY) 314 314 return; 315 if (((Way)selected).isClosed()315 if (((Way) selected).isClosed() 316 316 && (selected.hasTag("junction", "roundabout") 317 317 || selected.hasTag("oneway", "yes"))) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteSegment.java
r33417 r33429 187 187 public boolean equalsRouteSegment(PTRouteSegment other) { 188 188 189 // if(!firstStop.equalsStop(firstStop) || !lastStop.equalsStop(other.lastStop))190 // return false;191 192 189 List<Way> thisWays = new ArrayList<>(); 193 190 for (PTWay ptway : this.ptways) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r33418 r33429 126 126 } 127 127 128 public void setPrimitives(List<OsmPrimitive> primitives) 129 { 128 public void setPrimitives(List<OsmPrimitive> primitives) { 130 129 this.primitives.clear(); 131 130 this.primitives.addAll(primitives); … … 267 266 event.scheduleRemoval(Collections.singleton(this)); 268 267 269 if (event.getRemovedLayer() == this) {268 if (event.getRemovedLayer() == this) { 270 269 PTAssistantLayerManager.PTLM.resetLayer(); 271 270 PTAssistantPlugin.clearHighlightedRelations(); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayerManager.java
r33418 r33429 46 46 getLayer().setPrimitives(routes); 47 47 PTAssistantPlugin.clearHighlightedRelations(); 48 for (OsmPrimitive primitive : routes)48 for (OsmPrimitive primitive : routes) { 49 49 PTAssistantPlugin.addHighlightedRelation((Relation) primitive); 50 } 50 51 } 51 52 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r33417 r33429 67 67 } else if (rm.isRelation()) { 68 68 visit(rm.getRelation()); 69 } //else { 70 // if the relation has members that do not fit with the 71 // PT_Assistant data model, do nothing 72 //} 73 } //else { 74 // if the relation has members that do not fit with the 75 // PT_Assistant data model, do nothing 76 //} 69 } 70 } 77 71 } 78 72 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r33427 r33429 19 19 public final class RouteUtils { 20 20 21 private final staticString ptVersionTag = "public_transport:version";21 private static final String ptVersionTag = "public_transport:version"; 22 22 private RouteUtils() { 23 23 // private constructor for util classes … … 35 35 public static boolean isVersionTwoPTRoute(Relation r) { 36 36 37 if (!isPTRoute(r)) {37 if (!isPTRoute(r)) { 38 38 return false; 39 39 } … … 48 48 public static boolean isVersionOnePTRoute(Relation r) { 49 49 50 if (!isPTRoute(r)) {51 return false; 52 } 53 54 if (r.get(ptVersionTag) == null) {50 if (!isPTRoute(r)) { 51 return false; 52 } 53 54 if (r.get(ptVersionTag) == null) { 55 55 return true; 56 56 } … … 227 227 "tertiary_link", "living_street", "bus_guideway", "road"}; 228 228 229 if (way.hasTag("highway", acceptedHighwayTags)229 if (way.hasTag("highway", acceptedHighwayTags) 230 230 || way.hasTag("cycleway", "share_busway") 231 231 || way.hasTag("cycleway", "shared_lane")) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java
r33417 r33429 73 73 Way referringWay = (Way) referrer; 74 74 if (RouteUtils.isWaySuitableForPublicTransport(referringWay)) { 75 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY); 75 Builder builder = TestError.builder(this.test, Severity.WARNING, 76 PTAssistantValidatorTest.ERROR_CODE_PLATFORM_PART_OF_HIGHWAY); 76 77 builder.message(tr("PT: Platform should not be part of a way")); 77 78 builder.primitives(primitives); … … 120 121 Node problematicNode = (Node) testError.getPrimitives().iterator().next(); 121 122 122 final int[] userSelection = { JOptionPane.YES_OPTION }; 123 final int[] userSelection = { 124 JOptionPane.YES_OPTION }; 123 125 final TestError errorParameter = testError; 124 126 if (SwingUtilities.isEventDispatchThread()) { … … 167 169 AutoScaleAction.zoomTo(primitives); 168 170 169 String[] options = { tr("Yes"), tr("No") }; 171 String[] options = { 172 tr("Yes"), tr("No") }; 170 173 String message; 171 174 if (e.getCode() == PTAssistantValidatorTest.ERROR_CODE_SOLITARY_STOP_POSITION) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r33428 r33429 347 347 348 348 //At this point, there are 3 variants: 349 if (routeCheckerErrors.isEmpty()) {349 if (routeCheckerErrors.isEmpty()) { 350 350 if (!routeChecker.getHasGap()) { 351 351 //There are no errors => route is correct -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java
r33418 r33429 74 74 TestError e = builder.build(); 75 75 this.errors.add(e); 76 } else if (numOfGapsAfterSort < numOfGaps) {76 } else if (numOfGapsAfterSort < numOfGaps) { 77 77 Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_PARTIAL_SORTING); 78 78 builder.message(tr("PT: Route gaps can decrease by sorting members. Further validations will be required")); … … 100 100 for (int i = 0; i < links.size(); i++) { 101 101 final WayConnectionType link = links.get(i); 102 if (!(i == 0 || link.linkPrev)102 if (!(i == 0 || link.linkPrev) 103 103 || !(i == links.size() - 1 104 104 || link.linkNext) -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r33425 r33429 871 871 final Collection<OsmPrimitive> waysToZoom = new ArrayList<>(); 872 872 873 for (List<PTWay> variants : fixVariants) 874 for (PTWay variant : variants)873 for (List<PTWay> variants : fixVariants) { 874 for (PTWay variant : variants) { 875 875 waysToZoom.add(variant.getWay()); 876 } 877 } 876 878 877 879 if (SwingUtilities.isEventDispatchThread()) { -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutTest.java
r33417 r33429 92 92 assertEquals(4, sw2.size()); 93 93 sw2.forEach(w -> { 94 if (w.firstNode().getUniqueId() == 2158181809L && w.lastNode().getUniqueId() == 2158181798L)94 if (w.firstNode().getUniqueId() == 2158181809L && w.lastNode().getUniqueId() == 2158181798L) 95 95 assertEquals(8, w.getReferrers().size()); 96 96 else if (w.firstNode().getUniqueId() == 2158181798L && w.lastNode().getUniqueId() == 2158181789L) … … 110 110 assertEquals(4, sw3.size()); 111 111 sw3.forEach(w -> { 112 if (w.firstNode().getUniqueId() == 280697532L && w.lastNode().getUniqueId() == 280697452L)112 if (w.firstNode().getUniqueId() == 280697532L && w.lastNode().getUniqueId() == 280697452L) 113 113 assertEquals(0, w.getReferrers().size()); 114 114 else if (w.firstNode().getUniqueId() == 280697452L && w.lastNode().getUniqueId() == 280697591L) … … 139 139 140 140 sw4.forEach(w -> { 141 if (w.firstNode().equals(entry11) && w.lastNode().equals(exit22))141 if (w.firstNode().equals(entry11) && w.lastNode().equals(exit22)) 142 142 assertEquals(2, w.getReferrers().size()); 143 else if (w.firstNode().equals(exit22) && w.lastNode().equals(entry21))143 else if (w.firstNode().equals(exit22) && w.lastNode().equals(entry21)) 144 144 assertEquals(1, w.getReferrers().size()); 145 else if (w.firstNode().equals(entry21) && w.lastNode().equals(exit11))145 else if (w.firstNode().equals(entry21) && w.lastNode().equals(exit11)) 146 146 assertEquals(2, w.getReferrers().size()); 147 else if (w.firstNode().equals(exit11) && w.lastNode().equals(entry12))147 else if (w.firstNode().equals(exit11) && w.lastNode().equals(entry12)) 148 148 assertEquals(1, w.getReferrers().size()); 149 else if (w.firstNode().equals(entry12) && w.lastNode().equals(entry3))149 else if (w.firstNode().equals(entry12) && w.lastNode().equals(entry3)) 150 150 assertEquals(2, w.getReferrers().size()); 151 else if (w.firstNode().equals(entry3) && w.lastNode().equals(exit21))151 else if (w.firstNode().equals(entry3) && w.lastNode().equals(exit21)) 152 152 assertEquals(3, w.getReferrers().size()); 153 else if (w.firstNode().equals(exit21) && w.lastNode().equals(entry22))153 else if (w.firstNode().equals(exit21) && w.lastNode().equals(entry22)) 154 154 assertEquals(2, w.getReferrers().size()); 155 else if (w.firstNode().equals(entry22) && w.lastNode().equals(exit3))155 else if (w.firstNode().equals(entry22) && w.lastNode().equals(exit3)) 156 156 assertEquals(3, w.getReferrers().size()); 157 else if (w.firstNode().equals(exit3) && w.lastNode().equals(exit12))157 else if (w.firstNode().equals(exit3) && w.lastNode().equals(exit12)) 158 158 assertEquals(2, w.getReferrers().size()); 159 else if (w.firstNode().equals(exit12) && w.lastNode().equals(entry11))159 else if (w.firstNode().equals(exit12) && w.lastNode().equals(entry11)) 160 160 assertEquals(1, w.getReferrers().size()); 161 161 else -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/data/StopToWayAssignerTest.java
r33055 r33429 35 35 // test with a [correct] stop_position: 36 36 PTStop ptstop1 = manager.getPTStop(447358573L); 37 // PTWay ptway1 = assigner.get(ptstop1);38 // Way way1 = ptway1.getWays().get(0);39 37 Way way1 = assigner.get(ptstop1); 40 38 assertEquals(way1.getId(), 26956744L); -
applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentCheckerTest.java
r33428 r33429 17 17 @Test 18 18 public void test() { 19 20 21 19 File file = new File(AbstractTest.PATH_TO_SEGMENT_TEST); 22 20 DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
Note:
See TracChangeset
for help on using the changeset viewer.