File: ConvertNamesToTimes.java

package info (click to toggle)
gpsprune 13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,008 kB
  • sloc: java: 28,802; sh: 25; makefile: 17; python: 15
file content (73 lines) | stat: -rw-r--r-- 2,000 bytes parent folder | download | duplicates (5)
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
package tim.prune.function;

import tim.prune.App;
import tim.prune.DataSubscriber;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.UpdateMessageBroker;
import tim.prune.data.DataPoint;
import tim.prune.data.Field;
import tim.prune.data.Timestamp;
import tim.prune.data.Track;
import tim.prune.undo.UndoConvertNamesToTimes;

/**
 * Class to provide the function to convert waypoint names to timestamps
 */
public class ConvertNamesToTimes extends GenericFunction
{
	/**
	 * Constructor
	 * @param inApp application object for callback
	 */
	public ConvertNamesToTimes(App inApp)
	{
		super(inApp);
	}

	/** Get the name key */
	public String getNameKey() {
		return "function.convertnamestotimes";
	}

	/**
	 * Begin the function
	 */
	public void begin()
	{
		int selStart = _app.getTrackInfo().getSelection().getStart();
		int selEnd = _app.getTrackInfo().getSelection().getEnd();
		final Track track = _app.getTrackInfo().getTrack();
		if (!track.hasData(Field.WAYPT_NAME, selStart, selEnd))
		{
			_app.showErrorMessage(getNameKey(), "error.convertnamestotimes.nonames");
			return;
		}
		UndoConvertNamesToTimes undo = new UndoConvertNamesToTimes(_app.getTrackInfo());
		int numConverted = 0;
		// Loop over all points in selection
		for (int i=selStart; i<=selEnd; i++)
		{
			DataPoint point = track.getPoint(i);
			if (point.isWaypoint())
			{
				Timestamp tstamp = new Timestamp(point.getWaypointName());
				if (tstamp.isValid()) {
					// timestamp could be parsed!
					point.setFieldValue(Field.TIMESTAMP, point.getWaypointName(), false);
					// set waypoint name to nothing (track point)
					point.setFieldValue(Field.WAYPT_NAME, null, false);
					// increment counter
					numConverted++;
				}
			}
		}
		if (numConverted > 0)
		{
			_app.getTrackInfo().getTrack().requestRescale();
			UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED);
			_app.completeFunction(undo, I18nManager.getText("confirm.convertnamestotimes"));
		}
	}

}