Changeset 313 in josm


Ignore:
Timestamp:
2007-08-23T22:24:50+02:00 (17 years ago)
Author:
framm
Message:
  • Modified AddNodeAction so that the "add node and connect" mode can be used to insert nodes into existing segments (with CTRL) and connect to existing nodes (with ALT), requiring less mode changes while mapping.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r306 r313  
    5050                        actions.add(new AddNodeAction(mf,tr("Add node"), Mode.node, tr("Add a new node to the map")));
    5151                        actions.add(new AddNodeAction(mf, tr("Add node into segment"), Mode.nodesegment,tr( "Add a node into an existing segment")));
    52                         actions.add(new AddNodeAction(mf, tr("Add node and connect"), Mode.autonode,tr( "Add a node and connect it to the selected (previously added) node")));
     52                        actions.add(new AddNodeAction(mf, tr("Add node and connect"), Mode.autonode,tr( "Add a node and connect it to the selected node (with CTRL: add node into segment; with ALT: re-use existing node)")));
    5353                        setCurrent(0);
    5454                }
     
    9393                Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
    9494                if (n.coor.isOutSideWorld()) {
    95                         JOptionPane.showMessageDialog(Main.parent,tr("Can not add a node outside of the world."));
     95                        JOptionPane.showMessageDialog(Main.parent,tr("Cannot add a node outside of the world."));
    9696                        return;
    9797                }
     
    108108                        if (other == null && (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) == 0) {
    109109                                // moving the new point to the perpendicular point
     110                                // FIXME: when two segments are split, should move the new point to the
     111                                // intersection point!
    110112                                EastNorth A = s.from.eastNorth;
    111113                                EastNorth B = s.to.eastNorth;
     
    131133                }
    132134
     135                // Add a node and connecting segment.
    133136                if (mode == Mode.autonode) {
     137
     138                        Segment insertInto = null;
     139                        Node reuseNode = null;
     140                       
     141                        // If CTRL is held, insert the node into a potentially existing segment
     142                        if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) {
     143                                insertInto = Main.map.mapView.getNearestSegment(e.getPoint());
     144                                if (insertInto == null)
     145                                        return;
     146                        }
     147                        // If ALT is held, instead of creating a new node, re-use an existing
     148                        // node (making this action identical to AddSegmentAction with the
     149                        // small difference that the node used will then be selected to allow
     150                        // continuation of the "add node and connect" stuff)
     151                        else if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
     152                                OsmPrimitive clicked = Main.map.mapView.getNearest(e.getPoint(), false);
     153                                if (clicked == null || !(clicked instanceof Node))
     154                                        return;
     155                                reuseNode = (Node) clicked;
     156                        }
     157                       
    134158                        Collection<OsmPrimitive> selection = Main.ds.getSelected();
    135159                        if (selection.size() == 1 && selection.iterator().next() instanceof Node) {
    136160                                Node n1 = (Node)selection.iterator().next();
    137161                                Collection<Command> cmds = new LinkedList<Command>();
     162                               
     163                                if (reuseNode != null) {
     164                                        // in re-use node mode, n1 must not be identical to clicked node
     165                                        if (n1 == reuseNode) return;
     166                                        // replace newly created node with existing node
     167                                        n = reuseNode;
     168                                } else {
     169                                        // only add the node creation command if we're not re-using
     170                                        cmds.add(c);
     171                                }
     172                               
    138173                                Segment s = new Segment(n1, n);
    139                                 cmds.add(c);                           
     174                               
     175                                if (insertInto != null)
     176                                        splitSegmentAtNode(insertInto, n, cmds);
     177                               
    140178                                cmds.add(new AddCommand(s));                   
    141179
     
    153191                                }
    154192
    155                                 c = new SequenceCommand(tr("Add node and connect"), cmds);
     193                                c = new SequenceCommand(tr((insertInto == null) ? "Add node and connect" : "Add node into segment and connect"), cmds);
    156194                        }       
    157195                }               
Note: See TracChangeset for help on using the changeset viewer.