]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoLookupSrtm.java
2672bd55d95cf10a3576d30b6f90870a71fa4a23
[GpsPrune.git] / tim / prune / undo / UndoLookupSrtm.java
1 package tim.prune.undo;
2
3 import tim.prune.I18nManager;
4 import tim.prune.UpdateMessageBroker;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Field;
7 import tim.prune.data.Track;
8 import tim.prune.data.TrackInfo;
9
10 /**
11  * Undo lookup of altitudes from SRTM data
12  */
13 public class UndoLookupSrtm implements UndoOperation
14 {
15         /** DataPoint objects which didn't have altitudes before */
16         private DataPoint[] _points;
17
18
19         /**
20          * Constructor
21          * @param inTrackInfo track info object
22          */
23         public UndoLookupSrtm(TrackInfo inTrackInfo)
24         {
25                 Track track = inTrackInfo.getTrack();
26                 int numPoints = track.getNumPoints();
27                 // Make array of points without altitudes
28                 _points = new DataPoint[numPoints];
29                 for (int i=0; i<numPoints; i++) {
30                         DataPoint point = track.getPoint(i);
31                         if (!point.hasAltitude()) {
32                                 _points[i] = point;
33                         }
34                 }
35         }
36
37
38         /**
39          * @return description of operation
40          */
41         public String getDescription()
42         {
43                 return I18nManager.getText("undo.lookupsrtm");
44         }
45
46
47         /**
48          * Perform the undo operation on the given Track
49          * @param inTrackInfo TrackInfo object on which to perform the operation
50          */
51         public void performUndo(TrackInfo inTrackInfo) throws UndoException
52         {
53                 // Loop through points again, and reset altitudes if they have one
54                 final int numPoints = _points.length;
55                 for (int i=0; i<numPoints; i++) {
56                         DataPoint point = _points[i];
57                         if (point != null && point.hasAltitude()) {
58                                 point.setFieldValue(Field.ALTITUDE, null, true);
59                         }
60                 }
61                 _points = null;
62                 UpdateMessageBroker.informSubscribers();
63         }
64 }