Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new path starting at selected waypoint #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Alert;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -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);
}

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