Changeset 29948 in osm for applications/editors
- Timestamp:
- 2013-09-23T23:07:52+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 3 added
- 3 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationMapMode.java
r23795 r29948 21 21 import org.openstreetmap.josm.actions.mapmode.MapMode; 22 22 import org.openstreetmap.josm.gui.MapFrame; 23 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 23 24 24 25 /** -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModelListener.java
r29907 r29948 16 16 17 17 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel; 18 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 18 19 19 20 /** -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java
r29907 r29948 24 24 import org.openstreetmap.josm.data.gpx.WayPoint; 25 25 import org.openstreetmap.josm.plugins.elevation.IElevationModelListener; 26 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 27 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 26 import org.openstreetmap.josm.tools.CheckParameterUtil; 28 27 29 28 /** 30 29 * Represents the top-level part of the elevation model. The elevation model 31 * breaks done into the tracks/routes of a GPX file (see 32 * {@link ElevationProfileNode}). Each track is divided into 'slices' (see 33 * {@link ElevationProfileLeaf}) - a set of fixed number of way points. This 34 * structure allows as well an overview over a single track as a detailed 35 * elevation view of a track part. 30 * breaks done into the tracks/routes of a GPX file. 36 31 * 37 * @see ElevationProfileNode38 * @see ElevationProfileLeaf39 32 * @see IElevationModelTrackListener 40 * @see IElevationModelSliceListener41 33 * @author Oliver Wieland <oliver.wieland@online.de> 42 34 */ 43 public class ElevationModel extends ElevationProfileBase implements IGpxVisitor{35 public class ElevationModel implements IGpxVisitor, IElevationModel { 44 36 // private int sliceSize; 45 37 private int trackCounter; 46 38 private GpxData gpxData; 47 39 48 private List<IElevationProfile> tracks; 49 private List<WayPoint> buffer = new ArrayList<WayPoint>(1000); 50 private List<WayPoint> tmpWaypoints = new ArrayList<WayPoint>(1000); 51 40 private WayPointMap children = new WayPointMap(); 52 41 private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); 53 42 private List<WayPoint> buffer = new ArrayList<WayPoint>(); 43 private int currentProfileIndex = 0; 44 45 46 /** 47 * Instantiates a new elevation model. 48 */ 54 49 public ElevationModel() { 55 this("", null, 100); 56 } 57 58 public ElevationModel(String name, GpxData data, int sliceSize) { 59 super(name); 50 this("", null); 51 } 52 53 /** 54 * Instantiates a new elevation model. 55 * 56 * @param name the name of the model 57 * @param data the GPX data 58 */ 59 public ElevationModel(String name, GpxData data) { 60 60 gpxData = data; 61 setSliceSize(Math.max(sliceSize, 100)); 62 } 63 64 @Override 65 public void setSliceSize(int sliceSize) { 66 67 super.setSliceSize(sliceSize); 68 69 // FIXME: Listener should go in base class 70 updateElevationData(); 71 fireModelChanged(); 61 62 GpxIterator.visit(data, this); 72 63 } 73 64 … … 84 75 * @return the tracks 85 76 */ 86 protected List<IElevationProfile> getTracks() { 87 return tracks; 88 } 89 90 /** 91 * Gets a flag indicating whether the associated way points contained 92 * elevation data or not. This is the case if min and max height or both 93 * zero. 94 * 95 * @return 96 */ 97 public boolean hasElevationData() { 98 return getMaxHeight() != getMinHeight(); 77 protected WayPointMap getTracks() { 78 return children; 99 79 } 100 80 … … 102 82 * Fires the 'model changed' event to all listeners. 103 83 */ 104 protected void fireModelChanged() { 84 protected void fireModelChanged() { 105 85 for (IElevationModelListener listener : listeners) { 106 listener.elevationProfileChanged(this); 86 if (children != null && children.size() > 0) 87 listener.elevationProfileChanged(getCurrentProfile()); 107 88 } 108 89 } 109 90 110 /** 111 * Adds a model listener to this instance. 112 * 113 * @param listener 114 * The listener to add. 115 */ 91 /* (non-Javadoc) 92 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#addModelListener(org.openstreetmap.josm.plugins.elevation.IElevationModelListener) 93 */ 94 @Override 116 95 public void addModelListener(IElevationModelListener listener) { 117 96 this.listeners.add(listener); 118 97 } 119 98 120 /** 121 * Removes a model listener from this instance. 122 * 123 * @param listener 124 * The listener to remove. 125 */ 99 /* (non-Javadoc) 100 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#removeModelListener(org.openstreetmap.josm.plugins.elevation.IElevationModelListener) 101 */ 102 @Override 126 103 public void removeModelListener(IElevationModelListener listener) { 127 104 this.listeners.remove(listener); 128 105 } 129 106 130 /** 131 * Removes all listeners from this instance. 132 */ 107 /* (non-Javadoc) 108 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#removeAllListeners() 109 */ 110 @Override 133 111 public void removeAllListeners() { 134 112 this.listeners.clear(); 135 }136 137 /**138 * (Re)computes the elevation model.139 */140 private void computeProfile() {141 if (gpxData == null)142 return; // nothing to do143 144 trackCounter = 0;145 146 super.updateValues();147 if (tracks == null) {148 tracks = new ArrayList<IElevationProfile>();149 } else {150 tmpWaypoints.clear();151 buffer.clear();152 tracks.clear();153 }154 155 setDistance(gpxData.length()); // get distance from GPX156 GpxIterator.visit(gpxData, this);157 158 // reduce data159 setWayPoints(ElevationHelper.downsampleWayPoints(tmpWaypoints,160 getSliceSize()), false);161 }162 163 /**164 * Forces the model to refresh itself. Clients (e. g. UI widgets) may use165 * this method to notify the model on UI changes.166 */167 public void updateElevationData() {168 computeProfile();169 113 } 170 114 … … 189 133 */ 190 134 public void visit(GpxTrack track, GpxTrackSegment segment, WayPoint wp) { 135 // we ignore the segment here 191 136 processWayPoint(wp); 192 137 } … … 197 142 @Override 198 143 public void visit(WayPoint wp) { 199 super.visit(wp);200 144 processWayPoint(wp); 201 145 } 202 146 203 147 public void start() { 204 buffer.clear();148 children.clear(); 205 149 } 206 150 … … 211 155 212 156 private void addTrackOrRoute(String trackName) { 213 if (getSliceSize() > 0) { 214 ElevationProfileNode emt = new ElevationProfileNode(trackName, 215 this, buffer, getSliceSize()); 216 tracks.add(emt); 217 } 218 trackCounter++; 219 buffer.clear(); 157 if (buffer.size() > 0) { 158 159 System.out.println("Add track " + trackName + ", n = " + buffer.size()); // TODO: Remove 160 161 ElevationProfileBase ep = new ElevationProfileBase(trackName); 162 ep.setWayPoints(buffer); 163 ep.setName(trackName); 164 children.add(ep); 165 buffer.clear(); 166 } 220 167 } 221 168 … … 226 173 227 174 buffer.add(wp); 228 tmpWaypoints.add(wp); 229 } 230 231 /* 232 * (non-Javadoc) 233 * 234 * @see 235 * org.openstreetmap.josm.plugins.elevation.ElevationProfileBase#getChildren 236 * () 237 */ 238 @Override 239 public List<IElevationProfile> getChildren() { 240 return tracks; 175 } 176 177 178 /* (non-Javadoc) 179 * @see org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel#getProfiles() 180 */ 181 @Override 182 public List<IElevationProfile> getProfiles() { 183 return children; 184 } 185 186 @Override 187 public IElevationProfile getCurrentProfile() { 188 if (currentProfileIndex < 0 || currentProfileIndex >= profileCount()) return null; 189 190 return children.get(currentProfileIndex); 191 } 192 193 @Override 194 public void setCurrentProfile(IElevationProfile newProfile) { 195 CheckParameterUtil.ensureParameterNotNull(newProfile); 196 197 if (!children.contains(newProfile)) { 198 children.add(newProfile); 199 } 200 201 setCurrentProfile(children.indexOf(newProfile)); 202 } 203 204 @Override 205 public void setCurrentProfile(int index) { 206 if (index < 0 || index >= profileCount()) throw new RuntimeException("Invalid arg for setCurrentProfile: " + index + ", value must be 0.." + profileCount()); 207 208 currentProfileIndex = index; 209 fireModelChanged(); 210 } 211 212 @Override 213 public int profileCount() { 214 return children != null ? children.size() : 0; 241 215 } 242 216 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationProfileBase.java
r29907 r29948 20 20 21 21 import org.openstreetmap.josm.data.gpx.WayPoint; 22 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;23 22 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 24 23 … … 43 42 * 44 43 */ 45 public abstractclass ElevationProfileBase implements IElevationProfile,44 public class ElevationProfileBase implements IElevationProfile, 46 45 IGpxWaypointVisitor { 47 46 public static final int WAYPOINT_START = 0; … … 62 61 private List<WayPoint> wayPoints; 63 62 private int numWayPoints; // cached value 64 private int sliceSize;65 63 private int gain; 66 64 private int lastEle; … … 93 91 this.name = name; 94 92 this.parent = parent; 95 this.sliceSize = sliceSize; 96 setWayPoints(wayPoints, true); 93 setWayPoints(wayPoints); 97 94 } 98 95 … … 225 222 * @param wayPoints 226 223 */ 227 public void setWayPoints(List<WayPoint> wayPoints , boolean revisit) {224 public void setWayPoints(List<WayPoint> wayPoints) { 228 225 if (this.wayPoints != wayPoints) { 229 226 this.wayPoints = new ArrayList<WayPoint>(wayPoints); 230 227 numWayPoints = wayPoints != null ? wayPoints.size() : 0; 231 if (revisit) { 232 updateValues(); 233 } 228 updateValues(); 229 234 230 } 235 231 } … … 263 259 } 264 260 265 /**266 * Gets the slice size for the detail view.267 *268 * @return269 */270 public int getSliceSize() {271 return sliceSize;272 }273 274 /**275 * Sets the desired size of the elevation profile.276 */277 public void setSliceSize(int sliceSize) {278 if (this.sliceSize != sliceSize) {279 this.sliceSize = sliceSize;280 }281 }282 283 261 /* 284 262 * (non-Javadoc) … … 298 276 * org.openstreetmap.josm.plugins.elevation.IElevationProfile#getChildren() 299 277 */ 300 public abstract List<IElevationProfile> getChildren(); 278 public List<IElevationProfile> getChildren() { 279 return null; 280 } 301 281 302 282 /* -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r29907 r29948 32 32 import org.openstreetmap.josm.data.gpx.WayPoint; 33 33 import org.openstreetmap.josm.gui.MapView; 34 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;35 34 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 36 35 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 36 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 37 37 import org.openstreetmap.josm.tools.CheckParameterUtil; 38 38 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r29907 r29948 15 15 package org.openstreetmap.josm.plugins.elevation.gui; 16 16 17 import static org.openstreetmap.josm.tools.I18n.tr; 18 17 19 import java.awt.BorderLayout; 18 20 import java.awt.Font; 19 21 import java.awt.GridLayout; 20 import java.awt.event.ActionEvent;21 import java.awt.event.ActionListener;22 22 import java.awt.event.ComponentEvent; 23 23 import java.awt.event.ComponentListener; … … 26 26 import java.util.List; 27 27 28 import javax.swing.ButtonGroup;29 28 import javax.swing.JLabel; 30 29 import javax.swing.JPanel; … … 34 33 import org.openstreetmap.josm.Main; 35 34 import org.openstreetmap.josm.data.gpx.GpxData; 35 import org.openstreetmap.josm.gui.MapView; 36 36 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 37 import org.openstreetmap.josm.gui.MapView;38 37 import org.openstreetmap.josm.gui.NavigatableComponent; 39 38 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 40 39 import org.openstreetmap.josm.gui.layer.GpxLayer; 41 40 import org.openstreetmap.josm.gui.layer.Layer; 41 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 42 42 import org.openstreetmap.josm.plugins.elevation.IElevationModelListener; 43 import org.openstreetmap.josm.plugins.elevation.ElevationHelper;44 43 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel; 45 44 import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind; 45 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel; 46 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 46 47 import org.openstreetmap.josm.tools.Shortcut; 47 48 import static org.openstreetmap.josm.tools.I18n.tr;49 48 /** 50 49 * @author Oliver Wieland <oliver.wieland@online.de> … … 60 59 private static final long serialVersionUID = -868463893732535577L; 61 60 /* Elevation profile instance */ 62 private ElevationModel profile;61 private IElevationModel model; 63 62 /* GPX data */ 64 63 private GpxLayer activeLayer = null; … … 73 72 private JLabel totalTimeLabel; 74 73 private JLabel distLabel; 75 private JRadioButton geoidNone;76 private JRadioButton geoidAuto;77 private JRadioButton geoidFixed;78 private JTextField geoidFixedValue;79 74 /* Listener to the elevation model */ 80 75 private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); … … 160 155 dataPanel.add(totalTimeLabel); 161 156 162 // Geoid163 JLabel geoidHead = new JLabel(tr("Geoid"));164 geoidHead.setFont(getFont().deriveFont(Font.BOLD));165 dataPanel.add(geoidHead);166 167 geoidNone = new JRadioButton(tr("None"));168 // TODO: Obtain value from preferences169 geoidNone.setSelected(true);170 geoidNone.addActionListener(new ActionListener() {171 public void actionPerformed(ActionEvent arg0) {172 ElevationHelper.setGeoidKind(GeoidCorrectionKind.None);173 geoidFixedValue.setEnabled(false);174 getModel().updateElevationData();175 updateView();176 }177 });178 179 geoidAuto = new JRadioButton(tr("Automatic"));180 geoidAuto.addActionListener(new ActionListener() {181 public void actionPerformed(ActionEvent arg0) {182 ElevationHelper.setGeoidKind(GeoidCorrectionKind.Auto);183 geoidFixedValue.setEnabled(false);184 getModel().updateElevationData();185 updateView();186 }187 });188 189 geoidFixed = new JRadioButton(tr("Fixed value"));190 geoidFixed.setEnabled(false);191 geoidFixed.addActionListener(new ActionListener() {192 public void actionPerformed(ActionEvent arg0) {193 ElevationHelper.setGeoidKind(GeoidCorrectionKind.Fixed);194 geoidFixedValue.setEnabled(true);195 getModel().updateElevationData();196 updateView();197 }198 });199 200 // TODO: Obtain value from preferences201 geoidFixedValue = new JTextField("0");202 geoidFixedValue.setEnabled(false);203 geoidFixedValue.setAlignmentX(RIGHT_ALIGNMENT);204 ButtonGroup grp = new ButtonGroup();205 grp.add(geoidAuto);206 grp.add(geoidNone);207 grp.add(geoidFixed);208 209 dataPanel.add(geoidNone);210 dataPanel.add(geoidAuto);211 dataPanel.add(geoidFixed);212 dataPanel.add(geoidFixedValue);213 dataPanel.add(new JLabel(" m"));214 215 157 add(dataPanel, BorderLayout.PAGE_END); 216 profile= new ElevationModel();158 model = new ElevationModel(); 217 159 218 160 profPanel = new ElevationProfilePanel(null); 219 161 add(profPanel, BorderLayout.CENTER); 220 162 profPanel.addComponentListener(this); 221 222 if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Auto) {223 geoidAuto.setSelected(true);224 }225 if (ElevationHelper.getGeoidKind() == GeoidCorrectionKind.Fixed) {226 geoidFixed.setSelected(true);227 }228 163 229 164 dock(); … … 250 185 * @return 251 186 */ 252 public ElevationModel getModel() {253 return profile;187 public IElevationModel getModel() { 188 return model; 254 189 } 255 190 … … 258 193 * @param model The new model. 259 194 */ 260 public void setModel( ElevationModel model) {261 if (this. profile!= model) {262 this.profile= model;195 public void setModel(IElevationModel model) { 196 if (this.model != model) { 197 this.model = model; 263 198 profPanel.setElevationModel(model); 264 265 199 updateView(); 266 200 } … … 294 228 */ 295 229 private void updateView() { 230 if (model == null) return; 231 232 IElevationProfile profile = model.getCurrentProfile(); 233 296 234 if (profile != null) { 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 235 // Show name of profile in title 236 setTitle(String.format("%s: %s", tr("Elevation Profile"), profile.getName())); 237 238 if (profile.hasElevationData()) { 239 // Show elevation data 240 minHeightLabel.setText( 241 ElevationHelper.getElevationText(profile.getMinHeight())); 242 maxHeightLabel.setText( 243 ElevationHelper.getElevationText(profile.getMaxHeight())); 244 avrgHeightLabel.setText( 245 ElevationHelper.getElevationText(profile.getAverageHeight())); 246 elevationGainLabel.setText( 247 ElevationHelper.getElevationText(profile.getGain())); 248 } 249 250 // compute values for time and distance 251 long diff = profile.getTimeDifference(); 252 long minutes = diff / (1000 * 60); 253 long hours = minutes / 60; 254 minutes = minutes % 60; 255 256 double dist = profile.getDistance(); 257 258 totalTimeLabel.setText(String.format("%d:%d h", hours, minutes)); 259 distLabel.setText(NavigatableComponent.getSystemOfMeasurement().getDistText(dist)); 322 260 } else { // no elevation data, -> switch back to empty view 323 324 325 326 327 328 329 330 331 } 332 261 setTitle(String.format("%s: (No data)", tr("Elevation Profile"))); 262 263 minHeightLabel.setText(EMPTY_DATA_STRING); 264 maxHeightLabel.setText(EMPTY_DATA_STRING); 265 avrgHeightLabel.setText(EMPTY_DATA_STRING); 266 elevationGainLabel.setText(EMPTY_DATA_STRING); 267 totalTimeLabel.setText(EMPTY_DATA_STRING); 268 distLabel.setText(EMPTY_DATA_STRING); 269 } 270 333 271 fireModelChanged(); 334 repaint(); 272 repaint(); 335 273 } 336 274 … … 340 278 protected void fireModelChanged() { 341 279 for (IElevationModelListener listener : listeners) { 342 listener.elevationProfileChanged(getModel() );280 listener.elevationProfileChanged(getModel().getCurrentProfile()); 343 281 } 344 282 } … … 383 321 if (activeLayer != newLayer) { 384 322 activeLayer = newLayer; 385 int slices = 250; 386 if (profPanel != null && profPanel.getPlotArea().width > 0) { 387 slices = profPanel.getPlotArea().width; 388 } 389 323 324 // layer does not exist -> create 390 325 if (!layerMap.containsKey(newLayer)) { 391 326 GpxData gpxData = newLayer.data; 392 ElevationModel em= new ElevationModel(newLayer.getName(),393 gpxData , slices);394 layerMap.put(newLayer, em);327 ElevationModel newEM = new ElevationModel(newLayer.getName(), 328 gpxData); 329 layerMap.put(newLayer, newEM); 395 330 } 396 331 397 332 ElevationModel em = layerMap.get(newLayer); 398 em.setSliceSize(slices);399 333 setModel(em); 400 334 } … … 418 352 layerMap.remove(oldLayer); 419 353 } 354 420 355 if (layerMap.size() == 0) { 421 356 setModel(null); … … 433 368 */ 434 369 public void componentHidden(ComponentEvent e) { 435 // TODO Auto-generated method stub436 437 370 } 438 371 … … 445 378 */ 446 379 public void componentMoved(ComponentEvent e) { 447 // TODO Auto-generated method stub448 449 380 } 450 381 … … 456 387 */ 457 388 public void componentResized(ComponentEvent e) { 458 int slices = 100;459 if (profPanel != null) {460 slices = profPanel.getPlotArea().width;461 }462 463 if (profile != null && profile.getSliceSize() != slices) {464 profile.setSliceSize(slices);465 }466 389 } 467 390 … … 474 397 */ 475 398 public void componentShown(ComponentEvent e) { 476 477 399 } 478 400 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r29907 r29948 29 29 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 30 30 import org.openstreetmap.josm.gui.layer.Layer; 31 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;32 31 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 33 32 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 33 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 34 34 import org.openstreetmap.josm.tools.ImageProvider; 35 35 … … 74 74 */ 75 75 public void setProfile(IElevationProfile profile) { 76 this.profile = profile; 77 Main.map.repaint(); 76 if (this.profile != profile) { 77 this.profile = profile; 78 Main.map.repaint(); 79 } 78 80 } 79 81 … … 156 158 public void paint(Graphics2D g, MapView mv, Bounds box) { 157 159 WayPoint lastWpt = null; 158 int lastEle = 0;159 160 160 161 renderer.beginRendering(); … … 173 174 174 175 // remember some things for next iteration 175 lastEle = (int) ElevationHelper.getElevation(wpt);176 176 lastWpt = wpt; 177 177 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r29907 r29948 37 37 38 38 import org.openstreetmap.josm.data.gpx.WayPoint; 39 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;40 39 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 41 40 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 41 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel; 42 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 42 43 43 44 /** … … 51 52 */ 52 53 private static final long serialVersionUID = -7343429725259575319L; 53 private IElevation Profile profile;54 private IElevationModel model; 54 55 private Rectangle plotArea; 55 56 private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer(); … … 62 63 * @param profile The elevation profile to show in the panel. 63 64 */ 64 public ElevationProfilePanel(IElevation Profileprofile) {65 public ElevationProfilePanel(IElevationModel profile) { 65 66 super(); 66 this. profile= profile;67 this.model = profile; 67 68 setDoubleBuffered(true); 68 69 setBackground(Color.WHITE); … … 76 77 * @return 77 78 */ 78 public IElevation ProfilegetProfile() {79 return profile;79 public IElevationModel getProfile() { 80 return model; 80 81 } 81 82 82 83 /** 83 84 * Sets the new elevation profile instance. 84 * @param profile85 */ 86 public void setElevationModel(IElevation Profile profile) {87 if (this. profile != profile) {88 this. profile = profile;85 * @param model 86 */ 87 public void setElevationModel(IElevationModel model) { 88 if (this.model != model) { 89 this.model = model; 89 90 invalidate(); 90 91 } … … 121 122 public void setSelectedIndex(int selectedIndex) { 122 123 this.selectedIndex = selectedIndex; 124 125 if (model != null) { 126 model.setCurrentProfile(selectedIndex); 127 } 123 128 } 124 129 … … 128 133 */ 129 134 public WayPoint getSelectedWayPoint() { 130 if (this.selectedIndex != -1 && profile != null && profile.getWayPoints() != null && profile.getWayPoints().size() > this.selectedIndex) { 135 if (model == null) return null; 136 137 IElevationProfile profile = model.getCurrentProfile(); 138 139 if (profile != null && profile.getWayPoints() != null && profile.getWayPoints().size() > this.selectedIndex) { 131 140 return profile.getWayPoints().get(this.selectedIndex); 132 141 } else { … … 190 199 191 200 192 193 if (profile != null && profile.hasElevationData()) { 201 if (model != null) { 202 IElevationProfile profile = model.getCurrentProfile(); 203 if (profile != null && profile.hasElevationData()) { 194 204 drawAlignedString(formatDate(profile.getStart()), 5, y1 + 5, 195 205 TextAlignment.Left, g); 196 206 drawAlignedString(formatDate(profile.getEnd()), 197 198 199 207 getPlotRight(), y1 + 5, TextAlignment.Right, g); 208 209 200 210 drawProfile(g); 201 211 drawElevationLines(g); 202 } else { 212 } else { 213 // No profile or profile supports no elevation data 203 214 drawAlignedString(tr("(No elevation data)"), getPlotHCenter(), 204 getPlotVCenter(), TextAlignment.Centered, g); 215 getPlotVCenter(), TextAlignment.Centered, g); 216 } 205 217 } 206 218 } finally { … … 268 280 */ 269 281 private void drawElevationLines(Graphics g) { 282 IElevationProfile profile = model.getCurrentProfile(); 283 270 284 double diff = profile.getHeightDifference(); 271 285 … … 373 387 private int getYForEelevation(int elevation) { 374 388 int y1 = getPlotBottom(); 389 390 IElevationProfile profile = model.getCurrentProfile(); 375 391 376 392 if (!profile.hasElevationData()) { … … 380 396 double diff = profile.getHeightDifference(); 381 397 382 return y1 383 - (int) Math 384 .round(((elevation - profile.getMinHeight()) / diff * plotArea.height)); 398 return y1 - (int) Math.round(((elevation - profile.getMinHeight()) / diff * plotArea.height)); 385 399 } 386 400 … … 391 405 */ 392 406 private void drawProfile(Graphics g) { 407 IElevationProfile profile = model.getCurrentProfile(); 408 393 409 int n = Math.min(plotArea.width, profile.getNumberOfWayPoints()); 410 411 if (n == 0) return; // nothing to draw 412 // step size 413 int step = profile.getNumberOfWayPoints() / n; 394 414 395 415 // int y0 = plotArea.y + 1; … … 397 417 Color oldC = g.getColor(); 398 418 399 for (int i = 0; i < n; i ++) {419 for (int i = 0; i < n; i += step) { 400 420 WayPoint wpt = profile.getWayPoints().get(i); 401 421 int eleVal = (int) ElevationHelper.getElevation(wpt); … … 418 438 g.setColor(c); 419 439 g.drawLine(x, yBottom, x, yEle); 420 421 int geoidVal = 0;422 switch(ElevationHelper.getGeoidKind()) {423 case Auto: geoidVal = ElevationHelper.getGeoidCorrection(wpt); break;424 case Fixed: // not impl425 }426 427 440 g.setColor(ElevationColors.EPLightBlue); 428 429 int yGeoid = getYForEelevation(eleVal - geoidVal);430 g.drawLine(x, Math.min(yGeoid, yBottom), x, yEle);431 441 } 432 442 g.setColor(oldC); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/IElevationProfileRenderer.java
r29907 r29948 20 20 import org.openstreetmap.josm.data.gpx.WayPoint; 21 21 import org.openstreetmap.josm.gui.MapView; 22 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;23 22 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; 23 import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile; 24 24 25 25 /**
Note:
See TracChangeset
for help on using the changeset viewer.