- Timestamp:
- 2006-11-28T20:30:37+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r155 r170 21 21 import org.openstreetmap.josm.data.coor.EastNorth; 22 22 import org.openstreetmap.josm.data.osm.Node; 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 24 import org.openstreetmap.josm.data.osm.Segment; 24 25 import org.openstreetmap.josm.data.osm.Way; … … 38 39 public class AddNodeAction extends MapMode { 39 40 40 enum Mode {node, nodesegment }41 enum Mode {node, nodesegment, autonode} 41 42 private final Mode mode; 42 43 … … 47 48 actions.add(new AddNodeAction(mf,tr("Add node"), Mode.node, tr("Add a new node to the map"))); 48 49 actions.add(new AddNodeAction(mf, tr("Add node into segment"), Mode.nodesegment,tr( "Add a node into an existing segment"))); 50 actions.add(new AddNodeAction(mf, tr("Add node and connect"), Mode.autonode,tr( "Add a node and connect it to the selected (previous added) node"))); 49 51 setCurrent(0); 50 52 } … … 132 134 } 133 135 134 c = new SequenceCommand(tr("Add Node into Segment"), cmds);136 c = new SequenceCommand(tr("Add node into segment"), cmds); 135 137 } 138 139 if (mode == Mode.autonode) { 140 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 141 if (selection.size() == 1 && selection.iterator().next() instanceof Node) { 142 Node n1 = (Node)selection.iterator().next(); 143 Collection<Command> cmds = new LinkedList<Command>(); 144 Segment s = new Segment(n1, n); 145 cmds.add(c); 146 cmds.add(new AddCommand(s)); 147 148 Way way = getWayForNode(n1); 149 if (way != null) { 150 Way newWay = new Way(way); 151 if (way.segments.get(0).from == n1) 152 newWay.segments.add(0, s); 153 else 154 newWay.segments.add(s); 155 cmds.add(new ChangeCommand(way, newWay)); 156 } 157 158 c = new SequenceCommand(tr("Add node and connect"), cmds); 159 } 160 } 161 136 162 Main.main.editLayer().add(c); 137 163 Main.ds.setSelected(n); 138 164 Main.map.mapView.repaint(); 139 165 } 166 167 /** 168 * @return If the node is part of exactly one way, return this. 169 * <code>null</code> otherwise. 170 */ 171 private Way getWayForNode(Node n) { 172 Way way = null; 173 for (Way w : Main.ds.ways) { 174 for (Segment s : w.segments) { 175 if (s.from == n || s.to == n) { 176 if (way != null) 177 return null; 178 if (s.from == s.to) 179 return null; 180 way = w; 181 } 182 } 183 } 184 return way; 185 } 140 186 }
Note:
See TracChangeset
for help on using the changeset viewer.