File: UndoLookupSrtm.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (77 lines) | stat: -rw-r--r-- 1,895 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package tim.prune.undo;

import tim.prune.I18nManager;
import tim.prune.UpdateMessageBroker;
import tim.prune.data.DataPoint;
import tim.prune.data.Field;
import tim.prune.data.Track;
import tim.prune.data.TrackInfo;

/**
 * Undo lookup of altitudes from SRTM data
 */
public class UndoLookupSrtm implements UndoOperation
{
	/** DataPoint objects which didn't have altitudes before */
	private DataPoint[] _points;
	/** Altitude strings if present */
	private String[] _altitudes;


	/**
	 * Constructor
	 * @param inTrackInfo track info object
	 */
	public UndoLookupSrtm(TrackInfo inTrackInfo)
	{
		Track track = inTrackInfo.getTrack();
		int numPoints = track.getNumPoints();
		// Make arrays of points and altitudes
		_points = new DataPoint[numPoints];
		_altitudes = new String[numPoints];
		for (int i=0; i<numPoints; i++)
		{
			DataPoint point = track.getPoint(i);
			if (!point.hasAltitude() || point.getAltitude().getValue() == 0)
			{
				_points[i] = point;
				if (point.hasAltitude()) {
					_altitudes[i] = point.getFieldValue(Field.ALTITUDE);
				}
			}
		}
	}


	/**
	 * @return description of operation
	 */
	public String getDescription()
	{
		return I18nManager.getText("undo.lookupsrtm");
	}


	/**
	 * Perform the undo operation on the given Track
	 * @param inTrackInfo TrackInfo object on which to perform the operation
	 */
	public void performUndo(TrackInfo inTrackInfo) throws UndoException
	{
		// Loop through points again, and reset altitudes if they have one
		final int numPoints = _points.length;
		for (int i=0; i<numPoints; i++) {
			DataPoint point = _points[i];
			if (point != null && point.hasAltitude()) {
				if (_altitudes[i] == null) {
					point.setFieldValue(Field.ALTITUDE, null, true);
				}
				else {
					point.setFieldValue(Field.ALTITUDE, _altitudes[i], true);
				}
			}
		}
		_points = null;
		UpdateMessageBroker.informSubscribers();
	}
}