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