Ignore:
Timestamp:
2007-10-13T00:12:31+02:00 (17 years ago)
Author:
framm
Message:
  • introduced various modifier keys to existing modes (for add node mode, shift to disable auto-connect and ctrl to disable auto-insert/reuse; for delete mode, shift to delete way segment and alt to delete way+nodes)
  • added small help bar at bottom of screen to display available modifiers
Location:
trunk/src/org/openstreetmap/josm/actions/mapmode
Files:
5 edited

Legend:

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

    r368 r373  
    8383                        c = deleteWithReferences(Main.ds.getSelected());
    8484                } else {
    85                         c = delete(Main.ds.getSelected());
     85                        c = delete(Main.ds.getSelected(), false);
    8686                }
    8787                if (c != null) {
     
    100100                        return;
    101101                boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     102                boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     103                boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     104                System.out.println("meta="+alt);
    102105               
    103106                OsmPrimitive sel = Main.map.mapView.getNearestNode(e.getPoint());
     
    105108                if (sel == null) {
    106109                        WaySegment ws = Main.map.mapView.getNearestWaySegment(e.getPoint());
    107                         if (ws != null) c = deleteWaySegment(ws);
     110                        if (ws != null) {
     111                                if (shift) {
     112                                        c = deleteWaySegment(ws);
     113                                } else if (ctrl) {
     114                                        c = deleteWithReferences(Collections.singleton((OsmPrimitive)ws.way));
     115                                } else {
     116                                        c = delete(Collections.singleton((OsmPrimitive)ws.way), alt);
     117                                }
     118                        }
    108119                } else if (ctrl) {
    109120                        c = deleteWithReferences(Collections.singleton(sel));
    110121                } else {
    111                         c = delete(Collections.singleton(sel));
     122                        c = delete(Collections.singleton(sel), alt);
    112123                }
    113124                if (c != null) {
     
    155166         *
    156167         * @param selection The objects to delete.
     168         * @param alsoDeleteNodesInWay true if nodes should be deleted as well
    157169         * @return command A command to perform the deletions, or null of there is
    158170         * nothing to delete.
    159171         */
    160         private Command delete(Collection<OsmPrimitive> selection) {
     172        private Command delete(Collection<OsmPrimitive> selection, boolean alsoDeleteNodesInWay) {
    161173                if (selection.isEmpty()) return null;
    162174
    163175                Collection<OsmPrimitive> del = new HashSet<OsmPrimitive>(selection);
    164176                Collection<Way> waysToBeChanged = new HashSet<Way>();
     177               
     178                // nodes belonging to a way will be deleted if
     179                // 1. this has been requested (alt modifier)
     180                // 2. the node is not tagged
     181                // 3. the node is not used by anybody else (i.e. has only one backref)
     182                if (alsoDeleteNodesInWay) {
     183                        for (OsmPrimitive osm : del) {
     184                                if (osm instanceof Way) {
     185                                        for (Node n : ((Way)osm).nodes) {
     186                                                if (!n.tagged) {
     187                                                        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
     188                                                        n.visit(v);
     189                                                        if (v.data.size() == 1) {
     190                                                                del.add(n);
     191                                                        } else System.out.println("size="+v.data.size());
     192                                                }
     193                                                else System.out.println("tagged");
     194                                        }
     195                                }
     196                        }
     197                }
     198               
    165199                for (OsmPrimitive osm : del) {
    166200                        CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
     
    217251                if (n1.size() < 2 && n2.size() < 2) {
    218252                        return new DeleteCommand(Collections.singleton(ws.way));
    219                 } else {
    220                         Way wnew = new Way(ws.way);
    221                         wnew.nodes.clear();
    222 
    223                         if (n1.size() < 2) {
    224                                 wnew.nodes.addAll(n2);
    225                                 return new ChangeCommand(ws.way, wnew);
    226                         } else if (n2.size() < 2) {
    227                                 wnew.nodes.addAll(n1);
    228                                 return new ChangeCommand(ws.way, wnew);
    229                         } else {
    230                                 Collection<Command> cmds = new LinkedList<Command>();
    231 
    232                                 wnew.nodes.addAll(n1);
    233                                 cmds.add(new ChangeCommand(ws.way, wnew));
    234 
    235                                 Way wnew2 = new Way();
    236                                 wnew2.nodes.addAll(n2);
    237                                 cmds.add(new AddCommand(wnew2));
    238 
    239                                 return new SequenceCommand(tr("Split way segment"), cmds);
    240                         }
    241                 }
     253                }
     254               
     255                Way wnew = new Way(ws.way);
     256                wnew.nodes.clear();
     257
     258                if (n1.size() < 2) {
     259                        wnew.nodes.addAll(n2);
     260                        return new ChangeCommand(ws.way, wnew);
     261                } else if (n2.size() < 2) {
     262                        wnew.nodes.addAll(n1);
     263                        return new ChangeCommand(ws.way, wnew);
     264                } else {
     265                        Collection<Command> cmds = new LinkedList<Command>();
     266
     267                        wnew.nodes.addAll(n1);
     268                        cmds.add(new ChangeCommand(ws.way, wnew));
     269
     270                        Way wnew2 = new Way();
     271                        wnew2.nodes.addAll(n2);
     272                        cmds.add(new AddCommand(wnew2));
     273
     274                        return new SequenceCommand(tr("Split way segment"), cmds);
     275                }
     276        }
     277       
     278        @Override public String getModeHelpText() {
     279                return "Click to delete. Shift: delete way segment. Alt: delete way+nodes. Ctrl: delete referring objects.";
    242280        }
    243281}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r359 r373  
    55
    66import java.awt.Cursor;
     7import java.awt.event.ActionEvent;
    78import java.awt.event.KeyEvent;
    89import java.awt.event.MouseEvent;
     
    2021import org.openstreetmap.josm.Main;
    2122import org.openstreetmap.josm.actions.GroupAction;
     23import org.openstreetmap.josm.actions.mapmode.SelectAction.Mode;
    2224import org.openstreetmap.josm.command.AddCommand;
    2325import org.openstreetmap.josm.command.ChangeCommand;
     
    3335
    3436/**
    35  * This mode adds a new node to the dataset. The user clicks on a place to add
    36  * and there is it. Nothing more, nothing less.
    37  *
    38  * FIXME: "nothing more, nothing less" is a bit out-of-date
    39  *
    40  * Newly created nodes are selected. Shift modifier does not cancel the old
    41  * selection as usual.
    42  *
    43  * @author imi
    4437 *
    4538 */
     
    8073                        return;
    8174
     75                boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     76                boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     77                boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     78               
    8279                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    8380                Collection<Command> cmds = new LinkedList<Command>();
     
    8683                        replacedWays = new ArrayList<Way>();
    8784                boolean newNode = false;
    88                 Node n = Main.map.mapView.getNearestNode(e.getPoint());
     85                Node n = null;
     86                if (!ctrl) n = Main.map.mapView.getNearestNode(e.getPoint());
    8987                if (n == null) {
    9088                        n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
     
    9896                        cmds.add(new AddCommand(n));
    9997
    100                         // Insert the node into all the nearby way segments
    101                         List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint());
    102                         Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
    103                         for (WaySegment ws : wss) {
    104                                 List<Integer> is;
    105                                 if (insertPoints.containsKey(ws.way)) {
    106                                         is = insertPoints.get(ws.way);
    107                                 } else {
    108                                         is = new ArrayList<Integer>();
    109                                         insertPoints.put(ws.way, is);
     98                        if (!ctrl) {
     99                                // Insert the node into all the nearby way segments
     100                                List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint());
     101                                Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
     102                                for (WaySegment ws : wss) {
     103                                        List<Integer> is;
     104                                        if (insertPoints.containsKey(ws.way)) {
     105                                                is = insertPoints.get(ws.way);
     106                                        } else {
     107                                                is = new ArrayList<Integer>();
     108                                                insertPoints.put(ws.way, is);
     109                                        }
     110
     111                                        is.add(ws.lowerIndex);
    110112                                }
    111 
    112                                 is.add(ws.lowerIndex);
    113                         }
    114                         for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) {
    115                                 Way w = insertPoint.getKey();
    116                                 List<Integer> is = insertPoint.getValue();
    117 
    118                                 Way wnew = new Way(w);
    119 
    120                                 pruneSuccsAndReverse(is);
    121                                 for (int i : is) wnew.nodes.add(i + 1, n);
    122 
    123                                 cmds.add(new ChangeCommand(insertPoint.getKey(), wnew));
    124                                 replacedWays.add(insertPoint.getKey());
    125                                 reuseWays.add(wnew);
    126                         }
    127                 }
    128 
     113                       
     114                                for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) {
     115                                        Way w = insertPoint.getKey();
     116                                        List<Integer> is = insertPoint.getValue();
     117
     118                                        Way wnew = new Way(w);
     119
     120                                        pruneSuccsAndReverse(is);
     121                                        for (int i : is) wnew.nodes.add(i + 1, n);
     122
     123                                        cmds.add(new ChangeCommand(insertPoint.getKey(), wnew));
     124                                        replacedWays.add(insertPoint.getKey());
     125                                        reuseWays.add(wnew);
     126                                }
     127                        }
     128                }
    129129                boolean extendedWay = false;
    130                 if (selection.size() == 1 && selection.iterator().next() instanceof Node) {
     130                if (!shift && selection.size() == 1 && selection.iterator().next() instanceof Node) {
    131131                        Node n0 = (Node) selection.iterator().next();
    132132
     
    213213                Collections.reverse(is);
    214214        }
     215       
     216        @Override public String getModeHelpText() {
     217                return "Click to add a new node. Ctrl to disable node re-use/auto-insert. Shift to disable auto-connect.";
     218        }
    215219}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r343 r373  
    4848                oldCursor = Main.map.mapView.getCursor();
    4949                Main.map.mapView.setCursor(cursor);
    50                
     50                updateStatusLine();
    5151        }
    5252        public void exitMode() {
     
    5555        }
    5656
     57        protected void updateStatusLine() {
     58                Main.map.statusLine.setHelpText(getModeHelpText());
     59        }
     60       
     61        public String getModeHelpText() {
     62                return "";
     63        }
    5764        /**
    5865         * Call selectMapMode(this) on the parent mapFrame.
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r372 r373  
    199199                }
    200200
     201                updateStatusLine();
    201202                Main.map.mapView.repaint();
    202203
     
    212213                }
    213214                restoreCursor();
     215                updateStatusLine();
    214216                mode = null;
     217                updateStatusLine();
    215218        }
    216219
     
    237240                Main.map.mapView.repaint();
    238241    }
     242       
     243        @Override public String getModeHelpText() {
     244                if (mode == Mode.select) {
     245                        return "Release the mouse button to select the objects in the rectangle.";
     246                } else if (mode == Mode.move) {
     247                        return "Release the mouse button to stop moving.";
     248                } else if (mode == Mode.rotate) {
     249                        return "Release the mouse button to stop rotating.";
     250                } else {
     251                        return "Move objects by dragging; Shift to add to selection; Shift-Ctrl to rotate selected; or change selection";
     252                }
     253        }
    239254}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java

    r298 r373  
    7070                selectionManager.unregister(mv);
    7171        }
     72       
     73        @Override public String getModeHelpText() {
     74                return "Zoom in by dragging.";
     75        }
    7276}
Note: See TracChangeset for help on using the changeset viewer.