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