Changeset 3749 in osm for applications/editors
- Timestamp:
- 2007-07-26T16:04:28+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorAction.java
r3686 r3749 22 22 * 23 23 */ 24 public class NavigatorAction extends AbstractAction implements SelectionChangedListener{24 public class NavigatorAction extends AbstractAction { 25 25 private NavigatorPlugin navigatorPlugin; 26 private List<Node> selectedNodes;27 private int selectionChangedCalls;28 26 29 27 public NavigatorAction(NavigatorPlugin navigatorPlugin) { 30 28 super(tr("Navigate")); 31 29 this.navigatorPlugin = navigatorPlugin; 32 selectedNodes = new ArrayList<Node>();33 DataSet.listeners.add(this);34 30 35 31 } … … 39 35 */ 40 36 public void actionPerformed(ActionEvent e) { 41 navigatorPlugin.navigate(selectedNodes); 42 43 } 44 45 /* (non-Javadoc) 46 * @see org.openstreetmap.josm.data.SelectionChangedListener#selectionChanged(java.util.Collection) 47 */ 48 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 49 ++selectionChangedCalls; 50 // System.out.println("new selection: " + newSelection); 51 // System.out.println("selection till now: " + selectedNodes); 52 if(selectionChangedCalls > 1 && (newSelection == null || newSelection.size() == 0)) { 53 System.out.println("clearing selection for navigation"); 54 selectedNodes.clear(); 55 selectionChangedCalls = 0; 56 return; 57 } 58 if(selectionChangedCalls > 1) { 59 selectionChangedCalls = 0; 60 } 61 Node node; 62 // find a newly selected node and add it to the selection 63 for(OsmPrimitive selectedElement : newSelection) { 64 if(selectedElement instanceof Node) { 65 node = (Node)selectedElement; 66 if(!selectedNodes.contains(node)) { 67 selectedNodes.add(node); 68 // System.out.println("adding node " + node.id); 69 System.out.println("navigation nodes: " + selectedNodes); 70 } 71 } 72 } 37 navigatorPlugin.navigate(); 73 38 } 74 39 -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java
r3686 r3749 20 20 import org.openstreetmap.josm.data.osm.Node; 21 21 import org.openstreetmap.josm.data.osm.Segment; 22 import org.openstreetmap.josm.gui.IconToggleButton; 23 import org.openstreetmap.josm.gui.MapFrame; 24 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 25 import org.openstreetmap.josm.plugins.Plugin; 22 26 23 27 /** … … 25 29 * 26 30 * @author cdaller 27 * 31 * 28 32 */ 29 public class NavigatorPlugin { 30 private Graph graph; 33 public class NavigatorPlugin extends Plugin { 34 private NavigatorLayer navigatorLayer; 35 private NavigatorModel navigatorModel; 31 36 32 33 /** 34 * 35 */ 36 public NavigatorPlugin() { 37 super(); 38 JMenuBar menu = Main.main.menu; 39 JMenu navigatorMenu = new JMenu(tr("Navigation")); 40 JMenuItem navigatorMenuItem = new JMenuItem(new NavigatorAction(this)); 41 navigatorMenu.add(navigatorMenuItem); 42 JMenuItem resetMenuItem = new JMenuItem(tr("Reset Graph")); 43 resetMenuItem.addActionListener(new ActionListener() { 44 public void actionPerformed(ActionEvent e) { 45 graph = null; 46 } 47 }); 48 navigatorMenu.add(resetMenuItem); 49 menu.add(navigatorMenu); 37 /** 38 * 39 */ 40 public NavigatorPlugin() { 41 super(); 42 43 navigatorModel = new NavigatorModel(); 44 navigatorLayer = new NavigatorLayer(tr("Navigation")); 45 navigatorLayer.setNavigatorNodeModel(navigatorModel); 46 47 JMenuBar menu = Main.main.menu; 48 JMenu navigatorMenu = new JMenu(tr("Navigation")); 49 JMenuItem navigatorMenuItem = new JMenuItem(new NavigatorAction(this)); 50 navigatorMenu.add(navigatorMenuItem); 51 JMenuItem resetMenuItem = new JMenuItem(tr("Reset Graph")); 52 resetMenuItem.addActionListener(new ActionListener() { 53 public void actionPerformed(ActionEvent e) { 54 navigatorModel.resetGraph(); 55 } 56 }); 57 navigatorMenu.add(resetMenuItem); 58 menu.add(navigatorMenu); 59 } 50 60 51 }52 53 public Graph<Node, SegmentEdge> getGraph() {54 if(graph == null) {55 OsmGraphCreator graphCreator = new OsmGraphCreator();56 //graph = graphCreator.createGraph();57 graph = graphCreator.createSegmentGraph();61 /* (non-Javadoc) 62 * @see org.openstreetmap.josm.plugins.Plugin#mapFrameInitialized(org.openstreetmap.josm.gui.MapFrame, org.openstreetmap.josm.gui.MapFrame) 63 */ 64 @Override 65 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 66 newFrame.toolBarActions.add( 67 new IconToggleButton(new NavigatorModeAction(newFrame, navigatorModel, navigatorLayer))); 58 68 } 59 return graph;60 }61 69 62 /** 63 * @param startNode 64 * @param endNode 65 */ 66 public void navigate(List<Node> nodes) { 67 System.out.print("navigate nodes "); 68 for(Node node : nodes) { 69 System.out.print(node.id + ","); 70 /** 71 * @param startNode 72 * @param endNode 73 */ 74 public void navigate() { 75 navigatorLayer.navigate(); 70 76 } 71 System.out.println();72 73 DijkstraShortestPath<Node, SegmentEdge> routing;74 List<SegmentEdge> fullPath = new ArrayList<SegmentEdge>();75 List<SegmentEdge> path;76 for(int index = 1; index < nodes.size(); ++index) {77 routing = new DijkstraShortestPath<Node, SegmentEdge>(getGraph(), nodes.get(index - 1), nodes.get(index));78 path = routing.getPathEdgeList();79 if(path == null) {80 System.out.println("no path found!");81 return;82 }83 fullPath.addAll(path);84 }85 List<Segment> segmentPath = new ArrayList<Segment>();86 for(SegmentEdge edge : fullPath) {87 segmentPath.add(edge.getSegment());88 }89 Main.ds.setSelected(segmentPath);90 Main.map.mapView.repaint();91 System.out.println("shortest path found: " + fullPath);92 }93 77 } -
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java
r3686 r3749 42 42 highwayWeight.put("unclassified", 50.0); 43 43 highwayWeight.put("residential", 40.0); 44 highwayWeight.put("footway", 1.0); 44 45 } 45 46 … … 94 95 weight = weightValue.doubleValue(); 95 96 } 96 double distance = segment.from.coor.distance(segment.to.coor) * 111000; // deg to m (at equator :-)97 return distance 97 double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; // deg to m (at equator :-) 98 return distance; // weight; 98 99 } 99 100
Note:
See TracChangeset
for help on using the changeset viewer.