Changeset 805 in josm for trunk/src/org/openstreetmap/josm/actions/mapmode
- Timestamp:
- 2008-08-18T01:27:58+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r655 r805 11 11 import java.awt.event.MouseEvent; 12 12 import java.util.Collection; 13 import java.util.Collections; 13 14 import java.util.LinkedList; 14 15 … … 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.actions.MergeNodesAction; 20 import org.openstreetmap.josm.command.AddCommand; 19 21 import org.openstreetmap.josm.command.Command; 22 import org.openstreetmap.josm.command.ChangeCommand; 20 23 import org.openstreetmap.josm.command.MoveCommand; 21 24 import org.openstreetmap.josm.command.RotateCommand; 25 import org.openstreetmap.josm.command.SequenceCommand; 22 26 import org.openstreetmap.josm.data.coor.EastNorth; 23 27 import org.openstreetmap.josm.data.osm.Node; 24 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.data.osm.WaySegment; 25 31 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 26 32 import org.openstreetmap.josm.gui.MapFrame; 33 import org.openstreetmap.josm.gui.MapView; 27 34 import org.openstreetmap.josm.gui.SelectionManager; 28 35 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; … … 108 115 Main.map.mapView.addMouseListener(this); 109 116 Main.map.mapView.addMouseMotionListener(this); 117 Main.map.mapView.enableVirtualNodes(Main.pref.getInteger("mappaint.node.virtual-size", 4) != 0); 110 118 } 111 119 … … 115 123 Main.map.mapView.removeMouseListener(this); 116 124 Main.map.mapView.removeMouseMotionListener(this); 125 Main.map.mapView.enableVirtualNodes(false); 117 126 } 118 127 … … 195 204 } 196 205 206 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) { 207 MapView c = Main.map.mapView; 208 OsmPrimitive osm = c.getNearestNode(p); 209 if (osm == null) 210 { 211 WaySegment nearestWaySeg = c.getNearestWaySegment(p); 212 if(nearestWaySeg != null) 213 { 214 osm = nearestWaySeg.way; 215 if(Main.pref.getInteger("mappaint.node.virtual-size", 4) > 0) 216 { 217 Way w = (Way)osm; 218 Point p1 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex).eastNorth); 219 Point p2 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex+1).eastNorth); 220 int xd = p2.x-p1.x; if(xd < 0) xd = -xd; 221 int yd = p2.y-p1.y; if(yd < 0) yd = -yd; 222 if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 50)) 223 { 224 Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); 225 if(p.distanceSq(pc) < Main.map.mapView.snapDistance) 226 { 227 Collection<Command> cmds = new LinkedList<Command>(); 228 Node n = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 229 cmds.add(new AddCommand(n)); 230 231 Way wnew = new Way(w); 232 wnew.nodes.add(nearestWaySeg.lowerIndex+1, n); 233 cmds.add(new ChangeCommand(w, wnew)); 234 Main.main.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"), cmds)); 235 osm = n; 236 } 237 } 238 } 239 } 240 } 241 if (osm == null) 242 return Collections.emptySet(); 243 return Collections.singleton(osm); 244 } 245 197 246 /** 198 247 * Look, whether any object is selected. If not, select the nearest node. … … 216 265 initialMoveThresholdExceeded = false; 217 266 218 Collection<OsmPrimitive> osmColl = 219 Main.map.mapView.getNearestCollection(e.getPoint()); 267 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint()); 220 268 221 269 if (ctrl && shift) { … … 289 337 290 338 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, boolean ctrl) { 291 339 if (shift && ctrl) 292 340 return; // not allowed together 293 341 … … 305 353 Main.ds.setSelected(curSel); 306 354 Main.map.mapView.repaint(); 307 355 } 308 356 309 357 @Override public String getModeHelpText() {
Note:
See TracChangeset
for help on using the changeset viewer.