]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGparentNode.java
Remove listener calls when property values not updated.
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / scenegraph2 / CSGparentNode.java
index dcc564ab0abfe318f3006a5e8181520f724013f7..46610414f8c6ab4a061f6a08ab54ffab60caf870 100644 (file)
-package org.simantics.g3d.csg.scenegraph2;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-\r
-import javax.vecmath.AxisAngle4d;\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.jcae.opencascade.jni.TopoDS_Shape;\r
-import org.simantics.g3d.csg.ontology.CSG;\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.g3d.ontology.G3D;\r
-import org.simantics.g3d.property.annotations.GetPropertyValue;\r
-import org.simantics.g3d.property.annotations.PropertyContributor;\r
-import org.simantics.g3d.property.annotations.SetPropertyValue;\r
-import org.simantics.g3d.scenegraph.IG3DNode;\r
-import org.simantics.g3d.scenegraph.base.ParentNode;\r
-import org.simantics.g3d.tools.NodeTools;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.objmap.graph.annotations.RelatedElementsAdd;\r
-import org.simantics.objmap.graph.annotations.RelatedElementsGet;\r
-import org.simantics.objmap.graph.annotations.RelatedElementsRem;\r
-import org.simantics.objmap.graph.annotations.RelatedGetValue;\r
-import org.simantics.objmap.graph.annotations.RelatedSetValue;\r
-import org.simantics.opencascade.OccTriangulator;\r
-import org.simantics.opencascade.vtk.vtkSolidObject;\r
-import org.simantics.utils.threads.AWTThread;\r
-\r
-import vtk.vtkPanel;\r
-import vtk.vtkProp3D;\r
-\r
-@PropertyContributor\r
-public abstract class CSGparentNode extends ParentNode<ICSGnode> implements ICSGnode {\r
-\r
-       private String name;\r
-       \r
-\r
-       @RelatedGetValue(Layer0.URIs.HasName)\r
-       @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name")\r
-       public String getName() {\r
-               return name;\r
-       }\r
-       \r
-       @RelatedSetValue(Layer0.URIs.HasName)\r
-       @SetPropertyValue(Layer0.URIs.HasName)\r
-       public void setName(String name) {\r
-               if (name == null)\r
-                       return;\r
-               this.name = name;\r
-               firePropertyChanged(Layer0.URIs.HasName);\r
-       }\r
-       \r
-       @Override\r
-       public String toString() {\r
-               return getName();\r
-       }\r
-       \r
-       private Vector3d position = new Vector3d();\r
-       private Quat4d orientation = MathTools.getIdentityQuat();\r
-       \r
-       @Override\r
-       @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")\r
-       public Quat4d getOrientation() {\r
-               return orientation;\r
-       }\r
-       \r
-       @RelatedGetValue(G3D.URIs.hasOrientation)\r
-       public double[] getOrientationArr() {\r
-               double arr[] = new double[4];\r
-               orientation.get(arr);\r
-               return arr;\r
-               \r
-       }\r
-       \r
-       @Override\r
-       @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")\r
-       public Vector3d getPosition() {\r
-               return position;\r
-       }\r
-       \r
-       @RelatedGetValue(G3D.URIs.hasPosition)\r
-       public double[] getPositionArr() {\r
-               double arr[] = new double[3];\r
-               position.get(arr);\r
-               return arr;\r
-       }\r
-       \r
-       @RelatedElementsAdd(CSG.URIs.hasPrimaryShape)\r
-       public void addPrimaryChild(ICSGnode node) {\r
-               addNode("primary",node);\r
-       }\r
-       \r
-       @RelatedElementsGet(CSG.URIs.hasPrimaryShape)\r
-       public Collection<ICSGnode> getPrimaryChild() {\r
-               return getNodes("primary");\r
-       }\r
-       \r
-       @RelatedElementsRem(CSG.URIs.hasPrimaryShape)\r
-       public void remPrimaryChild(ICSGnode node) {\r
-               removeNode("primary", node);\r
-       }\r
-       \r
-       @RelatedElementsAdd(CSG.URIs.hasSecondaryShape)\r
-       public void addSecondaryChild(ICSGnode node) {\r
-               addNode("secondary",node);\r
-       }\r
-       \r
-       @RelatedElementsGet(CSG.URIs.hasSecondaryShape)\r
-       public Collection<ICSGnode> getSecondaryChild() {\r
-               return getNodes("secondary");\r
-       }\r
-       \r
-       @RelatedElementsRem(CSG.URIs.hasSecondaryShape)\r
-       public void remSecondaryChild(ICSGnode node) {\r
-               removeNode("secondary", node);\r
-       }\r
-       \r
-\r
-       @RelatedElementsAdd(CSG.URIs.hasChildShape)\r
-       public void addChild(ICSGnode node) {\r
-               addNode("child",node);\r
-       }\r
-       \r
-       @RelatedElementsGet(CSG.URIs.hasChildShape)\r
-       public Collection<ICSGnode> getChild() {\r
-               return getNodes("child");\r
-       }\r
-       \r
-       @RelatedElementsRem(CSG.URIs.hasChildShape)\r
-       public void remChild(ICSGnode node) {\r
-               removeNode("child", node);\r
-       }\r
-       \r
-       \r
-       \r
-       protected TopoDS_Shape getPrimary() {\r
-               for (ICSGnode node : getNodes("primary"))\r
-                       return node.getGeometry();\r
-               return null;\r
-       }\r
-       \r
-       protected TopoDS_Shape getSecondary() {\r
-               for (ICSGnode node : getNodes("secondary"))\r
-                       return node.getGeometry();\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public TopoDS_Shape getGeometry() {\r
-               TopoDS_Shape shape = getBaseGeometry();\r
-               if (shape == null)\r
-                       return null;\r
-               Quat4d q = getOrientation();\r
-               AxisAngle4d r = new AxisAngle4d();\r
-               r.set(q);\r
-               TopoDS_Shape tshape = OccTriangulator.makeRotation(shape, new double[] { 0.0, 0.0, 0.0, r.x, r.y, r.z }, r.angle);\r
-               shape.delete();\r
-               shape = tshape;\r
-               Vector3d p = getPosition();\r
-               tshape = OccTriangulator.makeTranslation(shape, p.x, p.y, p.z);\r
-               shape.delete();\r
-               return tshape;\r
-                       \r
-       }\r
-       \r
-\r
-       \r
-       @Override\r
-       @SetPropertyValue(G3D.URIs.hasOrientation)\r
-       public void setOrientation(Quat4d orientation) {\r
-               assert(orientation != null);\r
-               this.orientation = orientation;\r
-               \r
-               firePropertyChanged(G3D.URIs.hasOrientation);\r
-       }\r
-       \r
-       @Override\r
-       @SetPropertyValue(G3D.URIs.hasPosition)\r
-       public void setPosition(Vector3d position) {\r
-               assert(position != null);\r
-               this.position = position;\r
-               \r
-               firePropertyChanged(G3D.URIs.hasPosition);\r
-       }\r
-       \r
-       @RelatedSetValue(G3D.URIs.hasOrientation)\r
-       public void setOrientation(double[] arr) {\r
-               if (arr == null)\r
-                       return;\r
-               setOrientation(new Quat4d(arr));\r
-       }\r
-       \r
-       @RelatedSetValue(G3D.URIs.hasPosition)\r
-       public void setPosition(double[] arr) {\r
-               if (arr == null)\r
-                       return;\r
-               setPosition(new Vector3d(arr));\r
-       }\r
-       \r
-       @Override\r
-       @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")\r
-       public Vector3d getWorldPosition() {\r
-               IG3DNode parent = (IG3DNode) getParent();\r
-               if (parent == null)\r
-                       return position;\r
-               return NodeTools.getWorldPosition(parent, new Vector3d(position));\r
-       }\r
-\r
-       public Vector3d getWorldPosition(Vector3d localPosition) {\r
-               return NodeTools.getWorldPosition(this, localPosition);\r
-       }\r
-\r
-       \r
-       @Override\r
-       @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")\r
-       public Quat4d getWorldOrientation() {\r
-               return getWorldOrientation(new Quat4d(orientation));\r
-       }\r
-       \r
-       public Quat4d getWorldOrientation(Quat4d localOrientation) {\r
-               IG3DNode parent = (IG3DNode)getParent();\r
-               if (parent == null)\r
-                       return localOrientation;\r
-               return NodeTools.getWorldOrientation(parent, localOrientation);\r
-       }\r
-       \r
-       @Override\r
-       public Vector3d getLocalPosition(Vector3d worldPosition) {\r
-               IG3DNode parent = (IG3DNode)getParent();\r
-               if (parent == null)\r
-                       return worldPosition;\r
-               return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));\r
-       }\r
-       \r
-       @Override\r
-       public Quat4d getLocalOrientation(Quat4d worldOrientation) {\r
-               IG3DNode parent = (IG3DNode)getParent();\r
-               if (parent == null)\r
-                       return worldOrientation;\r
-               return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));\r
-       }\r
-       \r
-       @Override\r
-       @SetPropertyValue(G3D.URIs.hasWorldPosition)\r
-       public void setWorldPosition(Vector3d position) {\r
-               Vector3d localPos = getLocalPosition(position);\r
-               setPosition(localPos);\r
-       }\r
-       \r
-       @Override\r
-       @SetPropertyValue(G3D.URIs.hasWorldOrientation)\r
-       public void setWorldOrientation(Quat4d orientation) {\r
-               Quat4d localOr = getLocalOrientation(orientation);\r
-               setOrientation(localOr);\r
-       }\r
-\r
-\r
-       private vtkSolidObject solidObject;\r
-       \r
-       \r
-       public void visualize(vtkPanel panel) {\r
-               if (solidObject != null) {\r
-                       solidObject.delete();\r
-                       solidObject = null;\r
-               }\r
-               TopoDS_Shape shape = getGeometry();\r
-               if (shape == null)\r
-                       return;\r
-               solidObject = new vtkSolidObject(panel, shape);\r
-               solidObject.visualizeSolid(true, false);\r
-       }\r
-       \r
-       @SuppressWarnings("unchecked")\r
-       public Collection<vtkProp3D> getActors() {\r
-               if (solidObject == null)\r
-                       return Collections.EMPTY_LIST;\r
-               return solidObject.getActors();\r
-       }\r
-       \r
-       public void stopVisualize() {\r
-               if (solidObject != null) {\r
-                       if (Thread.currentThread() == AWTThread.getThreadAccess().getThread())\r
-                               solidObject.delete();\r
-                       else\r
-                               solidObject.dispose();\r
-                       solidObject = null;\r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public void cleanup() {\r
-               stopVisualize();\r
-               super.cleanup();\r
-       }\r
-       \r
-       \r
-       @Override\r
-       public void remove() {\r
-               //FIXME: creating boolean shapes (removing nodes from parent and attaching under boolean shape would destroy the existing hierarchy, if default implementation is used.\r
-               super.remove();\r
-       }\r
-\r
-       @Override\r
-       public Object getAdapter(Class adapter) {\r
-               return null;\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.csg.scenegraph2;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.vecmath.AxisAngle4d;
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+import org.jcae.opencascade.jni.TopoDS_Shape;
+import org.simantics.g3d.csg.ontology.CSG;
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.ontology.G3D;
+import org.simantics.g3d.property.annotations.GetPropertyValue;
+import org.simantics.g3d.property.annotations.PropertyContributor;
+import org.simantics.g3d.property.annotations.SetPropertyValue;
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.scenegraph.base.ParentNode;
+import org.simantics.g3d.tools.NodeTools;
+import org.simantics.g3d.vtk.common.VtkView;
+import org.simantics.layer0.Layer0;
+import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
+import org.simantics.objmap.graph.annotations.RelatedElementsGet;
+import org.simantics.objmap.graph.annotations.RelatedElementsRem;
+import org.simantics.objmap.graph.annotations.RelatedGetValue;
+import org.simantics.objmap.graph.annotations.RelatedSetValue;
+import org.simantics.opencascade.OccTriangulator;
+import org.simantics.opencascade.vtk.vtkSolidObject;
+import org.simantics.utils.threads.AWTThread;
+
+import vtk.vtkProp3D;
+
+@PropertyContributor
+public abstract class CSGparentNode extends ParentNode<ICSGnode> implements ICSGnode {
+
+       private String name;
+       
+
+       @RelatedGetValue(Layer0.URIs.HasName)
+       @GetPropertyValue(value = Layer0.URIs.HasName, tabId = "Default", name = "Name")
+       public String getName() {
+               return name;
+       }
+       
+       @RelatedSetValue(Layer0.URIs.HasName)
+       @SetPropertyValue(Layer0.URIs.HasName)
+       public void setName(String name) {
+               if (name == null || name.equals(this.name))
+                       return;
+               this.name = name;
+               firePropertyChanged(Layer0.URIs.HasName);
+       }
+       
+       @Override
+       public String toString() {
+               return getName();
+       }
+       
+       private Vector3d position = new Vector3d();
+       private Quat4d orientation = MathTools.getIdentityQuat();
+       
+       @Override
+       @GetPropertyValue(value = G3D.URIs.hasOrientation, tabId = "Transform", name = "Orientation")
+       public Quat4d getOrientation() {
+               return orientation;
+       }
+       
+       @RelatedGetValue(G3D.URIs.hasOrientation)
+       public double[] getOrientationArr() {
+               double arr[] = new double[4];
+               orientation.get(arr);
+               return arr;
+               
+       }
+       
+       @Override
+       @GetPropertyValue(value = G3D.URIs.hasPosition, tabId = "Transform", name = "Position")
+       public Vector3d getPosition() {
+               return position;
+       }
+       
+       @RelatedGetValue(G3D.URIs.hasPosition)
+       public double[] getPositionArr() {
+               double arr[] = new double[3];
+               position.get(arr);
+               return arr;
+       }
+       
+       @RelatedElementsAdd(CSG.URIs.hasPrimaryShape)
+       public void addPrimaryChild(ICSGnode node) {
+               addNode("primary",node);
+       }
+       
+       @RelatedElementsGet(CSG.URIs.hasPrimaryShape)
+       public Collection<ICSGnode> getPrimaryChild() {
+               return getNodes("primary");
+       }
+       
+       @RelatedElementsRem(CSG.URIs.hasPrimaryShape)
+       public void remPrimaryChild(ICSGnode node) {
+               removeNode("primary", node);
+       }
+       
+       @RelatedElementsAdd(CSG.URIs.hasSecondaryShape)
+       public void addSecondaryChild(ICSGnode node) {
+               addNode("secondary",node);
+       }
+       
+       @RelatedElementsGet(CSG.URIs.hasSecondaryShape)
+       public Collection<ICSGnode> getSecondaryChild() {
+               return getNodes("secondary");
+       }
+       
+       @RelatedElementsRem(CSG.URIs.hasSecondaryShape)
+       public void remSecondaryChild(ICSGnode node) {
+               removeNode("secondary", node);
+       }
+       
+
+       @RelatedElementsAdd(CSG.URIs.hasChildShape)
+       public void addChild(ICSGnode node) {
+               addNode("child",node);
+       }
+       
+       @RelatedElementsGet(CSG.URIs.hasChildShape)
+       public Collection<ICSGnode> getChild() {
+               return getNodes("child");
+       }
+       
+       @RelatedElementsRem(CSG.URIs.hasChildShape)
+       public void remChild(ICSGnode node) {
+               removeNode("child", node);
+       }
+       
+       
+       
+       protected TopoDS_Shape getPrimary() {
+               for (ICSGnode node : getNodes("primary"))
+                       return node.getGeometry();
+               return null;
+       }
+       
+       protected TopoDS_Shape getSecondary() {
+               for (ICSGnode node : getNodes("secondary"))
+                       return node.getGeometry();
+               return null;
+       }
+       
+       @Override
+       public TopoDS_Shape getGeometry() {
+               TopoDS_Shape shape = getBaseGeometry();
+               if (shape == null)
+                       return null;
+               Quat4d q = getOrientation();
+               AxisAngle4d r = new AxisAngle4d();
+               r.set(q);
+               TopoDS_Shape tshape = OccTriangulator.makeRotation(shape, new double[] { 0.0, 0.0, 0.0, r.x, r.y, r.z }, r.angle);
+               shape.delete();
+               shape = tshape;
+               Vector3d p = getPosition();
+               tshape = OccTriangulator.makeTranslation(shape, p.x, p.y, p.z);
+               shape.delete();
+               return tshape;
+                       
+       }
+       
+
+       
+       @Override
+       @SetPropertyValue(G3D.URIs.hasOrientation)
+       public void setOrientation(Quat4d orientation) {
+               assert(orientation != null);
+               if (Objects.equals(this.orientation, orientation))
+                       return;
+               
+               this.orientation = orientation;
+               
+               firePropertyChanged(G3D.URIs.hasOrientation);
+       }
+       
+       @Override
+       @SetPropertyValue(G3D.URIs.hasPosition)
+       public void setPosition(Vector3d position) {
+               assert(position != null);
+               if (Objects.equals(this.position, position))
+                       return;
+               
+               this.position = position;
+               
+               firePropertyChanged(G3D.URIs.hasPosition);
+       }
+       
+       @RelatedSetValue(G3D.URIs.hasOrientation)
+       public void setOrientation(double[] arr) {
+               if (arr == null)
+                       return;
+               setOrientation(new Quat4d(arr));
+       }
+       
+       @RelatedSetValue(G3D.URIs.hasPosition)
+       public void setPosition(double[] arr) {
+               if (arr == null)
+                       return;
+               setPosition(new Vector3d(arr));
+       }
+       
+       @Override
+       @GetPropertyValue(value = G3D.URIs.hasWorldPosition, tabId = "Transform", name = "World Position")
+       public Vector3d getWorldPosition() {
+               IG3DNode parent = (IG3DNode) getParent();
+               if (parent == null)
+                       return position;
+               return NodeTools.getWorldPosition(parent, new Vector3d(position));
+       }
+
+       public Vector3d getWorldPosition(Vector3d localPosition) {
+               return NodeTools.getWorldPosition(this, localPosition);
+       }
+
+       
+       @Override
+       @GetPropertyValue(value = G3D.URIs.hasWorldOrientation, tabId = "Transform", name = "World Orientation")
+       public Quat4d getWorldOrientation() {
+               return getWorldOrientation(new Quat4d(orientation));
+       }
+       
+       public Quat4d getWorldOrientation(Quat4d localOrientation) {
+               IG3DNode parent = (IG3DNode)getParent();
+               if (parent == null)
+                       return localOrientation;
+               return NodeTools.getWorldOrientation(parent, localOrientation);
+       }
+       
+       @Override
+       public Vector3d getLocalPosition(Vector3d worldPosition) {
+               IG3DNode parent = (IG3DNode)getParent();
+               if (parent == null)
+                       return worldPosition;
+               return NodeTools.getLocalPosition(parent,new Vector3d(worldPosition));
+       }
+       
+       @Override
+       public Quat4d getLocalOrientation(Quat4d worldOrientation) {
+               IG3DNode parent = (IG3DNode)getParent();
+               if (parent == null)
+                       return worldOrientation;
+               return NodeTools.getLocalOrientation(parent, new Quat4d(worldOrientation));
+       }
+       
+       @Override
+       @SetPropertyValue(G3D.URIs.hasWorldPosition)
+       public void setWorldPosition(Vector3d position) {
+               Vector3d localPos = getLocalPosition(position);
+               setPosition(localPos);
+       }
+       
+       @Override
+       @SetPropertyValue(G3D.URIs.hasWorldOrientation)
+       public void setWorldOrientation(Quat4d orientation) {
+               Quat4d localOr = getLocalOrientation(orientation);
+               setOrientation(localOr);
+       }
+
+
+       private vtkSolidObject solidObject;
+       
+       
+       public void visualize(VtkView panel) {
+               if (solidObject != null) {
+                       solidObject.delete();
+                       solidObject = null;
+               }
+               TopoDS_Shape shape = getGeometry();
+               if (shape == null)
+                       return;
+               solidObject = new vtkSolidObject(panel, shape);
+               solidObject.visualizeSolid(true, false);
+       }
+       
+       @SuppressWarnings("unchecked")
+       public Collection<vtkProp3D> getActors() {
+               if (solidObject == null)
+                       return Collections.EMPTY_LIST;
+               return solidObject.getActors();
+       }
+       
+       public void stopVisualize() {
+               if (solidObject != null) {
+                       if (Thread.currentThread() == AWTThread.getThreadAccess().getThread())
+                               solidObject.delete();
+                       else
+                               solidObject.dispose();
+                       solidObject = null;
+               }
+       }
+       
+       @Override
+       public void cleanup() {
+               stopVisualize();
+               super.cleanup();
+       }
+       
+       
+       @Override
+       public void remove() {
+               //FIXME: creating boolean shapes (removing nodes from parent and attaching under boolean shape would destroy the existing hierarchy, if default implementation is used.
+               super.remove();
+       }
+
+       @Override
+       public <C> C getAdapter(Class<C> adapter) {
+               return null;
+       }
+}