1 package tim.prune.undo;
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;
11 * Undo lookup of altitudes from SRTM data
13 public class UndoLookupSrtm implements UndoOperation
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) */
26 * @param inTrackInfo track info object
28 public UndoLookupSrtm(TrackInfo inTrackInfo, boolean overwriteAlt)
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++)
37 DataPoint point = track.getPoint(i);
38 if (overwriteAlt || !point.hasAltitude() || point.getAltitude().getValue() == 0)
41 if (point.hasAltitude()) {
42 _altitudes[i] = point.getFieldValue(Field.ALTITUDE);
50 * @return description of operation
52 public String getDescription()
54 return I18nManager.getText("undo.lookupsrtm");
59 * Perform the undo operation on the given Track
60 * @param inTrackInfo TrackInfo object on which to perform the operation
62 public void performUndo(TrackInfo inTrackInfo) throws UndoException
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);
73 point.setFieldValue(Field.ALTITUDE, _altitudes[i], true);
78 UpdateMessageBroker.informSubscribers();