Changeset 3593 in josm


Ignore:
Timestamp:
Oct 9, 2010 12:27:51 AM (3 years ago)
Author:
bastiK
Message:

put back [3590]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r3590 r3593  
    1616import java.util.Collections; 
    1717import java.util.HashSet; 
     18import java.util.Iterator; 
    1819import java.util.LinkedList; 
    19 import java.util.List; 
    2020import java.util.Set; 
    2121import java.util.TreeSet; 
     
    203203                    virtualWays.size()); 
    204204            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)); 
    206206            virtualWays.clear(); 
    207207            virtualNode = null; 
     
    269269    } 
    270270 
    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 
    272276        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 
    275280        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) { 
    287297                if (nearestWS == null) { 
    288298                    continue; 
    289299                } 
    290300 
    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) { 
    295308                    Point p1 = c.getPoint(w.getNode(nearestWS.lowerIndex)); 
    296309                    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)) 
    298311                    { 
    299312                        Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); 
     
    304317                            // virtual node at the same spot will be joined which is likely unwanted 
    305318                            if(virtualWayNode != null) { 
    306                                 if(  !w.getNode(nearestWS.lowerIndex+1).equals(virtualWayNode) 
     319                                if(!w.getNode(nearestWS.lowerIndex+1).equals(virtualWayNode) 
    307320                                        && !w.getNode(nearestWS.lowerIndex).equals(virtualWayNode)) { 
    308321                                    continue; 
     
    312325                            } 
    313326 
    314                             virtualWays.add(nearestWS); 
     327                            (!sel.contains(w) ? virtualWays : virtualWaysInSel).add(nearestWS); 
    315328                            if(virtualNode == null) { 
    316329                                virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 
     
    320333                } 
    321334            } 
    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 
    323348        if (osm == null) 
    324349            return Collections.emptySet(); 
     
    338363        if(!Main.map.mapView.isActiveLayerVisible()) 
    339364            return; 
     365 
    340366        // request focus in order to enable the expected keyboard shortcuts 
    341         // 
    342367        Main.map.mapView.requestFocus(); 
    343368 
     
    347372            return; 
    348373        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 
    349         boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0; 
    350374        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 
    351375 
     
    360384        initialMoveThresholdExceeded = false; 
    361385 
    362         Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt); 
     386        Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint()); 
    363387 
    364388        if (ctrl && shift) { 
     
    383407            selectionManager.mousePressed(e); 
    384408        } 
    385         if(mode != Mode.move || shift || ctrl) 
    386         { 
     409 
     410        if(mode != Mode.move || shift || ctrl) { 
    387411            virtualNode = null; 
    388412            virtualWays.clear(); 
     
    421445            boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 
    422446            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 
    423453            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); 
    427465 
    428466                // 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) { 
    431469                    // We need to do it like this as otherwise drawAction will see a double 
    432470                    // click and switch back to SelectMode 
     
    501539    } 
    502540 
     541    private boolean selMorePrims = false; 
     542    private OsmPrimitive selCycleStart = null; 
     543 
    503544    public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 
    504545            boolean ctrl, boolean released, boolean area) { 
    505546        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        } 
    508606 
    509607        if (ctrl) { 
Note: See TracChangeset for help on using the changeset viewer.