1 package org.simantics.plant3d.scl;
3 import java.util.HashSet;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.RequestProcessor;
8 import org.simantics.db.Resource;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.g3d.ontology.G3D;
11 import org.simantics.g3d.scenegraph.base.INode;
12 import org.simantics.g3d.scenegraph.base.ParentNode;
13 import org.simantics.g3d.scl.ScriptNodeMap;
14 import org.simantics.objmap.graph.IMapping;
15 import org.simantics.plant3d.ontology.Plant3D;
16 import org.simantics.plant3d.scenegraph.IP3DNode;
17 import org.simantics.plant3d.scenegraph.IP3DVisualNode;
18 import org.simantics.plant3d.scenegraph.P3DParentNode;
19 import org.simantics.plant3d.scenegraph.P3DRootNode;
20 import org.simantics.plant3d.scenegraph.ParameterizedNode;
21 import org.simantics.plant3d.scenegraph.PipeRun;
22 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
23 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
25 public class P3DScriptNodeMap extends ScriptNodeMap<Resource,INode> {
27 private static final boolean DEBUG = false;
29 public P3DScriptNodeMap(RequestProcessor session, IMapping mapping, P3DRootNode rootNode) {
30 super(session,mapping,rootNode);
31 rootNode.setMapping(mapping);
35 protected void updateActor(INode n, Set<String> ids) {
36 if (DEBUG) System.out.println("P3DNodeMap update " + n);
37 if (!(n instanceof IP3DVisualNode)) {
38 if (n instanceof PipeControlPoint) {
39 n = ((PipeControlPoint)n).getPipelineComponent();
47 IP3DVisualNode node = (IP3DVisualNode)n;
50 System.out.print("P3DNodeMap update " + node);
52 System.out.print(" " + s);
56 if (ids.contains(Plant3D.URIs.hasGeometry)) {
57 //node.visualize(view);
58 //updateRenderObjectsFor(node);
59 updateTransform(node);
61 if (n instanceof ParameterizedNode) {
62 ParameterizedNode geom = (ParameterizedNode)n;
63 for (String id : geom.getParameterMap().keySet()) {
64 if (ids.contains(id)) {
65 // node.visualize(view);
66 // updateRenderObjectsFor(node);
67 updateTransform(node);
71 } else if (n instanceof PipeRun) {
72 // FIXME: may require rule based update!
73 PipeRun run = (PipeRun)n;
74 Set<String> ids2 = new HashSet<String>();
75 ids2.add(Plant3D.URIs.hasGeometry);
76 for (PipeControlPoint pcp : run.getControlPoints()) {
77 updateActor(pcp, ids2);
81 if (ids.contains(G3D.URIs.hasPosition) ||
82 ids.contains(G3D.URIs.hasOrientation) ||
83 ids.contains(G3D.URIs.hasWorldPosition) ||
84 ids.contains(G3D.URIs.hasWorldOrientation)) {
85 updateTransform(node);
89 private void updateTransform(IP3DNode node) {
90 if (DEBUG) System.out.println("P3DNodeMap update Transform " + node);
93 if (node instanceof ParentNode<?>) {
94 @SuppressWarnings("unchecked")
95 ParentNode<IP3DNode> p = (ParentNode<IP3DNode>)node;
96 for (IP3DNode n : p.getNodes())
102 protected void removeActor(INode n) {
103 if (DEBUG) System.out.println("P3DNodeMap.removeActor " + n);
104 if (!(n instanceof IP3DVisualNode))
106 IP3DVisualNode node = (IP3DVisualNode)n;
109 if (node instanceof P3DParentNode<?>) {
110 for (IP3DNode n2 : ((P3DParentNode<?>)node).getNodes())
111 if (n2 instanceof IP3DVisualNode)
112 removeActor((IP3DVisualNode)n2);
117 protected void addActor(INode n) {
118 if (DEBUG) System.out.println("P3DNodeMap.addActor " + n);
119 if (!(n instanceof IP3DVisualNode))
121 IP3DVisualNode node = (IP3DVisualNode)n;
123 // if (hasActor(node))
126 if (node instanceof P3DParentNode<?>) {
127 for (IP3DNode n2 : ((P3DParentNode<?>)node).getNodes())
128 if (n2 instanceof IP3DVisualNode)
129 addActor((IP3DVisualNode)n2);
132 updateTransform(node);
136 protected void update(ReadGraph graph) throws DatabaseException {
138 // System.out.println("Graph updates");
144 public void commit(String commitMessage) {
146 // System.out.println("Graph commit");
147 super.commit(commitMessage);
151 protected void doCommit() throws DatabaseException{
152 // System.out.println("Do commit");
157 private void validate() {
158 for (INode node : rootNode.getNodes()) {
159 if (node instanceof PipeRun)
160 PipingRules.validate((PipeRun)node);
165 public void update() throws DatabaseException {
170 b = PipingRules.update();
172 } catch (Exception e) {