Commit 3d89ea7e authored by Ivan Dages's avatar Ivan Dages
Browse files

axis calibration

parent bba5253d
......@@ -11,6 +11,7 @@ import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.ConfigParams;
import fr.ill.ics.n3d.model.Axis.Type;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
......@@ -40,6 +41,7 @@ import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
......@@ -268,12 +270,139 @@ public class EditorMenuBar extends MenuBar {
});
MenuItem calibrateAxisItem = new MenuItem("Calibrate axis");
calibrateAxisItem.setOnAction(event -> {
// TODO calibration
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(calibrateAxisItem.getText());
alert.setHeaderText("Calibration");
alert.setContentText("TODO");
alert.showAndWait();
if (editor.model == null || editor.model.getRoot() == null) {
return;
}
HashSet<Component> selectRoots = Component.rootsOf(editor.model.getSelection());
if (selectRoots.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
Component modifiedComponent = null;
if(selectRoots.size() > 1) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Several components are selected, multiple axes cannot be calibrated at once.");
alert.showAndWait();
return;
} else {
modifiedComponent = selectRoots.iterator().next();
}
if (modifiedComponent == null) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Unable to get the selected axis.");
alert.showAndWait();
return;
}
final Axis selectedAxis = modifiedComponent.getAxis();
Logger.getLogger("nomad-3d").info("Calibrating axis of " + modifiedComponent.getName());
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene calibrateScene = new Scene(scenePane);
Stage calibrateStage = new Stage(StageStyle.UTILITY);
calibrateStage.setTitle(addAxisItem.getText());
calibrateStage.setScene(calibrateScene);
calibrateStage.initOwner(editor.stage);
GridPane valuePane = new GridPane();
valuePane.setVgap(5);
valuePane.setHgap(10);
valuePane.setAlignment(Pos.CENTER);
scenePane.addRow(0, valuePane);
GridPane.setMargin(valuePane, new Insets(5));
Label valueText = new Label("Current value : ");
valueText.setAlignment(Pos.CENTER_LEFT);
TextField valueField = new TextField(Double.toString(selectedAxis.getValue()));
valueField.setAlignment(Pos.CENTER_RIGHT);
valueField.setOnAction(valueEvent -> {
try {
selectedAxis.move(Double.parseDouble(valueField.getText()) - selectedAxis.getValue());
} catch (Exception e) {
// Invalid input, nothing to do
}
});
valuePane.addRow(0, valueText, valueField);
Thread valueThread = new Thread(new Runnable() {
@Override
public void run() {
try {
while (true) {
if (!valueField.isFocused()) {
Platform.runLater(() -> valueField.setText(Double.toString(selectedAxis.getValue())));
}
Thread.sleep(50);
}
} catch (InterruptedException e) {
// Nothing to do
}
}
});
GridPane calibratePane = new GridPane();
calibratePane.setVgap(5);
calibratePane.setHgap(10);
calibratePane.setAlignment(Pos.CENTER);
scenePane.addRow(1, calibratePane);
GridPane.setMargin(calibratePane, new Insets(5));
Button minButton = new Button("Set min value");
minButton.setPrefWidth(125);
minButton.setOnAction(minEvent -> {
selectedAxis.setMinValue(selectedAxis.getValue());
});
Button medianButton = new Button("Set median value");
medianButton.setPrefWidth(125);
medianButton.setOnAction(medianEvent -> {
selectedAxis.setMedianValue(selectedAxis.getValue());
});
Button maxButton = new Button("Set max value");
maxButton.setPrefWidth(125);
maxButton.setOnAction(maxEvent -> {
selectedAxis.setMaxValue(selectedAxis.getValue());
});
calibratePane.addRow(0, minButton, medianButton, maxButton);
GridPane buttonsPane = new GridPane();
buttonsPane.setVgap(5);
buttonsPane.setHgap(10);
buttonsPane.setAlignment(Pos.CENTER);
scenePane.addRow(2, buttonsPane);
GridPane.setMargin(buttonsPane, new Insets(10));
Button okButton = new Button("OK");
okButton.setOnAction(okEvent -> {
calibrateStage.close();
valueThread.interrupt();
});
Button resetButton = new Button("Reset");
final double minInit = selectedAxis.getMinValue();
final double medianInit = selectedAxis.getMedianValue();
final double maxInit = selectedAxis.getMaxValue();
final double valueInit = selectedAxis.getValue();
resetButton.setOnAction(resetEvent -> {
selectedAxis.setMinValue(minInit);
selectedAxis.setMedianValue(medianInit);
selectedAxis.setMaxValue(maxInit);
selectedAxis.move(valueInit - selectedAxis.getValue());
});
Button cancelButton = new Button("Cancel");
cancelButton.setOnAction(cancelEvent -> {
resetButton.getOnAction().handle(null);
okButton.getOnAction().handle(null);
});
buttonsPane.addRow(1, okButton, resetButton, cancelButton);
valueThread.start();
calibrateStage.show();
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem);
MenuItem modifyMaterialItem = new MenuItem("Modify material");
......
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