Commit d264491b authored by legoc's avatar legoc
Browse files

Started with the definition of a reference axis

parent 1fb12b14
......@@ -64,6 +64,7 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.Group;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
......@@ -1439,6 +1440,207 @@ public class EditorMenuBar extends MenuBar {
stage.showAndWait();
});
///////////////////////////////////////////////////////////////////////////////////////
// Add reference axis menu
MenuItem addReferenceAxisItem = new MenuItem("Add Reference Axis");
addReferenceAxisItem.setOnAction(event -> {
if (!modelLoaded()) {
return;
}
///////////////////////////////////////////////////////////////////////////////////
// Name
Label nameLabel = new Label("Name : ");
TextField nameField = new TextField("");
nameField.setAlignment(Pos.TOP_LEFT);
nameField.setPrefColumnCount(15);
// List of reference axes.
ObservableList<String> references = FXCollections.observableArrayList("");
references.addAll(ReferenceAxisList.getInstance().getNames());
// Reference axis builder
ReferenceAxisBuilder referenceAxisBuilder = new ReferenceAxisBuilder();
Group rootNode = (Group)Nomad3DEditor.getInstance().getModel().getRoot().getSceneNode();
// We must set it at the end of the group.
rootNode.getChildren().add(referenceAxisBuilder.getVisualGroup());
///////////////////////////////////////////////////////////////////////////////////////
// Position
Label positionLabel = new Label("Position : ");
ComboBox<String> positionBox = new ComboBox<>(references);
positionBox.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);
referenceAxisBuilder.setPosition(referenceAxis.getPosition());
referenceAxisBuilder.update();
}
});
///////////////////////////////////////////////////////////////////////////////////////
// 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) {
// ?
}
});
ComboBox<String> reference1Box = new ComboBox<>(references);
reference1Box.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 reference 1.
referenceAxisBuilder.setReference1(referenceAxis.getName(), referenceAxis.getDirection(), false);
referenceAxisBuilder.update();
}
});
///////////////////////////////////////////////////////////////////////////////////////
// Reference for second axis
Label reference2Label = new Label("Reference Axis B : ");
CheckBox reversedDirection2Check = new CheckBox("Reversed");
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
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
// Get the reference axis.
ReferenceAxis referenceAxis = ReferenceAxisList.getInstance().getAxis(newValue);
// Set the reference 2.
referenceAxisBuilder.setReference2(referenceAxis.getName(), referenceAxis.getDirection(), false);
referenceAxisBuilder.update();
}
});
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene scene = new Scene(scenePane);
Stage stage = new Stage(StageStyle.UTILITY);
stage.setTitle("Add 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 addPane = new GridPane();
addPane.setVgap(5);
addPane.setHgap(10);
addPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, addPane);
GridPane.setMargin(addPane, new Insets(10));
addPane.addRow(0, nameLabel, nameField);
addPane.addRow(1, positionLabel, positionBox);
addPane.addRow(2, reference1Label, reference1Box);
addPane.addRow(3, reference2Label, reference2Box);
Button okButton = new Button("OK");
okButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// 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));
// Change the title.
updateModified(true);
// Remove the reference axis builder.
rootNode.getChildren().remove(referenceAxisBuilder.getVisualGroup());
// Close the stage.
stage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Remove the reference axis builder.
rootNode.getChildren().remove(referenceAxisBuilder.getVisualGroup());
// Close the stage.
stage.close();
}
});
GridPane buttonPane = new GridPane();
buttonPane.setHgap(10);
buttonPane.setAlignment(Pos.CENTER);
buttonPane.addRow(0, okButton, cancelButton);
mainPane.addRow(0, addPane);
mainPane.addRow(1, buttonPane);
stage.showAndWait();
});
///////////////////////////////////////////////////////////////////////////////////////
// Not used anymore
......@@ -1857,7 +2059,7 @@ 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);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), addComponentItem, removeComponentsItem, renameComponentItem, moveComponentsItem, addReferenceAxisItem);
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 javafx.geometry.Point3D;
import javafx.scene.DepthTest;
import javafx.scene.Group;
/**
* Class for creating reference axes.
*/
public class ReferenceAxisBuilder {
private Group visualGroup;
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;
/**
* Default constructor.
*/
public ReferenceAxisBuilder() {
visualGroup = new Group();
visualGroup.setVisible(true);
visualGroup1 = new Group();
visualGroup2 = new Group();
}
public Group getVisualGroup() {
return visualGroup;
}
public void setPosition(Point3D position) {
this.position = position;
}
public void setReference1(String name, Point3D direction, boolean reversed) {
name1 = name;
direction1 = direction;
reversed1 = reversed;
}
public void setReference2(String name, Point3D direction, boolean reversed) {
name2 = name;
direction2 = direction;
reversed2 = reversed;
}
public void update() {
visualGroup.getChildren().clear();
visualGroup.getTransforms().clear();
if (position == null) {
return;
}
// The axis 1 to display.
if (!name1.isEmpty()) {
Axis.updateVisualAxisGroup(visualGroup1, Axis.Type.REFERENCE1, position, direction1, reversed1);
visualGroup.getChildren().add(visualGroup1);
}
// The axis 2 to display.
if (!name2.isEmpty()) {
Axis.updateVisualAxisGroup(visualGroup2, Axis.Type.REFERENCE2, position, direction2, reversed2);
visualGroup.getChildren().add(visualGroup2);
}
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