Skip to content

Commit

Permalink
Create new path starting at selected waypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lhvy committed May 23, 2021
1 parent ee9116d commit c7f28f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/main/java/edu/wpi/first/pathweaver/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
import javafx.scene.input.KeyCode;
Expand Down Expand Up @@ -335,9 +336,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit c7f28f3

Please sign in to comment.