Changeset 3593 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-10-09T00:27:51+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r3590 r3593 16 16 import java.util.Collections; 17 17 import java.util.HashSet; 18 import java.util.Iterator; 18 19 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 selectPrims(Collections.singleton((OsmPrimitive)virtualNode), false, false, false, false);205 getCurrentDataSet().setSelected(Collections.singleton((OsmPrimitive)virtualNode)); 206 206 virtualWays.clear(); 207 207 virtualNode = null; … … 269 269 } 270 270 271 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p, boolean allSegements) { 271 private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) { 272 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 273 int virtualSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70); 274 snapDistance *= snapDistance; 275 272 276 MapView c = Main.map.mapView; 273 int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 274 snapDistance *= snapDistance; 277 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 278 279 // take nearest node 275 280 OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate); 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) { 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) { 287 297 if (nearestWS == null) { 288 298 continue; 289 299 } 290 300 291 osm = nearestWS.way; 292 if(Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0) 293 { 294 Way w = (Way)osm; 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) { 295 308 Point p1 = c.getPoint(w.getNode(nearestWS.lowerIndex)); 296 309 Point p2 = c.getPoint(w.getNode(nearestWS.lowerIndex+1)); 297 if(SimplePaintVisitor.isLargeSegment(p1, p2, Main.pref.getInteger("mappaint.node.virtual-space", 70)))310 if(SimplePaintVisitor.isLargeSegment(p1, p2, virtualSpace)) 298 311 { 299 312 Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); … … 304 317 // virtual node at the same spot will be joined which is likely unwanted 305 318 if(virtualWayNode != null) { 306 if( 319 if(!w.getNode(nearestWS.lowerIndex+1).equals(virtualWayNode) 307 320 && !w.getNode(nearestWS.lowerIndex).equals(virtualWayNode)) { 308 321 continue; … … 312 325 } 313 326 314 virtualWays.add(nearestWS);327 (!sel.contains(w) ? virtualWays : virtualWaysInSel).add(nearestWS); 315 328 if(virtualNode == null) { 316 329 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); … … 320 333 } 321 334 } 322 } 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 323 348 if (osm == null) 324 349 return Collections.emptySet(); … … 338 363 if(!Main.map.mapView.isActiveLayerVisible()) 339 364 return; 365 340 366 // request focus in order to enable the expected keyboard shortcuts 341 //342 367 Main.map.mapView.requestFocus(); 343 368 … … 347 372 return; 348 373 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 349 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0;350 374 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 351 375 … … 360 384 initialMoveThresholdExceeded = false; 361 385 362 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint() , alt);386 Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint()); 363 387 364 388 if (ctrl && shift) { … … 383 407 selectionManager.mousePressed(e); 384 408 } 385 if(mode != Mode.move || shift || ctrl) 386 {409 410 if(mode != Mode.move || shift || ctrl) { 387 411 virtualNode = null; 388 412 virtualWays.clear(); … … 421 445 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 422 446 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 447 boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0 448 || Main.pref.getBoolean("selectaction.cycles.multiple.matches", false); 449 450 virtualWays.clear(); 451 virtualNode = null; 452 423 453 if (!didMove) { 424 selectPrims( 425 Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate), 426 shift, ctrl, true, false); 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); 427 465 428 466 // If the user double-clicked a node, change to draw mode 429 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected());430 if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) {467 c = getCurrentDataSet().getSelected(); 468 if(e.getClickCount() >=2 && c.size() == 1 && c.iterator().next() instanceof Node) { 431 469 // We need to do it like this as otherwise drawAction will see a double 432 470 // click and switch back to SelectMode … … 501 539 } 502 540 541 private boolean selMorePrims = false; 542 private OsmPrimitive selCycleStart = null; 543 503 544 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 504 545 boolean ctrl, boolean released, boolean area) { 505 546 DataSet ds = getCurrentDataSet(); 506 if ((shift && ctrl) || (ctrl && !released)) 507 return; // not allowed together 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 } 508 606 509 607 if (ctrl) {
Note:
See TracChangeset
for help on using the changeset viewer.