Commit c9529b0e authored by Robert Smith's avatar Robert Smith
Browse files

Implemented JavaFX Mesh Editor



Created a IVizMeshCanvas interface for use by the UI when interacting
with Mesh Editor canvases. The JME3 Mesh Editor now implements this
interface. 

The JavaFX Mesh Editor is now working, although there needs to be a
refactor for the observer pattern to recognize different kinds of
messages, to both fix a bug with the Mesh Element treee viewer and for
performance issues.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 889f344b
......@@ -20,10 +20,10 @@ import org.eclipse.ice.client.common.ActionTree;
import org.eclipse.ice.datastructures.ICEObject.ICEObject;
import org.eclipse.ice.datastructures.form.MeshComponent;
import org.eclipse.ice.viz.service.IVizService;
import org.eclipse.ice.viz.service.geometry.widgets.ShapeTreeView;
import org.eclipse.ice.viz.service.geometry.widgets.TransformationView;
import org.eclipse.ice.viz.service.jme3.mesh.IMeshSelectionListener;
import org.eclipse.ice.viz.service.mesh.datastructures.IMeshVizCanvas;
import org.eclipse.ice.viz.service.mesh.javafx.FXMeshCanvas;
import org.eclipse.ice.viz.service.mesh.javafx.FXMeshVizService;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
......@@ -45,7 +45,6 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
......@@ -185,22 +184,29 @@ public class ICEMeshPage extends ICEFormPage
// Local Declarations
final ScrolledForm form = managedForm.getForm();
GridLayout layout = new GridLayout();
// Setup the layout
// Setup the layout and layout data
layout.numColumns = 1;
form.getBody().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
form.getBody().setLayout(new FillLayout());
// Show the view related views
// Opening the views in order to interact with the geometryEditor
try {
getSite().getWorkbenchWindow().getActivePage()
.showView(MeshElementTreeView.ID);
.showView(ShapeTreeView.ID);
getSite().getWorkbenchWindow().getActivePage()
.showView(TransformationView.ID);
} catch (PartInitException e) {
logger.error(getClass().getName() + " Exception!", e);
}
// Create the geometry composite - get the parent
Form pageForm = managedForm.getForm().getForm();
org.eclipse.ui.forms.widgets.Form pageForm = managedForm.getForm()
.getForm();
Composite parent = pageForm.getBody();
// Set the layout
......@@ -212,31 +218,22 @@ public class ICEMeshPage extends ICEFormPage
new GridData(SWT.FILL, SWT.BEGINNING, true, false));
actionToolBarManager = new ToolBarManager(toolBar);
// Grid data so that the VizCanvas will fill the entire area
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
// Get the JME3 viz service for meshes
// IVizService service = editor.getVizServiceFactory()
// .get("JME3 Mesh Service");
// TODO Get this service through OSGI
// Get JME3 Geometry service from factory
// IVizServiceFactory factory = editor.getVizServiceFactory();
IVizService service = new FXMeshVizService();
// Create the VizCanvas
canvas = null;
try {
// canvas = (JME3MeshCanvas)
// service.createCanvas(meshComp.getMesh());
canvas = (FXMeshCanvas) service.createCanvas(meshComp.getMesh());
} catch (Exception e) {
logger.error("Mesh Viz Service failed to create mesh Viz Canvas.");
}
// Composite editorComposite = new Composite(parent, SWT.NONE);
// Draw the canvas and set its layout data
// Create and draw geometry canvas
try {
canvas = (IMeshVizCanvas) service.createCanvas(meshComp.getMesh());
Composite composite = canvas.draw(parent);
composite.setLayoutData(gridData);
composite.setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
} catch (Exception e) {
logger.error("Error drawing Mesh Viz Canvas.");
logger.error(
"Error creating Geometry Canvas with Geometry Service.", e);
}
// The MeshPage should also listen for changes to the MeshApplication's
......@@ -262,6 +259,7 @@ public class ICEMeshPage extends ICEFormPage
.addSelectionListener(MeshElementTreeView.ID, this);
return;
}
/**
......@@ -311,16 +309,35 @@ public class ICEMeshPage extends ICEFormPage
// TODO Add actions for toggling the hud based on JME3/JavaFX specific
// implementation
// Create the toggle switch to show or hide the heads-up display
action = new org.eclipse.ice.viz.service.jme3.mesh.ToggleHUDAction(
canvas);
// action = new org.eclipse.ice.viz.service.jme3.mesh.ToggleHUDAction(
// canvas);
action = new Action() {
@Override
public void run() {
canvas.setVisibleHUD(!canvas.HUDIsVisible());
}
};
action.setText("Toggle HUD");
toggleHUDActionTree = new ActionTree(action);
actions.add(toggleHUDActionTree);
// TODO Add the action for toggling the axes based on JME3/JavaFX
// specific implementation
// Create the toggle switch to show or hide the axes.
action = new org.eclipse.ice.viz.service.jme3.mesh.ToggleAxesAction(
canvas);
// action = new org.eclipse.ice.viz.service.jme3.mesh.ToggleAxesAction(
// canvas);
action = new Action() {
@Override
public void run() {
canvas.setVisibleAxis(!canvas.AxisAreVisible());
}
};
action.setText("Toggle Axis");
toggleAxesActionTree = new ActionTree(action);
actions.add(toggleAxesActionTree);
......@@ -461,4 +478,4 @@ public class ICEMeshPage extends ICEFormPage
}
// ----------------------------------------------------------- //
}
}
\ No newline at end of file
......@@ -25,6 +25,8 @@ import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.AbstractMeshComponent;
import org.eclipse.ice.viz.service.modeling.AbstractView;
import org.eclipse.ice.viz.service.modeling.Face;
/**
......@@ -71,7 +73,8 @@ public class MeshComponent extends ICEObject
*/
public MeshComponent() {
super();
mesh = new AbstractController();
mesh = new AbstractController(new AbstractMeshComponent(),
new AbstractView());
mesh.register(this);
return;
}
......
......@@ -18,6 +18,8 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
import javafx.scene.Group;
/**
* <p>
* JFace Viewer base for GeometryViewer implementations.
......@@ -28,148 +30,156 @@ import org.eclipse.swt.widgets.Composite;
*/
public abstract class GeometryViewer extends Viewer {
/** The parent the viewer is created on. */
protected final Composite parent;
/** The current input model node. */
protected INode input;
/** The active scene selection. */
private ISelection selection;
/** The active renderer. */
protected IRenderer renderer;
/** The active camera. */
protected ICamera activeCamera;
/**
* <p>
* Creates a new GeometryViewer.
* </p>
*
* @param parent
* the parent widget to create the viewer in
*/
public GeometryViewer(Composite parent) {
this.parent = parent;
createControl(parent);
}
/**
* <p>
* Returns the renderer for this viewer.
* </p>
*
* @return the renderer for this viewer.
*/
public IRenderer getRenderer() {
return renderer;
}
/**
* <p>
* Creates the control that backs this viewer, to be implemented by
* subclasses.
* </p>
*
* @param parent
* the parent widget that owns the viewer control.
*/
protected abstract void createControl(Composite parent);
/**
* <p>
* Returns the active input scene model object.
* </p>
*
* @see Viewer#getInput()
*/
@Override
public Object getInput() {
return input;
}
/**
* <p>
* Sets the active scene, supports either INode or IScene.
* </p>
*/
@Override
public void setInput(Object newInput) {
if (newInput == input) {
return;
}
if (newInput == null) {
newInput = null;
} else if (!ModelUtil.isNode(newInput)) {
throw new IllegalArgumentException(Messages.GeometryViewer_InvalidInput);
}
Object oldInput = input;
this.input = (INode) newInput;
// Fire the inputChanged event
inputChanged(oldInput, this.input);
}
/**
* <p>
* Returns the currently active selection in the scene.
* </p>
*/
@Override
public ISelection getSelection() {
return selection;
}
/**
* <p>
* Sets the selection in the scene.
* </p>
*/
@Override
public void setSelection(ISelection selection, boolean makeVisible) {
this.selection = selection;
fireSelectionChanged(new SelectionChangedEvent(this, selection));
}
/**
* <p>
* Sets the active camera displayed by the viewer.
* </p>
*
* @param camera
* the camera to use to display the viewer
*/
public void setCamera(ICamera camera) {
this.activeCamera = camera;
updateCamera(camera);
}
/**
* <p>
* Updates the active camera.
* </p>
*
* @param camera
* the camera to use in the scene.
*/
protected abstract void updateCamera(ICamera camera);
/**
* <p>
* Return the active camera.
* </p>
*
* @return the active camera
*/
public ICamera getCamera() {
return this.activeCamera;
}
/** The parent the viewer is created on. */
protected final Composite parent;
/** The current input model node. */
protected INode input;
/** The active scene selection. */
private ISelection selection;
/** The active renderer. */
protected IRenderer renderer;
/** The active camera. */
protected ICamera activeCamera;
/**
* <p>
* Creates a new GeometryViewer.
* </p>
*
* @param parent
* the parent widget to create the viewer in
*/
public GeometryViewer(Composite parent) {
this.parent = parent;
createControl(parent);
}
/**
* <p>
* Returns the renderer for this viewer.
* </p>
*
* @return the renderer for this viewer.
*/
public IRenderer getRenderer() {
return renderer;
}
/**
* <p>
* Creates the control that backs this viewer, to be implemented by
* subclasses.
* </p>
*
* @param parent
* the parent widget that owns the viewer control.
*/
protected abstract void createControl(Composite parent);
/**
* <p>
* Returns the active input scene model object.
* </p>
*
* @see Viewer#getInput()
*/
@Override
public Object getInput() {
return input;
}
/**
* <p>
* Sets the active scene, supports either INode or IScene.
* </p>
*/
@Override
public void setInput(Object newInput) {
if (newInput == input) {
return;
}
if (newInput == null) {
newInput = null;
} else if (!ModelUtil.isNode(newInput)) {
throw new IllegalArgumentException(
Messages.GeometryViewer_InvalidInput);
}
Object oldInput = input;
this.input = (INode) newInput;
// Fire the inputChanged event
inputChanged(oldInput, this.input);
}
/**
* <p>
* Returns the currently active selection in the scene.
* </p>
*/
@Override
public ISelection getSelection() {
return selection;
}
/**
* <p>
* Sets the selection in the scene.
* </p>
*/
@Override
public void setSelection(ISelection selection, boolean makeVisible) {
this.selection = selection;
fireSelectionChanged(new SelectionChangedEvent(this, selection));
}
/**
* <p>
* Sets the active camera displayed by the viewer.
* </p>
*
* @param camera
* the camera to use to display the viewer
*/
public void setCamera(ICamera camera) {
this.activeCamera = camera;
updateCamera(camera);
}
/**
* <p>
* Updates the active camera.
* </p>
*
* @param camera
* the camera to use in the scene.
*/
protected abstract void updateCamera(ICamera camera);
/**
* <p>
* Return the active camera.
* </p>
*
* @return the active camera
*/
public ICamera getCamera() {
return this.activeCamera;
}
/**
* Gets the topmost node in the scene graph.
*
* @return The scene graph's root node
*/
public abstract Group getRoot();
}
......@@ -12,6 +12,7 @@ package org.eclipse.ice.viz.service.javafx.internal;
import org.eclipse.ice.viz.service.geometry.scene.base.ISceneGenerator;
import org.eclipse.ice.viz.service.geometry.scene.model.INode;
import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.Viewer;
......@@ -29,80 +30,85 @@ import javafx.scene.Node;
*/
public class FXContentProvider implements IContentProvider {
/** Used to generate the JavaFX scene from the input model. */
private ISceneGenerator sceneGenerator;
/**
* <p>
* Generates a JavaFX scene from the input model.
* </p>
*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer viewer, Object input, Object oldInput) {
verifyInput(viewer, input, oldInput);
FXGeometryViewer fxViewer = (FXGeometryViewer) viewer;
INode newRoot = (INode) input;
Group fxRoot = fxViewer.getRoot();
if (sceneGenerator == null) {
sceneGenerator = new FXSceneGenerator();
}
Node generatedRoot = sceneGenerator.generateScene(newRoot);
fxRoot.getChildren().setAll(generatedRoot);
}
/**
* <p>
* Verifies the model inputs for sanity.
* </p>
*
* @param viewer
* the viewer being modified
* @param input
* the new input
* @param oldInput
* the old input
*/
private void verifyInput(Viewer viewer, Object input, Object oldInput) {
if (!(viewer instanceof FXGeometryViewer)) {
throw new IllegalArgumentException(Messages.FXContentProvider_InvalidViewerType);
}
if (!(input instanceof INode)) {
throw new IllegalArgumentException(Messages.FXContentProvider_InvalidInputType);
}
if (oldInput != null && !(oldInput instanceof INode)) {
throw new IllegalArgumentException(Messages.FXContentProvider_InvalidInputNode);
}
}
/**
* <p>
* Disposes the Viewer input.
* </p>
*/
public void dispose() {
}
/**
*
*/
public ISceneGenerator getGenerator() {
return sceneGenerator;
}
/**
*
*/
public void setGenerator(ISceneGenerator generator) {
this.sceneGenerator = generator;
}
/** Used to generate the JavaFX scene from the input model. */
private ISceneGenerator sceneGenerator;
/**
* <p>
* Generates a JavaFX scene from the input model.
* </p>
*
* @see IContentProvider#inputChanged(Viewer, Object, Object)
*/
@Override
public void inputChanged(Viewer viewer, Object input, Object oldInput) {