Commit c7d1e30d authored by legoc's avatar legoc
Browse files

Updated project

parent 4a63cf1c
......@@ -13,7 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
......
......@@ -4,11 +4,11 @@ $ mvn clean package
The application can be launched with a connection to Nomad e.g:
$ java -jar target/nomad-3d-editor-0.0.3-full.jar "{\"name\":\"n3d\", \"server\":\"tcp://localhost:7000\"}"
$ java -jar target/nomad-3d-editor-0.0.4-full.jar "{\"name\":\"n3d\", \"server\":\"tcp://localhost:7000\"}"
Or standalone:
$ java -jar target/nomad-3d-editor-0.0.3-full.jar --no-link
$ java -jar target/nomad-3d-editor-0.0.4-full.jar --no-link
For windows, ensure that jzmq.dll and libzmq.dll are accessible from the path.
......
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ill.ics</groupId>
<artifactId>nomad-3d-editor</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<distributionManagement>
<repository>
......@@ -41,20 +41,19 @@
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>nomad-3d-commons</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Force the compilation with 1.8 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>Cp1252</encoding>
<source>10</source>
<target>10</target>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
......
package fr.ill.ics.n3d;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Optional;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
......@@ -44,11 +40,10 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.MenuBar;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
......
package fr.ill.ics.n3d.gui;
import fr.ill.ics.n3d.gui.CameraControls;
import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Component;
import javafx.geometry.Point2D;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.transform.NonInvertibleTransformException;
import javafx.scene.transform.Rotate;
/**
......
......@@ -48,7 +48,6 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Point3D;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
......@@ -2169,379 +2168,8 @@ public class EditorMenuBar extends MenuBar {
stage.showAndWait();
});
///////////////////////////////////////////////////////////////////////////////////////
// Not used anymore
// TODO remove?
MenuItem subdivideComponentItem = new MenuItem("Subdivide Component");
subdivideComponentItem.setOnAction(event -> {
if (!modelLoaded()) {
return;
}
Component selectedComponent = selectComponent(subdivideComponentItem.getText());
if (selectedComponent == null) {
return;
}
Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
confirmAlert.setTitle(subdivideComponentItem.getText());
confirmAlert.setContentText("Subdividing a component will remove its geometry.");
Optional<ButtonType> res = confirmAlert.showAndWait();
if (res.get() != ButtonType.OK) {
return;
}
this.subdividedChilds.clear();
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.TOP_CENTER);
Scene subdivScene = new Scene(scenePane);
Stage subdivStage = new Stage(StageStyle.UTILITY);
subdivStage.setTitle(editMaterialItem.getText());
subdivStage.setScene(subdivScene);
subdivStage.initOwner(Nomad3DEditor.getInstance().getStage());
final double lineHeight = 30;
GridPane childPane = new GridPane();
childPane.setVgap(5);
childPane.setHgap(10);
childPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, childPane);
childPane.setPrefHeight(2 * lineHeight);
GridPane.setMargin(childPane, new Insets(10));
Label childLabel = new Label("Children : ");
childLabel.setPrefWidth(500);
Label nameLabel = new Label("Name");
nameLabel.setPrefWidth((childLabel.getPrefWidth() - childPane.getHgap()) / 2);
nameLabel.setAlignment(Pos.CENTER);
nameLabel.setTextAlignment(TextAlignment.CENTER);
Label meshLabel = new Label("STL file");
meshLabel.setPrefWidth((childLabel.getPrefWidth() - childPane.getHgap()) / 2);
meshLabel.setAlignment(Pos.CENTER);
meshLabel.setTextAlignment(TextAlignment.CENTER);
Button addButton = new Button("Add");
addButton.setPrefSize(40, lineHeight);
addButton.setAlignment(Pos.CENTER_RIGHT);
addButton.setTextAlignment(TextAlignment.CENTER);
addButton.setOnAction(addEvent -> {
SubdividedChild newChild = new SubdividedChild();
subdividedChilds.push(newChild);
int colCount = 20;
TextField nameField = new TextField();
nameField.setPrefColumnCount(colCount);
nameField.setPrefHeight(lineHeight);
newChild.name.bind(nameField.textProperty());
TextField meshField = new TextField();
meshField.setPrefColumnCount(colCount);
meshField.setPrefHeight(lineHeight);
newChild.path.bind(meshField.textProperty());
Button browseButton = new Button("Browse Files");
browseButton.setPrefSize(80, lineHeight);
browseButton.setOnAction(browseEvent -> {
FileChooser chooser = new FileChooser();
chooser.setTitle("Open Model");
if (!meshField.getText().isEmpty()) {
File meshFile = new File(meshField.getText());
if (meshFile.exists() && meshFile.getParentFile() != null
&& meshFile.getParentFile().exists()) {
chooser.setInitialDirectory(meshFile.getParentFile());
}
}
chooser.getExtensionFilters().addAll(new ExtensionFilter("STL files", "*.STL"));
File selectedFile = chooser.showOpenDialog(null);
if (selectedFile != null) {
meshField.setText(selectedFile.getAbsolutePath());
if (nameField.getText().isEmpty()) {
nameField.setText(FilenameUtils.removeExtension(selectedFile.getName()));
}
}
});
childPane.addRow(subdividedChilds.size() + 1, nameField, meshField, browseButton);
childPane.setPrefHeight(childPane.getPrefHeight() + lineHeight);
subdivStage.setHeight(subdivStage.getHeight() + lineHeight);
});
childPane.addColumn(0, childLabel);
childPane.addColumn(2, addButton);
GridPane.setColumnSpan(childLabel, 2);
GridPane.setMargin(addButton, new Insets(0, 0, 0, 40));
childPane.addRow(1, nameLabel, meshLabel);
childPane.setPrefWidth(childLabel.getPrefWidth() + 2 * addButton.getPrefWidth() + 2 * childPane.getHgap());
int initLines = 1;
for (int i = 0; i < initLines; i++) {
addButton.getOnAction().handle(null);
}
GridPane buttonsPane = new GridPane();
buttonsPane.setVgap(5);
buttonsPane.setHgap(10);
buttonsPane.setAlignment(Pos.CENTER);
scenePane.addRow(1, buttonsPane);
GridPane.setMargin(buttonsPane, new Insets(10));
Button okButton = new Button("OK");
okButton.setDefaultButton(true);
okButton.setOnAction(okEvent -> {
try {
// TODO remove traces
System.out.println(subdividedChilds);
Path tmpDirPath = Files.createTempDirectory("nomad-3d-editor-subdivision-");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
Logger.getLogger("nomad-3d").info("Creating temporary directory " + tmpDirPath + " for STL files");
for (SubdividedChild child : subdividedChilds) {
try {
File inFile = new File(child.path.get());
File tmpFile = new File(tmpDir, inFile.getName());
Files.copy(inFile.toPath(), tmpFile.toPath());
tmpFile.deleteOnExit();
Logger.getLogger("nomad-3d").info("Copy : " + inFile + " --> " + tmpFile);
} catch (Exception e) {
// Empty fields are ignored
if (!child.name.get().isEmpty() && !child.path.get().isEmpty()) {
Logger.getLogger("nomad-3d").severe(e.getMessage());
e.printStackTrace();
}
}
}
// Convert geometries
File modelDir = new File(Nomad3DEditor.getInstance().getModel().getDirectoryPath());
String blenderExe = "blender";
if (System.getProperty("os.name").toUpperCase().startsWith("WIN")) {
blenderExe = "C:\\Program Files\\Blender Foundation\\Blender\\blender.exe";
}
double decimateRatio = 0.5;
String converterPath = ".." + File.separator + "nomad-3d-converter";
// Call the blender script
ProcessBuilder builder = new ProcessBuilder(blenderExe, "--background", "--python",
converterPath + File.separator + "scripts" + File.separator + "simplify.py",
tmpDir.toString(), modelDir.toString(), Double.toString(decimateRatio));
builder.inheritIO();
// builder.redirectOutput(ProcessBuilder.Redirect.appendTo(BLENDER_LOG_FILE));
// builder.redirectError(ProcessBuilder.Redirect.appendTo(BLENDER_LOG_FILE));
Logger.getLogger("nomad-3d").info("Executing command : \n" + builder.command());
Process blenderProcess = builder.start();
int exitValue = blenderProcess.waitFor();
Logger.getLogger("nomad-3d").info("Blender exit value : " + exitValue);
// Add new components to the model
Logger.getLogger("nomad-3d").info("Adding new components to the model...");
for (SubdividedChild subChild : subdividedChilds) {
Component child = new Component();
child.setName(subChild.name.get());
child.setFileName(FilenameUtils.removeExtension(new File(subChild.path.get()).getName()));
boolean fixed = false;
ConfigParams parentConfig = selectedComponent.getConfiguration();
ConfigParams config = new ConfigParams(child);
config.setName(parentConfig.getName());
config.setTranslation(parentConfig.getTranslation().clone());
config.setRotation(parentConfig.getRotation().clone());
config.setScale(parentConfig.getScale().clone());
config.setVisible(parentConfig.isVisible());
config.setFixed(parentConfig.isFixed());
fixed |= config.isFixed();
child.setConfiguration(config);
child.setMaterial(selectedComponent.getMaterial());
child.setAxis(((fixed) ? Axis.FIXED_AXIS : Axis.FREE_AXIS).clone());
selectedComponent.addChild(child);
}
Logger.getLogger("nomad-3d").info("New components added.");
updateScene();
} catch (Exception e) {
e.printStackTrace();
} finally {
subdividedChilds.clear();
subdivStage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(cancelEvent -> {
subdividedChilds.clear();
subdivStage.close();
});
buttonsPane.addRow(0, okButton, cancelButton);
subdivStage.show();
});
MenuItem insertComponentItem = new MenuItem("Insert component");
insertComponentItem.setOnAction(event -> {
if (!modelLoaded()) {
return;
}
Component selectedComponent = selectComponent(insertComponentItem.getText());
if (selectedComponent == null) {
return;
}
// TODO refactor : a lot of the following code is a copy/paste from
// subdivideComponentItem
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.TOP_CENTER);
Scene insertScene = new Scene(scenePane);
Stage insertStage = new Stage(StageStyle.UTILITY);
insertStage.setTitle(insertComponentItem.getText());
insertStage.setScene(insertScene);
insertStage.initOwner(Nomad3DEditor.getInstance().getStage());
final double lineHeight = 30;
GridPane childPane = new GridPane();
childPane.setVgap(5);
childPane.setHgap(10);
childPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, childPane);
childPane.setPrefHeight(2 * lineHeight);
GridPane.setMargin(childPane, new Insets(10));
Label nameLabel = new Label("Name : ");
nameLabel.setPrefWidth(50);
Label meshLabel = new Label("STL file : ");
meshLabel.setPrefWidth(nameLabel.getPrefWidth());
int colCount = 20;
TextField nameField = new TextField();
nameField.setPrefColumnCount(colCount);
nameField.setPrefHeight(lineHeight);
TextField meshField = new TextField();
meshField.setPrefColumnCount(colCount);
meshField.setPrefHeight(lineHeight);
Button browseButton = new Button("Browse files");
browseButton.setPrefSize(80, lineHeight);
browseButton.setOnAction(browseEvent -> {
FileChooser chooser = new FileChooser();
chooser.setTitle("Open Model");
if (!meshField.getText().isEmpty()) {
File meshFile = new File(meshField.getText());
if (meshFile.exists() && meshFile.getParentFile() != null && meshFile.getParentFile().exists()) {
chooser.setInitialDirectory(meshFile.getParentFile());
}
}
chooser.getExtensionFilters().addAll(new ExtensionFilter("STL files", "*.STL"));
File selectedFile = chooser.showOpenDialog(null);
if (selectedFile != null) {
meshField.setText(selectedFile.getAbsolutePath());
if (nameField.getText().isEmpty()) {
nameField.setText(FilenameUtils.removeExtension(selectedFile.getName()));
}
}
});
childPane.addRow(0, nameLabel, nameField);
childPane.addRow(1, meshLabel, meshField, browseButton);
childPane.setPrefWidth(450);
GridPane buttonsPane = new GridPane();
buttonsPane.setVgap(5);
buttonsPane.setHgap(10);
buttonsPane.setAlignment(Pos.CENTER);
scenePane.addRow(1, buttonsPane);
GridPane.setMargin(buttonsPane, new Insets(10));
Button okButton = new Button("OK");
okButton.setDefaultButton(true);
okButton.setOnAction(okEvent -> {
try {
Path tmpDirPath = Files.createTempDirectory("nomad-3d-editor-insertion-");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
Logger.getLogger("nomad-3d").info("Creating temporary directory " + tmpDirPath + " for STL files");
try {
File inFile = new File(meshField.getText());
File tmpFile = new File(tmpDir, inFile.getName());
Files.copy(inFile.toPath(), tmpFile.toPath());
tmpFile.deleteOnExit();
Logger.getLogger("nomad-3d").info("Copy : " + inFile + " --> " + tmpFile);
} catch (Exception e) {
// Empty fields are ignored
if (!nameField.getText().isEmpty() && !meshField.getText().isEmpty()) {
Logger.getLogger("nomad-3d").severe(e.getMessage());
e.printStackTrace();
}
}
// Convert geometries
File modelDir = new File(Nomad3DEditor.getInstance().getModel().getDirectoryPath());
String blenderExe = "blender";
if (System.getProperty("os.name").toUpperCase().startsWith("WIN")) {
blenderExe = "C:\\Program Files\\Blender Foundation\\Blender\\blender.exe";
}
double decimateRatio = 0.5;
String converterPath = ".." + File.separator + "nomad-3d-converter";
// Call the blender script
ProcessBuilder builder = new ProcessBuilder(blenderExe, "--background", "--python",
converterPath + File.separator + "scripts" + File.separator + "simplify.py",
tmpDir.toString(), modelDir.toString(), Double.toString(decimateRatio));
builder.inheritIO();
// builder.redirectOutput(ProcessBuilder.Redirect.appendTo(BLENDER_LOG_FILE));
// builder.redirectError(ProcessBuilder.Redirect.appendTo(BLENDER_LOG_FILE));
Logger.getLogger("nomad-3d").info("Executing command : \n" + builder.command());
Process blenderProcess = builder.start();
int exitValue = blenderProcess.waitFor();
Logger.getLogger("nomad-3d").info("Blender exit value : " + exitValue);
// Add new components to the model
Logger.getLogger("nomad-3d").info("Inserting the new component in the model...");
Component child = new Component();
child.setName(nameField.getText());
child.setFileName(FilenameUtils.removeExtension(new File(meshField.getText()).getName()));
boolean fixed = false;
ConfigParams parentConfig = selectedComponent.getConfiguration();
ConfigParams config = new ConfigParams(child);
config.setName(parentConfig.getName());
config.setTranslation(parentConfig.getTranslation().clone());
config.setRotation(parentConfig.getRotation().clone());
config.setScale(parentConfig.getScale().clone());
config.setVisible(parentConfig.isVisible());
config.setFixed(parentConfig.isFixed());
fixed |= config.isFixed();
child.setConfiguration(config);
child.setMaterial(selectedComponent.getMaterial());
child.setAxis(((fixed) ? Axis.FIXED_AXIS : Axis.FREE_AXIS).clone());
selectedComponent.addChild(child);
Logger.getLogger("nomad-3d").info("New component inserted.");
updateScene();
} catch (Exception e) {
e.printStackTrace();
} finally {
insertStage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(cancelEvent -> {
insertStage.close();
});
buttonsPane.addRow(0, okButton, cancelButton);
insertStage.show();
});
MenuItem saveConfigItem = new MenuItem("Save current configuration");
saveConfigItem.setOnAction(event -> {
GridPane scenePane = new GridPane();
......@@ -2589,9 +2217,8 @@ public class EditorMenuBar extends MenuBar {
modifyStage.showAndWait();
});
// 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, new SeparatorMenuItem(), displayReferenceAxesItem, addReferenceAxisItem,
......@@ -2871,35 +2498,17 @@ public class EditorMenuBar extends MenuBar {
movePane.addRow(1, diagonalLabel, typeBox, valueField, unitLabel);
class Apply {
void doIt() {
// Check the selection.
if (Nomad3DEditor.getInstance().getModel() == null
|| Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
hideBBDiagonal = Double.parseDouble(valueField.getText());
if (hideBBType.equals(LESS_THAN)) {
Nomad3DEditor.getInstance().getModel().hideComponentsUsingBBs(true, hideBBDiagonal);
} else {
Nomad3DEditor.getInstance().getModel().hideComponentsUsingBBs(false, hideBBDiagonal);
}
}
}
typeBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
hideBBType = newValue;
new Apply().doIt();
applyValue(valueField.getText());
}
});
valueField.setOnAction(valueEvent -> {
new Apply().doIt();
applyValue(valueField.getText());
});
mainPane.addRow(0, movePane);
......@@ -3007,6 +2616,22 @@ public class EditorMenuBar extends MenuBar {
this.getMenus().addAll(this.file, this.edit, this.view, this.selection, this.help);
}
private void applyValue(String value) {
// Check the selection.
if (Nomad3DEditor.getInstance().getModel() == null
|| Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
hideBBDiagonal = Double.parseDouble(value);
if (hideBBType.equals(LESS_THAN)) {
Nomad3DEditor.getInstance().getModel().hideComponentsUsingBBs(true, hideBBDiagonal);
} else {
Nomad3DEditor.getInstance().getModel().hideComponentsUsingBBs(false, hideBBDiagonal);
}
}
/**
* Sets the modified flag. Updates the title with a modification or not.
*/
......
......@@ -2,11 +2,9 @@ package fr.ill.ics.n3d.gui;
import java.util.ArrayList;
import fr.ill.ics.n3d.gui.EditorMenuBar.AxisTableEntry;
import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.ReferenceAxis;
import fr.ill.ics.n3d.model.ReferenceAxisList;
import javafx.geometry.Point3D;
import javafx.scene.DepthTest;
import javafx.scene.Group;
......
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