Ignore:
Timestamp:
18.08.2008 01:27:58 (4 years ago)
Author:
stoecker
Message:

Added virtual nodes in select mode. Closes #595.

File:
1 edited

Legend:

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

    r655 r805  
    1111import java.awt.event.MouseEvent; 
    1212import java.util.Collection; 
     13import java.util.Collections; 
    1314import java.util.LinkedList; 
    1415 
     
    1718import org.openstreetmap.josm.Main; 
    1819import org.openstreetmap.josm.actions.MergeNodesAction; 
     20import org.openstreetmap.josm.command.AddCommand; 
    1921import org.openstreetmap.josm.command.Command; 
     22import org.openstreetmap.josm.command.ChangeCommand; 
    2023import org.openstreetmap.josm.command.MoveCommand; 
    2124import org.openstreetmap.josm.command.RotateCommand; 
     25import org.openstreetmap.josm.command.SequenceCommand; 
    2226import org.openstreetmap.josm.data.coor.EastNorth; 
    2327import org.openstreetmap.josm.data.osm.Node; 
    2428import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     29import org.openstreetmap.josm.data.osm.Way; 
     30import org.openstreetmap.josm.data.osm.WaySegment; 
    2531import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 
    2632import org.openstreetmap.josm.gui.MapFrame; 
     33import org.openstreetmap.josm.gui.MapView; 
    2734import org.openstreetmap.josm.gui.SelectionManager; 
    2835import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 
     
    108115                Main.map.mapView.addMouseListener(this); 
    109116                Main.map.mapView.addMouseMotionListener(this); 
     117                Main.map.mapView.enableVirtualNodes(Main.pref.getInteger("mappaint.node.virtual-size", 4) != 0); 
    110118        } 
    111119 
     
    115123                Main.map.mapView.removeMouseListener(this); 
    116124                Main.map.mapView.removeMouseMotionListener(this); 
     125                Main.map.mapView.enableVirtualNodes(false); 
    117126        } 
    118127 
     
    195204        } 
    196205 
     206        private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) { 
     207                MapView c = Main.map.mapView; 
     208                OsmPrimitive osm = c.getNearestNode(p); 
     209                if (osm == null) 
     210                { 
     211                        WaySegment nearestWaySeg = c.getNearestWaySegment(p); 
     212                        if(nearestWaySeg != null) 
     213                        { 
     214                                osm = nearestWaySeg.way; 
     215                                if(Main.pref.getInteger("mappaint.node.virtual-size", 4) > 0) 
     216                                { 
     217                                        Way w = (Way)osm; 
     218                                        Point p1 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex).eastNorth); 
     219                                        Point p2 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex+1).eastNorth); 
     220                                        int xd = p2.x-p1.x; if(xd < 0) xd = -xd; 
     221                                        int yd = p2.y-p1.y; if(yd < 0) yd = -yd; 
     222                                        if(xd+yd > Main.pref.getInteger("mappaint.node.virtual-space", 50)) 
     223                                        { 
     224                                                Point pc = new Point((p1.x+p2.x)/2, (p1.y+p2.y)/2); 
     225                                                if(p.distanceSq(pc) < Main.map.mapView.snapDistance) 
     226                                                { 
     227                                                        Collection<Command> cmds = new LinkedList<Command>(); 
     228                                                        Node n = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 
     229                                                        cmds.add(new AddCommand(n)); 
     230 
     231                                                        Way wnew = new Way(w); 
     232                                                        wnew.nodes.add(nearestWaySeg.lowerIndex+1, n); 
     233                                                        cmds.add(new ChangeCommand(w, wnew)); 
     234                                                        Main.main.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"), cmds)); 
     235                                                        osm = n; 
     236                                                } 
     237                                        } 
     238                                } 
     239                        } 
     240                } 
     241                if (osm == null)  
     242                        return Collections.emptySet(); 
     243                return Collections.singleton(osm); 
     244        } 
     245 
    197246        /** 
    198247         * Look, whether any object is selected. If not, select the nearest node. 
     
    216265                initialMoveThresholdExceeded = false; 
    217266 
    218                 Collection<OsmPrimitive> osmColl = 
    219                         Main.map.mapView.getNearestCollection(e.getPoint()); 
     267                Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint()); 
    220268 
    221269                if (ctrl && shift) { 
     
    289337 
    290338        public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, boolean ctrl) { 
    291             if (shift && ctrl) 
     339                if (shift && ctrl) 
    292340                        return; // not allowed together 
    293341 
     
    305353                Main.ds.setSelected(curSel); 
    306354                Main.map.mapView.repaint(); 
    307     } 
     355        } 
    308356         
    309357        @Override public String getModeHelpText() { 
Note: See TracChangeset for help on using the changeset viewer.