Changeset 3177 in josm


Ignore:
Timestamp:
Apr 11, 2010 3:29:02 PM (3 years ago)
Author:
bastiK
Message:

Filter: improved selection handling. (Don't allow to select filtered or disabled objects by clicking on them. Don't connect to hidden ways in add mode.)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
11 edited

Legend:

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

    r2431 r3177  
    4141 
    4242        List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 
    43                 Main.map.mapView.getPoint(node)); 
     43                Main.map.mapView.getPoint(node), OsmPrimitive.isSelectablePredicate); 
    4444        HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 
    4545        for (WaySegment ws : wss) { 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r2986 r3177  
    1919import org.openstreetmap.josm.command.DeleteCommand; 
    2020import org.openstreetmap.josm.data.osm.Node; 
     21import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    2122import org.openstreetmap.josm.data.osm.Relation; 
    2223import org.openstreetmap.josm.data.osm.WaySegment; 
     
    286287        DeleteParameters result = new DeleteParameters(); 
    287288 
    288         result.nearestNode = Main.map.mapView.getNearestNode(e.getPoint()); 
     289        result.nearestNode = Main.map.mapView.getNearestNode(e.getPoint(), OsmPrimitive.isSelectablePredicate); 
    289290        if (result.nearestNode == null) { 
    290             result.nearestSegment = Main.map.mapView.getNearestWaySegment(e.getPoint()); 
     291            result.nearestSegment = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate); 
    291292            if (result.nearestSegment != null) { 
    292293                if (shift) { 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r3116 r3177  
    164164        if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().size() == 0 
    165165                && mousePos != null) { 
    166             mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos); 
     166            mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 
    167167        } 
    168168 
     
    332332 
    333333        if (!ctrl) { 
    334             n = Main.map.mapView.getNearestNode(mousePos); 
     334            n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 
    335335        } 
    336336 
     
    366366            if (!ctrl) { 
    367367                // Insert the node into all the nearby way segments 
    368                 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint()); 
     368                List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive.isSelectablePredicate); 
    369369                Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 
    370370                for (WaySegment ws : wss) { 
     
    681681 
    682682        if (!ctrl && mousePos != null) { 
    683             currentMouseNode = mv.getNearestNode(mousePos); 
     683            currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 
    684684        } 
    685685 
     
    687687        // *and* there is no node nearby (because nodes beat ways when re-using) 
    688688        if(!ctrl && currentMouseNode == null) { 
    689             List<WaySegment> wss = mv.getNearestWaySegments(mousePos); 
     689            List<WaySegment> wss = mv.getNearestWaySegments(mousePos, OsmPrimitive.isSelectablePredicate); 
    690690            for(WaySegment ws : wss) { 
    691691                mouseOnExistingWays.add(ws.way); 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r2990 r3177  
    308308        // boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 
    309309 
    310         selectedSegment = Main.map.mapView.getNearestWaySegment(e.getPoint()); 
     310        selectedSegment = Main.map.mapView.getNearestWaySegment(e.getPoint(), OsmPrimitive.isSelectablePredicate); 
    311311 
    312312        if (selectedSegment == null) { 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r2719 r3177  
    285285        int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8); 
    286286        snapDistance *= snapDistance; 
    287         OsmPrimitive osm = c.getNearestNode(p); 
     287        OsmPrimitive osm = c.getNearestNode(p, OsmPrimitive.isSelectablePredicate); 
    288288        virtualWays.clear(); 
    289289        virtualNode = null; 
     
    293293        { 
    294294            Collection<WaySegment> nearestWaySegs = allSegements 
    295             ? c.getNearestWaySegments(p) 
    296                     : Collections.singleton(c.getNearestWaySegment(p)); 
     295            ? c.getNearestWaySegments(p, OsmPrimitive.isSelectablePredicate) 
     296                    : Collections.singleton(c.getNearestWaySegment(p, OsmPrimitive.isSelectablePredicate)); 
    297297 
    298298            for(WaySegment nearestWS : nearestWaySegs) { 
     
    435435            if (!didMove) { 
    436436                selectPrims( 
    437                         Main.map.mapView.getNearestCollection(e.getPoint()), 
     437                        Main.map.mapView.getNearestCollection(e.getPoint(), OsmPrimitive.isSelectablePredicate), 
    438438                        shift, ctrl, true, false); 
    439439 
     
    485485                if (ctrl) { 
    486486                    Collection<Node> affectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 
    487                     Collection<Node> nn = Main.map.mapView.getNearestNodes(e.getPoint(), affectedNodes); 
     487                    Collection<Node> nn = Main.map.mapView.getNearestNodes(e.getPoint(), affectedNodes, OsmPrimitive.isSelectablePredicate); 
    488488                    if (nn != null) { 
    489489                        Node targetNode = nn.iterator().next(); 
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r3166 r3177  
    2020import org.openstreetmap.josm.data.SelectionChangedListener; 
    2121import org.openstreetmap.josm.data.coor.LatLon; 
     22import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    2223import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 
    2324import org.openstreetmap.josm.data.osm.event.ChangesetIdChangedEvent; 
     
    174175     */ 
    175176    public Collection<OsmPrimitive> allNonDeletedPrimitives() { 
    176         return new DatasetCollection.AllNonDeleted(allPrimitives); 
     177        return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedPredicate); 
    177178    } 
    178179 
    179180    public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() { 
    180         return new DatasetCollection.AllNonDeletedComplete(allPrimitives); 
     181        return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedCompletePredicate); 
    181182    } 
    182183 
    183184    public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() { 
    184         return new DatasetCollection.AllNonDeletedPhysical(allPrimitives); 
    185     } 
    186  
    187     /** 
    188      * @return A collection containing all modified primitives 
    189      */ 
     185        return new DatasetCollection(allPrimitives, OsmPrimitive.nonDeletedPhysicalPredicate); 
     186    } 
     187 
    190188    public Collection<OsmPrimitive> allModifiedPrimitives() { 
    191         return new DatasetCollection.AllModified(allPrimitives); 
     189        return new DatasetCollection(allPrimitives, OsmPrimitive.modifiedPredicate); 
    192190    } 
    193191 
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetCollection.java

    r3147 r3177  
    66import java.util.Iterator; 
    77 
    8 abstract class DatasetCollection extends AbstractCollection<OsmPrimitive> { 
     8import org.openstreetmap.josm.tools.Predicate; 
     9 
     10class DatasetCollection extends AbstractCollection<OsmPrimitive> { 
    911 
    1012    private class FilterIterator implements Iterator<OsmPrimitive> { 
     
    2123                while (iterator.hasNext()) { 
    2224                    current = iterator.next(); 
    23                     if (filter(current)) 
     25                    if (predicate.evaluate(current)) 
    2426                        return; 
    2527                } 
     
    4648 
    4749    private final Collection<OsmPrimitive> primitives; 
     50    private final Predicate<OsmPrimitive> predicate; 
    4851 
    49     public DatasetCollection(Collection<OsmPrimitive> primitives) { 
     52    public DatasetCollection(Collection<OsmPrimitive> primitives, Predicate<OsmPrimitive> predicate) { 
    5053        this.primitives = primitives; 
     54        this.predicate = predicate; 
    5155    } 
    52  
    53     protected abstract boolean filter(OsmPrimitive primitive); 
    5456 
    5557    @Override 
     
    7375        return !iterator().hasNext(); 
    7476    } 
    75  
    76     public static class AllNonDeleted extends DatasetCollection { 
    77  
    78         public AllNonDeleted(Collection<OsmPrimitive> primitives) { 
    79             super(primitives); 
    80         } 
    81  
    82         @Override 
    83         protected boolean filter(OsmPrimitive primitive) { 
    84             return primitive.isVisible() && !primitive.isDeleted(); 
    85         } 
    86  
    87     } 
    88  
    89     public static class AllNonDeletedComplete extends DatasetCollection { 
    90  
    91         public AllNonDeletedComplete(Collection<OsmPrimitive> primitives) { 
    92             super(primitives); 
    93         } 
    94  
    95         @Override 
    96         protected boolean filter(OsmPrimitive primitive) { 
    97             return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete(); 
    98         } 
    99  
    100     } 
    101  
    102     public static class AllNonDeletedPhysical extends DatasetCollection { 
    103  
    104         public AllNonDeletedPhysical(Collection<OsmPrimitive> primitives) { 
    105             super(primitives); 
    106         } 
    107  
    108         @Override 
    109         protected boolean filter(OsmPrimitive primitive) { 
    110             return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 
    111         } 
    112  
    113     } 
    114  
    115     public static class AllModified extends DatasetCollection { 
    116  
    117         public AllModified(Collection<OsmPrimitive> primitives) { 
    118             super(primitives); 
    119         } 
    120  
    121         @Override 
    122         protected boolean filter(OsmPrimitive primitive) { 
    123             return primitive.isVisible() && primitive.isModified(); 
    124         } 
    125  
    126     } 
    127  
    12877} 
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r3149 r3177  
    2828import org.openstreetmap.josm.gui.mappaint.ElemStyle; 
    2929import org.openstreetmap.josm.tools.CheckParameterUtil; 
     30import org.openstreetmap.josm.tools.Predicate; 
    3031 
    3132/** 
     
    4748    } 
    4849 
     50    /** 
     51     * This flag shows, that the properties have been changed by the user 
     52     * and on upload the object will be send to the server 
     53     */ 
    4954    private static final int FLAG_MODIFIED = 1 << 0; 
     55 
     56    /** 
     57     * The visible flag indicates, that an object is marked 
     58     * as deleted on the server. 
     59     */ 
    5060    private static final int FLAG_VISIBLE  = 1 << 1; 
     61 
     62    /** 
     63     * An object can be disabled by the filter mechanism. 
     64     * Then it will show in a shade of grey on the map. 
     65     * Disabled objects usually cannot be selected or modified 
     66     * while the filter is active. 
     67     */ 
    5168    private static final int FLAG_DISABLED = 1 << 2; 
     69 
     70    /** 
     71     * An object that was deleted by the user. 
     72     * Deleted objects are usually hidden on the map and a request 
     73     * for deletion will be send to the server on upload. 
     74     * An object usually cannot be deleted if it has non-deleted 
     75     * objects still referring to it. 
     76     */ 
    5277    private static final int FLAG_DELETED  = 1 << 3; 
     78 
     79    /** 
     80     * An object can be filtered by the filter mechanism. 
     81     * Then it will be hidden on the map and usually 
     82     * cannot be selected or modified while the filter is active. 
     83     */ 
    5384    private static final int FLAG_FILTERED = 1 << 4; 
     85 
     86    /** 
     87     * This flag is set if the primitive is a way and 
     88     * according to the tags, the direction of the way is important. 
     89     * (e.g. one way street.) 
     90     */ 
    5491    private static final int FLAG_HAS_DIRECTIONS = 1 << 5; 
     92 
     93    /** 
     94     * If the primitive is tagged. 
     95     * Some trivial tags like source=* are ignored here. 
     96     */ 
    5597    private static final int FLAG_TAGGED = 1 << 6; 
     98 
     99    /** 
     100     * This flag is only relevant if FLAG_HAS_DIRECTIONS is set. 
     101     * It shows, that direction of the arrows should be reversed. 
     102     * (E.g. oneway=-1.) 
     103     */ 
    56104    private static final int FLAG_DIRECTION_REVERSED = 1 << 7; 
     105 
     106    /** 
     107     * When hovering over ways and nodes in add mode, the 
     108     * "target" objects are visually highlighted. This flag indicates 
     109     * that the primitive is currently highlighted. 
     110     */ 
    57111    private static final int FLAG_HIGHLIGHTED = 1 << 8; 
     112 
     113    /** 
     114     * A primitive is incomplete if we know its id and type, but nothing more. 
     115     * Typically some members of a relation are incomplete until they are 
     116     * fetched from the server. 
     117     */ 
    58118    private static final int FLAG_INCOMPLETE = 1 << 9; 
    59119 
     
    329389     */ 
    330390    public boolean isUsable() { 
    331         return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_DISABLED)) == 0; 
     391        return (flags & (FLAG_DELETED + FLAG_INCOMPLETE)) == 0; 
     392    } 
     393 
     394    public boolean isSelectable() { 
     395        return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_DISABLED + FLAG_FILTERED)) == 0; 
    332396    } 
    333397 
     
    335399        return (flags & (FLAG_DELETED + FLAG_INCOMPLETE + FLAG_FILTERED)) == 0; 
    336400    } 
     401 
     402    /** 
     403     * Some predicates, that describe conditions on primitives. 
     404     */ 
     405    public static Predicate<OsmPrimitive> isUsablePredicate = new Predicate<OsmPrimitive>() { 
     406        public boolean evaluate(OsmPrimitive primitive) { 
     407            return primitive.isUsable(); 
     408        } 
     409    }; 
     410 
     411    public static Predicate<OsmPrimitive> isSelectablePredicate = new Predicate<OsmPrimitive>() { 
     412        public boolean evaluate(OsmPrimitive primitive) { 
     413            return primitive.isSelectable(); 
     414        } 
     415    }; 
     416 
     417    public static Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() { 
     418        public boolean evaluate(OsmPrimitive primitive) { 
     419            return primitive.isVisible() && !primitive.isDeleted(); 
     420        } 
     421    }; 
     422 
     423    public static Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() { 
     424        public boolean evaluate(OsmPrimitive primitive) { 
     425            return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete(); 
     426        } 
     427    }; 
     428 
     429    public static Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() { 
     430        public boolean evaluate(OsmPrimitive primitive) { 
     431            return primitive.isVisible() && !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 
     432        } 
     433    }; 
     434 
     435    public static Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() { 
     436        public boolean evaluate(OsmPrimitive primitive) { 
     437            return primitive.isVisible() && primitive.isModified(); 
     438        } 
     439    }; 
    337440 
    338441    /** 
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r2906 r3177  
    193193                        if (middleMouseDown || isAtOldPosition) 
    194194                        { 
    195                             Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos); 
     195                            Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos, OsmPrimitive.isUsablePredicate); 
    196196 
    197197                            if (osms == null) { 
     
    292292         */ 
    293293        private final void statusBarElementUpdate(MouseState ms) { 
    294             final OsmPrimitive osmNearest = mv.getNearest(ms.mousePos); 
     294            final OsmPrimitive osmNearest = mv.getNearest(ms.mousePos, OsmPrimitive.isUsablePredicate); 
    295295            if (osmNearest != null) { 
    296296                nameText.setText(osmNearest.getDisplayName(DefaultNameFormatter.getInstance())); 
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r3116 r3177  
    3232import org.openstreetmap.josm.data.projection.Projection; 
    3333import org.openstreetmap.josm.gui.help.Helpful; 
     34import org.openstreetmap.josm.tools.Predicate; 
    3435 
    3536/** 
     
    426427    } 
    427428 
    428     /** 
    429      * Return the nearest point to the screen point given. 
    430      * If a node within snapDistance pixel is found, the nearest node is returned. 
    431      */ 
     429    @Deprecated 
    432430    public final Node getNearestNode(Point p) { 
     431        return getNearestNode(p, OsmPrimitive.isUsablePredicate); 
     432    } 
     433 
     434    /** 
     435     * Return the nearest node to the screen point given. 
     436     * If more then one node within snapDistance pixel is found, 
     437     * the nearest node is returned. 
     438     * @param p the screen point 
     439     * @param predicate this parameter imposes a condition on the returned object, e.g. 
     440     *        give the nearest node that is tagged. 
     441     */ 
     442    public final Node getNearestNode(Point p, Predicate<OsmPrimitive> predicate) { 
    433443        DataSet ds = getCurrentDataSet(); 
    434444        if (ds == null) 
     
    438448        Node minPrimitive = null; 
    439449        for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 
    440             if (!n.isUsable()) { 
     450            if (! predicate.evaluate(n)) 
    441451                continue; 
    442             } 
    443452            Point sp = getPoint(n); 
    444453            double dist = p.distanceSq(sp); 
     
    462471     * 
    463472     * @param p the point for which to search the nearest segment. 
    464      */ 
    465     public final List<WaySegment> getNearestWaySegments(Point p) { 
     473     * @param predicate the returned objects have to fulfill certain properties. 
     474     */ 
     475    public final List<WaySegment> getNearestWaySegments(Point p, Predicate<OsmPrimitive> predicate) { 
    466476        TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>(); 
    467477        DataSet ds = getCurrentDataSet(); 
     
    470480 
    471481        for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 
    472             if (!w.isUsable()) { 
     482            if (!predicate.evaluate(w)) 
    473483                continue; 
    474             } 
    475484            Node lastN = null; 
    476485            int i = -2; 
    477486            for (Node n : w.getNodes()) { 
    478487                i++; 
    479                 if (n.isDeleted() || n.isIncomplete()) { 
     488                if (n.isDeleted() || n.isIncomplete()) {//FIXME: This shouldn't happen, raise exception? 
    480489                    continue; 
    481490                } 
     
    521530     * @param p the point for which to search the nearest segment. 
    522531     * @param ignore a collection of segments which are not to be returned. 
     532     * @param predicate the returned object has to fulfill certain properties. 
    523533     * May be null. 
    524534     */ 
    525     public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) { 
    526         List<WaySegment> nearest = getNearestWaySegments(p); 
     535    public final WaySegment getNearestWaySegment 
     536                                    (Point p, Collection<WaySegment> ignore, Predicate<OsmPrimitive> predicate) { 
     537        List<WaySegment> nearest = getNearestWaySegments(p, predicate); 
    527538        if(nearest == null) 
    528539            return null; 
     
    536547     * @return the nearest way segment to the screen point given. 
    537548     */ 
    538     public final WaySegment getNearestWaySegment(Point p) { 
    539         return getNearestWaySegment(p, null); 
     549    public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate) { 
     550        return getNearestWaySegment(p, null, predicate); 
     551    } 
     552 
     553    @Deprecated 
     554    public final Way getNearestWay(Point p) { 
     555        return getNearestWay(p, OsmPrimitive.isUsablePredicate); 
    540556    } 
    541557 
     
    543559     * @return the nearest way to the screen point given. 
    544560     */ 
    545     public final Way getNearestWay(Point p) { 
    546         WaySegment nearestWaySeg = getNearestWaySegment(p); 
     561    public final Way getNearestWay(Point p, Predicate<OsmPrimitive> predicate) { 
     562        WaySegment nearestWaySeg = getNearestWaySegment(p, predicate); 
    547563        return nearestWaySeg == null ? null : nearestWaySeg.way; 
    548564    } 
     
    559575     * 
    560576     * @param p The point on screen. 
     577     * @param predicate the returned object has to fulfill certain properties. 
    561578     * @return  The primitive that is nearest to the point p. 
    562579     */ 
    563     public OsmPrimitive getNearest(Point p) { 
    564         OsmPrimitive osm = getNearestNode(p); 
     580    public OsmPrimitive getNearest(Point p, Predicate<OsmPrimitive> predicate) { 
     581        OsmPrimitive osm = getNearestNode(p, predicate); 
    565582        if (osm == null) 
    566583        { 
    567             osm = getNearestWay(p); 
     584            osm = getNearestWay(p, predicate); 
    568585        } 
    569586        return osm; 
     
    573590     * Returns a singleton of the nearest object, or else an empty collection. 
    574591     */ 
    575     public Collection<OsmPrimitive> getNearestCollection(Point p) { 
    576         OsmPrimitive osm = getNearest(p); 
     592    public Collection<OsmPrimitive> getNearestCollection(Point p, Predicate<OsmPrimitive> predicate) { 
     593        OsmPrimitive osm = getNearest(p, predicate); 
    577594        if (osm == null) 
    578595            return Collections.emptySet(); 
     
    588605     *      list is never empty. 
    589606     */ 
    590     public Collection<OsmPrimitive> getAllNearest(Point p) { 
     607    public Collection<OsmPrimitive> getAllNearest(Point p, Predicate<OsmPrimitive> predicate) { 
    591608        Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>(); 
    592609        DataSet ds = getCurrentDataSet(); 
     
    594611            return null; 
    595612        for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 
    596             if (!w.isUsable()) { 
     613            if (!predicate.evaluate(w)) 
    597614                continue; 
    598             } 
    599615            Node lastN = null; 
    600616            for (Node n : w.getNodes()) { 
    601                 if (!n.isUsable()) { 
     617                if (!predicate.evaluate(n)) 
    602618                    continue; 
    603                 } 
    604619                if (lastN == null) { 
    605620                    lastN = n; 
     
    636651     *      list is never empty. 
    637652     */ 
    638     public Collection<Node> getNearestNodes(Point p) { 
     653    public Collection<Node> getNearestNodes(Point p, Predicate<OsmPrimitive> predicate) { 
    639654        Collection<Node> nearest = new HashSet<Node>(); 
    640655        DataSet ds = getCurrentDataSet(); 
     
    643658 
    644659        for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 
    645             if (n.isUsable() 
    646                     && getPoint(n).distanceSq(p) < snapDistanceSq) { 
     660            if (!predicate.evaluate(n)) 
     661                continue; 
     662            if (getPoint(n).distanceSq(p) < snapDistanceSq) { 
    647663                nearest.add(n); 
    648664            } 
     
    657673     * @param p the point for which to search the nearest segment. 
    658674     * @param ignore a collection of nodes which are not to be returned. 
     675     * @param predicate the returned objects have to fulfill certain properties. 
    659676     * May be null. 
    660677     */ 
    661     public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) { 
    662         Collection<Node> nearest = getNearestNodes(p); 
     678    public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore, Predicate<OsmPrimitive> predicate) { 
     679        Collection<Node> nearest = getNearestNodes(p, predicate); 
    663680        if (nearest == null) return null; 
    664681        if (ignore != null) { 
  • trunk/src/org/openstreetmap/josm/gui/SelectionManager.java

    r2578 r3177  
    277277 
    278278        if (clicked) { 
    279             OsmPrimitive osm = nc.getNearest(center); 
     279            OsmPrimitive osm = nc.getNearest(center, OsmPrimitive.isSelectablePredicate); 
    280280            if (osm != null) { 
    281281                selection.add(osm); 
Note: See TracChangeset for help on using the changeset viewer.