X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FTrack.java;h=9c65437b60abc86df5bd803c3f045d946e89a2f5;hb=ca9bdb3916f9c39adbbf95d06ac95c21dafbb4e6;hp=683cd21fcf6b3f07da472b64fc151970372ef51d;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/data/Track.java b/tim/prune/data/Track.java index 683cd21..9c65437 100644 --- a/tim/prune/data/Track.java +++ b/tim/prune/data/Track.java @@ -1,6 +1,10 @@ package tim.prune.data; +import java.util.List; + import tim.prune.UpdateMessageBroker; +import tim.prune.edit.FieldEdit; +import tim.prune.edit.FieldEditList; /** @@ -9,8 +13,6 @@ import tim.prune.UpdateMessageBroker; */ public class Track { - // Broker object - UpdateMessageBroker _broker = null; // Data points private DataPoint[] _dataPoints = null; // Scaled x, y values @@ -28,13 +30,10 @@ public class Track /** - * Constructor giving arrays of Fields and Objects - * @param inFieldArray field array - * @param inPointArray 2d array of field values + * Constructor for empty track */ - public Track(UpdateMessageBroker inBroker) + public Track() { - _broker = inBroker; // create field list _masterFieldList = new FieldList(null); // make empty DataPoint array @@ -53,6 +52,11 @@ public class Track */ public void load(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat) { + if (inFieldArray == null || inPointArray == null) + { + _numPoints = 0; + return; + } // copy field list _masterFieldList = new FieldList(inFieldArray); // make DataPoint object from each point in inPointList @@ -71,6 +75,11 @@ public class Track } } _numPoints = pointIndex; + // Set first track point to be start of segment + DataPoint firstTrackPoint = getNextTrackPoint(0); + if (firstTrackPoint != null) { + firstTrackPoint.setSegmentStart(true); + } // needs to be scaled _scaled = false; } @@ -81,7 +90,7 @@ public class Track /** * Combine this Track with new data - * @param inOtherTrack + * @param inOtherTrack other track to combine */ public void combine(Track inOtherTrack) { @@ -98,7 +107,7 @@ public class Track // needs to be scaled again _scaled = false; // inform listeners - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } @@ -113,7 +122,7 @@ public class Track _numPoints = inNewSize; // needs to be scaled again _scaled = false; - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } } @@ -138,13 +147,17 @@ public class Track if (yscale > wholeScale) wholeScale = yscale; double minDist = wholeScale / inResolution; + // Keep track of segment start flags of the deleted points + boolean setSegment = false; // Copy selected points DataPoint[] newPointArray = new DataPoint[_numPoints]; int[] pointIndices = new int[_numPoints]; for (int i=0; i<_numPoints; i++) { + DataPoint point = _dataPoints[i]; boolean keepPoint = true; - if (!_dataPoints[i].isWaypoint()) + // Don't delete waypoints or photo points + if (!point.isWaypoint() && point.getPhoto() == null) { // go through newPointArray to check for range for (int j=0; j 0) + { + insertRange(inPoints, _numPoints); + } + // needs to be scaled again to recalc x, y + _scaled = false; + UpdateMessageBroker.informSubscribers(); } @@ -511,6 +594,23 @@ public class Track return _yRange; } + /** + * @return The range of lat values as a DoubleRange object + */ + public DoubleRange getLatRange() + { + if (!_scaled) scalePoints(); + return _latRange; + } + /** + * @return The range of lon values as a DoubleRange object + */ + public DoubleRange getLonRange() + { + if (!_scaled) scalePoints(); + return _longRange; + } + /** * @param inPointNum point index, starting at 0 * @return scaled x value of specified point @@ -581,6 +681,48 @@ public class Track } + /** + * Collect all the waypoints into the given List + * @param inList List to fill with waypoints + */ + public void getWaypoints(List inList) + { + // clear list + inList.clear(); + // loop over points and copy all waypoints into list + for (int i=0; i<=_numPoints-1; i++) + { + if (_dataPoints[i] != null && _dataPoints[i].isWaypoint()) + { + inList.add(_dataPoints[i]); + } + } + } + + + /** + * Search for the given Point in the track and return the index + * @param inPoint Point to look for + * @return index of Point, if any or -1 if not found + */ + public int getPointIndex(DataPoint inPoint) + { + if (inPoint != null) + { + // Loop over points in track + for (int i=0; i<=_numPoints-1; i++) + { + if (_dataPoints[i] == inPoint) + { + return i; + } + } + } + // not found + return -1; + } + + ///////// Internal processing methods //////////////// @@ -604,7 +746,9 @@ public class Track _longRange.addValue(point.getLongitude().getDouble()); _latRange.addValue(point.getLatitude().getDouble()); if (point.getAltitude().isValid()) + { _altitudeRange.addValue(point.getAltitude()); + } if (point.isWaypoint()) hasWaypoint = true; else @@ -673,6 +817,71 @@ public class Track } + /** + * Get the next track point starting from the given index + * @param inStartIndex index to start looking from + * @return next track point, or null if end of data reached + */ + public DataPoint getNextTrackPoint(int inStartIndex) + { + return getNextTrackPoint(inStartIndex, 1); + } + + /** + * Get the previous track point starting from the given index + * @param inStartIndex index to start looking from + * @return next track point, or null if end of data reached + */ + public DataPoint getPreviousTrackPoint(int inStartIndex) + { + return getNextTrackPoint(inStartIndex, -1); + } + + /** + * Get the next track point starting from the given index + * @param inStartIndex index to start looking from + * @param inIncrement increment to add to point index, +1 for next, -1 for previous + * @return next track point, or null if end of data reached + */ + private DataPoint getNextTrackPoint(int inStartIndex, int inIncrement) + { + // Loop forever over points + for (int i=inStartIndex; ; i+=inIncrement) + { + DataPoint point = getPoint(i); + // Exit if end of data reached - there wasn't a track point + if (point == null) {return null;} + if (point.isValid() && !point.isWaypoint()) { + // next track point found + return point; + } + } + } + + /** + * Shift all the segment start flags in the given range by 1 + * Method used by reverse range and its undo + * @param inStartIndex start of range, inclusive + * @param inEndIndex end of range, inclusive + */ + public void shiftSegmentStarts(int inStartIndex, int inEndIndex) + { + boolean prevFlag = true; + boolean currFlag = true; + for (int i=inStartIndex; i<= inEndIndex; i++) + { + DataPoint point = getPoint(i); + if (point != null && !point.isWaypoint()) + { + // remember flag + currFlag = point.getSegmentStart(); + // shift flag by 1 + point.setSegmentStart(prevFlag); + prevFlag = currFlag; + } + } + } + ////////////////// Cloning and replacing /////////////////// /** @@ -737,7 +946,7 @@ public class Track _numPoints++; // needs to be scaled again _scaled = false; - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); return true; } @@ -770,7 +979,7 @@ public class Track _numPoints += inPoints.length; // needs to be scaled again _scaled = false; - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); return true; } @@ -778,6 +987,7 @@ public class Track /** * Replace the track contents with the given point array * @param inContents array of DataPoint objects + * @return true on success */ public boolean replaceContents(DataPoint[] inContents) { @@ -787,7 +997,44 @@ public class Track _dataPoints = inContents; _numPoints = _dataPoints.length; _scaled = false; - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); return true; } + + + /** + * Edit the specified point + * @param inPoint point to edit + * @param inEditList list of edits to make + * @return true if successful + */ + public boolean editPoint(DataPoint inPoint, FieldEditList inEditList) + { + if (inPoint != null && inEditList != null && inEditList.getNumEdits() > 0) + { + // remember if coordinates have changed + boolean coordsChanged = false; + // go through edits one by one + int numEdits = inEditList.getNumEdits(); + for (int i=0; i