Ignore:
Timestamp:
2007-10-21T20:40:41+02:00 (17 years ago)
Author:
framm
Message:
  • when drawing a way, select the way and not the last node
  • when clicking on a node with nothing selected in draw mode, select that node
  • U key in draw mode clears selection
File:
1 edited

Legend:

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

    r408 r409  
    2424
    2525import org.openstreetmap.josm.Main;
    26 import org.openstreetmap.josm.actions.GroupAction;
    27 import org.openstreetmap.josm.actions.mapmode.SelectAction.Mode;
    2826import org.openstreetmap.josm.command.AddCommand;
    2927import org.openstreetmap.josm.command.ChangeCommand;
     
    4341 */
    4442public class DrawAction extends MapMode {
     43       
     44        private static Node lastUsedNode = null;
    4545
    4646        public DrawAction(MapFrame mapFrame) {
     
    5252                        KeyStroke.getKeyStroke(KeyEvent.VK_N, 0), tr("Draw"));
    5353
     54                // Add extra shortcut U
     55                Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     56                        KeyStroke.getKeyStroke(KeyEvent.VK_U, 0), tr("Unselect All"));
     57               
    5458                //putValue("help", "Action/AddNode/Autnode");
    5559        }
     
    9498                boolean newNode = false;
    9599                Node n = null;
    96                 if (!ctrl) n = Main.map.mapView.getNearestNode(e.getPoint());
    97                 if (n == null) {
     100                if (!ctrl) {
     101                        n = Main.map.mapView.getNearestNode(e.getPoint());
     102                }
     103               
     104                if (n != null) {
     105                        // user clicked on node
     106                        if (selection.isEmpty()) {
     107                                // select the clicked node and do nothing else
     108                                // (this is just a convenience option so that people don't
     109                                // have to switch modes)
     110                                Main.ds.setSelected(n);
     111                                return;
     112                        }
     113                       
     114                } else {
     115                        // no node found in clicked area
    98116                        n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
    99117                        if (n.coor.isOutSideWorld()) {
     
    143161                        }
    144162                }
     163               
     164                // This part decides whether or not a "segment" (i.e. a connection) is made to an
     165                // existing node.
     166               
     167                // For a connection to be made, the user must either have a node selected (connection
     168                // is made to that node), or he must have a way selected *and* one of the endpoints
     169                // of that way must be the last used node (connection is made to last used node), or
     170                // he must have a way and a node selected (connection is made to the selected node).
     171               
    145172                boolean extendedWay = false;
    146                 // shift modifier never connects, just makes new node
    147                 if (!shift && selection.size() == 1 && selection.iterator().next() instanceof Node) {
    148                         Node n0 = (Node) selection.iterator().next();
    149                         if (n0 == n) {
     173
     174                if (!shift && selection.size() > 0 && selection.size() < 3) {
     175                       
     176                        Node selectedNode = null;
     177                        Way selectedWay = null;
     178                       
     179                        for (OsmPrimitive p : selection) {
     180                                if (p instanceof Node) {
     181                                        if (selectedNode != null) return;
     182                                        selectedNode = (Node) p;
     183                                } else if (p instanceof Way) {
     184                                        if (selectedWay != null) return;
     185                                        selectedWay = (Way) p;
     186                                }
     187                        }
     188                       
     189                        // the node from which we make a connection
     190                        Node n0 = null;
     191                       
     192                        if (selectedNode == null) {
     193                                if (selectedWay == null) return;
     194                                if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) {
     195                                        n0 = lastUsedNode;
     196                                }
     197                        } else if (selectedWay == null) {
     198                                n0 = selectedNode;
     199                        } else {
     200                                if (selectedNode == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) {
     201                                        n0 = selectedNode;
     202                                }                       
     203                        }
     204                       
     205                        if (n0 == null || n0 == n) {
    150206                                return; // Don't create zero length way segments.
    151207                        }
    152208
    153                         // alt modifier makes connection to selected node but not existing way
    154                         Way way = alt ? null : getWayForNode(n0);
     209                        // Ok we know now that we'll insert a line segment, but will it connect to an
     210                        // existing way or make a new way of its own? The "alt" modifier means that the
     211                        // user wants a new way.
     212                       
     213                        Way way = alt ? null : (selectedWay != null) ? selectedWay : getWayForNode(n0);
    155214                        if (way == null) {
    156215                                way = new Way();
     
    175234
    176235                        extendedWay = true;
     236                        Main.ds.setSelected(way);
    177237                }
    178238
     
    186246                                title = tr("Add node into way");
    187247                        }
     248                        Main.ds.setSelected(n);
    188249                } else if (!newNode) {
    189250                        title = tr("Connect existing way to node");
     
    197258       
    198259                Main.main.undoRedo.add(c);
    199                 Main.ds.setSelected(n);
     260                lastUsedNode = n;
    200261                Main.map.mapView.repaint();
    201262        }
Note: See TracChangeset for help on using the changeset viewer.