Commit b403dec0 authored by legoc's avatar legoc
Browse files

Implemented New and Remove Reference Axis

parent cc97175a
......@@ -27,9 +27,11 @@ import fr.ill.ics.n3d.model.ReferenceAxis;
import fr.ill.ics.n3d.model.ReferenceAxisList;
import fr.ill.ics.n3d.operations.MoveComponentsOperation;
import fr.ill.ics.n3d.operations.NewComponentOperation;
import fr.ill.ics.n3d.operations.NewReferenceAxisOperation;
import fr.ill.ics.n3d.operations.Operations;
import fr.ill.ics.n3d.operations.OperationsSerializer;
import fr.ill.ics.n3d.operations.RemoveComponentOperation;
import fr.ill.ics.n3d.operations.RemoveReferenceAxisOperation;
import fr.ill.ics.n3d.operations.RenameComponentOperation;
import fr.ill.ics.n3d.operations.SetAxisOperation;
import fr.ill.ics.n3d.operations.SetMaterialOperation;
......@@ -915,7 +917,7 @@ public class EditorMenuBar extends MenuBar {
final ObservableList<AxisTableEntry> data = FXCollections.observableArrayList();
List<AxisInfo> axisInfos = Nomad3DEditor.getInstance().getModel().getAxisInfo();
List<AxisInfo> axisInfos = Nomad3DEditor.getInstance().getModel().getAxisInfos();
for (AxisInfo info : axisInfos) {
data.add(new AxisTableEntry(info.getAxisName(), info.getComponentName(), info.getType().toString()));
}
......@@ -1476,6 +1478,24 @@ public class EditorMenuBar extends MenuBar {
rootNode.getChildren().add(0, referenceAxisBuilder.getVisualGroup());
referenceAxisBuilder.getVisualGroup().toFront();
///////////////////////////////////////////////////////////////////////////////////////
// Length
Label lengthLabel = new Label("Length");
TextField lengthField = new TextField("0.0");
lengthField.setOnAction(valueEvent -> {
try {
double length = Double.parseDouble(lengthField.getText());
referenceAxisBuilder.setName(nameField.getText());
referenceAxisBuilder.setLength(length);
referenceAxisBuilder.update();
}
catch (Exception e) {
// Invalid input, nothing to do
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Position
Label positionLabel = new Label("Position : ");
......@@ -1488,22 +1508,20 @@ public class EditorMenuBar extends MenuBar {
// Get the reference axis.
ReferenceAxis referenceAxis = ReferenceAxisList.getInstance().getAxis(newValue);
referenceAxisBuilder.setName(nameField.getText());
referenceAxisBuilder.setPosition(referenceAxis.getPosition());
referenceAxisBuilder.update();
ReferenceAxis newAxis = referenceAxisBuilder.getNewAxis();
if (newAxis != null) {
lengthField.setText("" + newAxis.getDirection().magnitude());
}
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference for first axis
Label reference1Label = new Label("Reference Axis A : ");
CheckBox reversedDirection1Check = new CheckBox("Reversed");
reversedDirection1Check.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
// ?
}
});
Label reference1Label = new Label("Direction : ");
ComboBox<String> reference1Box = new ComboBox<>(references);
reference1Box.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
......@@ -1512,23 +1530,20 @@ public class EditorMenuBar extends MenuBar {
// Get the reference axis.
ReferenceAxis referenceAxis = ReferenceAxisList.getInstance().getAxis(newValue);
// Set the reference 1.
referenceAxisBuilder.setReference1(referenceAxis.getName(), referenceAxis.getDirection(), false);
referenceAxisBuilder.setName(nameField.getText());
referenceAxisBuilder.setReference1(referenceAxis.getName(), referenceAxis.getDirection());
referenceAxisBuilder.update();
ReferenceAxis newAxis = referenceAxisBuilder.getNewAxis();
if (newAxis != null) {
lengthField.setText("" + newAxis.getDirection().magnitude());
}
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference for second axis
Label reference2Label = new Label("Reference Axis B : ");
CheckBox reversedDirection2Check = new CheckBox("Reversed");
Label reference2Label = new Label("^ Direction : ");
reversedDirection2Check.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
// ?
}
});
ComboBox<String> reference2Box = new ComboBox<>(references);
reference2Box.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
......@@ -1537,12 +1552,34 @@ public class EditorMenuBar extends MenuBar {
// Get the reference axis.
ReferenceAxis referenceAxis = ReferenceAxisList.getInstance().getAxis(newValue);
// Set the reference 2.
referenceAxisBuilder.setReference2(referenceAxis.getName(), referenceAxis.getDirection(), false);
referenceAxisBuilder.setName(nameField.getText());
referenceAxisBuilder.setReference2(referenceAxis.getName(), referenceAxis.getDirection());
referenceAxisBuilder.update();
ReferenceAxis newAxis = referenceAxisBuilder.getNewAxis();
if (newAxis != null) {
lengthField.setText("" + newAxis.getDirection().magnitude());
}
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reversed direction
Label reversedDirectionLabel = new Label("Reversed");
CheckBox reversedDirectionCheck = new CheckBox();
reversedDirectionCheck.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
referenceAxisBuilder.setName(nameField.getText());
referenceAxisBuilder.setReversed(newValue);
referenceAxisBuilder.update();
ReferenceAxis newAxis = referenceAxisBuilder.getNewAxis();
if (newAxis != null) {
lengthField.setText("" + newAxis.getDirection().magnitude());
}
}
});
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane scenePane = new GridPane();
......@@ -1572,6 +1609,8 @@ public class EditorMenuBar extends MenuBar {
addPane.addRow(1, positionLabel, positionBox);
addPane.addRow(2, reference1Label, reference1Box);
addPane.addRow(3, reference2Label, reference2Box);
addPane.addRow(4, reversedDirectionLabel, reversedDirectionCheck);
addPane.addRow(5, lengthLabel, lengthField);
Button okButton = new Button("OK");
okButton.setOnAction(new EventHandler<ActionEvent>() {
......@@ -1581,33 +1620,43 @@ public class EditorMenuBar extends MenuBar {
// Get the names.
String newAxisName = nameField.getText();
// String parentComponentName = parentBox.getSelectionModel().getSelectedItem();
// boolean error = false;
// String errorMessage = null;
//
// // Check the name.
// if (nameExists(newAxisName)) {
// error = true;
// errorMessage = "The component name already exists.";
// }
//
// if (newAxisName.isEmpty()) {
// error = true;
// errorMessage = "The name is empty.";
// }
//
// // Check the name.
// if (error) {
// Alert emptyAlert = new Alert(AlertType.WARNING);
// emptyAlert.setTitle("Bad name");
// emptyAlert.setContentText(errorMessage);
// emptyAlert.showAndWait();
// return;
// }
//
// // Save the operation.
// Operations.getInstance().addOperation(new NewComponentOperation(newAxisName, parentComponentName));
boolean error = false;
String errorMessage = null;
// Check the name.
if (ReferenceAxisList.getInstance().getAxis(newAxisName) != null) {
error = true;
errorMessage = "The axis name already exists.";
}
if (newAxisName.isEmpty()) {
error = true;
errorMessage = "The name is empty.";
}
ReferenceAxis newAxis = referenceAxisBuilder.getNewAxis();
if (newAxis != null) {
newAxis.setName(newAxisName);
}
else {
error = true;
errorMessage = "The axis is not defined.";
}
// Check the name.
if (error) {
Alert emptyAlert = new Alert(AlertType.WARNING);
emptyAlert.setTitle("Bad name");
emptyAlert.setContentText(errorMessage);
emptyAlert.showAndWait();
return;
}
ReferenceAxisList.getInstance().add(newAxis);
// Save the operation.
Operations.getInstance().addOperation(new NewReferenceAxisOperation(newAxis));
// Change the title.
updateModified(true);
......@@ -1645,8 +1694,113 @@ public class EditorMenuBar extends MenuBar {
stage.showAndWait();
});
///////////////////////////////////////////////////////////////////////////////////////
// Remove reference axis menu
MenuItem removeReferenceAxisItem = new MenuItem("Remove Reference Axis");
removeReferenceAxisItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
// List of reference axes.
ObservableList<String> references = FXCollections.observableArrayList("");
references.addAll(ReferenceAxisList.getInstance().getNames());
///////////////////////////////////////////////////////////////////////////////////
// Parent
Label axisLabel = new Label("Reference Axis : ");
ObservableList<String> referenceAxes = FXCollections.observableArrayList(references);
ComboBox<String> axisBox = new ComboBox<String>(referenceAxes);
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene scene = new Scene(scenePane);
Stage stage = new Stage(StageStyle.UTILITY);
stage.setTitle("Remove Reference Axis");
stage.setScene(scene);
stage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane mainPane = new GridPane();
mainPane.setVgap(5);
mainPane.setHgap(10);
mainPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, mainPane);
GridPane.setMargin(mainPane, new Insets(10));
GridPane movePane = new GridPane();
movePane.setVgap(5);
movePane.setHgap(10);
movePane.setAlignment(Pos.CENTER);
scenePane.addRow(0, movePane);
GridPane.setMargin(movePane, new Insets(10));
movePane.addRow(1, axisLabel, axisBox);
Button okButton = new Button("OK");
okButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String axisName = axisBox.getValue();
ReferenceAxis axis = ReferenceAxisList.getInstance().getAxis(axisName);
if (axis == null) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(editAxisItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
String componentName = Nomad3DEditor.getInstance().getModel().findAxisDependent(axis);
if (componentName != null) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(editAxisItem.getText());
alert.setContentText("The component " + componentName + " depends on the reference axis.");
alert.showAndWait();
return;
}
// Remove the axis.
ReferenceAxisList.getInstance().remove(ReferenceAxisList.getInstance().getAxis(axisBox.getValue()));
// Save the operation.
Operations.getInstance().addOperation(new RemoveReferenceAxisOperation(axisName));
// Change the title.
updateModified(true);
// Close the stage.
stage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.close();
}
});
GridPane buttonPane = new GridPane();
buttonPane.setHgap(10);
buttonPane.setAlignment(Pos.CENTER);
buttonPane.addRow(0, okButton, cancelButton);
mainPane.addRow(0, movePane);
mainPane.addRow(1, buttonPane);
stage.showAndWait();
});
......@@ -2067,7 +2221,11 @@ public class EditorMenuBar extends MenuBar {
// Menu componentsMenu = new Menu("Components");
// componentsMenu.getItems().addAll(subdivideComponentItem, insertComponentItem);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), addComponentItem, removeComponentsItem, renameComponentItem, moveComponentsItem, addReferenceAxisItem);
this.edit.getItems().addAll(
undoItem,
new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem,
new SeparatorMenuItem(), addComponentItem, removeComponentsItem, renameComponentItem, moveComponentsItem,
new SeparatorMenuItem(), addReferenceAxisItem, removeReferenceAxisItem);
this.view = new Menu("View");
Menu cameraMenu = new Menu("Camera");
......
package fr.ill.ics.n3d.gui;
import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Axis.Type;
import fr.ill.ics.n3d.model.ReferenceAxis;
import javafx.geometry.Point3D;
import javafx.scene.DepthTest;
import javafx.scene.Group;
......@@ -13,18 +13,26 @@ public class ReferenceAxisBuilder {
private Group visualGroup;
private String name;
private Point3D position;
private String name1 = "";
private Point3D direction1;
private boolean reversed1;
private Group visualGroup1;
private String name2 = "";
private Point3D direction2;
private boolean reversed2;
private Group visualGroup2;
private boolean reversed = false;
private double length;
private boolean lengthFromCalculation = true;
private ReferenceAxis newAxis;
private Group newVisualGroup;
/**
* Default constructor.
*/
......@@ -34,30 +42,55 @@ public class ReferenceAxisBuilder {
visualGroup1 = new Group();
visualGroup2 = new Group();
newVisualGroup = new Group();
}
public Group getVisualGroup() {
return visualGroup;
}
public void setName(String name) {
this.name = name;
}
public void setPosition(Point3D position) {
this.position = position;
}
public void setReference1(String name, Point3D direction, boolean reversed) {
public void setReference1(String name, Point3D direction) {
name1 = name;
direction1 = direction;
reversed1 = reversed;
lengthFromCalculation = true;
}
public void setReference2(String name, Point3D direction, boolean reversed) {
public void setReference2(String name, Point3D direction) {
name2 = name;
direction2 = direction;
reversed2 = reversed;
lengthFromCalculation = true;
}
public void setReversed(boolean value) {
reversed = value;
}
public void setLength(double value) {
length = value;
lengthFromCalculation = false;
}
public ReferenceAxis getNewAxis() {
return newAxis;
}
public void update() {
if (lengthFromCalculation) {
newAxis = ReferenceAxis.create(name, position, direction1, direction2, reversed, 50);
}
else {
newAxis = ReferenceAxis.create(name, position, direction1, direction2, reversed, length);
}
visualGroup.getChildren().clear();
visualGroup.getTransforms().clear();
......@@ -67,16 +100,21 @@ public class ReferenceAxisBuilder {
// The axis 1 to display.
if (!name1.isEmpty()) {
Axis.updateVisualAxisGroup(visualGroup1, Axis.Type.REFERENCE1, position, direction1, reversed1);
Axis.updateVisualAxisGroup(visualGroup1, Axis.Type.REFERENCE1, position, direction1, false);
visualGroup.getChildren().add(visualGroup1);
}
// The axis 2 to display.
if (!name2.isEmpty()) {
Axis.updateVisualAxisGroup(visualGroup2, Axis.Type.REFERENCE2, position, direction2, reversed2);
Axis.updateVisualAxisGroup(visualGroup2, Axis.Type.REFERENCE2, position, direction2, false);
visualGroup.getChildren().add(visualGroup2);
}
if (newAxis != null) {
Axis.updateVisualAxisGroup(newVisualGroup, Axis.Type.NEW, newAxis.getPosition(), newAxis.getDirection(), false);
visualGroup.getChildren().add(newVisualGroup);
}
visualGroup.setDepthTest(DepthTest.DISABLE);
}
}
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