X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.csg%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fcsg%2Fscenegraph2%2FCSGrootNode.java;h=9ae55a1fe33458359f5105108362578d44c6e614;hb=9070983be64f9f107e0a6388549aad475fcd9d76;hp=ac7a5158521f59d0f0076db7602da109d56b5647;hpb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;p=simantics%2F3d.git diff --git a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java index ac7a5158..9ae55a1f 100644 --- a/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java +++ b/org.simantics.g3d.csg/src/org/simantics/g3d/csg/scenegraph2/CSGrootNode.java @@ -1,157 +1,169 @@ -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 implements IG3DNode, NodeMapProvider { - - - private CSGNodeMap nodeMap; - - public void setNodeMap(CSGNodeMap nodeMap) { - this.nodeMap = nodeMap; - } - - @Override - public NodeMap 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 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 names = new HashSet(); - Stack nodes = new Stack(); - 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; - } - - -} +/******************************************************************************* + * 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.db.Resource; +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 implements IG3DNode, NodeMapProvider { + + + private CSGNodeMap nodeMap; + + public void setNodeMap(CSGNodeMap nodeMap) { + this.nodeMap = nodeMap; + } + + @Override + public NodeMap 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 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 names = new HashSet(); + Stack nodes = new Stack(); + 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; + } + + +}