From d00d86bd49b77696830771103b91b7715816bef8 Mon Sep 17 00:00:00 2001 From: lhvy Date: Mon, 24 May 2021 09:29:48 +1000 Subject: [PATCH] Create new path starting at selected waypoint --- .../edu/wpi/first/pathweaver/MainController.java | 14 +++++++++++--- .../first/pathweaver/path/wpilib/WpilibPath.java | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/wpi/first/pathweaver/MainController.java b/src/main/java/edu/wpi/first/pathweaver/MainController.java index 954cb37c..aeb7c751 100644 --- a/src/main/java/edu/wpi/first/pathweaver/MainController.java +++ b/src/main/java/edu/wpi/first/pathweaver/MainController.java @@ -14,6 +14,7 @@ import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.geometry.Point2D; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; @@ -333,9 +334,16 @@ private void duplicate() { private void createPath() { String name = MainIOUtil.getValidFileName(pathDirectory, "Unnamed", ".path"); MainIOUtil.addChild(pathRoot, name); - Path newPath = new WpilibPath(name); - // The default path defaults to FEET - newPath.convertUnit(PathUnits.FOOT, ProjectPreferences.getInstance().getValues().getLengthUnit()); + Path newPath; + Waypoint currentWaypoint = CurrentSelections.getCurWaypoint(); + if (currentWaypoint == null) { // have nothing selected + newPath = new WpilibPath(name); + // The default path defaults to FEET + newPath.convertUnit(PathUnits.FOOT, ProjectPreferences.getInstance().getValues().getLengthUnit()); + } else { + newPath = new WpilibPath(new Point2D(currentWaypoint.getX(), currentWaypoint.getY()), new Point2D(8, -4), + new Point2D(currentWaypoint.getTangentX(), currentWaypoint.getTangentY()), new Point2D(0, 1), name); + } SaveManager.getInstance().saveChange(newPath); } diff --git a/src/main/java/edu/wpi/first/pathweaver/path/wpilib/WpilibPath.java b/src/main/java/edu/wpi/first/pathweaver/path/wpilib/WpilibPath.java index 6ced2db4..c959fbeb 100644 --- a/src/main/java/edu/wpi/first/pathweaver/path/wpilib/WpilibPath.java +++ b/src/main/java/edu/wpi/first/pathweaver/path/wpilib/WpilibPath.java @@ -169,7 +169,7 @@ public WpilibPath(String name) { * @param endTangent The ending tangent vector of new path * @param name The string name to assign path, also used for naming exported files */ - private WpilibPath(Point2D startPos, Point2D endPos, Point2D startTangent, Point2D endTangent, String name) { + public WpilibPath(Point2D startPos, Point2D endPos, Point2D startTangent, Point2D endTangent, String name) { this(List.of(new Waypoint(startPos, startTangent, true, false), new Waypoint(endPos, endTangent, true, false)), name); }