From: Reino Ruusu Date: Wed, 6 Nov 2019 10:53:38 +0000 (+0200) Subject: Access to mapping between object and resources via P3DRootNode X-Git-Tag: v1.43.0~141 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F58%2F3458%2F1;p=simantics%2F3d.git Access to mapping between object and resources via P3DRootNode gitlab #48 Change-Id: I8fd2a6c0adbce3a1b6cc8e7e3055b9023de009ba --- 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 0fb7ed4f..5b7fe274 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java @@ -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 implements IG3DNode, NodeMapProvider { +public class P3DRootNode extends ParentNode implements IG3DNode, NodeMapProvider { @RelatedElementsAdd(Plant3D.URIs.children) @@ -45,17 +45,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; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java b/org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java index 4d1fb18c..21a77a6e 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scl/P3DScriptNodeMap.java @@ -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{ +public class P3DScriptNodeMap extends ScriptNodeMap { 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{ if (node instanceof ParentNode) { + @SuppressWarnings("unchecked") ParentNode p = (ParentNode)node; for (IP3DNode n : p.getNodes()) updateTransform(n); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java index cdbf6626..4c4b6d57 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scl/SCLUtil.java @@ -58,6 +58,7 @@ public class SCLUtil { IMappingSchema schema = schemaProvider.get(graph); IMapping 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 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; } });