diff --git a/org.eclipse.ice.client.widgets/src/org/eclipse/ice/client/widgets/ICEGeometryPage.java b/org.eclipse.ice.client.widgets/src/org/eclipse/ice/client/widgets/ICEGeometryPage.java index 55613dfcd9fc2d550d27b48848381f3757c40fd8..94999d6fc700de3cc3331481730f9e831ea6eb45 100644 --- a/org.eclipse.ice.client.widgets/src/org/eclipse/ice/client/widgets/ICEGeometryPage.java +++ b/org.eclipse.ice.client.widgets/src/org/eclipse/ice/client/widgets/ICEGeometryPage.java @@ -32,7 +32,7 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; /** *
- * This class is ICEFormPage that displays the GeometryEditor powered by JME3. + * This class is ICEFormPage that displays the GeometryEditor powered by JavaFX. * It automatically opens the ShapeTreeView and TransformationView to allow the * user to add and edit geometry. *
@@ -170,13 +170,15 @@ public class ICEGeometryPage extends ICEFormPage implements IUpdateableListener // Get JME3 Geometry service from factory IVizServiceFactory factory = ((ICEFormEditor) editor) .getVizServiceFactory(); - IVizService service = factory.get("JME3 Geometry Editor"); + IVizService service = factory.get("ICE Geometry Editor"); // Create and draw geometry canvas try { IVizCanvas vizCanvas = service.createCanvas(geometryComp .getGeometry().getGeometry()); vizCanvas.draw(parent); + + } catch (Exception e) { logger.error( diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.classpath b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..49f9f41e31147547f3a25730e047361866c5a4fc --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.classpath @@ -0,0 +1,11 @@ + ++ * Generates JavaFX GeometryViewer instances. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class GeometryViewerFactory implements IViewerFactory { + + /** + *+ * Creates a JavaFX geometry viewer instance on the supplied parent + * composite. + *
+ */ + public GeometryViewer createViewer(Composite parent) { + return new FXGeometryViewer(parent); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXContentProvider.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXContentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..63043fd0cbc99e7df499b581310ba3a427c4b248 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXContentProvider.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +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.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import javafx.scene.Group; +import javafx.scene.Node; + +/** + *+ * Handles parsing the scene model input (INode, etc) and generates an internal + * JavaFX model that can be visualized in the viewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXContentProvider implements IContentProvider { + + /** Used to generate the JavaFX scene from the input model. */ + private ISceneGenerator sceneGenerator; + + /** + *+ * Generates a JavaFX scene from the input model. + *
+ * + * @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); + } + + /** + *+ * Verifies the model inputs for sanity. + *
+ * + * @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); + } + } + + /** + *+ * Disposes the Viewer input. + *
+ */ + public void dispose() { + } + + /** + * + */ + public ISceneGenerator getGenerator() { + return sceneGenerator; + } + + /** + * + */ + public void setGenerator(ISceneGenerator generator) { + this.sceneGenerator = generator; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXGeometryViewer.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXGeometryViewer.java new file mode 100644 index 0000000000000000000000000000000000000000..a792561956f3025bcdf5b8e587a14b13b9ed1f96 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXGeometryViewer.java @@ -0,0 +1,342 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal; + +import org.eclipse.ice.viz.service.geometry.GeometrySelection; +import org.eclipse.ice.viz.service.geometry.scene.base.GeometryAttachment; +import org.eclipse.ice.viz.service.geometry.scene.base.ICamera; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; +import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer; +import org.eclipse.ice.viz.service.javafx.internal.model.FXCameraAttachment; +import org.eclipse.ice.viz.service.javafx.internal.model.FXRenderer; +import org.eclipse.ice.viz.service.javafx.internal.model.FXShape; +import org.eclipse.ice.viz.service.javafx.internal.model.geometry.FXGeometryAttachmentManager; +import org.eclipse.ice.viz.service.javafx.internal.scene.TransformGizmo; +import org.eclipse.ice.viz.service.javafx.internal.scene.camera.CameraController; +import org.eclipse.ice.viz.service.javafx.internal.scene.camera.FPSController; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +import javafx.embed.swt.FXCanvas; +import javafx.event.EventHandler; +import javafx.scene.AmbientLight; +import javafx.scene.Camera; +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.PerspectiveCamera; +import javafx.scene.PointLight; +import javafx.scene.Scene; +import javafx.scene.input.MouseEvent; +import javafx.scene.input.PickResult; +import javafx.scene.paint.Color; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.shape.Box; +import javafx.scene.shape.DrawMode; + +/** + *+ * JavaFX implementation of GeometryViewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXGeometryViewer extends GeometryViewer { + + /** The root JavaFX widget that displays content. */ + private FXCanvas fxCanvas; + + /** + * The internally used root that cannot be modified by clients. + */ + private Group internalRoot; + + /** The root of the scene as exposed to clients. */ + private Group root; + + /** The active scene displayed to the end user. */ + private Scene scene; + + /** + * The content provider that generates JavaFX scene data from the geometry + * editor scene model. + */ + private FXContentProvider contentProvider; + + /** Default camera controller. */ + private CameraController cameraController; + + /** Default camera. */ + private Camera defaultCamera; + + /** + *+ * Creates a JavaFX GeometryViewer. + *
+ * + * @param parent + */ + public FXGeometryViewer(Composite parent) { + super(parent); + + renderer = new FXRenderer(); + renderer.register(GeometryAttachment.class, new FXGeometryAttachmentManager()); + } + + /** + *+ * Creates an FXCanvas control and initializes a default empty JavaFX scene. + *
+ */ + @Override + protected void createControl(Composite parent) { + contentProvider = new FXContentProvider(); + + fxCanvas = new FXCanvas(parent, SWT.NONE); + + // Create the root nodes + internalRoot = new Group(); + root = new Group(); + + internalRoot.getChildren().add(root); + + setupSceneInternals(internalRoot); + + scene = new Scene(internalRoot, Color.rgb(24, 30, 31)); + + // Setup camera and input + createDefaultCamera(internalRoot); + wireSelectionHandling(); + + fxCanvas.setScene(scene); + } + + /** + *+ * Creates the current geometry editor camera. + *
+ * + * @param parent + * the parent to create the camera on + * + */ + private void createDefaultCamera(Group parent) { + PerspectiveCamera perspCamera = new PerspectiveCamera(); + perspCamera.setNearClip(0.1); + perspCamera.setFarClip(2000.0); + perspCamera.setFieldOfView(35); + perspCamera.setTranslateX(0); + perspCamera.setTranslateY(-100); + perspCamera.setTranslateZ(-1000); + + parent.getChildren().add(perspCamera); + + // Hacked in camera (for now) + FXCameraAttachment cameraAttachment = new FXCameraAttachment(perspCamera); + setCamera(cameraAttachment); + } + + /** + *+ * Hooks up JavaFX picking with JFace selections. + *
+ */ + private void wireSelectionHandling() { + + scene.setOnMousePressed(new EventHandler+ * Creates scene elements that aren't meant to be manipulated by the user + * (markers, camera, etc.) + *
+ */ + private void setupSceneInternals(Group parent) { + // Create scene plane for frame of reference. + Box box = new Box(1000, 0, 1000); + box.setMouseTransparent(true); + box.setDrawMode(DrawMode.LINE); + box.setMaterial(new PhongMaterial(Color.ANTIQUEWHITE)); + + AmbientLight ambientLight = new AmbientLight(Color.rgb(100, 100, 100)); + + PointLight light1 = new PointLight(Color.ANTIQUEWHITE); + light1.setMouseTransparent(true); + light1.setTranslateY(-350); + + PointLight light2 = new PointLight(Color.ANTIQUEWHITE); + light2.setMouseTransparent(true); + light2.setTranslateZ(350); + + PointLight light3 = new PointLight(Color.ANTIQUEWHITE); + light3.setMouseTransparent(true); + light3.setTranslateZ(-350); + + PointLight light4 = new PointLight(Color.ANTIQUEWHITE); + light4.setMouseTransparent(true); + light4.setTranslateZ(350); + + TransformGizmo gizmo = new TransformGizmo(1000); + gizmo.showHandles(false); + + parent.getChildren().addAll(gizmo, box, light1, light2, light3, light4, ambientLight); + + } + + /** + *+ * Handles recreating the scene when the input changes. + *
+ * + * @see Viewer#inputChanged(Object, Object) + */ + @Override + protected void inputChanged(Object oldInput, Object newInput) { + contentProvider.inputChanged(this, newInput, input); + } + + /** + * @see GeometryViewer#updateCamera(ICamera) + */ + @Override + protected void updateCamera(ICamera camera) { + if (!(camera instanceof FXCameraAttachment)) { + throw new IllegalArgumentException(Messages.FXGeometryViewer_InvalidCamera); + } + + FXCameraAttachment attachment = (FXCameraAttachment) camera; + Camera fxCamera = attachment.getFxCamera(); + + if (fxCamera == null) { + throw new NullPointerException(Messages.FXGeometryViewer_NullCamera); + } + + cameraController = new FPSController(fxCamera, scene, fxCanvas); + + scene.setCamera(fxCamera); + + defaultCamera = fxCamera; + } + + /** + * @see Viewer#getClass() + */ + @Override + public Control getControl() { + return fxCanvas; + } + + /** + * @see Viewer#refresh() + */ + @Override + public void refresh() { + + } + + /** + * + * @return + */ + public FXCanvas getFxCanvas() { + return fxCanvas; + } + + /** + * + * @return + */ + public Group getRoot() { + return root; + } + + /** + * + * @return + */ + public Scene getScene() { + return scene; + } + + /** + * + * @return + */ + public FXContentProvider getContentProvider() { + return contentProvider; + } + + /** + * + * @param contentProvider + */ + public void setContentProvider(FXContentProvider contentProvider) { + this.contentProvider = contentProvider; + } + + public CameraController getCameraController() { + return cameraController; + } + + public Camera getDefaultCamera() { + return defaultCamera; + } + +} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXSceneGenerator.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXSceneGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..566e7bc962d2967601b100e32eee4d952dcf6744 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/FXSceneGenerator.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal; + +import java.util.ArrayDeque; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; +import java.util.Set; + +import org.eclipse.ice.viz.service.geometry.scene.base.ISceneGenerator; +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; + +import javafx.scene.Group; +import javafx.scene.Node; + +/** + *+ * Generates JavaFX scenes from ICE geometry model inputs. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXSceneGenerator implements ISceneGenerator { + + /** + *+ * Iteratively generates a JavaFX scene from the input {@link INode} model. + * TODO: parallelize scene generation. + *
+ * + * @param iceRoot + * the root model node of the scene + * @param fxRoot + * the fxRoot + */ + @Override + public Node generateScene(INode iceRoot) { + + // Queue for managing search + Queue+ * Generates a JavaFX node from the scene model node. + *
+ * + * @param node + * the scene model node to use to generate a JavaFX node. + * + * @return JavaFX node representative of the input model node. + */ + @Override + public Node generateNode(INode node) { + Group fxNode = new Group(); + node.setProperty(INode.RENDERER_NODE_PROP, fxNode); + + processAttachmentGroups(node); + + INode parent = (INode) node.getParent(); + + // Add the child to scene, if it's not the root + if (parent != null) { + Group fxGroup = Util.getFxGroup(parent); + fxGroup.getChildren().add(fxNode); + } + + // Add a reference to ICE model on the javafx side + fxNode.getProperties().put(INode.class, node); + + return fxNode; + } + + /** + *+ * Processes all attachments for the given model node, for all types of + * attachments. + *
+ * + * @param child + * the input model node + */ + @Override + public void processAttachmentGroups(INode child) { + Map+ * Processes the node attachment, generating the JavaFX specific + * functionality related to the attachment. + *
+ * + * @param child + * the node who owns the attachments to process + * @param currentAttachment + * the attachment to process. + */ + @Override + public void processAttachment(INode node, IAttachment currentAttachment) { + currentAttachment.attach(node); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Messages.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Messages.java new file mode 100644 index 0000000000000000000000000000000000000000..f151c898a623b30f550aa7afeaf9ae8ed6e69a26 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Messages.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.ice.viz.service.javafx.internal.messages"; //$NON-NLS-1$ + public static String FXContentProvider_InvalidInputNode; + public static String FXContentProvider_InvalidInputType; + public static String FXContentProvider_InvalidViewerType; + public static String FXGeometryViewer_InvalidCamera; + public static String FXGeometryViewer_NullCamera; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Util.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Util.java new file mode 100644 index 0000000000000000000000000000000000000000..e8e9f7ce30f64330d47e5cdc63e71158db720adf --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/Util.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal; + +import org.eclipse.ice.viz.service.geometry.scene.model.INode; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; +import org.eclipse.ice.viz.service.geometry.shapes.Transformation; + +import javafx.geometry.Point3D; +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.paint.Color; +import javafx.scene.paint.Material; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.transform.Affine; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Scale; +import javafx.scene.transform.Transform; +import javafx.scene.transform.Translate; + +/** + *+ * Contains various static utility functions and constants used throughout that + * can't be refactored into specific classes.. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class Util { + + /** Default material for normal states. */ + public static final Material DEFAULT_MATERIAL = new PhongMaterial(Color.BLUE); + + /** Default material for selected, highlighted, etc. states. */ + public static final Material DEFAULT_HIGHLIGHTED_MATERIAL = new PhongMaterial(Color.RED); + + /** Default material for errors or inconsistent states. */ + public static final Material DEFAULT_ERROR_MATERIAL = new PhongMaterial(Color.YELLOW); + + /** */ + public static final String SHAPE_PROP_KEY = "shape"; //$NON-NLS-1$ + + /** + *+ * Converts an ICE Geometry Transformation data structure to a JavaFX + * Transform. + *
+ * + * @param transform + * ICE Transformation data structure + * @return a JavaFX transformation that is analagous to the Transformation + */ + public static Transform convertTransformation(Transformation transformation) { + Affine transform = new Affine(); + + if (transformation == null) { + return transform; + } + + double size = transformation.getSize(); + double[] scale = transformation.getScale(); + double[] rotation = transformation.getRotation(); + double[] translation = transformation.getTranslation(); + + Scale sizeXform = new Scale(size, size, size); + Scale scaleXform = new Scale(scale[0], scale[1], scale[2]); + Rotate rotateXform = eulerToRotate(rotation[0], rotation[1], rotation[2]); + Translate translateXform = new Translate(translation[0], translation[1], translation[2]); + Transform transformOutput = transform.createConcatenation(translateXform) + .createConcatenation(rotateXform) + .createConcatenation(sizeXform) + .createConcatenation(scaleXform); + + return transformOutput; + } + + /** + *+ * Converts Euler angle representation to Axis Angle that can be used by + * JavaFX. + *
+ * + * @param radX + * @param radY + * @param radZ + * + * @return Rotate object that represents the euler angle orientation + */ + public static Rotate eulerToRotate(double radX, double radY, double radZ) { + double invSqr = 1.0d / 2.0d; + + double cosX = Math.cos(radX * invSqr); + double sinX = Math.sin(radX * invSqr); + + double cosY = Math.cos(radY * invSqr); + double sinY = Math.sin(radY * invSqr); + + double cosZ = Math.cos(radZ * invSqr); + double sinZ = Math.sin(radZ * invSqr); + + double cosSqr = cosX * cosY; + double sinSqr = sinX * sinY; + + double x = (sinX * cosY * cosZ) + (cosX * sinY * sinZ); + double y = (cosX * sinY * cosZ) - (sinX * cosY * sinZ); + double z = (cosSqr * sinZ) + (sinSqr * cosZ); + + double w = (cosSqr * cosZ) - (sinSqr * sinZ); + double angle = Math.acos(w) * 2.0d; + + double dist = x * x + y * y + z * z; + + if (dist < 0.0001d) { + x = 1.0d; + y = 0.0d; + z = 0.0d; + } else { + dist = 1.0d / Math.sqrt(dist); + x *= dist; + y *= dist; + z *= dist; + } + + return new Rotate(Math.toDegrees(angle), new Point3D(x, y, z)); + } + + /** + *+ * Returns the IShape property defined by Util.SHAPE_PROP_KEY from the + * supplied node, if one exists. + *
+ * + * @param node + * @return an IShape that is assigned to the supplied node. + */ + public static IShape getShapeProperty(Node node) { + Object shapeProperty = node.getProperties().get(SHAPE_PROP_KEY); + + if (shapeProperty != null && shapeProperty instanceof IShape) { + return (IShape) shapeProperty; + } + + return null; + } + + /** + *+ * Returns the JavaFX node associated with the supplied ICE model node. + *
+ * + * @param node + * ICE Mode + * + * @return JavaFX node associated with the supplied ICE model node + */ + public static Group getFxGroup(INode node) { + return (Group) node.getProperty(INode.RENDERER_NODE_PROP); + } +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/messages.properties b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/messages.properties new file mode 100644 index 0000000000000000000000000000000000000000..f467ffc00ccd737e89af1db22f719391304c4479 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/messages.properties @@ -0,0 +1,5 @@ +FXContentProvider_InvalidInputNode=Input object required to be of FXNode type. +FXContentProvider_InvalidInputType=Input object required to be of FXNode type. +FXContentProvider_InvalidViewerType=Input viewer type required: FXGeometryViewer. +FXGeometryViewer_InvalidCamera=Unsupported ICamera supplied to viewer, must be FXCameraAttachment. +FXGeometryViewer_NullCamera=Null FXCameraAttachment camera instance. diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXCameraAttachment.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXCameraAttachment.java new file mode 100644 index 0000000000000000000000000000000000000000..4caeed5c83b597df2620e19e93010c1a18d00f2b --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXCameraAttachment.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.model; + +import org.eclipse.ice.viz.service.geometry.scene.base.CameraAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; +import org.eclipse.ice.viz.service.javafx.internal.Util; + +import javafx.scene.Camera; +import javafx.scene.Group; +import javafx.scene.PerspectiveCamera; + +/** + *+ * Implementation of CameraAttachment for JavaFX. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXCameraAttachment extends CameraAttachment { + + /** The JavaFX camera used with this attachment. */ + private Camera camera; + + /** + *+ * Creates a JavaFX camera attachment. + *
+ * + * @param cam + */ + public FXCameraAttachment(Camera cam) { + this.camera = cam; + } + + /** + * @see IAttachment#attach(INode) + */ + @Override + public void attach(INode owner) { + super.attach(owner); + + if (camera == null) { + camera = new PerspectiveCamera(); + } + + Group fxGroup = Util.getFxGroup(owner); + + fxGroup.getChildren().add(fxGroup); + } + + /** + * @see IAttachment#detach(INode) + */ + public void detach(INode owner) { + super.attach(owner); + + Group fxGroup = Util.getFxGroup(owner); + + fxGroup.getChildren().remove(camera); + } + + /** + *+ * Returns the JavaFX camera for this attachment. + *
+ * + * @return the camera for this attachment + */ + public Camera getFxCamera() { + return camera; + } + + /** + * @see IAttachment#getType() + */ + public Class> getType() { + return CameraAttachment.class; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXRenderer.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..9a1b1ece31f4a9c03be7e150c30f979117c8d9ea --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXRenderer.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.model; + +import org.eclipse.ice.viz.service.geometry.viewer.Renderer; + +public class FXRenderer extends Renderer { + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXScene.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXScene.java new file mode 100644 index 0000000000000000000000000000000000000000..ca4ca302f19f698fb1eb5d0628e405ccfe208b97 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXScene.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.model; + +import org.eclipse.ice.viz.service.geometry.scene.base.GScene; + +/** + *+ *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXScene extends GScene { + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXShape.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXShape.java new file mode 100644 index 0000000000000000000000000000000000000000..7989ba26c1ce84bad16e925cac07854bcd714d07 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/FXShape.java @@ -0,0 +1,126 @@ +package org.eclipse.ice.viz.service.javafx.internal.model; + +import org.eclipse.ice.viz.service.geometry.shapes.ShapeType; +import org.eclipse.ice.viz.service.javafx.internal.Util; +import org.eclipse.ice.viz.service.javafx.internal.scene.TransformGizmo; + +import javafx.scene.Group; +import javafx.scene.paint.Color; +import javafx.scene.paint.Material; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.shape.Box; +import javafx.scene.shape.Cylinder; +import javafx.scene.shape.Shape3D; +import javafx.scene.shape.Sphere; + +/** + *+ * JavaFX node for managing Geometry shapes in a scene. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXShape extends Group { + + /** */ + private Shape3D shape; + + /** */ + private TransformGizmo gizmo; + + /** */ + private PhongMaterial defaultMaterial; + + /** */ + private Material selectedMaterial = Util.DEFAULT_HIGHLIGHTED_MATERIAL; + + /** */ + private boolean selected; + + /** + * + * @param type + */ + public FXShape(ShapeType type) { + + switch (type) { + case Cone: + break; + case Cube: + Box box = new Box(50, 50, 50); + defaultMaterial = new PhongMaterial(Color.rgb(50, 50, 255)); + defaultMaterial.setSpecularColor(Color.WHITE); + shape = box; + break; + case Cylinder: + Cylinder cyl = new Cylinder(20, 250); + + defaultMaterial = new PhongMaterial(Color.rgb(0, 181, 255)); + defaultMaterial.setSpecularColor(Color.WHITE); + cyl.setMaterial(defaultMaterial); + + shape = cyl; + break; + case None: + break; + case Sphere: + Sphere sphere = new Sphere(50, 50); + + defaultMaterial = new PhongMaterial(Color.rgb(131, 0, 157)); + defaultMaterial.setSpecularColor(Color.WHITE); + sphere.setMaterial(defaultMaterial); + + shape = sphere; + break; + case Tube: + Cylinder tube = new Cylinder(25, 250); + + defaultMaterial = new PhongMaterial(Color.rgb(0, 131, 157)); + defaultMaterial.setSpecularColor(Color.WHITE); + shape = tube; + break; + default: + break; + } + + gizmo = new TransformGizmo(100); + gizmo.showHandles(false); + gizmo.setVisible(false); + + getChildren().addAll(shape, gizmo); + } + + /** + * + * @return + */ + public Shape3D getShape() { + return shape; + } + + /** + * + * @return + */ + public boolean isSelected() { + return selected; + } + + /** + * + * @param selected + */ + public void setSelected(boolean selected) { + this.selected = selected; + + if (selected) { + shape.setMaterial(selectedMaterial); + gizmo.setVisible(true); + } else { + shape.setMaterial(defaultMaterial); + gizmo.setVisible(false); + } + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/Messages.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/Messages.java new file mode 100644 index 0000000000000000000000000000000000000000..e2893e2d601ac6db559337f566a0180753ea663a --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/Messages.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.model; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.ice.viz.service.javafx.internal.renderer.messages"; //$NON-NLS-1$ + public static String FXGeometryAttachment_IncompatibleNodeGeometry; + public static String FXGeometryAttachment_IncompatibleNodeMesh; + public static String FXMesh_IncompatibleMesh; + public static String FXNode_IncompatibleNodeGeometry; + public static String FXNode_IncompatibleNodeMesh; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/AddShapeToNode.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/AddShapeToNode.java new file mode 100644 index 0000000000000000000000000000000000000000..5ecb4897681482bd7e8b23629353cf0ab245595e --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/AddShapeToNode.java @@ -0,0 +1,103 @@ +package org.eclipse.ice.viz.service.javafx.internal.model.geometry; + +import java.util.ArrayList; + +import org.eclipse.ice.viz.service.geometry.shapes.ComplexShape; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; +import org.eclipse.ice.viz.service.geometry.shapes.IShapeVisitor; +import org.eclipse.ice.viz.service.geometry.shapes.OperatorType; +import org.eclipse.ice.viz.service.geometry.shapes.PrimitiveShape; +import org.eclipse.ice.viz.service.geometry.shapes.ShapeType; +import org.eclipse.ice.viz.service.geometry.widgets.ShapeMaterial; +import org.eclipse.ice.viz.service.javafx.internal.Util; +import org.eclipse.ice.viz.service.javafx.internal.model.FXShape; + +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.shape.Mesh; + +/** + * Adds all visited shapes to the JME3 scene graph node + * + * @author Andrew P. Belt + * + */ +class AddShapeToNode implements IShapeVisitor { + + /** + * The node whose children will be added for each visited IShape + */ + private Group node; + + /** + * Initializes the instance with the given JME3 node + * + * @param node + */ + public AddShapeToNode(Group node) { + this.node = node; + } + + /** + * Prepares the ComplexShape to be synchronized + */ + @Override + public void visit(ComplexShape complexShape) { + + // Only unions are currently supported until the mesh renderer is + // implemented + + if (complexShape.getType() == OperatorType.Union) { + + // Create a new Node + + Group complexShapeNode = new Group(); + complexShapeNode.setId(complexShape.getName()); + + complexShapeNode.getProperties().put(IShape.class, complexShape); + complexShapeNode.getTransforms().setAll(Util.convertTransformation(complexShape.getTransformation())); + + // Loop through the shapes in the ComplexShape + + ArrayList+ * JavaFX implementation of GeometryAttachment. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXGeometryAttachment extends GeometryAttachment { + + /** + * Node used to attach geometry to (instead of the root, to keep things + * easier to manipulate). + */ + private Group fxAttachmentNode; + + /** The manager that owns this attachment. */ + private final FXGeometryAttachmentManager manager; + + /** Maps ICE Geometry shapes to JavaFX shapes. */ + private Map+ * Creates an FXGeometryAttachment instance. + *
+ * + * @param manager + * the manager that created this instance. + */ + public FXGeometryAttachment(FXGeometryAttachmentManager manager) { + this.manager = manager; + } + + /** + * @see GeometryAttachment#attach(INode) + */ + @Override + public void attach(INode owner) { + super.attach(owner); + + if (fxAttachmentNode == null) { + fxAttachmentNode = new Group(); + } + + Group fxNode = Util.getFxGroup(owner); + fxNode.getChildren().add(fxAttachmentNode); + } + + /** + * @see IAttachment#detach(INode) + */ + @Override + public void detach(INode owner) { + Group fxNode = Util.getFxGroup(owner); + + if (fxAttachmentNode != null) { + fxNode.getChildren().remove(fxAttachmentNode); + } + + super.detach(owner); + } + + /** + * @see IAttachment#isSingleton() + */ + @Override + public boolean isSingleton() { + return false; + } + + /** + * @see IGeometry#setVisible(boolean) + */ + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + + fxAttachmentNode.setVisible(visible); + } + + @Override + public void addGeometry(Geometry geom) { + super.addGeometry(geom); + + if (fxAttachmentNode == null) { + fxAttachmentNode = new Group(); + } + + if (knownGeometry == null) { + knownGeometry = new ArrayList<>(); + } + + if (!knownGeometry.contains(geom)) { + geom.register(new IVizUpdateableListener() { + + public void update(IVizUpdateable component) { + SyncShapes sync = new SyncShapes(fxAttachmentNode); + + for (IShape shape : geom.getShapes()) { + shape.acceptShapeVisitor(sync); + } + + javafx.application.Platform.runLater(new Runnable() { + public void run() { + sync.commit(); + } + }); + } + }); + + knownGeometry.add(geom); + } + } + + /** + *+ * Generates JavaFX shapes from the input IShape. + *
+ * + * @param shape + * an ICE Geometry IShape + */ + @Override + public void processShape(IShape shape) { + + if (fxShapeMap == null) { + fxShapeMap = new HashMap<>(); + } + + shape.acceptShapeVisitor(new IShapeVisitor() { + public void visit(PrimitiveShape primitiveShape) { + processShape(primitiveShape); + } + + public void visit(ComplexShape complexShape) { + processShape(complexShape); + } + }); + } + + /** + *+ * Generates JavaFX shapes from the input primitive type. + *
+ * + * @param ICE + * primitive shape instance + */ + private void processShape(PrimitiveShape shape) { + ShapeType type = shape.getType(); + + Transform xform = Util.convertTransformation(shape.getTransformation()); + + FXShape fxShape = new FXShape(type); + + fxShape.getProperties().put(IShape.class, shape); + fxShape.getProperties().put(Geometry.class, currentGeom); + + fxShape.getTransforms().setAll(xform); + + fxAttachmentNode.getChildren().add(fxShape); + + fxShapeMap.put(shape, fxShape); + } + + /** + *+ * Generates geometry from a complex CSG shape. + *
+ * + * @param shape + */ + private void processShape(ComplexShape shape) { + OperatorType type = shape.getType(); + + switch (type) { + case Complement: + break; + case Intersection: + break; + case None: + break; + case Union: + break; + default: + break; + } + + for (IShape subShape : shape.getShapes()) { + subShape.acceptShapeVisitor(new IShapeVisitor() { + + public void visit(PrimitiveShape primitiveShape) { + processShape(primitiveShape); + } + + public void visit(ComplexShape complexShape) { + processShape(complexShape); + } + }); + } + } + + /** + * + */ + @Override + protected void disposeShape(IShape shape) { + Node node = fxShapeMap.get(shape); + + if (node == null) { + return; + } + + fxAttachmentNode.getChildren().remove(node); + } + + /** + * + * @param copy + * @return + */ + @Override + public List+ * Manages FXGeometryAttachment allocations. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXGeometryAttachmentManager implements IAttachmentManager { + + /** The active list of attachments. */ + private List+ * Batch deletes the attachments in the removal queue. + *
+ */ + private void processDeletions() { + if (removalQueue == null || removalQueue.isEmpty()) { + return; + } + + for (FXGeometryAttachment attachment : removalQueue) { + attachment.detach(attachment.getOwner()); + } + + removalQueue.clear(); + } + + /** + * @see IAttachmentManager#update() + */ + public void update() { + processDeletions(); + + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/SyncShapes.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/SyncShapes.java new file mode 100644 index 0000000000000000000000000000000000000000..1f25ae20b47c2f851f522aee59cd3ed4c8f6eb1f --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/SyncShapes.java @@ -0,0 +1,179 @@ +package org.eclipse.ice.viz.service.javafx.internal.model.geometry; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Vector; + +import org.eclipse.ice.viz.service.geometry.shapes.ComplexShape; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; +import org.eclipse.ice.viz.service.geometry.shapes.IShapeVisitor; +import org.eclipse.ice.viz.service.geometry.shapes.PrimitiveShape; +import org.eclipse.ice.viz.service.javafx.internal.Util; + +import javafx.scene.Group; +import javafx.scene.Node; + +/** + *+ * Sync ICE Geometry with the current scene. + *
+ * + *+ * (Adapted from ICE JME3 impl) + *
+ * + * @author Andrew P. Belt + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +class SyncShapes implements IShapeVisitor { + + /** + * The JavaFX scene graph node to update + */ + private Group parentNode; + + /** + * The temporary working list of PrimitiveShapes + */ + private ArrayList+ * ArcBallController provides 3D editor like features to a camera, by rotating + * around a point and letting the user zoom in and out. + *
+ */ +public class ArcBallController extends CameraController { + + /** */ + Transform xform; + + /** */ + Affine transform; + + /** */ + private Camera camera; + + /** */ + private Scene scene; + + /** */ + double anchorX; + + /** */ + double anchorY; + + /** */ + double anchorAngle; + + /** */ + private double sphereRadius; + + /** */ + private double height; + + /** */ + private double width; + + /** */ + protected Point3D currentRot; + + /** */ + private Point3D startRot; + + /** */ + protected boolean activeRotation; + + /** */ + private FXCanvas canvas; + + /** + *+ *
+ */ + public ArcBallController(Camera camera, Scene scene, FXCanvas canvas) { + this.camera = camera; + this.scene = scene; + this.canvas = canvas; + + scene.setOnScroll(new EventHandler+ * Utility for working with Cameras in the FXGeometryViewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class CamUtil { + + /** + *+ * Maps canvas coordinate to a spherical location. + *
+ * + * @param x + * canvas x coordinate + * @param y + * canvas y coordinate + * + * @return x/y location mapped onto sphere + */ + public static Point3D pointToSphere(double x, double y, double sphereRadius) { + double screenDist = x * x + y * y; + double sphereSquared = sphereRadius * sphereRadius; + + if (screenDist > sphereSquared) { + return new Point3D(x, y, 0); + } else { + double z = Math.sqrt(sphereSquared - screenDist); + return new Point3D(x, y, z); + } + } + + /** + *+ * Computes a matrix to orient a node towards a given point, defined by + * target. + *
+ * + * @param target + * the target to look at + * @param pos + * the viewer's current location + * @param yUp + * the direction of "up" + * + * @return affine transform that orients towards the target + */ + public static Affine lookAt(Point3D target, Point3D pos, Point3D yUp) { + Point3D z = target.subtract(pos).normalize(); + Point3D x = yUp.normalize().crossProduct(z).normalize(); + Point3D y = z.crossProduct(x).normalize(); + + return new Affine(x.getX(), y.getX(), z.getX(), pos.getX(), x.getY(), y.getY(), z.getY(), pos.getY(), x.getZ(), + y.getZ(), z.getZ(), pos.getZ()); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CameraController.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CameraController.java new file mode 100644 index 0000000000000000000000000000000000000000..fe2d2e6a881edf8a8f95d5157f66cef2e0c27187 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CameraController.java @@ -0,0 +1,5 @@ +package org.eclipse.ice.viz.service.javafx.internal.scene.camera; + +public abstract class CameraController { + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/FPSController.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/FPSController.java new file mode 100644 index 0000000000000000000000000000000000000000..8c21604b6b8161897c3089b1ba083e818d64caa8 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/FPSController.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.scene.camera; + +import javafx.embed.swt.FXCanvas; +import javafx.event.EventHandler; +import javafx.geometry.Point3D; +import javafx.scene.Camera; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseEvent; +import javafx.scene.transform.Affine; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Transform; + +/** + *+ * ArcBallController provides 3D editor like features to a camera, by rotating + * around a point and letting the user zoom in and out. + *
+ */ +public class FPSController extends CameraController { + + /** */ + Transform xform; + + /** */ + Affine transform; + + /** */ + private Camera camera; + + /** */ + private Scene scene; + + /** */ + double anchorX; + + /** */ + double anchorY; + + /** */ + double anchorAngle; + + /** */ + private double sphereRadius; + + /** */ + private double height; + + /** */ + private double width; + + /** */ + protected Point3D currentRot; + + /** */ + private Point3D startRot; + + /** */ + protected boolean activeRotation; + + /** */ + private FXCanvas canvas; + + private double mousePosX; + + private double mousePosY; + + private double mouseOldX; + + private double mouseOldY; + + private double mouseDeltaX; + + private double mouseDeltaY; + + private Affine affine; + + private final double NORMAL_SPEED = 60.0d; + + private final double FAST_SPEED = 120.0d; + + private double speed; + + /** + *+ *
+ */ + public FPSController(Camera camera, Scene scene, FXCanvas canvas) { + this.camera = camera; + this.scene = scene; + this.canvas = canvas; + + Group xform = (Group) camera.getParent(); + + Rotate x = new Rotate(); + x.setAxis(Rotate.X_AXIS); + + Rotate y = new Rotate(); + y.setAxis(Rotate.Y_AXIS); + + affine = new Affine(); + camera.getTransforms().setAll(affine); + + scene.setOnKeyPressed(new EventHandler+ * Turntable provides 3D editor like features to a camera, by rotating around a + * point and letting the user zoom in and out. + *
+ */ +public class TurntableController extends CameraController { + + /** */ + Transform xform; + + /** */ + Affine transform; + + /** */ + private Camera camera; + + /** */ + private Scene scene; + + /** */ + double anchorX; + + /** */ + double anchorY; + + /** */ + double anchorAngle; + + /** */ + private double sphereRadius; + + /** */ + private double height; + + /** */ + private double width; + + /** */ + protected Point3D currentRot; + + /** */ + private Point3D startRot; + + /** */ + protected boolean activeRotation; + + /** */ + private FXCanvas canvas; + + /** */ + private double startX; + + /** */ + private double startY; + + /** + *+ *
+ */ + public TurntableController(Camera camera, Scene scene, FXCanvas canvas) { + this.camera = camera; + this.scene = scene; + this.canvas = canvas; + + Affine affine = new Affine(); + + scene.setOnMousePressed(new EventHandler+ * GeometryCanvas provides the ability to visualize and manipulate 3D geometry + * data. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +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+ * Creates a canvas for the supplied geometry. + *
+ * + * @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; + } + + /** + *+ * Fix for Eclipse/PDE's wonky fragment support. Creates a GeometryViewer + * supplied by an implementation fragment. + *
+ * + * @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$ + } + } + + /** + *+ * Handles the processing and setting up the canvas' supplied geometry for + * visualization. + *
+ * + * @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); + } + + /** + *+ * Returns the underlying GeometryViewer. + *
+ * + * @return a GeometryViewer instance that is used to visualize scenes + */ + public GeometryViewer getViewer() { + return viewer; + } + + /** + *+ * Listens for updates coming in from the geometry provider. + *
+ * + * @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+ * Implements an ICE viz service for geometry modeling. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +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 version of the service. */ + private static final String CURRENT_VERSION = "1.0"; + + /** + *+ * Creates a GeometryCanvas. + *
+ * + * @see IVizService#createCanvas(IVizObject) + */ + public IVizCanvas createCanvas(IVizObject geometry) throws Exception { + if (geometry instanceof Geometry) { + GeometryCanvas canvas = new GeometryCanvas((Geometry) geometry); + + return canvas; + } else { + throw new IllegalArgumentException(Messages.GeometryVizService_InvalidInput); + } + } + + /** + * @see IVizService#getName() + */ + public String getName() { + return VIZ_SERVICE_NAME; + } + + /** + * @see IVizService#getVersion() + */ + public String getVersion() { + return CURRENT_VERSION; // $NON-NLS-1$ + } + + /** + * @see AbstractVizService#findSupportedExtensions() + */ + @Override + protected Set+ * Contains various static utility functions and constants used throughout that + * can't be refactored into specific classes.. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class Util { + + /** */ + public static final String SHAPE_PROP_KEY = "shape"; //$NON-NLS-1$ + + /** + *+ * Returns the IShape property defined by Util.SHAPE_PROP_KEY from the + * supplied node, if one exists. + *
+ * + * @param node + * @return + */ + public static IShape getShapeProperty(Node node) { + Object shapeProperty = node.getProperties().get(SHAPE_PROP_KEY); + + if (shapeProperty != null && shapeProperty instanceof IShape) { + return (IShape) shapeProperty; + } + + return null; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/messages.properties b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/messages.properties new file mode 100644 index 0000000000000000000000000000000000000000..3cc108f72065764d0364836a706fbf3fca0c7f08 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/messages.properties @@ -0,0 +1,2 @@ +GeometryCanvas_ErrorCreatingViewer=Could not create GeometryViewer. +JavaFXGeometryVizService_InvalidInput=Invalid GeometryService can only render geometry viz objects. diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/Attachment.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/Attachment.java new file mode 100644 index 0000000000000000000000000000000000000000..dd6d49af44a38365074a64d792a6b1d7c4425185 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/Attachment.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; + +/** + *+ * Base for IAttachment implementations. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public abstract class Attachment implements IAttachment { + + /** The node that owns this attachment (is attached). */ + protected INode owner; + + /** + * @see IAttachment#getOwner() + */ + public INode getOwner() { + return owner; + } + + /** + * @see IAttachment#attach(INode) + */ + public void attach(INode owner) { + this.owner = owner; + } + + /** + * @see IAttachment#detach(INode) + */ + public void detach(INode owner) { + this.owner = null; + } + + /** + * @see IAttachment#isSingleton() + */ + public boolean isSingleton() { + return false; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraAttachment.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraAttachment.java new file mode 100644 index 0000000000000000000000000000000000000000..e1eb6a26118ac2225728976bf07565c516c7be12 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraAttachment.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; + +/** + *+ * Abstract base for creating Camera implementations, which control how the + * scene is viewed in a GeometryViewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + */ +public abstract class CameraAttachment extends Attachment implements ICamera { + + /** The camera's name. */ + protected String name; + + /** + * @see IAttachment#isSingleton() + */ + public boolean isSingleton() { + return true; + } + + /** + * @see ICamera#getName() + */ + public String getName() { + return name; + } + + /** + *+ * Sets the name of the camera. + *
+ * + * @param name + * the new name of this camera. + */ + public void setName(String name) { + this.name = name; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraType.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraType.java new file mode 100644 index 0000000000000000000000000000000000000000..baabbb419ffafd7fd51a58cafa97539effc7f628 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/CameraType.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +public enum CameraType { + PERSPECTIVE, PARALLEL +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GNode.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GNode.java new file mode 100644 index 0000000000000000000000000000000000000000..d77b1068c238d4d38ac29d86db3a54995e2cb3f0 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GNode.java @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; + +/** + *+ * INode model implementation. This class is not meant to be extended, either + * implement new functionality via the {@link INode} interface or with + * attachments via {@link IAttachment}. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public final class GNode implements INode { + + /** */ + private List+ * Base impl for IScene. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public abstract class GScene implements IScene { + + /** */ + private INode root; + + /** */ + private Map+ * Base for GeometryAttachment implementations, which provide nodes with the + * ability to display ICE Geometry elements and their constituent IShapes. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public abstract class GeometryAttachment extends Attachment implements IGeometry { + + /** + * Geometry that has been added but has not been integrated as the node + * hasn't been attached yet. + */ + private List+ * Handles generating renderer specific data from the input model shape. + *
+ * + * @param shape + * ICE shape to visualize + */ + protected abstract void processShape(IShape shape); + + /** + * @see IGeometry#addShape(Geometry) + */ + public void removeShape(IShape shape) { + if (shapes == null) { + return; + } + + if (!shapes.contains(shape)) { + return; + } + + shapes.remove(shape); + + disposeShape(shape); + } + + /** + * + * @param shape + */ + protected abstract void disposeShape(IShape shape); + + /** + * + */ + public boolean hasShape(IShape shape) { + if (shapes == null) { + return false; + } + + return shapes.contains(shape); + } + + /** + * + */ + public IShape getShape(int index) { + if (shapes == null) { + return null; + } + + return shapes.get(index); + } + + /** + * + * @param copy + * @return + */ + public List+ * Interface for implementing camera functionality in a GeometryViewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface ICamera { + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/IGeometry.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/IGeometry.java new file mode 100644 index 0000000000000000000000000000000000000000..da16f7bce50dd3907399cbfb8c296d346a8920c2 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/IGeometry.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import java.util.List; + +import org.eclipse.ice.viz.service.geometry.shapes.Geometry; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; + +/** + *+ * Interface for accepting and working with ICE Geometry instances. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IGeometry { + + /** + *+ * Adds a Geometry instance to this entity. + *
+ * + * @param geom + * an ICE Geometry instance + */ + public void addGeometry(Geometry geom); + + /** + *+ * Adds an IShape to this entity. + *
+ * + * @param shape + * an ICE IShape instance + */ + public void addShape(IShape shape); + + /** + *+ * Removes the supplied IShape from this entity. + *
+ * + * @param shape + * the ICE IShape to remove + */ + public void removeShape(IShape shape); + + /** + *+ * Returns true if the entity contains the supplied IShape, false otherwise. + *
+ * + * @param the + * ICE IShape to test for + * + * @return true if the entity contains the supplied IShape, false otherwise. + */ + public boolean hasShape(IShape shape); + + /** + *+ * Returns the IShape at the specified index or null if it cannot be found. + *
+ * + * @param index + * the index to retrieve the IShape at + * + * @return an IShape instance or null if one cannot be found + */ + public IShape getShape(int index); + + /** + *+ * Returns a list of the shapes associated with this entity. + *
+ * + *+ * Optionally, a copy can be made of the list. + *
+ * + * @param copy + * if true, the returned list will be a copy + * + * @return a List of IShapes associated with this shape. + */ + public List+ * Removes all shapes associated with this entity. + *
+ */ + public void clearShapes(); + + /** + *+ * Sets the entity to be immutable, which means it's values cannot be + * changed (no new geometry or shapes). + *
+ * + * @param immutable + * if true, the entity will be made immutable otherwise the + * entity will be mutable + */ + void setImmutable(boolean immutable); + + /** + *+ * Returns true if the entity is immutable, false otherwise. + *
+ */ + boolean isImmutable(); + + /** + *+ * Sets the entity to be visible or not visible in the scene. + *
+ * + * @param visible + * if true, the entity will be made visible otherwise the entity + * will not be visible + */ + void setVisible(boolean visible); + + /** + *+ * Returns true if the entity is visible, false otherwise. + *
+ */ + boolean isVisible(); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ISceneGenerator.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ISceneGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..574ed4af706a7bf85f71d86f0e1b9dc3f05dc70b --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ISceneGenerator.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; + +import javafx.scene.Node; + +/** + *+ * Generates an input + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface ISceneGenerator { + + /** + * + * @param newRoot + * @param internalRoot + * @param scene + * @return + */ + Node generateScene(INode newRoot); + + /** + * + * @param child + * @return + */ + Node generateNode(INode child); + + /** + * + * @param child + */ + void processAttachmentGroups(INode child); + + /** + * + * @param node + * @param currentAttachment + */ + void processAttachment(INode node, IAttachment currentAttachment); + +} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ModelUtil.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ModelUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..963150af223ab4a202ed583a41c7f2f00d4b858f --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ModelUtil.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.base; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; + +/** + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class ModelUtil { + + /** + *+ *
+ * + * @param obj + * @return + */ + public static boolean isNode(Object obj) { + return obj != null && obj instanceof INode; + } + + /** + * + * @param obj + * @return + */ + public static boolean isAttachment(Object obj) { + return obj != null && obj instanceof IAttachment; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IAttachment.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IAttachment.java new file mode 100644 index 0000000000000000000000000000000000000000..49ed083c0b5287a38bdd60c6cbfe5f0a5b2d3c99 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IAttachment.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.model; + +/** + *+ * Interface for attachments, which provide new capabilities for INode + * instances. These capabilities can be things like rendering geometry, + * providing advanced control over the node and more. + *
+ * + *+ * Because inheritance is a very poor, brittle way to extend node capabilities + * in a scene hierarchy, this approach allows for design via composition. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IAttachment { + + /** + *+ * Returns the node this attachment is attached to or null if there is no + * attached node. + *
+ * + * @return the INode currently attached or null if a node has not been + * attached. + */ + public INode getOwner(); + + /** + *+ * Adds this instance to the supplied node. The attachment's functionality + * will be applied to the new owner node. + *
+ * + *+ * If the attachment is a singleton, this will replace any existing + * attachment of the same type. + *
+ * + * @param owner + * the node to attach to + */ + public void attach(INode owner); + + /** + *+ * Removes this instance from the supplied node. Any functionality provided + * by this attachment will be removed from the owner node. + *
+ * + *+ * If the supplied node is not attached, this is a no-op. + *
+ * + * @param owner + * the node to detach from + */ + public void detach(INode owner); + + /** + *+ * If the attachment is a singleton, only a single instance of the + * attachment can be attached to any given node. + *
+ * + * @return true if the attachment type is a singleton, false otherwise. + */ + public boolean isSingleton(); + + /** + *+ * Returns the class type of the attachment. Note that this may not be the + * same as the concrete type. + *
+ * + * @return the class type of the attachment + */ + public Class> getType(); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/INode.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/INode.java new file mode 100644 index 0000000000000000000000000000000000000000..c9c6a76233b5fdc40429b5193e67bce000f734fd --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/INode.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.model; + +import java.util.List; +import java.util.Map; + +/** + *+ * Interface representation of a node in a scene. A node is an element in a + * scene that can contain other nodes, such: as child nodes, attachments which + * provide new capabilities (rendering, control, etc.) and properties which can + * be used to define node specific attributes. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface INode { + + /** Property key for accessing the associated renderer node. */ + public static final String RENDERER_NODE_PROP = "RENDERER_NODE"; + + /** + * + *+ * Returns the parent of the node, or null if the node is not associated + * with a parent. + *
+ * + * @return the parent of the node + */ + public INode getParent(); + + /** + *+ * Sets the parent of the node. + *
+ * + * @param parent + * the parent of the node to set + */ + public void setParent(INode parent); + + /** + *+ * Returns the human readable name of the node. + *
+ * + * @return a String containing the human readable name of the node. + */ + public String getName(); + + /** + *+ * Adds a node to this node as a child node. Once the child has been added, + * the child node will be linked to the parent for transforms and other + * operations. + *
+ * + * @param node + * node to add as child + */ + public void addChild(INode node); + + /** + *+ * Removes the supplied node as a child from this node. If node is not + * currently a child, this is a no-op. + *
+ * + * @param node + * node to remove as child + */ + public void removeChild(INode node); + + /** + *+ * Removes all children from this node. + *
+ * + * @param node + * removes all children from this node. + */ + public void removeAllChildren(); + + /** + *+ * Returns a List of this node's children, optionally returning a copy of + * the List. + *
+ * + * @return copy if true, the list will be a copy of the node's internal + * List. if false, the list will be a reference to the internal + * List. + */ + public List+ * Sets the visibility of the node. If the node is not visible, it will not + * show up in a viewport. + *
+ * + * @param visible + * if true, the node will be rendered in visualizations. if + * false, the node will not be rendered. + */ + public void setVisible(boolean visible); + + /** + *+ * Returns if the node is visible. + *
+ * + * @return true if the node is visible, false otherwise. + */ + public boolean isVisible(); + + /** + *+ * Adds the supplied attachment to this node. The attachment's functionality + * will be applied to this node. + *
+ * + * @param attachment + * the attachment to attach + */ + public void attach(IAttachment attachment); + + /** + *+ * Removes the supplied attachment to this node. The attachment's + * functionality with be removed from this node. + *
+ * + *+ * If the attachment is not currently attached, this is a no-op. + *
+ * + * @param attachment + * the attachment to remove. + */ + public void detach(IAttachment attachment); + + /** + *+ * Returns true if this node has an attachment of the supplied class type. + *
+ * + * @param attachmentClass + * the attachment class to check for. + * + * @return true if the attachment type exists in this node, false otherwise. + */ + public boolean hasAttachment(Class> attachmentClass); + + /** + *+ * Returns true if the node supports the supplied attachment. Some + * attachments may not be used together. + *
+ * + * @param attachment + * the attachment to check for + * + * @return true if the node supports the attachment, false otherwise + */ + public boolean supports(IAttachment attachment); + + /** + *+ * Returns a Map of all the node's attachments. + *
+ * + * @return a Map of the node's current attachments + */ + public Map+ * Returns a List of the node's attachments that are of the supplied type. + *
+ * + * @param clazz + * the attachment class type to retrieve + * + * @return a List of the node's attachments of the specified type. + */ + public List+ * Returns a Map of the node's current properties. + *
+ * + * @return a Map of the node's current properties. + */ + public Map+ * Returns the node property of the specified type or null if the property + * doesn't exist. + *
+ * + * @return the node property of the specified type or null if the property + * doesn't exist + */ + public Object getProperty(String key); + + /** + *+ * Sets the property identified by the key String to the supplied value. + *
+ * + * @param key + * the String identifier of the property + * @param value + * the value of the property + */ + public void setProperty(String key, Object value); + + /** + *+ * Returns true if the property has been set on this object, false + * otherwise. + *
+ * + * @param key + * the property key to check for + * + * @return true if the property exists, false otherwise + */ + public boolean hasProperty(String key); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IScene.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IScene.java new file mode 100644 index 0000000000000000000000000000000000000000..59bcc5ad8762d1e47028bc2b88860ec5ee9ad33c --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/model/IScene.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.scene.model; + +import java.util.List; +import java.util.Map; + +import org.eclipse.ice.viz.service.geometry.scene.base.ICamera; +import org.eclipse.ice.viz.service.geometry.scene.base.IGeometry; + +/** + *+ * Interface for a global scene representation. A scene has a root {@link INode} + * and also provides other data for easy access (camera, geometry, nodes, etc.) + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IScene { + + /** + *+ * Returns the scene's root node. + *
+ * + * @return an INode that is the top most node in the scene hierarchy. + */ + public INode getRoot(); + + /** + *+ * Returns the scene's cameras. + *
+ * + * @return a Map of the scene's cameras + */ + public Map+ * Returns a Map of all the INode instances in the scene. + *
+ * + * @return a Map of all the INode instances in the scene. + */ + public Map+ * Returns a list of all the {@link Geometry} used in the scene. + *
+ * + * @return a List of all the geometry used in the scene. + */ + public List- * Stores the list of keys for the property list - *
- * - */ - @XmlElement(name = "Keys") - private ArrayList- * Stores the list of values for the property list - *
- * - */ - @XmlElement(name = "Values") - private ArrayList- * The matrix transformation applied to the shape - *
- *- * In the case of a ComplexShape, each transformation affects its child - * shapes, so in order to calculate the final transformation of an - * individual PrimitiveShape, you must take the matrix product of all of the - * ancestors' transformations. - *
- *- * The transformation matrix applied to this node in the CSG tree - *
- * - */ - @XmlElement(name = "Transformation") - protected Transformation transformation; - - /** - *- * If applicable, the parent of the shape in the CSG tree - *
- * - */ - @XmlTransient - private IShape parent; - - /** - *- * Initializes the transformation matrix, creates the array containing the - * key/value property pairs, and creates a listeners list - *
- * - */ - public AbstractShape() { - - // Initialize transformation - transformation = new Transformation(); - - // Create properties lists - keys = new ArrayList- * Returns a copy of the transformation matrix associated with this shape - * node - *
- * - * @return- * The transformation matrix applied to this node in the CSG tree - *
- */ - @Override - public Transformation getTransformation() { - return this.transformation; - } - - /** - *- * Replaces the transformation matrix with a copy of the given Matrix4x4 - *
- *- * Returns whether the setting was successful - *
- * - * @param transformation - *- * The transformation matrix to be applied to the shape - *
- * @return- * True if setting the transformation was successful, false - * otherwise - *
- */ - @Override - public boolean setTransformation(Transformation transformation) { - - // Fail if null and return false - if (transformation == null) { - return false; - } - - // Otherwise set and return true - - this.transformation = transformation; - - // Notify listeners and return success - notifyListeners(); - return true; - - } - - /** - *- * Returns the value associated with the property key - *
- *- * If the key does not exist, this operation returns null. - *
- * - * @param key - *- * The key corresponding to the desired value - *
- * @return- * The value associated with the property key - *
- */ - @Override - public String getProperty(String key) { - - if (key == null || "".equals(key)) { - return null; - } - - // Get index of key - int index = keys.indexOf(key); - - if (index < 0) { - return null; - } - - // Return the value - try { - return values.get(index); - } catch (IndexOutOfBoundsException e) { - return null; - } - - } - - /** - *- * Sets the property value associated with the key string - *
- *- * If the key does not yet exist, append the key/value pair to the end of - * the property list. If it exists, find and replace the property value with - * the new one. - *
- * - * @param key - *- * The new key - *
- * @param value - *- * The new value - *
- * @return- * True if the property setting is valid, false otherwise - *
- */ - @Override - public boolean setProperty(String key, String value) { - - // Validate parameters - if (key == null || "".equals(key) || value == null) { - return false; - } - // Find index of key - int index = keys.indexOf(key); - - // Update - - if (index < 0) { - // Insert new value - - keys.add(key); - values.add(value); - } else { - // Modify the value - - values.set(index, value); - } - - // Notify listeners and return success - notifyListeners(); - return true; - - } - - /** - *- * Removes the value associated with the key in the properties list - *
- *- * This operation returns whether the key was found and removed. - *
- * - * @param key - *- * The key associated with the value to remove - *
- * @return- * True if the value was found and removed, false otherwise - *
- */ - @Override - public boolean removeProperty(String key) { - // Validate parameters - - if (key == null) { - return false; - } - // Get index of key - - int index = keys.indexOf(key); - - if (index < 0) { - return false; - } - keys.remove(index); - values.remove(index); - - // Notify listeners and return success - notifyListeners(); - return true; - } - - /** - *- * This operation returns the hashcode value of the shape. - *
- * - * @return- * The hashcode of the object - *
- */ - @Override - public int hashCode() { - // Get initial hash code - int hash = super.hashCode(); - - // Hash the transformation - hash = 31 * hash + transformation.hashCode(); - - // Hash the properties - hash = 31 * hash + keys.hashCode(); - hash = 31 * hash + values.hashCode(); - - return hash; - } - - /** - *- * This operation is used to check equality between this shape and another - * shape. It returns true if the shape are equal and false if they are not. - *
- * - * @param otherObject - *- * The other ICEObject that should be compared with this one. - *
- * @return- * True if the ICEObjects are equal, false otherwise. - *
- */ - @Override - public boolean equals(Object otherObject) { - - // Check if a similar reference - if (this == otherObject) { - return true; - } - // Check that the other object is not null and an instance of the - // PrimitiveShape - if (otherObject == null || !(otherObject instanceof AbstractShape)) { - return false; - } - // Check that these objects have the same ICEObject data - if (!super.equals(otherObject)) { - return false; - } - - // At this point, other object must be a PrimitiveShape, so cast it - AbstractShape abstractShape = (AbstractShape) otherObject; - - // Check for unequal transformation - if (!transformation.equals(abstractShape.transformation)) { - return false; - } - // Check for unequal properties - if (!keys.equals(abstractShape.keys) - || !values.equals(abstractShape.values)) { - return false; - } - // The two objects are equal - return true; - - } - - /** - *- * Copies the contents of a shape into the current object using a deep copy - *
- * - * @param iceObject - *- * The ICEObject from which the values should be copied - *
- */ - public void copy(AbstractShape iceObject) { - - // Return if object is null - if (iceObject == null) { - return; - } - // Copy the ICEObject data - super.copy(iceObject); - - // Copy transformation - this.transformation = (Transformation) iceObject.transformation.clone(); - - // Copy properties - - this.keys.clear(); - this.values.clear(); - - for (String key : iceObject.keys) { - this.keys.add(key); - } - - for (String value : iceObject.values) { - this.values.add(value); - } - - this.notifyListeners(); - - } - - /** - *- * This operation directs the Component to call back to an IComponentVisitor - * so that the visitor can perform its required actions for the exact type - * of the Component. - *
- * - * @param visitor - *- * The visitor querying the type of the object - *
- */ - public void accept(IShapeVisitor visitor) { - - } - - /** - *- * Notifies all IUpdateableListeners in the listener list that an event has - * occurred which has changed the state of the shape - *
- * - */ - @Override - protected void notifyListeners() { - - // Let the base class handle most of the notifications - super.notifyListeners(); - - // Notify the parent's listeners - if (parent != null) { - ((AbstractShape) parent).notifyListeners(); - } - } - - /** - *- * Returns the parent associated with this shape, or null if the shape does - * not have a parent - *
- * - * @return- * The parent of the shape - *
- */ - @Override - public IShape getParent() { - return parent; - } - - /** - *- * Sets the parent of the IShape - *
- * - * @param parent - *- * The parent of the IShape - *
- */ - public void setParent(IShape parent) { - this.parent = parent; - } + /** + *+ * Stores the list of keys for the property list + *
+ * + */ + @XmlElement(name = "Keys") + private ArrayList+ * Stores the list of values for the property list + *
+ * + */ + @XmlElement(name = "Values") + private ArrayList+ * The matrix transformation applied to the shape + *
+ *+ * In the case of a ComplexShape, each transformation affects its child + * shapes, so in order to calculate the final transformation of an + * individual PrimitiveShape, you must take the matrix product of all of the + * ancestors' transformations. + *
+ *+ * The transformation matrix applied to this node in the CSG tree + *
+ * + */ + @XmlElement(name = "Transformation") + protected Transformation transformation; + + /** + *+ * If applicable, the parent of the shape in the CSG tree + *
+ * + */ + @XmlTransient + private IShape parent; + + /** + *+ * Initializes the transformation matrix, creates the array containing the + * key/value property pairs, and creates a listeners list + *
+ * + */ + public AbstractShape() { + + // Initialize transformation + transformation = new Transformation(); + + // Create properties lists + keys = new ArrayList+ * Returns a copy of the transformation matrix associated with this shape + * node + *
+ * + * @return + *+ * The transformation matrix applied to this node in the CSG tree + *
+ */ + @Override + public Transformation getTransformation() { + return this.transformation; + } + + /** + *+ * Replaces the transformation matrix with a copy of the given Matrix4x4 + *
+ *+ * Returns whether the setting was successful + *
+ * + * @param transformation + *+ * The transformation matrix to be applied to the shape + *
+ * @return + *+ * True if setting the transformation was successful, false + * otherwise + *
+ */ + @Override + public boolean setTransformation(Transformation transformation) { + + // Fail if null and return false + if (transformation == null) { + return false; + } + + // Otherwise set and return true + + this.transformation = transformation; + + // Notify listeners and return success + notifyListeners(); + return true; + + } + + /** + *+ * Returns the value associated with the property key + *
+ *+ * If the key does not exist, this operation returns null. + *
+ * + * @param key + *+ * The key corresponding to the desired value + *
+ * @return + *+ * The value associated with the property key + *
+ */ + @Override + public String getProperty(String key) { + + if (key == null || "".equals(key)) { + return null; + } + + // Get index of key + int index = keys.indexOf(key); + + if (index < 0) { + return null; + } + + // Return the value + try { + return values.get(index); + } catch (IndexOutOfBoundsException e) { + return null; + } + + } + + /** + *+ * Sets the property value associated with the key string + *
+ *+ * If the key does not yet exist, append the key/value pair to the end of + * the property list. If it exists, find and replace the property value with + * the new one. + *
+ * + * @param key + *+ * The new key + *
+ * @param value + *+ * The new value + *
+ * @return + *+ * True if the property setting is valid, false otherwise + *
+ */ + @Override + public boolean setProperty(String key, String value) { + + // Validate parameters + if (key == null || "".equals(key) || value == null) { + return false; + } + // Find index of key + int index = keys.indexOf(key); + + // Update + + if (index < 0) { + // Insert new value + + keys.add(key); + values.add(value); + } else { + // Modify the value + + values.set(index, value); + } + + // Notify listeners and return success + notifyListeners(); + return true; + + } + + /** + *+ * Removes the value associated with the key in the properties list + *
+ *+ * This operation returns whether the key was found and removed. + *
+ * + * @param key + *+ * The key associated with the value to remove + *
+ * @return + *+ * True if the value was found and removed, false otherwise + *
+ */ + @Override + public boolean removeProperty(String key) { + // Validate parameters + + if (key == null) { + return false; + } + // Get index of key + + int index = keys.indexOf(key); + + if (index < 0) { + return false; + } + keys.remove(index); + values.remove(index); + + // Notify listeners and return success + notifyListeners(); + return true; + } + + /** + *+ * This operation returns the hashcode value of the shape. + *
+ * + * @return + *+ * The hashcode of the object + *
+ */ + @Override + public int hashCode() { + // Get initial hash code + int hash = super.hashCode(); + + // Hash the transformation + hash = 31 * hash + transformation.hashCode(); + + // Hash the properties + hash = 31 * hash + keys.hashCode(); + hash = 31 * hash + values.hashCode(); + + return hash; + } + + /** + *+ * This operation is used to check equality between this shape and another + * shape. It returns true if the shape are equal and false if they are not. + *
+ * + * @param otherObject + *+ * The other ICEObject that should be compared with this one. + *
+ * @return + *+ * True if the ICEObjects are equal, false otherwise. + *
+ */ + @Override + public boolean equals(Object otherObject) { + + // Check if a similar reference + if (this == otherObject) { + return true; + } + // Check that the other object is not null and an instance of the + // PrimitiveShape + if (otherObject == null || !(otherObject instanceof AbstractShape)) { + return false; + } + // Check that these objects have the same ICEObject data + if (!super.equals(otherObject)) { + return false; + } + + // At this point, other object must be a PrimitiveShape, so cast it + AbstractShape abstractShape = (AbstractShape) otherObject; + + // Check for unequal transformation + if (!transformation.equals(abstractShape.transformation)) { + return false; + } + // Check for unequal properties + if (!keys.equals(abstractShape.keys) || !values.equals(abstractShape.values)) { + return false; + } + // The two objects are equal + return true; + + } + + /** + *+ * Copies the contents of a shape into the current object using a deep copy + *
+ * + * @param iceObject + *+ * The ICEObject from which the values should be copied + *
+ */ + public void copy(AbstractShape iceObject) { + + // Return if object is null + if (iceObject == null) { + return; + } + // Copy the ICEObject data + super.copy(iceObject); + + // Copy transformation + this.transformation = (Transformation) iceObject.transformation.clone(); + + // Copy properties + + this.keys.clear(); + this.values.clear(); + + for (String key : iceObject.keys) { + this.keys.add(key); + } + + for (String value : iceObject.values) { + this.values.add(value); + } + + this.notifyListeners(); + + } + + /** + *+ * This operation directs the Component to call back to an IComponentVisitor + * so that the visitor can perform its required actions for the exact type + * of the Component. + *
+ * + * @param visitor + *+ * The visitor querying the type of the object + *
+ */ + public void accept(IShapeVisitor visitor) { + + } + + /** + *+ * Notifies all IUpdateableListeners in the listener list that an event has + * occurred which has changed the state of the shape + *
+ * + */ + @Override + protected void notifyListeners() { + + // Let the base class handle most of the notifications + super.notifyListeners(); + + // Notify the parent's listeners + if (parent != null) { + ((AbstractShape) parent).notifyListeners(); + } + } + + /** + *+ * Returns the parent associated with this shape, or null if the shape does + * not have a parent + *
+ * + * @return + *+ * The parent of the shape + *
+ */ + @Override + public IShape getParent() { + return parent; + } + + /** + *+ * Sets the parent of the IShape + *
+ * + * @param parent + *+ * The parent of the IShape + *
+ */ + public void setParent(IShape parent) { + this.parent = parent; + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ComplexShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ComplexShape.java index 3df1fdb6f0976c307b18d09605b2cbcd5598b6e9..25278684300a5bfa9416d0df07465cd98b5a12bb 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ComplexShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ComplexShape.java @@ -38,390 +38,393 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "ComplexShape") @XmlAccessorType(XmlAccessType.FIELD) public class ComplexShape extends AbstractShape { - /** - *- * Represents the type of boolean operator applied to the ComplexShape - *
- *- * Type of the geometry set operator applied to this set of shapes - *
- * - */ - @XmlAttribute - private OperatorType operatorType; - /** - *- * Ordered list of shapes which are contained - *
- *- * List of shapes in the set - *
- * - */ - @XmlAnyElement() - @XmlElementRefs(value = { - @XmlElementRef(name = "ComplexShape", type = ComplexShape.class), - @XmlElementRef(name = "PrimitiveShape", type = PrimitiveShape.class) }) - private ArrayList- * Calls AbstractShape's constructor and sets the operator type to None - *
- * - */ - public ComplexShape() { - - // Call AbstractShape's constructor - super(); - - // Initialize operatorType to None - this.operatorType = OperatorType.None; - - // Initialize shapes list - shapes = new ArrayList- * Calls AbstractShape's constructor and sets the operator type to the given - * value - *
- * - * @param operatorType - *- * The OperatorType to set for the new ComplexShape - *
- */ - public ComplexShape(OperatorType operatorType) { - - // Call nullery constructor first - this(); - - // Set the given operatorType - if (operatorType == null) { - operatorType = OperatorType.None; - } - this.operatorType = operatorType; - - } - - /** - *- * Accepts all values of the OperatorType enumerator - *
- *- * Once the OperatorType has been set to a value which is not None, the - * OperatorType cannot be changed. Any additional calls to this operation - * will be ignored. - *
- * - * @param operatorType - *- * The type of the geometry set operator to be applied to this - * set of shapes - *
- */ - public void setType(OperatorType operatorType) { - - // Fail silently if operatorType is null - if (operatorType == null) { - return; - } - // Set the type only if the current OperatorType is None - if (this.operatorType == OperatorType.None) { - this.operatorType = operatorType; - - // We've updated a value, so notify listeners - notifyListeners(); - } - - } - - /** - *- * Returns the OperatorType of the ComplexShape - *
- * - * @return- * Type of the geometry set operator applied to this set of shapes - *
- */ - public OperatorType getType() { - return operatorType; - } - - /** - *- * Appends a single shape to the end of the shape list - *
- * - * @param shape - *- * The shape to be added - *
- */ - public void addShape(IShape shape) { - - // Check that the shape is not null or a reference to itself - if (shape == null || shape == this) { - return; - } - shapes.add(shape); - - // Notify listeners - notifyListeners(); - - ((AbstractShape) shape).setParent(this); - - } - - /** - *- * Removes a single shape from the shape list - *
- * - * @param shape - *- * The shape reference to find and remove from the ComplexShape - *
- */ - public void removeShape(IShape shape) { - - // Remove the shape from the shapes list - boolean success = shapes.remove(shape); - - if (success) { - // If the shape was actually removed, notify listeners - notifyListeners(); - - ((AbstractShape) shape).setParent(null); - } - - } - - /** - *- * Returns a reference to the list of shapes containing in this ComplexShape - *
- * - * @return- * List of shapes contained in the ComplexShape - *
- */ - public ArrayList- * Replaces the list of shapes with the given ArrayList - *
- * - * @param shapes - *- * The list of shapes which will replace the old list - *
- */ - public void setShapes(ArrayList- * This operation returns the hashcode value of the ComplexShape. - *
- * - * @return- * The hashcode of the ICEObject. - *
- */ - @Override - public int hashCode() { - - // Get the initial hashcode - int hash = super.hashCode(); - - // Hash the OperatorType - hash = 31 * hash + operatorType.hashCode(); - - // Hash each shape in the shapes list - for (IShape shape : shapes) { - hash = 31 * hash + shape.hashCode(); - } - - return hash; - - } - - /** - *- * This operation is used to check equality between this ComplexShape and - * another ComplexShape. It returns true if the ComplexShapes are equal and - * false if they are not. - *
- * - * @param otherObject - *- * The other ICEObject that should be compared with this one. - *
- * @return- * True if the ICEObjects are equal, false otherwise. - *
- */ - @Override - public boolean equals(Object otherObject) { - - // Check if a similar reference - if (this == otherObject) { - return true; - } - // Check that the other object is not null and an instance of the - // ComplexShape - if (otherObject == null || !(otherObject instanceof ComplexShape)) { - return false; - } - // Check that these objects have the same ICEObject data - if (!super.equals(otherObject)) { - return false; - } - // At this point, other object must be a PrimitiveShape, so cast it - ComplexShape otherComplexShape = (ComplexShape) otherObject; - - // Check for equal OperatorTypes - if (this.operatorType != otherComplexShape.operatorType) { - return false; - } - // Check for equal number of shapes in shapes list - if (this.shapes.size() != otherComplexShape.shapes.size()) { - return false; - } - // Check for equal elements in shapes list - // The list must be ordered similarly for this test to pass. - // This is desired for an intersection, for example, where the first - // element has significance. - int numShapes = shapes.size(); - for (int index = 0; index < numShapes; index++) { - - // Check for equal shapes in the current index - if (!shapes.get(index).equals(otherComplexShape.shapes.get(index))) { - return false; - } - } - - // The two shapes might as well be equal. - return true; - - } - - /** - *- * This operation copies the contents of a ComplexShape into the current - * object using a deep copy. - *
- * - * @param iceObject - *- * The ICEObject from which the values should be copied. - *
- */ - public void copy(ComplexShape iceObject) { - - // Return if object is null - if (iceObject == null) { - return; - } - // Copy the ICEObject data - super.copy(iceObject); - - // Copy operatorType - this.operatorType = iceObject.operatorType; - - // Copy shapes list - this.shapes.clear(); - - for (IShape shape : iceObject.shapes) { - - // Assume that all IShapes are AbstractShapes - // (We must do this because IShape is an interface. It cannot - // extend ICEObject to be cloned.) - - AbstractShape clonedShape = (AbstractShape) ((AbstractShape) shape) - .clone(); - clonedShape.setParent(this); - - this.shapes.add(clonedShape); - } - - } - - /** - *- * This operation returns a clone of the ComplexShape using a deep copy. - *
- * - * @return- * The new clone. - *
- */ - @Override - public Object clone() { - - // Create a new ComplexShape - ComplexShape complexShape = new ComplexShape(); - - // Copy `this` into complexShape - complexShape.copy(this); - - return complexShape; - - } - - /** - * (non-Javadoc) - * - * @see IUpdateable#update(String updatedKey, String newValue) - */ - @Override - public void update(String updatedKey, String newValue) { - // Not implemented - } - - /** - * (non-Javadoc) - * - * @see IShape#acceptShapeVisitor(IShapeVisitor visitor) - */ - @Override - public void acceptShapeVisitor(IShapeVisitor visitor) { - - // Only visit if it is not null - if (visitor != null) { - visitor.visit(this); - } - } + /** + *+ * Represents the type of boolean operator applied to the ComplexShape + *
+ *+ * Type of the geometry set operator applied to this set of shapes + *
+ * + */ + @XmlAttribute + private OperatorType operatorType; + /** + *+ * Ordered list of shapes which are contained + *
+ *+ * List of shapes in the set + *
+ * + */ + @XmlAnyElement() + @XmlElementRefs(value = { @XmlElementRef(name = "ComplexShape", type = ComplexShape.class), + @XmlElementRef(name = "PrimitiveShape", type = PrimitiveShape.class) }) + private ArrayList+ * Calls AbstractShape's constructor and sets the operator type to None + *
+ * + */ + public ComplexShape() { + + // Call AbstractShape's constructor + super(); + + // Initialize operatorType to None + this.operatorType = OperatorType.None; + + // Initialize shapes list + shapes = new ArrayList+ * Calls AbstractShape's constructor and sets the operator type to the given + * value + *
+ * + * @param operatorType + *+ * The OperatorType to set for the new ComplexShape + *
+ */ + public ComplexShape(OperatorType operatorType) { + + // Call nullery constructor first + this(); + + // Set the given operatorType + if (operatorType == null) { + operatorType = OperatorType.None; + } + this.operatorType = operatorType; + + } + + /** + *+ * Accepts all values of the OperatorType enumerator + *
+ *+ * Once the OperatorType has been set to a value which is not None, the + * OperatorType cannot be changed. Any additional calls to this operation + * will be ignored. + *
+ * + * @param operatorType + *+ * The type of the geometry set operator to be applied to this + * set of shapes + *
+ */ + public void setType(OperatorType operatorType) { + + // Fail silently if operatorType is null + if (operatorType == null) { + return; + } + // Set the type only if the current OperatorType is None + if (this.operatorType == OperatorType.None) { + this.operatorType = operatorType; + + // We've updated a value, so notify listeners + notifyListeners(); + } + + } + + /** + *+ * Returns the OperatorType of the ComplexShape + *
+ * + * @return + *+ * Type of the geometry set operator applied to this set of shapes + *
+ */ + public OperatorType getType() { + return operatorType; + } + + /** + *+ * Appends a single shape to the end of the shape list + *
+ * + * @param shape + *+ * The shape to be added + *
+ */ + public void addShape(IShape shape) { + + // Check that the shape is not null or a reference to itself + if (shape == null || shape == this) { + return; + } + shapes.add(shape); + + // Notify listeners + notifyListeners(); + + ((AbstractShape) shape).setParent(this); + + } + + /** + *+ * Removes a single shape from the shape list + *
+ * + * @param shape + *+ * The shape reference to find and remove from the ComplexShape + *
+ */ + public void removeShape(IShape shape) { + + // Remove the shape from the shapes list + boolean success = shapes.remove(shape); + + if (success) { + // If the shape was actually removed, notify listeners + notifyListeners(); + + ((AbstractShape) shape).setParent(null); + } + + } + + /** + *+ * Returns a reference to the list of shapes containing in this ComplexShape + *
+ * + * @return + *+ * List of shapes contained in the ComplexShape + *
+ */ + public ArrayList+ * Replaces the list of shapes with the given ArrayList + *
+ * + * @param shapes + *+ * The list of shapes which will replace the old list + *
+ */ + public void setShapes(ArrayList+ * This operation returns the hashcode value of the ComplexShape. + *
+ * + * @return + *+ * The hashcode of the ICEObject. + *
+ */ + @Override + public int hashCode() { + + // Get the initial hashcode + int hash = super.hashCode(); + + // Hash the OperatorType + hash = 31 * hash + operatorType.hashCode(); + + // Hash each shape in the shapes list + for (IShape shape : shapes) { + hash = 31 * hash + shape.hashCode(); + } + + return hash; + + } + + /** + *+ * This operation is used to check equality between this ComplexShape and + * another ComplexShape. It returns true if the ComplexShapes are equal and + * false if they are not. + *
+ * + * @param otherObject + *+ * The other ICEObject that should be compared with this one. + *
+ * @return + *+ * True if the ICEObjects are equal, false otherwise. + *
+ */ + @Override + public boolean equals(Object otherObject) { + + // Check if a similar reference + if (this == otherObject) { + return true; + } + // Check that the other object is not null and an instance of the + // ComplexShape + if (otherObject == null || !(otherObject instanceof ComplexShape)) { + return false; + } + // Check that these objects have the same ICEObject data + if (!super.equals(otherObject)) { + return false; + } + // At this point, other object must be a PrimitiveShape, so cast it + ComplexShape otherComplexShape = (ComplexShape) otherObject; + + // Check for equal OperatorTypes + if (this.operatorType != otherComplexShape.operatorType) { + return false; + } + // Check for equal number of shapes in shapes list + if (this.shapes.size() != otherComplexShape.shapes.size()) { + return false; + } + // Check for equal elements in shapes list + // The list must be ordered similarly for this test to pass. + // This is desired for an intersection, for example, where the first + // element has significance. + int numShapes = shapes.size(); + for (int index = 0; index < numShapes; index++) { + + // Check for equal shapes in the current index + if (!shapes.get(index).equals(otherComplexShape.shapes.get(index))) { + return false; + } + } + + // The two shapes might as well be equal. + return true; + + } + + /** + *+ * This operation copies the contents of a ComplexShape into the current + * object using a deep copy. + *
+ * + * @param iceObject + *+ * The ICEObject from which the values should be copied. + *
+ */ + public void copy(ComplexShape iceObject) { + + // Return if object is null + if (iceObject == null) { + return; + } + // Copy the ICEObject data + super.copy(iceObject); + + // Copy operatorType + this.operatorType = iceObject.operatorType; + + // Copy shapes list + this.shapes.clear(); + + for (IShape shape : iceObject.shapes) { + + // Assume that all IShapes are AbstractShapes + // (We must do this because IShape is an interface. It cannot + // extend ICEObject to be cloned.) + + AbstractShape clonedShape = (AbstractShape) ((AbstractShape) shape).clone(); + clonedShape.setParent(this); + + this.shapes.add(clonedShape); + } + + } + + /** + *+ * This operation returns a clone of the ComplexShape using a deep copy. + *
+ * + * @return + *+ * The new clone. + *
+ */ + @Override + public Object clone() { + + // Create a new ComplexShape + ComplexShape complexShape = new ComplexShape(); + + // Copy `this` into complexShape + complexShape.copy(this); + + return complexShape; + + } + + /** + * (non-Javadoc) + * + * @see IUpdateable#update(String updatedKey, String newValue) + */ + @Override + public void update(String updatedKey, String newValue) { + // Not implemented + } + + /** + * (non-Javadoc) + * + * @see IShape#acceptShapeVisitor(IShapeVisitor visitor) + */ + @Override + public void acceptShapeVisitor(IShapeVisitor visitor) { + + // Only visit if it is not null + if (visitor != null) { + visitor.visit(this); + } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Geometry.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Geometry.java index 5089ff7b5af38203d0bba153123b3c67914b5756..34d0eb12015f0fe5e8a0c9a22a940f882007cec6 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Geometry.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Geometry.java @@ -1,481 +1,487 @@ -/******************************************************************************* - * Copyright (c) 2015 UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Initial API and implementation and/or initial documentation - Jay Jay Billings, - * Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson, - * Claire Saunders, Matthew Wang, Anna Wojtowicz, Robert Smith - *******************************************************************************/ -package org.eclipse.ice.viz.service.geometry.shapes; - -import java.util.ArrayList; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAnyElement; -import javax.xml.bind.annotation.XmlElementRef; -import javax.xml.bind.annotation.XmlElementRefs; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; -import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener; -import org.eclipse.ice.viz.service.datastructures.VizObject.VizObject; - -/** - * A class which manages a collection of shapes for its parent - * GeometryComponent. It is registered as a listener for each IShape and the - * parent GeometryComponent is registered as a listener of this class. - * - * @author Jay Jay Billings - * @author Robert Smith - * - */ - -@XmlRootElement(name = "Geometry") -@XmlAccessorType(XmlAccessType.FIELD) -public class Geometry extends VizObject implements IVizUpdateable, IVizUpdateableListener { - - /** - *- * The list of shapes referenced by the GeometryComponent container - *
- * - */ - @XmlAnyElement() - @XmlElementRefs(value = { - @XmlElementRef(name = "ComplexShape", type = ComplexShape.class), - @XmlElementRef(name = "PrimitiveShape", type = PrimitiveShape.class) }) - private ArrayList- * Creates empty lists of IShapes and IUpdateableListeners - *
- * - */ - public Geometry() { - // Create new shapes and listeners lists - shapes = new ArrayList- * Adds an IShape to the shape list - *
- * - * @param shape - *- * The new shape to be added to the existing list - *
- */ - public void addShape(IShape shape) { - - // Ignore null - if (shape == null) { - return; - } - // Register the parent GeometryComponent as a listener - shape.register(this); - - // Add the shape to the shapes list - shapes.add(shape); - - // Notify the listeners - update(shape); - - } - - /** - *- * Removes the given IShape if it exists in the shape list - *
- * - * @param shape - *- * The IShape reference to be removed from the shapes list - *
- */ - public void removeShape(IShape shape) { - - // Ignore null - if (shape == null) { - return; - } - // Remove the shape from the shapes list if it exists - if (shapes.remove(shape)) { - - // Notify listeners if a change was made - update(shape); - } - - } - - /** - *- * Returns a list of all IShapes stored in the shapes list - *
- * - * @return- * The list of shapes contained in this GeometryComponent container - *
- */ - public ArrayList- * The shapes list to replace the existing shapes list - *
- */ - public void setShapes(ArrayList- * This operation returns the hashcode value of the GeometryComponent. - *
- * - * @return- * The hashcode of the ICEObject. - *
- */ - @Override - public int hashCode() { - - // Start with the ICEObject's hashcode - int hash = super.hashCode(); - - // Hash the list - for (IShape shape : shapes) { - hash = 31 * hash + shape.hashCode(); - } - - return hash; - - } - - /** - *- * This operation is used to check equality between this GeometryComponent - * and another GeometryComponent. It returns true if the GeometryComponents - * are equal and false if they are not. - *
- * - * @param otherObject - *- * The other ICEObject that should be compared with this one. - *
- * @return- * True if the ICEObjects are equal, false otherwise. - *
- */ - @Override - public boolean equals(Object otherObject) { - - // Check if a similar reference - if (this == otherObject) { - return true; - } - // Check that the other object is not null and an instance of the - // GeometryComponent - if (otherObject == null || !(otherObject instanceof Geometry)) { - return false; - } - - // At this point, other object must be a PrimitiveShape, so cast it - Geometry geometry = (Geometry) otherObject; - - // Check for equal number of shapes in shapes list - if (this.shapes.size() != geometry.shapes.size()) { - return false; - } - // Check for equal elements in shapes list - // The list must be ordered similarly for this test to pass. - int numShapes = shapes.size(); - for (int index = 0; index < numShapes; index++) { - - // Check for equal shapes in the current index - if (!shapes.get(index).equals(geometry.shapes.get(index))) { - return false; - } - } - - // The two shapes are equal - return true; - - } - - /** - *- * This operation copies the contents of a GeometryComponent into the - * current object using a deep copy. - *
- * - * @param iceObject - *- * The ICEObject from which the values should be copied - *
- */ - public void copy(Geometry iceObject) { - - // Return if object is null - if (iceObject == null) { - return; - } - - // Copy listeners list - this.listeners.clear(); - - for (IVizUpdateableListener listener : iceObject.listeners) { - this.listeners.add(listener); - } - - // Tracks whether the parent component needs to be alerted to a change - boolean updateComponent = false; - - // If there were shapes that will be overwritten, a change has been made - if (shapes.size() > 0) { - updateComponent = true; - } - - // Copy shapes list - this.shapes.clear(); - - for (IShape shape : iceObject.shapes) { - this.shapes.add((IShape) shape.clone()); - - // At least one shape has been added - updateComponent = true; - } - - // A change has been made, notify the listeners - if (updateComponent) { - update(new PrimitiveShape()); - } - - } - - /** - *- * This operation returns a clone of the GeometryComponent using a deep - * copy. - *
- * - * @return- * The new clone - *
- */ - @Override - public Object clone() { - - // Instantiate GeometryComponent - Geometry geometry = new Geometry(); - - // Return the copied GeometryComponent - geometry.copy(this); - return geometry; - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.IUpdateableListener#update(org - * .eclipse.ice.datastructures.ICEObject.IUpdateable) - */ - @Override - public void update(IVizUpdateable component) { - final Geometry geometry = this; - - // If the listeners are empty, return - if (this.listeners == null || this.listeners.isEmpty()) { - return; - } - // Create a thread object that notifies all listeners - - Thread notifyThread = new Thread() { - - @Override - public void run() { - // Loop over all listeners and update them - for (int i = 0; i < listeners.size(); i++) { - listeners.get(i).update(geometry); - } - } - }; - - // Start the thread - notifyThread.start(); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#setId(int) - */ - @Override - public void setId(int id) { - this.id = id; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.Identifiable#getDescription() - */ - @Override - public String getDescription() { - return description; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#getId() - */ - @Override - public int getId() { - return id; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.Identifiable#setName(java.lang - * .String) - */ - @Override - public void setName(String name) { - this.name = name; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#getName() - */ - @Override - public String getName() { - return name; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.Identifiable#setDescription( - * java.lang.String) - */ - @Override - public void setDescription(String description) { - this.description = description; - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.IUpdateable#update(java.lang - * .String, java.lang.String) - */ - @Override - public void update(String updatedKey, String newValue) { - // Not implemented - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.IUpdateable#register(org.eclipse - * .ice.datastructures.ICEObject.IUpdateableListener) - */ - @Override - public void register(IVizUpdateableListener listener) { - listeners.add(listener); - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ice.datastructures.ICEObject.IUpdateable#unregister(org.eclipse - * .ice.datastructures.ICEObject.IUpdateableListener) - */ - @Override - public void unregister(IVizUpdateableListener listener) { - listeners.remove(listener); - - } - -} +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - Jay Jay Billings, + * Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson, + * Claire Saunders, Matthew Wang, Anna Wojtowicz, Robert Smith + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.shapes; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener; +import org.eclipse.ice.viz.service.datastructures.VizObject.VizObject; + +/** + * A class which manages a collection of shapes for its parent + * GeometryComponent. It is registered as a listener for each IShape and the + * parent GeometryComponent is registered as a listener of this class. + * + * @author Jay Jay Billings + * @author Robert Smith + * + */ + +@XmlRootElement(name = "Geometry") +@XmlAccessorType(XmlAccessType.FIELD) +public class Geometry extends VizObject implements IVizUpdateable, IVizUpdateableListener { + + /** + *+ * The list of shapes referenced by the GeometryComponent container + *
+ * + */ + @XmlAnyElement() + @XmlElementRefs(value = { @XmlElementRef(name = "ComplexShape", type = ComplexShape.class), + @XmlElementRef(name = "PrimitiveShape", type = PrimitiveShape.class) }) + private ArrayList+ * Creates empty lists of IShapes and IUpdateableListeners + *
+ * + */ + public Geometry() { + // Create new shapes and listeners lists + shapes = new ArrayList+ * Adds an IShape to the shape list + *
+ * + * @param shape + *+ * The new shape to be added to the existing list + *
+ */ + public void addShape(IShape shape) { + + // Ignore null + if (shape == null) { + return; + } + // Register the parent GeometryComponent as a listener + shape.register(this); + + // Add the shape to the shapes list + shapes.add(shape); + + // Notify the listeners + update(shape); + + } + + /** + *+ * Removes the given IShape if it exists in the shape list + *
+ * + * @param shape + *+ * The IShape reference to be removed from the shapes list + *
+ */ + public void removeShape(IShape shape) { + + // Ignore null + if (shape == null) { + return; + } + // Remove the shape from the shapes list if it exists + if (shapes.remove(shape)) { + + // Notify listeners if a change was made + update(shape); + } + + } + + /** + *+ * Returns a list of all IShapes stored in the shapes list + *
+ * + * @return + *+ * The list of shapes contained in this GeometryComponent container + *
+ */ + public ArrayList+ * The shapes list to replace the existing shapes list + *
+ */ + public void setShapes(ArrayList+ * This operation returns the hashcode value of the GeometryComponent. + *
+ * + * @return + *+ * The hashcode of the ICEObject. + *
+ */ + @Override + public int hashCode() { + + // Start with the ICEObject's hashcode + int hash = super.hashCode(); + + // Hash the list + for (IShape shape : shapes) { + hash = 31 * hash + shape.hashCode(); + } + + return hash; + + } + + /** + *+ * This operation is used to check equality between this GeometryComponent + * and another GeometryComponent. It returns true if the GeometryComponents + * are equal and false if they are not. + *
+ * + * @param otherObject + *+ * The other ICEObject that should be compared with this one. + *
+ * @return + *+ * True if the ICEObjects are equal, false otherwise. + *
+ */ + @Override + public boolean equals(Object otherObject) { + + // Check if a similar reference + if (this == otherObject) { + return true; + } + // Check that the other object is not null and an instance of the + // GeometryComponent + if (otherObject == null || !(otherObject instanceof Geometry)) { + return false; + } + + // At this point, other object must be a PrimitiveShape, so cast it + Geometry geometry = (Geometry) otherObject; + + // Check for equal number of shapes in shapes list + if (this.shapes.size() != geometry.shapes.size()) { + return false; + } + // Check for equal elements in shapes list + // The list must be ordered similarly for this test to pass. + int numShapes = shapes.size(); + for (int index = 0; index < numShapes; index++) { + + // Check for equal shapes in the current index + if (!shapes.get(index).equals(geometry.shapes.get(index))) { + return false; + } + } + + // The two shapes are equal + return true; + + } + + /** + *+ * This operation copies the contents of a GeometryComponent into the + * current object using a deep copy. + *
+ * + * @param iceObject + *+ * The ICEObject from which the values should be copied + *
+ */ + public void copy(Geometry iceObject) { + + // Return if object is null + if (iceObject == null) { + return; + } + + // Copy listeners list + this.listeners.clear(); + + for (IVizUpdateableListener listener : iceObject.listeners) { + this.listeners.add(listener); + } + + // Tracks whether the parent component needs to be alerted to a change + boolean updateComponent = false; + + // If there were shapes that will be overwritten, a change has been made + if (shapes.size() > 0) { + updateComponent = true; + } + + // Copy shapes list + this.shapes.clear(); + + for (IShape shape : iceObject.shapes) { + this.shapes.add((IShape) shape.clone()); + + // At least one shape has been added + updateComponent = true; + } + + // A change has been made, notify the listeners + if (updateComponent) { + update(new PrimitiveShape()); + } + + } + + /** + *+ * This operation returns a clone of the GeometryComponent using a deep + * copy. + *
+ * + * @return + *+ * The new clone + *
+ */ + @Override + public Object clone() { + + // Instantiate GeometryComponent + Geometry geometry = new Geometry(); + + // Return the copied GeometryComponent + geometry.copy(this); + return geometry; + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.IUpdateableListener#update(org + * .eclipse.ice.datastructures.ICEObject.IUpdateable) + */ + @Override + public void update(IVizUpdateable component) { + final Geometry geometry = this; + + // If the listeners are empty, return + if (this.listeners == null || this.listeners.isEmpty()) { + return; + } + // Create a thread object that notifies all listeners + + Thread notifyThread = new Thread() { + + @Override + public void run() { + // Loop over all listeners and update them + for (int i = 0; i < listeners.size(); i++) { + listeners.get(i).update(geometry); + } + } + }; + + // Start the thread + notifyThread.start(); + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#setId(int) + */ + @Override + public void setId(int id) { + this.id = id; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.Identifiable#getDescription() + */ + @Override + public String getDescription() { + return description; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#getId() + */ + @Override + public int getId() { + return id; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.Identifiable#setName(java.lang + * .String) + */ + @Override + public void setName(String name) { + this.name = name; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ice.datastructures.ICEObject.Identifiable#getName() + */ + @Override + public String getName() { + return name; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.Identifiable#setDescription( + * java.lang.String) + */ + @Override + public void setDescription(String description) { + this.description = description; + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.IUpdateable#update(java.lang + * .String, java.lang.String) + */ + @Override + public void update(String updatedKey, String newValue) { + // Not implemented + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.datastructures.ICEObject.IUpdateable#register(org.eclipse + * .ice.datastructures.ICEObject.IUpdateableListener) + */ + @Override + public void register(IVizUpdateableListener listener) { + if (listeners.contains(listener)) { + return; + } + + listeners.add(listener); + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ice.datastructures.ICEObject.IUpdateable#unregister(org. + * eclipse .ice.datastructures.ICEObject.IUpdateableListener) + */ + @Override + public void unregister(IVizUpdateableListener listener) { + listeners.remove(listener); + + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShape.java index 4a4b6304416fd5672c0510dee17f4b74f4f50bb4..97d2dd2f0b916bc9d32b07447fd80b7238a3a8ad 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShape.java @@ -14,7 +14,6 @@ package org.eclipse.ice.viz.service.geometry.shapes; import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; - /** ** Interface describing a type of solid in the geometry editor @@ -26,126 +25,132 @@ import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; * * @author Jay Jay Billings */ -public interface IShape extends IVizUpdateable{ - /** - *
- * Returns a copy of the transformation matrix associated with this shape - * node - *
- * - * @return- * The transformation matrix applied to this node in the CSG tree - *
- */ - public Transformation getTransformation(); +public interface IShape extends IVizUpdateable { + /** + *+ * Returns a copy of the transformation matrix associated with this shape + * node + *
+ * + * @return + *+ * The transformation matrix applied to this node in the CSG tree + *
+ */ + public Transformation getTransformation(); - /** - *- * Replaces the transformation matrix with a copy of the given Matrix4x4 - *
- *- * Returns whether the setting was successful - *
- * - * @param transformation - *- * The transformation matrix to be applied to the shape - *
- * @return- * True if setting the transformation was successful, false - * otherwise - *
- */ - public boolean setTransformation(Transformation transformation); + /** + *+ * Replaces the transformation matrix with a copy of the given Matrix4x4 + *
+ *+ * Returns whether the setting was successful + *
+ * + * @param transformation + *+ * The transformation matrix to be applied to the shape + *
+ * @return + *+ * True if setting the transformation was successful, false + * otherwise + *
+ */ + public boolean setTransformation(Transformation transformation); - /** - *- * Returns the value associated with the property key - *
- *- * If the key does not exist, this operation returns null. - *
- * - * @param key - *- * The key corresponding to the desired property value - *
- * @return- * The desired value, or null if the key does not exist - *
- */ - public String getProperty(String key); + /** + *+ * Returns the value associated with the property key + *
+ *+ * If the key does not exist, this operation returns null. + *
+ * + * @param key + *+ * The key corresponding to the desired property value + *
+ * @return + *+ * The desired value, or null if the key does not exist + *
+ */ + public String getProperty(String key); - /** - *- * Sets the property value associated with the key string - *
- *- * If the key does not yet exist, append the key/value pair to the end of - * the property list. If it exists, find and replace the property value with - * the new one. - *
- * - * @param key - *- * The new or pre-existing key - *
- * @param value - *- * The new value - *
- * @return- * True if the property setting is valid, false otherwise - *
- */ - public boolean setProperty(String key, String value); + /** + *+ * Sets the property value associated with the key string + *
+ *+ * If the key does not yet exist, append the key/value pair to the end of + * the property list. If it exists, find and replace the property value with + * the new one. + *
+ * + * @param key + *+ * The new or pre-existing key + *
+ * @param value + *+ * The new value + *
+ * @return + *+ * True if the property setting is valid, false otherwise + *
+ */ + public boolean setProperty(String key, String value); - /** - *- * Removes the value associated with the key in the properties list - *
- *- * This operation returns whether the key was found and removed. - *
- * - * @param key - *- * The key associated with the value to remove - *
- * @return- * True if the value was found and removed, false otherwise - *
- */ - public boolean removeProperty(String key); + /** + *+ * Removes the value associated with the key in the properties list + *
+ *+ * This operation returns whether the key was found and removed. + *
+ * + * @param key + *+ * The key associated with the value to remove + *
+ * @return + *+ * True if the value was found and removed, false otherwise + *
+ */ + public boolean removeProperty(String key); - /** - *- * Calls back onto the visitor's visit() operation, revealing the concrete - * type of the IShape - *
- *- * The name of this operation is changed from the typical naming conventions - * of the visitor pattern to avoid conflicts with the Component::accept() - * operation. - *
- * - * @param visitor - *- * The IShapeVisitor to call back in order to reveal the type of - * this IShape - *
- */ - public void acceptShapeVisitor(IShapeVisitor visitor); + /** + *+ * Calls back onto the visitor's visit() operation, revealing the concrete + * type of the IShape + *
+ *+ * The name of this operation is changed from the typical naming conventions + * of the visitor pattern to avoid conflicts with the Component::accept() + * operation. + *
+ * + * @param visitor + *+ * The IShapeVisitor to call back in order to reveal the type of + * this IShape + *
+ */ + public void acceptShapeVisitor(IShapeVisitor visitor); - /** - *- * Returns the parent associated with this shape, or null if the shape does - * not have a parent - *
- * - * @return- * The IShape's parent - *
- */ - public IShape getParent(); + /** + *+ * Returns the parent associated with this shape, or null if the shape does + * not have a parent + *
+ * + * @return + *+ * The IShape's parent + *
+ */ + public IShape getParent(); } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShapeVisitor.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShapeVisitor.java index b8e96835611e497ba2213627fe395c954d884467..1f2b82a8f18c908d1b03a5ada743c295d130e144 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShapeVisitor.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/IShapeVisitor.java @@ -21,21 +21,21 @@ package org.eclipse.ice.viz.service.geometry.shapes; * @author Jay Jay Billings */ public interface IShapeVisitor { - /** - *- * Visits an IShapeVisitor as a ComplexShape - *
- * - * @param complexShape - */ - public void visit(ComplexShape complexShape); + /** + *+ * Visits an IShapeVisitor as a ComplexShape + *
+ * + * @param complexShape + */ + public void visit(ComplexShape complexShape); - /** - *- * Visits an IShapeVisitor as a PrimitiveShape - *
- * - * @param primitiveShape - */ - public void visit(PrimitiveShape primitiveShape); + /** + *+ * Visits an IShapeVisitor as a PrimitiveShape + *
+ * + * @param primitiveShape + */ + public void visit(PrimitiveShape primitiveShape); } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/OperatorType.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/OperatorType.java index ea7555ffd7d72530f3e3afe24dd78850ddc8e386..38c6000b11207b07350c853990188df712a941f3 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/OperatorType.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/OperatorType.java @@ -20,58 +20,57 @@ package org.eclipse.ice.viz.service.geometry.shapes; * @author Jay Jay Billings */ public enum OperatorType { - /** - *- * Default operator type - *
- *- * When rendering, None should be taken to mean "invisible". A ComplexShape - * with this type should have no effect on its parent. - *
- * - */ - None, - /** - *- * Union of any number of sets - *
- *- * The result of a union may be disjoint, meaning that the child shapes may - * be separated with no points in common. - *
- * - */ - Union, - /** - *- * Intersection of any number of sets - *
- *- * The intersection of more than 2 sets is defined as - *
- *- * ((A_1 intersection A_2) intersection A_3) ... - *
- * - */ - Intersection, - /** - *- * Complement of any number of sets - *
- *- * Unlike the union and intersection operators, the order of shapes is - * important when applying the multi-valued complement operator. For more - * than two shapes, the multi-valued complement is defined as - *
- *- * A_1 / A_2 / A_3 / .. - *
- *- * where "/" is the complement operator. The first shape has significance as - * the only additive shape in the final result of the operation. - *
- * - */ - Complement + /** + *+ * Default operator type + *
+ *+ * When rendering, None should be taken to mean "invisible". A ComplexShape + * with this type should have no effect on its parent. + *
+ * + */ + None, /** + *+ * Union of any number of sets + *
+ *+ * The result of a union may be disjoint, meaning that the child + * shapes may be separated with no points in common. + *
+ * + */ + Union, /** + *+ * Intersection of any number of sets + *
+ *+ * The intersection of more than 2 sets is defined as + *
+ *+ * ((A_1 intersection A_2) intersection A_3) ... + *
+ * + */ + Intersection, /** + *+ * Complement of any number of sets + *
+ *+ * Unlike the union and intersection operators, the order of + * shapes is important when applying the multi-valued + * complement operator. For more than two shapes, the + * multi-valued complement is defined as + *
+ *+ * A_1 / A_2 / A_3 / .. + *
+ *+ * where "/" is the complement operator. The first shape has + * significance as the only additive shape in the final result + * of the operation. + *
+ * + */ + Complement } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/PrimitiveShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/PrimitiveShape.java index 691c97220fa9661b95a2b614c46c183ca444642d..5276b3a613c10000ddb19a566adb9943aa2705e6 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/PrimitiveShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/PrimitiveShape.java @@ -31,249 +31,254 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "PrimitiveShape") @XmlAccessorType(XmlAccessType.FIELD) public class PrimitiveShape extends AbstractShape { - /** - *- * The type of shape of this PrimitiveShape - *
- * - */ - @XmlAttribute - private ShapeType shapeType; - - /** - *- * Calls AbstractShape's constructor and initializes the ShapeType - *
- *- * Upon creation, the associated ShapeType is set to None and must be reset - * appropriately in order for the PrimitiveShape to have an effect on a - * generated mesh. - *
- * - */ - public PrimitiveShape() { - - // Call AbstractShape's constructor - - super(); - - // Set the ShapeType to None - - shapeType = ShapeType.None; - - } - - /** - *- * Calls AbstractShape's constructor and initializes the ShapeType - *
- *- * When this constructor is called, the ShapeType enumerator is set to the - * given value. - *
- * - * @param shapeType - *- * The type of shape to be set in this new PrimitiveShape - *
- */ - public PrimitiveShape(ShapeType shapeType) { - - // Call nullery constructor first - this(); - - // Set the type to the given value - if (shapeType == null) { - shapeType = ShapeType.None; - } - this.shapeType = shapeType; - - } - - /** - *- * Sets the type of shape of the PrimitiveShape - *
- *- * If the shape type has previously been set, this operation ignores - * additional calls to this function. That is, the shape type is permitted - * to change only if the current shape type is None. - *
- * - * @param shapeType - *- * The type of shape to set on this PrimitiveShape - *
- */ - public void setType(ShapeType shapeType) { - - if (shapeType == null) { - return; - } - // Set the type only if the current ShapeType is None - if (this.shapeType == ShapeType.None) { - this.shapeType = shapeType; - - // Notify listeners - notifyListeners(); - } - - } - - /** - *- * Gets the ShapeType of the PrimitiveShape - *
- * - * @return- * The ShapeType corresponding to this PrimitiveShape - *
- */ - public ShapeType getType() { - return shapeType; - } - - /** - *- * This operation is used to check equality between the PrimitiveShape and - * another PrimitiveShape. It returns true if the PrimitiveShapes are equal - * and false if they are not. - *
- * - * @param otherObject - *- * The other ICEObject that should be compared with this one. - *
- * @return- * True if the ICEObjects are equal, false otherwise. - *
- */ - @Override - public boolean equals(Object otherObject) { - - // Check if a similar reference - if (this == otherObject) { - return true; - } - // Check that the other object is not null and an instance of the - // PrimitiveShape - if (otherObject == null || !(otherObject instanceof PrimitiveShape)) { - return false; - } - // Check that these objects have the same ICEObject data - if (!super.equals(otherObject)) { - return false; - } - // At this point, other object must be a PrimitiveShape, so cast it - PrimitiveShape otherPrimitiveShape = (PrimitiveShape) otherObject; - - // Check for unequal types - if (shapeType != otherPrimitiveShape.shapeType) { - return false; - } - // The two objects are equal - return true; - - } - - /** - *- * This operation copies the contents of a PrimitiveShape into the current - * object using a deep copy. - *
- * - * @param iceObject - *- * The ICEObject from which the values should be copied. - *
- */ - public void copy(PrimitiveShape iceObject) { - - // Return if object is null - if (iceObject == null) { - return; - } - // Copy the ICEObject data - super.copy(iceObject); - - // Copy shapeType - this.shapeType = iceObject.shapeType; - - } - - /** - *- * This operation returns a clone of the PrimitiveShape using a deep copy. - *
- * - * @return- * The new clone. - *
- */ - @Override - public Object clone() { - - // Create a new PrimitiveShape - PrimitiveShape primitiveShape = new PrimitiveShape(); - - // Copy `this` into primitiveShape - primitiveShape.copy(this); - - return primitiveShape; - - } - - /** - *- * This operation returns the hashcode value of the PrimitiveShape. - *
- * - * @return- * The hashcode of the ICEObject. - *
- */ - @Override - public int hashCode() { - // Get initial hash code - int hash = super.hashCode(); - - // Hash the ShapeType - hash = 31 * hash + shapeType.hashCode(); - - return hash; - } - - /** - *- * This operation returns a clone of the PrimitiveShape using a deep copy. - *
- * - * @return- * The new clone. - *
- */ - - /** - * (non-Javadoc) - * - * @see IUpdateable#update(String updatedKey, String newValue) - */ - @Override - public void update(String updatedKey, String newValue) { - // Not implemented - } - - /** - * (non-Javadoc) - * - * @see IShape#acceptShapeVisitor(IShapeVisitor visitor) - */ - @Override - public void acceptShapeVisitor(IShapeVisitor visitor) { - - // Only visit if it is not null - if (visitor != null) { - visitor.visit(this); - } - } + /** + *+ * The type of shape of this PrimitiveShape + *
+ * + */ + @XmlAttribute + private ShapeType shapeType; + + /** + *+ * Calls AbstractShape's constructor and initializes the ShapeType + *
+ *+ * Upon creation, the associated ShapeType is set to None and must be reset + * appropriately in order for the PrimitiveShape to have an effect on a + * generated mesh. + *
+ * + */ + public PrimitiveShape() { + + // Call AbstractShape's constructor + + super(); + + // Set the ShapeType to None + + shapeType = ShapeType.None; + + } + + /** + *+ * Calls AbstractShape's constructor and initializes the ShapeType + *
+ *+ * When this constructor is called, the ShapeType enumerator is set to the + * given value. + *
+ * + * @param shapeType + *+ * The type of shape to be set in this new PrimitiveShape + *
+ */ + public PrimitiveShape(ShapeType shapeType) { + + // Call nullery constructor first + this(); + + // Set the type to the given value + if (shapeType == null) { + shapeType = ShapeType.None; + } + this.shapeType = shapeType; + + } + + /** + *+ * Sets the type of shape of the PrimitiveShape + *
+ *+ * If the shape type has previously been set, this operation ignores + * additional calls to this function. That is, the shape type is permitted + * to change only if the current shape type is None. + *
+ * + * @param shapeType + *+ * The type of shape to set on this PrimitiveShape + *
+ */ + public void setType(ShapeType shapeType) { + + if (shapeType == null) { + return; + } + // Set the type only if the current ShapeType is None + if (this.shapeType == ShapeType.None) { + this.shapeType = shapeType; + + // Notify listeners + notifyListeners(); + } + + } + + /** + *+ * Gets the ShapeType of the PrimitiveShape + *
+ * + * @return + *+ * The ShapeType corresponding to this PrimitiveShape + *
+ */ + public ShapeType getType() { + return shapeType; + } + + /** + *+ * This operation is used to check equality between the PrimitiveShape and + * another PrimitiveShape. It returns true if the PrimitiveShapes are equal + * and false if they are not. + *
+ * + * @param otherObject + *+ * The other ICEObject that should be compared with this one. + *
+ * @return + *+ * True if the ICEObjects are equal, false otherwise. + *
+ */ + @Override + public boolean equals(Object otherObject) { + + // Check if a similar reference + if (this == otherObject) { + return true; + } + // Check that the other object is not null and an instance of the + // PrimitiveShape + if (otherObject == null || !(otherObject instanceof PrimitiveShape)) { + return false; + } + // Check that these objects have the same ICEObject data + if (!super.equals(otherObject)) { + return false; + } + // At this point, other object must be a PrimitiveShape, so cast it + PrimitiveShape otherPrimitiveShape = (PrimitiveShape) otherObject; + + // Check for unequal types + if (shapeType != otherPrimitiveShape.shapeType) { + return false; + } + // The two objects are equal + return true; + + } + + /** + *+ * This operation copies the contents of a PrimitiveShape into the current + * object using a deep copy. + *
+ * + * @param iceObject + *+ * The ICEObject from which the values should be copied. + *
+ */ + public void copy(PrimitiveShape iceObject) { + + // Return if object is null + if (iceObject == null) { + return; + } + // Copy the ICEObject data + super.copy(iceObject); + + // Copy shapeType + this.shapeType = iceObject.shapeType; + + } + + /** + *+ * This operation returns a clone of the PrimitiveShape using a deep copy. + *
+ * + * @return + *+ * The new clone. + *
+ */ + @Override + public Object clone() { + + // Create a new PrimitiveShape + PrimitiveShape primitiveShape = new PrimitiveShape(); + + // Copy `this` into primitiveShape + primitiveShape.copy(this); + + return primitiveShape; + + } + + /** + *+ * This operation returns the hashcode value of the PrimitiveShape. + *
+ * + * @return + *+ * The hashcode of the ICEObject. + *
+ */ + @Override + public int hashCode() { + // Get initial hash code + int hash = super.hashCode(); + + // Hash the ShapeType + hash = 31 * hash + shapeType.hashCode(); + + return hash; + } + + /** + *+ * This operation returns a clone of the PrimitiveShape using a deep copy. + *
+ * + * @return + *+ * The new clone. + *
+ */ + + /** + * (non-Javadoc) + * + * @see IUpdateable#update(String updatedKey, String newValue) + */ + @Override + public void update(String updatedKey, String newValue) { + // Not implemented + } + + /** + * (non-Javadoc) + * + * @see IShape#acceptShapeVisitor(IShapeVisitor visitor) + */ + @Override + public void acceptShapeVisitor(IShapeVisitor visitor) { + + // Only visit if it is not null + if (visitor != null) { + visitor.visit(this); + } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ShapeType.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ShapeType.java index 9bea505770fa68213b6f2dfb8ff513ab7a8d453a..d7d77f949b35318b6b16cb19b7fe3e2cec93c5d8 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ShapeType.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/ShapeType.java @@ -20,53 +20,48 @@ package org.eclipse.ice.viz.service.geometry.shapes; * @author Jay Jay Billings */ public enum ShapeType { - /** - *- * Default shape type - *
- *- * When rendering, None should be taken to mean "invisible". A - * PrimitiveShape with this type should have no effect on its parent. - *
- * - */ - None, - /** - *- * A "half-unit" sphere with a radius of 0.5 (diameter of 1) with its origin - * at its center - *
- * - */ - Sphere, - /** - *- * A 1x1x1 cube with its origin at its center (0.5, 0.5, 0.5) - *
- * - */ - Cube, - /** - *- * A cylinder with a radius of 0.5 (diameter of 1), a height of 1, and its - * origin at its center (0.5, 0.5, 0.5) - *
- * - */ - Cylinder, - /** - *- * A circular cone with a diameter of 1, height of 1, and its center at - * (0.5, 0.5, 0.5) - *
- * - */ - Cone, - /** - *- * A cylinder with an inner and outer radius, an extruded annulus - *
- * - */ - Tube + /** + *+ * Default shape type + *
+ *+ * When rendering, None should be taken to mean "invisible". A + * PrimitiveShape with this type should have no effect on its parent. + *
+ * + */ + None, /** + *+ * A "half-unit" sphere with a radius of 0.5 (diameter of 1) with its + * origin at its center + *
+ * + */ + Sphere, /** + *+ * A 1x1x1 cube with its origin at its center (0.5, 0.5, 0.5) + *
+ * + */ + Cube, /** + *+ * A cylinder with a radius of 0.5 (diameter of 1), a height of 1, and + * its origin at its center (0.5, 0.5, 0.5) + *
+ * + */ + Cylinder, /** + *+ * A circular cone with a diameter of 1, height of 1, and its + * center at (0.5, 0.5, 0.5) + *
+ * + */ + Cone, /** + *+ * A cylinder with an inner and outer radius, an extruded annulus + *
+ * + */ + Tube } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Transformation.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Transformation.java index f4a9eff5a4d969c001bcec096e1638304353f87b..21920f7db8f541bdc32286dbba5a91a658296c5a 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Transformation.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/Transformation.java @@ -37,442 +37,450 @@ import org.eclipse.ice.viz.service.datastructures.VizObject.VizObject; @XmlRootElement(name = "Transformation") @XmlAccessorType(XmlAccessType.FIELD) public class Transformation extends VizObject { - /** - *- * The amount of skew for each of the three axes: x, y, and z - *
- * - */ - @XmlElement(name = "Skew") - @XmlList - private double[] skew = new double[3]; - /** - *- * Defines the amount of uniform scale for all three dimensions - *
- * - */ - @XmlElement(name = "Size") - private double size; - /** - *- * Defines the scaling factors in each of the three dimensions: x, y, and z - *
- * - */ - @XmlElement(name = "Scale") - @XmlList - private double[] scale = new double[3]; - /** - *- * Defines the rotation in radians along the x, y, and z axes passing - * through the origin - *
- * - */ - @XmlElement(name = "Rotation") - @XmlList - private double[] rotation = new double[3]; - /** - *- * Defines the translation along each of the three dimensions: x, y, and z - *
- * - */ - @XmlElement(name = "Translation") - @XmlList - private double[] translation = new double[3]; - - /** - *- * Upon creation, the Transformation should set its skew values to 0, sizes - * to 1, scale to 1, rotations to 0, and translation to 0. The resultant - * transformation matrix should be the 4x4 identity matrix. - *
- * - */ - public Transformation() { - - // Set initial transformation variables - - size = 1.0; - scale[0] = 1.0; - scale[1] = 1.0; - scale[2] = 1.0; - - } - - /** - *- * Returns an array of the 3 skew values - *
- * - * @return- * The skew values - *
- */ - public double[] getSkew() { - return skew; - } - - /** - *- * Returns the size factor - *
- * - * @return- * The size value - *
- */ - public double getSize() { - return size; - } - - /** - *- * Returns an array of the 3 scale values - *
- * - * @return- * The scale values - *
- */ - public double[] getScale() { - return scale; - } - - /** - *- * Returns an array of the 3 rotation values - *
- * - * @return- * The rotation values - *
- */ - public double[] getRotation() { - return rotation; - } - - /** - *- * Returns an array of the 3 translation values - *
- * - * @return- * The translation values - *
- */ - public double[] getTranslation() { - return translation; - } - - /** - *- * Sets the skew values to the three given parameters - *
- * - * @param x - *- * The skew on the x-axis - *
- * @param y - *- * The skew on the y-axis - *
- * @param z - *- * The skew on the z-axis - *
- */ - public void setSkew(double x, double y, double z) { - skew[0] = x; - skew[1] = y; - skew[2] = z; - } - - /** - *- * Sets the size value to the given parameter - *
- * - * @param size - *- * The size scaling factor - *
- */ - public void setSize(double size) { - this.size = size; - } - - /** - *- * Sets the scale values to the three given parameters - *
- * - * @param x - *- * The scale on the x-axis - *
- * @param y - *- * The scale on the y-axis - *
- * @param z - *- * The scale on the z-axis - *
- */ - public void setScale(double x, double y, double z) { - scale[0] = x; - scale[1] = y; - scale[2] = z; - } - - /** - *- * Sets the rotation values to the three given parameters - *
- * - * @param xAxis - *- * The rotation on the x-axis through the origin - *
- * @param yAxis - *- * The rotation on the y-axis through the origin - *
- * @param zAxis - *- * The rotation on the z-axis through the origin - *
- */ - public void setRotation(double xAxis, double yAxis, double zAxis) { - rotation[0] = xAxis; - rotation[1] = yAxis; - rotation[2] = zAxis; - } - - /** - *- * Sets the translation values to the three given parameters - *
- * - * @param x - *- * The translation on the x-axis - *
- * @param y - *- * The translation on the y-axis - *
- * @param z - *- * The translation on the z-axis - *
- */ - public void setTranslation(double x, double y, double z) { - translation[0] = x; - translation[1] = y; - translation[2] = z; - } - - /** - *- * Applies an additional translation to the existing transformation - * variables - *
- * - * @param translation - *- * An array of three doubles to add to the existing translation - * values - *
- */ - public void translate(double[] translation) { - - // Don't do anything if the translation array has less or greater - // than 3 elements - - if (translation.length != 3) { - return; - } - for (int i = 0; i < 3; i++) { - this.translation[i] += translation[i]; - } - - } - - /** - *- * Returns the flat array of elements in the matrix - *
- * - * @return- * Flat list of elements in the array - *
- *- * Each row from the top to the bottom is stacked end-to-end in a - * one-dimensional array. The ith row and the jth column can be - * accessed as index i * 4 + j in the flat array. - *
- */ - public double[] getMatrixArray() { - - // TODO Implement transformation-to-matrix conversion - - return null; - - } - - /** - *- * This operation returns the hashcode value of the Transformation. - *
- * - * @return- * The hashcode of the ICEObject. - *
- */ - @Override - public int hashCode() { - - // Local Declaration - int hash = 1; - - // Compute hash code from ICEObject data - hash = 31 * hash + super.hashCode(); - - // Hash the transformation variables - hash = 31 * hash + Arrays.hashCode(skew); - hash = 31 * hash + new Double(size).hashCode(); - hash = 31 * hash + Arrays.hashCode(scale); - hash = 31 * hash + Arrays.hashCode(rotation); - hash = 31 * hash + Arrays.hashCode(translation); - - return hash; - - } - - /** - *- * This operation is used to check equality between this Transformation and - * another Transformation. It returns true if the Transformations are equal - * and false if they are not. - *
- * - * @param otherObject - *- * The other ICEObject that should be compared with this one. - *
- * @return- * True if the ICEObjects are equal, false otherwise. - *
- */ - @Override - public boolean equals(Object otherObject) { - - // Check if they are the same reference in memory - if (this == otherObject) { - return true; - } - - // Check that the object is not null, and that it is a Matrix4x4 - if (otherObject == null || !(otherObject instanceof Transformation)) { - return false; - } - - // Check that these objects have the same ICEObject data - if (!super.equals(otherObject)) { - return false; - } - - // At this point, other object must be a Matrix4x4, so cast it - Transformation other = (Transformation) otherObject; - - // Check elements - return (Arrays.equals(this.skew, other.skew) && this.size == other.size - && Arrays.equals(this.scale, other.scale) - && Arrays.equals(this.rotation, other.rotation) && Arrays - .equals(this.translation, other.translation)); - - } - - /** - *- * Copies the contents of a Transformation into the current object using a - * deep copy - *
- * - * @param iceObject - *- * The ICEObject from which the values should be copied - *
- */ - public void copy(Transformation iceObject) { - - // Return if object is null - if (iceObject == null) { - return; - } - // Copy contents of super - super.copy(iceObject); - - // Copy contents of elements - Deep copy - this.skew = iceObject.skew.clone(); - this.size = iceObject.size; - this.scale = iceObject.scale.clone(); - this.rotation = iceObject.rotation.clone(); - this.translation = iceObject.translation.clone(); - - } - - /** - *- * Returns a clone of the Transformation using a deep copy. - *
- * - * @return- * The new clone - *
- */ - @Override - public Object clone() { - - // Create a new Transformation and copy the current object's data - - Transformation transformation = new Transformation(); - transformation.copy(this); - return transformation; - - } - - /** - * Returns the string representation of this Transformation including all of - * its transformation variables - * - * @return The string representation - */ - @Override - public String toString() { - - // When a new Transformation is initialized, the default string - // representation is the following. - - // Skew: (0, 0, 0), Size: 1, Scale: (1, 1, 1), Rotation: (0, 0, 0), - // Translation: (0, 0, 0) - - String output = "Skew: (" + skew[0] + ", "; - output += skew[1] + ", " + skew[2] + "), "; - output += "Size: " + size + ", "; - output += "Scale: (" + scale[0] + ", "; - output += scale[1] + ", " + scale[2] + "), "; - output += "Rotation: (" + rotation[0] + ", "; - output += rotation[1] + ", " + rotation[2] + "), "; - output += "Translation: (" + translation[0] + ", "; - output += translation[1] + ", " + translation[2] + ")"; - - return output; - } + /** + *+ * The amount of skew for each of the three axes: x, y, and z + *
+ * + */ + @XmlElement(name = "Skew") + @XmlList + private double[] skew = new double[3]; + /** + *+ * Defines the amount of uniform scale for all three dimensions + *
+ * + */ + @XmlElement(name = "Size") + private double size; + /** + *+ * Defines the scaling factors in each of the three dimensions: x, y, and z + *
+ * + */ + @XmlElement(name = "Scale") + @XmlList + private double[] scale = new double[3]; + /** + *+ * Defines the rotation in radians along the x, y, and z axes passing + * through the origin + *
+ * + */ + @XmlElement(name = "Rotation") + @XmlList + private double[] rotation = new double[3]; + /** + *+ * Defines the translation along each of the three dimensions: x, y, and z + *
+ * + */ + @XmlElement(name = "Translation") + @XmlList + private double[] translation = new double[3]; + + /** + *+ * Upon creation, the Transformation should set its skew values to 0, sizes + * to 1, scale to 1, rotations to 0, and translation to 0. The resultant + * transformation matrix should be the 4x4 identity matrix. + *
+ * + */ + public Transformation() { + + // Set initial transformation variables + + size = 1.0; + scale[0] = 1.0; + scale[1] = 1.0; + scale[2] = 1.0; + + } + + /** + *+ * Returns an array of the 3 skew values + *
+ * + * @return + *+ * The skew values + *
+ */ + public double[] getSkew() { + return skew; + } + + /** + *+ * Returns the size factor + *
+ * + * @return + *+ * The size value + *
+ */ + public double getSize() { + return size; + } + + /** + *+ * Returns an array of the 3 scale values + *
+ * + * @return + *+ * The scale values + *
+ */ + public double[] getScale() { + return scale; + } + + /** + *+ * Returns an array of the 3 rotation values + *
+ * + * @return + *+ * The rotation values + *
+ */ + public double[] getRotation() { + return rotation; + } + + /** + *+ * Returns an array of the 3 translation values + *
+ * + * @return + *+ * The translation values + *
+ */ + public double[] getTranslation() { + return translation; + } + + /** + *+ * Sets the skew values to the three given parameters + *
+ * + * @param x + *+ * The skew on the x-axis + *
+ * @param y + *+ * The skew on the y-axis + *
+ * @param z + *+ * The skew on the z-axis + *
+ */ + public void setSkew(double x, double y, double z) { + skew[0] = x; + skew[1] = y; + skew[2] = z; + } + + /** + *+ * Sets the size value to the given parameter + *
+ * + * @param size + *+ * The size scaling factor + *
+ */ + public void setSize(double size) { + this.size = size; + } + + /** + *+ * Sets the scale values to the three given parameters + *
+ * + * @param x + *+ * The scale on the x-axis + *
+ * @param y + *+ * The scale on the y-axis + *
+ * @param z + *+ * The scale on the z-axis + *
+ */ + public void setScale(double x, double y, double z) { + scale[0] = x; + scale[1] = y; + scale[2] = z; + } + + /** + *+ * Sets the rotation values to the three given parameters + *
+ * + * @param xAxis + *+ * The rotation on the x-axis through the origin + *
+ * @param yAxis + *+ * The rotation on the y-axis through the origin + *
+ * @param zAxis + *+ * The rotation on the z-axis through the origin + *
+ */ + public void setRotation(double xAxis, double yAxis, double zAxis) { + rotation[0] = xAxis; + rotation[1] = yAxis; + rotation[2] = zAxis; + } + + /** + *+ * Sets the translation values to the three given parameters + *
+ * + * @param x + *+ * The translation on the x-axis + *
+ * @param y + *+ * The translation on the y-axis + *
+ * @param z + *+ * The translation on the z-axis + *
+ */ + public void setTranslation(double x, double y, double z) { + translation[0] = x; + translation[1] = y; + translation[2] = z; + } + + /** + *+ * Applies an additional translation to the existing transformation + * variables + *
+ * + * @param translation + *+ * An array of three doubles to add to the existing translation + * values + *
+ */ + public void translate(double[] translation) { + + // Don't do anything if the translation array has less or greater + // than 3 elements + + if (translation.length != 3) { + return; + } + for (int i = 0; i < 3; i++) { + this.translation[i] += translation[i]; + } + + } + + /** + *+ * Returns the flat array of elements in the matrix + *
+ * + * @return + *+ * Flat list of elements in the array + *
+ *+ * Each row from the top to the bottom is stacked end-to-end in a + * one-dimensional array. The ith row and the jth column can be + * accessed as index i * 4 + j in the flat array. + *
+ */ + public double[] getMatrixArray() { + + // TODO Implement transformation-to-matrix conversion + + return null; + + } + + /** + *+ * This operation returns the hashcode value of the Transformation. + *
+ * + * @return + *+ * The hashcode of the ICEObject. + *
+ */ + @Override + public int hashCode() { + + // Local Declaration + int hash = 1; + + // Compute hash code from ICEObject data + hash = 31 * hash + super.hashCode(); + + // Hash the transformation variables + hash = 31 * hash + Arrays.hashCode(skew); + hash = 31 * hash + new Double(size).hashCode(); + hash = 31 * hash + Arrays.hashCode(scale); + hash = 31 * hash + Arrays.hashCode(rotation); + hash = 31 * hash + Arrays.hashCode(translation); + + return hash; + + } + + /** + *+ * This operation is used to check equality between this Transformation and + * another Transformation. It returns true if the Transformations are equal + * and false if they are not. + *
+ * + * @param otherObject + *+ * The other ICEObject that should be compared with this one. + *
+ * @return + *+ * True if the ICEObjects are equal, false otherwise. + *
+ */ + @Override + public boolean equals(Object otherObject) { + + // Check if they are the same reference in memory + if (this == otherObject) { + return true; + } + + // Check that the object is not null, and that it is a Matrix4x4 + if (otherObject == null || !(otherObject instanceof Transformation)) { + return false; + } + + // Check that these objects have the same ICEObject data + if (!super.equals(otherObject)) { + return false; + } + + // At this point, other object must be a Matrix4x4, so cast it + Transformation other = (Transformation) otherObject; + + // Check elements + return (Arrays.equals(this.skew, other.skew) && this.size == other.size + && Arrays.equals(this.scale, other.scale) && Arrays.equals(this.rotation, other.rotation) + && Arrays.equals(this.translation, other.translation)); + + } + + /** + *+ * Copies the contents of a Transformation into the current object using a + * deep copy + *
+ * + * @param iceObject + *+ * The ICEObject from which the values should be copied + *
+ */ + public void copy(Transformation iceObject) { + + // Return if object is null + if (iceObject == null) { + return; + } + // Copy contents of super + super.copy(iceObject); + + // Copy contents of elements - Deep copy + this.skew = iceObject.skew.clone(); + this.size = iceObject.size; + this.scale = iceObject.scale.clone(); + this.rotation = iceObject.rotation.clone(); + this.translation = iceObject.translation.clone(); + + } + + /** + *+ * Returns a clone of the Transformation using a deep copy. + *
+ * + * @return + *+ * The new clone + *
+ */ + @Override + public Object clone() { + + // Create a new Transformation and copy the current object's data + + Transformation transformation = new Transformation(); + transformation.copy(this); + return transformation; + + } + + /** + * Returns the string representation of this Transformation including all of + * its transformation variables + * + * @return The string representation + */ + @Override + public String toString() { + + // When a new Transformation is initialized, the default string + // representation is the following. + + // Skew: (0, 0, 0), Size: 1, Scale: (1, 1, 1), Rotation: (0, 0, 0), + // Translation: (0, 0, 0) + + String output = "Skew: (" + skew[0] + ", "; + output += skew[1] + ", " + skew[2] + "), "; + output += "Size: " + size + ", "; + output += "Scale: (" + scale[0] + ", "; + output += scale[1] + ", " + scale[2] + "), "; + output += "Rotation: (" + rotation[0] + ", "; + output += rotation[1] + ", " + rotation[2] + "), "; + output += "Translation: (" + translation[0] + ", "; + output += translation[1] + ", " + translation[2] + ")"; + + return output; + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/GeometryViewer.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/GeometryViewer.java new file mode 100644 index 0000000000000000000000000000000000000000..3d1eaa007270d74400f873cc4377c18c31798827 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/GeometryViewer.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import org.eclipse.ice.viz.service.geometry.scene.base.ICamera; +import org.eclipse.ice.viz.service.geometry.scene.base.ModelUtil; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Composite; + +/** + *+ * JFace Viewer base for GeometryViewer implementations. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +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; + + /** + *+ * Creates a new GeometryViewer. + *
+ * + * @param parent + * the parent widget to create the viewer in + */ + public GeometryViewer(Composite parent) { + this.parent = parent; + + createControl(parent); + } + + /** + *+ * Returns the renderer for this viewer. + *
+ * + * @return the renderer for this viewer. + */ + public IRenderer getRenderer() { + return renderer; + } + + /** + *+ * Creates the control that backs this viewer, to be implemented by + * subclasses. + *
+ * + * @param parent + * the parent widget that owns the viewer control. + */ + protected abstract void createControl(Composite parent); + + /** + *+ * Returns the active input scene model object. + *
+ * + * @see Viewer#getInput() + */ + @Override + public Object getInput() { + return input; + } + + /** + *+ * Sets the active scene, supports either INode or IScene. + *
+ */ + @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); + } + + /** + *+ * Returns the currently active selection in the scene. + *
+ */ + @Override + public ISelection getSelection() { + return selection; + } + + /** + *+ * Sets the selection in the scene. + *
+ */ + @Override + public void setSelection(ISelection selection, boolean makeVisible) { + this.selection = selection; + + fireSelectionChanged(new SelectionChangedEvent(this, selection)); + } + + /** + *+ * Sets the active camera displayed by the viewer. + *
+ * + * @param camera + * the camera to use to display the viewer + */ + public void setCamera(ICamera camera) { + this.activeCamera = camera; + + updateCamera(camera); + } + + /** + *+ * Updates the active camera. + *
+ * + * @param camera + * the camera to use in the scene. + */ + protected abstract void updateCamera(ICamera camera); + + /** + *+ * Return the active camera. + *
+ * + * @return the active camera + */ + public ICamera getCamera() { + return this.activeCamera; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IAttachmentManager.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IAttachmentManager.java new file mode 100644 index 0000000000000000000000000000000000000000..500195d2dd3d00c1f9b47d3a941b4d84248d2589 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IAttachmentManager.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; + +/** + *+ * Interface for managing attachment allocations in a geometry viewer + * implementation. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IAttachmentManager { + + /** + *+ * Create a new instance of IAttachment. + *
+ * + * @return an IAttachment instance of the manager's type + */ + IAttachment allocate(); + + /** + *+ * Frees an instance of IAttachment. + *
+ * + * @param attach + * an IAttachment to free + */ + void destroy(IAttachment attach); + + /** + *+ * Called when the attachment should update its logic. + *
+ */ + void update(); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IRenderer.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..550fbf56bcc2420090a70a7a498a6f2119a66698 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IRenderer.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; + +/** + *+ * Interface defines logic for executing and managing a scene via a viewer. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IRenderer { + + /** + *+ * Creates an attachment of the specified type. + *
+ * + * @param clazz + * the type of IAttachment to allocate. + * + * @return an IAttachment instance of the specified type or null if the + * attachment cannot be allocated. + */ + public IAttachment createAttachment(Class extends IAttachment> clazz); + + /** + *+ * Returns true if the renderer supports the supplied attachment type, false + * otherwise. + *
+ * + * @param clazz + * the type of attachment to check for + * + * @return true if the renderer supports the supplied attachment type, false + * otherwise. + */ + public boolean supportsAttachment(Class extends IAttachment> clazz); + + /** + *+ * Associates the supplied IAttachmentManager with the renderer, so + * attachments can be allocated with the associated type. + *
+ * + * @param type + * the type of attachments supplied by the manager + * + * @param mgr + * the manager instance to handle allocating attachments + */ + void register(Class extends IAttachment> type, IAttachmentManager mgr); + + /** + *+ * Removes any manager associated with the supplied type from the renderer. + *
+ * + * @param type + * the type of attachment manager to unregister + */ + void unregister(Class extends IAttachment> type); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IViewerFactory.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IViewerFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..773cda2bf10754e73dc33947bf026105de1c83b2 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/IViewerFactory.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import org.eclipse.swt.widgets.Composite; + +/** + *+ * Defines an abstract way to create GeometryViewer instances. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public interface IViewerFactory { + + /** + *+ * Creates a geometry viewer instance on the supplied parent composite. + *
+ */ + public GeometryViewer createViewer(Composite parent); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Messages.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Messages.java new file mode 100644 index 0000000000000000000000000000000000000000..b3302c401a77d68918e35c9cbcd725751f7101ca --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Messages.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.ice.viz.service.geometry.viewer.messages"; //$NON-NLS-1$ + public static String GeometryViewer_InvalidInput; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Renderer.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Renderer.java new file mode 100644 index 0000000000000000000000000000000000000000..3cfe8ff2949302252b7dcd8b285b2c8635ddcbb9 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/Renderer.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2015 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.geometry.viewer; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; + +/** + *+ * Default IRenderer implementation to be used by client implementations. + *
+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public abstract class Renderer implements IRenderer { + + /** Stores attachment manager associations. */ + private Map- * The current ShapeTreeViewer associated with the AddShape action - *
- * - */ - private ShapeTreeView view; - /** - *- * The ShapeType used to create new PrimitiveShapes when the AddShape action - * is triggered - *
- *- * If the value is null, the Operator is used to create ComplexShapes. - *
- * - */ - private ShapeType shapeType; - /** - *- * The OperatorType used to create new ComplexShapes when the AddShape - * action is triggered - *
- *- * If the value is null, the ShapeType is used to create PrimitiveShapes. - *
- * - */ - private OperatorType operatorType; - - /** - *- * The current used default shape number appended to the name of every newly - * created shape - *
- *- * Starting from zero, this number increments every time a new shape is - * added to the tree. - *
- * - */ - private int currentShapeId; - - /** - * The image to display as the action's icon - */ - private ImageDescriptor imageDescriptor; - - /** - *- * Constructor for creating new PrimitiveShapes with a given ShapeType - *
- * - * @param view - *- * The current ShapeTreeViewer - *
- * @param shapeType - *- * The type of PrimitiveShape to create with the action is - * triggered - *
- */ - public ActionAddShape(ShapeTreeView view, ShapeType shapeType) { - - this.view = view; - this.shapeType = shapeType; - operatorType = null; - currentShapeId = 0; - - // Set the Action's name to "Add {ShapeType}" - setText("Add " + shapeType.toString()); - - // Create a map which stores the filenames of the icons, relative - // to the icons/ directory - Map- * Constructor for creating new ComplexShapes with a given OperatorType - *
- * - * @param view - *- * The current ShapeTreeViewer - *
- * @param operatorType - *- * The type of ComplexShape to create with the action is - * triggered - *
- */ - public ActionAddShape(ShapeTreeView view, OperatorType operatorType) { - - this.view = view; - this.shapeType = null; - this.operatorType = operatorType; - currentShapeId = 0; - - // Set the Action's name to "Add {ShapeType}" - - this.setText("Add " + operatorType.toString()); - - // Create a map which stores the filenames of the icons, relative - // to the icons/ directory - - Map- * Runs this action - *
- *- * Each action implementation must define the steps needed to carry out this - * action. - *
- * - */ - @Override - public void run() { - - // Get the selection - - ITreeSelection selection = (ITreeSelection) view.treeViewer - .getSelection(); - TreePath[] paths = selection.getPaths(); - - // Fail silently if multiple items are selected - - if (paths.length > 1) { - return; - } - // Get the GeometryComponent from the ShapeTreeView's TreeViewer + /** + *+ * The current ShapeTreeViewer associated with the AddShape action + *
+ * + */ + private ShapeTreeView view; + /** + *+ * The ShapeType used to create new PrimitiveShapes when the AddShape action + * is triggered + *
+ *+ * If the value is null, the Operator is used to create ComplexShapes. + *
+ * + */ + private ShapeType shapeType; + /** + *+ * The OperatorType used to create new ComplexShapes when the AddShape + * action is triggered + *
+ *+ * If the value is null, the ShapeType is used to create PrimitiveShapes. + *
+ * + */ + private OperatorType operatorType; + + /** + *+ * The current used default shape number appended to the name of every newly + * created shape + *
+ *+ * Starting from zero, this number increments every time a new shape is + * added to the tree. + *
+ * + */ + private int currentShapeId; + + /** + * The image to display as the action's icon + */ + private ImageDescriptor imageDescriptor; + + /** + *+ * Constructor for creating new PrimitiveShapes with a given ShapeType + *
+ * + * @param view + *+ * The current ShapeTreeViewer + *
+ * @param shapeType + *+ * The type of PrimitiveShape to create with the action is + * triggered + *
+ */ + public ActionAddShape(ShapeTreeView view, ShapeType shapeType) { + + this.view = view; + this.shapeType = shapeType; + operatorType = null; + currentShapeId = 0; + + // Set the Action's name to "Add {ShapeType}" + setText("Add " + shapeType.toString()); + + // Create a map which stores the filenames of the icons, relative + // to the icons/ directory + Map+ * Constructor for creating new ComplexShapes with a given OperatorType + *
+ * + * @param view + *+ * The current ShapeTreeViewer + *
+ * @param operatorType + *+ * The type of ComplexShape to create with the action is + * triggered + *
+ */ + public ActionAddShape(ShapeTreeView view, OperatorType operatorType) { + + this.view = view; + this.shapeType = null; + this.operatorType = operatorType; + currentShapeId = 0; + + // Set the Action's name to "Add {ShapeType}" + + this.setText("Add " + operatorType.toString()); + + // Create a map which stores the filenames of the icons, relative + // to the icons/ directory + + Map+ * Runs this action + *
+ *+ * Each action implementation must define the steps needed to carry out this + * action. + *
+ * + */ + @Override + public void run() { + + // Get the selection + + ITreeSelection selection = (ITreeSelection) view.treeViewer.getSelection(); + TreePath[] paths = selection.getPaths(); + + // Fail silently if multiple items are selected + + if (paths.length > 1) { + return; + } + // Get the GeometryComponent from the ShapeTreeView's TreeViewer - Geometry geometry = (Geometry) view.treeViewer - .getInput(); + Geometry geometry = (Geometry) view.treeViewer.getInput(); - if (geometry == null) { - return; - } - // Get the parent shape, regardless of whether an IShape or BlankShape - // is selected + if (geometry == null) { + return; + } + // Get the parent shape, regardless of whether an IShape or BlankShape + // is selected - ComplexShape parentComplexShape = null; + ComplexShape parentComplexShape = null; - if (paths.length == 1) { + if (paths.length == 1) { - // Get the selected object from the single selection + // Get the selected object from the single selection - Object selectedObject = paths[0].getLastSegment(); + Object selectedObject = paths[0].getLastSegment(); - if (selectedObject instanceof IShape) { + if (selectedObject instanceof IShape) { - // Get the selected shape's parent + // Get the selected shape's parent - IShape selectedShape = (IShape) selectedObject; - parentComplexShape = (ComplexShape) selectedShape.getParent(); - } else if (selectedObject instanceof BlankShape) { + IShape selectedShape = (IShape) selectedObject; + parentComplexShape = (ComplexShape) selectedShape.getParent(); + } else if (selectedObject instanceof BlankShape) { - // Get the selected blank shape's parent + // Get the selected blank shape's parent - BlankShape selectedBlank = (BlankShape) selectedObject; - parentComplexShape = (ComplexShape) selectedBlank.getParent(); - } + BlankShape selectedBlank = (BlankShape) selectedObject; + parentComplexShape = (ComplexShape) selectedBlank.getParent(); + } - } + } - // Add a child shape to either the GeometryComponent or the parent - // ComplexShape + // Add a child shape to either the GeometryComponent or the parent + // ComplexShape - IShape childShape = createShape(); + IShape childShape = createShape(); - if (parentComplexShape == null) { + if (parentComplexShape == null) { - // Add a new shape to the root GeometryComponent + // Add a new shape to the root GeometryComponent - synchronized (geometry) { - geometry.addShape(childShape); - } + synchronized (geometry) { + geometry.addShape(childShape); + } - view.treeViewer.refresh(); - } + view.treeViewer.refresh(); + } - else { + else { - // Create a new shape and add it to the parentComplexShape + // Create a new shape and add it to the parentComplexShape - synchronized (geometry) { - parentComplexShape.addShape(childShape); - } + synchronized (geometry) { + parentComplexShape.addShape(childShape); + } - view.treeViewer.refresh(parentComplexShape); - } + view.treeViewer.refresh(parentComplexShape); + } - // Expand the child in the tree if a ComplexShape was added + // Expand the child in the tree if a ComplexShape was added - if (childShape != null && operatorType != null) { - view.treeViewer.expandToLevel(childShape, 1); - } - } + if (childShape != null && operatorType != null) { + view.treeViewer.expandToLevel(childShape, 1); + } + } - /** - * Returns the appropriate image descriptor for the action's icon - * - * @return The ImageDescriptor generated from the appropriate ShapeType or - * OperatorType - * @see org.eclipse.jface.action.Action#getImageDescriptor() - */ - @Override - public ImageDescriptor getImageDescriptor() { - return imageDescriptor; - } + /** + * Returns the appropriate image descriptor for the action's icon + * + * @return The ImageDescriptor generated from the appropriate ShapeType or + * OperatorType + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } - /** - *- * Creates a shape corresponding to this Action's ShapeType or OperatorType - *
- * - * @return- * The newly created shape - *
- */ - public IShape createShape() { + /** + *+ * Creates a shape corresponding to this Action's ShapeType or OperatorType + *
+ * + * @return + *+ * The newly created shape + *
+ */ + public IShape createShape() { - AbstractShape shape = null; + AbstractShape shape = null; - // Determine which type of shape should be created + // Determine which type of shape should be created - if (shapeType != null && operatorType == null) { + if (shapeType != null && operatorType == null) { - // Instantiate a PrimitiveShape and set its name and ID + // Instantiate a PrimitiveShape and set its name and ID - shape = new PrimitiveShape(shapeType); + shape = new PrimitiveShape(shapeType); - currentShapeId++; - shape.setName(shapeType.toString()); - shape.setId(currentShapeId); - } + currentShapeId++; + shape.setName(shapeType.toString()); + shape.setId(currentShapeId); + } - else if (operatorType != null && shapeType == null) { + else if (operatorType != null && shapeType == null) { - // Instantiate a ComplexShape and set its name + // Instantiate a ComplexShape and set its name - shape = new ComplexShape(operatorType); + shape = new ComplexShape(operatorType); - currentShapeId++; - shape.setName(operatorType.toString()); - shape.setId(currentShapeId); - } + currentShapeId++; + shape.setName(operatorType.toString()); + shape.setId(currentShapeId); + } - // Return the shape - // If none of the conditions above passed, this will return null. + // Return the shape + // If none of the conditions above passed, this will return null. - return shape; + return shape; - } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDeleteShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDeleteShape.java index 14e9754d477d93761431f1b7be95956cda0f63d2..39f82f6c99eb97f8b9cde653508540f6e8cdb21d 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDeleteShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDeleteShape.java @@ -33,115 +33,113 @@ import org.osgi.framework.FrameworkUtil; * @author Andrew P. Belt */ public class ActionDeleteShape extends Action { - /** - *- * The current ShapeTreeViewer associated with the DeleteShape action - *
- * - */ - private ShapeTreeView view; - - /** - * The image descriptor associated with the delete action's icon - */ - private ImageDescriptor imageDescriptor; + /** + *+ * The current ShapeTreeViewer associated with the DeleteShape action + *
+ * + */ + private ShapeTreeView view; - /** - *- * Constructor for setting the current ShapeTreeViewer - *
- * - * @param view - *- * The current ShapeTreeView - *
- */ - public ActionDeleteShape(ShapeTreeView view) { + /** + * The image descriptor associated with the delete action's icon + */ + private ImageDescriptor imageDescriptor; - this.view = view; + /** + *+ * Constructor for setting the current ShapeTreeViewer + *
+ * + * @param view + *+ * The current ShapeTreeView + *
+ */ + public ActionDeleteShape(ShapeTreeView view) { - this.setText("Delete Shape"); + this.view = view; - // Load the delete.gif ImageDescriptor from the bundle's - // `icons` directory + this.setText("Delete Shape"); - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, "icons/delete.gif"); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); + // Load the delete.gif ImageDescriptor from the bundle's + // `icons` directory - } + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, "icons/delete.gif"); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); - /** - * Returns the image descriptor associated with the delete action's icon - * - * @return The ImageDescriptor with the loaded delete.gif file - * @see org.eclipse.jface.action.Action#getImageDescriptor() - */ - @Override - public ImageDescriptor getImageDescriptor() { - return imageDescriptor; - } + } - /** - *- * Runs this action - *
- *- * Each action implementation must define the steps needed to carry out this - * action. - *
- * - */ - @Override - public void run() { + /** + * Returns the image descriptor associated with the delete action's icon + * + * @return The ImageDescriptor with the loaded delete.gif file + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } - // Get the tree paths of the current selection + /** + *+ * Runs this action + *
+ *+ * Each action implementation must define the steps needed to carry out this + * action. + *
+ * + */ + @Override + public void run() { - ITreeSelection selection = (ITreeSelection) view.treeViewer - .getSelection(); - TreePath[] paths = selection.getPaths(); + // Get the tree paths of the current selection - Geometry geometry = (Geometry) view.treeViewer - .getInput(); + ITreeSelection selection = (ITreeSelection) view.treeViewer.getSelection(); + TreePath[] paths = selection.getPaths(); - // Loop through each TreePath + Geometry geometry = (Geometry) view.treeViewer.getInput(); - for (TreePath path : paths) { + // Loop through each TreePath - Object selectedObject = path.getLastSegment(); + for (TreePath path : paths) { - // Check if the selected object is an IShape + Object selectedObject = path.getLastSegment(); - if (selectedObject instanceof IShape) { + // Check if the selected object is an IShape - IShape selectedShape = (IShape) selectedObject; - IShape parentShape = selectedShape.getParent(); + if (selectedObject instanceof IShape) { - if (parentShape instanceof ComplexShape) { + IShape selectedShape = (IShape) selectedObject; + IShape parentShape = selectedShape.getParent(); - // Remove the selected shape from the parent + if (parentShape instanceof ComplexShape) { - ComplexShape parentComplexShape = (ComplexShape) parentShape; + // Remove the selected shape from the parent - synchronized (geometry) { - parentComplexShape.removeShape(selectedShape); - } + ComplexShape parentComplexShape = (ComplexShape) parentShape; - view.treeViewer.refresh(parentShape); - } + synchronized (geometry) { + parentComplexShape.removeShape(selectedShape); + } - else if (parentShape == null) { + view.treeViewer.refresh(parentShape); + } - // The parent shape may be the root GeometryComponent, - // so try removing it from there. + else if (parentShape == null) { - synchronized (geometry) { - geometry.removeShape(selectedShape); - } - view.treeViewer.refresh(); - } - } - } + // The parent shape may be the root GeometryComponent, + // so try removing it from there. - } + synchronized (geometry) { + geometry.removeShape(selectedShape); + } + view.treeViewer.refresh(); + } + } + } + + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDuplicateShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDuplicateShape.java index 75f8d874f5e6b5046334407ac990cb5e3b6e52e6..e43015eacbcbf1a69b7fc873b89cb542c17d2125 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDuplicateShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionDuplicateShape.java @@ -33,130 +33,126 @@ import org.osgi.framework.FrameworkUtil; * @author Andrew P. Belt */ public class ActionDuplicateShape extends Action { - /** - * - */ - private ShapeTreeView view; + /** + * + */ + private ShapeTreeView view; - /** - * The image descriptor associated with the duplicate action's icon - */ - private ImageDescriptor imageDescriptor; + /** + * The image descriptor associated with the duplicate action's icon + */ + private ImageDescriptor imageDescriptor; - /** - * - * @param view - */ - public ActionDuplicateShape(ShapeTreeView view) { + /** + * + * @param view + */ + public ActionDuplicateShape(ShapeTreeView view) { - this.view = view; + this.view = view; - this.setText("Duplicate Shape"); + this.setText("Duplicate Shape"); - // Load duplicate.gif icon from the bundle's icons/ directory + // Load duplicate.gif icon from the bundle's icons/ directory - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, "icons/duplicate.gif"); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, "icons/duplicate.gif"); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); - } + } - /** - * Returns the image descriptor associated with the duplicate action's icon - * - * @see org.eclipse.jface.action.Action#getImageDescriptor() - */ - @Override - public ImageDescriptor getImageDescriptor() { - return imageDescriptor; - } + /** + * Returns the image descriptor associated with the duplicate action's icon + * + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } - /** - * - */ - @Override - public void run() { + /** + * + */ + @Override + public void run() { - Geometry geometry = (Geometry) view.treeViewer - .getInput(); + Geometry geometry = (Geometry) view.treeViewer.getInput(); - // Get selection + // Get selection - ITreeSelection selection = (ITreeSelection) view.treeViewer - .getSelection(); - TreePath[] paths = selection.getPaths(); + ITreeSelection selection = (ITreeSelection) view.treeViewer.getSelection(); + TreePath[] paths = selection.getPaths(); - // Iterate through the paths + // Iterate through the paths - for (TreePath path : paths) { - Object selectedObject = path.getLastSegment(); + for (TreePath path : paths) { + Object selectedObject = path.getLastSegment(); - if (selectedObject instanceof AbstractShape) { - AbstractShape selectedShape = (AbstractShape) selectedObject; + if (selectedObject instanceof AbstractShape) { + AbstractShape selectedShape = (AbstractShape) selectedObject; - // Clone the shape + // Clone the shape - IShape clonedShape = (IShape) selectedShape.clone(); + IShape clonedShape = (IShape) selectedShape.clone(); - // Remove the selected state from the cloned shape + // Remove the selected state from the cloned shape - clonedShape.removeProperty("selected"); + clonedShape.removeProperty("selected"); - // Try to get the selected shape's parent shape - // We can assume that if the parent exists, it is a ComplexShape + // Try to get the selected shape's parent shape + // We can assume that if the parent exists, it is a ComplexShape - ComplexShape parentShape = (ComplexShape) selectedShape - .getParent(); + ComplexShape parentShape = (ComplexShape) selectedShape.getParent(); - if (parentShape != null) { + if (parentShape != null) { - // Find the index of the selected shape in the list of its - // siblings + // Find the index of the selected shape in the list of its + // siblings - ArrayList- * The current ShapeTreeView - *
- * - */ - private ShapeTreeView view; - - /** - * The image descriptor associated with the duplicate action's icon - */ - private ImageDescriptor imageDescriptor; - - /** - *- * Initializes the instance with the current ShapeTreeView - *
- * - * @param view - *- * The current ShapeTreeView - *
- */ - public ActionReplicateShape(ShapeTreeView view) { + /** + *+ * The current ShapeTreeView + *
+ * + */ + private ShapeTreeView view; + + /** + * The image descriptor associated with the duplicate action's icon + */ + private ImageDescriptor imageDescriptor; - this.view = view; + /** + *+ * Initializes the instance with the current ShapeTreeView + *
+ * + * @param view + *+ * The current ShapeTreeView + *
+ */ + public ActionReplicateShape(ShapeTreeView view) { - this.setText("Replicate Shape"); + this.view = view; - // Load replicate.gif icon from the bundle's icons/ directory + this.setText("Replicate Shape"); - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, "icons/replicate.gif"); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); + // Load replicate.gif icon from the bundle's icons/ directory - } + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, "icons/replicate.gif"); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); - @Override - public ImageDescriptor getImageDescriptor() { - return imageDescriptor; - } + } - /** - *- * Opens the replicate dialog box and clones the selected shape to the - * properties - *
- * - */ - @Override - public void run() { + @Override + public ImageDescriptor getImageDescriptor() { + return imageDescriptor; + } - Geometry geometry = (Geometry) view.treeViewer - .getInput(); + /** + *+ * Opens the replicate dialog box and clones the selected shape to the + * properties + *
+ * + */ + @Override + public void run() { - // Check that only one shape is selected + Geometry geometry = (Geometry) view.treeViewer.getInput(); - ITreeSelection selection = (ITreeSelection) view.treeViewer - .getSelection(); - TreePath[] paths = selection.getPaths(); + // Check that only one shape is selected - if (paths.length != 1) { - return; - } - // Get the selected shape from the selection + ITreeSelection selection = (ITreeSelection) view.treeViewer.getSelection(); + TreePath[] paths = selection.getPaths(); - Object selectedObject = paths[0].getLastSegment(); + if (paths.length != 1) { + return; + } + // Get the selected shape from the selection - if (!(selectedObject instanceof IShape)) { - return; - } - IShape selectedShape = (IShape) selectedObject; + Object selectedObject = paths[0].getLastSegment(); - // Create a transformation, initialized from the selected shape's - // transformation + if (!(selectedObject instanceof IShape)) { + return; + } + IShape selectedShape = (IShape) selectedObject; - Transformation accumulatedTransformation = (Transformation) selectedShape - .getTransformation().clone(); + // Create a transformation, initialized from the selected shape's + // transformation - // Open the dialog + Transformation accumulatedTransformation = (Transformation) selectedShape.getTransformation().clone(); - ReplicateDialog replicateDialog = new ReplicateDialog(view.getSite() - .getShell()); + // Open the dialog - if (replicateDialog.open() != IDialogConstants.OK_ID) { - return; - } - // Get the dialog parameters + ReplicateDialog replicateDialog = new ReplicateDialog(view.getSite().getShell()); - int quantity = replicateDialog.getQuantity(); - double[] shift = replicateDialog.getShift(); + if (replicateDialog.open() != IDialogConstants.OK_ID) { + return; + } + // Get the dialog parameters - // Ignore the request if the desired quantity is 1 + int quantity = replicateDialog.getQuantity(); + double[] shift = replicateDialog.getShift(); - if (quantity == 1) { - return; - } - // Get the parent of the shape - // If the selected shape is a direct child of a GeometryComponent, - // its parent shape is null. + // Ignore the request if the desired quantity is 1 - ComplexShape parentShape = (ComplexShape) selectedShape.getParent(); + if (quantity == 1) { + return; + } + // Get the parent of the shape + // If the selected shape is a direct child of a GeometryComponent, + // its parent shape is null. - // Remove the selected shape from its original parent + ComplexShape parentShape = (ComplexShape) selectedShape.getParent(); - synchronized (geometry) { - if (parentShape != null) { - parentShape.removeShape(selectedShape); - } else { - geometry.removeShape(selectedShape); - } - } + // Remove the selected shape from its original parent - // Create a new parent union shape + synchronized (geometry) { + if (parentShape != null) { + parentShape.removeShape(selectedShape); + } else { + geometry.removeShape(selectedShape); + } + } - ComplexShape replicateUnion = new ComplexShape(OperatorType.Union); - replicateUnion.setName("Replication"); - replicateUnion.setId(((VizObject) selectedShape).getId()); + // Create a new parent union shape - for (int i = 1; i <= quantity; i++) { + ComplexShape replicateUnion = new ComplexShape(OperatorType.Union); + replicateUnion.setName("Replication"); + replicateUnion.setId(((VizObject) selectedShape).getId()); - // Clone the selected shape and remove its "selected" property + for (int i = 1; i <= quantity; i++) { - IShape clonedShape = (IShape) ((AbstractShape) selectedShape) - .clone(); - clonedShape.removeProperty("selected"); - ((VizObject) clonedShape).setId(i); + // Clone the selected shape and remove its "selected" property - // Add the translation + IShape clonedShape = (IShape) ((AbstractShape) selectedShape).clone(); + clonedShape.removeProperty("selected"); + ((VizObject) clonedShape).setId(i); - clonedShape - .setTransformation((Transformation) accumulatedTransformation - .clone()); + // Add the translation - // Add it to the replicated union + clonedShape.setTransformation((Transformation) accumulatedTransformation.clone()); - replicateUnion.addShape(clonedShape); + // Add it to the replicated union - // Shift the transform for the next shape + replicateUnion.addShape(clonedShape); - accumulatedTransformation.translate(shift); - } + // Shift the transform for the next shape - // Refresh the TreeViewer + accumulatedTransformation.translate(shift); + } - if (parentShape != null) { + // Refresh the TreeViewer - // The parent is an IShape + if (parentShape != null) { - synchronized (geometry) { - parentShape.addShape(replicateUnion); - } + // The parent is an IShape - view.treeViewer.refresh(parentShape); - } else { + synchronized (geometry) { + parentShape.addShape(replicateUnion); + } - // The parent is the root GeometryComponent + view.treeViewer.refresh(parentShape); + } else { - synchronized (geometry) { - geometry.addShape(replicateUnion); - } + // The parent is the root GeometryComponent - view.treeViewer.refresh(); - } + synchronized (geometry) { + geometry.addShape(replicateUnion); + } - view.treeViewer.expandToLevel(parentShape, 1); + view.treeViewer.refresh(); + } - } + view.treeViewer.expandToLevel(parentShape, 1); + + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/DropdownAction.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/DropdownAction.java index c314feabb04d02e9a8eb5d5f2055d7d97b39575a..5c708731660ae7ec7525941868d3af0d9a66bdd9 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/DropdownAction.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/DropdownAction.java @@ -37,152 +37,154 @@ import org.osgi.framework.FrameworkUtil; */ public class DropdownAction extends Action implements IMenuCreator { - @Override - public ImageDescriptor getImageDescriptor() { - // TODO Auto-generated method stub - return super.getImageDescriptor(); - } - - /** - * The root menu containing all the actions - */ - private Menu menu; - - /** - * The actions to display when this dropdown action is expanded - */ - private List- * Creates a dropdown action with a text label - *
- * - * @param text - *- * The label text to appear on the action button - *
- */ - public DropdownAction(String text) { - - super(text, IAction.AS_DROP_DOWN_MENU); - setMenuCreator(this); - - } - - /** - *- * Creates a dropdown action with an icon label - *
- * - * @param text - *- * The tooltip text - *
- * @param imageFilename - *- * The filename of the icon image, relative to the OSGi bundle - * location - *
- */ - public DropdownAction(String text, String imageFilename) { - - this(text); - - // Load the icon image - - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, imageFilename); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); - - } - - /** - *- * Cleans up and disposes internal Menu instance - *
- * - */ - @Override - public void dispose() { - - if (menu != null) { - menu.dispose(); - menu = null; - } - - } - - /** - *- * Returns null in this implementation - *
- * - * @param parent - *- * The parent Menu - *
- * @return- * The generated menu - *
- */ - @Override - public Menu getMenu(Menu parent) { - return null; - } - - /** - *- * Returns the Menu generated by this DropdownAction - *
- * - * @param parent - *- * The parent Control instance - *
- * @return- * The menu generated by this DropdownAction - *
- */ - @Override - public Menu getMenu(Control parent) { - - // Dispose of the old menu - - if (menu != null) { - menu.dispose(); - } - // Put all the actions into a new menu - - menu = new Menu(parent); - - for (Action action : childActions) { - ActionContributionItem item = new ActionContributionItem(action); - item.fill(menu, -1); - } - - return menu; - - } - - /** - *- * Appends an Action to the bottom of the current menu - *
- * - * @param action - *- * The Action to append - *
- */ - public void addAction(Action action) { - - childActions.add(action); - - } + @Override + public ImageDescriptor getImageDescriptor() { + // TODO Auto-generated method stub + return super.getImageDescriptor(); + } + + /** + * The root menu containing all the actions + */ + private Menu menu; + + /** + * The actions to display when this dropdown action is expanded + */ + private List+ * Creates a dropdown action with a text label + *
+ * + * @param text + *+ * The label text to appear on the action button + *
+ */ + public DropdownAction(String text) { + + super(text, IAction.AS_DROP_DOWN_MENU); + setMenuCreator(this); + + } + + /** + *+ * Creates a dropdown action with an icon label + *
+ * + * @param text + *+ * The tooltip text + *
+ * @param imageFilename + *+ * The filename of the icon image, relative to the OSGi bundle + * location + *
+ */ + public DropdownAction(String text, String imageFilename) { + + this(text); + + // Load the icon image + + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, imageFilename); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); + + } + + /** + *+ * Cleans up and disposes internal Menu instance + *
+ * + */ + @Override + public void dispose() { + + if (menu != null) { + menu.dispose(); + menu = null; + } + + } + + /** + *+ * Returns null in this implementation + *
+ * + * @param parent + *+ * The parent Menu + *
+ * @return + *+ * The generated menu + *
+ */ + @Override + public Menu getMenu(Menu parent) { + return null; + } + + /** + *+ * Returns the Menu generated by this DropdownAction + *
+ * + * @param parent + *+ * The parent Control instance + *
+ * @return + *+ * The menu generated by this DropdownAction + *
+ */ + @Override + public Menu getMenu(Control parent) { + + // Dispose of the old menu + + if (menu != null) { + menu.dispose(); + } + // Put all the actions into a new menu + + menu = new Menu(parent); + + for (Action action : childActions) { + ActionContributionItem item = new ActionContributionItem(action); + item.fill(menu, -1); + } + + return menu; + + } + + /** + *+ * Appends an Action to the bottom of the current menu + *
+ * + * @param action + *+ * The Action to append + *
+ */ + public void addAction(Action action) { + + childActions.add(action); + + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinner.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinner.java index bd907a07751269574cce433101483ff7c1009cff..6fb967775771fc18ef2c73544615e48f8aed25db 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinner.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinner.java @@ -36,258 +36,259 @@ import org.eclipse.swt.widgets.Text; * @author Andrew P. Belt */ public class RealSpinner { - /** - *- * The internal text box - *
- * - */ - private Text textWidget; + /** + *+ * The internal text box + *
+ * + */ + private Text textWidget; - /** - * The minimum value to allow, inclusive - */ - private double minimum = Double.NEGATIVE_INFINITY; + /** + * The minimum value to allow, inclusive + */ + private double minimum = Double.NEGATIVE_INFINITY; - /** - * The maximum value to allow, inclusive - */ - private double maximum = Double.POSITIVE_INFINITY; + /** + * The maximum value to allow, inclusive + */ + private double maximum = Double.POSITIVE_INFINITY; - /** - * The latest valid value - */ - private double value; + /** + * The latest valid value + */ + private double value; - /** - * The listeners to be notified of changes to the value - */ - private List- * Initializes the object and adds the widget to the given parent - *
- * - * @param parent - *- * The parent of the new RealSpinner - *
- */ - public RealSpinner(Composite parent) { + /** + *+ * Initializes the object and adds the widget to the given parent + *
+ * + * @param parent + *+ * The parent of the new RealSpinner + *
+ */ + public RealSpinner(Composite parent) { - textWidget = new Text(parent, SWT.LEFT | SWT.BORDER); + textWidget = new Text(parent, SWT.LEFT | SWT.BORDER); - // Add a FocusListener + // Add a FocusListener - FocusListener focusListener = new FocusListener() { + FocusListener focusListener = new FocusListener() { - @Override - public void focusGained(FocusEvent event) { + @Override + public void focusGained(FocusEvent event) { - // Select all the text in the Text widget + // Select all the text in the Text widget - textWidget.selectAll(); - } + textWidget.selectAll(); + } - @Override - public void focusLost(FocusEvent event) { + @Override + public void focusLost(FocusEvent event) { - // Just validate the text + // Just validate the text - validateText(); - } - }; + validateText(); + } + }; - textWidget.addFocusListener(focusListener); + textWidget.addFocusListener(focusListener); - // Add a DefaultSelection listener + // Add a DefaultSelection listener - Listener defaultSelectionListener = new Listener() { + Listener defaultSelectionListener = new Listener() { - @Override - public void handleEvent(Event event) { + @Override + public void handleEvent(Event event) { - // Validate the text and select all in the text box + // Validate the text and select all in the text box - validateText(); - textWidget.selectAll(); - } - }; + validateText(); + textWidget.selectAll(); + } + }; - textWidget.addListener(SWT.DefaultSelection, defaultSelectionListener); + textWidget.addListener(SWT.DefaultSelection, defaultSelectionListener); - // Add a key listener for key commands + // Add a key listener for key commands - KeyListener keyListener = new KeyAdapter() { + KeyListener keyListener = new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - - double change; - - // Calculate the change amount depending on the button pressed - - if (e.keyCode == SWT.ARROW_UP) { - change = 1.0; - } else if (e.keyCode == SWT.ARROW_DOWN) { - change = -1.0; - } else if (e.keyCode == SWT.PAGE_UP) { - change = 10.0; - } else if (e.keyCode == SWT.PAGE_DOWN) { - change = -10.0; - } else { - return; - } - // Scale the change amount by the modifier keys + @Override + public void keyPressed(KeyEvent e) { + + double change; + + // Calculate the change amount depending on the button pressed + + if (e.keyCode == SWT.ARROW_UP) { + change = 1.0; + } else if (e.keyCode == SWT.ARROW_DOWN) { + change = -1.0; + } else if (e.keyCode == SWT.PAGE_UP) { + change = 10.0; + } else if (e.keyCode == SWT.PAGE_DOWN) { + change = -10.0; + } else { + return; + } + // Scale the change amount by the modifier keys - if (e.stateMask == SWT.CTRL) { - change *= 0.1; - } else if (e.stateMask == SWT.SHIFT) { - change *= 0.01; - } else if (e.stateMask == (SWT.CTRL | SWT.SHIFT)) { - change *= 0.001; - } - // Increase the RealSpinner value by the computed amount + if (e.stateMask == SWT.CTRL) { + change *= 0.1; + } else if (e.stateMask == SWT.SHIFT) { + change *= 0.01; + } else if (e.stateMask == (SWT.CTRL | SWT.SHIFT)) { + change *= 0.001; + } + // Increase the RealSpinner value by the computed amount - setValue(value + change); - } - }; + setValue(value + change); + } + }; - textWidget.addKeyListener(keyListener); + textWidget.addKeyListener(keyListener); - // Set the value to zero as a default + // Set the value to zero as a default - setValue(0); + setValue(0); - } + } - /** - *- * Replaces the value with the given number - *
- * - * @param value - *- * The new value - *
- */ - public void setValue(double value) { + /** + *+ * Replaces the value with the given number + *
+ * + * @param value + *+ * The new value + *
+ */ + public void setValue(double value) { - // Clip the value to the closest allowed number + // Clip the value to the closest allowed number - if (value < minimum) { - value = minimum; - } else if (value > maximum) { - value = maximum; - } - this.value = value; + if (value < minimum) { + value = minimum; + } else if (value > maximum) { + value = maximum; + } + this.value = value; - // Set the widget text + // Set the widget text - textWidget.setText(String.valueOf(value)); + textWidget.setText(String.valueOf(value)); - // Notify each listener + // Notify each listener - for (RealSpinnerListener listener : listeners) { - listener.update(this); - } + for (RealSpinnerListener listener : listeners) { + listener.update(this); + } - } + } - /** - *- * Returns the real input value - *
- * - * @return- * The value - *
- */ - public double getValue() { - - // Return the last value + /** + *+ * Returns the real input value + *
+ * + * @return + *+ * The value + *
+ */ + public double getValue() { + + // Return the last value + + return value; + + } + + /** + *+ * Sets the minimum and maximum bounds (inclusive) + *
+ * + * @param minimum + *+ * The minimum value to enforce + *
+ * @param maximum + *+ * The maximum value to enforce + *
+ */ + public void setBounds(double minimum, double maximum) { + + // Assert that the bounds contain at least one possible allowed value + + if (minimum > maximum) { + return; + } + // Set the fields + + this.minimum = minimum; + this.maximum = maximum; + + // Clip the current value if needed + + setValue(value); + + } + + /** + * Adds a RealSpinnerListener to its listeners list to be notified of + * changes to the value + * + * @param listener + * The listener to notified of changes to the value + */ + public void listen(RealSpinnerListener listener) { - return value; - - } - - /** - *- * Sets the minimum and maximum bounds (inclusive) - *
- * - * @param minimum - *- * The minimum value to enforce - *
- * @param maximum - *- * The maximum value to enforce - *
- */ - public void setBounds(double minimum, double maximum) { - - // Assert that the bounds contain at least one possible allowed value - - if (minimum > maximum) { - return; - } - // Set the fields - - this.minimum = minimum; - this.maximum = maximum; - - // Clip the current value if needed - - setValue(value); - - } - - /** - * Adds a RealSpinnerListener to its listeners list to be notified of - * changes to the value - * - * @param listener - * The listener to notified of changes to the value - */ - public void listen(RealSpinnerListener listener) { + // Add the given listener to the listeners list + + if (listener != null && !listeners.contains(listener)) { + listeners.add(listener); + } + } + + /** + * Returns the Text control widget wrapped in this RealSpinner instance + * + * @return The Text widget + */ + public Control getControl() { + return textWidget; + } + + /** + * Checks the state of the Text widget and updates the value and text + * accordingly + */ + private void validateText() { + + // Check if the input can be parsed as a double + + try { + // Parse the text and set it as the new value - // Add the given listener to the listeners list - - if (listener != null && !listeners.contains(listener)) { - listeners.add(listener); - } - } - - /** - * Returns the Text control widget wrapped in this RealSpinner instance - * - * @return The Text widget - */ - public Control getControl() { - return textWidget; - } - - /** - * Checks the state of the Text widget and updates the value and text - * accordingly - */ - private void validateText() { - - // Check if the input can be parsed as a double - - try { - // Parse the text and set it as the new value + double newValue = Double.valueOf(textWidget.getText()); - double newValue = Double.valueOf(textWidget.getText()); - - setValue(newValue); - } catch (NumberFormatException e) { - - // Restore the value of the text box to the last valid value - - setValue(value); - } - } + setValue(newValue); + } catch (NumberFormatException e) { + + // Restore the value of the text box to the last valid value + + setValue(value); + } + } } diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinnerListener.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinnerListener.java index bfac76b90afa90bbe4cb274f94b1a4d99976eca5..780396a1e8116b544e4e9ada42342972c30abfc6 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinnerListener.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/RealSpinnerListener.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.ice.viz.service.geometry.widgets; - /** ** Enables the implementer to be notified of changes to a RealSpinner by calling @@ -22,12 +21,12 @@ package org.eclipse.ice.viz.service.geometry.widgets; * @author Andrew P. Belt */ public interface RealSpinnerListener { - /** - *
- * The function to call when RealSpinner is updated - *
- * - * @param realSpinner - */ - public void update(RealSpinner realSpinner); + /** + *+ * The function to call when RealSpinner is updated + *
+ * + * @param realSpinner + */ + public void update(RealSpinner realSpinner); } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ReplicateDialog.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ReplicateDialog.java index 155026fde5f66e2cb6c199690075ccdce4ff1b53..bf987485dc6a8ab328c01da1d0516eda1d031417 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ReplicateDialog.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ReplicateDialog.java @@ -39,168 +39,164 @@ import org.eclipse.swt.widgets.Spinner; */ public class ReplicateDialog extends Dialog { - /** - *- * The quantity spinner's value - *
- * - */ - private int quantity; - - /** - *- * An array of the shift spinner's values - *
- * - */ - private double[] shift = new double[3]; - - /** - * Shift spinners - */ - private RealSpinner[] shiftSpinners = new RealSpinner[3]; - - /** - * Quantity spinner - */ - private Spinner quantitySpinner; - - /** - * Initializes the Dialog with the given shell - * - * @param parentShell - * The shell - */ - public ReplicateDialog(Shell parentShell) { - super(parentShell); - } - - /** - *- * Returns the translation parameters - *
- * - * @return- * An array of three values representing the translation parameters - *
- */ - public double[] getShift() { - return shift; - } - - /** - *- * Returns the desired number of total similar shapes when cloning - *
- * - * @return- * The quantity - *
- */ - public int getQuantity() { - return quantity; - } - - @Override - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - - newShell.setText("Replicate"); - } - - /** - * Creates the buttons to close the Dialog - */ - @Override - protected void createButtonsForButtonBar(Composite parent) { - - // Local Declarations - String okLabel = "Ok", cancelLabel = "Cancel"; - - // Create der butans - createButton(parent, IDialogConstants.OK_ID, okLabel, true); - createButton(parent, IDialogConstants.CANCEL_ID, cancelLabel, false); - } - - /** - * Create the widgets for the main composite for the Dialog - */ - @Override - protected Control createDialogArea(Composite parent) { - - Composite container = (Composite) super.createDialogArea(parent); - container.setLayout(new GridLayout(4, false)); - - Label totalLabel = new Label(container, SWT.NONE); - totalLabel.setText("Quantity"); - - quantitySpinner = new Spinner(container, SWT.BORDER); - quantitySpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, - false, 3, 1)); - quantitySpinner.setValues(1, 1, 10000, 0, 1, 10); - new Label(container, SWT.NONE); - - // Create the X, Y, Z coordinate labels - - Label labelX = new Label(container, SWT.NONE); - labelX.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelX.setText("X"); - - Label labelY = new Label(container, SWT.NONE); - labelY.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelY.setText("Y"); - - Label labelZ = new Label(container, SWT.NONE); - labelZ.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelZ.setText("Z"); - - // Create the shift label - - Label shiftLabel = new Label(container, SWT.NONE); - shiftLabel.setText("Shift"); - - // Create the X, Y, Z shift spinners - - for (int i = 0; i < 3; i++) { - shiftSpinners[i] = new RealSpinner(container); - shiftSpinners[i].setBounds(-1.0e6, 1.0e6); - shiftSpinners[i].getControl().setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - } - - return container; - } - - @Override - protected void okPressed() { - - // Fire a default selection event on the spinners so they update - // their state - - Event defaultSelectionEvent = new Event(); - defaultSelectionEvent.type = SWT.DefaultSelection; + /** + *+ * The quantity spinner's value + *
+ * + */ + private int quantity; + + /** + *+ * An array of the shift spinner's values + *
+ * + */ + private double[] shift = new double[3]; + + /** + * Shift spinners + */ + private RealSpinner[] shiftSpinners = new RealSpinner[3]; + + /** + * Quantity spinner + */ + private Spinner quantitySpinner; + + /** + * Initializes the Dialog with the given shell + * + * @param parentShell + * The shell + */ + public ReplicateDialog(Shell parentShell) { + super(parentShell); + } + + /** + *+ * Returns the translation parameters + *
+ * + * @return + *+ * An array of three values representing the translation parameters + *
+ */ + public double[] getShift() { + return shift; + } + + /** + *+ * Returns the desired number of total similar shapes when cloning + *
+ * + * @return + *+ * The quantity + *
+ */ + public int getQuantity() { + return quantity; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + + newShell.setText("Replicate"); + } + + /** + * Creates the buttons to close the Dialog + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + + // Local Declarations + String okLabel = "Ok", cancelLabel = "Cancel"; + + // Create der butans + createButton(parent, IDialogConstants.OK_ID, okLabel, true); + createButton(parent, IDialogConstants.CANCEL_ID, cancelLabel, false); + } + + /** + * Create the widgets for the main composite for the Dialog + */ + @Override + protected Control createDialogArea(Composite parent) { + + Composite container = (Composite) super.createDialogArea(parent); + container.setLayout(new GridLayout(4, false)); + + Label totalLabel = new Label(container, SWT.NONE); + totalLabel.setText("Quantity"); + + quantitySpinner = new Spinner(container, SWT.BORDER); + quantitySpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); + quantitySpinner.setValues(1, 1, 10000, 0, 1, 10); + new Label(container, SWT.NONE); + + // Create the X, Y, Z coordinate labels + + Label labelX = new Label(container, SWT.NONE); + labelX.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelX.setText("X"); + + Label labelY = new Label(container, SWT.NONE); + labelY.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelY.setText("Y"); + + Label labelZ = new Label(container, SWT.NONE); + labelZ.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelZ.setText("Z"); + + // Create the shift label + + Label shiftLabel = new Label(container, SWT.NONE); + shiftLabel.setText("Shift"); + + // Create the X, Y, Z shift spinners + + for (int i = 0; i < 3; i++) { + shiftSpinners[i] = new RealSpinner(container); + shiftSpinners[i].setBounds(-1.0e6, 1.0e6); + shiftSpinners[i].getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + } + + return container; + } + + @Override + protected void okPressed() { - for (RealSpinner spinner : shiftSpinners) { - spinner.getControl().notifyListeners(SWT.DefaultSelection, - defaultSelectionEvent); - } + // Fire a default selection event on the spinners so they update + // their state - // Save the quantity value + Event defaultSelectionEvent = new Event(); + defaultSelectionEvent.type = SWT.DefaultSelection; - quantity = quantitySpinner.getSelection(); + for (RealSpinner spinner : shiftSpinners) { + spinner.getControl().notifyListeners(SWT.DefaultSelection, defaultSelectionEvent); + } - // Save the shift values + // Save the quantity value - for (int i = 0; i < 3; i++) { + quantity = quantitySpinner.getSelection(); - shift[i] = shiftSpinners[i].getValue(); - } + // Save the shift values - // Call Dialog's okPressed operation + for (int i = 0; i < 3; i++) { - super.okPressed(); - } + shift[i] = shiftSpinners[i].getValue(); + } + + // Call Dialog's okPressed operation + + super.okPressed(); + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeMaterial.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeMaterial.java index 332f5019edd045c5761830bb07fe905b01285082..df1fd856f9df7226f592837f20a6a228d6af1d8b 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeMaterial.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeMaterial.java @@ -14,172 +14,157 @@ package org.eclipse.ice.viz.service.geometry.widgets; import org.eclipse.ice.viz.service.geometry.shapes.IShape; -import com.jme3.asset.AssetManager; -import com.jme3.material.Material; +import javafx.scene.paint.Material; /** *- * Converts and stores an IShape's key/value properties list in format of JME3 + * Converts and stores an IShape's key/value properties list in format of JavaFX * data *
* + * @author Tony McCrary (tmccrary@l33tlabs.com) * @author Andrew P. Belt */ public class ShapeMaterial { - /** - *- * The selected state of the shape - *
- * - */ - private boolean selected; - /** - * - */ - private float alpha; - - /** - *- * The current AssetManager - *
- * - */ - private AssetManager assetManager; - - /** - * The Material used for this shape. - */ - private Material material; - - /** - * The Material used for this shape when it is selected/highlighted. - */ - private Material highlightedMaterial; - - /** - *- * Initializes the instance with a given IShape - *
- * - * @param assetManager - *- * The AssetManager to load the Material definition - *
- * @param shape - *- * The shape associated with this ShapeRenderProperties instance - *
- */ - public ShapeMaterial(AssetManager assetManager, IShape shape) { - - // Set the assetManager used for this shape and material - this.assetManager = assetManager; - - // Initialize variables - selected = false; - alpha = 1.0f; - - // Loop through each of the shape's parents - while (shape != null) { - applyShape(shape); - // Get the shape's parent - shape = shape.getParent(); - } - - return; - } - - /** - *- * Returns the material associated with the IShape properties - *
- * - * @return- * The material to render the shape - *
- */ - public Material getMaterial() { - - // There's no material if there is no assetManager! - if (assetManager == null) { - return null; - } - // Highlight the shape if it is selected. The if statement is ordered - // backwards because it is most likely that the shape is not selected - // and in this case it will execute this function quicker because it - // only has to do the first check. - if (!selected) { - return material; - } else { - return highlightedMaterial; - } - } - - /** - * This operation sets the material that should be used for this shape. - * - * @param mat - * The JME3 material. - */ - public void setMaterial(Material mat) { - - // Set the material that should be used for this shape - material = mat; - - return; - } - - /** - * This operation sets the material that should be used for the shape when - * it is selected. - * - * @param mat - * The JME3 material used when this shape is selected. - */ - public void setHighlightedMaterial(Material mat) { - - // Set the material - highlightedMaterial = mat; - - return; - } - - /** - *- * Applies the properties of the given shape to the state of the - * ShapeRenderProperties - *
- * - * @param shape - *- * The shape to apply (either a child or its ancestors) - *
- */ - private void applyShape(IShape shape) { - - // Extract the shape properties - - String selectedValue = shape.getProperty("selected"); - String alphaValue = shape.getProperty("alpha"); - - // Selected - - if (selectedValue != null && "true".equals(selectedValue)) { - selected = true; - } - // Alpha - - if (alphaValue != null) { - try { - float alphaFloat = Float.valueOf(alphaValue); - - alpha *= alphaFloat; - } catch (NumberFormatException e) { - } - } - - // Scale alpha value with a constant factor - - } + /** + *+ * The selected state of the shape + *
+ * + */ + private boolean selected; + /** + * + */ + private float alpha; + + /** + * The Material used for this shape. + */ + private Material material; + + /** + * The Material used for this shape when it is selected/highlighted. + */ + private Material highlightedMaterial; + + /** + *+ * Initializes the instance with a given IShape + *
+ * + * @param assetManager + *+ * The AssetManager to load the Material definition + *
+ * @param shape + *+ * The shape associated with this ShapeRenderProperties instance + *
+ */ + public ShapeMaterial(IShape shape) { + + // Initialize variables + selected = false; + alpha = 1.0f; + + // Loop through each of the shape's parents + while (shape != null) { + applyShape(shape); + // Get the shape's parent + shape = shape.getParent(); + } + + return; + } + + /** + *+ * Returns the material associated with the IShape properties + *
+ * + * @return + *+ * The material to render the shape + *
+ */ + public Material getMaterial() { + // Highlight the shape if it is selected. The if statement is ordered + // backwards because it is most likely that the shape is not selected + // and in this case it will execute this function quicker because it + // only has to do the first check. + if (!selected) { + return material; + } else { + return highlightedMaterial; + } + } + + /** + * This operation sets the material that should be used for this shape. + * + * @param mat + * The JavaFX material. + */ + public void setMaterial(Material mat) { + + // Set the material that should be used for this shape + material = mat; + + return; + } + + /** + * This operation sets the material that should be used for the shape when + * it is selected. + * + * @param mat + * The JavaFX material used when this shape is selected. + */ + public void setHighlightedMaterial(Material mat) { + + // Set the material + highlightedMaterial = mat; + + return; + } + + /** + *+ * Applies the properties of the given shape to the state of the + * ShapeRenderProperties + *
+ * + * @param shape + *+ * The shape to apply (either a child or its ancestors) + *
+ */ + private void applyShape(IShape shape) { + + // Extract the shape properties + + String selectedValue = shape.getProperty("selected"); + String alphaValue = shape.getProperty("alpha"); + + // Selected + + if (selectedValue != null && "true".equals(selectedValue)) { + selected = true; + } + // Alpha + + if (alphaValue != null) { + try { + float alphaFloat = Float.valueOf(alphaValue); + + alpha *= alphaFloat; + } catch (NumberFormatException e) { + } + } + + // Scale alpha value with a constant factor + + } } diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTransient.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTransient.java deleted file mode 100644 index bf4a6a8bd8a1b77b4b7468a8910889938a148f37..0000000000000000000000000000000000000000 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTransient.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012, 2014 UT-Battelle, LLC. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Initial API and implementation and/or initial documentation - Jay Jay Billings, - * Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson, - * Claire Saunders, Matthew Wang, Anna Wojtowicz - *******************************************************************************/ -package org.eclipse.ice.viz.service.geometry.widgets; - -import java.io.IOException; - -import org.eclipse.ice.viz.service.geometry.shapes.IShape; - -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.Savable; - - -/** - *- * Wrapper class for allowing an IShape to be stored in a JME3 Spatial as user - * data - *
- *- * ShapeTransient implements JME3's Savable interface but does not offer the - * ability to persist the IShape. This class exists solely to avoid IShape - * implementing Savable. - *
- * - * @author Andrew P. Belt - */ -public class ShapeTransient implements Savable { - /** - *- * The associated shape - *
- * - */ - private IShape shape; - - /** - *- * Associates a new ShapeTransient with the given IShape - *
- * - * @param shape - *- * The associated shape - *
- */ - public ShapeTransient(IShape shape) { - this.shape = shape; - } - - /** - *- * Returns the associated shape - *
- * - * @return- * The associated shape - *
- */ - public IShape getShape() { - return shape; - } - - /** - * Not implemented - */ - @Override - public void read(JmeImporter importer) throws IOException { - // Do nothing - } - - /** - * Not implemented - */ - @Override - public void write(JmeExporter exporter) throws IOException { - // Do nothing - } -} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeContentProvider.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeContentProvider.java index 0ab8cd1f8da771a1c72b9d32c0eb9b1e39f784a2..1b4b483b4b21fde37e975cad31ebbb43eb1023c5 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeContentProvider.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeContentProvider.java @@ -28,250 +28,253 @@ import org.eclipse.jface.viewers.Viewer; * * @author Andrew P. Belt */ -public class ShapeTreeContentProvider implements ITreeContentProvider, - IShapeVisitor { - /** - *- * Temporary variable for setting the return value of getChildren when the - * visit() operation is called - *
- * - */ - private Object[] temporaryChildren = null; - - /** - *- * Returns the child shapes of the given parent shape, if any - *
- *- * If a PrimitiveShape, an empty ComplexShape, or null is passed, this - * operation returns an empty array of Objects. - *
- * - * @param parentElement - *- * The parent IShape element - *
- * @return- * The child IShapes - *
- */ - @Override - public Object[] getChildren(Object parentElement) { - - // If the element is an IShape, call its accept() operation to - // trigger the visit() call - - if (parentElement instanceof IShape) { - temporaryChildren = null; - - // Call the parentShape's accept operation to call the appropriate - // visit member function in this class - - IShape parentShape = (IShape) parentElement; - parentShape.acceptShapeVisitor(this); - - // Return the result of the visit() operation - - return temporaryChildren; - } else { - return null; - } - - } - - /** - *- * Returns the child shape elements of a root GeometryComponent when the - * input of the shape TreeViewer is set or reset - *
- * - * @param inputElement - *- * The input GeometryComponent - *
- * @return- * The child IShapes - *
- */ - @Override - public Object[] getElements(Object inputElement) { - - // If the element is a GeometryComponent, return its shapes - if (inputElement instanceof Geometry) { - // Return an array of the GeometryComponent's shapes - Geometry parentGeometry = (Geometry) inputElement; - return parentGeometry.getShapes().toArray(); - } else { - return null; - } - - } - - /** - *- * Returns the parent of the element if it exists - *
- * - * @param element - *- * The child IShape - *
- * @return- * The parent IShape - *
- */ - @Override - public Object getParent(Object element) { - - // Return null if the element is not an IShape - - if (!(element instanceof IShape)) { - return null; - } - // Return the object's parent - - IShape shape = (IShape) element; - return shape.getParent(); - - } - - /** - *- * Returns whether the given element has children - *
- *- * In this implementation, there are no optimizations to quickly retrieve - * whether the element has children, so the array of child objects is found - * and counted. - *
- * - * @param element - *- * The IShape to check for children - *
- * @return- * Represents whether the element has children - *
- */ - @Override - public boolean hasChildren(Object element) { - - // Get the children from the getChildren operation and return whether - // there are elements in the array - - // No optimizations can be made to quickly retrieve the number of - // children from an object, so the best we can do is retrieve the - // entire array of objects and count the number of elements. - - Object[] elements = getChildren(element); - - if (elements != null) { - return elements.length > 0; - } else { - return false; - } - - } - - /** - * (non-Javadoc) - * - * @see IContentProvider#dispose() - */ - @Override - public void dispose() { - - // We don't need to dispose of anything. - - } - - /** - * (non-Javadoc) - * - * @see IContentProvider#inputChanged(Viewer viewer, Object oldInput, Object - * newInput) - */ - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - - // The state of this class does not depend on the input, so we do not - // need to change the state when the input of the TreeViewer changes. - - } - - /** - * The blank state item to display in the shape TreeViewer when a - * ComplexShape has no children - * - * @author Andrew P. Belt - * - */ - public class BlankShape { - - /** - * The default label of the BlankShape, designed to be as generic as - * possible - */ - public static final String TEXT = "+ * Temporary variable for setting the return value of getChildren when the + * visit() operation is called + *
+ * + */ + private Object[] temporaryChildren = null; + + /** + *+ * Returns the child shapes of the given parent shape, if any + *
+ *+ * If a PrimitiveShape, an empty ComplexShape, or null is passed, this + * operation returns an empty array of Objects. + *
+ * + * @param parentElement + *+ * The parent IShape element + *
+ * @return + *+ * The child IShapes + *
+ */ + @Override + public Object[] getChildren(Object parentElement) { + + // If the element is an IShape, call its accept() operation to + // trigger the visit() call + + if (parentElement instanceof IShape) { + temporaryChildren = null; + + // Call the parentShape's accept operation to call the appropriate + // visit member function in this class + + IShape parentShape = (IShape) parentElement; + parentShape.acceptShapeVisitor(this); + + // Return the result of the visit() operation + + return temporaryChildren; + } else { + return null; + } + + } + + /** + *+ * Returns the child shape elements of a root GeometryComponent when the + * input of the shape TreeViewer is set or reset + *
+ * + * @param inputElement + *+ * The input GeometryComponent + *
+ * @return + *+ * The child IShapes + *
+ */ + @Override + public Object[] getElements(Object inputElement) { + + // If the element is a GeometryComponent, return its shapes + if (inputElement instanceof Geometry) { + // Return an array of the GeometryComponent's shapes + Geometry parentGeometry = (Geometry) inputElement; + return parentGeometry.getShapes().toArray(); + } else { + return null; + } + + } + + /** + *+ * Returns the parent of the element if it exists + *
+ * + * @param element + *+ * The child IShape + *
+ * @return + *+ * The parent IShape + *
+ */ + @Override + public Object getParent(Object element) { + + // Return null if the element is not an IShape + + if (!(element instanceof IShape)) { + return null; + } + // Return the object's parent + + IShape shape = (IShape) element; + return shape.getParent(); + + } + + /** + *+ * Returns whether the given element has children + *
+ *+ * In this implementation, there are no optimizations to quickly retrieve + * whether the element has children, so the array of child objects is found + * and counted. + *
+ * + * @param element + *+ * The IShape to check for children + *
+ * @return + *+ * Represents whether the element has children + *
+ */ + @Override + public boolean hasChildren(Object element) { + + // Get the children from the getChildren operation and return whether + // there are elements in the array + + // No optimizations can be made to quickly retrieve the number of + // children from an object, so the best we can do is retrieve the + // entire array of objects and count the number of elements. + + Object[] elements = getChildren(element); + + if (elements != null) { + return elements.length > 0; + } else { + return false; + } + + } + + /** + * (non-Javadoc) + * + * @see IContentProvider#dispose() + */ + @Override + public void dispose() { + + // We don't need to dispose of anything. + + } + + /** + * (non-Javadoc) + * + * @see IContentProvider#inputChanged(Viewer viewer, Object oldInput, Object + * newInput) + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + + // The state of this class does not depend on the input, so we do not + // need to change the state when the input of the TreeViewer changes. + + } + + /** + * The blank state item to display in the shape TreeViewer when a + * ComplexShape has no children + * + * @author Andrew P. Belt + * + */ + public class BlankShape { + + /** + * The default label of the BlankShape, designed to be as generic as + * possible + */ + public static final String TEXT = "* Handles the drop actions of the ShapeTreeViewer when the user releases the @@ -22,57 +21,57 @@ package org.eclipse.ice.viz.service.geometry.widgets; * @author Jay Jay Billings */ public class ShapeTreeDropListener { - /** - * - * @param event - */ - public void dragEnter(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragEnter(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dragLeave(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragLeave(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dragOperationChanged(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragOperationChanged(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dragOver(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragOver(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void drop(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void drop(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dropAccept(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dropAccept(Class event) { + // TODO Auto-generated method stub - } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeLabelProvider.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeLabelProvider.java index 6b818f5ccafad2f0753a6c4410e8793e9d768b2a..c9113ccc53bb872eb0607ec60c7e04bbcd616874 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeLabelProvider.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeLabelProvider.java @@ -26,65 +26,67 @@ import org.eclipse.swt.graphics.Image; * @author Andrew P. Belt */ public class ShapeTreeLabelProvider extends LabelProvider { - /** - *
- * Returns the image associated with the given element object - *
- * - * @param element - *- * An IShape to produce its image - *
- * @return- * The icon associated with the given IShape element - *
- */ - @Override - public Image getImage(Object element) { + /** + *+ * Returns the image associated with the given element object + *
+ * + * @param element + *+ * An IShape to produce its image + *
+ * @return + *+ * The icon associated with the given IShape element + *
+ */ + @Override + public Image getImage(Object element) { - // Don't display an image beside the shape + // Don't display an image beside the shape - return null; + return null; - } + } - /** - *- * Returns the name associated with the given element object - *
- * - * @param element - *- * The ICEObject or AbstractShape to produce its text - *
- * @return- * The name associated with the element's ICEObject properties - *
- */ - @Override - public String getText(Object element) { + /** + *+ * Returns the name associated with the given element object + *
+ * + * @param element + *+ * The ICEObject or AbstractShape to produce its text + *
+ * @return + *+ * The name associated with the element's ICEObject properties + *
+ */ + @Override + public String getText(Object element) { - // Check that the element is an ICEObject and is not null + // Check that the element is an ICEObject and is not null - if (element instanceof IVizObject) { + if (element instanceof IVizObject) { - // Return the ICEObject's name property with its ICEObject ID - // appended with a space separator + // Return the ICEObject's name property with its ICEObject ID + // appended with a space separator - VizObject iceElement = (VizObject) element; - return iceElement.getName() + " " + iceElement.getId(); - } + VizObject iceElement = (VizObject) element; + return iceElement.getName() + " " + iceElement.getId(); + } - else if (element instanceof ShapeTreeContentProvider.BlankShape) { + else if (element instanceof ShapeTreeContentProvider.BlankShape) { - // Return the BlankShape default label text + // Return the BlankShape default label text - return BlankShape.TEXT; - } + return BlankShape.TEXT; + } - else { - return null; - } + else { + return null; + } - } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeSelectionListener.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeSelectionListener.java index 59b5da0187470ed5b8ed6644ab749e20be6e20c0..a28e4b40279ae947fbfc9d3fd7d6713eab54e4c3 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeSelectionListener.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeSelectionListener.java @@ -29,123 +29,122 @@ import org.eclipse.ui.IWorkbenchPage; * @author Jay Jay Billings */ public class ShapeTreeSelectionListener implements ISelectionChangedListener { - /** - *- * The reference to the current IWorkbenchPage - *
- * - */ - private IWorkbenchPage workbenchPage; - - /** - * A list of shapes of the last selection event - */ - private ArrayList- * The constructor for setting the internal reference to the current - * IWorkbenchPage - *
- * - * @param workbenchPage - *- * The current IWorkbenchPage - *
- */ - public ShapeTreeSelectionListener(IWorkbenchPage workbenchPage) { - - this.workbenchPage = workbenchPage; - - } - - /** - *- * Triggered with the shape tree selection is changed - *
- *- * The current implementation updates the referenced shape of the - * TransformationView. - *
- * - * @param event - *- * The selection event - *
- */ - public void selectionChanged(Class event) { - // TODO Auto-generated method stub - - } - - /** - * Changes the state of the TransformationView according to the currently - * selected shape - * - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent - * event) - */ - @Override - public void selectionChanged(SelectionChangedEvent event) { - - // Get the TransformationView if it is open - - TransformationView transformationView = (TransformationView) workbenchPage - .findView(TransformationView.ID); - - // Return if not - - if (transformationView == null) { - return; - } - // Get the tree paths - - ITreeSelection selection = (ITreeSelection) event.getSelection(); - TreePath[] paths = selection.getPaths(); - - // Remove the "selected" value from previously selected shapes - - for (IShape shape : selectedShapes) { - shape.removeProperty("selected"); - } - - selectedShapes.clear(); - - // Set the "selected" value to true for newly selected shapes - - for (TreePath path : paths) { - Object selectedObject = path.getLastSegment(); - - // Only perform the action for selected IShapes - // (rather than GeometryComponents or null) - - if (selectedObject instanceof IShape) { - IShape selectedShape = (IShape) selectedObject; - - selectedShape.setProperty("selected", "true"); - selectedShapes.add(selectedShape); - } - } - - // Set the TransformationView shape to null if nothing is selected - // or there are multiple selections - - if (paths.length != 1) { - transformationView.setShape(null); - return; - } - - Object selectedObject = paths[0].getLastSegment(); - - // Determine if the shape of the TransformationView should be set - - if (selectedObject instanceof IShape) { - transformationView.setShape((IShape) selectedObject); - } - - else { - transformationView.setShape(null); - } + /** + *+ * The reference to the current IWorkbenchPage + *
+ * + */ + private IWorkbenchPage workbenchPage; + + /** + * A list of shapes of the last selection event + */ + private ArrayList+ * The constructor for setting the internal reference to the current + * IWorkbenchPage + *
+ * + * @param workbenchPage + *+ * The current IWorkbenchPage + *
+ */ + public ShapeTreeSelectionListener(IWorkbenchPage workbenchPage) { + + this.workbenchPage = workbenchPage; + + } + + /** + *+ * Triggered with the shape tree selection is changed + *
+ *+ * The current implementation updates the referenced shape of the + * TransformationView. + *
+ * + * @param event + *+ * The selection event + *
+ */ + public void selectionChanged(Class event) { + // TODO Auto-generated method stub + + } + + /** + * Changes the state of the TransformationView according to the currently + * selected shape + * + * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent + * event) + */ + @Override + public void selectionChanged(SelectionChangedEvent event) { + + // Get the TransformationView if it is open + + TransformationView transformationView = (TransformationView) workbenchPage.findView(TransformationView.ID); + + // Return if not + + if (transformationView == null) { + return; + } + // Get the tree paths + + ITreeSelection selection = (ITreeSelection) event.getSelection(); + TreePath[] paths = selection.getPaths(); + + // Remove the "selected" value from previously selected shapes + + for (IShape shape : selectedShapes) { + shape.removeProperty("selected"); + } + + selectedShapes.clear(); + + // Set the "selected" value to true for newly selected shapes + + for (TreePath path : paths) { + Object selectedObject = path.getLastSegment(); + + // Only perform the action for selected IShapes + // (rather than GeometryComponents or null) + + if (selectedObject instanceof IShape) { + IShape selectedShape = (IShape) selectedObject; + + selectedShape.setProperty("selected", "true"); + selectedShapes.add(selectedShape); + } + } + + // Set the TransformationView shape to null if nothing is selected + // or there are multiple selections + + if (paths.length != 1) { + transformationView.setShape(null); + return; + } + + Object selectedObject = paths[0].getLastSegment(); + + // Determine if the shape of the TransformationView should be set + + if (selectedObject instanceof IShape) { + transformationView.setShape((IShape) selectedObject); + } - } + else { + transformationView.setShape(null); + } + + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeView.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeView.java index 5c62185699c30e2d7818a55f8f94f51a269c1a7b..741418ab95a56778645be64cce656dd9435e8952 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeView.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeView.java @@ -39,277 +39,275 @@ import org.eclipse.ui.part.ViewPart; * * @author Andrew P. Belt */ -public class ShapeTreeView extends ViewPart implements - ISelectionChangedListener { +public class ShapeTreeView extends ViewPart implements ISelectionChangedListener { - /** - *- * The currently displayed GeometryComponent - *
- * - */ - private Geometry geometry; + /** + *+ * The currently displayed GeometryComponent + *
+ * + */ + private Geometry geometry; - /** - *- * The main TreeViewer occupying the entire space of the view - *
- * - */ - TreeViewer treeViewer; + /** + *+ * The main TreeViewer occupying the entire space of the view + *
+ * + */ + TreeViewer treeViewer; - /** - * Eclipse view ID - */ - public static final String ID = "org.eclipse.ice.viz.service.geometry.widgets.ShapeTreeView"; + /** + * Eclipse view ID + */ + public static final String ID = "org.eclipse.ice.viz.service.geometry.widgets.ShapeTreeView"; - /** - * A list of shapes of the last selection event - */ - private ArrayList- * Creates the SWT controls for this ShapeTreeView - *
- * - * @param parent - *- * The parent Composite - *
- */ - @Override - public void createPartControl(Composite parent) { + /** + *+ * Creates the SWT controls for this ShapeTreeView + *
+ * + * @param parent + *+ * The parent Composite + *
+ */ + @Override + public void createPartControl(Composite parent) { - // Create the actions + // Create the actions - createActions(); + createActions(); - // Make a TreeViewer and add a content provider to it + // Make a TreeViewer and add a content provider to it - treeViewer = new TreeViewer(parent); + treeViewer = new TreeViewer(parent); - ShapeTreeContentProvider contentProvider = new ShapeTreeContentProvider(); - treeViewer.setContentProvider(contentProvider); + ShapeTreeContentProvider contentProvider = new ShapeTreeContentProvider(); + treeViewer.setContentProvider(contentProvider); - // Add label provider to TreeViewer + // Add label provider to TreeViewer - ShapeTreeLabelProvider labelProvider = new ShapeTreeLabelProvider(); - treeViewer.setLabelProvider(labelProvider); + ShapeTreeLabelProvider labelProvider = new ShapeTreeLabelProvider(); + treeViewer.setLabelProvider(labelProvider); - // Add selection listener to TreeViewer + // Add selection listener to TreeViewer - treeViewer.addSelectionChangedListener(this); + treeViewer.addSelectionChangedListener(this); - } + } - /** - *- * Creates actions required for manipulating the ShapeTreeView and adds them - * to the view's toolbar - *
- * - */ - private void createActions() { + /** + *+ * Creates actions required for manipulating the ShapeTreeView and adds them + * to the view's toolbar + *
+ * + */ + private void createActions() { - // Get the toolbar + // Get the toolbar - IActionBars actionBars = getViewSite().getActionBars(); - IToolBarManager toolbarManager = actionBars.getToolBarManager(); + IActionBars actionBars = getViewSite().getActionBars(); + IToolBarManager toolbarManager = actionBars.getToolBarManager(); - // Create the add shapes menu managers + // Create the add shapes menu managers - addPrimitiveShapes = new DropdownAction("Add Primitives"); - addComplexShapes = new DropdownAction("Add Complex"); + addPrimitiveShapes = new DropdownAction("Add Primitives"); + addComplexShapes = new DropdownAction("Add Complex"); - // Add the PrimitiveShape actions + // Add the PrimitiveShape actions - Action addSphere = new ActionAddShape(this, ShapeType.Sphere); - addPrimitiveShapes.addAction(addSphere); + Action addSphere = new ActionAddShape(this, ShapeType.Sphere); + addPrimitiveShapes.addAction(addSphere); - Action addCube = new ActionAddShape(this, ShapeType.Cube); - addPrimitiveShapes.addAction(addCube); + Action addCube = new ActionAddShape(this, ShapeType.Cube); + addPrimitiveShapes.addAction(addCube); - Action addCylinder = new ActionAddShape(this, ShapeType.Cylinder); - addPrimitiveShapes.addAction(addCylinder); + Action addCylinder = new ActionAddShape(this, ShapeType.Cylinder); + addPrimitiveShapes.addAction(addCylinder); - Action addTube = new ActionAddShape(this, ShapeType.Tube); - addPrimitiveShapes.addAction(addTube); + Action addTube = new ActionAddShape(this, ShapeType.Tube); + addPrimitiveShapes.addAction(addTube); - // Add the ComplexShape actions + // Add the ComplexShape actions - Action addUnion = new ActionAddShape(this, OperatorType.Union); - addComplexShapes.addAction(addUnion); + Action addUnion = new ActionAddShape(this, OperatorType.Union); + addComplexShapes.addAction(addUnion); - Action addIntersection = new ActionAddShape(this, - OperatorType.Intersection); - addIntersection.setEnabled(false); - addComplexShapes.addAction(addIntersection); + Action addIntersection = new ActionAddShape(this, OperatorType.Intersection); + addIntersection.setEnabled(false); + addComplexShapes.addAction(addIntersection); - Action addComplement = new ActionAddShape(this, OperatorType.Complement); - addComplement.setEnabled(false); - addComplexShapes.addAction(addComplement); + Action addComplement = new ActionAddShape(this, OperatorType.Complement); + addComplement.setEnabled(false); + addComplexShapes.addAction(addComplement); - // Add the Duplicate Shapes action + // Add the Duplicate Shapes action - duplicateShapes = new ActionDuplicateShape(this); + duplicateShapes = new ActionDuplicateShape(this); - // Add the Replicate action + // Add the Replicate action - replicateShapes = new ActionReplicateShape(this); + replicateShapes = new ActionReplicateShape(this); - // Add the DeleteShape action + // Add the DeleteShape action - deleteShape = new ActionDeleteShape(this); + deleteShape = new ActionDeleteShape(this); - // Add the top level menus to the toolbar - toolbarManager.add(addPrimitiveShapes); - toolbarManager.add(addComplexShapes); - toolbarManager.add(duplicateShapes); - toolbarManager.add(replicateShapes); - toolbarManager.add(deleteShape); + // Add the top level menus to the toolbar + toolbarManager.add(addPrimitiveShapes); + toolbarManager.add(addComplexShapes); + toolbarManager.add(duplicateShapes); + toolbarManager.add(replicateShapes); + toolbarManager.add(deleteShape); - } + } - /** - * - * @param geometry - */ - public void setGeometry(Geometry geometry) { + /** + * + * @param geometry + */ + public void setGeometry(Geometry geometry) { - this.geometry = geometry; + this.geometry = geometry; - // Set the TreeViewer's input + // Set the TreeViewer's input - this.treeViewer.setInput(geometry); + this.treeViewer.setInput(geometry); - } + } - /** - * (non-Javadoc) - * - * @see IWorkbenchPart#setFocus() - */ - @Override - public void setFocus() { - // TODO Auto-generated method stub + /** + * (non-Javadoc) + * + * @see IWorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + // TODO Auto-generated method stub - } + } - /** - * Updates the disabled state of the action icons and the state of the - * TransformationView - */ - @Override - public void selectionChanged(SelectionChangedEvent event) { + /** + * Updates the disabled state of the action icons and the state of the + * TransformationView + */ + @Override + public void selectionChanged(SelectionChangedEvent event) { - // Get the current selection + // Get the current selection - ITreeSelection selection = (ITreeSelection) event.getSelection(); - TreePath[] paths = selection.getPaths(); + ITreeSelection selection = (ITreeSelection) event.getSelection(); + TreePath[] paths = selection.getPaths(); - // Get the TransformationView + // Get the TransformationView - TransformationView transformationView = (TransformationView) getSite() - .getPage().findView(TransformationView.ID); + TransformationView transformationView = (TransformationView) getSite().getPage() + .findView(TransformationView.ID); - if (paths.length == 1) { + if (paths.length == 1) { - // Only one item is selected + // Only one item is selected - Object selectedObject = paths[0].getLastSegment(); + Object selectedObject = paths[0].getLastSegment(); - if (selectedObject instanceof IShape) { - IShape selectedShape = (IShape) selectedObject; + if (selectedObject instanceof IShape) { + IShape selectedShape = (IShape) selectedObject; - // Set the TransformationView's shape + // Set the TransformationView's shape - if (transformationView != null) { - transformationView.setShape(selectedShape); - } - // Enable/disable action buttons + if (transformationView != null) { + transformationView.setShape(selectedShape); + } + // Enable/disable action buttons - addPrimitiveShapes.setEnabled(true); - addComplexShapes.setEnabled(true); - duplicateShapes.setEnabled(true); - replicateShapes.setEnabled(true); - deleteShape.setEnabled(true); - } else if (selectedObject instanceof BlankShape) { + addPrimitiveShapes.setEnabled(true); + addComplexShapes.setEnabled(true); + duplicateShapes.setEnabled(true); + replicateShapes.setEnabled(true); + deleteShape.setEnabled(true); + } else if (selectedObject instanceof BlankShape) { - // Enable/disable action buttons + // Enable/disable action buttons - addPrimitiveShapes.setEnabled(true); - addComplexShapes.setEnabled(true); - duplicateShapes.setEnabled(false); - replicateShapes.setEnabled(false); - deleteShape.setEnabled(false); + addPrimitiveShapes.setEnabled(true); + addComplexShapes.setEnabled(true); + duplicateShapes.setEnabled(false); + replicateShapes.setEnabled(false); + deleteShape.setEnabled(false); - // Set the TransformationView to a blank state + // Set the TransformationView to a blank state - if (transformationView != null) { - transformationView.setShape(null); - } - } - } else { + if (transformationView != null) { + transformationView.setShape(null); + } + } + } else { - // Multiple or zero items are selected + // Multiple or zero items are selected - if (transformationView != null) { - transformationView.setShape(null); - } - if (paths.length > 1) { + if (transformationView != null) { + transformationView.setShape(null); + } + if (paths.length > 1) { - // Multiple items are selected. + // Multiple items are selected. - // Enable/disable action buttons + // Enable/disable action buttons - addPrimitiveShapes.setEnabled(false); - addComplexShapes.setEnabled(false); - duplicateShapes.setEnabled(true); - replicateShapes.setEnabled(false); - deleteShape.setEnabled(true); - } else { + addPrimitiveShapes.setEnabled(false); + addComplexShapes.setEnabled(false); + duplicateShapes.setEnabled(true); + replicateShapes.setEnabled(false); + deleteShape.setEnabled(true); + } else { - // Zero items are selected + // Zero items are selected - // Enable/disable action buttons + // Enable/disable action buttons - addPrimitiveShapes.setEnabled(true); - addComplexShapes.setEnabled(true); - duplicateShapes.setEnabled(false); - replicateShapes.setEnabled(false); - deleteShape.setEnabled(false); - } - } + addPrimitiveShapes.setEnabled(true); + addComplexShapes.setEnabled(true); + duplicateShapes.setEnabled(false); + replicateShapes.setEnabled(false); + deleteShape.setEnabled(false); + } + } - // Edit the shapes' selection property + // Edit the shapes' selection property - for (IShape selectedShape : selectedShapes) { - selectedShape.removeProperty("selected"); - } + for (IShape selectedShape : selectedShapes) { + selectedShape.removeProperty("selected"); + } - // Update the list of last-selected shapes + // Update the list of last-selected shapes - selectedShapes.clear(); + selectedShapes.clear(); - for (TreePath path : paths) { - Object selectedObject = path.getLastSegment(); + for (TreePath path : paths) { + Object selectedObject = path.getLastSegment(); - // Only include IShapes, not ShapeTreeLabelProvider::BlankShapes + // Only include IShapes, not ShapeTreeLabelProvider::BlankShapes - if (selectedObject instanceof IShape) { + if (selectedObject instanceof IShape) { - IShape selectedShape = (IShape) selectedObject; - selectedShape.setProperty("selected", "true"); - selectedShapes.add(selectedShape); - } - } - } + IShape selectedShape = (IShape) selectedObject; + selectedShape.setProperty("selected", "true"); + selectedShapes.add(selectedShape); + } + } + } } diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/TransformationView.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/TransformationView.java index 44734ccde6270a02ed8c3e3c63b3359828692840..1ad543a0459b055d66e4c94b68ef83dfd8a37ff4 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/TransformationView.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/TransformationView.java @@ -34,329 +34,313 @@ import org.eclipse.ui.part.ViewPart; */ public class TransformationView extends ViewPart { - /** - * Eclipse view ID - */ - public static final String ID = "org.eclipse.ice.viz.service.geometry.widgets.TransformationView"; - /** - * - */ - private RealSpinner[] skewSpinners = new RealSpinner[3]; - /** - * - */ - private RealSpinner sizeSpinner; - /** - * - */ - private RealSpinner[] scaleSpinners = new RealSpinner[3]; - /** - * - */ - private RealSpinner[] rotationSpinners = new RealSpinner[3]; - /** - * - */ - private RealSpinner[] translateSpinners = new RealSpinner[3]; - - /** - *- * The IShape which represents the state of the TransformationView - *
- * - */ - private IShape currentShape; - - /** - * Defines whether degrees or radians are used for rotation angles - */ - private boolean degrees = true; - - /** - * - * @param enabled - */ - private void setSpinnersEnabled(boolean enabled) { - - sizeSpinner.getControl().setEnabled(enabled); - - for (RealSpinner scaleSpinner : scaleSpinners) { - scaleSpinner.getControl().setEnabled(enabled); - } - - for (RealSpinner rotationSpinner : rotationSpinners) { - rotationSpinner.getControl().setEnabled(enabled); - } - - for (RealSpinner translateSpinner : translateSpinners) { - translateSpinner.getControl().setEnabled(enabled); - } - - } - - /** - * - * @param parent - */ - @Override - public void createPartControl(Composite parent) { - - // Create a scrolled composite - scroll bars! - ScrolledComposite scrolledParent = new ScrolledComposite(parent, - SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - // Create a sub-composite to hold the actual widgets - final Composite realParent = new Composite(scrolledParent, SWT.NONE); - - // Main layout - realParent.setLayout(new GridLayout(4, false)); - realParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, - 1, 1)); - - // Size parameter - Label sizeLabel = new Label(realParent, SWT.NONE); - sizeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - false, 1, 1)); - sizeLabel.setText("Size"); - - sizeSpinner = new RealSpinner(realParent); - sizeSpinner.getControl().setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); - sizeSpinner.setBounds(0.0, 1.0e6); - sizeSpinner.setValue(1.0); - - // Horizontal line - - Label separator = new Label(realParent, SWT.SEPARATOR | SWT.HORIZONTAL); - separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, - false, 4, 1)); - - // Coordinate labels - - Label labelBlank = new Label(realParent, SWT.NONE); - - Label labelX = new Label(realParent, SWT.NONE); - labelX.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelX.setText("X"); - - Label labelY = new Label(realParent, SWT.NONE); - labelY.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelY.setText("Y"); - - Label labelZ = new Label(realParent, SWT.NONE); - labelZ.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, - 1, 1)); - labelZ.setText("Z"); - - // Translation - Label translateLabel = new Label(realParent, SWT.NONE); - translateLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - false, 1, 1)); - translateLabel.setText("Translate"); - for (int i = 0; i < 3; i++) { - translateSpinners[i] = new RealSpinner(realParent); - translateSpinners[i].getControl().setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - translateSpinners[i].setBounds(-1.0e6, 1.0e6); - } - - // Rotation - Label rotationLabel = new Label(realParent, SWT.NONE); - rotationLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - false, 1, 1)); - rotationLabel.setText("Rotation"); - for (int i = 0; i < 3; i++) { - rotationSpinners[i] = new RealSpinner(realParent); - rotationSpinners[i].getControl().setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - rotationSpinners[i].setBounds(-1.0e6, 1.0e6); - } - - // Scale - Label scaleLabel = new Label(realParent, SWT.NONE); - scaleLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - false, 1, 1)); - scaleLabel.setText("Scale"); - for (int i = 0; i < 3; i++) { - scaleSpinners[i] = new RealSpinner(realParent); - scaleSpinners[i].getControl().setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - scaleSpinners[i].setBounds(0.0, 1.0e6); - scaleSpinners[i].setValue(1.0); - } - - // Skew - // TODO When skew is implemented on the JME3 application, uncomment this - // Label skewLabel = new Label(realParent, SWT.NONE); - // skewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - // false, 1, 1)); - // skewLabel.setText("Skew"); - // - // for (int i = 0; i < 3; i++) { - // skewSpinners[i] = new Spinner(realParent, SWT.BORDER); - // skewSpinners[i].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, - // true, false, 1, 1)); - // skewSpinners[i].setValues(0, -999000, 999000, 3, 1000, 10000); - // skewSpinners[i].setEnabled(false); - // } - - // Set the initial shape - createListeners(); - setShape(null); - - // Tell the scrolled composite to watch the real parent composite - scrolledParent.setContent(realParent); - // Set the expansion sizes and minimum size of the scrolled composite - scrolledParent.setExpandHorizontal(true); - scrolledParent.setExpandVertical(true); - scrolledParent.setMinSize(realParent.computeSize(SWT.DEFAULT, - SWT.DEFAULT)); - scrolledParent.setShowFocusedControl(true); - - } - - /** - *- * Sets the input shape and updates the state of the TransformationView to - * manipulate the input shape's transformation - *
- *- * Passing a null value for the input shape reinitializes and disables all - * the text boxes in the view. - *
- * - * @param shape - */ - public void setShape(IShape shape) { - - this.currentShape = shape; - - // Define a transformation for getting values - - Transformation transformation; - - if (shape == null) { - // Make a new transformation to set the default values of the - // spinners - - transformation = new Transformation(); - } else { - transformation = shape.getTransformation(); - } - - // Set the spinner values - - double size = transformation.getSize(); - sizeSpinner.setValue(size); - - double[] scale = transformation.getScale(); - for (int i = 0; i < 3; i++) { - scaleSpinners[i].setValue(scale[i]); - } - - double[] rotation = transformation.getRotation(); - - for (int i = 0; i < 3; i++) { - - // Convert the rotation value to degrees if needed - - if (degrees) { - rotationSpinners[i].setValue(Math.toDegrees(rotation[i])); - } else { - rotationSpinners[i].setValue(rotation[i]); - } - } - - double[] translations = transformation.getTranslation(); - for (int i = 0; i < 3; i++) { - translateSpinners[i].setValue(translations[i]); - } - - // Set the enabled state of the spinners, depending on whether the - // shape parameter is null - - setSpinnersEnabled(shape != null); - - } - - /** - * - */ - private void createListeners() { + /** + * Eclipse view ID + */ + public static final String ID = "org.eclipse.ice.viz.service.geometry.widgets.TransformationView"; + /** + * + */ + private RealSpinner[] skewSpinners = new RealSpinner[3]; + /** + * + */ + private RealSpinner sizeSpinner; + /** + * + */ + private RealSpinner[] scaleSpinners = new RealSpinner[3]; + /** + * + */ + private RealSpinner[] rotationSpinners = new RealSpinner[3]; + /** + * + */ + private RealSpinner[] translateSpinners = new RealSpinner[3]; + + /** + *+ * The IShape which represents the state of the TransformationView + *
+ * + */ + private IShape currentShape; + + /** + * Defines whether degrees or radians are used for rotation angles + */ + private boolean degrees = true; + + /** + * + * @param enabled + */ + private void setSpinnersEnabled(boolean enabled) { + + sizeSpinner.getControl().setEnabled(enabled); + + for (RealSpinner scaleSpinner : scaleSpinners) { + scaleSpinner.getControl().setEnabled(enabled); + } + + for (RealSpinner rotationSpinner : rotationSpinners) { + rotationSpinner.getControl().setEnabled(enabled); + } + + for (RealSpinner translateSpinner : translateSpinners) { + translateSpinner.getControl().setEnabled(enabled); + } + + } + + /** + * + * @param parent + */ + @Override + public void createPartControl(Composite parent) { + + // Create a scrolled composite - scroll bars! + ScrolledComposite scrolledParent = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + // Create a sub-composite to hold the actual widgets + final Composite realParent = new Composite(scrolledParent, SWT.NONE); + + // Main layout + realParent.setLayout(new GridLayout(4, false)); + realParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); + + // Size parameter + Label sizeLabel = new Label(realParent, SWT.NONE); + sizeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + sizeLabel.setText("Size"); + + sizeSpinner = new RealSpinner(realParent); + sizeSpinner.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); + sizeSpinner.setBounds(0.0, 1.0e6); + sizeSpinner.setValue(1.0); + + // Horizontal line + + Label separator = new Label(realParent, SWT.SEPARATOR | SWT.HORIZONTAL); + separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1)); + + // Coordinate labels + + Label labelBlank = new Label(realParent, SWT.NONE); + + Label labelX = new Label(realParent, SWT.NONE); + labelX.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelX.setText("X"); + + Label labelY = new Label(realParent, SWT.NONE); + labelY.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelY.setText("Y"); + + Label labelZ = new Label(realParent, SWT.NONE); + labelZ.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); + labelZ.setText("Z"); + + // Translation + Label translateLabel = new Label(realParent, SWT.NONE); + translateLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + translateLabel.setText("Translate"); + for (int i = 0; i < 3; i++) { + translateSpinners[i] = new RealSpinner(realParent); + translateSpinners[i].getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + translateSpinners[i].setBounds(-1.0e6, 1.0e6); + } + + // Rotation + Label rotationLabel = new Label(realParent, SWT.NONE); + rotationLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + rotationLabel.setText("Rotation"); + for (int i = 0; i < 3; i++) { + rotationSpinners[i] = new RealSpinner(realParent); + rotationSpinners[i].getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + rotationSpinners[i].setBounds(-1.0e6, 1.0e6); + } + + // Scale + Label scaleLabel = new Label(realParent, SWT.NONE); + scaleLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + scaleLabel.setText("Scale"); + for (int i = 0; i < 3; i++) { + scaleSpinners[i] = new RealSpinner(realParent); + scaleSpinners[i].getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + scaleSpinners[i].setBounds(0.0, 1.0e6); + scaleSpinners[i].setValue(1.0); + } + + // Skew + // TODO When skew is implemented on the JME3 application, uncomment this + // Label skewLabel = new Label(realParent, SWT.NONE); + // skewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, + // false, 1, 1)); + // skewLabel.setText("Skew"); + // + // for (int i = 0; i < 3; i++) { + // skewSpinners[i] = new Spinner(realParent, SWT.BORDER); + // skewSpinners[i].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + // true, false, 1, 1)); + // skewSpinners[i].setValues(0, -999000, 999000, 3, 1000, 10000); + // skewSpinners[i].setEnabled(false); + // } + + // Set the initial shape + createListeners(); + setShape(null); + + // Tell the scrolled composite to watch the real parent composite + scrolledParent.setContent(realParent); + // Set the expansion sizes and minimum size of the scrolled composite + scrolledParent.setExpandHorizontal(true); + scrolledParent.setExpandVertical(true); + scrolledParent.setMinSize(realParent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + scrolledParent.setShowFocusedControl(true); + + } + + /** + *+ * Sets the input shape and updates the state of the TransformationView to + * manipulate the input shape's transformation + *
+ *+ * Passing a null value for the input shape reinitializes and disables all + * the text boxes in the view. + *
+ * + * @param shape + */ + public void setShape(IShape shape) { + + this.currentShape = shape; + + // Define a transformation for getting values + + Transformation transformation; + + if (shape == null) { + // Make a new transformation to set the default values of the + // spinners + + transformation = new Transformation(); + } else { + transformation = shape.getTransformation(); + } + + // Set the spinner values + + double size = transformation.getSize(); + sizeSpinner.setValue(size); + + double[] scale = transformation.getScale(); + for (int i = 0; i < 3; i++) { + scaleSpinners[i].setValue(scale[i]); + } + + double[] rotation = transformation.getRotation(); + + for (int i = 0; i < 3; i++) { + + // Convert the rotation value to degrees if needed + + if (degrees) { + rotationSpinners[i].setValue(Math.toDegrees(rotation[i])); + } else { + rotationSpinners[i].setValue(rotation[i]); + } + } + + double[] translations = transformation.getTranslation(); + for (int i = 0; i < 3; i++) { + translateSpinners[i].setValue(translations[i]); + } + + // Set the enabled state of the spinners, depending on whether the + // shape parameter is null - IWidgetValueProperty property = WidgetProperties.selection(); + setSpinnersEnabled(shape != null); + + } - // Create anonymous listener + /** + * + */ + private void createListeners() { - RealSpinnerListener listener = new RealSpinnerListener() { + IWidgetValueProperty property = WidgetProperties.selection(); - @Override - public void update(RealSpinner realSpinner) { + // Create anonymous listener - // Handle a null currentShape + RealSpinnerListener listener = new RealSpinnerListener() { - if (currentShape == null) { - return; - } - // Get all the spinner values + @Override + public void update(RealSpinner realSpinner) { - double size = sizeSpinner.getValue(); + // Handle a null currentShape - double scaleX = scaleSpinners[0].getValue(); - double scaleY = scaleSpinners[1].getValue(); - double scaleZ = scaleSpinners[2].getValue(); + if (currentShape == null) { + return; + } + // Get all the spinner values - double rotationX = rotationSpinners[0].getValue(); - double rotationY = rotationSpinners[1].getValue(); - double rotationZ = rotationSpinners[2].getValue(); + double size = sizeSpinner.getValue(); - double translationX = translateSpinners[0].getValue(); - double translationY = translateSpinners[1].getValue(); - double translationZ = translateSpinners[2].getValue(); + double scaleX = scaleSpinners[0].getValue(); + double scaleY = scaleSpinners[1].getValue(); + double scaleZ = scaleSpinners[2].getValue(); - // Convert rotation from degrees to radians if needed + double rotationX = rotationSpinners[0].getValue(); + double rotationY = rotationSpinners[1].getValue(); + double rotationZ = rotationSpinners[2].getValue(); - if (degrees) { - rotationX = Math.toRadians(rotationX); - rotationY = Math.toRadians(rotationY); - rotationZ = Math.toRadians(rotationZ); - } + double translationX = translateSpinners[0].getValue(); + double translationY = translateSpinners[1].getValue(); + double translationZ = translateSpinners[2].getValue(); - // Reset the Transformation to the new parameters + // Convert rotation from degrees to radians if needed - Transformation transformation = new Transformation(); - transformation.setSize(size); - transformation.setScale(scaleX, scaleY, scaleZ); - transformation.setRotation(rotationX, rotationY, rotationZ); - transformation.setTranslation(translationX, translationY, - translationZ); + if (degrees) { + rotationX = Math.toRadians(rotationX); + rotationY = Math.toRadians(rotationY); + rotationZ = Math.toRadians(rotationZ); + } - // Reset the shape's transformation + // Reset the Transformation to the new parameters - currentShape.setTransformation(transformation); - } - }; + Transformation transformation = new Transformation(); + transformation.setSize(size); + transformation.setScale(scaleX, scaleY, scaleZ); + transformation.setRotation(rotationX, rotationY, rotationZ); + transformation.setTranslation(translationX, translationY, translationZ); - // Add the listener to each spinner + // Reset the shape's transformation - sizeSpinner.listen(listener); + currentShape.setTransformation(transformation); + } + }; - for (RealSpinner spinner : scaleSpinners) { - spinner.listen(listener); - } + // Add the listener to each spinner - for (RealSpinner spinner : rotationSpinners) { - spinner.listen(listener); - } - for (RealSpinner spinner : translateSpinners) { - spinner.listen(listener); - } - } + sizeSpinner.listen(listener); - @Override - public void setFocus() { - // TODO Auto-generated method stub + for (RealSpinner spinner : scaleSpinners) { + spinner.listen(listener); + } - } + for (RealSpinner spinner : rotationSpinners) { + spinner.listen(listener); + } + for (RealSpinner spinner : translateSpinners) { + spinner.listen(listener); + } + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 867017d16a1fb94164095f157566564e52fc5910..35c948535988dfdc1162570ec2752e5309530f7e 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,7 @@