Changeset 30200 in osm for applications/editors/josm/plugins
- Timestamp:
- 2014-01-13T17:02:07+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r30177 r30200 3 3 4 4 <!-- enter the SVN commit message --> 5 <property name="commit.message" value="[josm_utilsplugin2]: Use notifications instead of MessageBoxes"/>5 <property name="commit.message" value="[josm_utilsplugin2]: move search classes to separate package, inside now finds both node and ways"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 7 <property name="plugin.main.version" value="6317"/> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java
r30002 r30200 2 2 package org.openstreetmap.josm.plugins.utilsplugin2; 3 3 4 import java.util.Arrays;5 import java.util.Collection;6 import java.util.HashSet;7 import java.util.Set;8 4 9 5 import javax.swing.JMenu; … … 11 7 12 8 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.actions.search.PushbackTokenizer;14 9 import org.openstreetmap.josm.actions.search.SearchCompiler; 15 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;16 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;17 import org.openstreetmap.josm.actions.search.SearchCompiler.UnaryMatch;18 import org.openstreetmap.josm.actions.search.SearchCompiler.UnaryMatchFactory;19 import org.openstreetmap.josm.data.osm.Node;20 import org.openstreetmap.josm.data.osm.OsmPrimitive;21 import org.openstreetmap.josm.data.osm.Relation;22 import org.openstreetmap.josm.data.osm.Way;23 10 import org.openstreetmap.josm.gui.MainMenu; 24 11 import org.openstreetmap.josm.gui.MapFrame; … … 42 29 import org.openstreetmap.josm.plugins.utilsplugin2.latlon.LatLonAction; 43 30 import org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry.ReplaceGeometryAction; 31 import org.openstreetmap.josm.plugins.utilsplugin2.search.UtilsUnaryMatchFactory; 44 32 import org.openstreetmap.josm.plugins.utilsplugin2.selection.AdjacentNodesAction; 45 33 import org.openstreetmap.josm.plugins.utilsplugin2.selection.AdjacentWaysAction; … … 48 36 import org.openstreetmap.josm.plugins.utilsplugin2.selection.IntersectedWaysRecursiveAction; 49 37 import org.openstreetmap.josm.plugins.utilsplugin2.selection.MiddleNodesAction; 50 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;51 38 import org.openstreetmap.josm.plugins.utilsplugin2.selection.SelectAllInsideAction; 52 39 import org.openstreetmap.josm.plugins.utilsplugin2.selection.SelectBoundaryAction; … … 175 162 } 176 163 177 public static class UtilsUnaryMatchFactory implements UnaryMatchFactory { 178 private static Collection<String> keywords = Arrays.asList("inside", 179 "intersecting", "allintersecting", "adjacent", "connected"); 180 181 @Override 182 public UnaryMatch get(String keyword, Match matchOperand, PushbackTokenizer tokenizer) throws ParseError { 183 if ("inside".equals(keyword)) 184 return new InsideMatch(matchOperand); 185 else if ("adjacent".equals(keyword)) 186 return new ConnectedMatch(matchOperand, false); 187 else if ("connected".equals(keyword)) 188 return new ConnectedMatch(matchOperand, true); 189 else if ("intersecting".equals(keyword)) 190 return new IntersectingMatch(matchOperand, false); 191 else if ("allintersecting".equals(keyword)) 192 return new IntersectingMatch(matchOperand, true); 193 return null; 194 } 195 196 @Override 197 public Collection<String> getKeywords() { 198 return keywords; 199 } 200 } 201 202 /** 203 * Matches all objects contained within the match expression. 204 */ 205 public static class InsideMatch extends UnaryMatch { 206 private Collection<OsmPrimitive> inside = null; 207 208 public InsideMatch(Match match) { 209 super(match); 210 } 211 212 /** 213 * Find all objects inside areas which match the expression 214 */ 215 private void init() { 216 Collection<OsmPrimitive> matchedAreas = new HashSet<OsmPrimitive>(); 217 218 // find all ways that match the expression 219 Collection<Way> ways = Main.main.getCurrentDataSet().getWays(); 220 for (Way way : ways) { 221 if (match.match(way)) 222 matchedAreas.add(way); 223 } 224 225 // find all relations that match the expression 226 Collection<Relation> rels = Main.main.getCurrentDataSet().getRelations(); 227 for (Relation rel : rels) { 228 if (match.match(rel)) 229 matchedAreas.add(rel); 230 } 231 232 inside = NodeWayUtils.selectAllInside(matchedAreas, Main.main.getCurrentDataSet()); 233 } 234 235 @Override 236 public boolean match(OsmPrimitive osm) { 237 if (inside == null) 238 init(); // lazy initialization 239 240 return inside.contains(osm); 241 } 242 } 243 244 public static class IntersectingMatch extends UnaryMatch { 245 private Collection<Way> intersecting = null; 246 boolean all; 247 248 public IntersectingMatch(Match match, boolean all) { 249 super(match); 250 this.all=all; 251 //init(all); 252 } 253 254 /** 255 * Find (all) ways intersecting ways which match the expression. 256 */ 257 private void init(boolean all) { 258 Collection<Way> matchedWays = new HashSet<Way>(); 259 260 // find all ways that match the expression 261 Collection<Way> allWays = Main.main.getCurrentDataSet().getWays(); 262 for (Way way : allWays) { 263 if (match.match(way)) 264 matchedWays.add(way); 265 } 266 267 Set<Way> newWays = new HashSet<Way>(); 268 if (all) 269 NodeWayUtils.addWaysIntersectingWaysRecursively(allWays, matchedWays, newWays); 270 else 271 NodeWayUtils.addWaysIntersectingWays(allWays, matchedWays, newWays); 272 intersecting = newWays; 273 } 274 275 @Override 276 public boolean match(OsmPrimitive osm) { 277 if (intersecting==null) init(all); // lazy initialization 278 if (osm instanceof Way) 279 return intersecting.contains((Way)osm); 280 return false; 281 } 282 } 283 284 public static class ConnectedMatch extends UnaryMatch { 285 private Collection<Way> connected = null; 286 boolean all; 287 288 public ConnectedMatch(Match match, boolean all) { 289 super(match); 290 this.all=all; 291 } 292 293 /** 294 * Find (all) ways intersecting ways which match the expression. 295 */ 296 private void init(boolean all) { 297 Collection<Way> matchedWays = new HashSet<Way>(); 298 Set<Node> matchedNodes = new HashSet<Node>(); 299 300 // find all ways that match the expression 301 Collection<Way> allWays = Main.main.getCurrentDataSet().getWays(); 302 for (Way way : allWays) { 303 if (match.match(way)) 304 matchedWays.add(way); 305 } 306 307 // find all nodes that match the expression 308 Collection<Node> allNodes = Main.main.getCurrentDataSet().getNodes(); 309 for (Node node: allNodes) { 310 if (match.match(node)) 311 matchedNodes.add(node); 312 } 313 314 Set<Way> newWays = new HashSet<Way>(); 315 if (all) { 316 NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays); 317 NodeWayUtils.addWaysConnectedToWaysRecursively(matchedWays, newWays); 318 } else { 319 NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays); 320 NodeWayUtils.addWaysConnectedToWays(matchedWays, newWays); 321 } 322 connected = newWays; 323 } 324 325 @Override 326 public boolean match(OsmPrimitive osm) { 327 if (connected==null) init(all); // lazy initialization 328 if (osm instanceof Way) 329 return connected.contains((Way)osm); 330 return false; 331 } 332 } 164 333 165 334 166 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r30177 r30200 408 408 newestWays.add(w); 409 409 } 410 }411 for (Way w : newestWays) {412 newestNodes.removeAll(w.getNodes());413 // do not select nodes of already selected ways414 410 } 415 411 … … 474 470 475 471 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset) { 472 return selectAllInside(selected, dataset, true); 473 } 474 475 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset, boolean ignoreNodesOfFoundWays) { 476 476 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(selected, Way.class); 477 477 Set<Relation> selectedRels = OsmPrimitive.getFilteredSet(selected, Relation.class); … … 486 486 Set<Way> newWays = new HashSet<Way>(); 487 487 Set<Node> newNodes = new HashSet<Node>(); 488 // select ways attached to already selected ways488 // select nodes and ways inside slexcted ways and multipolygons 489 489 if (!selectedWays.isEmpty()) { 490 490 for (Way w: selectedWays) { … … 496 496 addAllInsideMultipolygon(dataset,r,newWays,newNodes); 497 497 } 498 } 499 if (ignoreNodesOfFoundWays) { 500 for (Way w : newWays) { 501 newNodes.removeAll(w.getNodes()); 502 // do not select nodes of already selected ways 503 } 498 504 } 499 505 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java
r30177 r30200 32 32 @Override 33 33 public void actionPerformed(ActionEvent e) { 34 Collection<OsmPrimitive> insideSelected = NodeWayUtils.selectAllInside(getCurrentDataSet().getSelected(), getCurrentDataSet() );34 Collection<OsmPrimitive> insideSelected = NodeWayUtils.selectAllInside(getCurrentDataSet().getSelected(), getCurrentDataSet(), true); 35 35 36 36 if (!insideSelected.isEmpty()) {
Note:
See TracChangeset
for help on using the changeset viewer.