Changeset 23100 in osm for applications
- Timestamp:
- 2010-09-10T21:24:17+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/wayselector
- Files:
-
- 2 edited
-
build.xml (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wayselector/build.xml
r21706 r23100 31 31 32 32 <!-- enter the SVN commit message --> 33 <property name="commit.message" value=" Adjust to read-only JOSM selection object" />33 <property name="commit.message" value="Do not mutate the collection of selected ways. Convert TAB to spaces." /> 34 34 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 35 35 <property name="plugin.main.version" value="3095" /> -
applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java
r20784 r23100 18 18 */ 19 19 public class WaySelection { 20 /** selected ways */21 Collection<Way> ways;22 20 /** outer endpoints of selected ways */ 23 21 TreeSet<Node> outerNodes; … … 28 26 @param[in] selection a selection of ways 29 27 */ 30 public WaySelection(Collection<Way> ways) { 31 this.ways = ways; 32 outerNodes = null; 33 nodes = null; 28 public WaySelection(final Collection<Way> ways) { 29 if (ways.isEmpty()) { 30 // The selection cannot be extended. 31 outerNodes = null; 32 nodes = null; 33 } 34 else { 35 nodes = new TreeSet<Node>(); 36 outerNodes = new TreeSet<Node>(); 37 38 for (Way way : ways) 39 addNodes(way); 40 } 34 41 } 35 42 … … 38 45 private void addNodes(Node node) { 39 46 if (node == null); 40 else if (!nodes.add(node))41 outerNodes.remove(node);42 else43 outerNodes.add(node);47 else if (!nodes.add(node)) 48 outerNodes.remove(node); 49 else 50 outerNodes.add(node); 44 51 } 45 52 … … 48 55 private void addNodes(Way way) { 49 56 addNodes(way.firstNode()); 50 addNodes(way.lastNode());57 addNodes(way.lastNode()); 51 58 } 52 59 … … 54 61 @return true if the selection can be extended */ 55 62 public boolean canExtend() { 56 if (ways.isEmpty()) 57 return false; 58 59 nodes = new TreeSet<Node>(); 60 outerNodes = new TreeSet<Node>(); 61 62 for (Way way : ways) 63 addNodes(way); 64 65 return !outerNodes.isEmpty(); 63 return outerNodes != null && !outerNodes.isEmpty(); 66 64 } 67 65 … … 75 73 76 74 for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), 77 Way.class))78 if (way.getNodesCount() >= 2 && !selection.contains(way) &&79 way.isFirstLastNode(node))75 Way.class)) 76 if (way.getNodesCount() >= 2 && !selection.contains(way) && 77 way.isFirstLastNode(node)) 80 78 foundWays.add(way); 81 79 82 return foundWays.size() == 1 ? foundWays.first() : null;80 return foundWays.size() == 1 ? foundWays.first() : null; 83 81 } 84 82 … … 86 84 Finds out if the current selection can be extended. 87 85 88 The members ways, outerNodes, nodes must have been 89 initialized; @see canExtend(). How to update these 90 members when extending the selection, @see extend(). 86 The members outerNodes, nodes must have been initialized. 87 How to update these members when extending the selection, @see extend(). 91 88 @param selection current selection 92 89 @return a way by which to extend the selection, or null */ 93 90 private Way findWay(Collection<OsmPrimitive> selection) { 94 for (Node node : outerNodes) {95 Way way = findWay(selection, node);96 if (way != null)97 return way;98 }91 for (Node node : outerNodes) { 92 Way way = findWay(selection, node); 93 if (way != null) 94 return way; 95 } 99 96 100 return null;97 return null; 101 98 } 102 99 … … 104 101 @param data the data set in which to extend the selection */ 105 102 void extend(DataSet data) { 106 Collection<OsmPrimitive> currentSelection;107 LinkedList<OsmPrimitive> selection;108 boolean selectionChanged = false;103 Collection<OsmPrimitive> currentSelection; 104 LinkedList<OsmPrimitive> selection; 105 boolean selectionChanged = false; 109 106 Way way; 110 107 111 108 if (!canExtend()) 112 return;109 return; 113 110 114 currentSelection = data.getSelected();111 currentSelection = data.getSelected(); 115 112 116 way = findWay(currentSelection);113 way = findWay(currentSelection); 117 114 118 if (way == null)119 return;115 if (way == null) 116 return; 120 117 121 selection = new LinkedList<OsmPrimitive>();122 for (OsmPrimitive primitive : currentSelection)123 selection.add(primitive);118 selection = new LinkedList<OsmPrimitive>(); 119 for (OsmPrimitive primitive : currentSelection) 120 selection.add(primitive); 124 121 125 do {126 if (!selection.add(way))127 break;122 do { 123 if (!selection.add(way)) 124 break; 128 125 129 selectionChanged = true; 130 ways.add(way); 131 addNodes(way); 126 selectionChanged = true; 127 addNodes(way); 132 128 133 way = findWay(selection);134 } while (way != null);129 way = findWay(selection); 130 } while (way != null); 135 131 136 if (selectionChanged)137 data.setSelected(selection, true);132 if (selectionChanged) 133 data.setSelected(selection, true); 138 134 } 139 135 }
Note:
See TracChangeset
for help on using the changeset viewer.
