package tim.prune.data;
+import java.util.List;
+
import tim.prune.UpdateMessageBroker;
+import tim.prune.edit.FieldEdit;
+import tim.prune.edit.FieldEditList;
/**
*/
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
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<numCopied && keepPoint; j++)
System.arraycopy(_dataPoints, inEnd + 1, newPointArray, inStart,
_numPoints - inEnd - 1);
}
- // Copy points over original array (careful!)
+ // Copy points over original array
_dataPoints = newPointArray;
_numPoints -= numToDelete;
// needs to be scaled again
// Make array of points to insert
DataPoint[] insertedPoints = startPoint.interpolate(endPoint, inNumPoints);
-
+
// Insert points into track
- insertRange(insertedPoints, inStartIndex + 1);
- return true;
+ return insertRange(insertedPoints, inStartIndex + 1);
+ }
+
+
+ /**
+ * Append the specified points to the end of the track
+ * @param inPoints DataPoint objects to add
+ */
+ public void appendPoints(DataPoint[] inPoints)
+ {
+ // Insert points into track
+ if (inPoints != null && inPoints.length > 0)
+ {
+ insertRange(inPoints, _numPoints);
+ }
+ // needs to be scaled again to recalc x, y
+ _scaled = false;
+ _broker.informSubscribers();
}
}
+ /**
+ * 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 ////////////////
_longRange.addValue(point.getLongitude().getDouble());
_latRange.addValue(point.getLatitude().getDouble());
if (point.getAltitude().isValid())
+ {
_altitudeRange.addValue(point.getAltitude());
+ }
if (point.isWaypoint())
hasWaypoint = true;
else
_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<numEdits; i++)
+ {
+ FieldEdit edit = inEditList.getEdit(i);
+ inPoint.setFieldValue(edit.getField(), edit.getValue());
+ // check coordinates
+ coordsChanged |= (edit.getField().equals(Field.LATITUDE)
+ || edit.getField().equals(Field.LONGITUDE) || edit.getField().equals(Field.ALTITUDE));
+ }
+ // set photo status if coordinates have changed
+ if (inPoint.getPhoto() != null && coordsChanged)
+ {
+ inPoint.getPhoto().setCurrentStatus(PhotoStatus.CONNECTED);
+ }
+ // point possibly needs to be scaled again
+ _scaled = false;
+ // trigger listeners
+ _broker.informSubscribers();
+ return true;
+ }
+ return false;
+ }
}