X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FSelection.java;h=95e0cfbd7ded462f51fb750c79df010e18a2ce20;hb=52bf9e8686c916be37a26a0b75340393d4478b05;hp=b26c11ff7bbca551bbc4f6574dc4123259512fc0;hpb=da0b1f449260a0b4a94318006382a9039726ef3e;p=GpsPrune.git diff --git a/tim/prune/data/Selection.java b/tim/prune/data/Selection.java index b26c11f..95e0cfb 100644 --- a/tim/prune/data/Selection.java +++ b/tim/prune/data/Selection.java @@ -10,7 +10,6 @@ import tim.prune.UpdateMessageBroker; public class Selection { private Track _track = null; - private UpdateMessageBroker _broker = null; private int _currentPoint = -1; private boolean _valid = false; private int _startIndex = -1, _endIndex = -1; @@ -18,19 +17,17 @@ public class Selection private IntegerRange _altitudeRange = null; private int _climb = -1, _descent = -1; private int _altitudeFormat = Altitude.FORMAT_NONE; - private long _seconds = 0L; - private double _angDistance = -1.0; //, _averageSpeed = -1.0; + private long _totalSeconds = 0L, _movingSeconds = 0L; + private double _angDistance = -1.0, _angMovingDistance = -1.0; /** * Constructor * @param inTrack track object - * @param inBroker broker object */ - public Selection(Track inTrack, UpdateMessageBroker inBroker) + public Selection(Track inTrack) { _track = inTrack; - _broker = inBroker; } @@ -120,8 +117,10 @@ public class Selection _descent = 0; Altitude altitude = null; Timestamp time = null, startTime = null, endTime = null; + Timestamp previousTime = null; DataPoint lastPoint = null, currPoint = null; - _angDistance = 0.0; + _angDistance = 0.0; _angMovingDistance = 0.0; + _totalSeconds = 0L; _movingSeconds = 0L; int altValue = 0; int lastAltValue = 0; boolean foundAlt = false; @@ -150,26 +149,30 @@ public class Selection time = currPoint.getTimestamp(); if (time.isValid()) { - if (startTime == null) startTime = time; - endTime = time; + if (startTime == null || startTime.isAfter(time)) startTime = time; + if (endTime == null || time.isAfter(endTime)) endTime = time; + // add moving time + if (!currPoint.getSegmentStart() && previousTime != null && time.isAfter(previousTime)) { + _movingSeconds += time.getSecondsSince(previousTime); + } + previousTime = time; } // Calculate distances, again ignoring waypoints if (!currPoint.isWaypoint()) { if (lastPoint != null) { - _angDistance += DataPoint.calculateRadiansBetween(lastPoint, currPoint); + double radians = DataPoint.calculateRadiansBetween(lastPoint, currPoint); + _angDistance += radians; + if (!currPoint.getSegmentStart()) { + _angMovingDistance += radians; + } } lastPoint = currPoint; } } - if (endTime != null) - { - _seconds = endTime.getSecondsSince(startTime); - } - else - { - _seconds = 0L; + if (endTime != null) { + _totalSeconds = endTime.getSecondsSince(startTime); } } _valid = true; @@ -239,9 +242,17 @@ public class Selection public long getNumSeconds() { if (!_valid) recalculate(); - return _seconds; + return _totalSeconds; } + /** + * @return number of seconds spanned by segments within selection + */ + public long getMovingSeconds() + { + if (!_valid) recalculate(); + return _movingSeconds; + } /** * @param inUnits distance units to use, from class Distance @@ -252,6 +263,14 @@ public class Selection return Distance.convertRadiansToDistance(_angDistance, inUnits); } + /** + * @param inUnits distance units to use, from class Distance + * @return moving distance of Selection in specified units + */ + public double getMovingDistance(int inUnits) + { + return Distance.convertRadiansToDistance(_angMovingDistance, inUnits); + } /** * Clear selected point and range @@ -304,7 +323,7 @@ public class Selection } } reset(); - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } @@ -337,7 +356,7 @@ public class Selection } } reset(); - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } @@ -419,7 +438,6 @@ public class Selection return _currentPhotoIndex; } - /** * Check that the selection still makes sense * and fire update message to listeners @@ -450,6 +468,6 @@ public class Selection _currentPoint = _startIndex = _endIndex = -1; } } - _broker.informSubscribers(DataSubscriber.SELECTION_CHANGED); + UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED); } }