]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java
Plant3D customization
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / utils / P3DUtil.java
index e6e3385f3a2967aaee826a684136ac98be7dce50..0d656b054de0e724e72d4592597fa46aa52b4a17 100644 (file)
@@ -11,20 +11,30 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.layer0.Layer0;
 import org.simantics.plant3d.ontology.Plant3D;
+import org.simantics.plant3d.scenegraph.Equipment;
+import org.simantics.plant3d.scenegraph.P3DRootNode;
+import org.simantics.plant3d.scenegraph.PipeRun;
+import org.simantics.plant3d.scenegraph.PipelineComponent;
+import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
+import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 import org.simantics.plant3d.utils.Item.Type;
-import org.simantics.ui.SimanticsUI;
 
 public class P3DUtil {
+    
+    public static List<Item> getEquipments() throws DatabaseException {
+        return getEquipments(Plant3D.URIs.Builtin);
+    }
        
-       public static List<Item> getEquipments() throws DatabaseException {
+       public static List<Item> getEquipments(final String libUri) throws DatabaseException {
                return Simantics.getSession().syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
                                Resource project = Simantics.getProject().get();
-                               Resource builtins = graph.getResource(Plant3D.URIs.Builtin);
+                               Resource builtins = graph.getResource(libUri);
                                List<Item> actions = getItems(graph, project,p3d.Equipment);
                                actions.addAll(getItems(graph, builtins,p3d.Equipment));
                                return actions;
@@ -39,26 +49,43 @@ public class P3DUtil {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
-                               ItemQuery query = new ItemQuery(p3d.Nozzle);
+                               ItemQuery query = new ItemQuery(p3d.Nozzle, Plant3D.URIs.Builtin);
                                return graph.syncRequest(query);
                        }
                });
        }
        
-       private static class ItemQuery implements Read<List<Item>> {
+       public static class ItemQuery implements Read<List<Item>> {
                private Resource type;
-               public ItemQuery(Resource type) {
+               private String libUri;
+               public ItemQuery(Resource type, String libUri) {
                        this.type = type;
+                       this.libUri = libUri;
                }
                
                @Override
                public List<Item> perform(ReadGraph graph) throws DatabaseException {
                        Resource project = Simantics.getProject().get();
-                       Resource builtins = graph.getResource(Plant3D.URIs.Builtin);
+                       Resource builtins = graph.getResource(libUri);
                        List<Item> actions = getItems(graph, project,type);
                        actions.addAll(getItems(graph, builtins,type));
                        return actions;
                }
+               
+               @Override
+               public boolean equals(Object obj) {
+                   if (obj.getClass() != this.getClass())
+                       return false;
+                   ItemQuery other = (ItemQuery)obj;
+                   if (!type.equals(other.type))
+                       return false;
+                   return libUri.equals(other.libUri);
+               }
+               
+               @Override
+               public int hashCode() {
+                   return type.hashCode() + libUri.hashCode();
+               }
        }
        
        public static List<Item> getEnds() throws DatabaseException {
@@ -66,7 +93,7 @@ public class P3DUtil {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
-                               ItemQuery query = new ItemQuery(p3d.EndComponent);
+                               ItemQuery query = new ItemQuery(p3d.EndComponent, Plant3D.URIs.Builtin);
                                return graph.syncRequest(query);
                        }
                });
@@ -77,7 +104,7 @@ public class P3DUtil {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
-                               ItemQuery query = new ItemQuery(p3d.TurnComponent);
+                               ItemQuery query = new ItemQuery(p3d.TurnComponent, Plant3D.URIs.Builtin);
                                return graph.syncRequest(query);
                        }
                });
@@ -88,7 +115,7 @@ public class P3DUtil {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
-                               ItemQuery query = new ItemQuery(p3d.InlineComponent);
+                               ItemQuery query = new ItemQuery(p3d.InlineComponent, Plant3D.URIs.Builtin);
                                return graph.syncRequest(query);
                        }
                });
@@ -175,5 +202,40 @@ public class P3DUtil {
                
                return model;
        }
+       
+       public static void finalizeDBLoad(P3DRootNode rootNode) throws Exception{
+           for (INode node : rootNode.getChild()) {
+            if (node instanceof PipeRun) {
+                for (PipelineComponent pc : ((PipeRun) node).getChild())
+                    pc.sync();
+            } else if (node instanceof Equipment) {
+                for (PipelineComponent pc : ((Equipment) node).getChild())
+                    pc.sync();
+            }
+        }
+        
+        for (INode node : rootNode.getChild()) {
+            if (node instanceof PipeRun) {
+                for (PipelineComponent pc : ((PipeRun) node).getChild())
+                    pc.sync2();
+            } else if (node instanceof Equipment) {
+                for (PipelineComponent pc : ((Equipment) node).getChild())
+                    pc.sync2();
+            }
+        }
+        for (INode node : rootNode.getChild()) {
+            if (node instanceof PipeRun) {
+                PipingRules.validate((PipeRun)node);
+            }
+        }
+        PipingRules.setEnabled(true);
+        for (INode node : rootNode.getChild()) {
+            if (node instanceof PipeRun) {
+                PipeRun run = (PipeRun)node;
+                for (PipeControlPoint pcp : run.getControlPoints())
+                    PipingRules.positionUpdate(pcp);        
+            }
+        }
+       }
 
 }