Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Protos
Nomad 3D
nomad-3d-editor
Commits
1fb12b14
Commit
1fb12b14
authored
Feb 12, 2019
by
legoc
Browse files
The zero value can be set manually or by reference axes
parent
450e9058
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/n3d/gui/EditorMenuBar.java
View file @
1fb12b14
...
...
@@ -352,9 +352,9 @@ public class EditorMenuBar extends MenuBar {
Label
zeroValueField
=
new
Label
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
zeroValueField
.
setAlignment
(
Pos
.
CENTER_RIGHT
);
Button
setZeroButton
=
new
Button
(
"Set Zero"
);
Button
setZeroButton
=
new
Button
(
"Set Zero
From Current
"
);
setZeroButton
.
setOnAction
(
medianEvent
->
{
selectedAxis
.
setZeroValue
(
selectedAxis
.
getValue
());
selectedAxis
.
setZeroValue
(
selectedAxis
.
getValue
()
,
false
);
zeroValueField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
});
...
...
@@ -408,7 +408,7 @@ public class EditorMenuBar extends MenuBar {
selectedAxis
.
setZeroValueReferenceAxis1Reversed
(
newValue
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
// Refresh the zero value.
zeroValueField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
...
...
@@ -439,7 +439,7 @@ public class EditorMenuBar extends MenuBar {
zeroValueReference1Label
.
setTextFill
(
selectedAxis
.
calculateZeroValueReferenceAxis1Status
()
==
Axis
.
Status
.
NOK
?
Color
.
RED
:
Color
.
BLACK
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
// Refresh the zero value.
zeroValueField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
...
...
@@ -460,7 +460,7 @@ public class EditorMenuBar extends MenuBar {
selectedAxis
.
setZeroValueReferenceAxis2Reversed
(
newValue
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
// Refresh the zero value.
zeroValueField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
...
...
@@ -491,7 +491,7 @@ public class EditorMenuBar extends MenuBar {
zeroValueReference2Label
.
setTextFill
(
selectedAxis
.
calculateZeroValueReferenceAxis2Status
()
==
Axis
.
Status
.
NOK
?
Color
.
RED
:
Color
.
BLACK
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
// Refresh the zero value.
zeroValueField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getZeroValue
()));
...
...
@@ -519,7 +519,7 @@ public class EditorMenuBar extends MenuBar {
zeroValueReference2Label
.
setTextFill
(
selectedAxis
.
calculateZeroValueReferenceAxis2Status
()
==
Axis
.
Status
.
NOK
?
Color
.
RED
:
Color
.
BLACK
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
// Set the direction fields.
xDirField
.
setText
(
String
.
format
(
"%.3f"
,
selectedAxis
.
getDirection
().
getX
()));
...
...
@@ -682,8 +682,7 @@ public class EditorMenuBar extends MenuBar {
zeroValueReference2Label
.
setTextFill
(
selectedAxis
.
calculateZeroValueReferenceAxis2Status
()
==
Axis
.
Status
.
NOK
?
Color
.
RED
:
Color
.
BLACK
);
// Calculate the zero value if possible.
calculateZeroValueFromReferences
(
selectedAxis
);
selectedAxis
.
calculateZeroValueFromReferences
();
}
});
...
...
@@ -761,6 +760,13 @@ public class EditorMenuBar extends MenuBar {
controllerName
=
selectedAxis
.
getController
().
getName
();
}
// Special case for the zero value.
// Set it to null if it is calculated.
Double
zeroValue
=
null
;
if
(!
selectedAxis
.
isZeroValueFromReferenceAxes
())
{
zeroValue
=
selectedAxis
.
getZeroValue
();
}
// Save the operation.
Operations
.
getInstance
().
addOperation
(
new
SetAxisOperation
(
selectedComponent
.
getName
(),
...
...
@@ -771,7 +777,7 @@ public class EditorMenuBar extends MenuBar {
reversedDirection1Check
.
isSelected
(),
zeroValueReferenceAxis2Name
,
reversedDirection2Check
.
isSelected
(),
selectedAxis
.
getZ
eroValue
()
,
z
eroValue
,
controllerName
));
// Change the title.
...
...
@@ -2152,72 +2158,6 @@ public class EditorMenuBar extends MenuBar {
return
modified
;
}
/**
* Calculates the zero value of an axis from its reference axes.
* @param selectedAxis The axis to calculate the zero value.
*/
private
void
calculateZeroValueFromReferences
(
Axis
selectedAxis
)
{
ReferenceAxis
reference1
=
selectedAxis
.
getZeroValueReferenceAxis1
();
ReferenceAxis
reference2
=
selectedAxis
.
getZeroValueReferenceAxis2
();
if
(
selectedAxis
.
getType
()
==
Axis
.
Type
.
ROTATION
&&
reference1
!=
null
&&
reference2
!=
null
)
{
// Get the vector A.
Point3D
A
=
reference1
.
getDirection
();
if
(
selectedAxis
.
isZeroValueReferenceAxis1Reversed
())
{
A
=
A
.
multiply
(-
1.0
);
}
// Get the vector B.
Point3D
B
=
reference2
.
getDirection
();
if
(
selectedAxis
.
isZeroValueReferenceAxis2Reversed
())
{
B
=
B
.
multiply
(-
1.0
);
}
// Get the vector C.
Point3D
C
=
selectedAxis
.
getDirection
();
// Check the relative position of A and B.
Point3D
AB
=
A
.
crossProduct
(
B
);
// Calculate the angle.
double
angle
=
A
.
angle
(
B
);
// Revert if needed.
if
(
AB
.
dotProduct
(
C
)
<
0
)
{
angle
*=
-
1.0
;
}
// Set the zero value.
selectedAxis
.
setZeroValue
(
angle
);
}
else
if
(
selectedAxis
.
getType
()
==
Axis
.
Type
.
TRANSLATION
&&
reference1
!=
null
)
{
// Get the vector A.
Point3D
A
=
reference1
.
getDirection
();
// Get the vector C.
Point3D
C
=
selectedAxis
.
getDirection
();
// Calculate the length of the projection of A onto C.
double
translation
=
A
.
dotProduct
(
C
)
/
C
.
magnitude
();
if
(
selectedAxis
.
isZeroValueReferenceAxis1Reversed
())
{
translation
*=
-
1.0
;
}
// Set the zero value.
selectedAxis
.
setZeroValue
(
translation
);
}
else
{
// Reset the zero value.
selectedAxis
.
setZeroValue
(
0.0
);
}
}
/**
* Returns the text for the current value label.
* @param type The input type.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment