* Load method, for initialising and reinitialising data
* @param inFieldArray array of Field objects describing fields
* @param inPointArray 2d object array containing data
- * @param inAltFormat altitude format
+ * @param inOptions load options such as units
*/
- public void load(Field[] inFieldArray, Object[][] inPointArray, Altitude.Format inAltFormat)
+ public void load(Field[] inFieldArray, Object[][] inPointArray, PointCreateOptions inOptions)
{
if (inFieldArray == null || inPointArray == null)
{
{
dataArray = (String[]) inPointArray[p];
// Convert to DataPoint objects
- DataPoint point = new DataPoint(dataArray, _masterFieldList, inAltFormat);
+ DataPoint point = new DataPoint(dataArray, _masterFieldList, inOptions);
if (point.isValid())
{
_dataPoints[pointIndex] = point;
pointIndex++;
}
+ else
+ {
+ // TODO: Maybe report this somehow?
+ // System.out.println("point is not valid!");
+ }
}
_numPoints = pointIndex;
// Set first track point to be start of segment
// Loop over all points within range
for (int i=inStart; i<=inEnd; i++)
{
- Timestamp timestamp = _dataPoints[i].getTimestamp();
- if (timestamp != null)
+ DataPoint p = _dataPoints[i];
+ if (p != null && p.hasTimestamp())
{
// This point has a timestamp so add the offset to it
foundTimestamp = true;
- timestamp.addOffset(inOffset);
- _dataPoints[i].setModified(inUndo);
+ p.addTimeOffset(inOffset);
+ p.setModified(inUndo);
}
}
return foundTimestamp;
* @param inStart start of range
* @param inEnd end of range
* @param inOffset offset to add (-ve to subtract)
- * @param inFormat altitude format of offset
+ * @param inUnit altitude unit of offset
* @param inDecimals number of decimal places in offset
* @return true on success
*/
public boolean addAltitudeOffset(int inStart, int inEnd, double inOffset,
- Altitude.Format inFormat, int inDecimals)
+ Unit inUnit, int inDecimals)
{
// sanity check
if (inStart < 0 || inEnd < 0 || inStart >= inEnd || inEnd >= _numPoints) {
// Loop over all points within range
for (int i=inStart; i<=inEnd; i++)
{
- Altitude alt = _dataPoints[i].getAltitude();
- if (alt != null && alt.isValid())
+ DataPoint p = _dataPoints[i];
+ if (p != null && p.hasAltitude())
{
// This point has an altitude so add the offset to it
foundAlt = true;
- alt.addOffset(inOffset, inFormat, inDecimals);
- _dataPoints[i].setModified(false);
+ p.addAltitudeOffset(inOffset, inUnit, inDecimals);
+ p.setModified(false);
}
}
// needs to be scaled again
}
- /**
- * Collect all waypoints to the start or end of the track
- * @param inAtStart true to collect at start, false for end
- * @return true if successful, false if no change
- */
- public boolean collectWaypoints(boolean inAtStart)
- {
- // Check for mixed data, numbers of waypoints & nons
- int numWaypoints = 0, numNonWaypoints = 0;
- boolean wayAfterNon = false, nonAfterWay = false;
- DataPoint[] waypoints = new DataPoint[_numPoints];
- DataPoint[] nonWaypoints = new DataPoint[_numPoints];
- DataPoint point = null;
- for (int i=0; i<_numPoints; i++)
- {
- point = _dataPoints[i];
- if (point.isWaypoint())
- {
- waypoints[numWaypoints] = point;
- numWaypoints++;
- wayAfterNon |= (numNonWaypoints > 0);
- }
- else
- {
- nonWaypoints[numNonWaypoints] = point;
- numNonWaypoints++;
- nonAfterWay |= (numWaypoints > 0);
- }
- }
- // Exit if the data is already in the specified order
- if (numWaypoints == 0 || numNonWaypoints == 0
- || (inAtStart && !wayAfterNon && nonAfterWay)
- || (!inAtStart && wayAfterNon && !nonAfterWay))
- {
- return false;
- }
-
- // Copy the arrays back into _dataPoints in the specified order
- if (inAtStart)
- {
- System.arraycopy(waypoints, 0, _dataPoints, 0, numWaypoints);
- System.arraycopy(nonWaypoints, 0, _dataPoints, numWaypoints, numNonWaypoints);
- }
- else
- {
- System.arraycopy(nonWaypoints, 0, _dataPoints, 0, numNonWaypoints);
- System.arraycopy(waypoints, 0, _dataPoints, numNonWaypoints, numWaypoints);
- }
- // needs to be scaled again
- _scaled = false;
- UpdateMessageBroker.informSubscribers();
- return true;
- }
-
-
/**
* Interleave all waypoints by each nearest track point
* @return true if successful, false if no change
double latitudeDiff = 0.0, longitudeDiff = 0.0;
double totalAltitude = 0;
int numAltitudes = 0;
- Altitude.Format altFormat = Altitude.Format.NO_FORMAT;
+ Unit altUnit = null;
// loop between start and end points
for (int i=inStartIndex; i<= inEndIndex; i++)
{
DataPoint currPoint = getPoint(i);
latitudeDiff += (currPoint.getLatitude().getDouble() - firstLatitude);
longitudeDiff += (currPoint.getLongitude().getDouble() - firstLongitude);
- if (currPoint.hasAltitude()) {
- totalAltitude += currPoint.getAltitude().getValue(altFormat);
+ if (currPoint.hasAltitude())
+ {
+ totalAltitude += currPoint.getAltitude().getValue(altUnit);
// Use altitude format of first valid altitude
- if (altFormat == Altitude.Format.NO_FORMAT)
- altFormat = currPoint.getAltitude().getFormat();
+ if (altUnit == null)
+ altUnit = currPoint.getAltitude().getUnit();
numAltitudes++;
}
}
double meanLatitude = firstLatitude + (latitudeDiff / numPoints);
double meanLongitude = firstLongitude + (longitudeDiff / numPoints);
Altitude meanAltitude = null;
- if (numAltitudes > 0) {meanAltitude = new Altitude((int) (totalAltitude / numAltitudes), altFormat);}
+ if (numAltitudes > 0) {
+ meanAltitude = new Altitude((int) (totalAltitude / numAltitudes), altUnit);
+ }
DataPoint insertedPoint = new DataPoint(new Latitude(meanLatitude, Coordinate.FORMAT_NONE),
new Longitude(meanLongitude, Coordinate.FORMAT_NONE), meanAltitude);
*/
public DoubleRange getXRange()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _xRange;
}
*/
public DoubleRange getYRange()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _yRange;
}
*/
public DoubleRange getLatRange()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _latRange;
}
/**
*/
public DoubleRange getLonRange()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _longRange;
}
*/
public double getX(int inPointNum)
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _xValues[inPointNum];
}
*/
public double getY(int inPointNum)
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _yValues[inPointNum];
}
*/
public boolean hasTrackPoints()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _hasTrackpoint;
}
*/
public boolean hasWaypoints()
{
- if (!_scaled) scalePoints();
+ if (!_scaled) {scalePoints();}
return _hasWaypoint;
}
* Scale all the points in the track to gain x and y values
* ready for plotting
*/
- private void scalePoints()
+ private synchronized void scalePoints()
{
// Loop through all points in track, to see limits of lat, long
_longRange = new DoubleRange();