]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Access to mapping between object and resources via P3DRootNode 58/3458/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 6 Nov 2019 10:53:38 +0000 (12:53 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 6 Nov 2019 12:59:20 +0000 (14:59 +0200)
gitlab #48

Change-Id: I8fd2a6c0adbce3a1b6cc8e7e3055b9023de009ba

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java
org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java

index 0fb7ed4f8d1fa9b990cb9ea54f14f5713d9038bc..5b7fe274c0b509dcba87151505d3794054a60e15 100644 (file)
@@ -15,17 +15,17 @@ 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<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp , INode> {
+public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp, INode> {
        
        
        @RelatedElementsAdd(Plant3D.URIs.children)
@@ -45,17 +45,31 @@ public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapP
                removeNode(Plant3D.URIs.children, node);
        }
        
-       private P3DNodeMap nodeMap;
+       private NodeMap<Resource, vtkProp, INode> nodeMap;
+       private IMapping<Resource, INode> mapping;
        
-       public void setNodeMap(P3DNodeMap nodeMap) {
+       public void setNodeMap(NodeMap<Resource, vtkProp, INode> nodeMap) {
                this.nodeMap = nodeMap;
+               this.mapping = nodeMap.getMapping();
+       }
+       
+       public void setMapping(IMapping<Resource, INode> mapping) {
+               this.mapping = mapping;
        }
        
        @Override
-       public NodeMap<Resource,vtkProp, INode> getNodeMap() {
+       public NodeMap<Resource, vtkProp, INode> 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;
index 4d1fb18c2720f37075c7b054ef7303d91ad05bce..21a77a6edf07a17a23e0f04c7a4c3752d2644b24 100644 (file)
@@ -11,7 +11,6 @@ import org.simantics.g3d.ontology.G3D;
 import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.scenegraph.base.ParentNode;
 import org.simantics.g3d.scl.ScriptNodeMap;
-import org.simantics.g3d.vtk.common.VtkView;
 import org.simantics.objmap.graph.IMapping;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.IP3DNode;
@@ -23,15 +22,13 @@ import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 
-import vtk.vtkProp3D;
-
-public class P3DScriptNodeMap extends ScriptNodeMap<Resource,INode>{
+public class P3DScriptNodeMap extends ScriptNodeMap<Resource,INode> {
        
        private static final boolean DEBUG = false;
        
        public P3DScriptNodeMap(Session session, IMapping mapping, P3DRootNode rootNode) {
                super(session,mapping,rootNode);
-               //rootNode.setNodeMap(this);
+               rootNode.setMapping(mapping);
        }
        
        @Override
@@ -94,6 +91,7 @@ public class P3DScriptNodeMap extends ScriptNodeMap<Resource,INode>{
 
                
                if (node instanceof ParentNode<?>) {
+                       @SuppressWarnings("unchecked")
                        ParentNode<IP3DNode> p = (ParentNode<IP3DNode>)node;
                        for (IP3DNode n : p.getNodes())
                                updateTransform(n);
index cdbf6626b197548c624f65e57b6f2d7b58cbdff1..4c4b6d5760a6f40b68533dba92a67b741585fc27 100644 (file)
@@ -58,6 +58,7 @@ public class SCLUtil {
                                IMappingSchema<Resource, Object> schema = schemaProvider.get(graph);
                                IMapping<Resource, Object> mapping = Mappings.createWithListening(schema);
                                P3DRootNode rootNode = (P3DRootNode) mapping.map(graph, root);
+                               rootNode.setMapping((IMapping)mapping);
                                try {
                                        P3DUtil.finalizeDBLoad(rootNode);
                                        // FIXME: Something needs to be done here...
@@ -83,12 +84,14 @@ public class SCLUtil {
                                IMapping<Resource, Object> mapping = Mappings.createWithoutListening(schema);
                                @SuppressWarnings("unchecked")
                                Root rootNode = (Root) mapping.map(graph, root);
+                               rootNode.setMapping((IMapping)mapping);
                                try {
                                        P3DUtil.finalizeDBLoad(rootNode);
                                        P3DUtil.finalizeDBLoad2(rootNode);
                                } catch (Exception e) {
                                        throw new DatabaseException(e);
                                }
+                               
                                return rootNode;
                        }
                });