Ignore:
Timestamp:
2012-03-06T11:17:12+01:00 (13 years ago)
Author:
akks
Message:

'Utilsplugin2: search speed-up, added adjacent and connected keywords (search for ways only)'

Location:
applications/editors/josm/plugins/utilsplugin2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/build.xml

    r27859 r27998  
    3030<project name="utilsplugin2" default="dist" basedir=".">
    3131    <!-- enter the SVN commit message -->
    32     <property name="commit.message" value="Utilsplugin2: fixing shortcut conflicts, one better key"/>
     32    <property name="commit.message" value="Utilsplugin2: search speed-up, added adjacent and connected keywords (search for ways only)"/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    3434    <property name="plugin.main.version" value="4980"/>
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java

    r27936 r27998  
    22package utilsplugin2;
    33
     4import org.openstreetmap.josm.data.osm.Node;
    45import utilsplugin2.customurl.ChooseURLAction;
    56import utilsplugin2.customurl.OpenPageAction;
     
    151152    public static class UtilsUnaryMatchFactory implements UnaryMatchFactory {
    152153        private static Collection<String> keywords = Arrays.asList("inside",
    153                 "intersecting", "allintersecting");
     154                "intersecting", "allintersecting", "adjacent", "connected");
    154155       
    155156        @Override
     
    157158            if ("inside".equals(keyword))
    158159                return new InsideMatch(matchOperand);
     160            else if ("adjacent".equals(keyword))
     161                return new ConnectedMatch(matchOperand, false);
     162            else if ("connected".equals(keyword))
     163                return new ConnectedMatch(matchOperand, true);
    159164            else if ("intersecting".equals(keyword))
    160165                return new IntersectingMatch(matchOperand, false);
     
    178183        public InsideMatch(Match match) {
    179184            super(match);
    180             init();
     185            //init();
    181186        }
    182187       
     
    185190         */
    186191        private void init() {
     192            if (inside==null) init(); // lazy initialization
    187193            Collection<OsmPrimitive> matchedAreas = new HashSet<OsmPrimitive>();
    188194
     
    212218    public static class IntersectingMatch extends UnaryMatch {
    213219        private Collection<Way> intersecting = null;
     220        boolean all;
    214221       
    215222        public IntersectingMatch(Match match, boolean all) {
    216223            super(match);
    217             init(all);
     224            this.all=all;
     225            //init(all);
    218226        }   
    219227       
     
    241249        @Override
    242250        public boolean match(OsmPrimitive osm) {
     251            if (intersecting==null) init(all); // lazy initialization
    243252            if (osm instanceof Way)
    244253                return intersecting.contains((Way)osm);
     
    246255        }
    247256    }
     257   
     258    public static class ConnectedMatch extends UnaryMatch {
     259        private Collection<Way> connected = null;
     260        boolean all;
     261       
     262        public ConnectedMatch(Match match, boolean all) {
     263            super(match);
     264            this.all=all;
     265        }   
     266       
     267        /**
     268         * Find (all) ways intersecting ways which match the expression.
     269         */
     270        private void init(boolean all) {
     271            Collection<Way> matchedWays = new HashSet<Way>();
     272            Set<Node> matchedNodes = new HashSet<Node>();
     273           
     274            // find all ways that match the expression
     275            Collection<Way> allWays = Main.main.getCurrentDataSet().getWays();
     276            for (Way way : allWays) {
     277                if (match.match(way))
     278                    matchedWays.add(way);
     279            }
     280           
     281            // find all nodes that match the expression
     282            Collection<Node> allNodes = Main.main.getCurrentDataSet().getNodes();
     283            for (Node node: allNodes) {
     284                if (match.match(node))
     285                    matchedNodes.add(node);
     286            }
     287           
     288            Set<Way> newWays = new HashSet<Way>();
     289            if (all) {
     290                NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
     291                NodeWayUtils.addWaysConnectedToWaysRecursively(matchedWays, newWays);
     292            } else {
     293                NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
     294                NodeWayUtils.addWaysConnectedToWays(matchedWays, newWays);
     295            }
     296            connected = newWays;
     297        }
     298       
     299        @Override
     300        public boolean match(OsmPrimitive osm) {
     301            if (connected==null) init(all); // lazy initialization
     302            if (osm instanceof Way)
     303                return connected.contains((Way)osm);
     304            return false;
     305        }
     306    }   
     307   
    248308}
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/AdjacentWaysAction.java

    r27852 r27998  
    3838        // select ways attached to already selected ways
    3939        Set<Way> newWays = new HashSet<Way>();
     40        NodeWayUtils.addWaysConnectedToWays(selectedWays, newWays);
    4041        newWays.addAll(selectedWays);
    41         for (Way w : selectedWays){
    42             NodeWayUtils.addWaysConnectedToWay(w, newWays);
    43         }
    4442
    4543        // selecting ways attached to selected nodes
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java

    r27936 r27998  
    3030public final class NodeWayUtils {
    3131
    32     static final int maxLevel = Main.pref.getInteger("selection.maxrecursion", 5);
     32    static final int maxLevel = Main.pref.getInteger("selection.maxrecursion", 15);
    3333    static final int maxWays = Main.pref.getInteger("selection.maxfoundways", 2000);
    3434    static final int maxWays1 = Main.pref.getInteger("selection.maxfoundways.intersection", 500);
     
    7373         int s = ways.size();
    7474        List<Node> nodes = w.getNodes();
     75        boolean flag = ways.contains(w);
    7576        for (Node n: nodes) {
    7677            ways.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));
    7778        }
     79        if (!flag) ways.remove(w);
    7880        return ways.size() - s;
    7981    }
     
    155157        return count;
    156158    }
    157 
    158     static int addWaysConnectedToNodes(Set<Node> selectedNodes, Set<Way> newWays) {
     159   
     160    public static void addWaysConnectedToWays(Collection<Way> ways, Set<Way> newWays) {
     161        for (Way w : ways){
     162            NodeWayUtils.addWaysConnectedToWay(w, newWays);
     163        }
     164    }
     165
     166    public static int addWaysConnectedToNodes(Set<Node> selectedNodes, Set<Way> newWays) {
    159167        int s = newWays.size();
    160168        for (Node node: selectedNodes) {
     
    164172    }
    165173
    166     static int addNodesConnectedToWays(Set<Way> initWays, Set<Node> newNodes) {
     174    public static int addNodesConnectedToWays(Set<Way> initWays, Set<Node> newNodes) {
    167175        int s = newNodes.size();
    168176        for (Way w: initWays) {
     
    202210    }
    203211
    204  static void addWaysConnectedToWaysRecursively
     212    public static void addWaysConnectedToWaysRecursively
    205213            (Collection<Way> initWays, Set<Way> newWays)
    206214    {
     
    493501
    494502
     503
    495504}
Note: See TracChangeset for help on using the changeset viewer.