Changeset 422 in josm


Ignore:
Timestamp:
Oct 25, 2007 10:54:01 PM (6 years ago)
Author:
framm
Message:
  • added patch by Matthew Newton <matthew-osm@…> to merge nodes. I know there's already a merge nodes in the utils plugin but I guess we need the node merge in the core, as we already have merging and splitting ways there...
Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

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

    r402 r422  
    2929import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 
    3030import org.openstreetmap.josm.tools.ImageProvider; 
     31import org.openstreetmap.josm.actions.MergeNodesAction; 
    3132/** 
    3233 * Move is an action that can move all kind of OsmPrimitives (except Keys for now). 
     
    232233                } 
    233234                restoreCursor(); 
     235    if (mode == Mode.move) { 
     236                  boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 
     237      if (ctrl) { 
     238                    Collection<OsmPrimitive> selection = Main.ds.getSelected(); 
     239                    Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 
     240                    Collection<Node> nn = Main.map.mapView.getNearestNodes(e.getPoint(), affectedNodes); 
     241        if (nn != null) { 
     242          Node n = nn.iterator().next(); 
     243          LinkedList<Node> selNodes = new LinkedList<Node>(); 
     244          for (OsmPrimitive osm : selection) 
     245            if (osm instanceof Node) 
     246              selNodes.add((Node)osm); 
     247          if (selNodes.size() > 0) { 
     248            selNodes.add(n); 
     249            MergeNodesAction.mergeNodes(selNodes, n); 
     250          } 
     251        } 
     252      } 
     253    } 
    234254                updateStatusLine(); 
    235255                mode = null; 
     
    264284                        return "Release the mouse button to select the objects in the rectangle."; 
    265285                } else if (mode == Mode.move) { 
    266                         return "Release the mouse button to stop moving."; 
     286                        return "Release the mouse button to stop moving. Ctrl to merge with nearest node."; 
    267287                } else if (mode == Mode.rotate) { 
    268288                        return "Release the mouse button to stop rotating."; 
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r420 r422  
    2323import org.openstreetmap.josm.actions.GpxExportAction; 
    2424import org.openstreetmap.josm.actions.HelpAction; 
     25import org.openstreetmap.josm.actions.MergeNodesAction; 
    2526import org.openstreetmap.josm.actions.NewAction; 
    2627import org.openstreetmap.josm.actions.OpenAction; 
     
    6566        public final Action alignInCircle = new AlignInCircleAction(); 
    6667        public final Action alignInLine = new AlignInLineAction(); 
     68        public final Action mergeNodes = new MergeNodesAction(); 
    6769        public final Action upload = new UploadAction(); 
    6870        public final Action save = new SaveAction(null); 
     
    129131                toolsMenu.add(splitWay); 
    130132                toolsMenu.add(combineWay); 
     133                toolsMenu.addSeparator(); 
     134                toolsMenu.add(mergeNodes); 
    131135                add(toolsMenu); 
    132136 
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r407 r422  
    291291 
    292292        /** 
     293         * @return A list of all nodes that are nearest to 
     294         * the mouse.  Does a simple sequential scan on all the data. 
     295         * 
     296         * @return A collection of all nodes or <code>null</code> 
     297         *              if no node under or near the point. The returned 
     298         *              list is never empty. 
     299         */ 
     300        public Collection<Node> getNearestNodes(Point p) { 
     301                Collection<Node> nearest = new HashSet<Node>(); 
     302                for (Node n : Main.ds.nodes) { 
     303                        if (!n.deleted && !n.incomplete 
     304                                        && getPoint(n.eastNorth).distanceSq(p) < 100) { 
     305                                nearest.add(n); 
     306                        } 
     307                } 
     308                return nearest.isEmpty() ? null : nearest; 
     309        } 
     310 
     311        /** 
     312         * @return the nearest nodes to the screen point given that is not  
     313         * in ignore. 
     314         *  
     315         * @param p the point for which to search the nearest segment. 
     316         * @param ignore a collection of nodes which are not to be returned. 
     317         * May be null. 
     318         */ 
     319        public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) { 
     320                Collection<Node> nearest = getNearestNodes(p); 
     321                if (nearest == null) return null; 
     322                if (ignore != null) nearest.removeAll(ignore); 
     323                return nearest.isEmpty() ? null : nearest; 
     324        } 
     325 
     326        /** 
    293327         * @return The projection to be used in calculating stuff. 
    294328         */ 
Note: See TracChangeset for help on using the changeset viewer.