Skip to content

Commit 672c373

Browse files
committed
Create new path starting at selected waypoint
1 parent ee9116d commit 672c373

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/java/edu/wpi/first/pathweaver/MainController.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javafx.beans.value.ObservableValue;
1515
import javafx.fxml.FXML;
1616
import javafx.fxml.FXMLLoader;
17+
import javafx.geometry.Point2D;
1718
import javafx.scene.Scene;
1819
import javafx.scene.control.*;
1920
import javafx.scene.input.KeyCode;
@@ -335,9 +336,16 @@ private void duplicate() {
335336
private void createPath() {
336337
String name = MainIOUtil.getValidFileName(pathDirectory, "Unnamed", ".path");
337338
MainIOUtil.addChild(pathRoot, name);
338-
Path newPath = new WpilibPath(name);
339-
// The default path defaults to FEET
340-
newPath.convertUnit(PathUnits.FOOT, ProjectPreferences.getInstance().getValues().getLengthUnit());
339+
Path newPath;
340+
Waypoint currentWaypoint = CurrentSelections.getCurWaypoint();
341+
if (currentWaypoint == null) { // have nothing selected
342+
newPath = new WpilibPath(name);
343+
// The default path defaults to FEET
344+
newPath.convertUnit(PathUnits.FOOT, ProjectPreferences.getInstance().getValues().getLengthUnit());
345+
} else {
346+
newPath = new WpilibPath(new Point2D(currentWaypoint.getX(), currentWaypoint.getY()), new Point2D(8, -4),
347+
new Point2D(currentWaypoint.getTangentX(), currentWaypoint.getTangentY()), new Point2D(0, 1), name);
348+
}
341349
SaveManager.getInstance().saveChange(newPath);
342350
}
343351

src/main/java/edu/wpi/first/pathweaver/path/wpilib/WpilibPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public WpilibPath(String name) {
169169
* @param endTangent The ending tangent vector of new path
170170
* @param name The string name to assign path, also used for naming exported files
171171
*/
172-
private WpilibPath(Point2D startPos, Point2D endPos, Point2D startTangent, Point2D endTangent, String name) {
172+
public WpilibPath(Point2D startPos, Point2D endPos, Point2D startTangent, Point2D endTangent, String name) {
173173
this(List.of(new Waypoint(startPos, startTangent, true, false), new Waypoint(endPos, endTangent, true, false)), name);
174174
}
175175

0 commit comments

Comments
 (0)