]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoLookupSrtm.java
d82714ae1e6444ce18fda96d1d2cddbc1a0fcff9
[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         /** Altitude strings if present */
18         private String[] _altitudes;
19
20
21         /**
22          * Constructor
23          * @param inTrackInfo track info object
24          */
25         public UndoLookupSrtm(TrackInfo inTrackInfo)
26         {
27                 Track track = inTrackInfo.getTrack();
28                 int numPoints = track.getNumPoints();
29                 // Make arrays of points and altitudes
30                 _points = new DataPoint[numPoints];
31                 _altitudes = new String[numPoints];
32                 for (int i=0; i<numPoints; i++) {
33                         DataPoint point = track.getPoint(i);
34                         if (!point.hasAltitude() || point.getAltitude().getValue() == 0) {
35                                 _points[i] = point;
36                                 if (point.hasAltitude()) {
37                                         _altitudes[i] = point.getFieldValue(Field.ALTITUDE);
38                                 }
39                         }
40                 }
41         }
42
43
44         /**
45          * @return description of operation
46          */
47         public String getDescription()
48         {
49                 return I18nManager.getText("undo.lookupsrtm");
50         }
51
52
53         /**
54          * Perform the undo operation on the given Track
55          * @param inTrackInfo TrackInfo object on which to perform the operation
56          */
57         public void performUndo(TrackInfo inTrackInfo) throws UndoException
58         {
59                 // Loop through points again, and reset altitudes if they have one
60                 final int numPoints = _points.length;
61                 for (int i=0; i<numPoints; i++) {
62                         DataPoint point = _points[i];
63                         if (point != null && point.hasAltitude()) {
64                                 if (_altitudes[i] == null) {
65                                         point.setFieldValue(Field.ALTITUDE, null, true);
66                                 }
67                                 else {
68                                         point.setFieldValue(Field.ALTITUDE, _altitudes[i], true);
69                                 }
70                         }
71                 }
72                 _points = null;
73                 UpdateMessageBroker.informSubscribers();
74         }
75 }