X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FTrack.java;h=1188a7c5a83d6edef42a2d8f66c1b7bf59f608df;hb=da0b1f449260a0b4a94318006382a9039726ef3e;hp=683cd21fcf6b3f07da472b64fc151970372ef51d;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/data/Track.java b/tim/prune/data/Track.java index 683cd21..1188a7c 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; /** @@ -28,9 +32,8 @@ 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 + * @param inBroker message broker object */ public Track(UpdateMessageBroker inBroker) { @@ -53,6 +56,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 @@ -144,7 +152,8 @@ public class Track for (int i=0; i<_numPoints; i++) { boolean keepPoint = true; - if (!_dataPoints[i].isWaypoint()) + // Don't delete waypoints or photo points + if (!_dataPoints[i].isWaypoint() && _dataPoints[i].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; + _broker.informSubscribers(); } @@ -581,6 +607,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 +672,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 @@ -778,6 +848,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) { @@ -790,4 +861,41 @@ public class Track _broker.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