Changeset 29962 in osm for applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap
- Timestamp:
- 2013-09-25T20:34:15+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java
r29958 r29962 22 22 import org.openstreetmap.josm.data.gpx.GpxTrack; 23 23 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 24 import org.openstreetmap.josm.data.gpx.IWithAttributes; 24 25 import org.openstreetmap.josm.data.gpx.WayPoint; 25 26 import org.openstreetmap.josm.plugins.elevation.IElevationModel; … … 44 45 private List<WayPoint> buffer = new ArrayList<WayPoint>(); 45 46 private int currentProfileIndex = 0; 46 private ElevationProfile BasecurProfile = null;47 private ElevationProfile curProfile = null; 47 48 48 49 /** … … 115 116 } 116 117 117 /* 118 * (non-Javadoc) 119 * 120 * @see 121 * org.openstreetmap.josm.plugins.elevation.IGpxVisitor#visit(org.openstreetmap 122 * .josm.data.gpx.GpxRoute, org.openstreetmap.josm.data.gpx.WayPoint) 123 */ 124 public void visit(GpxRoute route, WayPoint wp) { 125 processWayPoint(wp); 126 } 127 128 /* 129 * (non-Javadoc) 130 * 131 * @see 132 * org.openstreetmap.josm.plugins.elevation.IGpxVisitor#visit(org.openstreetmap 133 * .josm.data.gpx.GpxTrack, org.openstreetmap.josm.data.gpx.GpxTrackSegment, 134 * org.openstreetmap.josm.data.gpx.WayPoint) 135 */ 136 public void visit(GpxTrack track, GpxTrackSegment segment, WayPoint wp) { 137 // we ignore the segment here 138 processWayPoint(wp); 139 118 /* (non-Javadoc) 119 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#getProfiles() 120 */ 121 @Override 122 public List<IElevationProfile> getProfiles() { 123 return profiles; 124 } 125 126 /* (non-Javadoc) 127 * @see org.openstreetmap.josm.plugins.elevation.IElevationModel#getCurrentProfile() 128 */ 129 @Override 130 public IElevationProfile getCurrentProfile() { 131 if (currentProfileIndex < 0 || currentProfileIndex >= profileCount()) return null; 132 133 return profiles.get(currentProfileIndex); 134 } 135 136 /* (non-Javadoc) 137 * @see org.openstreetmap.josm.plugins.elevation.IElevationModel#setCurrentProfile(org.openstreetmap.josm.plugins.elevation.IElevationProfile) 138 */ 139 @Override 140 public void setCurrentProfile(IElevationProfile newProfile) { 141 CheckParameterUtil.ensureParameterNotNull(newProfile); 142 143 if (!profiles.contains(newProfile)) { 144 profiles.add(newProfile); 145 } 146 147 setCurrentProfile(profiles.indexOf(newProfile)); 148 } 149 150 /* (non-Javadoc) 151 * @see org.openstreetmap.josm.plugins.elevation.IElevationModel#setCurrentProfile(int) 152 */ 153 @Override 154 public void setCurrentProfile(int index) { 155 if (index < 0 || index >= profileCount()) throw new RuntimeException("Invalid arg for setCurrentProfile: " + index + ", value must be 0.." + profileCount()); 156 157 currentProfileIndex = index; 158 fireModelChanged(); 159 } 160 161 /* (non-Javadoc) 162 * @see org.openstreetmap.josm.plugins.elevation.IElevationModel#profileCount() 163 */ 164 @Override 165 public int profileCount() { 166 return profiles != null ? profiles.size() : 0; 167 } 168 169 // Visitor stuff starts here... 170 171 /* (non-Javadoc) 172 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#beginWayPoints() 173 */ 174 public void beginWayPoints() { 175 // we ignore single way points (elevation profile is quite meaningless...) 176 } 177 178 /* (non-Javadoc) 179 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#endWayPoints() 180 */ 181 public void endWayPoints() { 182 // we ignore single way points (elevation profile is quite meaningless...) 140 183 } 141 184 … … 144 187 */ 145 188 @Override 146 public void visit(WayPoint wp) { 147 processWayPoint(wp); 148 } 149 150 public void start() { 151 curProfile = new ElevationProfileBase(name); 152 trackCounter++; 153 } 154 155 public void end() { 156 commitTrack(); 157 } 158 159 160 @Override 161 public void start(GpxTrack track) { 189 public void visitWayPoint(WayPoint wp) { 190 // we ignore single way points (elevation profile is quite meaningless...) 191 } 192 193 194 /* (non-Javadoc) 195 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#beginTrack(org.openstreetmap.josm.data.gpx.GpxTrack) 196 */ 197 @Override 198 public void beginTrack(GpxTrack track) { 199 createProfile(track); 200 } 201 202 /* (non-Javadoc) 203 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#endTrack(org.openstreetmap.josm.data.gpx.GpxTrack) 204 */ 205 @Override 206 public void endTrack(GpxTrack track) { 207 if (curProfile == null) throw new RuntimeException("Internal error: No elevation profile"); 208 209 curProfile.setDistance(track.length()); 210 commitProfile(); 211 } 212 213 /* (non-Javadoc) 214 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#beginTrackSegment(org.openstreetmap.josm.data.gpx.GpxTrack, org.openstreetmap.josm.data.gpx.GpxTrackSegment) 215 */ 216 @Override 217 public void beginTrackSegment(GpxTrack track, GpxTrackSegment segment) { 218 // Nothing to do here for now 219 } 220 221 /* (non-Javadoc) 222 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#endTrackSegment(org.openstreetmap.josm.data.gpx.GpxTrack, org.openstreetmap.josm.data.gpx.GpxTrackSegment) 223 */ 224 @Override 225 public void endTrackSegment(GpxTrack track, GpxTrackSegment segment) { 226 // Nothing to do here for now 227 } 228 229 /* (non-Javadoc) 230 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#visitTrackPoint(org.openstreetmap.josm.data.gpx.WayPoint, org.openstreetmap.josm.data.gpx.GpxTrack, org.openstreetmap.josm.data.gpx.GpxTrackSegment) 231 */ 232 @Override 233 public void visitTrackPoint(WayPoint wp, GpxTrack track, 234 GpxTrackSegment segment) { 235 236 processWayPoint(wp); 237 } 238 239 240 /* (non-Javadoc) 241 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#beginRoute(org.openstreetmap.josm.data.gpx.GpxRoute) 242 */ 243 @Override 244 public void beginRoute(GpxRoute route) { 245 createProfile(route); 246 } 247 248 /* (non-Javadoc) 249 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#endRoute(org.openstreetmap.josm.data.gpx.GpxRoute) 250 */ 251 @Override 252 public void endRoute(GpxRoute route) { 253 if (curProfile == null) throw new RuntimeException("Internal error: No elevation profile"); 254 // a GpxRoute has no 'length' property 255 curProfile.setDistance(0); 256 commitProfile(); 257 } 258 259 /* (non-Javadoc) 260 * @see org.openstreetmap.josm.plugins.elevation.gpx.IGpxVisitor#visitRoutePoint(org.openstreetmap.josm.data.gpx.WayPoint, org.openstreetmap.josm.data.gpx.GpxRoute) 261 */ 262 @Override 263 public void visitRoutePoint(WayPoint wp, GpxRoute route) { 264 processWayPoint(wp); 265 } 266 267 /** 268 * Creates a new profile. 269 * 270 * @param trackOrRoute the track or route 271 */ 272 private void createProfile(IWithAttributes trackOrRoute) { 162 273 // check GPX data 163 String trackName = (String) track .get("name");274 String trackName = (String) trackOrRoute.get("name"); 164 275 165 276 // no name given, build artificial one 166 277 if (trackName == null) { 167 trackName = (String) track .get(GpxData.META_NAME);278 trackName = (String) trackOrRoute.get(GpxData.META_NAME); 168 279 if (trackName == null) { 169 280 trackName = name + "." + trackCounter; … … 171 282 } 172 283 173 curProfile = new ElevationProfileBase(trackName); 174 } 175 176 @Override 177 public void end(GpxTrack track) { 178 if (curProfile == null) throw new RuntimeException("Internal error: No elevation profile"); 179 180 curProfile.setDistance(track.length()); 181 commitTrack(); 182 } 183 184 @Override 185 public void start(GpxTrack track, GpxTrackSegment segment) { 186 // Nothing to do here for now 187 } 188 189 @Override 190 public void end(GpxTrack track, GpxTrackSegment segment) { 191 // Nothing to do here for now 192 } 193 284 curProfile = new ElevationProfile(trackName); 285 } 194 286 195 287 /** … … 198 290 * @param trackName the track name 199 291 */ 200 private void commit Track() {292 private void commitProfile() { 201 293 if (buffer.size() > 0) { 202 294 // assign way points to profile... … … 208 300 } 209 301 302 /** 303 * Adds the given way point to the current buffer. 304 * 305 * @param wp the wp 306 */ 210 307 private void processWayPoint(WayPoint wp) { 211 308 if (wp == null) { … … 215 312 buffer.add(wp); 216 313 } 217 218 219 /* (non-Javadoc)220 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#getProfiles()221 */222 @Override223 public List<IElevationProfile> getProfiles() {224 return profiles;225 }226 227 @Override228 public IElevationProfile getCurrentProfile() {229 if (currentProfileIndex < 0 || currentProfileIndex >= profileCount()) return null;230 231 return profiles.get(currentProfileIndex);232 }233 234 @Override235 public void setCurrentProfile(IElevationProfile newProfile) {236 CheckParameterUtil.ensureParameterNotNull(newProfile);237 238 if (!profiles.contains(newProfile)) {239 profiles.add(newProfile);240 }241 242 setCurrentProfile(profiles.indexOf(newProfile));243 }244 245 @Override246 public void setCurrentProfile(int index) {247 if (index < 0 || index >= profileCount()) throw new RuntimeException("Invalid arg for setCurrentProfile: " + index + ", value must be 0.." + profileCount());248 249 currentProfileIndex = index;250 fireModelChanged();251 }252 253 @Override254 public int profileCount() {255 return profiles != null ? profiles.size() : 0;256 }257 314 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationProfile.java
r29961 r29962 31 31 * 32 32 * The computation is done via implementing {@link IGpxWaypointVisitor}, 33 * subclasses may override the {@link ElevationProfile Base#visit(WayPoint)}33 * subclasses may override the {@link ElevationProfile#visitWayPoint(WayPoint)} 34 34 * method to compute own values or run specific actions. The computation is 35 * triggered by calling {@link ElevationProfile Base#updateValues()}.35 * triggered by calling {@link ElevationProfile#updateValues()}. 36 36 * 37 37 * Elevation profiles can break down into further child profiles. This is … … 44 44 * 45 45 */ 46 public class ElevationProfile Baseimplements IElevationProfile,46 public class ElevationProfile implements IElevationProfile, 47 47 IGpxWaypointVisitor { 48 48 public static final int WAYPOINT_START = 0; … … 74 74 * @param name 75 75 */ 76 public ElevationProfile Base(String name) {76 public ElevationProfile(String name) { 77 77 this(name, null, null, 0); 78 78 } … … 90 90 * The requested target size of the profile. 91 91 */ 92 public ElevationProfile Base(String name, IElevationProfile parent,92 public ElevationProfile(String name, IElevationProfile parent, 93 93 List<WayPoint> wayPoints, int sliceSize) { 94 94 super(); … … 114 114 */ 115 115 public static void setIgnoreZeroHeight(boolean ignoreZeroHeight) { 116 ElevationProfile Base.ignoreZeroHeight = ignoreZeroHeight;116 ElevationProfile.ignoreZeroHeight = ignoreZeroHeight; 117 117 } 118 118 … … 149 149 150 150 for (WayPoint wayPoint : this.wayPoints) { 151 visit (wayPoint);151 visitWayPoint(wayPoint); 152 152 } 153 153 … … 487 487 * way point list. 488 488 */ 489 public void visit (WayPoint wp) {489 public void visitWayPoint(WayPoint wp) { 490 490 if (wp.getTime().after(end)) { 491 491 setEnd(wp); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/GpxIterator.java
r29955 r29962 48 48 if (data.isEmpty()) return; 49 49 50 visitor. start();50 visitor.beginWayPoints(); 51 51 visitSingleWaypoints(data, visitor); 52 visitor.end ();52 visitor.endWayPoints(); 53 53 54 54 // routes … … 98 98 99 99 if (segments != null) { 100 visitor. start(trk);100 visitor.beginTrack(trk); 101 101 // visit all segments 102 102 for (GpxTrackSegment segment : segments) { … … 106 106 continue; 107 107 108 visitor. start(trk, segment);108 visitor.beginTrackSegment(trk, segment); 109 109 110 110 for (WayPoint wayPoint : waypts) { 111 visitor.visit (wayPoint);111 visitor.visitTrackPoint(wayPoint, trk, segment); 112 112 } 113 113 114 visitor.end (trk, segment);114 visitor.endTrackSegment(trk, segment); 115 115 } 116 visitor.end (trk);116 visitor.endTrack(trk); 117 117 } 118 118 … … 127 127 if (visitor == null) return; 128 128 129 visitor. start();129 visitor.beginWayPoints(); 130 130 for (WayPoint wpt : route.routePoints) { 131 visitor.visit (wpt);131 visitor.visitRoutePoint(wpt, route); 132 132 } 133 visitor.end ();133 visitor.endWayPoints(); 134 134 } 135 135 … … 142 142 if (data.waypoints != null) { // better with an hasWaypoints method!? 143 143 for (WayPoint wpt : data.waypoints) { 144 visitor.visit (wpt);144 visitor.visitWayPoint(wpt); 145 145 } 146 146 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/IGpxVisitor.java
r29955 r29962 15 15 package org.openstreetmap.josm.plugins.elevation.gpx; 16 16 17 import org.openstreetmap.josm.data.gpx.GpxRoute; 17 18 import org.openstreetmap.josm.data.gpx.GpxTrack; 18 19 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; … … 25 26 public interface IGpxVisitor extends IGpxWaypointVisitor { 26 27 /** 27 * Starts a GPX route orway point collection.28 * Starts a GPX way point collection. 28 29 */ 29 void start();30 void beginWayPoints(); 30 31 31 32 /** 32 * Ends a GPX route orway point collection.33 * Ends a GPX way point collection. 33 34 */ 34 void end ();35 void endWayPoints(); 35 36 36 37 /** 37 38 * Starts a GPX track. 38 39 */ 39 void start(GpxTrack track);40 void beginTrack(GpxTrack track); 40 41 41 42 /** 42 43 * Ends a GPX track. 43 44 */ 44 void end(GpxTrack track); 45 void endTrack(GpxTrack track); 46 47 /** 48 * Starts a GPX route. 49 */ 50 void beginRoute(GpxRoute track); 51 52 /** 53 * Ends a GPX route. 54 */ 55 void endRoute(GpxRoute track); 45 56 46 57 … … 48 59 * Starts a segment within a GPX track. 49 60 */ 50 void start(GpxTrack track, GpxTrackSegment segment);61 void beginTrackSegment(GpxTrack track, GpxTrackSegment segment); 51 62 52 63 /** 53 64 * Ends a segment within a GPX track. 54 65 */ 55 void end (GpxTrack track, GpxTrackSegment segment);66 void endTrackSegment(GpxTrack track, GpxTrackSegment segment); 56 67 57 68 /** … … 60 71 * @param wp The way point to visit. 61 72 */ 62 void visit(WayPoint wp); 73 void visitWayPoint(WayPoint wp); 74 75 /** 76 * Visits a way point within a GPX track. 77 * 78 * @param wp The way point to visit. 79 * @param track the track containing the way point. 80 * @param segment the track segment 81 */ 82 void visitTrackPoint(WayPoint wp, GpxTrack track, GpxTrackSegment segment); 83 84 /** 85 * Visits a way point within a GPX route. 86 * @param route the route containing the way point. 87 * @param wp the way point to visit. 88 */ 89 void visitRoutePoint(WayPoint wp, GpxRoute route); 63 90 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/IGpxWaypointVisitor.java
r29907 r29962 27 27 * @param wp The way point to visit. 28 28 */ 29 void visit (WayPoint wp);29 void visitWayPoint(WayPoint wp); 30 30 }
Note:
See TracChangeset
for help on using the changeset viewer.