Ticket #1469: Virtual For All.patch
| File Virtual For All.patch, 7.8 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
60 60 private boolean didMove = false; 61 61 private boolean cancelDrawMode = false; 62 62 Node virtualNode = null; 63 WaySegment virtualWay = null;63 Collection<WaySegment> virtualWays = new ArrayList<WaySegment>(); 64 64 SequenceCommand virtualCmds = null; 65 65 66 66 /** … … 146 146 @Override public void mouseDragged(MouseEvent e) { 147 147 if(!Main.map.mapView.isVisibleDrawableLayer()) 148 148 return; 149 149 150 150 cancelDrawMode = true; 151 151 if (mode == Mode.select) return; 152 152 … … 180 180 if (dx == 0 && dy == 0) 181 181 return; 182 182 183 if (virtualWay != null){183 if (virtualWays.size() > 0) { 184 184 Collection<Command> virtualCmds = new LinkedList<Command>(); 185 185 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)); 186 for(WaySegment virtualWay : virtualWays) { 187 Way w = virtualWay.way; 188 Way wnew = new Way(w); 189 wnew.addNode(virtualWay.lowerIndex+1, virtualNode); 190 virtualCmds.add(new ChangeCommand(w, wnew)); 191 } 190 192 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)); 193 String text = virtualWays.size() == 1 194 ? tr("Add and move a virtual new node to way") 195 : tr("Add and move a virtual new node to {0} ways", virtualWays.size()); 196 197 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds)); 192 198 selectPrims(Collections.singleton((OsmPrimitive)virtualNode), false, false); 193 virtualWay = null;199 virtualWays.clear(); 194 200 virtualNode = null; 195 201 } else { 196 202 // Currently we support moving and rotating, which do not affect relations. … … 221 227 222 228 JOptionPane.showMessageDialog(Main.parent, 223 229 tr("Cannot move objects outside of the world.")); 230 restoreCursor(); 224 231 return; 225 232 } 226 233 } … … 238 245 didMove = true; 239 246 } 240 247 241 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p ) {248 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p, boolean allSegements) { 242 249 MapView c = Main.map.mapView; 243 250 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 244 251 snapDistance *= snapDistance; 245 252 OsmPrimitive osm = c.getNearestNode(p); 246 virtualWay = null;253 virtualWays.clear(); 247 254 virtualNode = null; 255 Node virtualWayNode = null; 248 256 249 257 if (osm == null) 250 258 { 251 WaySegment nearestWaySeg = c.getNearestWaySegment(p); 252 if (nearestWaySeg != null) 253 { 254 osm = nearestWaySeg.way; 259 Collection<WaySegment> nearestWaySegs = allSegements 260 ? c.getNearestWaySegments(p) 261 : Collections.singleton(c.getNearestWaySegment(p)); 262 263 for(WaySegment nearestWS : nearestWaySegs) { 264 if (nearestWS == null) 265 continue; 266 267 osm = nearestWS.way; 255 268 if(Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0) 256 269 { 257 270 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);271 Point p1 = c.getPoint(w.nodes.get(nearestWS.lowerIndex).eastNorth); 272 Point p2 = c.getPoint(w.nodes.get(nearestWS.lowerIndex+1).eastNorth); 260 273 if(SimplePaintVisitor.isLargeSegment(p1, p2, Main.pref.getInteger("mappaint.node.virtual-space", 70))) 261 274 { 262 275 Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); 263 276 if (p.distanceSq(pc) < snapDistance) 264 277 { 265 virtualWay = nearestWaySeg; 266 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 267 osm = w; 278 // Check that only segments on top of each other get added to the 279 // virtual ways list. Otherwise ways that coincidentally have their 280 // virtual node at the same spot will be joined which is likely unwanted 281 if(virtualWayNode != null) { 282 if( !w.nodes.get(nearestWS.lowerIndex+1).equals(virtualWayNode) 283 && !w.nodes.get(nearestWS.lowerIndex ).equals(virtualWayNode)) 284 continue; 285 } else 286 virtualWayNode = w.nodes.get(nearestWS.lowerIndex+1); 287 288 virtualWays.add(nearestWS); 289 if(virtualNode == null) 290 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 268 291 } 269 292 } 270 293 } … … 287 310 @Override public void mousePressed(MouseEvent e) { 288 311 if(!Main.map.mapView.isVisibleDrawableLayer()) 289 312 return; 290 313 291 314 cancelDrawMode = false; 292 315 if (! (Boolean)this.getValue("active")) return; 293 316 if (e.getButton() != MouseEvent.BUTTON1) 294 317 return; 295 318 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 296 //boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;319 boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 297 320 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 298 321 299 322 // We don't want to change to draw tool if the user tries to (de)select 300 323 // stuff but accidentally clicks in an empty area when selection is empty 301 324 if(shift || ctrl) … … 305 328 didMove = false; 306 329 initialMoveThresholdExceeded = false; 307 330 308 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint() );331 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt); 309 332 310 333 if (ctrl && shift) { 311 334 if (Main.ds.getSelected().isEmpty()) selectPrims(osmColl, true, false); … … 329 352 if(mode != Mode.move || shift || ctrl) 330 353 { 331 354 virtualNode = null; 332 virtualWay = null;355 virtualWays.clear(); 333 356 } 334 357 335 358 updateStatusLine(); 336 Main.map.mapView.repaint(); 359 // Mode.select redraws when selectPrims is called 360 // Mode.move redraws when mouseDragged is called 361 // Mode.rotate redraws here 362 if(mode == Mode.rotate) 363 Main.map.mapView.repaint(); 337 364 338 365 mousePos = e.getPoint(); 339 366 } … … 344 371 @Override public void mouseReleased(MouseEvent e) { 345 372 if(!Main.map.mapView.isVisibleDrawableLayer()) 346 373 return; 347 374 348 375 if (mode == Mode.select) { 349 376 selectionManager.unregister(Main.map.mapView); 350 377 … … 397 424 } 398 425 } 399 426 400 updateStatusLine(); 427 // I don't see why we need this. 428 //updateStatusLine(); 401 429 mode = null; 402 430 updateStatusLine(); 403 431 }
