X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FCreateMarkerWaypointsFunction.java;fp=tim%2Fprune%2Ffunction%2FCreateMarkerWaypointsFunction.java;h=f3dd1f1d9bca2eba8f78f42a3a136294363543e9;hp=0000000000000000000000000000000000000000;hb=92dad5df664287acb51728e9ea599f150765d34a;hpb=81843c3d8d0771bf00d0f26034a13aa515465c78 diff --git a/tim/prune/function/CreateMarkerWaypointsFunction.java b/tim/prune/function/CreateMarkerWaypointsFunction.java new file mode 100644 index 0000000..f3dd1f1 --- /dev/null +++ b/tim/prune/function/CreateMarkerWaypointsFunction.java @@ -0,0 +1,145 @@ +package tim.prune.function; + +import java.util.ArrayList; + +import tim.prune.App; +import tim.prune.I18nManager; +import tim.prune.UpdateMessageBroker; +import tim.prune.data.DataPoint; +import tim.prune.data.Field; +import tim.prune.data.FieldList; +import tim.prune.data.Track; +import tim.prune.undo.UndoAppendPoints; + +/** + * Function to create waypoints marking either + * at regular distance intervals or time intervals + */ +public class CreateMarkerWaypointsFunction extends DistanceTimeLimitFunction +{ + /** ArrayList of points to append to the track */ + private ArrayList _pointsToAdd = new ArrayList(); + /** Counter of previously used multiple */ + private int _previousMultiple = 0; + + + /** + * Constructor + */ + public CreateMarkerWaypointsFunction(App inApp) { + super(inApp); + } + + /** + * @return name key + */ + public String getNameKey() { + return "function.createmarkerwaypoints"; + } + + /** + * Init the state to start collecting a new set of points + */ + private void initMemory() + { + _pointsToAdd.clear(); + _previousMultiple = 0; + } + + /** + * The dialog has been completed and OK pressed, so do the point creation + */ + protected void performFunction() + { + // Distribute either by distance or time + final int timeLimitSeconds = getTimeLimitInSeconds(); + final boolean createByTime = (timeLimitSeconds > 0); + final double distLimitRadians = getDistanceLimitRadians(); + final boolean createByDistance = (distLimitRadians > 0.0); + if (!createByTime && !createByDistance) { + return; // neither option selected + } + + // Make undo object + final int numPoints = _app.getTrackInfo().getTrack().getNumPoints(); + UndoAppendPoints undo = new UndoAppendPoints(numPoints); + + // set up the memory from scratch to collect the created points + initMemory(); + + // Make new waypoints, looping through the points in the track + DataPoint currPoint = null, prevPoint = null; + double currValue = 0.0, prevValue = 0.0; + for (int i=0; i