Changeset 33415 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2017-06-28T14:42:16+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java
r33414 r33415 24 24 import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult; 25 25 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 26 import org.openstreetmap.josm.command.ChangeCommand; 27 import org.openstreetmap.josm.command.Command; 28 import org.openstreetmap.josm.command.SequenceCommand; 26 29 import org.openstreetmap.josm.data.Bounds; 27 30 import org.openstreetmap.josm.data.osm.BBox; … … 47 50 public class SplitRoundaboutAction extends JosmAction { 48 51 49 private static final String actionName= "Split Roundabout";52 private static final String ACTION_NAME = "Split Roundabout"; 50 53 private static final long serialVersionUID = 8912249304286025356L; 51 54 … … 54 57 */ 55 58 public SplitRoundaboutAction() { 56 super( actionName, "icons/splitroundabout",actionName, null, true);59 super(ACTION_NAME, "icons/splitroundabout", ACTION_NAME, null, true); 57 60 } 58 61 … … 99 102 Map<Relation, List<Integer>> savedPositions = getSavedPositions(roundabout); 100 103 104 //remove the roundabout from each relation 105 Main.main.undoRedo.add(getRemoveRoundaboutFromRelationsCommand(roundabout)); 106 101 107 //split the roundabout on the designed nodes 102 108 List<Node> splitNodes = getSplitNodes(roundabout); 103 109 SplitWayResult result = SplitWayAction.split(getLayerManager().getEditLayer(), 104 110 roundabout, splitNodes, Collections.emptyList()); 105 result.getCommand() .executeCommand();111 Main.main.undoRedo.add(result.getCommand()); 106 112 Collection<Way> splitWays = result.getNewWays(); 107 113 splitWays.add(result.getOriginalWay()); 108 114 109 115 //update the relations. 110 updateRelations(savedPositions, splitNodes, splitWays); 111 } 112 113 public void updateRelations(Map<Relation, List<Integer>> savedPositions, 116 Main.main.undoRedo.add(getUpdateRelationsCommand(savedPositions, splitNodes, splitWays)); 117 } 118 119 public Command getUpdateRelationsCommand(Map<Relation, 120 List<Integer>> savedPositions, 114 121 List<Node> splitNodes, Collection<Way> splitWays) { 122 123 Map<Relation, Relation> changingRelations = 124 updateRelations(savedPositions, splitNodes, splitWays); 125 126 List<Command> commands = new ArrayList<>(); 127 changingRelations.forEach((oldR, newR) -> 128 commands.add(new ChangeCommand(oldR, newR))); 129 130 return new SequenceCommand("Updating Relations for SplitRoundabout", commands); 131 } 132 133 private Map<Relation, Relation> updateRelations(Map<Relation, 134 List<Integer>> savedPositions, 135 List<Node> splitNodes, Collection<Way> splitWays) { 136 Map<Relation, Relation> changingRelation = new HashMap<>(); 115 137 Map<Relation, Integer> memberOffset = new HashMap<>(); 116 138 savedPositions.forEach((r, positions) -> 117 139 positions.forEach(i -> { 118 140 141 if(!changingRelation.containsKey(r)) 142 changingRelation.put(r, new Relation(r)); 143 144 Relation c = changingRelation.get(r); 145 119 146 if(!memberOffset.containsKey(r)) 120 147 memberOffset.put(r, 0); 121 148 int offset = memberOffset.get(r); 122 149 123 Pair<Way, Way> entryExitWays= getEntryExitWays( r, i + offset);150 Pair<Way, Way> entryExitWays= getEntryExitWays(c, i + offset); 124 151 Way entryWay = entryExitWays.a; 125 152 Way exitWay = entryExitWays.b; … … 141 168 142 169 while(!curr.lastNode().equals(exitNode)) { 143 r.addMember(i + offset++, new RelationMember(null, curr));170 c.addMember(i + offset++, new RelationMember(null, curr)); 144 171 parents = curr.lastNode().getParentWays(); 145 172 parents.remove(curr); … … 147 174 curr = parents.get(0); 148 175 } 149 r.addMember(i + offset++, new RelationMember(null, curr));176 c.addMember(i + offset++, new RelationMember(null, curr)); 150 177 memberOffset.put(r, offset); 151 178 })); 179 return changingRelation; 152 180 } 153 181 … … 184 212 parents.remove(roundabout); 185 213 for(Way parent: parents) { 186 for(OsmPrimitive prim : parent.getReferrers()) {187 if(prim.getType() == OsmPrimitiveType.RELATION &&188 RouteUtils.isPTRoute((Relation) prim))214 for(Relation r : OsmPrimitive.getFilteredList( 215 parent.getReferrers(), Relation.class)) { 216 if(RouteUtils.isPTRoute(r)) 189 217 return false; 190 218 } … … 196 224 } 197 225 226 public Command getRemoveRoundaboutFromRelationsCommand(Way roundabout) { 227 List <Relation> referrers = OsmPrimitive.getFilteredList( 228 roundabout.getReferrers(), Relation.class); 229 referrers.removeIf(r -> !RouteUtils.isPTRoute(r)); 230 231 List<Command> commands = new ArrayList<>(); 232 referrers.forEach(r -> { 233 Relation c = new Relation(r); 234 c.removeMembersFor(roundabout); 235 commands.add(new ChangeCommand(r, c)); 236 }); 237 238 return new SequenceCommand("Remove roundabout from relations", commands); 239 } 240 198 241 //save the position of the roundabout inside each public transport route 199 242 //it is contained in … … 201 244 202 245 Map<Relation, List<Integer>> savedPositions = new HashMap<>(); 203 List <OsmPrimitive> referrers = roundabout.getReferrers(); 204 referrers.removeIf(r -> r.getType() != OsmPrimitiveType.RELATION 205 || !RouteUtils.isPTRoute((Relation) r)); 206 207 for(OsmPrimitive currPrim : referrers) { 208 Relation curr = (Relation) currPrim; 246 List <Relation> referrers = OsmPrimitive.getFilteredList( 247 roundabout.getReferrers(), Relation.class); 248 referrers.removeIf(r -> !RouteUtils.isPTRoute(r)); 249 250 for(Relation curr : referrers) { 209 251 for(int j = 0; j < curr.getMembersCount(); j++) { 210 252 if(curr.getMember(j).getUniqueId() == roundabout.getUniqueId()) { … … 215 257 } 216 258 } 217 218 if(savedPositions.containsKey(curr))219 curr.removeMembersFor(roundabout);220 259 } 221 260
Note:
See TracChangeset
for help on using the changeset viewer.
