Commit c8bdccaf authored by Ivan Dages's avatar Ivan Dages
Browse files

debug termination

parent 435e2e14
......@@ -14,6 +14,7 @@ import fr.ill.ics.n3d.link.NomadLinker;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.Model;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Bounds;
......@@ -97,7 +98,7 @@ public class Nomad3DEditor extends Application {
/** Title of the editor's window. */
public final static String TITLE = "Nomad 3D editor";
/** Legth of the axes of the coordinate system (XYZ). */
/** Length of the axes of the coordinate system (XYZ). */
private final static double AXIS_LENGTH = 50;
/**
......@@ -112,8 +113,18 @@ public class Nomad3DEditor extends Application {
e.printStackTrace();
} finally {
NomadLinker.getInstance().terminate();
exit(0);
}
}
public static void exit(int status) {
Logger.getLogger("nomad-3d").info("Exiting JavaFX...");
Platform.exit();
Logger.getLogger("nomad-3d").info("Exiting program with status " + status + "...");
System.exit(status);
}
@Override
public void start(Stage stage) throws Exception {
......@@ -125,11 +136,11 @@ public class Nomad3DEditor extends Application {
FileHandler handler = new FileHandler(logPath);
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);
logger.info("Logging into " + logPath + "\n");
logger.info("Logging into " + logPath);
} catch (Exception e) {
e.printStackTrace();
}
Logger.getLogger("nomad-3d").info("Starting " + TITLE + "... \n");
Logger.getLogger("nomad-3d").info("Starting " + TITLE + "...");
model = null;
this.scene = null;
......
......@@ -34,6 +34,8 @@ import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeView;
import javafx.scene.input.KeyCode;
......@@ -270,34 +272,11 @@ 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()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
Component modifiedComponent = null;
if(selectRoots.size() > 1) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Several components are selected, multiple axes cannot be calibrated at once.");
alert.showAndWait();
return;
} else {
modifiedComponent = selectRoots.iterator().next();
}
if (modifiedComponent == null) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(calibrateAxisItem.getText());
alert.setContentText("Unable to get the selected axis.");
alert.showAndWait();
return;
}
final Axis selectedAxis = modifiedComponent.getAxis();
Logger.getLogger("nomad-3d").info("Calibrating axis of " + modifiedComponent.getName());
final Component selectedComponent = selectComponent(calibrateAxisItem.getText());
final Axis selectedAxis = selectedComponent.getAxis();
Logger.getLogger("nomad-3d").info("Calibrating axis of " + selectedComponent.getName());
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
......@@ -401,7 +380,57 @@ public class EditorMenuBar extends MenuBar {
valueThread.start();
calibrateStage.show();
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem);
MenuItem displayAxisItem = new MenuItem("Display axis properties");
displayAxisItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getRoot() == null) {
return;
}
final Component selectedComponent = selectComponent(calibrateAxisItem.getText());
final Axis selectedAxis = (selectedComponent == null) ? null : selectedComponent.getAxis();
if (selectedAxis == null) {
// Error alert already display in selectComponent(String)
return;
}
TabPane scenePane = new TabPane();
Scene displayScene = new Scene(scenePane);
Stage displayStage = new Stage(StageStyle.UTILITY);
displayStage.setTitle(displayAxisItem.getText());
displayStage.setScene(displayScene);
displayStage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane nomad3DPane = new GridPane();
nomad3DPane.setPrefSize(500, 200);
nomad3DPane.setVgap(5);
nomad3DPane.setHgap(10);
nomad3DPane.setAlignment(Pos.CENTER);
scenePane.getTabs().add(new Tab("Nomad 3D", nomad3DPane));
GridPane.setMargin(nomad3DPane, new Insets(10));
int i = 0;
nomad3DPane.addRow(i++, new Label("Type :"), new Label(selectedAxis.getType().toString()));
nomad3DPane.addRow(i++, new Label("Method :"), new Label(selectedAxis.getMethod().toString()));
nomad3DPane.addRow(i++, new Label("Direction :"), new Label(selectedAxis.getDirection().toString()));
nomad3DPane.addRow(i++, new Label("Position :"), new Label(selectedAxis.getPosition().toString()));
nomad3DPane.addRow(i++, new Label("Min value :"), new Label(Double.toString(selectedAxis.getMinValue())));
nomad3DPane.addRow(i++, new Label("Median value :"), new Label(Double.toString(selectedAxis.getMedianValue())));
nomad3DPane.addRow(i++, new Label("Max value :"), new Label(Double.toString(selectedAxis.getMaxValue())));
GridPane nomadPane = new GridPane();
nomadPane.setVgap(5);
nomadPane.setHgap(10);
nomadPane.setAlignment(Pos.CENTER);
scenePane.getTabs().add(new Tab("Nomad", nomadPane));
GridPane.setMargin(nomadPane, new Insets(10));
// TODO
nomadPane.addRow(0, new Label("TODO"));
displayStage.show();
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem, displayAxisItem);
MenuItem modifyMaterialItem = new MenuItem("Modify material");
modifyMaterialItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
......@@ -811,6 +840,35 @@ public class EditorMenuBar extends MenuBar {
this.getMenus().addAll(this.file, this.edit, this.view, this.selection);
}
private Component selectComponent(String title) {
HashSet<Component> selectRoots = Component.rootsOf(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectRoots.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(title);
alert.setContentText("Empty selection.");
alert.showAndWait();
return null;
}
Component modifiedComponent = null;
if(selectRoots.size() > 1) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(title);
alert.setContentText("Several components are selected, multiple axes cannot be calibrated at once.");
alert.showAndWait();
return null;
} else {
modifiedComponent = selectRoots.iterator().next();
}
if (modifiedComponent == null) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(title);
alert.setContentText("Unable to get the selected component.");
alert.showAndWait();
return null;
}
return modifiedComponent;
}
/**
* Updates the menu bar and the Nomad3DEditor.getInstance() accordingly.
*/
......
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