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 @@ + + + + + + + + + + + diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.project b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.project new file mode 100644 index 0000000000000000000000000000000000000000..411a260aaaa75091dc0f52fec64d26d50f6851ad --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.project @@ -0,0 +1,28 @@ + + + org.eclipse.ice.viz.service.geometry.javafx.jcsg + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..0c68a61dca867ceb49e79d2402935261ec3e3809 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/JCSG.jar b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/JCSG.jar new file mode 100644 index 0000000000000000000000000000000000000000..270b253b6b5fdbf2137d5f6366abe552362c40cc Binary files /dev/null and b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/JCSG.jar differ diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/META-INF/MANIFEST.MF b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..97e9694bd9ea5f7d5a74f88f20864a51fc54f37c --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ICE Geometry JavaFX Implementation - CSG Support +Bundle-SymbolicName: org.eclipse.ice.viz.service.geometry.javafx.jcsg +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: ECLIPSE +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: JCSG.jar, + slf4j-api-1.6.1.jar, + slf4j-simple-1.6.1.jar, + vecmath-1.3.1.jar, + . +Export-Package: eu.mihosoft.vrl.v3d, + eu.mihosoft.vrl.v3d.ext.imagej, + eu.mihosoft.vrl.v3d.ext.openjfx.importers, + eu.mihosoft.vrl.v3d.ext.openjfx.importers.obj, + eu.mihosoft.vrl.v3d.ext.openjfx.shape3d, + eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.symbolic, + eu.mihosoft.vrl.v3d.ext.openjfx.utils3d, + eu.mihosoft.vrl.v3d.ext.org.poly2tri, + eu.mihosoft.vrl.v3d.ext.quickhull3d diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/build.properties b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..70e36208128c7cb1562f644a847abe355d3ee7e2 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + JCSG.jar,\ + slf4j-api-1.6.1.jar,\ + slf4j-simple-1.6.1.jar,\ + vecmath-1.3.1.jar diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/pom.xml b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..83d9cc946f548fc79657d3cc2a7e6608a388fc62 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + ICE + org.eclipse.ice.build + 2.1.7.20150825 + ../${pom-filename} + + ICE + org.eclipse.ice.viz.service.geometry.javafx.jcsg + eclipse-plugin + diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-api-1.6.1.jar b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-api-1.6.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..f1f4fdd214940c76cefaad2419e538e4c13cef6b Binary files /dev/null and b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-api-1.6.1.jar differ diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-simple-1.6.1.jar b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-simple-1.6.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..9ad8c97ece32b79fba752a1849923f58aaf9a09f Binary files /dev/null and b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/slf4j-simple-1.6.1.jar differ diff --git a/org.eclipse.ice.viz.service.geometry.javafx.jcsg/vecmath-1.3.1.jar b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/vecmath-1.3.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..fc2244bc8c11505870b9285cf0dbba0ef36053d2 Binary files /dev/null and b/org.eclipse.ice.viz.service.geometry.javafx.jcsg/vecmath-1.3.1.jar differ diff --git a/org.eclipse.ice.viz.service.geometry.javafx/.classpath b/org.eclipse.ice.viz.service.geometry.javafx/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..b5818c8dfb6d1a90aa46dfa315e77c2a2f35539e --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.ice.viz.service.geometry.javafx/.gitignore b/org.eclipse.ice.viz.service.geometry.javafx/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b83d22266ac8aa2f8df2edef68082c789727841d --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/org.eclipse.ice.viz.service.geometry.javafx/.project b/org.eclipse.ice.viz.service.geometry.javafx/.project new file mode 100644 index 0000000000000000000000000000000000000000..ba1fc579d258beab10cd76940f94a62ddca02b5e --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/.project @@ -0,0 +1,39 @@ + + + org.eclipse.ice.viz.service.geometry.javafx + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.ice.viz.service.geometry.javafx/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.ice.viz.service.geometry.javafx/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..0c68a61dca867ceb49e79d2402935261ec3e3809 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/org.eclipse.ice.viz.service.geometry.javafx/META-INF/MANIFEST.MF b/org.eclipse.ice.viz.service.geometry.javafx/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..1fc27dcbfadd70eec1faf41a56f654a495e8e870 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JavaFX Visualization Plugin +Bundle-SymbolicName: org.eclipse.ice.viz.service.geometry.javafx;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Fragment-Host: org.eclipse.ice.viz.service.geometry +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0", + org.eclipse.ui +Bundle-Vendor: Oak Ridge National Laboratory +Import-Package: + javafx.scene.input;version="2.2.0", + javafx.scene.transform;version="2.2.0", + org.eclipse.ice.viz.service, + org.eclipse.ice.viz.service.datastructures, + org.eclipse.ice.viz.service.datastructures.VizObject, + org.eclipse.ice.viz.service.geometry.scene.base, + org.eclipse.ice.viz.service.geometry.scene.model, + org.eclipse.ice.viz.service.geometry.shapes, + org.eclipse.ice.viz.service.geometry.viewer, + org.eclipse.ice.viz.service.geometry.widgets, + org.eclipse.ice.viz.service.mesh.datastructures, + org.eclipse.jface.databinding.swt, + org.slf4j;version="1.7.2" +Bundle-ClassPath: . +Export-Package: org.eclipse.ice.viz.service.geometry.viewer.factory + diff --git a/org.eclipse.ice.viz.service.geometry.javafx/build.properties b/org.eclipse.ice.viz.service.geometry.javafx/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..e51cdaa8f63abb34132c07f97cd4aa7c8d25645e --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/build.properties @@ -0,0 +1,10 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + jcsg/JCSG.jar,\ + jcsg/slf4j-api-1.6.1.jar,\ + jcsg/slf4j-simple-1.6.1.jar,\ + jcsg/vecmath-1.3.1.jar +source.. = src/ diff --git a/org.eclipse.ice.viz.service.geometry.javafx/pom.xml b/org.eclipse.ice.viz.service.geometry.javafx/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..1a33ab959f3a11f1842119843adf3999e85ad698 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + ICE + org.eclipse.ice.build + 2.1.7.20150825 + ../${pom-filename} + + ICE + org.eclipse.ice.viz.service.geometry.javafx + eclipse-plugin + diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/geometry/viewer/factory/GeometryViewerFactory.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/geometry/viewer/factory/GeometryViewerFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..4d68ae6cb45ce8bf8c9411d117a0b01a46055429 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/geometry/viewer/factory/GeometryViewerFactory.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.factory; + +import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer; +import org.eclipse.ice.viz.service.geometry.viewer.IViewerFactory; +import org.eclipse.ice.viz.service.javafx.internal.FXGeometryViewer; +import org.eclipse.swt.widgets.Composite; + +/** + *

