Changeset 1441 in josm for trunk/src/org
- Timestamp:
- 2009-02-24T18:49:06+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r1421 r1441 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 6 7 import java.awt.Cursor; … … 61 62 private boolean cancelDrawMode = false; 62 63 Node virtualNode = null; 63 WaySegment virtualWay = null;64 Collection<WaySegment> virtualWays = new ArrayList<WaySegment>(); 64 65 SequenceCommand virtualCmds = null; 65 66 … … 147 148 if(!Main.map.mapView.isVisibleDrawableLayer()) 148 149 return; 149 150 150 151 cancelDrawMode = true; 151 152 if (mode == Mode.select) return; … … 181 182 return; 182 183 183 if (virtualWay != null){184 if (virtualWays.size() > 0) { 184 185 Collection<Command> virtualCmds = new LinkedList<Command>(); 185 186 virtualCmds.add(new AddCommand(virtualNode)); 186 Way w = virtualWay.way; 187 Way wnew = new Way(w); 188 wnew.addNode(virtualWay.lowerIndex+1, virtualNode); 189 virtualCmds.add(new ChangeCommand(w, wnew)); 187 for(WaySegment virtualWay : virtualWays) { 188 Way w = virtualWay.way; 189 Way wnew = new Way(w); 190 wnew.addNode(virtualWay.lowerIndex+1, virtualNode); 191 virtualCmds.add(new ChangeCommand(w, wnew)); 192 } 190 193 virtualCmds.add(new MoveCommand(virtualNode, dx, dy)); 191 Main.main.undoRedo.add(new SequenceCommand(tr("Add and move a virtual new node to way"), virtualCmds)); 194 String text = trn("Add and move a virtual new node to way", 195 "Add and move a virtual new node to {0} ways", virtualWays.size(), 196 virtualWays.size()); 197 198 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds)); 192 199 selectPrims(Collections.singleton((OsmPrimitive)virtualNode), false, false); 193 virtualWay = null;200 virtualWays.clear(); 194 201 virtualNode = null; 195 202 } else { … … 222 229 JOptionPane.showMessageDialog(Main.parent, 223 230 tr("Cannot move objects outside of the world.")); 231 restoreCursor(); 224 232 return; 225 233 } … … 239 247 } 240 248 241 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p ) {249 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p, boolean allSegements) { 242 250 MapView c = Main.map.mapView; 243 251 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 244 252 snapDistance *= snapDistance; 245 253 OsmPrimitive osm = c.getNearestNode(p); 246 virtualWay = null;254 virtualWays.clear(); 247 255 virtualNode = null; 256 Node virtualWayNode = null; 248 257 249 258 if (osm == null) 250 259 { 251 WaySegment nearestWaySeg = c.getNearestWaySegment(p); 252 if (nearestWaySeg != null) 253 { 254 osm = nearestWaySeg.way; 260 Collection<WaySegment> nearestWaySegs = allSegements 261 ? c.getNearestWaySegments(p) 262 : Collections.singleton(c.getNearestWaySegment(p)); 263 264 for(WaySegment nearestWS : nearestWaySegs) { 265 if (nearestWS == null) 266 continue; 267 268 osm = nearestWS.way; 255 269 if(Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0) 256 270 { 257 271 Way w = (Way)osm; 258 Point p1 = c.getPoint(w.nodes.get(nearestW aySeg.lowerIndex).eastNorth);259 Point p2 = c.getPoint(w.nodes.get(nearestW aySeg.lowerIndex+1).eastNorth);272 Point p1 = c.getPoint(w.nodes.get(nearestWS.lowerIndex).eastNorth); 273 Point p2 = c.getPoint(w.nodes.get(nearestWS.lowerIndex+1).eastNorth); 260 274 if(SimplePaintVisitor.isLargeSegment(p1, p2, Main.pref.getInteger("mappaint.node.virtual-space", 70))) 261 275 { … … 263 277 if (p.distanceSq(pc) < snapDistance) 264 278 { 265 virtualWay = nearestWaySeg; 266 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 267 osm = w; 279 // Check that only segments on top of each other get added to the 280 // virtual ways list. Otherwise ways that coincidentally have their 281 // virtual node at the same spot will be joined which is likely unwanted 282 if(virtualWayNode != null) { 283 if( !w.nodes.get(nearestWS.lowerIndex+1).equals(virtualWayNode) 284 && !w.nodes.get(nearestWS.lowerIndex ).equals(virtualWayNode)) 285 continue; 286 } else 287 virtualWayNode = w.nodes.get(nearestWS.lowerIndex+1); 288 289 virtualWays.add(nearestWS); 290 if(virtualNode == null) 291 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 268 292 } 269 293 } … … 288 312 if(!Main.map.mapView.isVisibleDrawableLayer()) 289 313 return; 290 314 291 315 cancelDrawMode = false; 292 316 if (! (Boolean)this.getValue("active")) return; … … 294 318 return; 295 319 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 296 //boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;320 boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 297 321 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 298 322 299 323 // We don't want to change to draw tool if the user tries to (de)select 300 324 // stuff but accidentally clicks in an empty area when selection is empty … … 306 330 initialMoveThresholdExceeded = false; 307 331 308 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint() );332 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt); 309 333 310 334 if (ctrl && shift) { … … 330 354 { 331 355 virtualNode = null; 332 virtualWay = null;356 virtualWays.clear(); 333 357 } 334 358 335 359 updateStatusLine(); 336 Main.map.mapView.repaint(); 360 // Mode.select redraws when selectPrims is called 361 // Mode.move redraws when mouseDragged is called 362 // Mode.rotate redraws here 363 if(mode == Mode.rotate) 364 Main.map.mapView.repaint(); 337 365 338 366 mousePos = e.getPoint(); … … 345 373 if(!Main.map.mapView.isVisibleDrawableLayer()) 346 374 return; 347 375 348 376 if (mode == Mode.select) { 349 377 selectionManager.unregister(Main.map.mapView); … … 398 426 } 399 427 400 updateStatusLine(); 428 // I don't see why we need this. 429 //updateStatusLine(); 401 430 mode = null; 402 431 updateStatusLine();
Note:
See TracChangeset
for help on using the changeset viewer.