Changeset 26792 in osm for applications/editors


Ignore:
Timestamp:
2011-10-07T07:56:35+02:00 (13 years ago)
Author:
zverik
Message:

У меня не компилируется — ну и нефиг потому что.

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java

    r26644 r26792  
    1010
    1111import org.openstreetmap.josm.Main;
    12 import org.openstreetmap.josm.actions.JosmAction;
    1312import org.openstreetmap.josm.gui.MainMenu;
    1413import org.openstreetmap.josm.gui.MapFrame;
     
    4342    JMenuItem selModifiedNodes;
    4443    JMenuItem selModifiedWays;
     44    JMenuItem selectHighway;
    4545   
    4646    JMenuItem selectURL;
     
    7878        selModifiedWays = MainMenu.add(selectionMenu, new SelectModWaysAction());
    7979        undoSelection = MainMenu.add(selectionMenu, new UndoSelectionAction());
     80        selectHighway = MainMenu.add(selectionMenu, new SelectHighwayAction());
    8081       
    8182        selectURL = MainMenu.add(toolsMenu, new ChooseURLAction());
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectHighwayAction.java

    r26791 r26792  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: PD
    22package utilsplugin2.selection;
    33
    4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    54import static org.openstreetmap.josm.tools.I18n.tr;
    65
    76import java.awt.event.ActionEvent;
    87import java.awt.event.KeyEvent;
    9 import java.util.Collection;
    10 import java.util.HashSet;
    11 import java.util.Set;
     8import java.util.*;
     9import javax.swing.JOptionPane;
     10import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.actions.JosmAction;
    1312import org.openstreetmap.josm.data.osm.*;
    14 
    1513import org.openstreetmap.josm.tools.Shortcut;
    1614
    1715/**
    18  *    Extends current selection by selecting nodes on all touched ways
     16 * Select all connected ways for a street if one way is selected (determine by name/ref),
     17 * select highway ways between two selected ways.
     18 *
     19 * @author zverik
    1920 */
    20 public class ConnectedWaysAction extends JosmAction {
     21public class SelectHighwayAction extends JosmAction {
    2122
    22     public ConnectedWaysAction() {
    23         super(tr("All connected ways"), "adjwaysall", tr("Select all connected ways"),
    24                 Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}","All connected ways"),
    25                 KeyEvent.VK_E, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);
    26         putValue("help", ht("/Action/SelectConnectedWays"));
     23    public SelectHighwayAction() {
     24        super(tr("Select Highway"), "selecthighway", tr("Select highway for the name/ref given"),
     25                Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}","Select Highway"),
     26                KeyEvent.VK_W, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);
    2727    }
    2828
     29    @Override
    2930    public void actionPerformed(ActionEvent e) {
    3031        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    31         Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
    32         Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Way.class);
    33 
     32        List<Way> selectedWays = OsmPrimitive.getFilteredList(getCurrentDataSet().getSelected(), Way.class);
    3433        Set<Way> newWays = new HashSet<Way>();
    3534
    36         // selecting ways attached to selected nodes
    37         if(!selectedNodes.isEmpty()) {
    38             NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays);
     35        if( selectedWays.size() == 1 ) {
     36            Way firstWay = selectedWays.get(0);
     37            String key = firstWay.hasKey("name") ? "name" : "ref";
     38            if( !firstWay.hasKey(key) ) {
     39                JOptionPane.showMessageDialog(Main.parent, "The selected way should have either name or ref tag.", "Select Highway", JOptionPane.ERROR_MESSAGE);
     40                return;
     41            }
     42            String value = firstWay.get(key);
     43
     44            Queue<Node> nodeQueue = new LinkedList<Node>();
     45            nodeQueue.add(firstWay.firstNode());
     46
     47            while( !nodeQueue.isEmpty() ) {
     48                Node node = nodeQueue.remove();
     49                for( Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class) ) {
     50                    if( !newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value) ) {
     51                        newWays.add(p);
     52                        nodeQueue.add(p.firstNode().equals(node) ? p.lastNode() : p.firstNode());
     53                    }
     54                }
     55            }
     56        } else if( selectedWays.size() == 2 ) {
     57            JOptionPane.showMessageDialog(Main.parent, "Sorry, two ways are not supported yet", "Select Highway", JOptionPane.ERROR_MESSAGE);
     58            return;
     59        } else {
     60            JOptionPane.showMessageDialog(Main.parent, "Please select exactly one way for this action", "Select Highway", JOptionPane.ERROR_MESSAGE);
     61            return;
    3962        }
    4063
    41         // select ways attached to already selected ways
    42         newWays.addAll(selectedWays);
    43         NodeWayUtils.addWaysConnectedToWaysRecursively(selectedWays, newWays);
    44        
    45 //        System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());
    4664        getCurrentDataSet().setSelected(newWays);
    47 
    4865    }
    4966
    5067    @Override
    5168    protected void updateEnabledState() {
    52         if (getCurrentDataSet() == null) {
     69        if (getCurrentDataSet() == null)
    5370            setEnabled(false);
    54         } else {
     71        else
    5572            updateEnabledState(getCurrentDataSet().getSelected());
    56         }
    5773    }
    5874
     
    6379            return;
    6480        }
    65         setEnabled(!selection.isEmpty());
     81        int count = 0;
     82        for( OsmPrimitive p : selection )
     83            if( p instanceof Way )
     84                count++;
     85        setEnabled(count == 1); // todo: or 2
    6686    }
    67 
    68 
    6987}
Note: See TracChangeset for help on using the changeset viewer.