Skip to content

Commit 99d72e2

Browse files
committed
Robot view on custom waypoint
1 parent ef7af9a commit 99d72e2

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

app/src/main/java/org/team2363/helixnavigator/global/Standards.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Standards {
5353
* Up to 50 characters
5454
*/
5555
public static final int MAX_NAME_LENGTH = 50;
56-
public static final String DEFAULT_FIELD_IMAGE = "2022: Rapid React";
56+
public static final String DEFAULT_FIELD_IMAGE = "2023: Charged Up";
5757
public static final double DEFAULT_OBSTACLE_SAFETY_DISTANCE = 5.0;
5858
public static final Color BACKGROUND_COLOR = Color.gray(0.85);
5959
public static final Color[] COLOR_PALETTE = {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,108 @@
11
package org.team2363.helixnavigator.ui.editor.waypoint;
22

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

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

79
public class CustomWaypointView extends WaypointView {
10+
11+
private final RobotView robotView = new RobotView();
12+
13+
private final HCustomWaypoint customWaypoint;
814

915
public CustomWaypointView(HCustomWaypoint customWaypoint) {
1016
super(customWaypoint);
17+
18+
this.customWaypoint = customWaypoint;
19+
1120
setWaypointFill(Color.GREEN);
21+
22+
robotView.getView().getTransforms().add(centerTranslate);
23+
robotView.headingProperty().bind(this.customWaypoint.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+
customWaypoint.setHeading(angle * (-Math.PI/180));
43+
});
44+
45+
if (customWaypoint.isHeadingConstrained()) {
46+
showRobot();
47+
} else {
48+
hideRobot();
49+
}
50+
customWaypoint.headingConstrainedProperty().addListener((obsVal, wasConstr, isContr) -> {
51+
if (isContr) {
52+
showRobot();
53+
} else {
54+
hideRobot();
55+
}
56+
});
57+
}
58+
59+
public final DoubleProperty bumperLengthProperty() {
60+
return robotView.bumperLengthProperty();
61+
}
62+
63+
public final void setBumperLength(double value) {
64+
robotView.setBumperLength(value);
65+
}
66+
67+
public final double getBumperLength() {
68+
return robotView.getBumperLength();
69+
}
70+
71+
public final DoubleProperty bumperWidthProperty() {
72+
return robotView.bumperWidthProperty();
73+
}
74+
75+
public final void setBumperWidth(double value) {
76+
robotView.setBumperWidth(value);
77+
}
78+
79+
public final double getBumperWidth() {
80+
return robotView.getBumperWidth();
81+
}
82+
83+
public final DoubleProperty headingProperty() {
84+
return robotView.headingProperty();
85+
}
86+
87+
public final void setHeading(double value) {
88+
robotView.setHeading(value);
89+
}
90+
91+
public final double getHeading() {
92+
return robotView.getHeading();
93+
}
94+
95+
public RobotView getRobotView() {
96+
return robotView;
97+
}
98+
99+
private void hideRobot() {
100+
robotView.getView().setOpacity(0.0);
101+
robotView.getView().setMouseTransparent(true);
102+
}
103+
104+
private void showRobot() {
105+
robotView.getView().setOpacity(1.0);
106+
robotView.getView().setMouseTransparent(false);
12107
}
13108
}

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
@@ -116,6 +116,9 @@ private void updateWaypoints(List<? extends HWaypoint> list) {
116116
case CUSTOM:
117117
HCustomWaypoint customWaypoint = (HCustomWaypoint) waypoint;
118118
CustomWaypointView customWaypointView = new CustomWaypointView(customWaypoint);
119+
customWaypointView.bumperLengthProperty().bind(this.documentManager.getDocument().getRobotConfiguration().bumperLengthProperty());
120+
customWaypointView.bumperWidthProperty().bind(this.documentManager.getDocument().getRobotConfiguration().bumperWidthProperty());
121+
robotsPane.getChildren().add(customWaypointView.getRobotView().getView());
119122
waypointView = customWaypointView;
120123
break;
121124
case INITIAL_GUESS:

0 commit comments

Comments
 (0)