Changeset 3749 in osm for applications/editors


Ignore:
Timestamp:
2007-07-26T16:04:28+02:00 (17 years ago)
Author:
christofd
Message:

added a mode and a layer to paint the start/end/middle points.
modified length calculation

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  
    2222 *
    2323 */
    24 public class NavigatorAction extends AbstractAction implements SelectionChangedListener {
     24public class NavigatorAction extends AbstractAction {
    2525  private NavigatorPlugin navigatorPlugin;
    26   private List<Node> selectedNodes;
    27   private int selectionChangedCalls;
    2826
    2927  public NavigatorAction(NavigatorPlugin navigatorPlugin) {
    3028    super(tr("Navigate"));
    3129    this.navigatorPlugin = navigatorPlugin;
    32     selectedNodes = new ArrayList<Node>();
    33     DataSet.listeners.add(this);
    3430   
    3531  }
     
    3935   */
    4036  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();
    7338  }
    7439
  • applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorPlugin.java

    r3686 r3749  
    2020import org.openstreetmap.josm.data.osm.Node;
    2121import org.openstreetmap.josm.data.osm.Segment;
     22import org.openstreetmap.josm.gui.IconToggleButton;
     23import org.openstreetmap.josm.gui.MapFrame;
     24import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
     25import org.openstreetmap.josm.plugins.Plugin;
    2226
    2327/**
     
    2529 *
    2630 * @author cdaller
    27  *
     31 * 
    2832 */
    29 public class NavigatorPlugin {
    30   private Graph graph;
     33public class NavigatorPlugin extends Plugin {
     34    private NavigatorLayer navigatorLayer;
     35    private NavigatorModel navigatorModel;
    3136
    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    }
    5060   
    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)));
    5868    }
    59     return graph;
    60   }
    6169
    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();
    7076    }
    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   }
    9377}
  • applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/OsmGraphCreator.java

    r3686 r3749  
    4242    highwayWeight.put("unclassified", 50.0);
    4343    highwayWeight.put("residential", 40.0);
     44    highwayWeight.put("footway", 1.0);
    4445  }
    4546 
     
    9495      weight = weightValue.doubleValue();
    9596    }
    96     double distance = segment.from.coor.distance(segment.to.coor) * 111000; // deg to m (at equator :-)
    97     return distance / weight;
     97    double distance = Math.sqrt(segment.from.coor.distance(segment.to.coor)) * 111000; // deg to m (at equator :-)
     98    return distance; // weight;
    9899  }
    99100 
Note: See TracChangeset for help on using the changeset viewer.