Changeset 3830 in osm for applications/editors/josm/plugins/navigator/src
- Timestamp:
- 2007-07-29T01:02:05+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorModel.java
r3749 r3830 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 18 import org.openstreetmap.josm.data.osm.Segment; 19 import org.openstreetmap.josm.data.osm.Way; 19 20 20 21 /** … … 27 28 private int selectionChangedCalls; 28 29 List<Segment> segmentPath; 30 List<SegmentEdge> edgePath; 29 31 30 32 public NavigatorModel() { … … 74 76 fullWeight += routing.getPathLength(); 75 77 } 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(" "); 80 103 } 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"); 81 109 } 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; 89 132 } 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; 91 138 } 92 139 … … 101 148 102 149 /** 103 * @return the segmentPath 150 * @return the segmentPath or <code>null</code>. 104 151 */ 105 152 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; 107 162 } 108 163 … … 115 170 nodes.add(node); 116 171 } 172 173 /** 174 * @return the edgePath 175 */ 176 public List<SegmentEdge> getEdgePath() { 177 return this.edgePath; 178 } 117 179 118 180 /** 119 * Clear all nodes to navigate.181 * Resets all data (nodes, edges, segments). 120 182 */ 121 public void clearNodes() { 122 nodes.clear(); 183 public void reset() { 184 segmentPath = null; 185 edgePath = null; 186 nodes.clear(); 123 187 } 124 188
Note:
See TracChangeset
for help on using the changeset viewer.