Changeset 26318 in osm for applications/editors


Ignore:
Timestamp:
2011-07-13T12:15:18+02:00 (13 years ago)
Author:
akks
Message:

'Utilsplugin2: added ExtractNode tool Alt-J'

Location:
applications/editors/josm/plugins/utilsplugin2
Files:
1 added
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/build.xml

    r26174 r26318  
    3030<project name="utilsplugin2" default="dist" basedir=".">
    3131    <!-- enter the SVN commit message -->
    32     <property name="commit.message" value="extend selection"/>
     32    <property name="commit.message" value="Utilsplugin2: added ExtractNode tool Alt-J"/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    34     <property name="plugin.main.version" value="4064"/>
     34    <property name="plugin.main.version" value="4201"/>
    3535    <!--
    3636      ************************************************
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/ExtractPointAction.java

    r26315 r26318  
    11// License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
    2 package utilsplugin2.selection;
     2package utilsplugin2;
    33
     4import java.awt.MouseInfo;
     5import java.awt.Point;
    46import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    57import static org.openstreetmap.josm.tools.I18n.tr;
     
    810import java.awt.event.KeyEvent;
    911import java.util.Collection;
    10 import java.util.Set;
     12import java.util.LinkedList;
     13import java.util.List;
     14import javax.swing.JOptionPane;
     15import org.openstreetmap.josm.Main;
    1116import org.openstreetmap.josm.actions.JosmAction;
     17import org.openstreetmap.josm.command.AddCommand;
     18import org.openstreetmap.josm.command.ChangeNodesCommand;
     19import org.openstreetmap.josm.command.Command;
     20import org.openstreetmap.josm.command.MoveCommand;
     21import org.openstreetmap.josm.command.SequenceCommand;
    1222import org.openstreetmap.josm.data.osm.*;
    1323
     
    1727 *    Unselects all nodes
    1828 */
    19 public class UnselectNodesAction extends JosmAction {
     29public class ExtractPointAction extends JosmAction {
    2030
    2131   
    22     public UnselectNodesAction() {
    23         super(tr("Unselect nodes"), "unsnodes",
    24                 tr("Removes all nodes from selection"),
    25                 Shortcut.registerShortcut("tools:unsnodes", tr("Tool: {0}","Unselect nodes"),
    26                 KeyEvent.VK_U, Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_MASK  ), true);
    27         putValue("help", ht("/Action/UnselectNodes"));
     32    public ExtractPointAction() {
     33        super(tr("Extract node"), "extpoint",
     34                tr("Extracts node from a way"),
     35                Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}","Extract node"),
     36                KeyEvent.VK_J, Shortcut.GROUP_MNEMONIC,KeyEvent.ALT_MASK  ), true);
     37        putValue("help", ht("/Action/ExtractNode"));
    2838    }
    2939
    3040    public void actionPerformed(ActionEvent e) {
    3141        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    32         Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
    33         getCurrentDataSet().clearSelection(selectedNodes);
     42        List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
     43        if (selectedNodes.size()!=1) {
     44             JOptionPane.showMessageDialog(Main.parent,
     45                    tr("This tool extracts node from its ways and requires single node to be selected."),
     46                    tr("Extract node"), JOptionPane.INFORMATION_MESSAGE);
     47            return;
     48        }
     49        Node nd = selectedNodes.get(0);
     50        Node ndCopy = new Node(nd.getCoor());
     51        List<Command> cmds = new LinkedList<Command>();
     52       
     53        Point p = Main.map.mapView.getMousePosition();
     54        if (p!=null) cmds.add(new MoveCommand(nd,Main.map.mapView.getLatLon(p.x, p.y)));
     55        List<OsmPrimitive> refs = nd.getReferrers();
     56        cmds.add(new AddCommand(ndCopy));
     57       
     58        for (OsmPrimitive pr: refs) {
     59            if (pr instanceof Way) {
     60                Way w=(Way)pr;
     61                List<Node> nodes = w.getNodes();
     62                int idx=nodes.indexOf(nd);
     63                nodes.set(idx, ndCopy); // replace node with its copy
     64                cmds.add(new ChangeNodesCommand(w, nodes));
     65            }
     66        }
     67        if (cmds.size()>1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"),cmds));
    3468    }
    3569
     
    4983            return;
    5084        }
    51         setEnabled(!selection.isEmpty());
     85        setEnabled(selection.size()==1);
    5286    }
    5387}
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java

    r26293 r26318  
    2828    JMenuItem intWaysR;
    2929    JMenuItem undoSelection;
     30    JMenuItem extractPoint;
    3031
    3132    JMenuItem replaceGeometry;
     
    3738    JMenuItem selModifiedNodes;
    3839    JMenuItem selModifiedWays;
    39 
     40   
    4041    public UtilsPlugin2(PluginInformation info) {
    4142        super(info);
     
    5354        alignWayNodes = MainMenu.add(toolsMenu, new AlignWayNodesAction());
    5455        splitOnIntersections = MainMenu.add(toolsMenu, new SplitOnIntersectionsAction());
     56        extractPoint = MainMenu.add(toolsMenu, new ExtractPointAction());
    5557
    5658        JMenu selectionMenu = Main.main.menu.addMenu(marktr("Selection"), KeyEvent.VK_N, Main.main.menu.defaultMenuPos, "help");
Note: See TracChangeset for help on using the changeset viewer.