1
1
package org .team2363 .helixnavigator .ui .editor .waypoint ;
2
2
3
3
import org .team2363 .helixnavigator .document .timeline .HCustomWaypoint ;
4
+ import org .team2363 .helixnavigator .global .Standards ;
4
5
6
+ import javafx .beans .property .DoubleProperty ;
5
7
import javafx .scene .paint .Color ;
6
8
7
9
public class CustomWaypointView extends WaypointView {
10
+
11
+ private final RobotView robotView = new RobotView ();
12
+
13
+ private final HCustomWaypoint customWaypoint ;
8
14
9
15
public CustomWaypointView (HCustomWaypoint customWaypoint ) {
10
16
super (customWaypoint );
17
+
18
+ this .customWaypoint = customWaypoint ;
19
+
11
20
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 );
12
107
}
13
108
}
0 commit comments