Commit 515d6efd authored by Robert Smith's avatar Robert Smith
Browse files

Began Geometry Editor refactor



Started changing the JavaFX Geometry Editor to make use of the new
unified modeling data structures. 
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent fd4ae42a
......@@ -21,10 +21,10 @@ import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListen
import org.eclipse.ice.viz.service.geometry.scene.base.GNode;
import org.eclipse.ice.viz.service.geometry.scene.base.GeometryAttachment;
import org.eclipse.ice.viz.service.geometry.scene.model.INode;
import org.eclipse.ice.viz.service.geometry.shapes.Geometry;
import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer;
import org.eclipse.ice.viz.service.geometry.viewer.IRenderer;
import org.eclipse.ice.viz.service.geometry.widgets.TransformationView;
import org.eclipse.ice.viz.service.modeling.Shape;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
......@@ -44,219 +44,231 @@ import org.eclipse.ui.PlatformUI;
*/
public class GeometryCanvas implements IVizCanvas, IVizUpdateableListener {
/** Factory class to be implemented by renderer implementations. */
private static final String GEOMETRY_VIEWER_FACTORY = "org.eclipse.ice.viz.service.geometry.viewer.factory.GeometryViewerFactory";
/**
* Number of dimensions supported for visualization. GeometryCanvas supports
* 3D views.
*/
private static final int SUPPORTED_AXES = 3;
/** The JFace viewer for displaying viz geometry. */
private GeometryViewer viewer;
/** The geometry object that is currently set on the viewer. */
private Geometry geometry;
/** The active rootnode in the scene. */
private INode rootNode;
/** The active root geometry. */
private GeometryAttachment rootGeometry;
/** ICE properties. */
private Map<String, String> properties;
/**
* <p>
* Creates a canvas for the supplied geometry.
* </p>
*
* @param geometry
* ICE Geometry instance to visualizer in the canvas.
*/
public GeometryCanvas(Geometry geometry) {
this.geometry = geometry;
}
/**
* @see IVizCanvas#draw(Composite)
*/
public Composite draw(Composite parent) throws Exception {
Composite viewerParent = new Composite(parent, SWT.NONE);
viewerParent.setLayout(new FillLayout());
this.viewer = materializeViewer(viewerParent);
if (viewer == null) {
throw new Exception(Messages.GeometryCanvas_ErrorCreatingViewer);
}
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findView(TransformationView.ID);
if (view == null || !(view instanceof TransformationView)) {
return;
}
TransformationView transformView = (TransformationView) view;
GeometrySelection selection = (GeometrySelection) event.getSelection();
transformView.setShape(selection.getShape());
}
});
loadGeometry(geometry);
return parent;
}
/**
* <p>
* Fix for Eclipse/PDE's wonky fragment support. Creates a GeometryViewer
* supplied by an implementation fragment.
* </p>
*
* @param viewerParent
* the parent widget
*
* @return a concrete implementation of GeometryViewer
*
* @throws Exception
* throws an exception if a concrete implementation cannot be
* found
*/
private GeometryViewer materializeViewer(Composite viewerParent) throws Exception {
try {
Class<?> viewerFactory = Class.forName(GEOMETRY_VIEWER_FACTORY); //$NON-NLS-1$
if (viewerFactory == null) {
throw new Exception(""); //$NON-NLS-1$
}
Object newInstance = viewerFactory.newInstance();
Method method = newInstance.getClass().getMethod("createViewer", Composite.class); //$NON-NLS-1$
return (GeometryViewer) method.invoke(newInstance, viewerParent);
} catch (Exception e) {
throw new Exception("", e); //$NON-NLS-1$
}
}
/**
* <p>
* Handles the processing and setting up the canvas' supplied geometry for
* visualization.
* </p>
*
* @param geometry
* the geometry to visualize
*/
private void loadGeometry(Geometry geometry) {
if (geometry == null) {
return;
}
this.geometry = geometry;
rootNode = new GNode();
IRenderer renderer = viewer.getRenderer();
rootGeometry = (GeometryAttachment) renderer.createAttachment(GeometryAttachment.class);
rootGeometry.addGeometry(geometry);
rootNode.attach(rootGeometry);
viewer.setInput(rootNode);
// geometry.register(this);
}
/**
* <p>
* Returns the underlying GeometryViewer.
* </p>
*
* @return a GeometryViewer instance that is used to visualize scenes
*/
public GeometryViewer getViewer() {
return viewer;
}
/**
* <p>
* Listens for updates coming in from the geometry provider.
* </p>
*
* @see IVizUpdateable#update
*/
public void update(final IVizUpdateable component) {
// Invoke this on the JavaFX UI thread
javafx.application.Platform.runLater(new Runnable() {
public void run() {
if (component == geometry) {
// rootGeometry.addGeometry(geometry);
}
}
});
}
/**
* @see IVizCanvas#getDataSource()
*/
public URI getDataSource() {
return null;
}
/**
* @see IVizCanvas#getNumberOfAxes()
*/
public int getNumberOfAxes() {
return SUPPORTED_AXES;
}
/**
* @see IVizCanvas#getProperties()
*/
public Map<String, String> getProperties() {
if (properties == null) {
return Collections.emptyMap();
} else {
return properties;
}
}
/**
* @see IVizCanvas#getSourceHost()
*/
public String getSourceHost() {
return null;
}
/**
* @see IVizCanvas#isSourceRemote()
*/
public boolean isSourceRemote() {
return false;
}
/**
* @see IVizCanvas#redraw()
*/
public void redraw() {
}
/**
* @see IVizCanvas#setProperties()
*/
public void setProperties(Map<String, String> props) throws Exception {
this.properties = props;
}
/** Factory class to be implemented by renderer implementations. */
private static final String GEOMETRY_VIEWER_FACTORY = "org.eclipse.ice.viz.service.geometry.viewer.factory.GeometryViewerFactory";
/**
* Number of dimensions supported for visualization. GeometryCanvas supports
* 3D views.
*/
private static final int SUPPORTED_AXES = 3;
/** The JFace viewer for displaying viz geometry. */
private GeometryViewer viewer;
/** The geometry object that is currently set on the viewer. */
private Shape geometry;
/** The active rootnode in the scene. */
private INode rootNode;
/** The active root geometry. */
private GeometryAttachment rootGeometry;
/** ICE properties. */
private Map<String, String> properties;
/**
* <p>
* Creates a canvas for the supplied geometry.
* </p>
*
* @param geometry
* ICE Geometry instance to visualizer in the canvas.
*/
public GeometryCanvas(Shape geometry) {
this.geometry = geometry;
}
/**
* @see IVizCanvas#draw(Composite)
*/
@Override
public Composite draw(Composite parent) throws Exception {
Composite viewerParent = new Composite(parent, SWT.NONE);
viewerParent.setLayout(new FillLayout());
this.viewer = materializeViewer(viewerParent);
if (viewer == null) {
throw new Exception(Messages.GeometryCanvas_ErrorCreatingViewer);
}
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findView(TransformationView.ID);
if (view == null || !(view instanceof TransformationView)) {
return;
}
TransformationView transformView = (TransformationView) view;
GeometrySelection selection = (GeometrySelection) event.getSelection();
transformView.setShape(selection.getShape());
}
});
loadGeometry(geometry);
return parent;
}
/**
* <p>
* Fix for Eclipse/PDE's wonky fragment support. Creates a GeometryViewer
* supplied by an implementation fragment.
* </p>
*
* @param viewerParent
* the parent widget
*
* @return a concrete implementation of GeometryViewer
*
* @throws Exception
* throws an exception if a concrete implementation cannot be
* found
*/
private GeometryViewer materializeViewer(Composite viewerParent) throws Exception {
try {
Class<?> viewerFactory = Class.forName(GEOMETRY_VIEWER_FACTORY); // $NON-NLS-1$
if (viewerFactory == null) {
throw new Exception(""); //$NON-NLS-1$
}
Object newInstance = viewerFactory.newInstance();
Method method = newInstance.getClass().getMethod("createViewer", Composite.class); //$NON-NLS-1$
return (GeometryViewer) method.invoke(newInstance, viewerParent);
} catch (Exception e) {
throw new Exception("", e); //$NON-NLS-1$
}
}
/**
* <p>
* Handles the processing and setting up the canvas' supplied geometry for
* visualization.
* </p>
*
* @param geometry
* the geometry to visualize
*/
private void loadGeometry(Shape geometry) {
if (geometry == null) {
return;
}
this.geometry = geometry;
rootNode = new GNode();
IRenderer renderer = viewer.getRenderer();
rootGeometry = (GeometryAttachment) renderer.createAttachment(GeometryAttachment.class);
rootGeometry.addGeometry(geometry);
rootNode.attach(rootGeometry);
viewer.setInput(rootNode);
// geometry.register(this);
}
/**
* <p>
* Returns the underlying GeometryViewer.
* </p>
*
* @return a GeometryViewer instance that is used to visualize scenes
*/
public GeometryViewer getViewer() {
return viewer;
}
/**
* <p>
* Listens for updates coming in from the geometry provider.
* </p>
*
* @see IVizUpdateable#update
*/
@Override
public void update(final IVizUpdateable component) {
// Invoke this on the JavaFX UI thread
javafx.application.Platform.runLater(new Runnable() {
@Override
public void run() {
if (component == geometry) {
// rootGeometry.addGeometry(geometry);
}
}
});
}
/**
* @see IVizCanvas#getDataSource()
*/
@Override
public URI getDataSource() {
return null;
}
/**
* @see IVizCanvas#getNumberOfAxes()
*/
@Override
public int getNumberOfAxes() {
return SUPPORTED_AXES;
}
/**
* @see IVizCanvas#getProperties()
*/
@Override
public Map<String, String> getProperties() {
if (properties == null) {
return Collections.emptyMap();
} else {
return properties;
}
}
/**
* @see IVizCanvas#getSourceHost()
*/
@Override
public String getSourceHost() {
return null;
}
/**
* @see IVizCanvas#isSourceRemote()
*/
@Override
public boolean isSourceRemote() {
return false;
}
/**
* @see IVizCanvas#redraw()
*/
@Override
public void redraw() {
}
/**
* @see IVizCanvas#setProperties()
*/
@Override
public void setProperties(Map<String, String> props) throws Exception {
this.properties = props;
}
}
......@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.ice.viz.service.geometry;
import org.eclipse.ice.viz.service.geometry.shapes.IShape;
import org.eclipse.ice.viz.service.modeling.Shape;
import org.eclipse.jface.viewers.StructuredSelection;
/**
......@@ -20,21 +20,21 @@ import org.eclipse.jface.viewers.StructuredSelection;
*/
public class GeometrySelection extends StructuredSelection {
/** */
private final IShape shape;
/** */
private final Shape shape;
/**
*
* @param modelShape
*/
public GeometrySelection(IShape modelShape) {
super(modelShape);
/**
*
* @param modelShape
*/
public GeometrySelection(Shape modelShape) {
super(modelShape);
this.shape = modelShape;
}
this.shape = modelShape;
}
public IShape getShape() {
return shape;
}
public Shape getShape() {
return shape;
}
}
......@@ -17,14 +17,8 @@ import org.eclipse.ice.viz.service.AbstractVizService;
import org.eclipse.ice.viz.service.IVizCanvas;
import org.eclipse.ice.viz.service.IVizService;
import org.eclipse.ice.viz.service.datastructures.VizObject.IVizObject;
import org.eclipse.ice.viz.service.geometry.shapes.Geometry;
import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer;
import org.eclipse.ice.viz.service.geometry.widgets.TransformationView;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ice.viz.service.modeling.AbstractController;
import org.eclipse.ice.viz.service.modeling.Shape;
/**
* <p>
......@@ -36,49 +30,52 @@ import org.eclipse.ui.PlatformUI;
*/
public class GeometryVizService extends AbstractVizService {
/** The name used to lookup this service. */
private static final String VIZ_SERVICE_NAME = "ICE Geometry Editor"; //$NON-NLS-1$
/** The name used to lookup this service. */
private static final String VIZ_SERVICE_NAME = "ICE Geometry Editor"; //$NON-NLS-1$
/** The version of the service. */
private static final String CURRENT_VERSION = "1.0";
/** The version of the service. */
private static final String CURRENT_VERSION = "1.0";
/**
* <p>
* Creates a GeometryCanvas.
* </p>
*
* @see IVizService#createCanvas(IVizObject)
*/
public IVizCanvas createCanvas(IVizObject geometry) throws Exception {
if (geometry instanceof Geometry) {
GeometryCanvas canvas = new GeometryCanvas((Geometry) geometry);
/**
* <p>
* Creates a GeometryCanvas.
* </p>
*
* @see IVizService#createCanvas(IVizObject)
*/
@Override
public IVizCanvas createCanvas(AbstractController geometry) throws Exception {
if (geometry instanceof Shape) {
GeometryCanvas canvas = new GeometryCanvas((Shape) geometry);
return canvas;
} else {
throw new IllegalArgumentException(Messages.GeometryVizService_InvalidInput);
}
}
return canvas;
} else {
throw new IllegalArgumentException(Messages.GeometryVizService_InvalidInput);
}
}
/**
* @see IVizService#getName()
*/
public String getName() {
return VIZ_SERVICE_NAME;
}
/**