X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2FP3DRootNode.java;h=93f4ecf27d4be74d4e67ade02c20a983a884eda1;hb=refs%2Fchanges%2F88%2F4288%2F1;hp=4f00530e7203f2e0ca010bf8423d9e57366d3188;hpb=d00bd5522f6a92bbfeb2a72a7d28ba25c3f36fed;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java index 4f00530e..93f4ecf2 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java @@ -7,6 +7,7 @@ import java.util.Set; import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; +import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.NodeMap; @@ -14,19 +15,21 @@ import org.simantics.g3d.scenegraph.NodeMapProvider; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.base.NodeException; import org.simantics.g3d.scenegraph.base.ParentNode; +import org.simantics.objmap.graph.IMapping; 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 org.simantics.plant3d.editor.P3DNodeMap; import org.simantics.plant3d.ontology.Plant3D; import vtk.vtkProp; @GraphType(Plant3D.URIs.Plant) -public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapProvider { - +public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapProvider { + // Vertical direction that determines the interpretation of rotation angle origin + protected Vector3d upVector = new Vector3d(0.0, 1.0, 0.0); + @RelatedElementsAdd(Plant3D.URIs.children) public void addChild(INode node) { //public void addChild(IP3DVisualNode node) { @@ -44,17 +47,31 @@ public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapP removeNode(Plant3D.URIs.children, node); } - private P3DNodeMap nodeMap; + private NodeMap nodeMap; + private IMapping mapping; - public void setNodeMap(P3DNodeMap nodeMap) { + public void setNodeMap(NodeMap nodeMap) { this.nodeMap = nodeMap; + this.mapping = nodeMap.getMapping(); + } + + public void setMapping(IMapping mapping) { + this.mapping = mapping; } @Override - public NodeMap getNodeMap() { + public NodeMap getNodeMap() { return nodeMap; } + public Resource getNodeResource(INode node) { + return mapping.inverseGet(node); + } + + public INode getResourceNode(Resource r) { + return mapping.get(r); + } + @Override public ParentNode getParent() { return null; @@ -124,6 +141,10 @@ public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapP throw new NodeException("Cannot set root node orientation"); } + /** + * Get a unique name in the Plant3D model with a given prefix followed by + * an underscore and number. + */ public String getUniqueName(String prefix) { Set names = new HashSet(); for (INode node : getChild()) { @@ -131,6 +152,8 @@ public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapP continue; IP3DVisualNode n = (IP3DVisualNode)node; names.add(n.getName()); + if (node instanceof P3DParentNode) + ((P3DParentNode) node).getComponentNames(names); } int i = 1; while (true) { @@ -142,11 +165,10 @@ public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapP } - @SuppressWarnings("rawtypes") @Override - public Object getAdapter(Class adapter) { - if (NodeMap.class == adapter) - return nodeMap; + public T getAdapter(Class adapter) { + if (adapter.isAssignableFrom(NodeMap.class)) + return adapter.cast(nodeMap); return null; } @@ -169,4 +191,8 @@ public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapP public TurnComponent createTurn() { return new TurnComponent(); } + + public Vector3d getUpVector() { + return upVector; + } }