X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FTrackInfo.java;h=bbbdefb2336d210a35d2336824d271a058557a76;hb=ca9bdb3916f9c39adbbf95d06ac95c21dafbb4e6;hp=71363dae1053ed3e89dba907a8dea89adfada90f;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/data/TrackInfo.java b/tim/prune/data/TrackInfo.java index 71363da..bbbdefb 100644 --- a/tim/prune/data/TrackInfo.java +++ b/tim/prune/data/TrackInfo.java @@ -1,5 +1,7 @@ package tim.prune.data; +import java.util.Iterator; +import java.util.Set; import tim.prune.UpdateMessageBroker; /** @@ -8,22 +10,22 @@ import tim.prune.UpdateMessageBroker; */ public class TrackInfo { - private UpdateMessageBroker _broker = null; private Track _track = null; private Selection _selection = null; private FileInfo _fileInfo = null; + private PhotoList _photoList = null; + /** * 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(); } @@ -53,6 +55,14 @@ public class TrackInfo return _fileInfo; } + /** + * @return the PhotoList object + */ + public PhotoList getPhotoList() + { + return _photoList; + } + /** * Get the currently selected point, if any * @return DataPoint if single point selected, otherwise null @@ -62,6 +72,15 @@ public class TrackInfo return _track.getPoint(_selection.getCurrentPointIndex()); } + /** + * Get the currently selected photo, if any + * @return Photo if selected, otherwise null + */ + public Photo getCurrentPhoto() + { + return _photoList.getPhoto(_selection.getCurrentPhotoIndex()); + } + /** * Load the specified data into the Track @@ -77,13 +96,87 @@ public class TrackInfo } + /** + * 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(Set inSet) + { + // Firstly count number of points and photos to add + int numPhotosToAdd = 0; + int numPointsToAdd = 0; + Iterator iterator = null; + if (inSet != null && !inSet.isEmpty()) + { + iterator = inSet.iterator(); + while (iterator.hasNext()) + { + try + { + Photo photo = (Photo) iterator.next(); + if (photo != null && !_photoList.contains(photo)) + { + numPhotosToAdd++; + if (photo.getDataPoint() != null) + { + numPointsToAdd++; + } + } + } + catch (ClassCastException ce) {} + } + } + // If there are any photos to add, add them + if (numPhotosToAdd > 0) + { + DataPoint[] dataPoints = new DataPoint[numPointsToAdd]; + int pointNum = 0; + boolean hasAltitude = false; + // Add each Photo in turn + iterator = inSet.iterator(); + while (iterator.hasNext()) + { + try + { + Photo photo = (Photo) iterator.next(); + if (photo != null && !_photoList.contains(photo)) + { + // Add photo + _photoList.addPhoto(photo); + // Add point if there is one + if (photo.getDataPoint() != null) + { + dataPoints[pointNum] = photo.getDataPoint(); + // Check if any points have altitudes + hasAltitude |= (photo.getDataPoint().getAltitude() != null); + pointNum++; + } + } + } + catch (ClassCastException ce) {} + } + if (numPointsToAdd > 0) + { + // add points to track + _track.appendPoints(dataPoints); + // modify track field list + _track.getFieldList().extendList(Field.LATITUDE); + _track.getFieldList().extendList(Field.LONGITUDE); + if (hasAltitude) {_track.getFieldList().extendList(Field.ALTITUDE);} + } + } + int[] result = {numPhotosToAdd, numPointsToAdd}; + return result; + } + + /** * Delete the currently selected range of points * @return true if successful */ public boolean deleteRange() { - int currPoint = _selection.getCurrentPointIndex(); int startSel = _selection.getStart(); int endSel = _selection.getEnd(); boolean answer = _track.deleteRange(startSel, endSel); @@ -102,13 +195,50 @@ public class TrackInfo if (_track.deletePoint(_selection.getCurrentPointIndex())) { _selection.modifyPointDeleted(); - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); return true; } return false; } + /** + * Delete the currently selected photo and optionally its point too + * @param inPointToo true to also delete associated point + * @return true if delete successful + */ + public boolean deleteCurrentPhoto(boolean inPointToo) + { + // delete currently selected photo + int photoIndex = _selection.getCurrentPhotoIndex(); + if (photoIndex >= 0) + { + Photo photo = _photoList.getPhoto(photoIndex); + _photoList.deletePhoto(photoIndex); + // has it got a point? + if (photo.getDataPoint() != null) + { + if (inPointToo) + { + // delete point + int pointIndex = _track.getPointIndex(photo.getDataPoint()); + _track.deletePoint(pointIndex); + } + else + { + // disconnect point from photo + photo.getDataPoint().setPhoto(null); + photo.setDataPoint(null); + } + } + // update subscribers + _selection.modifyPointDeleted(); + UpdateMessageBroker.informSubscribers(); + } + return true; + } + + /** * Compress the track to the given resolution * @param inResolution resolution @@ -117,8 +247,10 @@ public class TrackInfo public int compress(int inResolution) { int numDeleted = _track.compress(inResolution); - if (numDeleted > 0) + if (numDeleted > 0) { _selection.clearAll(); + UpdateMessageBroker.informSubscribers(); + } return numDeleted; } @@ -130,8 +262,10 @@ public class TrackInfo public int deleteDuplicates() { int numDeleted = _track.deleteDuplicates(); - if (numDeleted > 0) + if (numDeleted > 0) { _selection.clearAll(); + UpdateMessageBroker.informSubscribers(); + } return numDeleted; } @@ -159,4 +293,39 @@ public class TrackInfo _selection.selectRangeEnd(_selection.getEnd() + inNumPoints); return success; } + + + /** + * Select the given DataPoint + * @param inPoint DataPoint object to select + */ + public void selectPoint(DataPoint inPoint) + { + // get the index of the given Point + int index = _track.getPointIndex(inPoint); + // give to selection + _selection.selectPoint(index); + } + + /** + * Select the given Photo and its point if any + * @param inPhotoIndex index of photo to select + */ + public void selectPhoto(int inPhotoIndex) + { + // Find Photo object + Photo photo = _photoList.getPhoto(inPhotoIndex); + if (photo != null) + { + // Find point object and its index + int pointIndex = _track.getPointIndex(photo.getDataPoint()); + // give to selection object + _selection.selectPhotoAndPoint(inPhotoIndex, pointIndex); + } + else + { + // no photo, just reset selection + _selection.selectPhotoAndPoint(-1, -1); + } + } }