Changeset 4557 in josm for trunk


Ignore:
Timestamp:
2011-11-02T09:49:44+01:00 (13 years ago)
Author:
stoecker
Message:

fix #6951 - patch by olejorgenb - Join way to node only joins the node with selected ways

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r3713 r4557  
    3636        if (!isEnabled())
    3737            return;
    38         Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
    39         if (sel.size() < 1) return;
     38        Collection<Node> selectedNodes = getCurrentDataSet().getSelectedNodes();
     39        // Allow multiple selected nodes too?
     40        if (selectedNodes.size() != 1) return;
     41
     42        Node node = selectedNodes.iterator().next();
    4043
    4144        Collection<Command> cmds = new LinkedList<Command>();
    4245
    43         for (OsmPrimitive osm : sel) {
    44             if (!(osm instanceof Node)) {
    45                 continue;
    46             }
    47             Node node = (Node) osm;
     46        // If the user has selected some ways, only join the node to these.
     47        boolean restrictToSelectedWays =
     48            getCurrentDataSet().getSelectedWays().size() > 0;
    4849
    4950            List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
     
    5152            HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
    5253            for (WaySegment ws : wss) {
     54                // Maybe cleaner to pass a "isSelected" predicate to getNearestWaySegements, but this is atm. less invasive.
     55                if(restrictToSelectedWays && !ws.way.isSelected()) {
     56                    continue;
     57                }
     58
    5359                List<Integer> is;
    5460                if (insertPoints.containsKey(ws.way)) {
     
    8187                cmds.add(new ChangeCommand(w, wnew));
    8288            }
    83         }
    84         if (cmds.size() == 0) return;
    85         Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds));
    86         Main.map.repaint();
     89            if (cmds.size() == 0) return;
     90            Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds));
     91            Main.map.repaint();
    8792    }
    8893
Note: See TracChangeset for help on using the changeset viewer.