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

Added the export buttons and Waypoint List #224

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
36 changes: 32 additions & 4 deletions src/main/java/edu/wpi/first/pathweaver/EditWaypointController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import javafx.beans.property.DoubleProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Control;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.KeyEvent;
import javafx.util.converter.NumberStringConverter;

@SuppressWarnings("PMD.UnusedPrivateMethod")
public class EditWaypointController {
@FXML
private ListView listView;
@FXML
private TextField xPosition;
@FXML
Expand All @@ -29,13 +32,20 @@ public class EditWaypointController {
private CheckBox reverseSpline;
@FXML
private TextField pointName;
@FXML
private Button javaExport;
@FXML
private Button cExport;

private List<Control> controls;
private ChangeListener<String> nameListener;

final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();

@FXML
private void initialize() {
controls = List.of(xPosition, yPosition, tangentX, tangentY, lockedTangent, pointName, reverseSpline);
controls = List.of(listView, xPosition, yPosition, tangentX, tangentY, lockedTangent, pointName, reverseSpline, javaExport, cExport);
controls.forEach(control -> control.setDisable(true));
List<TextField> textFields = List.of(xPosition, yPosition, tangentX, tangentY);
textFields.forEach(textField -> textField.setTextFormatter(FxUtils.onlyDoubleText()));
Expand Down Expand Up @@ -163,4 +173,22 @@ private void lockTangentOnEdit() {
tangentY.setOnKeyTyped((KeyEvent event) -> lockedTangent.setSelected(true));
tangentX.setOnKeyTyped((KeyEvent event) -> lockedTangent.setSelected(true));
}

@FXML
private void handleJavaExport() {
String baseString = "var %s = new ControlVector(new double[] {%f, %f}, new double[] {%f, %f});";
var wp = CurrentSelections.getCurWaypoint();
String clipStr = String.format(baseString, wp.getName(), wp.getX(), wp.getTangentX(), wp.getY(), wp.getTangentY());
content.putString(clipStr);
clipboard.setContent(content);
}

@FXML
private void handleCExport() {
String baseString = "ControlVector %s{{%f, %f}, {%f, %f}};";
var wp = CurrentSelections.getCurWaypoint();
String clipStr = String.format(baseString, wp.getName(), wp.getX(), wp.getTangentX(), wp.getY(), wp.getTangentY());
content.putString(clipStr);
clipboard.setContent(content);
}
}
44 changes: 29 additions & 15 deletions src/main/resources/edu/wpi/first/pathweaver/editWaypoint.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Button?>
<GridPane fx:id="properties" hgap="5.0" vgap="5.0" BorderPane.alignment="CENTER" xmlns="http://javafx.com/javafx/10.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.wpi.first.pathweaver.EditWaypointController">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" percentWidth="12.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" percentWidth="12.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints halignment="RIGHT" minWidth="10.0" prefWidth="80.0"/>
<ColumnConstraints minWidth="10.0" prefWidth="230.0"/>
<ColumnConstraints halignment="RIGHT" minWidth="10.0" prefWidth="80.0"/>
<ColumnConstraints minWidth="10.0" prefWidth="230.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
Expand All @@ -25,18 +28,27 @@
<BorderPane.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</BorderPane.margin>
<Label text="X"/>
<Label text="Y" GridPane.rowIndex="1"/>
<Label text="Tangent X" GridPane.columnIndex="2"/>
<Label text="Tangent Y" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
<Label text="Name" GridPane.rowIndex="2"/>
<TextField GridPane.columnIndex="1" fx:id="xPosition"/>
<TextField fx:id="yPosition" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<TextField fx:id="tangentX" GridPane.columnIndex="3"/>
<TextField fx:id="tangentY" GridPane.columnIndex="3" GridPane.rowIndex="1"/>
<TextField fx:id="pointName" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<GridPane fx:id="properties" hgap="5.0" vgap="5.0" BorderPane.alignment="CENTER" xmlns="http://javafx.com/javafx/10.0.1"
xmlns:fx="http://javafx.com/fxml/1" GridPane.columnIndex="3" GridPane.rowIndex="2">
<Label text="X" GridPane.columnIndex="1"/>
<Label text="Y" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label text="Tangent X" GridPane.columnIndex="3"/>
<Label text="Tangent Y" GridPane.columnIndex="3" GridPane.rowIndex="1"/>
<Label text="Name" GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<GridPane fx:id="waypointList" hgap="5.0" vgap="5.0" BorderPane.alignment="CENTER" xmlns="http://javafx.com/javafx/10.0.1"
xmlns:fx="http://javafx.com/fxml/1" GridPane.rowSpan="3">
<columnConstraints>
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" minWidth="100.0" prefWidth="300.0"/>
</columnConstraints>
<ListView fx:id="listView"/>
</GridPane>

<TextField GridPane.columnIndex="2" fx:id="xPosition"/>
<TextField fx:id="yPosition" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
<TextField fx:id="tangentX" GridPane.columnIndex="4"/>
<TextField fx:id="tangentY" GridPane.columnIndex="4" GridPane.rowIndex="1"/>
<TextField fx:id="pointName" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
<GridPane fx:id="checkboxes" hgap="5.0" vgap="5.0" BorderPane.alignment="CENTER" xmlns="http://javafx.com/javafx/10.0.1"
xmlns:fx="http://javafx.com/fxml/1" GridPane.columnIndex="4" GridPane.rowIndex="2">
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="10.0"/>
Expand All @@ -48,4 +60,6 @@
<CheckBox fx:id="lockedTangent" mnemonicParsing="false" GridPane.columnIndex="1"/>
<CheckBox fx:id="reverseSpline" mnemonicParsing="false" GridPane.columnIndex="3"/>
</GridPane>
<Button text="Java Export" fx:id="javaExport" onAction="#handleJavaExport" GridPane.columnIndex="5"/>
<Button text="C++ Export" fx:id="cExport" onAction="#handleCExport" GridPane.columnIndex="5" GridPane.rowIndex="1"/>
</GridPane>