Commit fa8a5c9c authored by legoc's avatar legoc
Browse files

Added remove component operation

parent b9efa28f
......@@ -24,6 +24,7 @@ import fr.ill.ics.n3d.model.ReferenceAxisList;
import fr.ill.ics.n3d.operations.NewComponentOperation;
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.SetAxisOperation;
import fr.ill.ics.n3d.operations.SetMaterialOperation;
import javafx.application.Platform;
......@@ -218,8 +219,8 @@ public class EditorMenuBar extends MenuBar {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
HashSet<Component> selectedComponents = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectedComponents.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(editAxisItem.getText());
alert.setContentText("Empty selection.");
......@@ -227,14 +228,14 @@ public class EditorMenuBar extends MenuBar {
return;
}
Component modifiedComponent = null;
if (selectRoots.size() > 1) {
if (selectedComponents.size() > 1) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(editAxisItem.getText());
alert.setContentText("Select only one Component.");
alert.showAndWait();
} else {
modifiedComponent = selectRoots.iterator().next();
modifiedComponent = selectedComponents.iterator().next();
}
if (modifiedComponent == null) {
......@@ -1053,6 +1054,57 @@ public class EditorMenuBar extends MenuBar {
stage.showAndWait();
});
///////////////////////////////////////////////////////////////////////////////////////
// Remove components menu
MenuItem removeComponentsItem = new MenuItem("Remove Components");
removeComponentsItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
HashSet<Component> selectedComponents = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectedComponents.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(removeComponentsItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
String message = "The following components will be removed : ";
for (Component component : selectedComponents) {
message += "\n" + component.getName();
}
Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
confirmAlert.setTitle(removeComponentsItem.getText());
confirmAlert.setContentText(message);
Optional<ButtonType> res = confirmAlert.showAndWait();
if (res.get() != ButtonType.OK) {
return;
}
// Remove each selected component.
for (Component component : selectedComponents) {
// Create a new remove component operation.
RemoveComponentOperation removeOperation = new RemoveComponentOperation(component.getName());
removeOperation.apply(Nomad3DEditor.getInstance().getModel());
// Save the operation.
Operations.getInstance().addOperation(removeOperation);
// Change the title.
updateModified(true);
}
Nomad3DEditor.getInstance().getModel().clearSelection();
updateScene();
});
MenuItem regroupComponentsItem = new MenuItem("Regroup Components");
regroupComponentsItem.setOnAction(event -> {
......@@ -1060,15 +1112,15 @@ public class EditorMenuBar extends MenuBar {
return;
}
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
HashSet<Component> selectedComponents = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectedComponents.isEmpty()) {
Alert emptyAlert = new Alert(AlertType.WARNING);
emptyAlert.setTitle(regroupComponentsItem.getText());
emptyAlert.setContentText("Empty selection.");
emptyAlert.showAndWait();
return;
}
Component commonAncestor = Component.ancestorOf(selectRoots);
Component commonAncestor = Component.ancestorOf(selectedComponents);
if (commonAncestor == null) {
Alert ancestorAlert = new Alert(AlertType.WARNING);
ancestorAlert.setTitle(regroupComponentsItem.getText());
......@@ -1108,7 +1160,7 @@ public class EditorMenuBar extends MenuBar {
RadioButton selectButton = new RadioButton("Parent of : ");
selectButton.setToggleGroup(buttonsGroup);
Label commonLabel = new Label(commonAncestor.getName());
ObservableList<Component> selectList = FXCollections.observableArrayList(selectRoots);
ObservableList<Component> selectList = FXCollections.observableArrayList(selectedComponents);
ComboBox<Component> selectBox = new ComboBox<>(selectList);
selectBox.setCellFactory(ComboCell.FACTORY);
CheckBox addLevelBox = new CheckBox("Insert A New Component Regrouping The Selection");
......@@ -1133,10 +1185,10 @@ public class EditorMenuBar extends MenuBar {
}
if (addLevelBox.isSelected()) {
System.out.println("inserting " + selectRoots.size() + " components");
newParent.insertBlock(selectRoots, false, "REGROUPED");
System.out.println("inserting " + selectedComponents.size() + " components");
newParent.insertBlock(selectedComponents, false, "REGROUPED");
} else {
for (Component comp : selectRoots) {
for (Component comp : selectedComponents) {
newParent.addChild(comp);
}
}
......@@ -1521,44 +1573,7 @@ public class EditorMenuBar extends MenuBar {
insertStage.show();
});
MenuItem removeComponentsItem = new MenuItem("Remove components");
removeComponentsItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(removeComponentsItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
String confirmMsg = "The following components will be deleted : ";
for (Component c : selectRoots) {
confirmMsg += "\n" + c.getName();
}
Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
confirmAlert.setTitle(removeComponentsItem.getText());
confirmAlert.setContentText(confirmMsg);
Optional<ButtonType> res = confirmAlert.showAndWait();
if (res.get() != ButtonType.OK) {
return;
}
for (Component c : selectRoots) {
if (c.isRoot()) {
Nomad3DEditor.getInstance().getModel().clear();
return;
} else {
Component parent = c.getParent();
parent.removeChild(c);
}
}
Nomad3DEditor.getInstance().getModel().clearSelection();
updateScene();
});
MenuItem saveConfigItem = new MenuItem("Save current configuration");
saveConfigItem.setOnAction(event -> {
......@@ -1608,8 +1623,8 @@ public class EditorMenuBar extends MenuBar {
});
Menu componentsMenu = new Menu("Components");
componentsMenu.getItems().addAll(regroupComponentsItem, subdivideComponentItem, insertComponentItem, removeComponentsItem);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), componentsMenu, addComponentItem);
componentsMenu.getItems().addAll(regroupComponentsItem, subdivideComponentItem, insertComponentItem);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), componentsMenu, addComponentItem, removeComponentsItem);
this.view = new Menu("View");
Menu cameraMenu = new Menu("Camera");
......@@ -2003,7 +2018,7 @@ public class EditorMenuBar extends MenuBar {
* @return The root of the selection if there is one, null otherwise.
*/
private Component selectComponent(String title) {
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
HashSet<Component> selectRoots = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(title);
......
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