X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FTrackInfo.java;h=eddea09468c58f7f0cfda69772ce88c690462d7e;hb=112bb0c9b46894adca9a33ed8c99ea712b253185;hp=b987ea9449d6dff66fd52f2af60031752f415413;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b;p=GpsPrune.git diff --git a/tim/prune/data/TrackInfo.java b/tim/prune/data/TrackInfo.java index b987ea9..eddea09 100644 --- a/tim/prune/data/TrackInfo.java +++ b/tim/prune/data/TrackInfo.java @@ -1,7 +1,7 @@ package tim.prune.data; -import java.util.List; - +import java.util.Iterator; +import java.util.Set; import tim.prune.UpdateMessageBroker; /** @@ -10,7 +10,6 @@ import tim.prune.UpdateMessageBroker; */ public class TrackInfo { - private UpdateMessageBroker _broker = null; private Track _track = null; private Selection _selection = null; private FileInfo _fileInfo = null; @@ -20,13 +19,11 @@ public class TrackInfo /** * Constructor * @param inTrack Track object - * @param inBroker broker object */ - public TrackInfo(Track inTrack, UpdateMessageBroker inBroker) + public TrackInfo(Track inTrack) { - _broker = inBroker; _track = inTrack; - _selection = new Selection(_track, inBroker); + _selection = new Selection(_track); _fileInfo = new FileInfo(); _photoList = new PhotoList(); } @@ -86,37 +83,24 @@ public class TrackInfo /** - * Load the specified data into the Track - * @param inFieldArray array of Field objects describing fields - * @param inPointArray 2d object array containing data - * @param inAltFormat altitude format - */ - public void loadTrack(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat) - { - _track.cropTo(0); - _track.load(inFieldArray, inPointArray, inAltFormat); - _selection.clearAll(); - } - - - /** - * Add a List of Photos - * @param inList List containing Photo objects + * Add a Set of Photos + * @param inSet Set containing Photo objects * @return array containing number of photos and number of points added */ - public int[] addPhotos(List inList) + public int[] addPhotos(Set inSet) { - // TODO: Should photos be sorted at load-time, either by filename or date? // Firstly count number of points and photos to add int numPhotosToAdd = 0; int numPointsToAdd = 0; - if (inList != null && !inList.isEmpty()) + Iterator iterator = null; + if (inSet != null && !inSet.isEmpty()) { - for (int i=0; i 0) - _selection.clearAll(); - return numDeleted; - } - - - /** - * Delete all the duplicate points in the track + * Delete all the points which have been marked for deletion * @return number of points deleted */ - public int deleteDuplicates() + public int deleteMarkedPoints() { - int numDeleted = _track.deleteDuplicates(); - if (numDeleted > 0) + int numDeleted = _track.deleteMarkedPoints(); + if (numDeleted > 0) { _selection.clearAll(); + UpdateMessageBroker.informSubscribers(); + } return numDeleted; } @@ -276,18 +249,57 @@ public class TrackInfo return _track.cloneRange(_selection.getStart(), _selection.getEnd()); } + /** + * Merge the track segments within the given range + * @param inStart start index + * @param inEnd end index + * @return true if successful + */ + public boolean mergeTrackSegments(int inStart, int inEnd) + { + boolean firstTrackPoint = true; + // Loop between start and end + for (int i=inStart; i<=inEnd; i++) { + DataPoint point = _track.getPoint(i); + // Set all segments to false apart from first track point + if (point != null && !point.isWaypoint()) { + point.setSegmentStart(firstTrackPoint); + firstTrackPoint = false; + } + } + // Find following track point, if any + DataPoint nextPoint = _track.getNextTrackPoint(inEnd+1); + if (nextPoint != null) {nextPoint.setSegmentStart(true);} + _selection.markInvalid(); + UpdateMessageBroker.informSubscribers(); + return true; + } /** * Interpolate extra points between two selected ones - * @param inStartIndex start index of interpolation * @param inNumPoints num points to insert * @return true if successful */ public boolean interpolate(int inNumPoints) { boolean success = _track.interpolate(_selection.getStart(), inNumPoints); - if (success) + if (success) { _selection.selectRangeEnd(_selection.getEnd() + inNumPoints); + } + return success; + } + + + /** + * Average selected points to create a new one + * @return true if successful + */ + public boolean average() + { + boolean success = _track.average(_selection.getStart(), _selection.getEnd()); + if (success) { + selectPoint(_selection.getEnd()+1); + } return success; } @@ -298,10 +310,38 @@ public class TrackInfo */ public void selectPoint(DataPoint inPoint) { - // get the index of the given Point - int index = _track.getPointIndex(inPoint); + selectPoint(_track.getPointIndex(inPoint)); + } + + /** + * Select the data point with the given index + * @param inPointIndex index of DataPoint to select, or -1 for none + */ + public void selectPoint(int inPointIndex) + { + if (_selection.getCurrentPointIndex() == inPointIndex || inPointIndex >= _track.getNumPoints()) {return;} + // get the index of the current photo + int photoIndex = _selection.getCurrentPhotoIndex(); + // Check if point has photo or not + boolean pointHasPhoto = false; + if (inPointIndex >= 0) + { + Photo pointPhoto = _track.getPoint(inPointIndex).getPhoto(); + pointHasPhoto = (pointPhoto != null); + if (pointHasPhoto) { + photoIndex = _photoList.getPhotoIndex(pointPhoto); + } + } + // Might need to deselect photo + if (!pointHasPhoto) + { + // selected point hasn't got a photo - deselect photo if necessary + if (photoIndex < 0 || _photoList.getPhoto(photoIndex).isConnected()) { + photoIndex = -1; + } + } // give to selection - _selection.selectPoint(index); + _selection.selectPhotoAndPoint(photoIndex, inPointIndex); } /** @@ -310,28 +350,36 @@ public class TrackInfo */ public void selectPhoto(int inPhotoIndex) { + if (_selection.getCurrentPhotoIndex() == inPhotoIndex) {return;} + // Photo is primary selection here, not as a result of a point selection + // Therefore the photo selection takes priority, deselecting point if necessary // Find Photo object Photo photo = _photoList.getPhoto(inPhotoIndex); if (photo != null) { // Find point object and its index int pointIndex = _track.getPointIndex(photo.getDataPoint()); + // Check whether to deselect current point or not if photo not correlated + if (pointIndex < 0) + { + int currPointIndex = _selection.getCurrentPointIndex(); + if (currPointIndex >= 0 && _track.getPoint(currPointIndex).getPhoto() == null) + { + pointIndex = currPointIndex; // Keep currently selected point + } + } // give to selection object _selection.selectPhotoAndPoint(inPhotoIndex, pointIndex); } - else - { + else { // no photo, just reset selection - _selection.selectPhotoAndPoint(-1, -1); + DataPoint currPoint = getCurrentPoint(); + if (currPoint != null && currPoint.getPhoto() == null) { + _selection.selectPhotoAndPoint(-1, _selection.getCurrentPointIndex()); // keep point + } + else { + _selection.selectPhotoAndPoint(-1, -1); // deselect point too + } } } - - - /** - * Fire a trigger to all data subscribers - */ - public void triggerUpdate() - { - _broker.informSubscribers(); - } }