Skip to content

Commit 381edf2

Browse files
authored
Initial Guess Waypoint heading handle (#5)
* Add heading property to InitialGuessWaypoint * Visuals + dialog for initial guess heading
1 parent 99d72e2 commit 381edf2

File tree

4 files changed

+150
-29
lines changed

4 files changed

+150
-29
lines changed

app/src/main/java/org/team2363/helixnavigator/document/timeline/HInitialGuessWaypoint.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@
33
import org.team2363.helixtrajectory.InitialGuessPoint;
44

55
import com.jlbabilino.json.DeserializedJSONConstructor;
6+
import com.jlbabilino.json.DeserializedJSONObjectValue;
7+
import com.jlbabilino.json.DeserializedJSONTarget;
8+
import com.jlbabilino.json.SerializedJSONObjectValue;
9+
10+
import javafx.beans.property.DoubleProperty;
11+
import javafx.beans.property.SimpleDoubleProperty;
12+
import javafx.scene.transform.Transform;
613

714
public class HInitialGuessWaypoint extends HWaypoint {
15+
16+
private final DoubleProperty heading = new SimpleDoubleProperty(this, "heading", 0.0);
817

918
@DeserializedJSONConstructor
1019
public HInitialGuessWaypoint() {
1120
}
1221

22+
@Override
23+
public void transformRelative(Transform transform) {
24+
super.transformRelative(transform);
25+
double deltaAngle = Math.atan2(transform.getMyx(), transform.getMxx());
26+
setHeading(getHeading() + deltaAngle);
27+
}
28+
1329
@Override
1430
public WaypointType getWaypointType() {
1531
return WaypointType.INITIAL_GUESS;
@@ -20,7 +36,19 @@ public boolean isInitialGuess() {
2036
return true;
2137
}
2238

39+
public final DoubleProperty headingProperty() {
40+
return heading;
41+
}
42+
@DeserializedJSONTarget
43+
public final void setHeading(@DeserializedJSONObjectValue(key = "heading") double value) {
44+
heading.set(value);
45+
}
46+
@SerializedJSONObjectValue(key = "heading")
47+
public final double getHeading() {
48+
return heading.get();
49+
}
50+
2351
public InitialGuessPoint toInitialGuessPoint() {
24-
return new InitialGuessPoint(getX(), getY(), 0.0);
52+
return new InitialGuessPoint(getX(), getY(), getHeading());
2553
}
2654
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
11
package org.team2363.helixnavigator.ui.editor.waypoint;
22

33
import org.team2363.helixnavigator.document.timeline.HInitialGuessWaypoint;
4+
import org.team2363.helixnavigator.global.Standards;
45

6+
import javafx.beans.property.DoubleProperty;
57
import javafx.scene.paint.Color;
68

79
public class InitialGuessWaypointView extends WaypointView {
10+
11+
private final RobotView robotView = new RobotView();
12+
13+
private final HInitialGuessWaypoint initialGuessWaypoint;
814

915
public InitialGuessWaypointView(HInitialGuessWaypoint initialGuessWaypoint) {
1016
super(initialGuessWaypoint);
17+
18+
this.initialGuessWaypoint = initialGuessWaypoint;
19+
1120
setWaypointFill(Color.SKYBLUE);
21+
22+
robotView.getView().getTransforms().add(centerTranslate);
23+
robotView.headingProperty().bind(this.initialGuessWaypoint.headingProperty());
24+
robotView.zoomScaleProperty().bind(zoomScaleProperty());
25+
robotView.getView().setOnMouseDragged(event -> {
26+
// System.out.println("Dot dragged");
27+
double x = event.getX();
28+
double y = event.getY();
29+
double[] lockAngles = {-180, -90, 0, 90, 180};
30+
double lockRadius = Standards.HEADING_LOCK_RADIUS;
31+
double angle = Math.toDegrees(Math.atan2(y, x));
32+
// System.out.println(angle);
33+
for (double lockAngle : lockAngles) {
34+
if (!event.isShiftDown() && Math.abs(angle - lockAngle) <= lockRadius) {
35+
if (lockAngle == -180) {
36+
lockAngle = 180;
37+
}
38+
angle = lockAngle;
39+
break;
40+
}
41+
}
42+
initialGuessWaypoint.setHeading(angle * (-Math.PI/180));
43+
});
44+
}
45+
46+
public final DoubleProperty bumperLengthProperty() {
47+
return robotView.bumperLengthProperty();
48+
}
49+
50+
public final void setBumperLength(double value) {
51+
robotView.setBumperLength(value);
52+
}
53+
54+
public final double getBumperLength() {
55+
return robotView.getBumperLength();
56+
}
57+
58+
public final DoubleProperty bumperWidthProperty() {
59+
return robotView.bumperWidthProperty();
60+
}
61+
62+
public final void setBumperWidth(double value) {
63+
robotView.setBumperWidth(value);
64+
}
65+
66+
public final double getBumperWidth() {
67+
return robotView.getBumperWidth();
68+
}
69+
70+
public final DoubleProperty headingProperty() {
71+
return robotView.headingProperty();
72+
}
73+
74+
public final void setHeading(double value) {
75+
robotView.setHeading(value);
76+
}
77+
78+
public final double getHeading() {
79+
return robotView.getHeading();
80+
}
81+
82+
public RobotView getRobotView() {
83+
return robotView;
1284
}
1385
}

app/src/main/java/org/team2363/helixnavigator/ui/editor/waypoint/WaypointsPane.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ private void updateWaypoints(List<? extends HWaypoint> list) {
124124
case INITIAL_GUESS:
125125
HInitialGuessWaypoint initialGuessWaypoint = (HInitialGuessWaypoint) waypoint;
126126
InitialGuessWaypointView initialGuessWaypointView = new InitialGuessWaypointView(initialGuessWaypoint);
127+
initialGuessWaypointView.bumperLengthProperty().bind(this.documentManager.getDocument().getRobotConfiguration().bumperLengthProperty());
128+
initialGuessWaypointView.bumperWidthProperty().bind(this.documentManager.getDocument().getRobotConfiguration().bumperWidthProperty());
129+
robotsPane.getChildren().add(initialGuessWaypointView.getRobotView().getView());
127130
waypointView = initialGuessWaypointView;
128131
break;
129132
default:
Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package org.team2363.helixnavigator.ui.prompts.waypoint;
22

3+
import java.util.List;
4+
35
import org.team2363.helixnavigator.document.timeline.HInitialGuessWaypoint;
46

7+
import javafx.scene.layout.GridPane;
8+
import javafx.scene.text.Text;
9+
510
public class InitialGuessWaypointEditDialog extends WaypointEditDialog {
611

7-
// private HInitialGuessWaypoint initialGuessWaypoint;
8-
// private HInitialGuessWaypoint backupInitialGuessWaypoint;
12+
private HInitialGuessWaypoint initialGuessWaypoint;
13+
private HInitialGuessWaypoint backupInitialGuessWaypoint;
14+
15+
private final Text headingText = new Text("Heading:");
16+
private final HeadingTextField headingTextField = new HeadingTextField();
917

1018
public InitialGuessWaypointEditDialog(HInitialGuessWaypoint initialGuessWaypoint) {
1119
super(initialGuessWaypoint, new HInitialGuessWaypoint());
12-
// this.initialGuessWaypoint = (HInitialGuessWaypoint) super.waypoint;
13-
// this.backupInitialGuessWaypoint = (HInitialGuessWaypoint) super.backupWaypoint;
20+
this.initialGuessWaypoint = (HInitialGuessWaypoint) super.waypoint;
21+
this.backupInitialGuessWaypoint = (HInitialGuessWaypoint) super.backupWaypoint;
22+
23+
GridPane.setConstraints(headingText, 0, 3);
24+
GridPane.setConstraints(headingTextField, 1, 3);
25+
26+
addGridItems(List.of(headingText, headingTextField));
1427

1528
backupWaypoint();
1629
// Set ui to values of HWaypoint:
@@ -19,28 +32,33 @@ public InitialGuessWaypointEditDialog(HInitialGuessWaypoint initialGuessWaypoint
1932
bindWaypoint();
2033
}
2134

22-
// @Override
23-
// protected void initializeTextFields() {
24-
// super.initializeTextFields();
25-
// }
26-
27-
// @Override
28-
// protected void unbindWaypoint() {
29-
// super.unbindWaypoint();
30-
// }
31-
32-
// @Override
33-
// protected void bindWaypoint() {
34-
// super.bindWaypoint();
35-
// }
36-
37-
// @Override
38-
// protected void backupWaypoint() {
39-
// super.backupWaypoint();
40-
// }
41-
42-
// @Override
43-
// protected void restoreBackup() {
44-
// super.restoreBackup();
45-
// }
35+
@Override
36+
protected void initializeTextFields() {
37+
super.initializeTextFields();
38+
headingTextField.setValue(initialGuessWaypoint.getHeading());
39+
}
40+
41+
@Override
42+
protected void unbindWaypoint() {
43+
super.unbindWaypoint();
44+
initialGuessWaypoint.headingProperty().unbind();
45+
}
46+
47+
@Override
48+
protected void bindWaypoint() {
49+
super.bindWaypoint();
50+
initialGuessWaypoint.headingProperty().bind(headingTextField.valueProperty());
51+
}
52+
53+
@Override
54+
protected void backupWaypoint() {
55+
super.backupWaypoint();
56+
backupInitialGuessWaypoint.setHeading(initialGuessWaypoint.getHeading());
57+
}
58+
59+
@Override
60+
protected void restoreBackup() {
61+
super.restoreBackup();
62+
initialGuessWaypoint.setHeading(backupInitialGuessWaypoint.getHeading());
63+
}
4664
}

0 commit comments

Comments
 (0)