Commit 10f55af3 authored by legoc's avatar legoc
Browse files

Continuing with the review of the axis definition

parent f74d19df
......@@ -13,6 +13,7 @@ import fr.ill.ics.n3d.io.Nomad3DImporter;
import fr.ill.ics.n3d.link.NomadLinker;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.Model;
import fr.ill.ics.n3d.model.ReferenceAxisList;
import fr.ill.ics.n3d.operations.OperationsSerializer;
import javafx.application.Application;
import javafx.application.Platform;
......@@ -306,12 +307,15 @@ public class Nomad3DEditor extends Application {
} else {
n3dImporter.read();
}
//n3dImporter.readEdition();
if (n3dImporter.getModel().getRoot() != null) {
model = n3dImporter.getModel();
// Reset the list of reference axes.
ReferenceAxisList.getInstance().init(model);
// Read the operations.
OperationsSerializer serializer = new OperationsSerializer();
serializer.read(model);
......
......@@ -16,13 +16,14 @@ import fr.ill.ics.n3d.io.Nomad3DImporter;
import fr.ill.ics.n3d.link.Nomad3DController;
import fr.ill.ics.n3d.link.NomadLinker;
import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Axis.Type;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.ConfigParams;
import fr.ill.ics.n3d.model.ReferenceAxis;
import fr.ill.ics.n3d.model.ReferenceAxisList;
import fr.ill.ics.n3d.operations.Operations;
import fr.ill.ics.n3d.operations.OperationsSerializer;
import fr.ill.ics.n3d.operations.SetAxisOperation;
import fr.ill.ics.n3d.operations.SetMaterialOperation;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
......@@ -148,9 +149,6 @@ public class EditorMenuBar extends MenuBar {
Nomad3DEditor.getInstance().getStage().setScene(scene);
Nomad3DEditor.getInstance().getStage().setTitle(Nomad3DEditor.getInstance().getModel().getName() + " - " + Nomad3DEditor.TITLE);
update();
// Reset the list of reference axes.
ReferenceAxisList.getInstance().init(Nomad3DEditor.getInstance().getModel());
}
}
});
......@@ -177,6 +175,8 @@ public class EditorMenuBar extends MenuBar {
Operations.getInstance().undoLastOperation(Nomad3DEditor.getInstance().getModel());
});
///////////////////////////////////////////////////////////////////////////////////////
// Axis menu
Menu axisMenu = new Menu("Axis");
MenuItem addAxisItem = new MenuItem("Define axis");
addAxisItem.setOnAction(event -> {
......@@ -229,13 +229,11 @@ public class EditorMenuBar extends MenuBar {
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene addScene = new Scene(scenePane);
// ClassLoader classLoader = getClass().getClassLoader();
// addScene.getStylesheets().add(classLoader.getResource("Style.css").toExternalForm());
Stage addStage = new Stage(StageStyle.UTILITY);
addStage.setTitle(addAxisItem.getText());
addStage.setScene(addScene);
......@@ -248,13 +246,15 @@ public class EditorMenuBar extends MenuBar {
scenePane.addRow(0, addPane);
GridPane.setMargin(addPane, new Insets(10));
///////////////////////////////////////////////////////////////////////////////////////
// Type
Label typeLabel = new Label("Type : ");
ObservableList<Axis.Type> types = FXCollections.observableArrayList(Axis.Type.FIXED, Axis.Type.TRANSLATION, Axis.Type.ROTATION, Axis.Type.NONE);
ComboBox<Axis.Type> typeBox = new ComboBox<>(types);
typeBox.getSelectionModel().select(selectedAxis.getType());
typeBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Axis.Type>() {
@Override
public void changed(ObservableValue<? extends Type> observable, Type oldValue, Type newValue) {
public void changed(ObservableValue<? extends Axis.Type> observable, Axis.Type oldValue, Axis.Type newValue) {
Nomad3DEditor.getInstance().getAxisBuilder().setType(newValue);
}
});
......@@ -267,6 +267,31 @@ public class EditorMenuBar extends MenuBar {
Label yPosField = new Label("0.0");
Label zPosField = new Label("0.0");
///////////////////////////////////////////////////////////////////////////////////////
// Rotation direction
Label rotationDirectionLabel = new Label("Rotation Direction : ");
ObservableList<Axis.RotationDirection> rotationDirections = FXCollections.observableArrayList(Axis.RotationDirection.CW, Axis.RotationDirection.CCW);
ComboBox<Axis.RotationDirection> rotationDirectionBox = new ComboBox<>(rotationDirections);
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) {
// Set the rotation direction.
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setRotationDirection(newValue);
// Get the axis.
Axis axis = Nomad3DEditor.getInstance().getAxisBuilder().getAxis();
// Set the direction fields.
xDirField.setText(String.format("%.3f", axis.getDirection().getX()));
yDirField.setText(String.format("%.3f", axis.getDirection().getY()));
zDirField.setText(String.format("%.3f", axis.getDirection().getZ()));
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference
Label referenceLabel = new Label("Reference : ");
ObservableList<String> references = FXCollections.observableArrayList(ReferenceAxisList.getInstance().getNames());
......@@ -289,6 +314,7 @@ public class EditorMenuBar extends MenuBar {
zPosField.setText(String.format("%.3f", referenceAxis.getPosition().getZ()));
}
referenceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
......@@ -307,10 +333,15 @@ public class EditorMenuBar extends MenuBar {
// Set the selected axis with the reference.
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setReferenceAxis(referenceAxis);
// Reset the rotation direction.
rotationDirectionBox.setValue(Axis.RotationDirection.CW);
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setRotationDirection(Axis.RotationDirection.CW);
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Direction and position
Label dirLabel = new Label("Direction : ");
Label xDirLabel = new Label("X : ");
Label yDirLabel = new Label("Y : ");
......@@ -321,20 +352,46 @@ public class EditorMenuBar extends MenuBar {
Label yPosLabel = new Label("Y : ");
Label zPosLabel = new Label("Z : ");
Button reverseButton = new Button("Reverse axis");
reverseButton.setOnAction(reverseEvent -> {
Point3D newDir = new Point3D(-Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getX(), -Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getY(), -Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getZ());
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setDirection(newDir.normalize());
});
///////////////////////////////////////////////////////////////////////////////////////
// OK and Cancel
Button okButton = new Button("OK");
// okButton.setDefaultButton(true);
okButton.setOnAction(okEvent -> {
// Normalize here the direction, because the norm has an impact on the
// translation.
selectedAxis.setDirection(selectedAxis.getDirection().normalize());
// Stop the build.
Nomad3DEditor.getInstance().getAxisBuilder().stop(selectedComponent);
String zeroValueReferenceAxis1Name = null;
String zeroValueReferenceAxis2Name = null;
String controllerName = null;
if (selectedAxis.getZeroValueReferenceAxis1() != null) {
zeroValueReferenceAxis1Name = selectedAxis.getZeroValueReferenceAxis1().getName();
}
if (selectedAxis.getZeroValueReferenceAxis2() != null) {
zeroValueReferenceAxis2Name = selectedAxis.getZeroValueReferenceAxis2().getName();
}
if (selectedAxis.getController() != null) {
controllerName = selectedAxis.getController().getName();
}
// Save the operation.
Operations.getInstance().addOperation(new SetAxisOperation(
selectedComponent.getName(),
selectedAxis.getType(),
selectedAxis.getReferenceAxis().getName(),
selectedAxis.getRotationDirection(),
selectedAxis.getMinValue(),
selectedAxis.getMaxValue(),
zeroValueReferenceAxis1Name,
zeroValueReferenceAxis2Name,
selectedAxis.getZeroValue(),
controllerName));
Nomad3DEditor.getInstance().getModel().clearSelection();
updateScene();
Nomad3DEditor.getInstance().getModel().addToSelection(selectedComponent);
......@@ -357,6 +414,7 @@ public class EditorMenuBar extends MenuBar {
typePane.setAlignment(Pos.TOP_LEFT);
typePane.addRow(0, typeLabel, typeBox);
typePane.addRow(1, referenceLabel, referenceBox);
typePane.addRow(2, rotationDirectionLabel, rotationDirectionBox);
GridPane.setColumnSpan(typeBox, GridPane.REMAINING);
addPane.addRow(0, typePane);
......@@ -369,13 +427,13 @@ public class EditorMenuBar extends MenuBar {
vectorsPane.addRow(1, posLabel, xPosLabel, xPosField, yPosLabel, yPosField, zPosLabel, zPosField);
addPane.addRow(1, vectorsPane);
GridPane conveniencePane = new GridPane();
conveniencePane.setHgap(10);
conveniencePane.setVgap(5);
conveniencePane.setAlignment(Pos.CENTER);
conveniencePane.addRow(0, reverseButton);
addPane.addRow(2, conveniencePane);
GridPane.setMargin(conveniencePane, new Insets(10));
// GridPane conveniencePane = new GridPane();
// conveniencePane.setHgap(10);
// conveniencePane.setVgap(5);
// conveniencePane.setAlignment(Pos.CENTER);
// conveniencePane.addRow(0, rotationDirectionLabel, rotationDirectionBox);
// addPane.addRow(2, conveniencePane);
// GridPane.setMargin(conveniencePane, new Insets(10));
GridPane buttonPane = new GridPane();
buttonPane.setHgap(10);
......@@ -736,7 +794,7 @@ public class EditorMenuBar extends MenuBar {
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem, linkAxisItem, unlinkAxisItem, displayAxisItem);
MenuItem modifyMaterialItem = new MenuItem("Modify material");
MenuItem modifyMaterialItem = new MenuItem("Edit material");
modifyMaterialItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -785,7 +843,7 @@ public class EditorMenuBar extends MenuBar {
scenePane.addRow(1, buttonsPane);
GridPane.setMargin(buttonsPane, new Insets(10));
Button modifyButton = new Button("Modify");
Button modifyButton = new Button("Set");
modifyButton.setDefaultButton(true);
buttonsPane.addColumn(0, modifyButton);
modifyButton.setOnAction(new EventHandler<ActionEvent>() {
......@@ -803,7 +861,7 @@ public class EditorMenuBar extends MenuBar {
selectedComp.setMaterial(newMaterial, false);
// Save the operation.
Operations.getInstance().addMaterialOperation(newMaterial, selectedComp.getName());
Operations.getInstance().addOperation(new SetMaterialOperation(newMaterial, selectedComp.getName()));
}
Nomad3DEditor.getInstance().getModel().clearSelection();
......
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