Commit 251204bb authored by legoc's avatar legoc
Browse files

Changing status of reference axes

parent c4aab8a7
......@@ -108,7 +108,7 @@ public class EditorMenuBar extends MenuBar {
/** Currently displayed configuration. */
private String activeConfiguration;
private int activeLod;
private class SubdividedChild {
......@@ -296,31 +296,31 @@ public class EditorMenuBar extends MenuBar {
});
///////////////////////////////////////////////////////////////////////////////////////
// Rotation direction
ObservableList<Axis.RotationDirection> rotationDirections = FXCollections.observableArrayList(Axis.RotationDirection.CCW, Axis.RotationDirection.CW);
ComboBox<Axis.RotationDirection> rotationDirectionBox = new ComboBox<>(rotationDirections);
rotationDirectionBox.setVisible(selectedAxis.getType() == Axis.Type.ROTATION);
rotationDirectionBox.getSelectionModel().select(selectedAxis.getRotationDirection());
rotationDirectionBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Axis.RotationDirection>() {
@Override
public void changed(ObservableValue<? extends Axis.RotationDirection> observable, Axis.RotationDirection oldValue, Axis.RotationDirection newValue) {
// Reset the movement.
selectedAxis.resetMovement();
// Set the rotation direction.
selectedAxis.setRotationDirection(newValue);
// Set the direction fields.
xDirField.setText(String.format("%.3f", selectedAxis.getDirection().getX()));
yDirField.setText(String.format("%.3f", selectedAxis.getDirection().getY()));
zDirField.setText(String.format("%.3f", selectedAxis.getDirection().getZ()));
// Zero value
Label zeroValueText = new Label("Zero Value : ");
zeroValueText.setAlignment(Pos.CENTER_LEFT);
Label zeroValueField = new Label(String.format("%.3f", selectedAxis.getZeroValue()));
zeroValueField.setAlignment(Pos.CENTER_RIGHT);
Button setZeroButton = new Button("Set Zero");
setZeroButton.setOnAction(medianEvent -> {
selectedAxis.setZeroValue(selectedAxis.getValue());
zeroValueField.setText(String.format("%.3f", selectedAxis.getZeroValue()));
});
Button moveToZeroButton = new Button("Move To Zero");
moveToZeroButton.setOnAction(medianEvent -> {
try {
selectedAxis.move(selectedAxis.getZeroValue() - selectedAxis.getValue());
} catch (Exception e) {
// Invalid input, nothing to do
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference for first zero value
Label zeroValueReference1Label = new Label("Zero Value Reference 1 : ");
Label zeroValueReference1Label = new Label("Zero Value A : ");
Label zeroValueReference1StatusLabel = new Label("");
ComboBox<String> zeroValueReference1Box = new ComboBox<>(references);
zeroValueReference1Label.setVisible(selectedAxis.getType() == Axis.Type.ROTATION || selectedAxis.getType() == Axis.Type.TRANSLATION);
zeroValueReference1Box.setVisible(selectedAxis.getType() == Axis.Type.ROTATION || selectedAxis.getType() == Axis.Type.TRANSLATION);
......@@ -339,12 +339,22 @@ public class EditorMenuBar extends MenuBar {
// Set the selected axis with the reference.
selectedAxis.setZeroValueReferenceAxis1(referenceAxis);
// Set the status.
zeroValueReference1StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis1Status()));
// Calculate the zero value if possible.
calculateZeroValueFromReferences(selectedAxis);
// Refresh the zero value.
zeroValueField.setText(String.format("%.3f", selectedAxis.getZeroValue()));
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference for second zero value
Label zeroValueReference2Label = new Label("Zero Value Reference 2 : ");
Label zeroValueReference2Label = new Label("Zero Value B : ");
Label zeroValueReference2StatusLabel = new Label("");
ComboBox<String> zeroValueReference2Box = new ComboBox<>(references);
zeroValueReference2Label.setVisible(selectedAxis.getType() == Axis.Type.ROTATION);
zeroValueReference2Box.setVisible(selectedAxis.getType() == Axis.Type.ROTATION);
......@@ -363,9 +373,47 @@ public class EditorMenuBar extends MenuBar {
// Set the selected axis with the reference.
selectedAxis.setZeroValueReferenceAxis2(referenceAxis);
// Set the status.
zeroValueReference2StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis2Status()));
// Calculate the zero value if possible.
calculateZeroValueFromReferences(selectedAxis);
// Refresh the zero value.
zeroValueField.setText(String.format("%.3f", selectedAxis.getZeroValue()));
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Rotation direction
ObservableList<Axis.RotationDirection> rotationDirections = FXCollections.observableArrayList(Axis.RotationDirection.CCW, Axis.RotationDirection.CW);
ComboBox<Axis.RotationDirection> rotationDirectionBox = new ComboBox<>(rotationDirections);
rotationDirectionBox.setVisible(selectedAxis.getType() == Axis.Type.ROTATION);
rotationDirectionBox.getSelectionModel().select(selectedAxis.getRotationDirection());
rotationDirectionBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Axis.RotationDirection>() {
@Override
public void changed(ObservableValue<? extends Axis.RotationDirection> observable, Axis.RotationDirection oldValue, Axis.RotationDirection newValue) {
// Reset the movement.
selectedAxis.resetMovement();
// Set the rotation direction.
selectedAxis.setRotationDirection(newValue);
// Set the status.
zeroValueReference1StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis1Status()));
zeroValueReference2StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis2Status()));
// Calculate the zero value if possible.
calculateZeroValueFromReferences(selectedAxis);
// Set the direction fields.
xDirField.setText(String.format("%.3f", selectedAxis.getDirection().getX()));
yDirField.setText(String.format("%.3f", selectedAxis.getDirection().getY()));
zDirField.setText(String.format("%.3f", selectedAxis.getDirection().getZ()));
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Type
......@@ -395,7 +443,7 @@ public class EditorMenuBar extends MenuBar {
///////////////////////////////////////////////////////////////////////////////////////
// Reference
Label referenceLabel = new Label("Reference : ");
Label referenceLabel = new Label("Axis : ");
ComboBox<String> referenceBox = new ComboBox<>(references);
if (selectedAxis.getReferenceAxis() != null) {
......@@ -448,7 +496,15 @@ public class EditorMenuBar extends MenuBar {
// Reset the rotation direction.
rotationDirectionBox.setValue(Axis.RotationDirection.CCW);
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setRotationDirection(Axis.RotationDirection.CCW);
selectedAxis.setRotationDirection(Axis.RotationDirection.CCW);
// Set the status.
zeroValueReference1StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis1Status()));
zeroValueReference2StatusLabel.setText(convertStatus(selectedAxis.calculateZeroValueReferenceAxis2Status()));
// Calculate the zero value if possible.
calculateZeroValueFromReferences(selectedAxis);
}
});
......@@ -465,7 +521,7 @@ public class EditorMenuBar extends MenuBar {
Label zPosLabel = new Label("Z : ");
///////////////////////////////////////////////////////////////////////////////////////
// Current and zero value
// Current value
Label unitLabel = new Label();
Label zeroUnitLabel = new Label();
switch (selectedAxis.getType()) {
......@@ -511,28 +567,6 @@ public class EditorMenuBar extends MenuBar {
valueThread.start();
Label zeroValueText = new Label("Zero Value : ");
zeroValueText.setAlignment(Pos.CENTER_LEFT);
Label zeroValueField = new Label(String.format("%.3f", selectedAxis.getZeroValue()));
zeroValueField.setAlignment(Pos.CENTER_RIGHT);
Button setZeroButton = new Button("Set Zero");
setZeroButton.setOnAction(medianEvent -> {
selectedAxis.setZeroValue(selectedAxis.getValue());
zeroValueField.setText(String.format("%.3f", selectedAxis.getZeroValue()));
});
Button moveToZeroButton = new Button("Move To Zero");
moveToZeroButton.setOnAction(medianEvent -> {
try {
selectedAxis.move(selectedAxis.getZeroValue() - selectedAxis.getValue());
} catch (Exception e) {
// Invalid input, nothing to do
}
});
///////////////////////////////////////////////////////////////////////////////////////
// OK and Cancel
Button okButton = new Button("OK");
......@@ -631,8 +665,8 @@ public class EditorMenuBar extends MenuBar {
calibrationPane.setAlignment(Pos.TOP_LEFT);
calibrationPane.addRow(0, valueText, valueField, unitLabel, setZeroButton);
calibrationPane.addRow(1, zeroValueText, zeroValueField, zeroUnitLabel, moveToZeroButton);
calibrationPane.addRow(2, zeroValueReference1Label, zeroValueReference1Box);
calibrationPane.addRow(3, zeroValueReference2Label, zeroValueReference2Box);
calibrationPane.addRow(2, zeroValueReference1Label, zeroValueReference1Box, zeroValueReference1StatusLabel);
calibrationPane.addRow(3, zeroValueReference2Label, zeroValueReference2Box, zeroValueReference2StatusLabel);
addPane.addRow(2, calibrationPane);
......@@ -1604,13 +1638,54 @@ public class EditorMenuBar extends MenuBar {
this.getMenus().addAll(this.file, this.edit, this.view, this.selection, this.help);
}
/**
* Convert the axis status into text.
* @param status The status.
* @return The string result.
*/
private String convertStatus(Axis.Status status) {
if (status == Axis.Status.UNDEFINED) {
return "";
}
else if (status == Axis.Status.OK) {
return "OK";
}
else {
return "!OK";
}
}
/**
* 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) {
System.out.println("Calculating new zero value for rotation");
selectedAxis.setZeroValue(reference1.getDirection().angle(reference2.getDirection()));
}
else if (selectedAxis.getType() == Axis.Type.TRANSLATION && reference1 != null) {
System.out.println("Calculating new zero value for translation");
}
else {
// Reset the zero value.
selectedAxis.setZeroValue(0.0);
}
}
/**
* Selects the root component of the selection.
*
* @param title
* Title of the warning/error alerts in case of errors
* @return The root of the selection if there is one, null otherwise
* @param title Title of the warning/error alerts in case of errors.
* @return The root of the selection if there is one, null otherwise.
*/
private Component selectComponent(String title) {
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment