File: UndoSewSegments.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 (44 lines) | stat: -rw-r--r-- 1,269 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
package tim.prune.undo;

import tim.prune.data.DataPoint;
import tim.prune.data.Track;
import tim.prune.data.TrackInfo;

/**
 * Operation to undo the sewing together of track segments
 */
public class UndoSewSegments extends UndoReorder
{
	/** All segment start flags need to be remembered as well */
	private boolean[] _segmentStartFlags = null;

	/**
	 * Constructor
	 * @param inTrack track contents to copy
	 */
	public UndoSewSegments(Track inTrack)
	{
		super(inTrack, "undo.sewsegments");
		// Also remember segment start flags, as they may have been changed by reversals
		final int numPoints = inTrack.getNumPoints();
		_segmentStartFlags = new boolean[numPoints];
		for (int i=0; i<numPoints; i++) {
			_segmentStartFlags[i] = inTrack.getPoint(i).getSegmentStart();
		}
	}

	/** Perform the undo */
	public void performUndo(TrackInfo inTrackInfo) throws UndoException
	{
		// Put all the points back in the right order
		super.performUndo(inTrackInfo);
		// And then restore the segment flags
		for (int i=0; i<_segmentStartFlags.length; i++)
		{
			DataPoint point = inTrackInfo.getTrack().getPoint(i);
			if (point != null && !point.isWaypoint()) {
				point.setSegmentStart(_segmentStartFlags[i]);
			}
		}
	}
}