Changeset 26795 in osm for applications
- Timestamp:
- 2011-10-07T22:13:43+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectHighwayAction.java
r26792 r26795 31 31 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 32 32 List<Way> selectedWays = OsmPrimitive.getFilteredList(getCurrentDataSet().getSelected(), Way.class); 33 Set<Way> newWays = new HashSet<Way>();34 33 35 34 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 } 35 getCurrentDataSet().setSelected(selectNamedRoad(selectedWays.get(0))); 36 } else if( selectedWays.size() == 2 ) { 37 getCurrentDataSet().setSelected(selectHighwayBetween(selectedWays.get(0), selectedWays.get(1))); 38 } else { 39 JOptionPane.showMessageDialog(Main.parent, "Please select one or two ways for this action", "Select Highway", JOptionPane.ERROR_MESSAGE); 40 } 41 } 42 43 private Set<Way> selectNamedRoad( Way firstWay ) { 44 Set<Way> newWays = new HashSet<Way>(); 45 String key = firstWay.hasKey("name") ? "name" : "ref"; 46 if( firstWay.hasKey(key) ) { 42 47 String value = firstWay.get(key); 43 44 48 Queue<Node> nodeQueue = new LinkedList<Node>(); 45 49 nodeQueue.add(firstWay.firstNode()); 46 47 50 while( !nodeQueue.isEmpty() ) { 48 51 Node node = nodeQueue.remove(); … … 54 57 } 55 58 } 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;62 59 } 63 64 getCurrentDataSet().setSelected(newWays); 60 return newWays; 65 61 } 66 62 63 private Set<Way> selectHighwayBetween( Way firstWay, Way lastWay ) { 64 int minRank = Math.min(getHighwayRank(firstWay), getHighwayRank(lastWay)); 65 Set<Way> newWays = new HashSet<Way>(); 66 // todo: make two trees and expand them until they touch. 67 // do not lower highway rank! 68 JOptionPane.showMessageDialog(Main.parent, "Sorry, two ways are not supported yet", "Select Highway", JOptionPane.ERROR_MESSAGE); 69 newWays.add(lastWay); 70 newWays.add(firstWay); 71 return newWays; 72 } 73 74 private int getHighwayRank( OsmPrimitive way ) { 75 if( !way.hasKey("highway") ) 76 return 0; 77 String highway = way.get("highway"); 78 if( highway.equals("path") || highway.equals("footway") || highway.equals("cycleway") ) 79 return 1; 80 else if( highway.equals("track") || highway.equals("service") ) 81 return 2; 82 else if( highway.equals("unclassified") || highway.equals("residential") ) 83 return 3; 84 else if( highway.equals("tertiary") || highway.equals("tertiary_link") ) 85 return 4; 86 else if( highway.equals("secondary") || highway.equals("secondary_link") ) 87 return 5; 88 else if( highway.equals("primary") || highway.equals("primary_link") ) 89 return 6; 90 else if( highway.equals("trunk") || highway.equals("trunk_link") || highway.equals("motorway") || highway.equals("motorway_link") ) 91 return 7; 92 return 0; 93 } 94 67 95 @Override 68 96 protected void updateEnabledState() { … … 79 107 return; 80 108 } 81 int count = 0 ;82 for( OsmPrimitive p : selection ) 83 if( p instanceof Way ) 109 int count = 0, rank = 100; 110 for( OsmPrimitive p : selection ) { 111 if( p instanceof Way ) { 84 112 count++; 85 setEnabled(count == 1); // todo: or 2 113 rank = Math.min(rank, getHighwayRank(p)); 114 } 115 } 116 setEnabled(count == 1 || (count == 2 && rank > 0)); 86 117 } 87 118 }
Note:
See TracChangeset
for help on using the changeset viewer.