]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java
Adding exact INode type as generic parameter to NodeMap interface
[simantics/3d.git] / org.simantics.g3d.csg / src / org / simantics / g3d / csg / scenegraph2 / CSGrootNode.java
index 58db64e71ab2e2a9e7c9f19449911f6ecd7ea118..d88b42ed66adbc77863f986c094c93315e3a7d6e 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.csg.scenegraph2;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-import java.util.Stack;\r
-\r
-import javax.vecmath.Quat4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.csg.editor.CSGNodeMap;\r
-import org.simantics.g3d.csg.ontology.CSG;\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.g3d.scenegraph.IG3DNode;\r
-import org.simantics.g3d.scenegraph.NodeMap;\r
-import org.simantics.g3d.scenegraph.NodeMapProvider;\r
-import org.simantics.g3d.scenegraph.base.NodeException;\r
-import org.simantics.g3d.scenegraph.base.ParentNode;\r
-import org.simantics.objmap.graph.annotations.GraphType;\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
-\r
-import vtk.vtkProp;\r
-\r
-\r
-@GraphType(CSG.URIs.Model)\r
-public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<vtkProp> {\r
-       \r
-       \r
-       private CSGNodeMap nodeMap;\r
-       \r
-       public void setNodeMap(CSGNodeMap nodeMap) {\r
-               this.nodeMap = nodeMap;\r
-       }\r
-       \r
-       @Override\r
-       public NodeMap<vtkProp> getNodeMap() {\r
-               return nodeMap;\r
-       }\r
-       \r
-       @Override\r
-       public ParentNode<?> getParent() {\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public ParentNode<?> getRootNode() {\r
-               return this;\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
-       public javax.vecmath.Quat4d getOrientation() {\r
-               return MathTools.getIdentityQuat();\r
-       };\r
-       \r
-       @Override\r
-       public Vector3d getPosition() {\r
-               return new Vector3d();\r
-       }\r
-       \r
-       @Override\r
-       public Quat4d getWorldOrientation() {\r
-               return MathTools.getIdentityQuat();\r
-       }\r
-       \r
-       @Override\r
-       public Vector3d getWorldPosition() {\r
-               return new Vector3d();\r
-       }\r
-       \r
-       @Override\r
-       public Quat4d getWorldOrientation(Quat4d localOrientation) {\r
-               return localOrientation;\r
-       }\r
-       \r
-       @Override\r
-       public Vector3d getWorldPosition(Vector3d localPosition) {\r
-               return localPosition;\r
-       }\r
-       \r
-       @Override\r
-       public Quat4d getLocalOrientation(Quat4d worldOrientation) {\r
-               return worldOrientation;\r
-       }\r
-       \r
-       @Override\r
-       public Vector3d getLocalPosition(Vector3d worldPosition) {\r
-               return worldPosition;\r
-       }\r
-       \r
-       @Override\r
-       public void setPosition(Vector3d position) {\r
-               throw new NodeException("Cannot set root node position");\r
-       }\r
-       \r
-       @Override\r
-       public void setOrientation(Quat4d orientation) {\r
-               throw new NodeException("Cannot set root node orientation");\r
-       }\r
-       \r
-       @Override\r
-       public void setWorldOrientation(Quat4d orientation) {\r
-               throw new NodeException("Cannot set root node orientation");\r
-       }\r
-       \r
-       @Override\r
-       public void setWorldPosition(Vector3d position) {\r
-               throw new NodeException("Cannot set root node orientation");\r
-       }\r
-       \r
-       public String getUniqueName(String prefix) {\r
-               Set<String> names = new HashSet<String>();\r
-               Stack<ICSGnode> nodes = new Stack<ICSGnode>();\r
-               nodes.addAll(getChild());\r
-               while (!nodes.isEmpty()) {\r
-                       ICSGnode n = nodes.pop();\r
-                       names.add(((ICSGnode)n).getName());\r
-                       if (n instanceof CSGparentNode) {\r
-                               nodes.addAll(((CSGparentNode)n).getChild());\r
-                               nodes.addAll(((CSGparentNode)n).getPrimaryChild());\r
-                               nodes.addAll(((CSGparentNode)n).getSecondaryChild());\r
-                       }\r
-               }\r
-               int i = 1;\r
-               while (true) {\r
-                       String genName = prefix + "_" + i;\r
-                       if (!names.contains(genName))\r
-                               return genName;\r
-                       i++;\r
-               }\r
-       }\r
-       \r
-\r
-       @Override\r
-       public Object getAdapter(Class adapter) {\r
-               if (NodeMap.class == adapter)\r
-                       return nodeMap;\r
-               return null;\r
-       }\r
-       \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.HashSet;
+import java.util.Set;
+import java.util.Stack;
+
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.csg.editor.CSGNodeMap;
+import org.simantics.g3d.csg.ontology.CSG;
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.scenegraph.NodeMap;
+import org.simantics.g3d.scenegraph.NodeMapProvider;
+import org.simantics.g3d.scenegraph.base.NodeException;
+import org.simantics.g3d.scenegraph.base.ParentNode;
+import org.simantics.objmap.graph.annotations.GraphType;
+import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
+import org.simantics.objmap.graph.annotations.RelatedElementsGet;
+import org.simantics.objmap.graph.annotations.RelatedElementsRem;
+
+import vtk.vtkProp;
+
+
+@GraphType(CSG.URIs.Model)
+public class CSGrootNode extends ParentNode<ICSGnode> implements IG3DNode, NodeMapProvider<vtkProp, ICSGnode> {
+       
+       
+       private CSGNodeMap nodeMap;
+       
+       public void setNodeMap(CSGNodeMap nodeMap) {
+               this.nodeMap = nodeMap;
+       }
+       
+       @Override
+       public NodeMap<vtkProp, ICSGnode> getNodeMap() {
+               return nodeMap;
+       }
+       
+       @Override
+       public ParentNode<?> getParent() {
+               return null;
+       }
+       
+       @Override
+       public ParentNode<?> getRootNode() {
+               return this;
+       }
+       
+       @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);
+       }
+       
+       public javax.vecmath.Quat4d getOrientation() {
+               return MathTools.getIdentityQuat();
+       };
+       
+       @Override
+       public Vector3d getPosition() {
+               return new Vector3d();
+       }
+       
+       @Override
+       public Quat4d getWorldOrientation() {
+               return MathTools.getIdentityQuat();
+       }
+       
+       @Override
+       public Vector3d getWorldPosition() {
+               return new Vector3d();
+       }
+       
+       @Override
+       public Quat4d getWorldOrientation(Quat4d localOrientation) {
+               return localOrientation;
+       }
+       
+       @Override
+       public Vector3d getWorldPosition(Vector3d localPosition) {
+               return localPosition;
+       }
+       
+       @Override
+       public Quat4d getLocalOrientation(Quat4d worldOrientation) {
+               return worldOrientation;
+       }
+       
+       @Override
+       public Vector3d getLocalPosition(Vector3d worldPosition) {
+               return worldPosition;
+       }
+       
+       @Override
+       public void setPosition(Vector3d position) {
+               throw new NodeException("Cannot set root node position");
+       }
+       
+       @Override
+       public void setOrientation(Quat4d orientation) {
+               throw new NodeException("Cannot set root node orientation");
+       }
+       
+       @Override
+       public void setWorldOrientation(Quat4d orientation) {
+               throw new NodeException("Cannot set root node orientation");
+       }
+       
+       @Override
+       public void setWorldPosition(Vector3d position) {
+               throw new NodeException("Cannot set root node orientation");
+       }
+       
+       public String getUniqueName(String prefix) {
+               Set<String> names = new HashSet<String>();
+               Stack<ICSGnode> nodes = new Stack<ICSGnode>();
+               nodes.addAll(getChild());
+               while (!nodes.isEmpty()) {
+                       ICSGnode n = nodes.pop();
+                       names.add(((ICSGnode)n).getName());
+                       if (n instanceof CSGparentNode) {
+                               nodes.addAll(((CSGparentNode)n).getChild());
+                               nodes.addAll(((CSGparentNode)n).getPrimaryChild());
+                               nodes.addAll(((CSGparentNode)n).getSecondaryChild());
+                       }
+               }
+               int i = 1;
+               while (true) {
+                       String genName = prefix + "_" + i;
+                       if (!names.contains(genName))
+                               return genName;
+                       i++;
+               }
+       }
+       
+
+       @Override
+       public Object getAdapter(Class adapter) {
+               if (NodeMap.class == adapter)
+                       return nodeMap;
+               return null;
+       }
+       
+
+}