]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/undo/UndoRemoveAltitudes.java
Add menu item to remove altitudes from track
[GpsPrune.git] / src / tim / prune / undo / UndoRemoveAltitudes.java
1 package tim.prune.undo;
2
3 import tim.prune.I18nManager;
4 import tim.prune.UpdateMessageBroker;
5 import tim.prune.data.Altitude;
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.TrackInfo;
8
9 /**
10  * Undo removing (ie: restore the original) altitude from points
11  */
12 public class UndoRemoveAltitudes implements UndoOperation
13 {
14         /** Start index of section */
15         private int _startIndex;
16         /** altitude values before operation */
17         private Altitude[] _altitudes;
18
19
20         /**
21          * Constructor
22          * @param inTrackInfo track info object
23          */
24         public UndoRemoveAltitudes(TrackInfo inTrackInfo, int inStart, int inEnd)
25         {
26                 _startIndex = inStart;
27                 final int numPoints = inEnd - inStart + 1;
28                 // Make array of cloned altitude objects
29                 _altitudes = new Altitude[numPoints];
30                 for (int i=0; i<numPoints; i++) {
31                         Altitude a = inTrackInfo.getTrack().getPoint(_startIndex+i).getAltitude();
32                         if (a != null && a.isValid()) {
33                                 _altitudes[i] = a.clone();
34                         }
35                 }
36         }
37
38
39         /**
40          * @return description of operation including number of points adjusted
41          */
42         public String getDescription()
43         {
44                 return I18nManager.getText("undo.removealtitudes") + " (" + (_altitudes.length) + ")";
45         }
46
47
48         /**
49          * Perform the undo operation on the given Track
50          * @param inTrackInfo TrackInfo object on which to perform the operation
51          */
52         public void performUndo(TrackInfo inTrackInfo) throws UndoException
53         {
54                 // Perform the inverse operation
55                 final int numPoints = _altitudes.length;
56                 for (int i=0; i<numPoints; i++)
57                 {
58                         DataPoint point = inTrackInfo.getTrack().getPoint(i+_startIndex);
59                         point.resetAltitude(_altitudes[i]);
60                 }
61                 _altitudes = null;
62                 inTrackInfo.getSelection().markInvalid();
63                 UpdateMessageBroker.informSubscribers();
64         }
65 }