Commit 0a1966d2 authored by legoc's avatar legoc

Switched to full component path for operations

parent 597a4db8
......@@ -24,6 +24,7 @@ import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.Component.AxisInfo;
import fr.ill.ics.n3d.model.ConfigParams;
import fr.ill.ics.n3d.model.PathName;
import fr.ill.ics.n3d.model.ReferenceAxis;
import fr.ill.ics.n3d.model.ReferenceAxisList;
import fr.ill.ics.n3d.operations.MoveComponentsOperation;
......@@ -795,7 +796,7 @@ public class EditorMenuBar extends MenuBar {
// Save the operation.
Operations.getInstance().addOperation(new SetAxisOperation(
selectedComponent.getName(),
new PathName(selectedComponent).toString(),
selectedAxis.getType(),
referenceAxisName,
selectedAxis.getRotationDirection(),
......@@ -899,7 +900,7 @@ public class EditorMenuBar extends MenuBar {
TableView<AxisTableEntry> tableView = new TableView();
tableView.setEditable(false);
TableColumn axisNameColumn = new TableColumn<>("Name");
axisNameColumn.setMinWidth(200);
axisNameColumn.setCellValueFactory(new PropertyValueFactory<AxisTableEntry, String>("axisName"));
......@@ -918,11 +919,11 @@ public class EditorMenuBar extends MenuBar {
public void changed(ObservableValue<? extends AxisTableEntry> observable, AxisTableEntry oldValue, AxisTableEntry newValue) {
// Find the components.
if (oldValue != null) {
Component oldComponent = Nomad3DEditor.getInstance().getModel().findComponent(oldValue.getComponentName());
Component oldComponent = Nomad3DEditor.getInstance().getModel().findComponent(new PathName(oldValue.getComponentName()));
oldComponent.getTreeItem().selectedProperty().set(false);
}
Component newComponent = Nomad3DEditor.getInstance().getModel().findComponent(newValue.getComponentName());
Component newComponent = Nomad3DEditor.getInstance().getModel().findComponent(new PathName(newValue.getComponentName()));
newComponent.getTreeItem().selectedProperty().set(true);
}
});
......@@ -1017,13 +1018,13 @@ public class EditorMenuBar extends MenuBar {
newMaterial.setSpecularColor(specularPicker.getValue());
newMaterial.setSpecularPower(Double.parseDouble(shininessField.getText()));
for (Component selectedComp : Nomad3DEditor.getInstance().getModel().getSelection()) {
for (Component selectedComponent : Nomad3DEditor.getInstance().getModel().getSelection()) {
// Set the new material without setting the children.
selectedComp.setMaterial(newMaterial, false);
selectedComponent.setMaterial(newMaterial, false);
// Save the operation.
Operations.getInstance().addOperation(new SetMaterialOperation(newMaterial, selectedComp.getName()));
Operations.getInstance().addOperation(new SetMaterialOperation(newMaterial, new PathName(selectedComponent).toString()));
// Change the title.
updateModified(true);
......@@ -1066,7 +1067,7 @@ public class EditorMenuBar extends MenuBar {
///////////////////////////////////////////////////////////////////////////////////
// Parent
Label parentLabel = new Label("Parent : ");
ObservableList<String> assemblyComponents = FXCollections.observableArrayList(getAssemblyComponentNames());
ObservableList<String> assemblyComponents = FXCollections.observableArrayList(getAssemblyComponentPathNames());
ComboBox<String> parentBox = new ComboBox<String>(assemblyComponents);
parentBox.getSelectionModel().select(0);
......@@ -1130,19 +1131,22 @@ public class EditorMenuBar extends MenuBar {
emptyAlert.showAndWait();
return;
}
Component parent = Nomad3DEditor.getInstance().getModel().findComponent(parentComponentName);
parent.addComponent(newComponentName);
// Update the scene.
updateScene();
// Get the parent.
Component parent = Nomad3DEditor.getInstance().getModel().findComponent(new PathName(parentComponentName));
// Save the operation.
Operations.getInstance().addOperation(new NewComponentOperation(newComponentName, parentComponentName));
Operations.getInstance().addOperation(new NewComponentOperation(newComponentName, new PathName(parent).toString()));
// Change the title.
updateModified(true);
// Add the component.
parent.addComponent(newComponentName);
// Update the scene.
updateScene();
// Close the stage.
stage.close();
}
......@@ -1203,7 +1207,7 @@ public class EditorMenuBar extends MenuBar {
for (Component component : selectedComponents) {
// Create a new remove component operation.
RemoveComponentOperation removeOperation = new RemoveComponentOperation(component.getName());
RemoveComponentOperation removeOperation = new RemoveComponentOperation(new PathName(component).toString());
removeOperation.apply(Nomad3DEditor.getInstance().getModel());
// Save the operation.
......@@ -1319,21 +1323,18 @@ public class EditorMenuBar extends MenuBar {
return;
}
// Gets the component name.
String componentName = component.getName();
// Save the operation.
Operations.getInstance().addOperation(new RenameComponentOperation(new PathName(component).toString(), newComponentName));
// Change the title.
updateModified(true);
// Set the new name of the component.
component.setName(newComponentName);
// Update the scene.
updateScene();
// Save the operation.
Operations.getInstance().addOperation(new RenameComponentOperation(componentName, newComponentName));
// Change the title.
updateModified(true);
// Close the stage.
stage.close();
}
......@@ -1370,7 +1371,7 @@ public class EditorMenuBar extends MenuBar {
///////////////////////////////////////////////////////////////////////////////////
// Parent
Label parentLabel = new Label("New Parent : ");
ObservableList<String> assemblyComponents = FXCollections.observableArrayList(getAssemblyComponentNames());
ObservableList<String> assemblyComponents = FXCollections.observableArrayList(getAssemblyComponentPathNames());
ComboBox<String> parentBox = new ComboBox<String>(assemblyComponents);
parentBox.getSelectionModel().select(0);
......@@ -1422,17 +1423,17 @@ public class EditorMenuBar extends MenuBar {
}
// Get the names.
String newParentComponentName = parentBox.getSelectionModel().getSelectedItem();
Component newParentComponent = Nomad3DEditor.getInstance().getModel().findComponent(newParentComponentName);
String selectedParentComponentName = parentBox.getSelectionModel().getSelectedItem();
Component newParentComponent = Nomad3DEditor.getInstance().getModel().findComponent(new PathName(selectedParentComponentName));
// Create the operation.
MoveComponentsOperation operation = new MoveComponentsOperation(newParentComponentName);
MoveComponentsOperation operation = new MoveComponentsOperation(new PathName(newParentComponent).toString());
// Iterate the components to move.
for (Component component : selectedComponents) {
// Modify the operation by getting the name of the parent before it changes.
operation.addMovedComponent(component.getName(), component.getParent().getName());
operation.addMovedComponent(new PathName(component).toString());
// Move the component.
newParentComponent.addChild(component);
......@@ -2758,16 +2759,16 @@ public class EditorMenuBar extends MenuBar {
* @param result The list of names.
* @param component The component.
*/
private void getAssemblyComponentNames(ArrayList<String> result, Component component) {
private void getAssemblyComponentPathNames(ArrayList<String> result, Component component) {
// Get the lead component and those that were added.
if (!component.isLeaf() || component.isAdded()) {
result.add(component.getName());
result.add(new PathName(component).toString());
}
// Traverse the components recursively.
for (Component child : component.getChildren()) {
getAssemblyComponentNames(result, child);
getAssemblyComponentPathNames(result, child);
}
}
......@@ -2775,11 +2776,11 @@ public class EditorMenuBar extends MenuBar {
* Gets the assembly component names.
* @return The list of assembly names.
*/
private ArrayList<String> getAssemblyComponentNames() {
private ArrayList<String> getAssemblyComponentPathNames() {
ArrayList<String> result = new ArrayList<String>();
getAssemblyComponentNames(result, Nomad3DEditor.getInstance().getModel().getRoot());
getAssemblyComponentPathNames(result, Nomad3DEditor.getInstance().getModel().getRoot());
return result;
}
......
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