Ignore:
Timestamp:
2013-09-23T23:07:52+02:00 (11 years ago)
Author:
oliverw
Message:

[JOSM_ElevationProfile]: Redesign due to perf problems (see #josm8080)

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  
    2121import org.openstreetmap.josm.actions.mapmode.MapMode;
    2222import org.openstreetmap.josm.gui.MapFrame;
     23import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    2324
    2425/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IElevationModelListener.java

    r29907 r29948  
    1616
    1717import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
     18import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    1819
    1920/**
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java

    r29907 r29948  
    2424import org.openstreetmap.josm.data.gpx.WayPoint;
    2525import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
    26 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    27 import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
     26import org.openstreetmap.josm.tools.CheckParameterUtil;
    2827
    2928/**
    3029 * 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.
    3631 *
    37  * @see ElevationProfileNode
    38  * @see ElevationProfileLeaf
    3932 * @see IElevationModelTrackListener
    40  * @see IElevationModelSliceListener
    4133 * @author Oliver Wieland <oliver.wieland@online.de>
    4234 */
    43 public class ElevationModel extends ElevationProfileBase implements IGpxVisitor {
     35public class ElevationModel implements IGpxVisitor, IElevationModel {
    4436        // private int sliceSize;
    4537        private int trackCounter;
    4638        private GpxData gpxData;
    4739
    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();
    5241        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         */
    5449        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) {
    6060                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);         
    7263        }
    7364
     
    8475         * @return the tracks
    8576         */
    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;
    9979        }
    10080
     
    10282         * Fires the 'model changed' event to all listeners.
    10383         */
    104         protected void fireModelChanged() {
     84        protected void fireModelChanged() {             
    10585                for (IElevationModelListener listener : listeners) {
    106                         listener.elevationProfileChanged(this);
     86                    if (children != null && children.size() > 0)
     87                        listener.elevationProfileChanged(getCurrentProfile());
    10788                }
    10889        }
    10990
    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
    11695        public void addModelListener(IElevationModelListener listener) {
    11796                this.listeners.add(listener);
    11897        }
    11998
    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
    126103        public void removeModelListener(IElevationModelListener listener) {
    127104                this.listeners.remove(listener);
    128105        }
    129106
    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
    133111        public void removeAllListeners() {
    134112                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 do
    143 
    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 GPX
    156                 GpxIterator.visit(gpxData, this);
    157 
    158                 // reduce data
    159                 setWayPoints(ElevationHelper.downsampleWayPoints(tmpWaypoints,
    160                                 getSliceSize()), false);
    161         }
    162 
    163         /**
    164          * Forces the model to refresh itself. Clients (e. g. UI widgets) may use
    165          * this method to notify the model on UI changes.
    166          */
    167         public void updateElevationData() {
    168                 computeProfile();
    169113        }
    170114
     
    189133         */
    190134        public void visit(GpxTrack track, GpxTrackSegment segment, WayPoint wp) {
     135                // we ignore the segment here
    191136                processWayPoint(wp);
    192137        }
     
    197142        @Override
    198143        public void visit(WayPoint wp) {
    199                 super.visit(wp);
    200144                processWayPoint(wp);
    201145        }
    202146
    203147        public void start() {
    204                 buffer.clear();
     148                children.clear();               
    205149        }
    206150
     
    211155       
    212156        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                }
    220167        }
    221168
     
    226173               
    227174                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;
    241215        }
    242216}
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationProfileBase.java

    r29907 r29948  
    2020
    2121import org.openstreetmap.josm.data.gpx.WayPoint;
    22 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    2322import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    2423
     
    4342 *
    4443 */
    45 public abstract class ElevationProfileBase implements IElevationProfile,
     44public class ElevationProfileBase implements IElevationProfile,
    4645                IGpxWaypointVisitor {
    4746        public static final int WAYPOINT_START = 0;
     
    6261        private List<WayPoint> wayPoints;
    6362        private int numWayPoints; // cached value
    64         private int sliceSize;
    6563        private int gain;
    6664        private int lastEle;
     
    9391                this.name = name;
    9492                this.parent = parent;
    95                 this.sliceSize = sliceSize;
    96                 setWayPoints(wayPoints, true);
     93                setWayPoints(wayPoints);
    9794        }
    9895
     
    225222         * @param wayPoints
    226223         */
    227         public void setWayPoints(List<WayPoint> wayPoints, boolean revisit) {
     224        public void setWayPoints(List<WayPoint> wayPoints) {
    228225                if (this.wayPoints != wayPoints) {
    229226                        this.wayPoints = new ArrayList<WayPoint>(wayPoints);
    230227                        numWayPoints = wayPoints != null ? wayPoints.size() : 0;
    231                         if (revisit) {                         
    232                                 updateValues();
    233                         }
     228                        updateValues();
     229                       
    234230                }
    235231        }
     
    263259        }
    264260
    265         /**
    266          * Gets the slice size for the detail view.
    267          *
    268          * @return
    269          */
    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 
    283261        /*
    284262         * (non-Javadoc)
     
    298276         * org.openstreetmap.josm.plugins.elevation.IElevationProfile#getChildren()
    299277         */
    300         public abstract List<IElevationProfile> getChildren();
     278        public List<IElevationProfile> getChildren() {
     279            return null;
     280        }
    301281
    302282        /*
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java

    r29907 r29948  
    3232import org.openstreetmap.josm.data.gpx.WayPoint;
    3333import org.openstreetmap.josm.gui.MapView;
    34 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    3534import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    3635import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
     36import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    3737import org.openstreetmap.josm.tools.CheckParameterUtil;
    3838
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java

    r29907 r29948  
    1515package org.openstreetmap.josm.plugins.elevation.gui;
    1616
     17import static org.openstreetmap.josm.tools.I18n.tr;
     18
    1719import java.awt.BorderLayout;
    1820import java.awt.Font;
    1921import java.awt.GridLayout;
    20 import java.awt.event.ActionEvent;
    21 import java.awt.event.ActionListener;
    2222import java.awt.event.ComponentEvent;
    2323import java.awt.event.ComponentListener;
     
    2626import java.util.List;
    2727
    28 import javax.swing.ButtonGroup;
    2928import javax.swing.JLabel;
    3029import javax.swing.JPanel;
     
    3433import org.openstreetmap.josm.Main;
    3534import org.openstreetmap.josm.data.gpx.GpxData;
     35import org.openstreetmap.josm.gui.MapView;
    3636import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    37 import org.openstreetmap.josm.gui.MapView;
    3837import org.openstreetmap.josm.gui.NavigatableComponent;
    3938import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    4039import org.openstreetmap.josm.gui.layer.GpxLayer;
    4140import org.openstreetmap.josm.gui.layer.Layer;
     41import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    4242import org.openstreetmap.josm.plugins.elevation.IElevationModelListener;
    43 import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    4443import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel;
    4544import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind;
     45import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel;
     46import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    4647import org.openstreetmap.josm.tools.Shortcut;
    47 
    48 import static org.openstreetmap.josm.tools.I18n.tr;
    4948/**
    5049 * @author Oliver Wieland <oliver.wieland@online.de>
     
    6059        private static final long serialVersionUID = -868463893732535577L;
    6160        /* Elevation profile instance */
    62         private ElevationModel profile;
     61        private IElevationModel model;
    6362        /* GPX data */
    6463        private GpxLayer activeLayer = null;
     
    7372        private JLabel totalTimeLabel;
    7473        private JLabel distLabel;
    75         private JRadioButton geoidNone;
    76         private JRadioButton geoidAuto;
    77         private JRadioButton geoidFixed;
    78         private JTextField geoidFixedValue;
    7974        /* Listener to the elevation model */
    8075        private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>();
     
    160155                dataPanel.add(totalTimeLabel);
    161156
    162                 // Geoid
    163                 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 preferences
    169                 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 preferences
    201                 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 
    215157                add(dataPanel, BorderLayout.PAGE_END);
    216                 profile = new ElevationModel();
     158                model = new ElevationModel();
    217159
    218160                profPanel = new ElevationProfilePanel(null);
    219161                add(profPanel, BorderLayout.CENTER);
    220162                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                 }
    228163               
    229164                dock();
     
    250185         * @return
    251186         */
    252         public ElevationModel getModel() {
    253                 return profile;
     187        public IElevationModel getModel() {
     188                return model;
    254189        }
    255190
     
    258193         * @param model The new model.
    259194         */
    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;
    263198                        profPanel.setElevationModel(model);
    264                        
    265199                        updateView();
    266200                }
     
    294228         */
    295229        private void updateView() {
     230                if (model == null) return;
     231
     232                IElevationProfile profile = model.getCurrentProfile();
     233
    296234                if (profile != null) {
    297                         // Show name of profile in title
    298                         setTitle(String.format("%s: %s", tr("Elevation Profile"), profile.getName()));
    299 
    300                         if (profile.hasElevationData()) {
    301                                 // Show elevation data
    302                                 minHeightLabel.setText(
    303                                                 ElevationHelper.getElevationText(profile.getMinHeight()));
    304                                 maxHeightLabel.setText(
    305                                                 ElevationHelper.getElevationText(profile.getMaxHeight()));
    306                                 avrgHeightLabel.setText(
    307                                                 ElevationHelper.getElevationText(profile.getAverageHeight()));
    308                                 elevationGainLabel.setText(
    309                                                 ElevationHelper.getElevationText(profile.getGain()));
    310                         }
    311                        
    312                         // compute values for time and distance
    313                         long diff = profile.getTimeDifference();
    314                         long minutes = diff / (1000 * 60);
    315                         long hours = minutes / 60;
    316                         minutes = minutes % 60;
    317                        
    318                         double dist = profile.getDistance();
    319 
    320                         totalTimeLabel.setText(String.format("%d:%d h", hours, minutes));
    321                         distLabel.setText(NavigatableComponent.getSystemOfMeasurement().getDistText(dist));
     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));
    322260                } else { // no elevation data, -> switch back to empty view
    323                         setTitle(String.format("%s: (No data)", tr("Elevation Profile")));
    324                        
    325                         minHeightLabel.setText(EMPTY_DATA_STRING);
    326                         maxHeightLabel.setText(EMPTY_DATA_STRING);
    327                         avrgHeightLabel.setText(EMPTY_DATA_STRING);
    328                         elevationGainLabel.setText(EMPTY_DATA_STRING);
    329                         totalTimeLabel.setText(EMPTY_DATA_STRING);
    330                         distLabel.setText(EMPTY_DATA_STRING);
    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
    333271                fireModelChanged();
    334                 repaint();
     272                repaint();         
    335273        }
    336274
     
    340278        protected void fireModelChanged() {
    341279                for (IElevationModelListener listener : listeners) {
    342                         listener.elevationProfileChanged(getModel());
     280                        listener.elevationProfileChanged(getModel().getCurrentProfile());
    343281                }
    344282        }
     
    383321                if (activeLayer != newLayer) {
    384322                        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
    390325                        if (!layerMap.containsKey(newLayer)) {
    391326                                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);
    395330                        }
    396331                       
    397332                        ElevationModel em = layerMap.get(newLayer);
    398                         em.setSliceSize(slices);
    399333                        setModel(em);                   
    400334                }
     
    418352                        layerMap.remove(oldLayer);
    419353                }
     354               
    420355                if (layerMap.size() == 0) {
    421356                        setModel(null);
     
    433368         */
    434369        public void componentHidden(ComponentEvent e) {
    435                 // TODO Auto-generated method stub
    436 
    437370        }
    438371
     
    445378         */
    446379        public void componentMoved(ComponentEvent e) {
    447                 // TODO Auto-generated method stub
    448 
    449380        }
    450381
     
    456387         */
    457388        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                 }
    466389        }
    467390
     
    474397         */
    475398        public void componentShown(ComponentEvent e) {
    476 
    477399        }
    478400}
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java

    r29907 r29948  
    2929import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    3030import org.openstreetmap.josm.gui.layer.Layer;
    31 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    3231import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    3332import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
     33import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    3434import org.openstreetmap.josm.tools.ImageProvider;
    3535
     
    7474     */
    7575    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        }
    7880    }
    7981
     
    156158    public void paint(Graphics2D g, MapView mv, Bounds box) {
    157159        WayPoint lastWpt = null;
    158         int lastEle = 0;
    159160
    160161        renderer.beginRendering();
     
    173174
    174175                // remember some things for next iteration
    175                 lastEle = (int) ElevationHelper.getElevation(wpt);
    176176                lastWpt = wpt;
    177177            }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java

    r29907 r29948  
    3737
    3838import org.openstreetmap.josm.data.gpx.WayPoint;
    39 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    4039import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
    4140import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
     41import org.openstreetmap.josm.plugins.elevation.gpx.IElevationModel;
     42import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    4243
    4344/**
     
    5152         */
    5253        private static final long serialVersionUID = -7343429725259575319L;
    53         private IElevationProfile profile;
     54        private IElevationModel model;
    5455        private Rectangle plotArea;
    5556        private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer();
     
    6263         * @param profile The elevation profile to show in the panel.
    6364         */
    64         public ElevationProfilePanel(IElevationProfile profile) {
     65        public ElevationProfilePanel(IElevationModel profile) {
    6566                super();
    66                 this.profile = profile;
     67                this.model = profile;
    6768                setDoubleBuffered(true);
    6869                setBackground(Color.WHITE);
     
    7677         * @return
    7778         */
    78         public IElevationProfile getProfile() {
    79                 return profile;
     79        public IElevationModel getProfile() {
     80                return model;
    8081        }
    8182
    8283        /**
    8384         * Sets the new elevation profile instance.
    84          * @param profile
    85          */
    86         public void setElevationModel(IElevationProfile 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;
    8990                        invalidate();
    9091                }
     
    121122        public void setSelectedIndex(int selectedIndex) {
    122123                this.selectedIndex = selectedIndex;
     124               
     125                if (model != null) {
     126                    model.setCurrentProfile(selectedIndex);
     127                }
    123128        }
    124129       
     
    128133         */
    129134        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) {
    131140                        return profile.getWayPoints().get(this.selectedIndex);
    132141                } else {
     
    190199       
    191200                       
    192                
    193                         if (profile != null && profile.hasElevationData()) {
     201                        if (model != null) {
     202                            IElevationProfile profile = model.getCurrentProfile();
     203                            if (profile != null && profile.hasElevationData()) {
    194204                                drawAlignedString(formatDate(profile.getStart()), 5, y1 + 5,
    195                                                 TextAlignment.Left, g);
     205                                        TextAlignment.Left, g);
    196206                                drawAlignedString(formatDate(profile.getEnd()),
    197                                                 getPlotRight(), y1 + 5, TextAlignment.Right, g);
    198                                
    199                                
     207                                        getPlotRight(), y1 + 5, TextAlignment.Right, g);
     208
     209
    200210                                drawProfile(g);
    201211                                drawElevationLines(g);
    202                         } else {
     212                            } else {
     213                                // No profile or profile supports no elevation data
    203214                                drawAlignedString(tr("(No elevation data)"), getPlotHCenter(),
    204                                                 getPlotVCenter(), TextAlignment.Centered, g);
     215                                        getPlotVCenter(), TextAlignment.Centered, g);
     216                            }
    205217                        }
    206218                } finally {
     
    268280         */
    269281        private void drawElevationLines(Graphics g) {
     282                IElevationProfile profile = model.getCurrentProfile();
     283           
    270284                double diff = profile.getHeightDifference();
    271285
     
    373387        private int getYForEelevation(int elevation) {
    374388                int y1 = getPlotBottom();
     389               
     390                IElevationProfile profile = model.getCurrentProfile();
    375391
    376392                if (!profile.hasElevationData()) {
     
    380396                double diff = profile.getHeightDifference();
    381397
    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));
    385399        }
    386400
     
    391405         */
    392406        private void drawProfile(Graphics g) {
     407                IElevationProfile profile = model.getCurrentProfile();
     408               
    393409                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;
    394414
    395415                // int y0 = plotArea.y + 1;
     
    397417                Color oldC = g.getColor();
    398418
    399                 for (int i = 0; i < n; i++) {
     419                for (int i = 0; i < n; i += step) {
    400420                        WayPoint wpt = profile.getWayPoints().get(i);
    401421                        int eleVal = (int) ElevationHelper.getElevation(wpt);
     
    418438                        g.setColor(c);
    419439                        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 impl
    425                         }
    426                        
    427440                        g.setColor(ElevationColors.EPLightBlue);
    428                        
    429                         int yGeoid = getYForEelevation(eleVal - geoidVal);
    430                         g.drawLine(x, Math.min(yGeoid, yBottom), x, yEle);
    431441                }
    432442                g.setColor(oldC);
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/IElevationProfileRenderer.java

    r29907 r29948  
    2020import org.openstreetmap.josm.data.gpx.WayPoint;
    2121import org.openstreetmap.josm.gui.MapView;
    22 import org.openstreetmap.josm.plugins.elevation.IElevationProfile;
    2322import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind;
     23import org.openstreetmap.josm.plugins.elevation.gpx.IElevationProfile;
    2424
    2525/**
Note: See TracChangeset for help on using the changeset viewer.