Commit 894c287d authored by Ivan Dages's avatar Ivan Dages
Browse files

regroup components

parent 14640457
package fr.ill.ics.n3d.gui;
import fr.ill.ics.n3d.model.Component;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.ComboBoxListCell;
import javafx.util.Callback;
import javafx.util.StringConverter;
public class ComboCell extends ComboBoxListCell<Component> {
public static final Callback<ListView<Component>,ListCell<Component>> FACTORY;
static {
FACTORY = new Callback<ListView<Component>,ListCell<Component>>(){
@Override
public ListCell<Component> call(ListView<Component> p) {
return new ComboCell();
}
};
}
public ComboCell() {
super();
}
@Override
public void updateItem(Component item, boolean empty) {
super.updateItem(item, empty);
if (empty || isEditing()) {
return;
} else {
setText(item.getName());
}
}
}
package fr.ill.ics.n3d.gui;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.Iterator;
......@@ -34,6 +36,7 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
......@@ -42,10 +45,12 @@ import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioButton;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.TreeView;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
......@@ -246,7 +251,7 @@ public class EditorMenuBar extends MenuBar {
Axis.Type.TRANSLATION,
Axis.Type.ROTATION,
Axis.Type.NONE
);
);
ComboBox<Axis.Type> typeBox = new ComboBox<>(types);
typeBox.getSelectionModel().select(selectedAxis.getType());
typeBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Axis.Type>() {
......@@ -432,6 +437,9 @@ public class EditorMenuBar extends MenuBar {
Nomad3DEditor.getInstance().getAxisBuilder().start(selectedAxis, Nomad3DEditor.getInstance().getRoot(), Nomad3DEditor.getInstance().getControls(), modified);
updateThread.start();
addStage.setOnCloseRequest(closeEvent -> {
cancelButton.getOnAction().handle(null);
});
addStage.show();
});
MenuItem calibrateAxisItem = new MenuItem("Calibrate axis");
......@@ -862,7 +870,118 @@ public class EditorMenuBar extends MenuBar {
modifyStage.showAndWait();
}
});
MenuItem regroupComponentsItem = new MenuItem("Regroup components");
regroupComponentsItem.setOnAction(event -> {
if (!modelLoaded()) {
return;
}
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
Alert emptyAlert = new Alert(AlertType.WARNING);
emptyAlert.setTitle(regroupComponentsItem.getText());
emptyAlert.setContentText("Empty selection.");
emptyAlert.showAndWait();
return;
}
Component commonAncestor = Component.ancestorOf(selectRoots);
if (commonAncestor == null) {
Alert ancestorAlert = new Alert(AlertType.WARNING);
ancestorAlert.setTitle(regroupComponentsItem.getText());
ancestorAlert.setContentText("Unable to find the common parent of the selection.");
ancestorAlert.showAndWait();
return;
}
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene regroupScene = new Scene(scenePane);
Stage regroupStage = new Stage(StageStyle.UTILITY);
regroupStage.setTitle(modifyMaterialItem.getText());
regroupStage.setScene(regroupScene);
regroupStage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane parentPane = new GridPane();
parentPane.setVgap(5);
parentPane.setHgap(10);
parentPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, parentPane);
GridPane.setMargin(parentPane, new Insets(10));
GridPane buttonsPane = new GridPane();
buttonsPane.setVgap(5);
buttonsPane.setHgap(10);
buttonsPane.setAlignment(Pos.CENTER);
scenePane.addRow(1, buttonsPane);
GridPane.setMargin(buttonsPane, new Insets(10));
Label parentLabel = new Label("Parent of the group :");
ToggleGroup buttonsGroup = new ToggleGroup();
RadioButton commonButton = new RadioButton("Common parent : ");
commonButton.setSelected(true);
commonButton.setToggleGroup(buttonsGroup);
RadioButton selectButton = new RadioButton("Parent of : ");
selectButton.setToggleGroup(buttonsGroup);
Label commonLabel = new Label(commonAncestor.getName());
ObservableList<Component> selectList = FXCollections.observableArrayList(selectRoots);
ComboBox<Component> selectBox = new ComboBox<>(selectList);
selectBox.setCellFactory(ComboCell.FACTORY);
CheckBox addLevelBox = new CheckBox("Insert a new component regrouping the selection");
addLevelBox.setSelected(true);
parentPane.addRow(0, parentLabel);
parentPane.addRow(1, commonButton, commonLabel);
parentPane.addRow(2, selectButton, selectBox);
parentPane.addRow(3, addLevelBox);
GridPane.setColumnSpan(parentLabel, GridPane.REMAINING);
GridPane.setColumnSpan(addLevelBox, GridPane.REMAINING);
Button okButton = new Button("OK");
okButton.setDefaultButton(true);
okButton.setOnAction(okEvent -> {
try {
Component newParent = null;
if (commonButton.isSelected()) {
newParent = commonAncestor;
} else if (selectButton.isSelected()) {
newParent = selectBox.getSelectionModel().getSelectedItem().getParent();
}
if (addLevelBox.isSelected()) {
System.out.println("inserting " + selectRoots.size() + " components");
newParent.insertBlock(selectRoots, false, "REGROUPED");
} else {
for (Component comp : selectRoots) {
newParent.addChild(comp);
}
}
updateScene();
} catch (Exception e) {
e.printStackTrace();
} finally {
regroupStage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(cancelEvent -> {
regroupStage.close();
});
buttonsPane.addRow(0, okButton, cancelButton);
regroupStage.show();
});
MenuItem subdivideComponentItem = new MenuItem("Subdivide component");
subdivideComponentItem.setOnAction(event -> {
// TODO subdivide ui
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(subdivideComponentItem.getText());
alert.setContentText(subdivideComponentItem.getText() + " TODO");
alert.showAndWait();
});
MenuItem removeComponentsItem = new MenuItem("Remove components");
removeComponentsItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
......@@ -970,10 +1089,13 @@ public class EditorMenuBar extends MenuBar {
updateConfigMenus();
});
this.removeConfig = new Menu("Remove configuration");
this.edit.getItems().addAll(axisMenu, modifyMaterialItem, removeComponentsItem,
new SeparatorMenuItem(),
analyzeConfigItem, saveMedianConfigItem, saveMinConfigItem, saveMaxConfigItem, saveConfigItem,
this.removeConfig);
Menu componentsMenu = new Menu("Components");
componentsMenu.getItems().addAll(regroupComponentsItem, subdivideComponentItem, removeComponentsItem);
Menu editConfigMenu = new Menu("Configurations");
editConfigMenu.getItems().addAll(analyzeConfigItem, saveMedianConfigItem, saveMinConfigItem, saveMaxConfigItem,
saveConfigItem, this.removeConfig);
this.edit.getItems().addAll(axisMenu, modifyMaterialItem, componentsMenu, editConfigMenu);
this.view = new Menu("View");
Menu cameraMenu = new Menu("Camera");
......@@ -1262,7 +1384,17 @@ public class EditorMenuBar extends MenuBar {
helpStage.show();
});
this.help.getItems().addAll(cameraHelpItem);
MenuItem wikiItem = new MenuItem("Wiki");
wikiItem.setOnAction(event -> {
try {
java.awt.Desktop.getDesktop().browse(new java.net.URI("https://code.ill.fr/instrument-control/protos/nomad-3d/nomad-3d-commons/wikis/home"));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
});
this.help.getItems().addAll(cameraHelpItem, wikiItem);
update();
......@@ -1479,7 +1611,7 @@ public class EditorMenuBar extends MenuBar {
if (!modelLoaded()) {
return;
}
Nomad3DEditor.getInstance().getModel().clearSelection();
Nomad3DEditor.getInstance().getRoot().getChildren().remove(Nomad3DEditor.getInstance().getModel().getRoot().getSceneNode());
Nomad3DEditor.getInstance().getModel().computeSceneHierarchies(activeLod);
Nomad3DEditor.getInstance().getRoot().getChildren().add(Nomad3DEditor.getInstance().getModel().getRoot().getSceneNode());
......
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