Changeset 33461 in osm
- Timestamp:
- 2017-07-19T00:15:47+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/PTAssistantPlugin.java
r33459 r33461 18 18 import org.openstreetmap.josm.plugins.PluginInformation; 19 19 import org.openstreetmap.josm.plugins.pt_assistant.actions.AddStopPositionAction; 20 import org.openstreetmap.josm.plugins.pt_assistant.actions.CreatePlatformNodeAction; 20 21 import org.openstreetmap.josm.plugins.pt_assistant.actions.EdgeSelectionAction; 21 22 import org.openstreetmap.josm.plugins.pt_assistant.actions.EditHighlightedRelationsAction; … … 68 69 MainMenu.add(Main.main.menu.toolsMenu, new SplitRoundaboutAction()); 69 70 MainMenu.add(Main.main.menu.toolsMenu, new SortPTStopsAction()); 71 MainMenu.add(Main.main.menu.toolsMenu, new CreatePlatformNodeAction()); 70 72 } 71 73 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/CreatePlatformNodeAction.java
r33459 r33461 4 4 5 5 import java.awt.event.ActionEvent; 6 import java.util.ArrayList; 6 7 import java.util.Collection; 7 import java.util. HashMap;8 import java.util.Collections; 8 9 import java.util.List; 9 import java.util.Map;10 10 import java.util.Map.Entry; 11 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.actions.JosmAction; 14 import org.openstreetmap.josm.command.AddCommand; 15 import org.openstreetmap.josm.command.Command; 16 import org.openstreetmap.josm.command.DeleteCommand; 17 import org.openstreetmap.josm.command.SequenceCommand; 13 18 import org.openstreetmap.josm.data.osm.Node; 14 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 20 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 import org.openstreetmap.josm.data.osm. Relation;21 import org.openstreetmap.josm.data.osm.TagCollection; 17 22 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 23 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 24 import org.openstreetmap.josm.tools.UserCancelException; 19 25 20 26 /** … … 27 33 28 34 private static final String ACTION_NAME = "Transfer details of stop to platform node"; 35 36 private Node dummy1; 37 private Node dummy2; 38 private Node dummy3; 29 39 30 40 /** … … 39 49 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 40 50 Node platformNode = null; 41 Node stopPos tionNode = null;42 Way 43 Map<String, List<String>> tagsToCompare = new HashMap<>(); 51 Node stopPositionNode = null; 52 Way platformWay = null; 53 44 54 for (OsmPrimitive item: selection) { 45 if (item.getType() == OsmPrimitiveType.NODE && 46 (item.hasTag("amenity", "shelter") || item.hasTag("public_transport", "pole"))) { 47 platformNode = (Node) item; 48 } 49 if (item.getType() == OsmPrimitiveType.NODE && 50 item.hasTag("public_transport", "stop_position")) { 51 stopPostionNode = (Node) item; 52 } 53 if (item.getType() == OsmPrimitiveType.WAY && 55 if (item.getType() == OsmPrimitiveType.NODE) { 56 if (item.hasTag("public_transport", "stop_position")) 57 stopPositionNode = (Node) item; 58 else 59 platformNode = (Node) item; 60 } else if (item.getType() == OsmPrimitiveType.WAY && 54 61 item.hasTag("public_transport", "platform")) { 55 62 platformWay = (Way) item; 56 63 } 57 64 } 58 if (platformNode == null && stopPostionNode == null && platformWay == null) { 65 66 if (platformNode == null || stopPositionNode == null) { 59 67 return; 60 68 } 61 } 62 public void populateMap(OsmPrimitive prim, Map<String, List<String>> tagsToCompare) { 63 for ( Entry<String, String> tag: prim.getKeys().entrySet()) { 64 //tagsToCompare.put(tag.getKey(), tag.getValue()); 69 70 dummy1 = new Node(platformNode.getEastNorth()); 71 dummy2 = new Node(platformNode.getEastNorth()); 72 dummy3 = new Node(platformNode.getEastNorth()); 73 74 Main.main.undoRedo.add(new AddCommand(dummy1)); 75 Main.main.undoRedo.add(new AddCommand(dummy2)); 76 Main.main.undoRedo.add(new AddCommand(dummy3)); 77 78 populateMap(stopPositionNode); 79 populateMap(platformNode); 80 81 if (platformWay != null) { 82 populateMap(platformWay); 83 platformWay.removeAll(); 84 platformWay.put("public_transport", "platform"); 85 platformWay.put(" highway", "platform"); 86 } 87 88 stopPositionNode.removeAll(); 89 stopPositionNode.put("bus", "yes"); 90 stopPositionNode.put("public_transport", "stop_position"); 91 92 platformNode.removeAll(); 93 platformNode.put("public_transport", "platform"); 94 platformNode.put("highway", "bus_stop"); 95 96 List<OsmPrimitive> prims = new ArrayList<>(); 97 prims.add(platformNode); 98 prims.add(dummy1); 99 prims.add(dummy2); 100 prims.add(dummy3); 101 102 try { 103 TagCollection tagColl = TagCollection.unionOfAllPrimitives(prims); 104 List<Command> cmds = CombinePrimitiveResolverDialog.launchIfNecessary( 105 tagColl, prims, Collections.singleton(platformNode)); 106 Main.main.undoRedo.add(new SequenceCommand("merging", cmds)); 107 } catch (UserCancelException ex) { 108 Main.trace(ex); 109 } finally { 110 Main.main.undoRedo.add(new DeleteCommand(dummy1)); 111 Main.main.undoRedo.add(new DeleteCommand(dummy2)); 112 Main.main.undoRedo.add(new DeleteCommand(dummy3)); 65 113 } 66 114 } 115 116 public void populateMap(OsmPrimitive prim) { 117 List<String> unInterestingTags = new ArrayList<>(); 118 unInterestingTags.add("public_transport"); 119 unInterestingTags.add("highway"); 120 unInterestingTags.add("source"); 121 122 for (Entry<String, String> tag: prim.getKeys().entrySet()) { 123 if (unInterestingTags.contains(tag.getKey())) { 124 continue; 125 } 126 if (dummy1.get(tag.getKey()) == null) { 127 dummy1.put(tag.getKey(), tag.getValue()); 128 } else if (dummy2.get(tag.getKey()) == null) { 129 dummy2.put(tag.getKey(), tag.getValue()); 130 } else if (dummy3.get(tag.getKey()) == null) { 131 dummy3.put(tag.getKey(), tag.getValue()); 132 } 133 } 134 } 135 67 136 @Override 68 137 protected void updateEnabledState( 69 138 Collection<? extends OsmPrimitive> selection) { 70 139 setEnabled(false); 71 if (selection == null || selection.size() != 1) 72 return; 73 OsmPrimitive selected = selection.iterator().next(); 74 if (selected.getType() == OsmPrimitiveType.RELATION && 75 RouteUtils.isPTRoute((Relation) selected)) { 140 141 if (selection.size() > 1) { 76 142 setEnabled(true); 77 143 }
Note:
See TracChangeset
for help on using the changeset viewer.