Changeset 3590 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-10-05T01:54:52+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r3555 r3590 16 16 import java.util.Collections; 17 17 import java.util.HashSet; 18 import java.util.Iterator;19 18 import java.util.LinkedList; 19 import java.util.List; 20 20 import java.util.Set; 21 21 import java.util.TreeSet; … … 203 203 virtualWays.size()); 204 204 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds)); 205 getCurrentDataSet().setSelected(Collections.singleton((OsmPrimitive)virtualNode));205 selectPrims(Collections.singleton((OsmPrimitive)virtualNode), false, false, false, false); 206 206 virtualWays.clear(); 207 207 virtualNode = null; … … 269 269 } 270 270 271 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) { 271 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p, boolean allSegements) { 272 MapView c = Main.map.mapView; 272 273 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 273 int virtualSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);274 274 snapDistance *= snapDistance; 275 276 MapView c = Main.map.mapView;277 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();278 279 // take nearest node280 275 OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate); 281 282 if (osm != null) { 283 for (Node n : c.getNearestNodes(p, OsmPrimitive.isSelectablePredicate)) { 284 if (sel.contains(n)) { 285 // take nearest selected node 286 osm = n; 287 break; 288 } 289 } 290 } else { 291 Node virtualWayNode = null; 292 Way w = null; 293 294 Collection<WaySegment> virtualWaysInSel = new ArrayList<WaySegment>(); 295 Collection<WaySegment> wss = c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate); 296 for(WaySegment nearestWS : wss) { 276 virtualWays.clear(); 277 virtualNode = null; 278 Node virtualWayNode = null; 279 280 if (osm == null) 281 { 282 Collection<WaySegment> nearestWaySegs = allSegements 283 ? c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate) 284 : Collections.singleton(c.getNearestWaySegment(p, OsmPrimitive.isSelectablePredicate)); 285 286 for(WaySegment nearestWS : nearestWaySegs) { 297 287 if (nearestWS == null) { 298 288 continue; 299 289 } 300 290 301 w = nearestWS.way; 302 if (osm == null && sel.contains(w)) { 303 // take nearest selected way 304 osm = w; 305 } 306 307 if (Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0) { 291 osm = nearestWS.way; 292 if(Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0) 293 { 294 Way w = (Way)osm; 308 295 Point p1 = c.getPoint(w.getNode(nearestWS.lowerIndex)); 309 296 Point p2 = c.getPoint(w.getNode(nearestWS.lowerIndex+1)); 310 if(SimplePaintVisitor.isLargeSegment(p1, p2, virtualSpace))297 if(SimplePaintVisitor.isLargeSegment(p1, p2, Main.pref.getInteger("mappaint.node.virtual-space", 70))) 311 298 { 312 299 Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); … … 317 304 // virtual node at the same spot will be joined which is likely unwanted 318 305 if(virtualWayNode != null) { 319 if( !w.getNode(nearestWS.lowerIndex+1).equals(virtualWayNode)306 if( !w.getNode(nearestWS.lowerIndex+1).equals(virtualWayNode) 320 307 && !w.getNode(nearestWS.lowerIndex).equals(virtualWayNode)) { 321 308 continue; … … 325 312 } 326 313 327 (!sel.contains(w) ? virtualWays : virtualWaysInSel).add(nearestWS);314 virtualWays.add(nearestWS); 328 315 if(virtualNode == null) { 329 316 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); … … 333 320 } 334 321 } 335 336 if (virtualNode != null) { 337 // insert virtualNode into all segments if nothing was selected, 338 // else only into the (previously) selected segments 339 virtualWays = virtualWaysInSel.isEmpty() ? virtualWays : virtualWaysInSel; 340 } 341 342 if (osm == null && !wss.isEmpty()) { 343 // take nearest way 344 osm = wss.iterator().next().way; 345 } 346 } 347 322 } 348 323 if (osm == null) 349 324 return Collections.emptySet(); … … 363 338 if(!Main.map.mapView.isActiveLayerVisible()) 364 339 return; 365 366 340 // request focus in order to enable the expected keyboard shortcuts 341 // 367 342 Main.map.mapView.requestFocus(); 368 343 … … 372 347 return; 373 348 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 349 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 374 350 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 375 351 … … 384 360 initialMoveThresholdExceeded = false; 385 361 386 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint() );362 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt); 387 363 388 364 if (ctrl && shift) { … … 407 383 selectionManager.mousePressed(e); 408 384 } 409 410 if(mode != Mode.move || shift || ctrl){385 if(mode != Mode.move || shift || ctrl) 386 { 411 387 virtualNode = null; 412 388 virtualWays.clear(); … … 445 421 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 446 422 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 447 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0448 || Main.pref.getBoolean("selectaction.cycles.multiple.matches", false);449 450 virtualWays.clear();451 virtualNode = null;452 453 423 if (!didMove) { 454 Collection<OsmPrimitive> c = Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate); 455 if (!c.isEmpty() && alt) { 456 if (c.iterator().next() instanceof Node) { 457 // consider all nearest nodes 458 c = new ArrayList<OsmPrimitive>(Main.map.mapView.getNearestNodes(e.getPoint(), OsmPrimitive.isSelectablePredicate)); 459 } else { 460 // consider all nearest primitives (should be only ways at this point..) 461 c = Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate); 462 } 463 } 464 selectPrims(c, shift, ctrl, true, false); 424 selectPrims( 425 Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate), 426 shift, ctrl, true, false); 465 427 466 428 // If the user double-clicked a node, change to draw mode 467 c = getCurrentDataSet().getSelected();468 if(e.getClickCount() >=2 && c.size() == 1 && c.iterator().next() instanceof Node) {429 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected()); 430 if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) { 469 431 // We need to do it like this as otherwise drawAction will see a double 470 432 // click and switch back to SelectMode … … 539 501 } 540 502 541 private boolean selMorePrims = false;542 private OsmPrimitive selCycleStart = null;543 544 503 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 545 504 boolean ctrl, boolean released, boolean area) { 546 505 DataSet ds = getCurrentDataSet(); 547 548 // decides on mousePressed whether 549 // to cycle on mouseReleased (selList already selected) 550 // or not (selList is a new selection) 551 selMorePrims = (released || area) ? selMorePrims : ds.getSelected().containsAll(selectionList); 552 553 // not allowed together: do not change dataset selection, return early 554 if ((shift && ctrl) || (ctrl && !released) || (!virtualWays.isEmpty())) 555 return; 556 557 // toggle through possible objects on mouse release 558 if (released && !area) { 559 if (selectionList.size() > 1) { 560 Collection<OsmPrimitive> coll = ds.getSelected(); 561 562 OsmPrimitive first, foundInDS, node, nxt; 563 first = nxt = selectionList.iterator().next(); 564 foundInDS = node = null; 565 566 for (Iterator<OsmPrimitive> i = selectionList.iterator(); i.hasNext(); ) { 567 if (selMorePrims && shift) { 568 if (!coll.contains(nxt = i.next())) { 569 break; // take first primitive not in dsSel or last if all contained 570 } 571 } else { 572 if (coll.contains(nxt = i.next())) { 573 foundInDS = nxt; 574 if (selMorePrims || ctrl) { 575 ds.clearSelection(nxt); 576 nxt = i.hasNext() ? i.next() : first; 577 } 578 break; // take next primitive of selList 579 } else if (nxt instanceof Node && node == null) { 580 node = nxt; 581 } 582 } 583 } 584 585 if (ctrl) { 586 if (foundInDS != null) { 587 // a member of selList was foundInDS 588 if (!selectionList.contains(selCycleStart)) { 589 selCycleStart = foundInDS; 590 } 591 // check if selCycleStart == prim (equals next(foundInDS)) 592 if (selCycleStart.equals(nxt)) { 593 ds.addSelected(nxt); // cycle complete, prim toggled below 594 selCycleStart = null; // check: might do w/out ?? 595 } 596 } else { 597 // no member of selList was foundInDS (sets were disjunct), setup for new cycle 598 selCycleStart = nxt = (node != null) ? node : first; 599 } 600 } 601 602 selectionList = new ArrayList<OsmPrimitive>(1); // do not modify the passed object.. 603 selectionList.add(nxt); 604 } 605 } 506 if ((shift && ctrl) || (ctrl && !released)) 507 return; // not allowed together 606 508 607 509 if (ctrl) {
Note:
See TracChangeset
for help on using the changeset viewer.