Changeset 34812 in osm for applications/editors/josm/plugins/utilsplugin2
- Timestamp:
- 2019-01-11T11:01:03+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AddIntersectionsAction.java
r34454 r34812 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.HashSet; … … 47 48 if (!isEnabled()) 48 49 return; 49 List<Way> ways = OsmPrimitive.getFilteredList(getLayerManager().getEditDataSet().getSelected(), Way.class);50 List<Way> ways = new ArrayList<>(getLayerManager().getEditDataSet().getSelectedWays()); 50 51 if (ways.isEmpty()) { 51 52 new Notification( -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java
r34454 r34812 115 115 double m1 = (by - ay) / (bx - ax); 116 116 double c1 = ay - (ax * m1); 117 double m2 = (-1)/ m1;117 double m2 = -1.0 / m1; 118 118 double c2 = ny - (nx * m2); 119 119 … … 146 146 Set<Way> ways = null; 147 147 for (Node n : nodes.stream().filter(n -> n.getDataSet() != null).collect(Collectors.toList())) { 148 List<Way> referrers = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);149 148 if (ways == null) 150 ways = new HashSet<>( referrers);149 ways = new HashSet<>(n.getParentWays()); 151 150 else { 152 ways.retainAll( referrers);151 ways.retainAll(n.getParentWays()); 153 152 } 154 153 } … … 171 170 * 172 171 * TODO: not the maximum node count, but maximum distance! 172 * @param way the way 173 * @param nodes the selected nodes 174 * @return the index of the node right after the largest empty span 173 175 */ 174 176 private int findFirstNode(Way way, Set<Node> nodes) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/ExtractPointAction.java
r34454 r34812 48 48 public void actionPerformed(ActionEvent e) { 49 49 DataSet ds = getLayerManager().getEditDataSet(); 50 Collection<OsmPrimitive> selection = ds.getSelected(); 51 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 50 Collection<Node> selectedNodes = ds.getSelectedNodes(); 52 51 if (selectedNodes.size() != 1) { 53 52 new Notification(tr("This tool extracts node from its ways and requires single node to be selected.")) … … 55 54 return; 56 55 } 57 Node nd = selectedNodes. get(0);56 Node nd = selectedNodes.iterator().next(); 58 57 Node ndCopy = new Node(nd.getCoor()); 59 58 List<Command> cmds = new LinkedList<>(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java
r34454 r34812 28 28 import org.openstreetmap.josm.tools.Logging; 29 29 import org.openstreetmap.josm.tools.Shortcut; 30 import org.openstreetmap.josm.tools.Utils; 30 31 31 32 /** … … 59 60 OsmPrimitive p = getLayerManager().getEditDataSet().getPrimitiveById(pdata.getUniqueId(), pdata.getType()); 60 61 if (p != null) { 61 for (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {62 for (Relation r : Utils.filteredCollection(p.getReferrers(), Relation.class)) { 62 63 String role = relations.get(r); 63 64 for (RelationMember m : r.getMembers()) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java
r34778 r34812 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; 10 import java.util.ArrayList; 10 11 import java.util.Collection; 11 12 import java.util.Collections; … … 22 23 import org.openstreetmap.josm.command.SplitWayCommand; 23 24 import org.openstreetmap.josm.data.UndoRedoHandler; 25 import org.openstreetmap.josm.data.osm.DataSet; 24 26 import org.openstreetmap.josm.data.osm.Node; 25 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 56 58 @Override 57 59 public void actionPerformed(ActionEvent e) { 58 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 59 60 List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class); 61 List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class); 62 63 if (!checkSelection(selection)) { 60 DataSet ds = getLayerManager().getEditDataSet(); 61 if (!checkSelection(ds.getSelected())) { 64 62 showWarningNotification(tr("The current selection cannot be used for splitting.")); 65 63 return; 66 64 } 65 66 List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes()); 67 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays()); 67 68 68 69 Way selectedWay = null; … … 92 93 Map<Way, Integer> wayOccurenceCounter = new HashMap<>(); 93 94 for (Node n : selectedNodes) { 94 for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) {95 for (Way w : n.getParentWays()) { 95 96 if (!w.isUsable()) { 96 97 continue; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java
r34790 r34812 46 46 public void actionPerformed(ActionEvent e) { 47 47 List<Command> list = new ArrayList<>(); 48 List<Way> selectedWays = OsmPrimitive.getFilteredList(getLayerManager().getEditDataSet().getSelected(), Way.class);48 List<Way> selectedWays = new ArrayList<>(getLayerManager().getEditDataSet().getSelectedWays()); 49 49 Map<Way, List<Node>> splitWays = new HashMap<>(); 50 50 … … 52 52 if (way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed()) 53 53 for (Node node : new Node[] {way.getNode(0), way.getNode(way.getNodesCount() - 1)}) { 54 List<Way> refs = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class);54 List<Way> refs = node.getParentWays(); 55 55 refs.remove(way); 56 56 if (selectedWays.size() > 1) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SymmetryAction.java
r34454 r34812 31 31 * Note: If a ways are selected, their nodes are mirrored 32 32 * 33 * @author Alexei Kasatkin, based on much copy &Paste from other MirrorAction :)33 * @author Alexei Kasatkin, based on much copy+paste from other MirrorAction :) 34 34 */ 35 35 public final class SymmetryAction extends JosmAction { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
r34793 r34812 87 87 88 88 /** 89 * Find those tags which appear in all primitives of the selection89 * Find those tags which appear in all tagged primitives of the selection. 90 90 * @param selection the selection 91 * @return the common tags of all tagged primitives in the selection 91 92 */ 92 93 private static TagCollection getCommonTags(List<OsmPrimitive> selection) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java
r34454 r34812 24 24 import org.openstreetmap.josm.plugins.utilsplugin2.command.ChangeRelationMemberCommand; 25 25 import org.openstreetmap.josm.tools.Shortcut; 26 import org.openstreetmap.josm.tools.Utils; 26 27 27 28 /** … … 58 59 for (OsmPrimitive p : selection) { 59 60 boolean first = true; 60 for (Relation relation : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {61 for (Relation relation : Utils.filteredCollection(p.getReferrers(), Relation.class)) { 61 62 if (relation.isDeleted()) { 62 63 continue; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CircleArcMaker.java
r34454 r34812 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 21 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive;23 22 import org.openstreetmap.josm.data.osm.Way; 24 23 import org.openstreetmap.josm.gui.MainApplication; … … 57 56 Node n1 = null, n2 = null, n3 = null; 58 57 59 if (false) {60 int nodeCount = selectedNodes.size();61 int wayCount = selectedWays.size();62 63 // TODO: filter garbage nodes based on selected ways64 65 // Never interested in more than 3 nodes. Nodes prioritized by reverse selection order, but keep their order.66 // TODO: replace by helper function (eg. getPostFixList(int count))67 Node[] nodesOfInterest = new Node[3];68 int nodesOfInterestCount = Math.min(nodeCount, 3);69 for (int i = nodesOfInterestCount - 1; i >= 0; i--) {70 nodesOfInterest[i] = selectedNodes.get(nodeCount - 1 - i);71 }72 }73 74 58 Set<Way> targetWays = new HashSet<>(); 75 59 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); … … 125 109 126 110 for (Node n : consideredNodes) { 127 targetWays.addAll( OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));111 targetWays.addAll(n.getParentWays()); 128 112 } 129 113 } … … 222 206 * Return a list of coordinates lying an the circle arc determined by n1, n2 and n3. 223 207 * The order of the list and which of the 3 possible arcs to construct are given by the order of n1, n2, n3 224 * 225 * @param includeAnchors include the anchorpoints in the list. The original objects will be used, not copies. 208 * @param p1 n1 209 * @param p2 n2 210 * @param p3 n3 211 * @param angleSeparation maximum angle separation between the arc points 212 * @param includeAnchors include the anchor points in the list. The original objects will be used, not copies. 226 213 * If {@code false}, p2 will be replaced by the closest arcpoint. 227 214 * @param anchor2Index if non-null, it's value will be set to p2's index in the returned list. 228 * @ param angleSparation maximum angle separation between the arc points215 * @return list of coordinates lying an the circle arc determined by n1, n2 and n3 229 216 */ 230 217 private static List<EastNorth> circleArcPoints(EastNorth p1, EastNorth p2, EastNorth p3, … … 297 284 assert (closestIndexToP2 != 0); 298 285 299 double a = direction * (stepLength);286 double a = direction * stepLength; 300 287 points.add(p1); 301 288 if (indexJustBeforeP2 == 0 && includeAnchors) { … … 330 317 331 318 /** 332 * Normalizes {@code a} so it is between 0 and 2 PI 319 * Normalizes {@code angle} so it is between 0 and 2 PI 320 * @param angle the angle 321 * @return the normalized angle 333 322 */ 334 323 private static double normalizeAngle(double angle) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/OpenPageAction.java
r34454 r34812 26 26 27 27 /** 28 * Mirror the selected ways nodes or ways along line given by two first selected points29 28 * 30 * Note: If a ways are selected, their nodes are mirrored29 * Open custom URL 31 30 * 32 * @author Alexei Kasatkin , based on much copy&Paste from other MirrorAction :)31 * @author Alexei Kasatkin 33 32 */ 34 33 public final class OpenPageAction extends JosmAction { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java
r34454 r34812 19 19 20 20 /** 21 * Replaces already existing object (id >0) with a new object (id<0).21 * Replaces already existing object (id>0) with a new object (id<0). 22 22 * 23 23 * @author Zverik -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r34454 r34812 107 107 */ 108 108 public static ReplaceGeometryCommand buildReplaceNodeCommand(Node subjectNode, Node referenceNode) { 109 if (! OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) {109 if (!subjectNode.getParentWays().isEmpty()) { 110 110 throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace.")); 111 111 } … … 115 115 Arrays.asList(subjectNode, referenceNode), referenceNode); 116 116 if (c == null) { 117 // User cancel ed117 // User cancelled 118 118 return null; 119 119 } … … 132 132 */ 133 133 public static ReplaceGeometryCommand buildUpgradeNodeCommand(Node subjectNode, OsmPrimitive referenceObject) { 134 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) {134 if (!subjectNode.getParentWays().isEmpty()) { 135 135 throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace.")); 136 136 } … … 169 169 commands.addAll(getTagConflictResolutionCommands(subjectNode, referenceObject)); 170 170 } catch (UserCancelException e) { 171 // user cancel ed tag merge dialog171 // user cancelled tag merge dialog 172 172 return null; 173 173 } … … 255 255 commands.addAll(getTagConflictResolutionCommands(referenceWay, subjectWay)); 256 256 } catch (UserCancelException e) { 257 // user cancel ed tag merge dialog257 // user cancelled tag merge dialog 258 258 Logging.trace(e); 259 259 return null; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java
r34454 r34812 17 17 */ 18 18 public class ConnectedMatch extends SearchCompiler.UnaryMatch { 19 private Collection<Way> connected = null;19 private Set<Way> connected = null; 20 20 boolean all; 21 21 … … 80 80 if (this == obj) 81 81 return true; 82 if (!super.equals(obj) || getClass() != obj.getClass())82 if (!super.equals(obj) || !(obj instanceof ConnectedMatch)) 83 83 return false; 84 84 ConnectedMatch other = (ConnectedMatch) obj; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java
r34454 r34812 4 4 import java.util.Collection; 5 5 import java.util.HashSet; 6 import java.util.Set; 6 7 7 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 16 17 */ 17 18 public class InsideMatch extends SearchCompiler.UnaryMatch { 18 private Collection<OsmPrimitive> inside = null;19 private Set<OsmPrimitive> inside = null; 19 20 20 21 public InsideMatch(SearchCompiler.Match match) { … … 61 62 if (this == obj) 62 63 return true; 63 if (!super.equals(obj) || getClass() != obj.getClass())64 if (!super.equals(obj) || !(obj instanceof InsideMatch)) 64 65 return false; 65 66 InsideMatch other = (InsideMatch) obj; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java
r34454 r34812 16 16 */ 17 17 public class IntersectingMatch extends SearchCompiler.UnaryMatch { 18 private Collection<Way> intersecting = null;18 private Set<Way> intersecting = null; 19 19 boolean all; 20 20 … … 70 70 if (this == obj) 71 71 return true; 72 if (!super.equals(obj) || getClass() != obj.getClass())72 if (!super.equals(obj) || !(obj instanceof IntersectingMatch)) 73 73 return false; 74 74 IntersectingMatch other = (IntersectingMatch) obj; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/RangeMatch.java
r34454 r34812 54 54 if (this == obj) 55 55 return true; 56 if ( obj == null || getClass() != obj.getClass())56 if (!(obj instanceof RangeMatch)) 57 57 return false; 58 58 RangeMatch other = (RangeMatch) obj; -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentNodesAction.java
r32410 r34812 9 9 import java.util.Collection; 10 10 import java.util.HashSet; 11 import java.util.LinkedHashSet; 11 12 import java.util.Set; 12 13 … … 37 38 public void actionPerformed(ActionEvent e) { 38 39 DataSet ds = getLayerManager().getEditDataSet(); 39 Collection<OsmPrimitive> selection = ds.getSelected(); 40 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 41 42 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class); 40 Collection<Node> selectedNodes = ds.getSelectedNodes(); 41 Set<Way> selectedWays = new LinkedHashSet<>(ds.getSelectedWays()); 43 42 44 43 // if no nodes and no ways are selected, do nothing … … 46 45 47 46 if (selectedWays.isEmpty()) { 48 // if one node is selected, use d ways connected to it to extend selecteons47 // if one node is selected, use ways connected to it to extend selection 49 48 // activeWays are remembered for next extend action (!!!) 50 49 51 // FIXME: some strange behaviour is possible if user delete some of these way50 // FIXME: some strange behaviour is possible if user deletes some of these ways 52 51 // how to clear activeWays during such user actions? Do not know 53 52 if (selectedNodes.size() == 1) { 54 53 activeWays.clear(); 55 // System.out.println("Cleared active ways");56 54 } 57 55 } else { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java
r32410 r34812 36 36 public void actionPerformed(ActionEvent e) { 37 37 DataSet ds = getLayerManager().getEditDataSet(); 38 Collection<OsmPrimitive> selection = ds.getSelected(); 39 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 40 41 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class); 38 Collection<Node> selectedNodes = ds.getSelectedNodes(); 39 Collection<Way> selectedWays = ds.getSelectedWays(); 42 40 43 41 // select ways attached to already selected ways -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java
r32410 r34812 33 33 public void actionPerformed(ActionEvent e) { 34 34 DataSet ds = getLayerManager().getEditDataSet(); 35 Collection<OsmPrimitive> selection = ds.getSelected(); 36 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 37 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class); 35 Collection<Node> selectedNodes = ds.getSelectedNodes(); 36 Collection<Way> selectedWays = ds.getSelectedWays(); 38 37 39 38 Set<Way> newWays = new HashSet<>(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java
r32410 r34812 35 35 public void actionPerformed(ActionEvent e) { 36 36 DataSet ds = getLayerManager().getEditDataSet(); 37 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class);37 Collection<Way> selectedWays = ds.getSelectedWays(); 38 38 39 39 // select ways attached to already selected ways -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java
r32410 r34812 36 36 public void actionPerformed(ActionEvent e) { 37 37 DataSet ds = getLayerManager().getEditDataSet(); 38 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class);38 Collection<Way> selectedWays = ds.getSelectedWays(); 39 39 40 40 if (!selectedWays.isEmpty()) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java
r32410 r34812 34 34 @Override 35 35 public void actionPerformed(ActionEvent e) { 36 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 37 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 36 Set<Node> selectedNodes = new HashSet<>(getLayerManager().getEditDataSet().getSelectedNodes()); 38 37 39 38 // if no 2 nodes and no ways are selected, do nothing -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r34454 r34812 47 47 */ 48 48 static void addNeighbours(Way w, Node n, Collection<Node> nodes) { 49 if (!n.getParentWays().contains(w)) 50 return; 51 49 52 List<Node> nodeList = w.getNodes(); 50 51 53 int idx = nodeList.indexOf(n); 52 54 if (idx == -1) return; … … 75 77 * @param w way to find attached ways 76 78 * @param ways collection to place the ways we found 79 * @return number of ways added 77 80 */ 78 81 static int addWaysConnectedToWay(Way w, Set<Way> ways) { … … 81 84 boolean flag = ways.contains(w); 82 85 for (Node n: nodes) { 83 ways.addAll( OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));86 ways.addAll(n.getParentWays()); 84 87 } 85 88 if (!flag) ways.remove(w); … … 91 94 * @param n Node to find attached ways 92 95 * @param ways collection to place the ways we found 96 * @return number of ways added 93 97 */ 94 98 static int addWaysConnectedToNode(Node n, Set<Way> ways) { 95 99 int s = ways.size(); 96 ways.addAll( OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));100 ways.addAll(n.getParentWays()); 97 101 return ways.size() - s; 98 102 } … … 103 107 * @param w way to check intersections 104 108 * @param newWays set to place the ways we found 109 * @return number of ways possibly added added to newWays 105 110 */ 106 111 static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays, Set<Way> excludeWays) { … … 154 159 * @param initWays ways to check intersections 155 160 * @param newWays set to place the ways we found 161 * @return number of ways added to newWays 156 162 */ 157 163 public static int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) { … … 169 175 } 170 176 171 public static int addWaysConnectedToNodes( Set<Node> selectedNodes, Set<Way> newWays) {177 public static int addWaysConnectedToNodes(Collection<Node> selectedNodes, Set<Way> newWays) { 172 178 int s = newWays.size(); 173 179 for (Node node: selectedNodes) { … … 235 241 Node n2 = it.next(); 236 242 Set<Way> ways = new HashSet<>(); 237 ways.addAll( OsmPrimitive.getFilteredList(n1.getReferrers(), Way.class));243 ways.addAll(n1.getParentWays()); 238 244 for (Way w: ways) { 239 245 … … 342 348 } 343 349 } 344 }345 346 static boolean isPointInsideMultipolygon(EastNorth p, Relation rel) {347 Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class);348 return isPointInsidePolygon(p, buildPointList(usedWays));349 350 } 350 351 … … 463 464 } 464 465 465 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset) { 466 return selectAllInside(selected, dataset, true); 467 } 468 469 public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset, boolean ignoreNodesOfFoundWays) { 470 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(selected, Way.class); 471 Set<Relation> selectedRels = OsmPrimitive.getFilteredSet(selected, Relation.class); 472 473 for (Iterator<Relation> it = selectedRels.iterator(); it.hasNext();) { 474 Relation r = it.next(); 475 if (!r.isMultipolygon()) { 476 it.remove(); 477 } 478 } 479 466 public static Set<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset, boolean ignoreNodesOfFoundWays) { 480 467 Set<Way> newWays = new HashSet<>(); 481 468 Set<Node> newNodes = new HashSet<>(); 482 // select nodes and ways inside s lexcted ways and multipolygons483 if (!selectedWays.isEmpty()) {484 for (Way w: selectedWays) {485 addAllInsideWay(dataset, w, newWays, newNodes);486 487 } 488 if (!selectedRels.isEmpty()) {489 for (Relation r: selectedRels) {490 addAllInsideMultipolygon(dataset, r, newWays, newNodes);491 }469 // select nodes and ways inside selected ways and multipolygons 470 for (OsmPrimitive p: selected) { 471 if (p instanceof Way) { 472 addAllInsideWay(dataset, (Way)p, newWays, newNodes); 473 } 474 } 475 for (OsmPrimitive p: selected) { 476 if (!(p instanceof Relation) || p.isMultipolygon()) 477 continue; 478 addAllInsideMultipolygon(dataset, (Relation) p, newWays, newNodes); 492 479 } 493 480 if (ignoreNodesOfFoundWays) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java
r32410 r34812 42 42 public void actionPerformed(ActionEvent e) { 43 43 DataSet ds = getLayerManager().getEditDataSet(); 44 List<Way> selectedWays = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class);44 List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays()); 45 45 46 46 if (selectedWays.size() == 1) { … … 64 64 while (!nodeQueue.isEmpty()) { 65 65 Node node = nodeQueue.remove(); 66 for (Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {66 for (Way p : node.getParentWays()) { 67 67 if (!newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) { 68 68 newWays.add(p); … … 160 160 Node node = nodesToCheck.get(i); 161 161 Integer nodeRef = nodeRefs.get(i); 162 for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {162 for (Way way : node.getParentWays()) { 163 163 if ((way.firstNode().equals(node) || way.lastNode().equals(node)) && 164 164 !tree.contains(way) && suits(way)) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java
r34454 r34812 20 20 21 21 /** 22 * Unselects all nodes22 * Select last modified nodes. 23 23 */ 24 24 public class SelectModNodesAction extends JosmAction { 25 private int lastHash;26 25 private Command lastCmd; 27 26 … … 39 38 if (ds != null) { 40 39 Collection<OsmPrimitive> selection = ds.getSelected(); 41 ds.clearSelection( OsmPrimitive.getFilteredSet(selection, Node.class));40 ds.clearSelection(ds.getSelectedWays()); 42 41 Command cmd = null; 43 42 … … 46 45 if (num == 0) return; 47 46 int k = 0, idx; 48 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {49 // we are selecting next command in history if nothing is selected50 idx = UndoRedoHandler.getInstance().commands. indexOf(lastCmd);47 // check if executed again, we cycle through all available commands 48 if (lastCmd != null && !selection.isEmpty() ) { 49 idx = UndoRedoHandler.getInstance().commands.lastIndexOf(lastCmd); 51 50 } else { 52 51 idx = num; … … 57 56 if (idx > 0) idx--; else idx = num-1; 58 57 cmd = UndoRedoHandler.getInstance().commands.get(idx); 59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 60 nodes.clear(); 61 for (OsmPrimitive p : pp) { // find all affected ways 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p); 63 } 64 if (!nodes.isEmpty()) { 65 ds.setSelected(nodes); 66 lastCmd = cmd; // remember last used command and last selection 67 lastHash = ds.getSelected().hashCode(); 68 return; 58 if (cmd.getAffectedDataSet() == ds) { 59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 60 nodes.clear(); 61 for (OsmPrimitive p : pp) { // find all affected ways 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p); 63 } 64 if (!nodes.isEmpty() && !ds.getSelectedNodes().containsAll(nodes)) { 65 ds.setSelected(nodes); 66 lastCmd = cmd; // remember last used command and last selection 67 return; 68 } 69 69 } 70 70 k++; 71 71 } while (k < num); // try to find previous command if this affects nothing 72 lastCmd = null; lastHash = 0;72 lastCmd = null; 73 73 } 74 74 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java
r34454 r34812 15 15 import org.openstreetmap.josm.data.UndoRedoHandler; 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node;18 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 18 import org.openstreetmap.josm.data.osm.Way; … … 21 20 22 21 /** 23 * Unselects all nodes22 * Select last modified ways. 24 23 */ 25 24 public class SelectModWaysAction extends JosmAction { 26 private int lastHash;27 25 private Command lastCmd; 28 26 … … 39 37 DataSet ds = getLayerManager().getEditDataSet(); 40 38 if (ds != null) { 41 Collection<OsmPrimitive> selection = ds.getSelected(); 42 ds.clearSelection(OsmPrimitive.getFilteredSet(selection, Node.class)); 39 ds.clearSelection(ds.getSelectedNodes()); 43 40 Command cmd; 44 41 … … 47 44 if (num == 0) return; 48 45 int k = 0, idx; 49 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {50 // we are selecting next command in history if nothing is selected51 idx = UndoRedoHandler.getInstance().commands. indexOf(lastCmd);46 // check if executed again, we cycle through all available commands 47 if (lastCmd != null && !ds.getSelectedWays().isEmpty() ) { 48 idx = UndoRedoHandler.getInstance().commands.lastIndexOf(lastCmd); 52 49 } else { 53 50 idx = num; … … 58 55 if (idx > 0) idx--; else idx = num-1; 59 56 cmd = UndoRedoHandler.getInstance().commands.get(idx); 60 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 61 ways.clear(); 62 for (OsmPrimitive p : pp) { // find all affected ways 63 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p); 64 } 65 if (!ways.isEmpty() && !ds.getSelected().containsAll(ways)) { 66 ds.setSelected(ways); 67 lastCmd = cmd; // remember last used command and last selection 68 lastHash = ds.getSelected().hashCode(); 69 return; 57 if (cmd.getAffectedDataSet() == ds) { 58 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 59 ways.clear(); 60 for (OsmPrimitive p : pp) { 61 // find all affected ways 62 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p); 63 } 64 if (!ways.isEmpty() && !ds.getSelectedWays().containsAll(ways)) { 65 ds.setSelected(ways); 66 lastCmd = cmd; // remember last used command and last selection 67 return; 68 } 70 69 } 71 70 k++; 72 71 } while (k < num); // try to find previous command if this affects nothing 73 72 lastCmd = null; 74 lastHash = 0;75 73 } 76 74 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java
r34770 r34812 18 18 19 19 /** 20 * Use selection istory to restore previous selection20 * Use selection history to restore previous selection 21 21 */ 22 22 public class UndoSelectionAction extends JosmAction { … … 41 41 if (lastSel != null) { 42 42 Collection<OsmPrimitive> selection = ds.getSelected(); 43 if ( selection.containsAll(lastSel) && lastSel.containsAll(selection)) {43 if (lastSel.size() == selection.size() && selection.containsAll(lastSel)) { 44 44 // repeated action 45 45 } else { … … 51 51 int k = 0; 52 52 53 Set<OsmPrimitive> new sel = new HashSet<>();53 Set<OsmPrimitive> newSel = new HashSet<>(); 54 54 while (k < num) { 55 55 if (index+1 < history.size()) index++; else index = 0; 56 56 Collection<? extends OsmPrimitive> histsel = history.get(index); 57 57 // remove deleted entities from selection 58 new sel.clear();59 new sel.addAll(histsel);60 new sel.removeIf(p -> p == null || p.isDeleted());58 newSel.clear(); 59 newSel.addAll(histsel); 60 newSel.removeIf(p -> p == null || p.isDeleted()); 61 61 k++; 62 if (!newsel.isEmpty()) { 63 if (newsel.containsAll(ds.getSelected()) && ds.getSelected().containsAll(newsel)) { 62 if (!newSel.isEmpty()) { 63 Collection<OsmPrimitive> oldSel = ds.getSelected(); 64 if (oldSel.size() == newSel.size() && newSel.containsAll(oldSel)) { 64 65 // ignore no-change selection 65 66 continue; … … 70 71 71 72 // set new selection (is added to history) 72 ds.setSelected(new sel);73 ds.setSelected(newSel); 73 74 lastSel = ds.getSelected(); 74 75 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java
r32410 r34812 8 8 import java.awt.event.KeyEvent; 9 9 import java.util.Collection; 10 import java.util.Set;11 10 12 11 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.osm.Node;14 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 13 import org.openstreetmap.josm.tools.Shortcut; 16 14 17 15 /** 18 * Unselect s all nodes16 * Unselect all nodes. 19 17 */ 20 18 public class UnselectNodesAction extends JosmAction { … … 33 31 @Override 34 32 public void actionPerformed(ActionEvent e) { 35 Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected(); 36 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 37 getLayerManager().getEditDataSet().clearSelection(selectedNodes); 33 getLayerManager().getEditDataSet().clearSelection(getLayerManager().getEditDataSet().getSelectedNodes()); 38 34 } 39 35
Note:
See TracChangeset
for help on using the changeset viewer.