Changeset 27998 in osm for applications/editors/josm/plugins
- Timestamp:
- 2012-03-06T11:17:12+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r27859 r27998 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- 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)"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4980"/> -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
r27936 r27998 2 2 package utilsplugin2; 3 3 4 import org.openstreetmap.josm.data.osm.Node; 4 5 import utilsplugin2.customurl.ChooseURLAction; 5 6 import utilsplugin2.customurl.OpenPageAction; … … 151 152 public static class UtilsUnaryMatchFactory implements UnaryMatchFactory { 152 153 private static Collection<String> keywords = Arrays.asList("inside", 153 "intersecting", "allintersecting" );154 "intersecting", "allintersecting", "adjacent", "connected"); 154 155 155 156 @Override … … 157 158 if ("inside".equals(keyword)) 158 159 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); 159 164 else if ("intersecting".equals(keyword)) 160 165 return new IntersectingMatch(matchOperand, false); … … 178 183 public InsideMatch(Match match) { 179 184 super(match); 180 init();185 //init(); 181 186 } 182 187 … … 185 190 */ 186 191 private void init() { 192 if (inside==null) init(); // lazy initialization 187 193 Collection<OsmPrimitive> matchedAreas = new HashSet<OsmPrimitive>(); 188 194 … … 212 218 public static class IntersectingMatch extends UnaryMatch { 213 219 private Collection<Way> intersecting = null; 220 boolean all; 214 221 215 222 public IntersectingMatch(Match match, boolean all) { 216 223 super(match); 217 init(all); 224 this.all=all; 225 //init(all); 218 226 } 219 227 … … 241 249 @Override 242 250 public boolean match(OsmPrimitive osm) { 251 if (intersecting==null) init(all); // lazy initialization 243 252 if (osm instanceof Way) 244 253 return intersecting.contains((Way)osm); … … 246 255 } 247 256 } 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 248 308 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/AdjacentWaysAction.java
r27852 r27998 38 38 // select ways attached to already selected ways 39 39 Set<Way> newWays = new HashSet<Way>(); 40 NodeWayUtils.addWaysConnectedToWays(selectedWays, newWays); 40 41 newWays.addAll(selectedWays); 41 for (Way w : selectedWays){42 NodeWayUtils.addWaysConnectedToWay(w, newWays);43 }44 42 45 43 // selecting ways attached to selected nodes -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/NodeWayUtils.java
r27936 r27998 30 30 public final class NodeWayUtils { 31 31 32 static final int maxLevel = Main.pref.getInteger("selection.maxrecursion", 5);32 static final int maxLevel = Main.pref.getInteger("selection.maxrecursion", 15); 33 33 static final int maxWays = Main.pref.getInteger("selection.maxfoundways", 2000); 34 34 static final int maxWays1 = Main.pref.getInteger("selection.maxfoundways.intersection", 500); … … 73 73 int s = ways.size(); 74 74 List<Node> nodes = w.getNodes(); 75 boolean flag = ways.contains(w); 75 76 for (Node n: nodes) { 76 77 ways.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)); 77 78 } 79 if (!flag) ways.remove(w); 78 80 return ways.size() - s; 79 81 } … … 155 157 return count; 156 158 } 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) { 159 167 int s = newWays.size(); 160 168 for (Node node: selectedNodes) { … … 164 172 } 165 173 166 static int addNodesConnectedToWays(Set<Way> initWays, Set<Node> newNodes) {174 public static int addNodesConnectedToWays(Set<Way> initWays, Set<Node> newNodes) { 167 175 int s = newNodes.size(); 168 176 for (Way w: initWays) { … … 202 210 } 203 211 204 static void addWaysConnectedToWaysRecursively212 public static void addWaysConnectedToWaysRecursively 205 213 (Collection<Way> initWays, Set<Way> newWays) 206 214 { … … 493 501 494 502 503 495 504 }
Note:
See TracChangeset
for help on using the changeset viewer.