Changeset 23100 in osm for applications/editors/josm/plugins/wayselector/src
- Timestamp:
- 2010-09-10T21:24:17+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 41 42 43 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 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 78 79 75 Way.class)) 76 if (way.getNodesCount() >= 2 && !selection.contains(way) && 77 way.isFirstLastNode(node)) 80 78 foundWays.add(way); 81 79 82 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 95 96 97 98 91 for (Node node : outerNodes) { 92 Way way = findWay(selection, node); 93 if (way != null) 94 return way; 95 } 99 96 100 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 107 108 103 Collection<OsmPrimitive> currentSelection; 104 LinkedList<OsmPrimitive> selection; 105 boolean selectionChanged = false; 109 106 Way way; 110 107 111 108 if (!canExtend()) 112 109 return; 113 110 114 111 currentSelection = data.getSelected(); 115 112 116 113 way = findWay(currentSelection); 117 114 118 119 115 if (way == null) 116 return; 120 117 121 122 123 118 selection = new LinkedList<OsmPrimitive>(); 119 for (OsmPrimitive primitive : currentSelection) 120 selection.add(primitive); 124 121 125 126 127 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 134 129 way = findWay(selection); 130 } while (way != null); 135 131 136 137 132 if (selectionChanged) 133 data.setSelected(selection, true); 138 134 } 139 135 }
Note:
See TracChangeset
for help on using the changeset viewer.