X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2FConvertNamesToTimes.java;fp=src%2Ftim%2Fprune%2Ffunction%2FConvertNamesToTimes.java;h=2368dfd11fea277656b4c32eb8c826ad3bdc149f;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/ConvertNamesToTimes.java b/src/tim/prune/function/ConvertNamesToTimes.java new file mode 100644 index 0000000..2368dfd --- /dev/null +++ b/src/tim/prune/function/ConvertNamesToTimes.java @@ -0,0 +1,74 @@ +package tim.prune.function; + +import tim.prune.App; +import tim.prune.DataSubscriber; +import tim.prune.GenericFunction; +import tim.prune.I18nManager; +import tim.prune.UpdateMessageBroker; +import tim.prune.data.DataPoint; +import tim.prune.data.Field; +import tim.prune.data.TimestampUtc; +import tim.prune.data.Track; +import tim.prune.undo.UndoConvertNamesToTimes; + +/** + * Class to provide the function to convert waypoint names to timestamps + */ +public class ConvertNamesToTimes extends GenericFunction +{ + /** + * Constructor + * @param inApp application object for callback + */ + public ConvertNamesToTimes(App inApp) + { + super(inApp); + } + + /** Get the name key */ + public String getNameKey() { + return "function.convertnamestotimes"; + } + + /** + * Begin the function + */ + public void begin() + { + int selStart = _app.getTrackInfo().getSelection().getStart(); + int selEnd = _app.getTrackInfo().getSelection().getEnd(); + final Track track = _app.getTrackInfo().getTrack(); + if (!track.hasData(Field.WAYPT_NAME, selStart, selEnd)) + { + _app.showErrorMessage(getNameKey(), "error.convertnamestotimes.nonames"); + return; + } + UndoConvertNamesToTimes undo = new UndoConvertNamesToTimes(_app.getTrackInfo()); + int numConverted = 0; + // Loop over all points in selection + for (int i=selStart; i<=selEnd; i++) + { + DataPoint point = track.getPoint(i); + if (point.isWaypoint()) + { + TimestampUtc tstamp = new TimestampUtc(point.getWaypointName()); + if (tstamp.isValid()) + { + // timestamp could be parsed! + point.setFieldValue(Field.TIMESTAMP, point.getWaypointName(), false); + // set waypoint name to nothing (track point) + point.setFieldValue(Field.WAYPT_NAME, null, false); + // increment counter + numConverted++; + } + } + } + if (numConverted > 0) + { + _app.getTrackInfo().getTrack().requestRescale(); + UpdateMessageBroker.informSubscribers(DataSubscriber.DATA_EDITED); + _app.completeFunction(undo, I18nManager.getText("confirm.convertnamestotimes")); + } + } + +}