The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit cb0664bf authored by Bordais Anaelle's avatar Bordais Anaelle
Browse files

Function to set cam view works

parent bc079e70
......@@ -534,7 +534,7 @@ public class Nomad3DEditor extends Application {
axisGroup.getChildren().addAll(xAxis, yAxis, zAxis);
axisGroup.setVisible(true);
// root.getChildren().add(axisGroup);
//root.getChildren().add(axisGroup);
return axisGroup;
}
......@@ -590,6 +590,7 @@ public class Nomad3DEditor extends Application {
camera.setNearClip(0.1);
camera.setFarClip(Double.MAX_VALUE);
subScene.setCamera(camera);
}
/**
......
package fr.ill.ics.n3d.gui;
import fr.ill.ics.n3d.Nomad3DEditor;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.Model;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Point3D;
import javafx.scene.Camera;
......@@ -64,17 +68,17 @@ public class CameraControls {
* Default constructor.
*/
public CameraControls() {
this.longitude = 0;
this.latitude = 45; // 45 de base
this.longitude = 180;
this.latitude = 45;
this.center = new Point3D(0, 0, 0);
this.radius = 100; //100 de base
this.radius = 100;
this.target = null;
this.centerNode = null;
this.controlMultiplier = 10;
this.shiftMultiplier = 0.1;
this.rotationSensitivity = 0.1;
this.translationSensitivity = 0.0; //0.25 de base
this.translationSensitivity = 0.25;
this.zoomSensitivity = 0.5;
this.setResolution(new Point2D(1280, 720));
......@@ -101,8 +105,8 @@ public class CameraControls {
this.transform = cam.getTransform();
this.centerTransform = cam.getCenterTransform();
}
/**
* Gets the longitude.
* @return The longitude
......@@ -422,10 +426,9 @@ public class CameraControls {
*/
public void update() {
System.out.println("Vue Avant corps update: \n "+"resolution"+ resolution+ "center " + center + ", angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
target.getTransforms().remove(transform);
transform.setToIdentity();
if (centerNode != null) {
centerNode.getTransforms().remove(centerTransform);
......@@ -433,50 +436,26 @@ public class CameraControls {
centerTransform = new Translate(center.getX(), center.getY(), center.getZ());
transform.append(centerTransform);
Rotate rx = new Rotate(longitude, Rotate.Y_AXIS);
transform.append(rx);
System.out.println("YAXIS ROT: \n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
Rotate ry = new Rotate(latitude, Rotate.X_AXIS);
transform.append(ry);
System.out.println("XAXIS ROT \n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
Rotate rz = new Rotate(180, Rotate.Z_AXIS);//180 de base
Rotate rz = new Rotate(180, Rotate.Z_AXIS);
transform.append(rz);
System.out.println("ZAXIS ROT \n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
Translate t = new Translate(-resolution.getX()/2, -resolution.getY()/2, radius); // de base avec radius
Translate t = new Translate(-resolution.getX()/2, -resolution.getY()/2, radius);
transform.append(t);
System.out.println("TRANSLATE RESOLUTION\n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
// Translate t2 = new Translate(0, 0, radius); // elle n'y est pas
// transform.append(t2);
// System.out.println("TRANSLATE RADIUS \n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
// System.out.println("Transform matrix : "+ transform);
// System.out.println("Center transform matrix :" + centerTransform);
//
target.getTransforms().add(transform);
if (centerNode != null) {
centerNode.getTransforms().add(centerTransform);
}
System.out.println("APRES TOUT UPDATE: \n "+"resolution"+ resolution+ "center " + center + "\n angles " + longitude + ", " + latitude + ", radius " + radius);
System.out.println("Transform matrix : "+ transform);
System.out.println("Center transform matrix :" + centerTransform);
//System.out.println(target.);
System.out.println("-----------------------------------------------------");
System.out.println("view direction" + viewDirection());
}
......
package fr.ill.ics.n3d.gui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
......@@ -16,7 +19,9 @@ import java.util.Scanner;
import java.util.Set;
import java.util.logging.Logger;
import fr.ill.ics.n3d.util.CameraTableExporter;
import fr.ill.ics.n3d.Nomad3DEditor;
import fr.ill.ics.n3d.gui.EditorMenuBar.CameraTableEntry;
import fr.ill.ics.n3d.io.Nomad3DExporter;
import fr.ill.ics.n3d.io.Nomad3DImporter;
import fr.ill.ics.n3d.link.Nomad3DController;
......@@ -46,6 +51,7 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
......@@ -66,7 +72,9 @@ import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.Slider;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
......@@ -87,6 +95,7 @@ import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Callback;
import javafx.util.converter.DoubleStringConverter;
import javafx.geometry.Point3D;
......@@ -110,7 +119,6 @@ public class EditorMenuBar extends MenuBar {
/** Selection menu. */
private Menu selection;
// -------- JE RAJOUTE---------
/**CameraView menu**/
private Menu cameraView;
......@@ -243,6 +251,65 @@ public class EditorMenuBar extends MenuBar {
}
}
/**
* A new Camera class to copy the original camera parameters into SimpleDoubleProperty type
* to put them into the table used in "Set Camera POVs"
*/
public static class CameraTableEntry {
private final SimpleDoubleProperty x;
private final SimpleDoubleProperty y;
private final SimpleDoubleProperty z;
private final SimpleDoubleProperty xrot;
private final SimpleDoubleProperty yrot;
private final SimpleDoubleProperty zrot;
private final SimpleDoubleProperty radius ;
private CameraControls originalCamera;
private CameraTableEntry(CameraControls camera) {
super();
this.x = new SimpleDoubleProperty(camera.getCenter().getX());
this.y = new SimpleDoubleProperty(camera.getCenter().getY());
this.z = new SimpleDoubleProperty(camera.getCenter().getZ());
this.xrot = new SimpleDoubleProperty(camera.getLatitude());
this.yrot = new SimpleDoubleProperty(camera.getLongitude());
this.zrot = new SimpleDoubleProperty(180.0);
this.radius = new SimpleDoubleProperty(camera.getRadius());
this.originalCamera = new CameraControls(camera);
}
public Double getX() {
return Math.round(x.get()*1000)/1000.0; // round to 3 decimal digits
}
public Double getY() {
return Math.round(y.get()*1000)/1000.0;
}
public Double getZ() {
return Math.round(z.get()*1000)/1000.0;
}
public Double getXrot() {
return Math.round(xrot.get()*1000)/1000.0;
}
public Double getYrot() {
return Math.round(yrot.get()*1000)/1000.0;
}
public Double getZrot() {
return Math.round(zrot.get()*1000)/1000.0;
}
public Double getRadius() {
return Math.round(radius.get()*1000)/1000.0;
}
public CameraControls getCam() {
return originalCamera;
}
}
private static boolean isAxisDefined(String controllerName, List<AxisInfo> axisInfos) {
for (AxisInfo info : axisInfos) {
......@@ -253,7 +320,9 @@ public class EditorMenuBar extends MenuBar {
return false;
}
/**
* Constructor.
*/
......@@ -2686,185 +2755,138 @@ public class EditorMenuBar extends MenuBar {
});
this.help.getItems().addAll(cameraHelpItem, wikiItem);
update();
// update(); PK UPDATE ICI ? IL ETAIT A LA FIN AU DEBUT ??
//--------- RAJOUTE-----------
this.cameraView = new Menu("Camera View");
MenuItem setCamViewItem = new MenuItem("Set Camera POVs");
setCamViewItem.setOnAction(e->{
// if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getRoot() == null) {
// return;
// }
GridPane scenePane = new GridPane();
scenePane.setPadding(new Insets(30));
// There must be an object/model in the scene to be able to use the button Set Camera POVs
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getRoot() == null) {
return;
}
VBox scenePane = new VBox();
Scene displayScene = new Scene(scenePane);
Stage displayStage = new Stage(StageStyle.UTILITY);
displayStage.setTitle(setCamViewItem.getText());
displayStage.setScene(displayScene);
displayStage.initOwner(Nomad3DEditor.getInstance().getStage());
TableView<CameraControls> table = new TableView();
//table.setEditable(true);
// // Set column
TableColumn<CameraControls, Point3D > firstColumn = new TableColumn<>("Center");
firstColumn.setMinWidth(300);
// TableColumn xcol = new TableColumn("xcol");
// xcol.setMinWidth(130);
//
//
// TableColumn ycol = new TableColumn("ycol");
// ycol.setMinWidth(130);
// xcol.setCellValueFactory(new PropertyValueFactory<CameraControls, Point3D.Double>("x"));
// ycol.setCellValueFactory(new PropertyValueFactory<Point3D, Double>("y"));
// firstColumn.getColumns().addAll(xcol, ycol);
TableView<CameraTableEntry> table = new TableView();
TableColumn centerCol = new TableColumn("Center");
TableColumn xcol = new TableColumn<>("x");
xcol.setMinWidth(100);
xcol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("x"));
xcol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
TableColumn ycol = new TableColumn<>("y");
ycol.setMinWidth(100);
ycol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("y"));
ycol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
TableColumn zcol = new TableColumn<>("z");
zcol.setMinWidth(100);
zcol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("z"));
zcol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
firstColumn.setCellValueFactory(new PropertyValueFactory<CameraControls, Point3D>("center"));
TableColumn<CameraControls, Double > column2 = new TableColumn<>("Latitude");
column2.setMinWidth(100);
column2.setCellValueFactory(new PropertyValueFactory<CameraControls, Double>("latitude"));
TableColumn<CameraControls, Double > column3 = new TableColumn<>("Longitude");
column3.setMinWidth(100);
column3.setCellValueFactory(new PropertyValueFactory<CameraControls, Double>("Longitude"));
TableColumn<CameraControls, Double > column4 = new TableColumn<>("Radius");
column4.setMinWidth(100);
column4.setCellValueFactory(new PropertyValueFactory<CameraControls, Double>("radius"));
// Add subcolumns x,y,z to column center
centerCol.getColumns().addAll(xcol, ycol, zcol);
final ObservableList<CameraControls> data = FXCollections.observableArrayList();
TableColumn xRotCol = new TableColumn<>("X Rotation");
xRotCol.setMinWidth(100);
xRotCol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("xrot"));
xRotCol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
TableColumn yRotCol = new TableColumn<>("Y Rotation");
yRotCol.setMinWidth(100);
yRotCol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("yrot"));
yRotCol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
TableColumn zRotCol = new TableColumn<>("Z Rotation");
zRotCol.setMinWidth(100);
zRotCol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("zrot"));
zRotCol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
TableColumn radiusCol = new TableColumn<>("Radius");
radiusCol.setMinWidth(100);
radiusCol.setCellValueFactory(new PropertyValueFactory<CameraTableEntry, Double>("radius"));
radiusCol.setCellFactory(TextFieldTableCell.forTableColumn(new CustomDoubleStringConverter()));
//Button
Button addButton = new Button("Add");
Button deleteButton = new Button("Delete");
final ObservableList<CameraTableEntry> data = FXCollections.observableArrayList();
//Buttons
Button addButton = new Button("Add view");
Button deleteButton = new Button("Delete view");
Button exportButton = new Button ("Export camera views");
Button viewButton = new Button("See camera view");
// Buttons actions
addButton.setOnAction(event->{
CameraControls cam = Nomad3DEditor.getInstance().getControls();
// Point3D center = cam.getCenter();
// double latitude = cam.getLatitude();
// double longitude = cam.getLongitude();
// double radius = cam.getRadius();
CameraControls newCam = new CameraControls(cam);
data.add(newCam);
// We create a fictiveCam of type CameraTableEntry with parameters that are SimpleDoubleProperty instead of double
// In order to put the parameters in the table
CameraTableEntry fictiveCam = new CameraTableEntry(cam);
data.add(fictiveCam);
});
deleteButton.setOnAction(event->{
ObservableList<CameraControls> camSelected, allCams;
ObservableList<CameraTableEntry> camSelected, allCams;
allCams = table.getItems(); // gets all the items in the table
camSelected = table.getSelectionModel().getSelectedItems();
camSelected.forEach(allCams::remove);
});
exportButton.setOnAction(event->{
// // TO DO
// FileChooser fileChooser = new FileChooser();
// fileChooser.setTitle("Open Resource File");
// File file = fileChooser.showOpenDialog(displayStage);
//
Stage fileStage = new Stage();
fileStage.setTitle("File path");
fileStage.setWidth(400);
HBox fileBox = new HBox();
Label fileLabel = new Label("File Path : ");
TextField fileInput = new TextField();
fileInput.setPromptText("filepath.txt");
Button createFileButton = new Button("Create file");
fileBox.getChildren().addAll(fileLabel, fileInput, createFileButton);
fileBox.setSpacing(20);
Scene fileScene = new Scene(fileBox);
fileStage.setScene(fileScene);
fileStage.show();
createFileButton.setOnAction(eventButton->{
fileStage.close();
try {
String fileName = fileInput.getText();
File file = new File(fileName);
System.out.println("Filename :" + fileName);
if (file.createNewFile()) {
System.out.println("File has been created.");
} else {
System.out.println("File already exists.");
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
data.forEach((CameraControls)->{
// ----------- TO DO : REVOIR LES CONVERSIONS -----------------
// la distance va pas et le centre non plus, si on change ca marche pas
String radiusString = Double.toString(-CameraControls.getRadius());
String latitudeString = Double.toString((-CameraControls.getLatitude()+180.0)*Math.PI/180);
String longitudeString = Double.toString((-CameraControls.getLongitude()+180.0)*Math.PI/180);
String rotAxisZString = Double.toString((Math.PI));
String xString = Double.toString(-CameraControls.getCenter().getX());
String yString = Double.toString(-CameraControls.getCenter().getY());
String zString = Double.toString(-CameraControls.getCenter().getZ());
exportButton.setOnAction(event->{
CameraTableExporter exporter = new CameraTableExporter();
exporter.export(displayStage, data);
});
try {
bw.write(xString+" ");
bw.write(yString+" ");
bw.write(zString+" ");
bw.write(latitudeString+" ");
bw.write(longitudeString + " ");
bw.write(rotAxisZString + " ");
bw.write(radiusString + " " );
bw.write("\n");}
catch(IOException error) {
}
});
bw.close();}
catch(IOException error) {
}
});});
viewButton.setOnAction(event->{
CameraControls cam = Nomad3DEditor.getInstance().getControls();
System.out.println("resolution : " + cam.getResolution()+"control multiplier :"+ cam.getControlMultiplier() +"center : " + cam.getCenter() + "latitude :" + cam.getLatitude() + "longitude :" + cam.getLongitude() +"radius" + cam.getRadius());
cam = table.getSelectionModel().getSelectedItem();
System.out.println("ligne selectionnée : " + cam);
System.out.println("resolution : " + cam.getResolution()+"control multiplier :"+ cam.getControlMultiplier()+"center : " + cam.getCenter() + "latitude :" + cam.getLatitude() + "longitude :" + cam.getLongitude() +"radius" + cam.getRadius());
System.out.println("Avant Update");
cam.update();
System.out.println("Apres Update, Fin view Butoon action");
table.setRowFactory(tv -> {
// Define our new TableRow
TableRow<CameraTableEntry> row = new TableRow<>();
row.setOnMouseClicked(event -> {
CameraControls cam = Nomad3DEditor.getInstance().getControls();
cam = table.getSelectionModel().getSelectedItem().getCam();
cam.update();
});
return row;
});
// HBOX for buttons
HBox hbox = new HBox();
hbox.setPadding(new Insets(10,10,10,10));
hbox.setSpacing(10);
hbox.getChildren().addAll(addButton, deleteButton, exportButton, viewButton);
hbox.getChildren().addAll(addButton, deleteButton, exportButton);
hbox.setAlignment(Pos.CENTER);
table.setItems(data);
table.getColumns().addAll(firstColumn, column2, column3, column4);
scenePane.addRow(0, table, hbox);
table.getColumns().addAll(centerCol, xRotCol, yRotCol, zRotCol, radiusCol);
//table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
scenePane.getChildren().addAll(table, hbox);
displayStage.show();
});
......@@ -2872,47 +2894,7 @@ public class EditorMenuBar extends MenuBar {
this.cameraView.getItems().addAll(setCamViewItem);
MenuItem sphereItem = new MenuItem("Sphere");
sphereItem.setOnAction(event->{
Sphere sphere = new Sphere(10);
Group roottt = Nomad3DEditor.getInstance().getRoot();
roottt.getChildren().add(sphere);
GridPane scenePane = new GridPane();
scenePane.setPadding(new Insets(30));
Scene displayScene = new Scene(scenePane);
Stage displayStage = new Stage(StageStyle.UTILITY);
displayStage.setTitle(setCamViewItem.getText());
displayStage.setScene(displayScene);
displayStage.initOwner(Nomad3DEditor.getInstance().getStage());
Sphere spherex = new Sphere(10);
spherex.setLayoutX(100);
roottt.getChildren().add(spherex);
Sphere spherey = new Sphere(10);
spherey.setLayoutY(200);
roottt.getChildren().add(spherey);
Sphere spherez = new Sphere(10);
spherez.setTranslateZ(300);
roottt.getChildren().add(spherez);
HBox box = new HBox();
Button radiusButton = new Button("SetRadius");
TextField radiusInput = new TextField();
box.getChildren().addAll(radiusInput, radiusButton);
radiusButton.setOnAction(e->{
sphere.setRadius(Double.parseDouble(radiusInput.getText()));
});
scenePane.addRow(0, box);
displayStage.show();
update();
});
this.cameraView.getItems().addAll(sphereItem);
update();
this.getMenus().addAll(this.file, this.edit, this.view, this.selection, this.cameraView, this.help);
......@@ -3164,6 +3146,7 @@ public class EditorMenuBar extends MenuBar {
private void updateAxes() {
if (modelLoaded()) {
Nomad3DEditor.getInstance().getModel().setVisualizeAxes(showAxes);
}