Ignore:
Timestamp:
2019-01-11T11:01:03+01:00 (6 years ago)
Author:
gerdp
Message:

see #17187:

  • Replace deprecated methods
  • Remove dead code
  • Make Shift+Z (Select last modified nodes) work again + Repated Shift+Z cycles through the commands available in the undo tree + Ignore changes in other layers
  • Make Alt+Shift+Z (Select last modified Ways) work again (same logic as with Shift+Z)
  • fix some javadoc errors


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  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
     9import java.util.ArrayList;
    910import java.util.Collection;
    1011import java.util.HashSet;
     
    4748        if (!isEnabled())
    4849            return;
    49         List<Way> ways = OsmPrimitive.getFilteredList(getLayerManager().getEditDataSet().getSelected(), Way.class);
     50        List<Way> ways = new ArrayList<>(getLayerManager().getEditDataSet().getSelectedWays());
    5051        if (ways.isEmpty()) {
    5152            new Notification(
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java

    r34454 r34812  
    115115                double m1 = (by - ay) / (bx - ax);
    116116                double c1 = ay - (ax * m1);
    117                 double m2 = (-1) / m1;
     117                double m2 = -1.0 / m1;
    118118                double c2 = ny - (nx * m2);
    119119
     
    146146        Set<Way> ways = null;
    147147        for (Node n : nodes.stream().filter(n -> n.getDataSet() != null).collect(Collectors.toList())) {
    148             List<Way> referrers = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);
    149148            if (ways == null)
    150                 ways = new HashSet<>(referrers);
     149                ways = new HashSet<>(n.getParentWays());
    151150            else {
    152                 ways.retainAll(referrers);
     151                ways.retainAll(n.getParentWays());
    153152            }
    154153        }
     
    171170     *
    172171     * 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
    173175     */
    174176    private int findFirstNode(Way way, Set<Node> nodes) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/ExtractPointAction.java

    r34454 r34812  
    4848    public void actionPerformed(ActionEvent e) {
    4949        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();
    5251        if (selectedNodes.size() != 1) {
    5352            new Notification(tr("This tool extracts node from its ways and requires single node to be selected."))
     
    5554            return;
    5655        }
    57         Node nd = selectedNodes.get(0);
     56        Node nd = selectedNodes.iterator().next();
    5857        Node ndCopy = new Node(nd.getCoor());
    5958        List<Command> cmds = new LinkedList<>();
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java

    r34454 r34812  
    2828import org.openstreetmap.josm.tools.Logging;
    2929import org.openstreetmap.josm.tools.Shortcut;
     30import org.openstreetmap.josm.tools.Utils;
    3031
    3132/**
     
    5960            OsmPrimitive p = getLayerManager().getEditDataSet().getPrimitiveById(pdata.getUniqueId(), pdata.getType());
    6061            if (p != null) {
    61                 for (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {
     62                for (Relation r : Utils.filteredCollection(p.getReferrers(), Relation.class)) {
    6263                    String role = relations.get(r);
    6364                    for (RelationMember m : r.getMembers()) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java

    r34778 r34812  
    88import java.awt.event.ActionEvent;
    99import java.awt.event.KeyEvent;
     10import java.util.ArrayList;
    1011import java.util.Collection;
    1112import java.util.Collections;
     
    2223import org.openstreetmap.josm.command.SplitWayCommand;
    2324import org.openstreetmap.josm.data.UndoRedoHandler;
     25import org.openstreetmap.josm.data.osm.DataSet;
    2426import org.openstreetmap.josm.data.osm.Node;
    2527import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5658    @Override
    5759    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())) {
    6462            showWarningNotification(tr("The current selection cannot be used for splitting."));
    6563            return;
    6664        }
     65
     66        List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes());
     67        List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());
    6768
    6869        Way selectedWay = null;
     
    9293            Map<Way, Integer> wayOccurenceCounter = new HashMap<>();
    9394            for (Node n : selectedNodes) {
    94                 for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) {
     95                for (Way w : n.getParentWays()) {
    9596                    if (!w.isUsable()) {
    9697                        continue;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java

    r34790 r34812  
    4646    public void actionPerformed(ActionEvent e) {
    4747        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());
    4949        Map<Way, List<Node>> splitWays = new HashMap<>();
    5050
     
    5252            if (way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed())
    5353                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();
    5555                    refs.remove(way);
    5656                    if (selectedWays.size() > 1) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SymmetryAction.java

    r34454 r34812  
    3131 * Note: If a ways are selected, their nodes are mirrored
    3232 *
    33  * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :)
     33 * @author Alexei Kasatkin, based on much copy+paste from other MirrorAction :)
    3434 */
    3535public final class SymmetryAction extends JosmAction {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java

    r34793 r34812  
    8787
    8888    /**
    89      * Find those tags which appear in all primitives of the selection
     89     * Find those tags which appear in all tagged primitives of the selection.
    9090     * @param selection the selection
     91     * @return the common tags of all tagged primitives in the selection
    9192     */
    9293    private static TagCollection getCommonTags(List<OsmPrimitive> selection) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java

    r34454 r34812  
    2424import org.openstreetmap.josm.plugins.utilsplugin2.command.ChangeRelationMemberCommand;
    2525import org.openstreetmap.josm.tools.Shortcut;
     26import org.openstreetmap.josm.tools.Utils;
    2627
    2728/**
     
    5859        for (OsmPrimitive p : selection) {
    5960            boolean first = true;
    60             for (Relation relation : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {
     61            for (Relation relation : Utils.filteredCollection(p.getReferrers(), Relation.class)) {
    6162                if (relation.isDeleted()) {
    6263                    continue;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CircleArcMaker.java

    r34454 r34812  
    2020import org.openstreetmap.josm.data.osm.DataSet;
    2121import org.openstreetmap.josm.data.osm.Node;
    22 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2322import org.openstreetmap.josm.data.osm.Way;
    2423import org.openstreetmap.josm.gui.MainApplication;
     
    5756        Node n1 = null, n2 = null, n3 = null;
    5857
    59         if (false) {
    60             int nodeCount = selectedNodes.size();
    61             int wayCount = selectedWays.size();
    62 
    63             // TODO: filter garbage nodes based on selected ways
    64 
    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 
    7458        Set<Way> targetWays = new HashSet<>();
    7559        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     
    125109
    126110            for (Node n : consideredNodes) {
    127                 targetWays.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));
     111                targetWays.addAll(n.getParentWays());
    128112            }
    129113        }
     
    222206     * Return a list of coordinates lying an the circle arc determined by n1, n2 and n3.
    223207     * 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.
    226213     *                       If {@code false}, p2 will be replaced by the closest arcpoint.
    227214     * @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 points
     215     * @return list of coordinates lying an the circle arc determined by n1, n2 and n3
    229216     */
    230217    private static List<EastNorth> circleArcPoints(EastNorth p1, EastNorth p2, EastNorth p3,
     
    297284        assert (closestIndexToP2 != 0);
    298285
    299         double a = direction * (stepLength);
     286        double a = direction * stepLength;
    300287        points.add(p1);
    301288        if (indexJustBeforeP2 == 0 && includeAnchors) {
     
    330317
    331318    /**
    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
    333322     */
    334323    private static double normalizeAngle(double angle) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/OpenPageAction.java

    r34454 r34812  
    2626
    2727/**
    28  * Mirror the selected ways nodes or ways along line given by two first selected points
    2928 *
    30  * Note: If a ways are selected, their nodes are mirrored
     29 * Open custom URL
    3130 *
    32  * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :)
     31 * @author Alexei Kasatkin
    3332 */
    3433public final class OpenPageAction extends JosmAction {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java

    r34454 r34812  
    1919
    2020/**
    21  * Replaces already existing object (id>0) with a new object (id<0).
     21 * Replaces already existing object (id&gt;0) with a new object (id&lt;0).
    2222 *
    2323 * @author Zverik
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java

    r34454 r34812  
    107107     */
    108108    public static ReplaceGeometryCommand buildReplaceNodeCommand(Node subjectNode, Node referenceNode) {
    109         if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) {
     109        if (!subjectNode.getParentWays().isEmpty()) {
    110110            throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace."));
    111111        }
     
    115115            Arrays.asList(subjectNode, referenceNode), referenceNode);
    116116        if (c == null) {
    117             // User canceled
     117            // User cancelled
    118118            return null;
    119119        }
     
    132132     */
    133133    public static ReplaceGeometryCommand buildUpgradeNodeCommand(Node subjectNode, OsmPrimitive referenceObject) {
    134         if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) {
     134        if (!subjectNode.getParentWays().isEmpty()) {
    135135            throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace."));
    136136        }
     
    169169            commands.addAll(getTagConflictResolutionCommands(subjectNode, referenceObject));
    170170        } catch (UserCancelException e) {
    171             // user canceled tag merge dialog
     171            // user cancelled tag merge dialog
    172172            return null;
    173173        }
     
    255255            commands.addAll(getTagConflictResolutionCommands(referenceWay, subjectWay));
    256256        } catch (UserCancelException e) {
    257             // user canceled tag merge dialog
     257            // user cancelled tag merge dialog
    258258            Logging.trace(e);
    259259            return null;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java

    r34454 r34812  
    1717 */
    1818public class ConnectedMatch extends SearchCompiler.UnaryMatch {
    19     private Collection<Way> connected = null;
     19    private Set<Way> connected = null;
    2020    boolean all;
    2121
     
    8080        if (this == obj)
    8181            return true;
    82         if (!super.equals(obj) || getClass() != obj.getClass())
     82        if (!super.equals(obj) || !(obj instanceof ConnectedMatch))
    8383            return false;
    8484        ConnectedMatch other = (ConnectedMatch) obj;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java

    r34454 r34812  
    44import java.util.Collection;
    55import java.util.HashSet;
     6import java.util.Set;
    67
    78import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1617 */
    1718public class InsideMatch extends SearchCompiler.UnaryMatch {
    18     private Collection<OsmPrimitive> inside = null;
     19    private Set<OsmPrimitive> inside = null;
    1920
    2021    public InsideMatch(SearchCompiler.Match match) {
     
    6162        if (this == obj)
    6263            return true;
    63         if (!super.equals(obj) || getClass() != obj.getClass())
     64        if (!super.equals(obj) || !(obj instanceof InsideMatch))
    6465            return false;
    6566        InsideMatch other = (InsideMatch) obj;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java

    r34454 r34812  
    1616 */
    1717public class IntersectingMatch extends SearchCompiler.UnaryMatch {
    18     private Collection<Way> intersecting = null;
     18    private Set<Way> intersecting = null;
    1919    boolean all;
    2020
     
    7070        if (this == obj)
    7171            return true;
    72         if (!super.equals(obj) || getClass() != obj.getClass())
     72        if (!super.equals(obj) || !(obj instanceof IntersectingMatch))
    7373            return false;
    7474        IntersectingMatch other = (IntersectingMatch) obj;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/RangeMatch.java

    r34454 r34812  
    5454        if (this == obj)
    5555            return true;
    56         if (obj == null || getClass() != obj.getClass())
     56        if (!(obj instanceof RangeMatch))
    5757            return false;
    5858        RangeMatch other = (RangeMatch) obj;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentNodesAction.java

    r32410 r34812  
    99import java.util.Collection;
    1010import java.util.HashSet;
     11import java.util.LinkedHashSet;
    1112import java.util.Set;
    1213
     
    3738    public void actionPerformed(ActionEvent e) {
    3839        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());
    4342
    4443        // if no nodes and no ways are selected, do nothing
     
    4645
    4746        if (selectedWays.isEmpty()) {
    48             // if one node is selected, used ways connected to it to extend selecteons
     47            // if one node is selected, use ways connected to it to extend selection
    4948            // activeWays are remembered for next extend action (!!!)
    5049
    51             // FIXME: some strange behaviour is possible if user delete some of these way
     50            // FIXME: some strange behaviour is possible if user deletes some of these ways
    5251            // how to clear activeWays during such user actions? Do not know
    5352            if (selectedNodes.size() == 1) {
    5453                activeWays.clear();
    55                 //                System.out.println("Cleared active ways");
    5654            }
    5755        } else {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java

    r32410 r34812  
    3636    public void actionPerformed(ActionEvent e) {
    3737        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();
    4240
    4341        // select ways attached to already selected ways
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java

    r32410 r34812  
    3333    public void actionPerformed(ActionEvent e) {
    3434        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();
    3837
    3938        Set<Way> newWays = new HashSet<>();
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java

    r32410 r34812  
    3535    public void actionPerformed(ActionEvent e) {
    3636        DataSet ds = getLayerManager().getEditDataSet();
    37         Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class);
     37        Collection<Way> selectedWays = ds.getSelectedWays();
    3838
    3939        // select ways attached to already selected ways
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java

    r32410 r34812  
    3636    public void actionPerformed(ActionEvent e) {
    3737        DataSet ds = getLayerManager().getEditDataSet();
    38         Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class);
     38        Collection<Way> selectedWays = ds.getSelectedWays();
    3939
    4040        if (!selectedWays.isEmpty()) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java

    r32410 r34812  
    3434    @Override
    3535    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());
    3837
    3938        // 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  
    4747     */
    4848    static void addNeighbours(Way w, Node n, Collection<Node> nodes) {
     49        if (!n.getParentWays().contains(w))
     50                return;
     51
    4952        List<Node> nodeList = w.getNodes();
    50 
    5153        int idx = nodeList.indexOf(n);
    5254        if (idx == -1) return;
     
    7577     * @param w way to find attached ways
    7678     * @param ways  collection to place the ways we found
     79     * @return number of ways added
    7780     */
    7881    static int addWaysConnectedToWay(Way w, Set<Way> ways) {
     
    8184        boolean flag = ways.contains(w);
    8285        for (Node n: nodes) {
    83             ways.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));
     86            ways.addAll(n.getParentWays());
    8487        }
    8588        if (!flag) ways.remove(w);
     
    9194     * @param n Node to find attached ways
    9295     * @param ways  collection to place the ways we found
     96     * @return number of ways added
    9397     */
    9498    static int addWaysConnectedToNode(Node n, Set<Way> ways) {
    9599        int s = ways.size();
    96         ways.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));
     100        ways.addAll(n.getParentWays());
    97101        return ways.size() - s;
    98102    }
     
    103107     * @param w way to check intersections
    104108     * @param newWays set to place the ways we found
     109     * @return number of ways possibly added added to newWays
    105110     */
    106111    static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays, Set<Way> excludeWays) {
     
    154159     * @param initWays ways to check intersections
    155160     * @param newWays set to place the ways we found
     161     * @return number of ways added to newWays
    156162     */
    157163    public static int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) {
     
    169175    }
    170176
    171     public static int addWaysConnectedToNodes(Set<Node> selectedNodes, Set<Way> newWays) {
     177    public static int addWaysConnectedToNodes(Collection<Node> selectedNodes, Set<Way> newWays) {
    172178        int s = newWays.size();
    173179        for (Node node: selectedNodes) {
     
    235241        Node n2 = it.next();
    236242        Set<Way> ways = new HashSet<>();
    237         ways.addAll(OsmPrimitive.getFilteredList(n1.getReferrers(), Way.class));
     243        ways.addAll(n1.getParentWays());
    238244        for (Way w: ways) {
    239245
     
    342348            }
    343349        }
    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));
    349350    }
    350351
     
    463464    }
    464465
    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) {
    480467        Set<Way> newWays = new HashSet<>();
    481468        Set<Node> newNodes = new HashSet<>();
    482         // select nodes and ways inside slexcted ways and multipolygons
    483         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);
    492479        }
    493480        if (ignoreNodesOfFoundWays) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java

    r32410 r34812  
    4242    public void actionPerformed(ActionEvent e) {
    4343        DataSet ds = getLayerManager().getEditDataSet();
    44         List<Way> selectedWays = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class);
     44        List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());
    4545
    4646        if (selectedWays.size() == 1) {
     
    6464            while (!nodeQueue.isEmpty()) {
    6565                Node node = nodeQueue.remove();
    66                 for (Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
     66                for (Way p : node.getParentWays()) {
    6767                    if (!newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) {
    6868                        newWays.add(p);
     
    160160                Node node = nodesToCheck.get(i);
    161161                Integer nodeRef = nodeRefs.get(i);
    162                 for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
     162                for (Way way : node.getParentWays()) {
    163163                    if ((way.firstNode().equals(node) || way.lastNode().equals(node)) &&
    164164                            !tree.contains(way) && suits(way)) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java

    r34454 r34812  
    2020
    2121/**
    22  * Unselects all nodes
     22 * Select last modified nodes.
    2323 */
    2424public class SelectModNodesAction extends JosmAction {
    25     private int lastHash;
    2625    private Command lastCmd;
    2726
     
    3938        if (ds != null) {
    4039            Collection<OsmPrimitive> selection = ds.getSelected();
    41             ds.clearSelection(OsmPrimitive.getFilteredSet(selection, Node.class));
     40            ds.clearSelection(ds.getSelectedWays());
    4241            Command cmd = null;
    4342
     
    4645            if (num == 0) return;
    4746            int k = 0, idx;
    48             if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {
    49                 // we are selecting next command in history if nothing is selected
    50                 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);
    5150            } else {
    5251                idx = num;
     
    5756                if (idx > 0) idx--; else idx = num-1;
    5857                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                        }
    6969                }
    7070                k++;
    7171            } while (k < num); // try to find previous command if this affects nothing
    72             lastCmd = null; lastHash = 0;
     72            lastCmd = null;
    7373        }
    7474    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java

    r34454 r34812  
    1515import org.openstreetmap.josm.data.UndoRedoHandler;
    1616import org.openstreetmap.josm.data.osm.DataSet;
    17 import org.openstreetmap.josm.data.osm.Node;
    1817import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1918import org.openstreetmap.josm.data.osm.Way;
     
    2120
    2221/**
    23  * Unselects all nodes
     22 * Select last modified ways.
    2423 */
    2524public class SelectModWaysAction extends JosmAction {
    26     private int lastHash;
    2725    private Command lastCmd;
    2826
     
    3937        DataSet ds = getLayerManager().getEditDataSet();
    4038        if (ds != null) {
    41             Collection<OsmPrimitive> selection = ds.getSelected();
    42             ds.clearSelection(OsmPrimitive.getFilteredSet(selection, Node.class));
     39            ds.clearSelection(ds.getSelectedNodes());
    4340            Command cmd;
    4441
     
    4744            if (num == 0) return;
    4845            int k = 0, idx;
    49             if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {
    50                 // we are selecting next command in history if nothing is selected
    51                 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);
    5249            } else {
    5350                idx = num;
     
    5855                if (idx > 0) idx--; else idx = num-1;
    5956                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                        }
    7069                }
    7170                k++;
    7271            } while (k < num); // try to find previous command if this affects nothing
    7372            lastCmd = null;
    74             lastHash = 0;
    7573        }
    7674    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java

    r34770 r34812  
    1818
    1919/**
    20  * Use selection istory to restore previous selection
     20 * Use selection history to restore previous selection
    2121 */
    2222public class UndoSelectionAction extends JosmAction {
     
    4141            if (lastSel != null) {
    4242                Collection<OsmPrimitive> selection = ds.getSelected();
    43                 if (selection.containsAll(lastSel) && lastSel.containsAll(selection)) {
     43                if (lastSel.size() == selection.size() && selection.containsAll(lastSel)) {
    4444                        // repeated action
    4545                } else {
     
    5151            int k = 0;
    5252
    53             Set<OsmPrimitive> newsel = new HashSet<>();
     53            Set<OsmPrimitive> newSel = new HashSet<>();
    5454            while (k < num) {
    5555                if (index+1 < history.size()) index++; else index = 0;
    5656                Collection<? extends OsmPrimitive> histsel = history.get(index);
    5757                // remove deleted entities from selection
    58                 newsel.clear();
    59                 newsel.addAll(histsel);
    60                 newsel.removeIf(p -> p == null || p.isDeleted());
     58                newSel.clear();
     59                newSel.addAll(histsel);
     60                newSel.removeIf(p -> p == null || p.isDeleted());
    6161                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)) {
    6465                                // ignore no-change selection
    6566                                continue;
     
    7071
    7172            // set new selection (is added to history)
    72             ds.setSelected(newsel);
     73            ds.setSelected(newSel);
    7374            lastSel = ds.getSelected();
    7475        }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java

    r32410 r34812  
    88import java.awt.event.KeyEvent;
    99import java.util.Collection;
    10 import java.util.Set;
    1110
    1211import org.openstreetmap.josm.actions.JosmAction;
    13 import org.openstreetmap.josm.data.osm.Node;
    1412import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1513import org.openstreetmap.josm.tools.Shortcut;
    1614
    1715/**
    18  * Unselects all nodes
     16 * Unselect all nodes.
    1917 */
    2018public class UnselectNodesAction extends JosmAction {
     
    3331    @Override
    3432    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());
    3834    }
    3935
Note: See TracChangeset for help on using the changeset viewer.