+ * 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() { + + FXShape lastSelection = null; + + public void handle(MouseEvent event) { + // Pick + PickResult pickResult = event.getPickResult(); + + Node intersectedNode = pickResult.getIntersectedNode(); + + if (intersectedNode == null) { + return; + } + + if (!(intersectedNode instanceof FXShape)) { + return; + } + + // Resolve the parent + FXShape nodeParent = (FXShape) intersectedNode.getParent(); + + if (nodeParent == lastSelection) { + return; + } + + // Resolve the shape + IShape modelShape = (IShape) nodeParent.getProperties().get(IShape.class); + + if (modelShape == null) { + return; + } + + // Create and set the viewer selection + // (event gets fired in parent class) + GeometrySelection selection = new GeometrySelection(modelShape); + + setSelection(selection); + + nodeParent.setSelected(true); + + if (lastSelection != null) { + lastSelection.setSelected(false); + } + + lastSelection = nodeParent; + } + }); + } + + /** + *

+ * 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 processQueue = new ArrayDeque<>(); + Set nodeMap = new HashSet(); + + // Queue up the root node + processQueue.add(iceRoot); + nodeMap.add(iceRoot); + + // Iterate through the tree, generating the FX scene + while (!processQueue.isEmpty()) { + INode currentNode = (INode) processQueue.poll(); + + generateNode(currentNode); + + List children = currentNode.getChildren(false); + int size = children.size(); + + for (int i = 0; i < size; i++) { + INode child = children.get(i); + + if (!nodeMap.contains(child)) { + processQueue.add(child); + nodeMap.add(child); + } + } + } + + Node root = Util.getFxGroup(iceRoot); + + return root; + } + + /** + *

+ * 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, List> attachmentGroups = child.getAttachments(); + + if (attachmentGroups == null) { + return; + } + + // Iterate through each attachment type and each attachment + for (Entry, List> attachType : attachmentGroups.entrySet()) { + List attachmentItems = attachType.getValue(); + + int size = attachmentItems.size(); + + for (int i = 0; i < size; i++) { + IAttachment currentAttachment = attachmentItems.get(i); + processAttachment(child, currentAttachment); + } + } + } + + /** + *

+ * 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 shapes = complexShape.getShapes(); + + AddShapeToNode addShapeToNode = new AddShapeToNode(complexShapeNode); + + for (IShape shape : shapes) { + + // Visit the shape to add it to the current spatial + + shape.acceptShapeVisitor(addShapeToNode); + } + + // Attach the Node to a parent + + this.node.getChildren().add(complexShapeNode); + } + } + + /** + * Prepares the PrimitiveShape to be synchronized + */ + @Override + public void visit(PrimitiveShape primitiveShape) { + + // Local Declarations + ShapeType shapeType = ShapeType.None; + Mesh mesh = null; + + // Get the mesh. Since we are only using primitive shapes, we can + // reuse the meshes. + shapeType = primitiveShape.getType(); + + FXShape shape = new FXShape(shapeType); + + shape.getProperties().put(IShape.class, primitiveShape); + shape.getTransforms().setAll(Util.convertTransformation(primitiveShape.getTransformation())); + + // Attach the Geometry to a parent + this.node.getChildren().add(shape); + + return; + } +} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachment.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachment.java new file mode 100644 index 0000000000000000000000000000000000000000..0c1d8faf18503caf133d188383a4106c611d5fd1 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachment.java @@ -0,0 +1,319 @@ +/******************************************************************************* + * 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.geometry; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener; +import org.eclipse.ice.viz.service.geometry.scene.base.GeometryAttachment; +import org.eclipse.ice.viz.service.geometry.scene.base.IGeometry; +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.geometry.shapes.ComplexShape; +import org.eclipse.ice.viz.service.geometry.shapes.Geometry; +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.javafx.internal.Util; +import org.eclipse.ice.viz.service.javafx.internal.model.FXShape; + +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.transform.Transform; + +/** + *

+ * 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 fxShapeMap; + + /** */ + private List knownGeometry; + + /** + *

+ * 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 getShapes(boolean copy) { + return super.getShapes(copy); + + } + + /** + * + */ + @Override + public void clearShapes() { + super.clearShapes(); + } + + /** + * + * @return + */ + public FXGeometryAttachmentManager getManager() { + return manager; + } + + /** + * + * @return + */ + public javafx.scene.Node getFxParent() { + return fxAttachmentNode; + } + + /** + * + * @return + */ + public Group getFxNode() { + return fxAttachmentNode; + } + + /** + * + */ + public Class getType() { + return GeometryAttachment.class; + } + + /** + * + */ + public String getName() { + if (fxAttachmentNode == null) { + return "UNNAMED"; + } + + return fxAttachmentNode.getId(); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachmentManager.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachmentManager.java new file mode 100644 index 0000000000000000000000000000000000000000..322821957e163dcda3c68a7f700e43d0531cf23b --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/geometry/FXGeometryAttachmentManager.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * 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.geometry; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.ice.viz.service.geometry.scene.model.IAttachment; +import org.eclipse.ice.viz.service.geometry.viewer.IAttachmentManager; + +/** + *

+ * Manages FXGeometryAttachment allocations. + *

+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class FXGeometryAttachmentManager implements IAttachmentManager { + + /** The active list of attachments. */ + private List active; + + /** The list of attachments queued for removal. */ + private List removalQueue; + + /** + * @see IAttachmentManager#allocate() + */ + public IAttachment allocate() { + if (active == null) { + active = new ArrayList<>(); + } + + FXGeometryAttachment attach = new FXGeometryAttachment(this); + active.add(attach); + + return attach; + } + + /** + * @see IAttachmentManager#destroy(IAttachment) + */ + public void destroy(IAttachment attach) { + if (!(attach instanceof FXGeometryAttachment)) { + return; + } + + if (removalQueue == null) { + removalQueue = new ArrayList<>(); + } + + active.remove(attach); + removalQueue.add((FXGeometryAttachment) attach); + } + + /** + *

+ * 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 primitiveShapes = new ArrayList(); + + /** + * The temporary working list of ComplexShapes + */ + private ArrayList complexShapes = new ArrayList(); + + /** + * Initializes an instance with a JME3 scene graph node + * + * @param parentNode + * The parent of the nodes associated with the visited IShapes + */ + public SyncShapes(Group parentNode) { + this.parentNode = parentNode; + } + + /** + * Adds a ComplexShape to the temporary working list + */ + @Override + public void visit(ComplexShape complexShape) { + complexShapes.add(complexShape); + } + + /** + * Adds a PrimitiveShape to the temporary working list + */ + @Override + public void visit(PrimitiveShape primitiveShape) { + primitiveShapes.add(primitiveShape); + } + + /** + * Performs the synchronization of the node and the list of shapes + */ + public void commit() { + + // Local Declarations + IShape nodeShape = null; + int primitiveShapeIndex = -1; + int complexShapeIndex = -1; + + // Create a list of Node children indices to remove at a later time + List removeNodeIndices = new ArrayList(); + + int numNodeChildren = this.parentNode.getChildren().size(); + for (int nodeIndex = 0; nodeIndex < numNodeChildren; nodeIndex++) { + + // Get the child node + Node childSpatial = this.parentNode.getChildren().get(nodeIndex); + Group childNode = null; + + try { + childNode = (Group) childSpatial; + } catch (ClassCastException e) { + return; + } + + // Extract the reference to the child shape if it exists + if (childSpatial.getProperties().containsKey(IShape.class)) { + nodeShape = (IShape) childSpatial.getProperties().get(IShape.class); + primitiveShapeIndex = primitiveShapes.indexOf(nodeShape); + complexShapeIndex = complexShapes.indexOf(nodeShape); + } + + // Check if nodeShape is in one of the IShape lists + + if (primitiveShapeIndex >= 0) { + // nodeShape is an existing PrimitiveShape + + PrimitiveShape primitiveShape = primitiveShapes.get(primitiveShapeIndex); + + // Reset the transformation + childSpatial.getTransforms().setAll(Util.convertTransformation(primitiveShape.getTransformation())); + + // Rotate 90 degrees if it's a cylinder + + /* + * if (primitiveShape.getType() == ShapeType.Cylinder) { + * childSpatial.getTransforms().(Math.PI / 2, 0.0f, 0.0f); } + */ + + // Remove the shape from the PrimitiveShapes list + this.primitiveShapes.remove(primitiveShapeIndex); + } + + else if (complexShapeIndex >= 0) { + // nodeShape is an existing ComplexShape + + ComplexShape complexShape = complexShapes.get(complexShapeIndex); + + // Reset the transform + + childSpatial.getTransforms().setAll(Util.convertTransformation(complexShape.getTransformation())); + + // Synchronize each individual child in the ComplexShape + + SyncShapes syncComplexShapes = new SyncShapes(childNode); + ArrayList complexShapeChildren = complexShape.getShapes(); + + for (IShape complexShapeChild : complexShapeChildren) { + complexShapeChild.acceptShapeVisitor(syncComplexShapes); + } + + // Perform the updating on the scene graph + + syncComplexShapes.commit(); + + // Remove the shape from the ComplexShapes list + + this.complexShapes.remove(complexShapeIndex); + } + + else { + // nodeShape does not exist in one of the IShape lists + + removeNodeIndices.add(childSpatial); + } + } + + for (Node nodeIndex : removeNodeIndices) { + nodeIndex.setVisible(false); + this.parentNode.getChildren().remove(nodeIndex); + } + + // Add the new shapes to the node using the AddShapeToNode shape + // visitor class + + AddShapeToNode addShape = new AddShapeToNode(this.parentNode); + + for (IShape primitiveShape : primitiveShapes) { + primitiveShape.acceptShapeVisitor(addShape); + } + + for (IShape complexShape : complexShapes) { + complexShape.acceptShapeVisitor(addShape); + } + } +} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/messages.properties b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/messages.properties new file mode 100644 index 0000000000000000000000000000000000000000..919b66f8c0c360a6db2b9fcb8f5aa2bc1468ce48 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/model/messages.properties @@ -0,0 +1,5 @@ +FXGeometryAttachment_IncompatibleNodeGeometry=Incompatible node added, must be FXGeometryNode +FXGeometryAttachment_IncompatibleNodeMesh=Incompatible mesh added, must be FXMesh +FXMesh_IncompatibleMesh=FXMesh requires TriangleMesh instances. +FXNode_IncompatibleNodeGeometry=Incompatible node added, must be FXGeometryNode +FXNode_IncompatibleNodeMesh=Incompatible mesh added, must be FXMesh diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/AddShapeToNode.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/AddShapeToNode.java new file mode 100644 index 0000000000000000000000000000000000000000..939c9adadf3c1f1c7d83d8b2d9deacb345455ec8 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/AddShapeToNode.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * 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 implmentation - Andrew P. Belt + * Tony McCrary (tmccrary@l33tlabs.com) + *******************************************************************************/ +package org.eclipse.ice.viz.service.javafx.internal.scene; + +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 javafx.scene.Group; +import javafx.scene.paint.Material; +import javafx.scene.shape.Mesh; +import javafx.scene.shape.MeshView; +import javafx.scene.shape.TriangleMesh; +import javafx.scene.shape.VertexFormat; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Transform; + +/** + * Adds all visited shapes to the JavaFX scene graph node + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * @author Andrew P. Belt + * + */ +class AddShapeToNode implements IShapeVisitor { + + /** + * The node whose children will be added for each visited IShape + */ + private Group node; + + /** */ + private Mesh[] primitiveMeshes; + + /** */ + private Material baseMaterial; + + /** */ + private Material highlightedMaterial; + + /** + * Initializes the instance with the given JavaFX node + * + * @param node + */ + public AddShapeToNode(Group node) { + this.node = node; + + baseMaterial = Util.DEFAULT_MATERIAL; + highlightedMaterial = Util.DEFAULT_HIGHLIGHTED_MATERIAL; + } + + /** + * 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(Util.SHAPE_PROP_KEY, complexShape); + + complexShapeNode.getTransforms().add(Util.convertTransformation(complexShape.getTransformation())); + + // Loop through the shapes in the ComplexShape + + ArrayList shapes = complexShape.getShapes(); + + AddShapeToNode addShapeToNode = new AddShapeToNode(complexShapeNode); + + for (IShape shape : shapes) { + + // Visit the shape to add it to the current spatial + + shape.acceptShapeVisitor(addShapeToNode); + } + + // Attach the Node to a parent + + this.node.getChildren().add(complexShapeNode); + } + } + + /** + * Prepares the PrimitiveShape to be synchronized + */ + @Override + public void visit(PrimitiveShape primitiveShape) { + + // Local Declarations + ShapeType shapeType = ShapeType.None; + Mesh mesh = null; + + // Get the mesh. Since we are only using primitive shapes, we can + // reuse the meshes. + shapeType = primitiveShape.getType(); + if (shapeType != ShapeType.None && shapeType != ShapeType.Cone) { + mesh = primitiveMeshes[shapeType.ordinal()]; + } else { + return; + } + // Create geometry and store the reference to the shape data + // structure + + Group meshGroup = new Group(); + TriangleMesh geom = new TriangleMesh(VertexFormat.POINT_NORMAL_TEXCOORD); + + MeshView geomMeshView = new MeshView(geom); + meshGroup.getChildren().add(geomMeshView); + + meshGroup.getProperties().put(Util.SHAPE_PROP_KEY, primitiveShape); + meshGroup.getTransforms().setAll(Util.convertTransformation(primitiveShape.getTransformation())); + + // Cylinders need to be rotated 90 degrees on the x-axis + if (shapeType == ShapeType.Cylinder) { + Rotate rotate = Transform.rotate(90.0f, 0.0f, 0.0f); + meshGroup.getTransforms().add(rotate); + } + + // Give it a material + ShapeMaterial shapeMaterial = new ShapeMaterial(primitiveShape); + // Set the base material that is used for all the shapes + shapeMaterial.setMaterial(baseMaterial); + // Set the base material that is used for all selected shapes + shapeMaterial.setHighlightedMaterial(highlightedMaterial); + // Get the proper material from the shapeMaterial. It will change + // depending on whether or not it is selected. + geomMeshView.setMaterial(shapeMaterial.getMaterial()); + + // Attach the Geometry to a parent + this.node.getChildren().add(geomMeshView); + } +} \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/Plane.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/Plane.java new file mode 100644 index 0000000000000000000000000000000000000000..b555dd2bb5d0a7c5bd5b397f9252659201783c89 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/Plane.java @@ -0,0 +1,41 @@ +package org.eclipse.ice.viz.service.javafx.internal.scene; + +import javafx.scene.shape.MeshView; +import javafx.scene.shape.TriangleMesh; +import javafx.scene.shape.VertexFormat; + +/** + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class Plane extends MeshView { + + /** + * + * @param width + * @param height + * @param depth + */ + public Plane(double width, double height, double depth, int segments) { + TriangleMesh mesh = new TriangleMesh(); + mesh.setVertexFormat(VertexFormat.POINT_TEXCOORD); + + generatePlane(mesh, width, height, depth, segments); + + } + + /** + * + * @param mesh + * @param width + * @param height + * @param depth + * @param segments + * @return + */ + private float[] generatePlane(TriangleMesh mesh, double width, double height, double depth, int segments) { + return null; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/SyncShapes.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/SyncShapes.java new file mode 100644 index 0000000000000000000000000000000000000000..4ca0c4717f677e658ef75ec339e83bbf82439851 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/SyncShapes.java @@ -0,0 +1,221 @@ +/******************************************************************************* + * 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; + +import java.util.ArrayList; +import java.util.Collections; +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.geometry.shapes.ShapeType; +import org.eclipse.ice.viz.service.geometry.widgets.ShapeMaterial; +import org.eclipse.ice.viz.service.javafx.internal.Util; + +import javafx.scene.Group; +import javafx.scene.paint.Material; +import javafx.scene.shape.MeshView; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Transform; + +/** + * Synchronizes the given JavaFX node with each visited IShape child + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * @author Andrew P. Belt + * + */ +public class SyncShapes implements IShapeVisitor { + + /** + * The JavaFX scene graph node to update + */ + private Group parentNode; + + /** + * The temporary working list of PrimitiveShapes + */ + private ArrayList primitiveShapes = new ArrayList(); + + /** + * The temporary working list of ComplexShapes + */ + private ArrayList complexShapes = new ArrayList(); + + /** */ + private Material baseMaterial; + + /** */ + private Material highlightedMaterial; + + /** + * Initializes an instance with a JavaFX scene graph node + * + * @param parentNode + * The parent of the nodes associated with the visited + * IShapes + */ + public SyncShapes(Group parentNode) { + this.parentNode = parentNode; + + baseMaterial = Util.DEFAULT_MATERIAL; + highlightedMaterial = Util.DEFAULT_HIGHLIGHTED_MATERIAL; + } + + /** + * Adds a ComplexShape to the temporary working list + */ + @Override + public void visit(ComplexShape complexShape) { + complexShapes.add(complexShape); + } + + /** + * Adds a PrimitiveShape to the temporary working list + */ + @Override + public void visit(PrimitiveShape primitiveShape) { + primitiveShapes.add(primitiveShape); + } + + /** + * Performs the synchronization of the node and the list of shapes + */ + public void commit() { + + // Local Declarations + IShape nodeShape = null; + int primitiveShapeIndex = -1; + int complexShapeIndex = -1; + + // Create a list of Node children indices to remove at a later time + Vector removeNodeIndices = new Vector(); + + int numNodeChildren = this.parentNode.getChildren().size(); + for (int nodeIndex = 0; nodeIndex < numNodeChildren; nodeIndex++) { + + // Get the child node + MeshView childSpatial = (MeshView) this.parentNode.getChildren().get(nodeIndex); + Group childNode = null; + + /*try { + childNode = (Node) childSpatial; + } catch (ClassCastException e) { + }*/ + + // Extract the reference to the child shape if it exists + IShape shapeProperty = Util.getShapeProperty(childSpatial); + + if (shapeProperty != null) { + primitiveShapeIndex = primitiveShapes.indexOf(shapeProperty); + complexShapeIndex = complexShapes.indexOf(shapeProperty); + } + + // Check if nodeShape is in one of the IShape lists + + if (primitiveShapeIndex >= 0) { + // nodeShape is an existing PrimitiveShape + + PrimitiveShape primitiveShape = primitiveShapes + .get(primitiveShapeIndex); + + // Reset the transformation + + childSpatial + .getTransforms().add(Util.convertTransformation(primitiveShape + .getTransformation())); + + // Rotate 90 degrees if it's a cylinder + + if (primitiveShape.getType() == ShapeType.Cylinder) { + Rotate rotate = Transform.rotate(90.0f, 0.0f, 0.0f); + //meshGroup.getTransforms().add(rotate); + } + + // Reset the material - remember to use the baseMaterial and + // highlightedMaterial! + ShapeMaterial shapeMaterial = new ShapeMaterial(primitiveShape); + + shapeMaterial.setMaterial(baseMaterial); + // Set the base material that is used for all selected + // shapes + shapeMaterial.setHighlightedMaterial(highlightedMaterial); + // Get the proper material from the shapeMaterial. It will + // change depending on whether or not it is selected. + childSpatial.setMaterial(shapeMaterial.getMaterial()); + + // Remove the shape from the PrimitiveShapes list + + this.primitiveShapes.remove(primitiveShapeIndex); + } + + else if (complexShapeIndex >= 0) { + // nodeShape is an existing ComplexShape + + ComplexShape complexShape = complexShapes + .get(complexShapeIndex); + + // Reset the transform + + childSpatial + .getTransforms().setAll(Util.convertTransformation(complexShape + .getTransformation())); + + // Synchronize each individual child in the ComplexShape + + SyncShapes syncComplexShapes = new SyncShapes(childNode); + ArrayList complexShapeChildren = complexShape + .getShapes(); + + for (IShape complexShapeChild : complexShapeChildren) { + complexShapeChild.acceptShapeVisitor(syncComplexShapes); + } + + // Perform the updating on the scene graph + + syncComplexShapes.commit(); + + // Remove the shape from the ComplexShapes list + + this.complexShapes.remove(complexShapeIndex); + } + + else { + // nodeShape does not exist in one of the IShape lists + + removeNodeIndices.add(new Integer(nodeIndex)); + } + } + + // Remove the child Spatials by the given node indices + + Collections.reverse(removeNodeIndices); + + for (Integer nodeIndex : removeNodeIndices) { + //this.parentNode.detachChildAt(nodeIndex); + } + + // Add the new shapes to the node using the AddShapeToNode shape + // visitor class + + AddShapeToNode addShape = new AddShapeToNode(this.parentNode); + + for (IShape primitiveShape : primitiveShapes) { + primitiveShape.acceptShapeVisitor(addShape); + } + + for (IShape complexShape : complexShapes) { + complexShape.acceptShapeVisitor(addShape); + } + } +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/TransformGizmo.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/TransformGizmo.java new file mode 100644 index 0000000000000000000000000000000000000000..dd8ad67bcd6ff36db883e27ef548a305f3cd3576 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/TransformGizmo.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * 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; + +import javafx.collections.ObservableList; +import javafx.scene.DepthTest; +import javafx.scene.Group; +import javafx.scene.Node; +import javafx.scene.paint.Color; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.shape.Box; + +/** + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class TransformGizmo extends Group { + + /** */ + private Box handleX; + private Box handleY; + private Box handleZ; + + /** */ + private Box axisX; + private Box axisY; + private Box axisZ; + + /** */ + private float axisWidth = 2f; + + /** */ + private Node owner; + + /** + * + * @param axisSize + */ + public TransformGizmo(double axisSize) { + super(); + + PhongMaterial axisXMaterial = new PhongMaterial(); + axisXMaterial.setDiffuseColor(Color.RED); + + PhongMaterial axisYMaterial = new PhongMaterial(); + axisYMaterial.setDiffuseColor(Color.GREEN); + + PhongMaterial axisZMaterial = new PhongMaterial(); + axisZMaterial.setDiffuseColor(Color.BLUE); + + PhongMaterial handleMaterial = new PhongMaterial(); + handleMaterial.setDiffuseColor(Color.BLUE); + + setDepthTest(DepthTest.DISABLE); + + handleX = new Box(15, 15, 15); + handleX.setDepthTest(DepthTest.DISABLE); + handleX.setMaterial(handleMaterial); + handleX.setTranslateX(axisSize); + handleX.setTranslateY(0); + handleX.setTranslateZ(0); + + axisX = new Box(axisSize, axisWidth, axisWidth); + axisX.setDepthTest(DepthTest.DISABLE); + axisX.setMaterial(axisXMaterial); + axisX.setTranslateX(axisSize / 2f); + axisX.setTranslateY(0); + axisX.setTranslateZ(0); + + handleY = new Box(15, 15, 15); + handleY.setDepthTest(DepthTest.DISABLE); + handleY.setMaterial(handleMaterial); + handleY.setTranslateX(0); + handleY.setTranslateY(-axisSize); + handleY.setTranslateZ(0); + + axisY = new Box(axisWidth, axisSize, axisWidth); + axisY.setDepthTest(DepthTest.DISABLE); + axisY.setMaterial(axisYMaterial); + axisY.setTranslateX(0); + axisY.setTranslateY((axisSize / 2f)); + axisY.setTranslateZ(0); + + handleZ = new Box(15, 15, 15); + handleZ.setDepthTest(DepthTest.DISABLE); + handleZ.setMaterial(handleMaterial); + handleZ.setTranslateX(0); + handleZ.setTranslateY(0); + handleZ.setTranslateZ(axisSize); + + axisZ = new Box(axisWidth, axisWidth, axisSize); + axisZ.setDepthTest(DepthTest.DISABLE); + axisZ.setMaterial(axisZMaterial); + axisZ.setTranslateX(0); + axisZ.setTranslateY(0); + axisZ.setTranslateZ(axisSize / 2f); + + ObservableList children = getChildren(); + + children.add(handleX); + children.add(handleY); + children.add(handleZ); + + children.add(axisX); + children.add(axisY); + children.add(axisZ); + } + + /** + * + * @param handles + */ + public void showHandles(boolean handles) { + handleX.setVisible(handles); + handleY.setVisible(handles); + handleZ.setVisible(handles); + } + + public Node getOwner() { + return owner; + } + + public void setOwner(Node owner) { + this.owner = owner; + } +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/ArcBallController.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/ArcBallController.java new file mode 100644 index 0000000000000000000000000000000000000000..b6d36854122b41a72198bc7a6793a4f594ead41e --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/ArcBallController.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.Scene; +import javafx.scene.input.MouseEvent; +import javafx.scene.input.ScrollEvent; +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 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() { + + public void handle(ScrollEvent event) { + double translateX = -camera.getTranslateX(); + double translateY = -camera.getTranslateY(); + double translateZ = -camera.getTranslateZ(); + + double deltaY = event.getDeltaY(); + + // The direction the camera is facing + Point3D zVec = new Point3D(translateX, translateY, translateZ); + + // Normalized version that can be scaled + Point3D normalize = zVec.normalize(); + + double zoomSpeed = 50.0; + + // Final zoom scaling coefficient + Point3D scaledMovementCof = normalize.multiply(zoomSpeed); + + double currentX = camera.getTranslateX(); + double currentY = camera.getTranslateY(); + double currentZ = camera.getTranslateZ(); + + double zoomX = scaledMovementCof.getX(); + double zoomY = scaledMovementCof.getY(); + double zoomZ = scaledMovementCof.getZ(); + + if (deltaY < 0) { + camera.setTranslateX(currentX + zoomX); + camera.setTranslateY(currentY + zoomY); + camera.setTranslateZ(currentZ + zoomZ); + } else { + camera.setTranslateX(currentX - zoomX); + camera.setTranslateY(currentY - zoomY); + camera.setTranslateZ(currentZ - zoomZ); + } + } + }); + + scene.setOnMousePressed(new EventHandler() { + + public void handle(MouseEvent arg0) { + + width = scene.getWidth(); + height = scene.getHeight(); + + sphereRadius = Math.min(width / 2.0d, height / 2.0d); + + double startX = arg0.getSceneX() - (scene.getWidth() / 2.0d); + double startY = (scene.getHeight() / 2.0d) - arg0.getSceneY(); + + startRot = CamUtil.pointToSphere(-startX, startY, sphereRadius).normalize(); + currentRot = startRot; + + activeRotation = true; + } + + }); + + scene.setOnMouseReleased(new EventHandler() { + + public void handle(MouseEvent arg0) { + activeRotation = false; + } + + }); + + scene.setOnMouseDragged(new EventHandler() { + public void handle(MouseEvent arg0) { + double dragX = arg0.getSceneX() - (scene.getWidth() / 2.0d); + double dragY = (scene.getHeight() / 2.0d) - arg0.getSceneY(); + + currentRot = CamUtil.pointToSphere(-dragX, dragY, sphereRadius).normalize(); + + Point3D rotationAxis = currentRot.crossProduct(startRot).normalize(); + + double dotProduct = currentRot.dotProduct(startRot); + + if (dotProduct > 1 - 1E-10) { + dotProduct = 1.0; + } + + double angle = Math.acos(dotProduct) * 180.0f / Math.PI; + + Point3D invRotAxis = new Point3D(-rotationAxis.getX(), -rotationAxis.getY(), -rotationAxis.getZ()); + + Point3D pivot = new Point3D(0, 0, 0); + Rotate rotation = new Rotate(angle * 0.1d, pivot.getX(), pivot.getY(), pivot.getZ(), invRotAxis); + + if (camera.getTransforms().size() > 0) { + Transform totalRot = camera.getTransforms().get(0).createConcatenation(rotation); + camera.getTransforms().setAll(totalRot); + } else { + camera.getTransforms().add(rotation); + } + + double translateX = camera.getTranslateX(); + double translateY = camera.getTranslateY(); + double translateZ = camera.getTranslateZ(); + + Affine lookAt = CamUtil.lookAt(new Point3D(0, 0, 0), new Point3D(translateX, translateY, translateZ), + new Point3D(0, 1, 0)); + + camera.getTransforms().add(lookAt); + } + }); + + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CamUtil.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CamUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..df92274831b05bdf51f987bd814197172fd6c5bf --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/CamUtil.java @@ -0,0 +1,64 @@ +package org.eclipse.ice.viz.service.javafx.internal.scene.camera; + +import javafx.geometry.Point3D; +import javafx.scene.transform.Affine; + +/** + *

+ * 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() { + public void handle(KeyEvent event) { + + double speed = NORMAL_SPEED; + + if (event.isShiftDown()) { + speed = FAST_SPEED; + } + + KeyCode keyCode = event.getCode(); + + Transform worldTransform = xform.getLocalToSceneTransform(); + double zx = worldTransform.getMzx(); + double zy = worldTransform.getMzy(); + double zz = worldTransform.getMzz(); + + double xx = worldTransform.getMxx(); + double xy = worldTransform.getMxy(); + double xz = worldTransform.getMxz(); + + Point3D zDir = new Point3D(zx, zy, zz).normalize(); + Point3D xDir = new Point3D(xx, xy, xz).normalize(); + + if (keyCode == KeyCode.W) { + Point3D moveVec = zDir.multiply(speed); + affine.appendTranslation(moveVec.getX(), moveVec.getY(), moveVec.getZ()); + } else if (keyCode == KeyCode.S) { + Point3D moveVec = zDir.multiply(speed); + Point3D invVec = new Point3D(-moveVec.getX(), -moveVec.getY(), -moveVec.getZ()); + affine.appendTranslation(invVec.getX(), invVec.getY(), invVec.getZ()); + } else if (keyCode == KeyCode.A) { + Point3D moveVec = xDir.multiply(speed); + affine.appendTranslation(-moveVec.getX(), -moveVec.getY(), -moveVec.getZ()); + } else if (keyCode == KeyCode.D) { + Point3D moveVec = xDir.multiply(speed); + affine.appendTranslation(moveVec.getX(), moveVec.getY(), moveVec.getZ()); + } + + camera.getTransforms().setAll(affine); + + if (keyCode == KeyCode.SPACE) { + camera.setTranslateY(camera.getTranslateY() - speed); + } else if (keyCode == KeyCode.C) { + camera.setTranslateY(camera.getTranslateY() + speed); + } + } + }); + + scene.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent arg0) { + mousePosX = arg0.getSceneX(); + mousePosY = arg0.getSceneY(); + mouseOldX = arg0.getSceneX(); + mouseOldY = arg0.getSceneY(); + } + }); + + scene.setOnMouseDragged(new EventHandler() { + public void handle(MouseEvent arg0) { + mouseOldX = mousePosX; + mouseOldY = mousePosY; + mousePosX = arg0.getSceneX(); + mousePosY = arg0.getSceneY(); + mouseDeltaX = (mousePosX - mouseOldX); + mouseDeltaY = (mousePosY - mouseOldY); + + if (arg0.isPrimaryButtonDown()) { + affine.appendRotation((-mouseDeltaY % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.X_AXIS); + affine.appendRotation((mouseDeltaX % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.Y_AXIS); + + camera.getTransforms().setAll(affine); + } + } + }); + + } + +} diff --git a/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/TurntableController.java b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/TurntableController.java new file mode 100644 index 0000000000000000000000000000000000000000..b6b41e7b32f523273aa1a41085161f737fd70422 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry.javafx/src/org/eclipse/ice/viz/service/javafx/internal/scene/camera/TurntableController.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * 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.Scene; +import javafx.scene.input.MouseEvent; +import javafx.scene.transform.Affine; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Transform; + +/** + *

+ * 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() { + + public void handle(MouseEvent arg0) { + width = scene.getWidth(); + height = scene.getHeight(); + + startX = arg0.getSceneX(); + startY = arg0.getSceneY(); + + activeRotation = true; + } + + }); + + scene.setOnMouseReleased(new EventHandler() { + + public void handle(MouseEvent arg0) { + activeRotation = false; + } + + }); + + scene.setOnMouseDragged(new EventHandler() { + public void handle(MouseEvent arg0) { + + try { + Point3D yAxis = new Point3D(0.0d, -1.0d, 0.0d); + Affine transform = affine; + Affine createInverse = transform.createInverse(); + + Point3D zInv = new Point3D(createInverse.getMzx(), createInverse.getMzy(), createInverse.getMzz()); + Point3D xInv = new Point3D(createInverse.getMxx(), createInverse.getMxy(), createInverse.getMxz()); + + Point3D subtract = yAxis.subtract(zInv); + double invSqr = subtract.dotProduct(subtract); + + Point3D xAxis = null; + + if (invSqr > 0.0001f) { + xAxis = yAxis.crossProduct(zInv); + + double xDot = xAxis.dotProduct(xInv); + + if (xDot < 0.0d) { + xAxis = new Point3D(-xAxis.getX(), -xAxis.getY(), -xAxis.getZ()); + } + + double ac = Math.acos(xAxis.dotProduct(zInv)); + ac = Math.abs(ac - 0.5d) * 2.0d; + ac = ac * ac; + + Point3D scaledTo = new Point3D(zInv.getX(), zInv.getY(), zInv.getZ()).multiply(ac); + xAxis = yAxis.add(scaledTo); + } else { + xAxis = new Point3D(xInv.getX(), xInv.getY(), xInv.getZ()); + } + + double speedModifier = 0.005f; + + Rotate ry = new Rotate(speedModifier * -(arg0.getY() - startY), xAxis); + camera.getTransforms().add(ry); + + Rotate rx = new Rotate(speedModifier * (arg0.getX() - startX), yAxis); + Transform createConcatenation = rx.createConcatenation(ry); + + camera.getTransforms().add(createConcatenation); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/.classpath b/org.eclipse.ice.viz.service.geometry/.classpath index b1dabee38291b97f08cc3a18bee4e65b1e550530..69dcdab3edb40d28a4858dff1061aea8fe251664 100644 --- a/org.eclipse.ice.viz.service.geometry/.classpath +++ b/org.eclipse.ice.viz.service.geometry/.classpath @@ -1,7 +1,7 @@ - - - - - - - + + + + + + + diff --git a/org.eclipse.ice.viz.service.geometry/.project b/org.eclipse.ice.viz.service.geometry/.project index 67dc38d477c7b4187eeb76e7c3ec1e86edf4e30d..37e05b4d6616997520db60b7a5a4bf3bbec671de 100644 --- a/org.eclipse.ice.viz.service.geometry/.project +++ b/org.eclipse.ice.viz.service.geometry/.project @@ -25,8 +25,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature diff --git a/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.jdt.core.prefs index f42de363afaae68bbd968318f1d331877f5514fc..0c68a61dca867ceb49e79d2402935261ec3e3809 100644 --- a/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..f897a7f1cb2389f85fe6381425d29f0a9866fb65 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/org.eclipse.ice.viz.service.geometry/META-INF/MANIFEST.MF b/org.eclipse.ice.viz.service.geometry/META-INF/MANIFEST.MF index bdc86d7c5388235e735a2f656a34183d764c050b..e46031b0eaa01239723bdefb979e84867722a89a 100644 --- a/org.eclipse.ice.viz.service.geometry/META-INF/MANIFEST.MF +++ b/org.eclipse.ice.viz.service.geometry/META-INF/MANIFEST.MF @@ -3,32 +3,25 @@ Bundle-ManifestVersion: 2 Bundle-Name: Geometry Visualization Service Plugin Bundle-SymbolicName: org.eclipse.ice.viz.service.geometry;singleton:=true Bundle-Version: 2.1.7.20150825 -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 -Import-Package: com.jme3.app, - com.jme3.asset, - com.jme3.export, - com.jme3.font, - com.jme3.input, - com.jme3.light, - com.jme3.material, - com.jme3.math, - com.jme3.renderer, - com.jme3.renderer.queue, - com.jme3.scene, - com.jme3.scene.mesh, - com.jme3.scene.shape, - com.jme3.system, - com.jme3.util, - gov.lbnl.visit.swt, +Service-Component: OSGI-INF/vizGeometryService.xml, + OSGI-INF/vizMeshService.xml +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: gov.lbnl.visit.swt, gov.lbnl.visit.swt.widgets, org.eclipse.ice.viz.service, org.eclipse.ice.viz.service.datastructures, org.eclipse.ice.viz.service.datastructures.VizObject, + org.eclipse.ice.viz.service.geometry.viewer.factory, org.eclipse.jface.databinding.swt, org.slf4j;version="1.7.2", visit.java.client -Export-Package: org.eclipse.ice.viz.service.geometry.widgets, - org.eclipse.ice.viz.service.geometry.shapes +Export-Package: org.eclipse.ice.viz.service.geometry.scene.base, + org.eclipse.ice.viz.service.geometry.scene.model, + org.eclipse.ice.viz.service.geometry.shapes, + org.eclipse.ice.viz.service.geometry.viewer, + org.eclipse.ice.viz.service.geometry.widgets Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui Bundle-Vendor: Oak Ridge National Laboratory +Eclipse-ExtensibleAPI: true + diff --git a/org.eclipse.ice.viz.service.geometry/OSGI-INF/vizGeometryService.xml b/org.eclipse.ice.viz.service.geometry/OSGI-INF/vizGeometryService.xml new file mode 100644 index 0000000000000000000000000000000000000000..618e2365f1b33bd0dd4263a17fbe510b6cdc7a59 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/OSGI-INF/vizGeometryService.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.ice.viz.service.geometry/build.properties b/org.eclipse.ice.viz.service.geometry/build.properties index 7a22e3e1f8a0e7f5a0c7c14987e8dbd0f1764847..163cdac7a5e8eb9b565a4eef16586c493cf232c4 100644 --- a/org.eclipse.ice.viz.service.geometry/build.properties +++ b/org.eclipse.ice.viz.service.geometry/build.properties @@ -1,5 +1,6 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ - plugin.xml + plugin.xml,\ + OSGI-INF/ source.. = src/ diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryCanvas.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryCanvas.java new file mode 100644 index 0000000000000000000000000000000000000000..7625382761c81add4af08c3122afaf1055b7cebb --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryCanvas.java @@ -0,0 +1,262 @@ +/******************************************************************************* + * 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; + +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Collections; +import java.util.Map; + +import org.eclipse.ice.viz.service.IVizCanvas; +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable; +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener; +import org.eclipse.ice.viz.service.geometry.scene.base.GNode; +import org.eclipse.ice.viz.service.geometry.scene.base.GeometryAttachment; +import org.eclipse.ice.viz.service.geometry.scene.model.INode; +import org.eclipse.ice.viz.service.geometry.shapes.Geometry; +import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer; +import org.eclipse.ice.viz.service.geometry.viewer.IRenderer; +import org.eclipse.ice.viz.service.geometry.widgets.TransformationView; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; + +/** + *

+ * 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 properties; + + /** + *

+ * 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 getProperties() { + if (properties == null) { + return Collections.emptyMap(); + } else { + return properties; + } + } + + /** + * @see IVizCanvas#getSourceHost() + */ + public String getSourceHost() { + return null; + } + + /** + * @see IVizCanvas#isSourceRemote() + */ + public boolean isSourceRemote() { + return false; + } + + /** + * @see IVizCanvas#redraw() + */ + public void redraw() { + } + + /** + * @see IVizCanvas#setProperties() + */ + public void setProperties(Map props) throws Exception { + this.properties = props; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometrySelection.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometrySelection.java new file mode 100644 index 0000000000000000000000000000000000000000..b11a5ab0b7107fe4b49d738c4bcf0b6a4105ff6f --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometrySelection.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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; + +import org.eclipse.ice.viz.service.geometry.shapes.IShape; +import org.eclipse.jface.viewers.StructuredSelection; + +/** + * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public class GeometrySelection extends StructuredSelection { + + /** */ + private final IShape shape; + + /** + * + * @param modelShape + */ + public GeometrySelection(IShape modelShape) { + super(modelShape); + + this.shape = modelShape; + } + + public IShape getShape() { + return shape; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryVizService.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryVizService.java new file mode 100644 index 0000000000000000000000000000000000000000..266ed6ffd4b9630fc868c4d1dde846e073383d2d --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/GeometryVizService.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.ice.viz.service.AbstractVizService; +import org.eclipse.ice.viz.service.IVizCanvas; +import org.eclipse.ice.viz.service.IVizService; +import org.eclipse.ice.viz.service.datastructures.VizObject.IVizObject; +import org.eclipse.ice.viz.service.geometry.shapes.Geometry; +import org.eclipse.ice.viz.service.geometry.viewer.GeometryViewer; +import org.eclipse.ice.viz.service.geometry.widgets.TransformationView; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; + +/** + *

+ * 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 findSupportedExtensions() { + return Collections.emptySet(); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/Messages.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/Messages.java new file mode 100644 index 0000000000000000000000000000000000000000..8eec06e9f1ec74b76778dd62f9f56d54bcd6b0f6 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/Messages.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.ice.viz.service.javafx.geometry.messages"; //$NON-NLS-1$ + public static String GeometryCanvas_ErrorCreatingViewer; + public static String GeometryVizService_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/Util.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/Util.java new file mode 100644 index 0000000000000000000000000000000000000000..65cd038b6dabf822b2f70ee48cfa8c58260983ac --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/Util.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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; + +import org.eclipse.ice.viz.service.geometry.shapes.IShape; + +import javafx.scene.Node; + +/** + *

+ * 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 children; + + /** */ + private Map, List> attachments; + + /** */ + private Map properties; + + /** */ + private boolean visible; + + /** */ + private INode parent; + + /** */ + private String name; + + /** + * + */ + public void addChild(INode node) { + checkNode(node); + + if (children == null) { + children = new ArrayList<>(); + } + + children.add(node); + + node.setParent(this); + } + + /** + * + */ + public void removeChild(INode node) { + if (children == null) { + return; + } + + if (!children.contains(node)) { + return; + } + + checkNode(node); + + children.remove(node); + + node.setParent(null); + } + + public void removeAllChildren() { + if (children == null) { + return; + } + + children.clear(); + } + + public List getChildren(boolean copy) { + if (children == null) { + return Collections.emptyList(); + } + + if (copy) { + return new ArrayList(children); + } else { + return children; + } + } + + public void attach(IAttachment attachment) { + if (attachments == null) { + attachments = new HashMap<>(); + } + + if (attachment == null) { + throw new IllegalArgumentException("Null attachment."); + } + + Class attachmentClazz = attachment.getClass(); + + List currentAttachmentList = attachments.get(attachment.getClass()); + + if (currentAttachmentList == null) { + currentAttachmentList = new ArrayList<>(); + currentAttachmentList.add(attachment); + attachments.put(attachmentClazz, currentAttachmentList); + return; + } + + if (attachment.isSingleton() && hasAttachment(attachment.getClass())) { + IAttachment existingSingleton = currentAttachmentList.get(0); + existingSingleton.detach(this); + currentAttachmentList.clear(); + } + + currentAttachmentList.add(attachment); + + attachment.attach(this); + } + + public void detach(IAttachment attachment) { + if (attachments == null) { + return; + } + + attachment.detach(this); + } + + public boolean hasAttachment(Class attachmentClazz) { + if (attachmentClazz == null) { + return false; + } + + if (attachments.containsKey(attachmentClazz)) { + List list = attachments.get(attachmentClazz); + + if (list == null || list.isEmpty()) { + return false; + } else { + return true; + } + } + + return false; + } + + /** + * + */ + public boolean supports(IAttachment attachment) { + return true; + } + + /** + * + */ + public Map, List> getAttachments() { + return attachments; + } + + /** + * + */ + public List getAttachments(Class clazz) { + return attachments.get(clazz); + } + + /** + * + */ + public Map getProperties() { + if (properties == null) { + return Collections.emptyMap(); + } + + return properties; + } + + /** + * + */ + public Object getProperty(String key) { + if (properties == null) { + return null; + } + + return properties.get(key); + } + + /** + * + */ + public void setProperty(String key, Object value) { + if (properties == null) { + properties = new HashMap<>(); + } + + properties.put(key, value); + } + + /** + * + */ + public boolean hasProperty(String key) { + return properties.containsKey(key); + } + + /** + * + * @param node + */ + protected void checkNode(INode node) { + } + + /** + * + */ + @Override + public boolean isVisible() { + return visible; + } + + /** + * + */ + @Override + public void setVisible(boolean visible) { + this.visible = visible; + } + + /** + * + * @return + */ + public INode getParent() { + return parent; + } + + /** + * + * @return + */ + public void setParent(INode parent) { + this.parent = parent; + } + + /** + * + * @param name + */ + public void setName(String name) { + this.name = name; + } + + /** + * + */ + public String getName() { + return name; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GScene.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GScene.java new file mode 100644 index 0000000000000000000000000000000000000000..f6052cb653126d2b474075e35a15a39d490a052d --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GScene.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * 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.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.ice.viz.service.geometry.scene.model.INode; +import org.eclipse.ice.viz.service.geometry.scene.model.IScene; + +/** + *

+ * Base impl for IScene. + *

+ * + * @author Tony McCrary (tmccrary@l33tlabs.com) + * + */ +public abstract class GScene implements IScene { + + /** */ + private INode root; + + /** */ + private Map cameras; + + /** */ + private Map nodes; + + /** */ + private List geometry; + + /** + * @see IScene#getRoot() + */ + public INode getRoot() { + return root; + } + + /** + * @see IScene#getCameras() + */ + public Map getCameras() { + if (cameras == null) { + return Collections.emptyMap(); + } + + return cameras; + } + + /** + * @see IScene#getNodes() + */ + public Map getNodes() { + if (nodes == null) { + return Collections.emptyMap(); + } + + return nodes; + } + + /** + * @see IScene#getGeometry() + */ + public List getGeometry() { + if (geometry == null) { + return Collections.emptyList(); + } + + return geometry; + } + + public void setRoot(INode root) { + this.root = root; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GeometryAttachment.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GeometryAttachment.java new file mode 100644 index 0000000000000000000000000000000000000000..6dff81136f843b836fe44f5d2132ab5396a85734 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/GeometryAttachment.java @@ -0,0 +1,261 @@ +/******************************************************************************* + * 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.List; + +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.geometry.shapes.Geometry; +import org.eclipse.ice.viz.service.geometry.shapes.IShape; + +/** + *

+ * 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 queuedGeometry; + + /** List of shapes that have been added via Geometry instances. */ + private List shapes; + + /** */ + private boolean visible; + + /** */ + private boolean enabled; + + /** */ + private boolean immutable; + + /** */ + protected Geometry currentGeom = null; + + /** + * + * @param node + */ + protected void checkNode(INode node) { + } + + /** + * + * @param shape + */ + protected void checkMesh(IShape shape) { + } + + /** + * @see IGeometry#addGeometry(Geometry) + */ + public void addGeometry(Geometry geom) { + if (geom == null) { + return; + } + + if (currentGeom == geom) { + return; + } else { + currentGeom = geom; + } + + if (owner == null) { + if (queuedGeometry == null) { + queuedGeometry = new ArrayList<>(); + } + + queuedGeometry.add(geom); + + return; + } + + } + + /** + * @see IGeometry#addShape(Geometry) + */ + public void addShape(IShape shape) { + checkMesh(shape); + + if (shapes == null) { + shapes = new ArrayList<>(); + } + + shapes.add(shape); + + processShape(shape); + } + + /** + * @see IAttachment#attach(INode) + */ + @Override + public void attach(INode owner) { + super.attach(owner); + + if (queuedGeometry == null) { + return; + } + + for (Geometry geom : queuedGeometry) { + for (IShape shape : geom.getShapes()) { + addShape(shape); + } + } + + queuedGeometry.clear(); + } + + /** + * @see IAttachment#detach(INode) + */ + @Override + public void detach(INode owner) { + super.detach(owner); + + if (shapes != null) { + shapes.clear(); + } + + if (queuedGeometry != null) { + queuedGeometry.clear(); + } + } + + /** + *

+ * 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 getShapes(boolean copy) { + if (shapes == null) { + return Collections.emptyList(); + } + + if (copy) { + return new ArrayList(shapes); + } else { + return shapes; + } + } + + /** + * + */ + public void clearShapes() { + if (shapes == null) { + return; + } + + shapes.clear(); + } + + /** + */ + @Override + public void setVisible(boolean visible) { + this.visible = visible; + } + + /** + * + */ + @Override + public boolean isVisible() { + return visible; + } + + /** + * + * @return + */ + @Override + public boolean isImmutable() { + return immutable; + } + + /** + * + * @return + */ + @Override + public void setImmutable(boolean immutable) { + this.immutable = immutable; + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ICamera.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ICamera.java new file mode 100644 index 0000000000000000000000000000000000000000..906183bb6263c7054b97a290f345a64f53f1e467 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/scene/base/ICamera.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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; + +/** + *

+ * 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 getShapes(boolean copy); + + /** + *

+ * 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 getChildren(boolean copy); + + /** + *

+ * 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, List> getAttachments(); + + /** + *

+ * 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 getAttachments(Class clazz); + + /** + *

+ * Returns a Map of the node's current properties. + *

+ * + * @return a Map of the node's current properties. + */ + public Map getProperties(); + + /** + *

+ * 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 getCameras(); + + /** + *

+ * Returns a Map of all the INode instances in the scene. + *

+ * + * @return a Map of all the INode instances in the scene. + */ + public Map getNodes(); + + /** + *

+ * 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 getGeometry(); + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/AbstractShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/AbstractShape.java index dd621a2075adc786a29f969d61e1e5845f9b7601..4bebdeeebf844213ec3d4c8ef39310fdecb6e5d8 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/AbstractShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/shapes/AbstractShape.java @@ -34,420 +34,427 @@ import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListen @XmlSeeAlso({ PrimitiveShape.class, ComplexShape.class }) @XmlAccessorType(XmlAccessType.FIELD) public abstract class AbstractShape extends VizObject implements IShape { - /** - *

- * Stores the list of keys for the property list - *

- * - */ - @XmlElement(name = "Keys") - private ArrayList keys; - /** - *

- * Stores the list of values for the property list - *

- * - */ - @XmlElement(name = "Values") - private ArrayList values; - /** - *

- * 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(); - values = new ArrayList(); - - // Create listeners list - listeners = 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 keys; + /** + *

+ * Stores the list of values for the property list + *

+ * + */ + @XmlElement(name = "Values") + private ArrayList values; + /** + *

+ * 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(); + values = new ArrayList(); + + // Create listeners list + listeners = 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 shapes; - - /** - *

- * 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 getShapes() { - - // Return a reference to the shapes array - return shapes; - - } - - /** - *

- * 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 shapes) { - - // Check that the new shapes list is not null - if (shapes == null) { - return; - } - // Remove the parents from all existing children - for (IShape shape : shapes) { - ((AbstractShape) shape).setParent(null); - } - - // Set the shapes list to the same reference as shapes - this.shapes = shapes; - - // Set the parent for each of the new children - for (IShape shape : shapes) { - ((AbstractShape) shape).setParent(this); - } - - // Notify listeners - notifyListeners(); - - } - - /** - *

- * 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 shapes; + + /** + *

+ * 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 getShapes() { + + // Return a reference to the shapes array + return shapes; + + } + + /** + *

+ * 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 shapes) { + + // Check that the new shapes list is not null + if (shapes == null) { + return; + } + // Remove the parents from all existing children + for (IShape shape : shapes) { + ((AbstractShape) shape).setParent(null); + } + + // Set the shapes list to the same reference as shapes + this.shapes = shapes; + + // Set the parent for each of the new children + for (IShape shape : shapes) { + ((AbstractShape) shape).setParent(this); + } + + // Notify listeners + notifyListeners(); + + } + + /** + *

+ * 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 shapes; - - /** - * The list of objects registered as listeners to this one. - */ - @XmlTransient - private ArrayList listeners; - - /** - * The IUpdateable description - */ - String description; - - /** - * The IUpdateable ID - */ - int id; - - /** - * The IUpdateable name - */ - String name; - - /** - *

- * Creates empty lists of IShapes and IUpdateableListeners - *

- * - */ - public Geometry() { - // Create new shapes and listeners lists - shapes = new ArrayList(); - - listeners = 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 getShapes() { - - // Simply return a reference to the shapes list - return this.shapes; - - } - - /** - * - * @param shapes - *

- * The shapes list to replace the existing shapes list - *

- */ - public void setShapes(ArrayList shapes) { - - // If null, quietly fail - if (shapes == null) { - return; - } - - // Tracks whether the parent component needs to be alerted to a change - boolean updateComponent = false; - - // If shapes were already present, there has been a change - if (shapes.size() > 0) { - updateComponent = true; - } - - // Replace the reference to the shapes list - this.shapes = shapes; - - for (IShape shape : shapes) { - shape.register(this); - - // 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 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 shapes; + + /** + * The list of objects registered as listeners to this one. + */ + @XmlTransient + private ArrayList listeners; + + /** + * The IUpdateable description + */ + String description; + + /** + * The IUpdateable ID + */ + int id; + + /** + * The IUpdateable name + */ + String name; + + /** + *

+ * Creates empty lists of IShapes and IUpdateableListeners + *

+ * + */ + public Geometry() { + // Create new shapes and listeners lists + shapes = new ArrayList(); + + listeners = 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 getShapes() { + + // Simply return a reference to the shapes list + return this.shapes; + + } + + /** + * + * @param shapes + *

+ * The shapes list to replace the existing shapes list + *

+ */ + public void setShapes(ArrayList shapes) { + + // If null, quietly fail + if (shapes == null) { + return; + } + + // Tracks whether the parent component needs to be alerted to a change + boolean updateComponent = false; + + // If shapes were already present, there has been a change + if (shapes.size() > 0) { + updateComponent = true; + } + + // Replace the reference to the shapes list + this.shapes = shapes; + + for (IShape shape : shapes) { + shape.register(this); + + // 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 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 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 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 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 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, IAttachmentManager> attachmentMgr; + + /** + * @see IRenderer#supportsAttachment(Class) + */ + public boolean supportsAttachment(Class clazz) { + if (attachmentMgr == null) { + return false; + } + + return attachmentMgr.containsKey(clazz); + } + + /** + * @see IRenderer#createAttachment(Class) + */ + public IAttachment createAttachment(Class clazz) { + if (attachmentMgr == null) { + attachmentMgr = new HashMap<>(); + } + + IAttachmentManager attachManagerInst = attachmentMgr.get(clazz); + + if (attachManagerInst == null) { + return null; + } + + IAttachment allocation = attachManagerInst.allocate(); + + return allocation; + } + + /** + * @see IRenderer#register(Class, IAttachmentManager) + */ + @Override + public void register(Class type, IAttachmentManager mgr) { + if (attachmentMgr == null) { + attachmentMgr = new HashMap<>(); + } + + attachmentMgr.put(type, mgr); + } + + /** + * @see IRenderer#unregister(Class) + */ + @Override + public void unregister(Class type) { + if (attachmentMgr == null) { + return; + } + + attachmentMgr.remove(type); + } + +} diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/messages.properties b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/messages.properties new file mode 100644 index 0000000000000000000000000000000000000000..1e0643dc0a2257b3e66ef48c33c1fae15d930c98 --- /dev/null +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/viewer/messages.properties @@ -0,0 +1 @@ +GeometryViewer_InvalidInput=GeometryViewer requires a root INode input object. diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionAddShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionAddShape.java index 2be86c8b0cc1dc09010ec8782e577b6065ace657..c8adec06aba62e4004ef20c0feca8d0f126fc9f8 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionAddShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionAddShape.java @@ -40,285 +40,282 @@ import org.osgi.framework.FrameworkUtil; * @author Andrew P. Belt */ public class ActionAddShape extends Action { - /** - *

- * 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 shapeIcons = new HashMap(); - shapeIcons.put(ShapeType.Sphere, "sphere.gif"); - shapeIcons.put(ShapeType.Cube, "cube.gif"); - shapeIcons.put(ShapeType.Cylinder, "cylinder.gif"); - shapeIcons.put(ShapeType.Tube, "tube.gif"); - - // Create the image descriptor from the file path - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, - "icons/" + shapeIcons.get(shapeType)); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); - - return; - } - - /** - *

- * 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 operatorIcons = new HashMap(); - operatorIcons.put(OperatorType.Union, "union.gif"); - operatorIcons.put(OperatorType.Intersection, "intersection.gif"); - operatorIcons.put(OperatorType.Complement, "complement.gif"); - - // Create the image descriptor from the file path - - Bundle bundle = FrameworkUtil.getBundle(getClass()); - URL imagePath = BundleUtility.find(bundle, - "icons/" + operatorIcons.get(operatorType)); - imageDescriptor = ImageDescriptor.createFromURL(imagePath); - - } - - /** - *

- * 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 shapeIcons = new HashMap(); + shapeIcons.put(ShapeType.Sphere, "sphere.gif"); + shapeIcons.put(ShapeType.Cube, "cube.gif"); + shapeIcons.put(ShapeType.Cylinder, "cylinder.gif"); + shapeIcons.put(ShapeType.Tube, "tube.gif"); + + // Create the image descriptor from the file path + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, "icons/" + shapeIcons.get(shapeType)); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); + + return; + } + + /** + *

+ * 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 operatorIcons = new HashMap(); + operatorIcons.put(OperatorType.Union, "union.gif"); + operatorIcons.put(OperatorType.Intersection, "intersection.gif"); + operatorIcons.put(OperatorType.Complement, "complement.gif"); + + // Create the image descriptor from the file path + + Bundle bundle = FrameworkUtil.getBundle(getClass()); + URL imagePath = BundleUtility.find(bundle, "icons/" + operatorIcons.get(operatorType)); + imageDescriptor = ImageDescriptor.createFromURL(imagePath); + + } + + /** + *

+ * 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 childShapes = parentShape.getShapes(); - int selectedShapeIndex = childShapes.indexOf(selectedShape); + ArrayList childShapes = parentShape.getShapes(); + int selectedShapeIndex = childShapes.indexOf(selectedShape); - if (selectedShapeIndex < 0) { - continue; - } - // Add the cloned shape to the original shape's parent + if (selectedShapeIndex < 0) { + continue; + } + // Add the cloned shape to the original shape's parent - synchronized (geometry) { - childShapes.add(selectedShapeIndex + 1, clonedShape); - parentShape.setShapes(childShapes); - } + synchronized (geometry) { + childShapes.add(selectedShapeIndex + 1, clonedShape); + parentShape.setShapes(childShapes); + } - view.treeViewer.refresh(parentShape); - } else { + view.treeViewer.refresh(parentShape); + } else { - // 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 childShapes = geometry.getShapes(); - int selectedShapeIndex = childShapes.indexOf(selectedShape); + ArrayList childShapes = geometry.getShapes(); + int selectedShapeIndex = childShapes.indexOf(selectedShape); - // Add the cloned shape to the root GeometryComponent + // Add the cloned shape to the root GeometryComponent - synchronized (geometry) { - childShapes.add(selectedShapeIndex + 1, clonedShape); - geometry.setShapes(childShapes); - } + synchronized (geometry) { + childShapes.add(selectedShapeIndex + 1, clonedShape); + geometry.setShapes(childShapes); + } - view.treeViewer.refresh(); - } + view.treeViewer.refresh(); + } - // Collapse the cloned item and select it + // Collapse the cloned item and select it - view.treeViewer.collapseToLevel(clonedShape, 0); + view.treeViewer.collapseToLevel(clonedShape, 0); - // Change the current selection to the new duplicated shape + // Change the current selection to the new duplicated shape - TreePath clonedPath = path.getParentPath().createChildPath( - clonedShape); - TreeSelection clonedSelection = new TreeSelection(clonedPath); - view.treeViewer.setSelection(clonedSelection); - } - } + TreePath clonedPath = path.getParentPath().createChildPath(clonedShape); + TreeSelection clonedSelection = new TreeSelection(clonedPath); + view.treeViewer.setSelection(clonedSelection); + } + } - } + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionReplicateShape.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionReplicateShape.java index 13a7860cfe41895c87da3d2f373f1b076b1912d8..63224bd26eb59e72b33d940b4fd8a7cb582f5a9b 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionReplicateShape.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ActionReplicateShape.java @@ -41,172 +41,165 @@ import org.osgi.framework.FrameworkUtil; * @author Andrew P. Belt */ public class ActionReplicateShape extends Action { - /** - *

- * 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 childActions = new ArrayList(); - - /** - * The image descriptor associated with the duplicate action's icon - */ - private ImageDescriptor imageDescriptor; - - /** - *

- * 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 childActions = new ArrayList(); + + /** + * The image descriptor associated with the duplicate action's icon + */ + private ImageDescriptor imageDescriptor; + + /** + *

+ * 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 listeners = new ArrayList(); + /** + * The listeners to be notified of changes to the value + */ + private List listeners = new ArrayList(); - /** - *

- * 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 = ""; - - /** - * The shape which "contains" this blank shape object - */ - private IShape parent; - - /** - * Initializes the BlankShape with a parent - * - * @param parent - * The parent shape in the TreeViewer hierarchy - */ - public BlankShape(IShape parent) { - this.parent = parent; - } - - /** - * Returns the parent of this BlankShape - * - * @return The parent shape - */ - public IShape getParent() { - return parent; - } - } - - /** - * (non-Javadoc) - * - * @see IShapeVisitor#visit(ComplexShape complexShape) - */ - @Override - public void visit(ComplexShape complexShape) { - - // IShape is a ComplexShape, so put its children in the temporary - // children field - - temporaryChildren = complexShape.getShapes().toArray(); - - // Use a blank state if there are no children to display - - if (temporaryChildren.length == 0) { - temporaryChildren = new Object[] { new BlankShape(complexShape) }; - } - - } - - /** - * (non-Javadoc) - * - * @see IShapeVisitor#visit(PrimitiveShape primitiveShape) - */ - @Override - public void visit(PrimitiveShape primitiveShape) { - - // IShape is a PrimitiveShape, so it has no children :( - - temporaryChildren = new Object[0]; - - } +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 = ""; + + /** + * The shape which "contains" this blank shape object + */ + private IShape parent; + + /** + * Initializes the BlankShape with a parent + * + * @param parent + * The parent shape in the TreeViewer hierarchy + */ + public BlankShape(IShape parent) { + this.parent = parent; + } + + /** + * Returns the parent of this BlankShape + * + * @return The parent shape + */ + public IShape getParent() { + return parent; + } + } + + /** + * (non-Javadoc) + * + * @see IShapeVisitor#visit(ComplexShape complexShape) + */ + @Override + public void visit(ComplexShape complexShape) { + + // IShape is a ComplexShape, so put its children in the temporary + // children field + + temporaryChildren = complexShape.getShapes().toArray(); + + // Use a blank state if there are no children to display + + if (temporaryChildren.length == 0) { + temporaryChildren = new Object[] { new BlankShape(complexShape) }; + } + + } + + /** + * (non-Javadoc) + * + * @see IShapeVisitor#visit(PrimitiveShape primitiveShape) + */ + @Override + public void visit(PrimitiveShape primitiveShape) { + + // IShape is a PrimitiveShape, so it has no children :( + + temporaryChildren = new Object[0]; + + } } \ No newline at end of file diff --git a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDragListener.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDragListener.java index 1417d66281751b85e66df83bcbe3133b55bcc899..63762590657131a1cdfcf9d273dbb56dddd7d430 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDragListener.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDragListener.java @@ -21,30 +21,30 @@ package org.eclipse.ice.viz.service.geometry.widgets; * @author Jay Jay Billings */ public class ShapeTreeDragListener { - /** - * - * @param event - */ - public void dragFinished(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragFinished(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dragSetData(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragSetData(Class event) { + // TODO Auto-generated method stub - } + } - /** - * - * @param event - */ - public void dragStart(Class event) { - // TODO Auto-generated method stub + /** + * + * @param event + */ + public void dragStart(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/ShapeTreeDropListener.java b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDropListener.java index b340c831f1eac70162c949b60ee6c7152349ac22..cd12f560db83ed56e54409e28db2b00166443ff6 100644 --- a/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDropListener.java +++ b/org.eclipse.ice.viz.service.geometry/src/org/eclipse/ice/viz/service/geometry/widgets/ShapeTreeDropListener.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.ice.viz.service.geometry.widgets; - /** *

* 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 selectedShapes = new 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 selectedShapes = new 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 selectedShapes = new ArrayList(); + /** + * A list of shapes of the last selection event + */ + private ArrayList selectedShapes = new ArrayList(); - // The actions for manipulating shapes - private DropdownAction addPrimitiveShapes; - private DropdownAction addComplexShapes; - private Action duplicateShapes; - private Action replicateShapes; - private Action deleteShape; + // The actions for manipulating shapes + private DropdownAction addPrimitiveShapes; + private DropdownAction addComplexShapes; + private Action duplicateShapes; + private Action replicateShapes; + private Action deleteShape; - /** - *

- * 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 @@ org.eclipse.ice.viz.service org.eclipse.ice.viz.service.test org.eclipse.ice.viz.service.geometry + org.eclipse.ice.viz.service.geometry.javafx org.eclipse.ice.viz.service.geometry.test org.eclipse.ice.viz.service.jme3 org.eclipse.ice.viz.service.jme3.test