Ticket #5480: SelectAction.java.permissiveness.around.virtualnode.patch

File SelectAction.java.permissiveness.around.virtualnode.patch, 5.0 KB (added by cmuelle8, 16 years ago)

do not obstruct selection cycle when clicking virtualNode..

  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

     
    274274        snapDistance *= snapDistance;
    275275
    276276        MapView c = Main.map.mapView;
    277 
    278277        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
     278
     279        // take nearest node
    279280        OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate);
    280281
    281282        if (osm != null) {
    282283            for (Node n : c.getNearestNodes(p, OsmPrimitive.isSelectablePredicate)) {
    283284                if (sel.contains(n)) {
     285                    // take nearest selected node
    284286                    osm = n;
     287                    break;
    285288                }
    286289            }
    287290        } else {
     
    289292            Way w = null;
    290293
    291294            Collection<WaySegment> virtualWaysInSel = new ArrayList<WaySegment>();
    292             osm = c.getNearestWay(p, OsmPrimitive.isSelectablePredicate);
    293 
    294             for(WaySegment nearestWS : c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate)) {
     295            Collection<WaySegment> wss = c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate);
     296            for(WaySegment nearestWS : wss) {
    295297                if (nearestWS == null) {
    296298                    continue;
    297299                }
    298                 if (sel.contains(w = nearestWS.way)) {
     300
     301                w = nearestWS.way;
     302                if (osm == null && sel.contains(w)) {
     303                    // take nearest selected way
    299304                    osm = w;
    300305                }
    301306
     
    329334            }
    330335
    331336            if (virtualNode != null) {
     337                // insert virtualNode into all segments if nothing was selected,
     338                // else only into the (previously) selected segments
    332339                virtualWays = virtualWaysInSel.isEmpty() ? virtualWays : virtualWaysInSel;
    333                 osm = virtualWays.iterator().next().way;
     340            }
     341
     342            if (osm == null && !wss.isEmpty()) {
     343                // take nearest way
     344                osm = wss.iterator().next().way;
    334345            }
    335346        }
    336347
     
    434445            boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    435446            boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    436447            boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK|InputEvent.ALT_GRAPH_MASK)) != 0
    437                             || Main.pref.getBoolean("selectaction.rotates", false);
     448                            || Main.pref.getBoolean("selectaction.cycles.multiple.matches", false);
    438449
    439450            virtualWays.clear();
    440451            virtualNode = null;
     
    443454                Collection<OsmPrimitive> c = Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate);
    444455                if (!c.isEmpty() && alt) {
    445456                    if (c.iterator().next() instanceof Node) {
    446                         // there is at least one node under the cursor:
    447                         //   - make sure (first element of new list) equals (result of getNearestCollection)
    448                         //   - do not consider ways at all, but all nearest nodes
     457                        // consider all nearest nodes
    449458                        c = new ArrayList<OsmPrimitive>(Main.map.mapView.getNearestNodes(e.getPoint(), OsmPrimitive.isSelectablePredicate));
    450459                    } else {
    451                         // consider all ways..
     460                        // consider all nearest primitives (should be only ways at this point..)
    452461                        c = Main.map.mapView.getAllNearest(e.getPoint(), OsmPrimitive.isSelectablePredicate);
    453462                    }
    454463                }
     
    535544    public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift,
    536545            boolean ctrl, boolean released, boolean area) {
    537546        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
    538554        if ((shift && ctrl) || (ctrl && !released) || (!virtualWays.isEmpty()))
    539             return; // not allowed together
     555            return;
    540556
    541557        // toggle through possible objects on mouse release
    542558        if (released && !area) {
     
    588604            }
    589605        }
    590606
    591         // hard-wiring to false due to performance reasons, should do w/out
    592         selMorePrims = (released || area) ? false : ds.getSelected().containsAll(selectionList);
    593 
    594607        if (ctrl) {
    595608            // Ctrl on an item toggles its selection status,
    596609            // but Ctrl on an *area* just clears those items