Changeset 1441 in josm for trunk/src


Ignore:
Timestamp:
2009-02-24T18:49:06+01:00 (15 years ago)
Author:
stoecker
Message:

fixed #1469. patch by xeen

File:
1 edited

Legend:

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

    r1421 r1441  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.awt.Cursor;
     
    6162    private boolean cancelDrawMode = false;
    6263    Node virtualNode = null;
    63     WaySegment virtualWay = null;
     64    Collection<WaySegment> virtualWays = new ArrayList<WaySegment>();
    6465    SequenceCommand virtualCmds = null;
    6566
     
    147148        if(!Main.map.mapView.isVisibleDrawableLayer())
    148149            return;
    149        
     150
    150151        cancelDrawMode = true;
    151152        if (mode == Mode.select) return;
     
    181182            return;
    182183
    183         if (virtualWay != null)    {
     184        if (virtualWays.size() > 0) {
    184185            Collection<Command> virtualCmds = new LinkedList<Command>();
    185186            virtualCmds.add(new AddCommand(virtualNode));
    186             Way w = virtualWay.way;
    187             Way wnew = new Way(w);
    188             wnew.addNode(virtualWay.lowerIndex+1, virtualNode);
    189             virtualCmds.add(new ChangeCommand(w, wnew));
     187            for(WaySegment virtualWay : virtualWays) {
     188                Way w = virtualWay.way;
     189                Way wnew = new Way(w);
     190                wnew.addNode(virtualWay.lowerIndex+1, virtualNode);
     191                virtualCmds.add(new ChangeCommand(w, wnew));
     192            }
    190193            virtualCmds.add(new MoveCommand(virtualNode, dx, dy));
    191             Main.main.undoRedo.add(new SequenceCommand(tr("Add and move a virtual new node to way"), virtualCmds));
     194            String text = trn("Add and move a virtual new node to way",
     195            "Add and move a virtual new node to {0} ways", virtualWays.size(),
     196            virtualWays.size());
     197
     198            Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds));
    192199            selectPrims(Collections.singleton((OsmPrimitive)virtualNode), false, false);
    193             virtualWay = null;
     200            virtualWays.clear();
    194201            virtualNode = null;
    195202        } else {
     
    222229                        JOptionPane.showMessageDialog(Main.parent,
    223230                            tr("Cannot move objects outside of the world."));
     231                        restoreCursor();
    224232                        return;
    225233                    }
     
    239247    }
    240248
    241     private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p) {
     249    private Collection<OsmPrimitive> getNearestCollectionVirtual(Point p, boolean allSegements) {
    242250        MapView c = Main.map.mapView;
    243251        int snapDistance = Main.pref.getInteger("mappaint.node.virtual-snap-distance", 8);
    244252        snapDistance *= snapDistance;
    245253        OsmPrimitive osm = c.getNearestNode(p);
    246         virtualWay = null;
     254        virtualWays.clear();
    247255        virtualNode = null;
     256        Node virtualWayNode = null;
    248257
    249258        if (osm == null)
    250259        {
    251             WaySegment nearestWaySeg = c.getNearestWaySegment(p);
    252             if (nearestWaySeg != null)
    253             {
    254                 osm = nearestWaySeg.way;
     260            Collection<WaySegment> nearestWaySegs = allSegements
     261                 ? c.getNearestWaySegments(p)
     262                 : Collections.singleton(c.getNearestWaySegment(p));
     263
     264            for(WaySegment nearestWS : nearestWaySegs) {
     265                if (nearestWS == null)
     266                    continue;
     267
     268                osm = nearestWS.way;
    255269                if(Main.pref.getInteger("mappaint.node.virtual-size", 8) > 0)
    256270                {
    257271                    Way w = (Way)osm;
    258                     Point p1 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex).eastNorth);
    259                     Point p2 = c.getPoint(w.nodes.get(nearestWaySeg.lowerIndex+1).eastNorth);
     272                    Point p1 = c.getPoint(w.nodes.get(nearestWS.lowerIndex).eastNorth);
     273                    Point p2 = c.getPoint(w.nodes.get(nearestWS.lowerIndex+1).eastNorth);
    260274                    if(SimplePaintVisitor.isLargeSegment(p1, p2, Main.pref.getInteger("mappaint.node.virtual-space", 70)))
    261275                    {
     
    263277                        if (p.distanceSq(pc) < snapDistance)
    264278                        {
    265                             virtualWay = nearestWaySeg;
    266                             virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y));
    267                             osm = w;
     279                            // Check that only segments on top of each other get added to the
     280                            // virtual ways list. Otherwise ways that coincidentally have their
     281                            // virtual node at the same spot will be joined which is likely unwanted
     282                            if(virtualWayNode != null) {
     283                                if(  !w.nodes.get(nearestWS.lowerIndex+1).equals(virtualWayNode)
     284                                  && !w.nodes.get(nearestWS.lowerIndex  ).equals(virtualWayNode))
     285                                    continue;
     286                            } else
     287                                virtualWayNode = w.nodes.get(nearestWS.lowerIndex+1);
     288
     289                            virtualWays.add(nearestWS);
     290                            if(virtualNode == null)
     291                                virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y));
    268292                        }
    269293                    }
     
    288312        if(!Main.map.mapView.isVisibleDrawableLayer())
    289313            return;
    290        
     314
    291315        cancelDrawMode = false;
    292316        if (! (Boolean)this.getValue("active")) return;
     
    294318            return;
    295319        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    296         // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     320        boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
    297321        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    298        
     322
    299323        // We don't want to change to draw tool if the user tries to (de)select
    300324        // stuff but accidentally clicks in an empty area when selection is empty
     
    306330        initialMoveThresholdExceeded = false;
    307331
    308         Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint());
     332        Collection<OsmPrimitive> osmColl = getNearestCollectionVirtual(e.getPoint(), alt);
    309333
    310334        if (ctrl && shift) {
     
    330354        {
    331355            virtualNode = null;
    332             virtualWay = null;
     356            virtualWays.clear();
    333357        }
    334358
    335359        updateStatusLine();
    336         Main.map.mapView.repaint();
     360        // Mode.select redraws when selectPrims is called
     361        // Mode.move   redraws when mouseDragged is called
     362        // Mode.rotate redraws here
     363        if(mode == Mode.rotate)
     364            Main.map.mapView.repaint();
    337365
    338366        mousePos = e.getPoint();
     
    345373        if(!Main.map.mapView.isVisibleDrawableLayer())
    346374            return;
    347        
     375
    348376        if (mode == Mode.select) {
    349377            selectionManager.unregister(Main.map.mapView);
     
    398426        }
    399427
    400         updateStatusLine();
     428        // I don't see why we need this.
     429        //updateStatusLine();
    401430        mode = null;
    402431        updateStatusLine();
Note: See TracChangeset for help on using the changeset viewer.