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