X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FTrack.java;h=63cd01faaf488028085a6712c5648ad9ffa8ea1d;hb=f1b92378a792131ac8fb33a869405851d5b2d1f7;hp=08168d1fb6c348a43cc97eff367021b9c7241ab8;hpb=112bb0c9b46894adca9a33ed8c99ea712b253185;p=GpsPrune.git diff --git a/tim/prune/data/Track.java b/tim/prune/data/Track.java index 08168d1..63cd01f 100644 --- a/tim/prune/data/Track.java +++ b/tim/prune/data/Track.java @@ -2,8 +2,8 @@ package tim.prune.data; import java.util.List; -import tim.prune.Config; import tim.prune.UpdateMessageBroker; +import tim.prune.config.Config; import tim.prune.function.edit.FieldEdit; import tim.prune.function.edit.FieldEditList; import tim.prune.gui.map.MapUtils; @@ -46,6 +46,19 @@ public class Track _scaled = false; } + /** + * Constructor using fields and points from another Track + * @param inFieldList Field list from another Track object + * @param inPoints (edited) point array + */ + public Track(FieldList inFieldList, DataPoint[] inPoints) + { + _masterFieldList = inFieldList; + _dataPoints = inPoints; + if (_dataPoints == null) _dataPoints = new DataPoint[0]; + _numPoints = _dataPoints.length; + _scaled = false; + } /** * Load method, for initialising and reinitialising data @@ -101,6 +114,23 @@ public class Track _scaled = false; } + /** + * Request that a rescale be done to recalculate derived values + */ + public void requestRescale() + { + _scaled = false; + } + + /** + * Extend the track's field list with the given additional fields + * @param inFieldList list of fields to be added + */ + public void extendFieldList(FieldList inFieldList) + { + _masterFieldList = _masterFieldList.merge(inFieldList); + } + ////////////////// Modification methods ////////////////////// @@ -156,7 +186,7 @@ public class Track { DataPoint point = _dataPoints[i]; // Don't delete photo points - if (point.getPhoto() != null || !point.getDeleteFlag()) + if (point.hasMedia() || !point.getDeleteFlag()) { newPointArray[numCopied] = point; numCopied++; @@ -275,9 +305,10 @@ public class Track * @param inStart start of range * @param inEnd end of range * @param inOffset offset to add (-ve to subtract) + * @param inUndo true for undo operation * @return true on success */ - public boolean addTimeOffset(int inStart, int inEnd, long inOffset) + public boolean addTimeOffset(int inStart, int inEnd, long inOffset, boolean inUndo) { // sanity check if (inStart < 0 || inEnd < 0 || inStart >= inEnd || inEnd >= _numPoints) { @@ -293,6 +324,7 @@ public class Track // This point has a timestamp so add the offset to it foundTimestamp = true; timestamp.addOffset(inOffset); + _dataPoints[i].setModified(inUndo); } } return foundTimestamp; @@ -324,6 +356,7 @@ public class Track // This point has an altitude so add the offset to it foundAlt = true; alt.addOffset(inOffset, inFormat, inDecimals); + _dataPoints[i].setModified(false); } } // needs to be scaled again @@ -331,8 +364,6 @@ public class Track return foundAlt; } - // TODO: Function to collect and sort photo points by time or photo filename - // TODO: Function to convert waypoint names into timestamps /** * Collect all waypoints to the start or end of the track @@ -458,7 +489,7 @@ public class Track { // TODO: Move cut/move into separate function? // Check that indices make sense - if (inSectionStart > 0 && inSectionEnd > inSectionStart && inMoveTo >= 0 + if (inSectionStart >= 0 && inSectionEnd > inSectionStart && inMoveTo >= 0 && (inMoveTo < inSectionStart || inMoveTo > (inSectionEnd+1))) { // do the cut and move @@ -733,11 +764,14 @@ public class Track } /** - * @return true if track has altitude data (which are not all zero) + * @return true if track has altitude data */ public boolean hasAltitudeData() { - return getAltitudeRange().getMaximum() > 0; + for (int i=0; i<_numPoints; i++) { + if (_dataPoints[i].hasAltitude()) {return true;} + } + return false; } /** @@ -945,6 +979,7 @@ public class Track */ public DataPoint getPreviousTrackPoint(int inStartIndex) { + // end index is given as _numPoints but actually it just counts down to -1 return getNextTrackPoint(inStartIndex, _numPoints, false); } @@ -1120,9 +1155,10 @@ public class Track * Edit the specified point * @param inPoint point to edit * @param inEditList list of edits to make + * @param inUndo true if undo operation, false otherwise * @return true if successful */ - public boolean editPoint(DataPoint inPoint, FieldEditList inEditList) + public boolean editPoint(DataPoint inPoint, FieldEditList inEditList, boolean inUndo) { if (inPoint != null && inEditList != null && inEditList.getNumEdits() > 0) { @@ -1134,7 +1170,7 @@ public class Track { FieldEdit edit = inEditList.getEdit(i); Field editField = edit.getField(); - inPoint.setFieldValue(editField, edit.getValue()); + inPoint.setFieldValue(editField, edit.getValue(), inUndo); // Check that master field list has this field already (maybe point name has been added) if (!_masterFieldList.contains(editField)) { _masterFieldList.extendList(editField); @@ -1156,4 +1192,18 @@ public class Track } return false; } + + /** + * @param inPoint point to check + * @return true if this track contains the given point + */ + public boolean containsPoint(DataPoint inPoint) + { + if (inPoint == null) return false; + for (int i=0; i < getNumPoints(); i++) + { + if (getPoint(i) == inPoint) return true; + } + return false; // not found + } }