Ignore:
Timestamp:
2007-07-29T01:02:05+02:00 (17 years ago)
Author:
christofd
Message:

add description to route

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java

    r3749 r3830  
    1717import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1818import org.openstreetmap.josm.data.osm.Segment;
     19import org.openstreetmap.josm.data.osm.Way;
    1920
    2021/**
     
    2728    private int selectionChangedCalls;
    2829    List<Segment> segmentPath;
     30    List<SegmentEdge> edgePath;
    2931
    3032    public NavigatorModel() {
     
    7476            fullWeight += routing.getPathLength();
    7577        }
    76         segmentPath = new LinkedList<Segment>();
    77         synchronized(segmentPath) {
    78             for (SegmentEdge edge : fullPath) {
    79                 segmentPath.add(edge.getSegment());
     78       
     79        edgePath = new ArrayList<SegmentEdge>();
     80        edgePath.addAll(fullPath);
     81       
     82        System.out.println("shortest path found: " + fullPath + " weight: " + fullWeight);
     83        System.out.println(getPathDescription());
     84//        double weight2 = 0;
     85//        for(Segment seg : getSegmentPath()) {
     86//            weight2 += Math.sqrt(seg.from.coor.distance(seg.to.coor)) * 111000;
     87//        }
     88//        System.out.println("all added: " + weight2);
     89    }
     90   
     91    public String getPathDescription() {
     92        List<PathDescription> pathDescriptions = getPathDescriptions();
     93       
     94        // create text representation from description:
     95        StringBuilder builder = new StringBuilder();
     96        for(PathDescription desc : pathDescriptions) {
     97            builder.append("follow ");
     98            String tmp = desc.getWay().get("name");
     99            if(tmp == null) {
     100                builder.append("unkown street ");
     101            } else {
     102                builder.append(tmp).append(" ");
    80103            }
     104            tmp = desc.getWay().get("highway");
     105            if(tmp != null) {
     106                builder.append("(").append(tmp).append(") ");
     107            }
     108            builder.append("for ").append((int)desc.getLength()).append(" meters, then\n");
    81109        }
    82         Main.ds.setSelected(segmentPath);
    83         Main.map.mapView.repaint();
    84         System.out.println("shortest path found: " + fullPath + " weight: " + fullWeight);
    85        
    86         double weight2 = 0;
    87         for(Segment seg : segmentPath) {
    88             weight2 += Math.sqrt(seg.from.coor.distance(seg.to.coor)) * 111000;
     110        builder.delete(builder.length() - ", then ".length(), builder.length());
     111        return builder.toString();
     112    }
     113
     114    /**
     115     * @return
     116     */
     117    private List<PathDescription> getPathDescriptions() {
     118        List<PathDescription> pathDescriptions = new LinkedList<PathDescription>();
     119        PathDescription description;
     120        double length = 0;
     121        Way oldWay = null;
     122        Way way = null;
     123        for(SegmentEdge edge : edgePath) {
     124            way = edge.getWay();
     125            length += edge.getLengthInM();
     126            if(oldWay != null && !oldWay.equals(way)) {
     127                description = new PathDescription(oldWay, length);
     128                pathDescriptions.add(description);
     129                length = 0;
     130            }
     131            oldWay = way;
    89132        }
    90         System.out.println("all added: " + weight2);
     133        if(way != null) {
     134            description = new PathDescription(way, length);
     135            pathDescriptions.add(description);
     136        }
     137        return pathDescriptions;
    91138    }
    92139
     
    101148
    102149    /**
    103      * @return the segmentPath
     150     * @return the segmentPath or <code>null</code>.
    104151     */
    105152    public List<Segment> getSegmentPath() {
    106         return this.segmentPath;
     153        if(segmentPath == null && edgePath != null) {
     154            segmentPath = new LinkedList<Segment>();
     155            synchronized(segmentPath) {
     156                for (SegmentEdge edge : edgePath) {
     157                    segmentPath.add(edge.getSegment());
     158                }
     159            }
     160        }
     161        return segmentPath;
    107162    }
    108163
     
    115170        nodes.add(node);
    116171    }
     172
     173    /**
     174     * @return the edgePath
     175     */
     176    public List<SegmentEdge> getEdgePath() {
     177        return this.edgePath;
     178    }
    117179   
    118180    /**
    119      * Clear all nodes to navigate.
     181     * Resets all data (nodes, edges, segments).
    120182     */
    121     public void clearNodes() {
    122         nodes.clear();       
     183    public void reset() {
     184        segmentPath = null;
     185        edgePath = null;
     186        nodes.clear();
    123187    }
    124188
Note: See TracChangeset for help on using the changeset viewer.