Commit 685f0bfd authored by legoc's avatar legoc
Browse files

Review of the reference axis and the way to use them

parent f164014f
......@@ -142,7 +142,7 @@ public class Nomad3DEditor extends Application {
e.printStackTrace();
}
Logger.getLogger("nomad-3d").info("Starting " + TITLE + "...");
// NomadLinker.getInstance().displayProperties();
model = null;
......
......@@ -19,6 +19,7 @@ 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.operations.Operations;
import fr.ill.ics.n3d.operations.OperationsSerializer;
import fr.ill.ics.n3d.utils.ReferenceAxisList;
......@@ -31,7 +32,6 @@ import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Point3D;
......@@ -206,20 +206,22 @@ public class EditorMenuBar extends MenuBar {
return;
}
// TODO This code has to be reviewed.
final Component selectedComponent = modifiedComponent;
Axis modifiedAxis = null;
if (selectedComponent != null) {
modifiedAxis = selectedComponent.getAxis();
}
boolean modified = (modifiedAxis != null);
if (modifiedAxis == null) {
// ?
modifiedAxis = new Axis();
modifiedAxis.setType(Axis.Type.ROTATION);
modifiedAxis.setDirection(new Point3D(0, 1, 0));
modifiedAxis.setPosition(Nomad3DEditor.getInstance().getControls().getCenter());
} else {
Nomad3DEditor.getInstance().getControls().setCenter(modifiedAxis.getPosition());
}
final Axis selectedAxis = modifiedAxis;
final Axis axisInit = selectedAxis.clone();
......@@ -257,125 +259,77 @@ public class EditorMenuBar extends MenuBar {
}
});
Label xDirField = new Label("0.0");
Label yDirField = new Label("0.0");
Label zDirField = new Label("0.0");
Label xPosField = new Label("0.0");
Label yPosField = new Label("0.0");
Label zPosField = new Label("0.0");
Label referenceLabel = new Label("Reference : ");
ObservableList<String> references = FXCollections.observableArrayList(ReferenceAxisList.getInstance().getNames());
ComboBox<String> referenceBox = new ComboBox<>(references);
if (selectedAxis.getReferenceAxis() != null) {
// Get the reference axis.
ReferenceAxis referenceAxis = selectedAxis.getReferenceAxis();
// Select the reference axis.
referenceBox.getSelectionModel().select(referenceAxis.getName());
// Set the fields.
xDirField.setText(String.format("%.3f", referenceAxis.getDirection().getX()));
yDirField.setText(String.format("%.3f", referenceAxis.getDirection().getY()));
zDirField.setText(String.format("%.3f", referenceAxis.getDirection().getZ()));
xPosField.setText(String.format("%.3f", referenceAxis.getPosition().getX()));
yPosField.setText(String.format("%.3f", referenceAxis.getPosition().getY()));
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) {
// Get the reference axis.
ReferenceAxis referenceAxis = ReferenceAxisList.getInstance().getAxis(newValue);
// Set the fields.
xDirField.setText(String.format("%.3f", referenceAxis.getDirection().getX()));
yDirField.setText(String.format("%.3f", referenceAxis.getDirection().getY()));
zDirField.setText(String.format("%.3f", referenceAxis.getDirection().getZ()));
xPosField.setText(String.format("%.3f", referenceAxis.getPosition().getX()));
yPosField.setText(String.format("%.3f", referenceAxis.getPosition().getY()));
zPosField.setText(String.format("%.3f", referenceAxis.getPosition().getZ()));
// Set the selected axis with the reference.
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setReferenceAxis(referenceAxis);
}
});
Label dirLabel = new Label("Direction : ");
Label xDirLabel = new Label("X : ");
Label yDirLabel = new Label("Y : ");
Label zDirLabel = new Label("Z : ");
TextField xDirField = new TextField(Double.toString(selectedAxis.getDirection().getX()));
xDirField.setOnAction(valueEvent -> {
try {
Point3D newDir = new Point3D(Double.parseDouble(xDirField.getText()), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getY(), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getZ());
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setDirection(newDir);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
TextField yDirField = new TextField(Double.toString(selectedAxis.getDirection().getY()));
yDirField.setOnAction(valueEvent -> {
try {
Point3D newDir = new Point3D(Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getX(), Double.parseDouble(yDirField.getText()), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getZ());
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setDirection(newDir);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
TextField zDirField = new TextField(Double.toString(selectedAxis.getDirection().getZ()));
zDirField.setOnAction(valueEvent -> {
try {
Point3D newDir = new Point3D(Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getX(), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getDirection().getY(), Double.parseDouble(zDirField.getText()));
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setDirection(newDir);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
Label posLabel = new Label("Position : ");
Label xPosLabel = new Label("X : ");
Label yPosLabel = new Label("Y : ");
Label zPosLabel = new Label("Z : ");
TextField xPosField = new TextField(Double.toString(selectedAxis.getPosition().getX()));
xPosField.setOnAction(valueEvent -> {
try {
Point3D newPos = new Point3D(Double.parseDouble(xPosField.getText()), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getY(), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getZ());
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setPosition(newPos);
Nomad3DEditor.getInstance().getControls().setCenter(newPos);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
TextField yPosField = new TextField(Double.toString(selectedAxis.getPosition().getY()));
yPosField.setOnAction(valueEvent -> {
try {
Point3D newPos = new Point3D(Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getX(), Double.parseDouble(yPosField.getText()), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getZ());
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setPosition(newPos);
Nomad3DEditor.getInstance().getControls().setCenter(newPos);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
TextField zPosField = new TextField(Double.toString(selectedAxis.getPosition().getZ()));
zPosField.setOnAction(valueEvent -> {
try {
Point3D newPos = new Point3D(Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getX(), Nomad3DEditor.getInstance().getAxisBuilder().getAxis().getPosition().getY(), Double.parseDouble(zPosField.getText()));
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setPosition(newPos);
Nomad3DEditor.getInstance().getControls().setCenter(newPos);
} catch (Exception e) {
// Invalid input, nothing to do
}
});
Thread updateThread = new Thread(new Runnable() {
@Override
public void run() {
try {
while (true) {
boolean someFieldFocused = false;
someFieldFocused = someFieldFocused || xDirField.isFocused();
someFieldFocused = someFieldFocused || yDirField.isFocused();
someFieldFocused = someFieldFocused || zDirField.isFocused();
someFieldFocused = someFieldFocused || xPosField.isFocused();
someFieldFocused = someFieldFocused || yPosField.isFocused();
someFieldFocused = someFieldFocused || zPosField.isFocused();
if (!someFieldFocused) {
Platform.runLater(() -> xDirField.setText(Double.toString(selectedAxis.getDirection().getX())));
Platform.runLater(() -> yDirField.setText(Double.toString(selectedAxis.getDirection().getY())));
Platform.runLater(() -> zDirField.setText(Double.toString(selectedAxis.getDirection().getZ())));
Platform.runLater(() -> xPosField.setText(Double.toString(selectedAxis.getPosition().getX())));
Platform.runLater(() -> yPosField.setText(Double.toString(selectedAxis.getPosition().getY())));
Platform.runLater(() -> zPosField.setText(Double.toString(selectedAxis.getPosition().getZ())));
}
Thread.sleep(50);
}
} catch (InterruptedException e) {
// Nothing to do
}
}
});
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());
});
Button centerButton = new Button("Center axis");
centerButton.setOnAction(centerEvent -> {
Bounds bounds = selectedComponent.getSceneNode().localToScene(selectedComponent.getSceneNode().getBoundsInLocal());
Point3D center = new Point3D((bounds.getMinX() + bounds.getMaxX()) / 2, (bounds.getMinY() + bounds.getMaxY()) / 2, (bounds.getMinZ() + bounds.getMaxZ()) / 2);
Nomad3DEditor.getInstance().getAxisBuilder().getAxis().setPosition(center);
Nomad3DEditor.getInstance().getControls().setCenter(center);
});
Button okButton = new Button("OK");
// okButton.setDefaultButton(true);
okButton.setOnAction(okEvent -> {
updateThread.interrupt();
// Normalize here the direction, because the norm has an impact on the
// translation.
selectedAxis.setDirection(selectedAxis.getDirection().normalize());
......@@ -389,7 +343,6 @@ public class EditorMenuBar extends MenuBar {
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(cancelEvent -> {
updateThread.interrupt();
Nomad3DEditor.getInstance().getAxisBuilder().stop(modified);
selectedComponent.setAxis(axisInit);
Nomad3DEditor.getInstance().getModel().clearSelection();
......@@ -408,6 +361,7 @@ public class EditorMenuBar extends MenuBar {
addPane.addRow(0, typePane);
GridPane vectorsPane = new GridPane();
vectorsPane.setPrefWidth(500);
vectorsPane.setHgap(10);
vectorsPane.setVgap(5);
vectorsPane.setAlignment(Pos.TOP_LEFT);
......@@ -419,7 +373,7 @@ public class EditorMenuBar extends MenuBar {
conveniencePane.setHgap(10);
conveniencePane.setVgap(5);
conveniencePane.setAlignment(Pos.CENTER);
conveniencePane.addRow(0, reverseButton, centerButton);
conveniencePane.addRow(0, reverseButton);
addPane.addRow(2, conveniencePane);
GridPane.setMargin(conveniencePane, new Insets(10));
......@@ -430,7 +384,6 @@ public class EditorMenuBar extends MenuBar {
addPane.addRow(3, buttonPane);
Nomad3DEditor.getInstance().getAxisBuilder().start(selectedAxis, Nomad3DEditor.getInstance().getRoot(), Nomad3DEditor.getInstance().getControls(), modified);
updateThread.start();
addStage.setOnCloseRequest(closeEvent -> {
cancelButton.getOnAction().handle(null);
});
......
......@@ -41,7 +41,21 @@ public class ReferenceAxisList {
* @return The list of reference axes.
*/
public ArrayList<ReferenceAxis> get() {
return list;
return list;
}
/**
* Gets the reference axis with name.
* @return The reference axis.
*/
public ReferenceAxis getAxis(String name) {
for (ReferenceAxis axis : list) {
if (name.equals(axis.getName())) {
return axis;
}
}
return null;
}
/**
......
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