]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java
Enable model loading using an existing transaction.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / utils / P3DUtil.java
index 65b93cffd2688102500fb30a0b67dce44949c87f..2f5972a8d86a160dd4fd022fd93c605cc2706194 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Set;
 
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
@@ -28,12 +29,12 @@ import org.simantics.plant3d.utils.Item.Type;
 
 public class P3DUtil {
        
-       public static List<Item> getEquipments() throws DatabaseException {
-               return getEquipments(Plant3D.URIs.Builtin);
+       public static List<Item> getEquipments(RequestProcessor session) throws DatabaseException {
+               return getEquipments(session, Plant3D.URIs.Builtin);
        }
        
-       public static List<Item> getEquipments(final String libUri) throws DatabaseException {
-               return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+       public static List<Item> getEquipments(RequestProcessor session, final String libUri) throws DatabaseException {
+               return session.syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
@@ -48,8 +49,8 @@ public class P3DUtil {
                });
        }
        
-       public static List<Item> getNozzles(String libUri) throws DatabaseException {
-               return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+       public static List<Item> getNozzles(RequestProcessor session, String libUri) throws DatabaseException {
+               return session.syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
@@ -69,7 +70,7 @@ public class P3DUtil {
                
                @Override
                public List<Item> perform(ReadGraph graph) throws DatabaseException {
-                       Resource project = Simantics.getProject().get();
+//                     Resource project = Simantics.getProject().get();
                        Resource builtins = graph.getResource(libUri);
                        List<Item> actions = new ArrayList<>();
 //                     actions.addAll(getItems(graph, project,type));
@@ -92,9 +93,9 @@ public class P3DUtil {
                        return type.hashCode() + libUri.hashCode();
                }
        }
-       
-       public static List<Item> getEnds(String libUri) throws DatabaseException {
-               return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+
+       public static List<Item> getEnds(RequestProcessor session, String libUri) throws DatabaseException {
+               return session.syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
@@ -104,8 +105,8 @@ public class P3DUtil {
                });
        }
        
-       public static List<Item> getTurns(String libUri) throws DatabaseException {
-               return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+       public static List<Item> getTurns(RequestProcessor session, String libUri) throws DatabaseException {
+               return session.syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
@@ -115,8 +116,8 @@ public class P3DUtil {
                });
        }
        
-       public static List<Item> getInlines(String libUri) throws DatabaseException {
-               return Simantics.getSession().syncRequest(new Read<List<Item>>() {
+       public static List<Item> getInlines(RequestProcessor session, String libUri) throws DatabaseException {
+               return session.syncRequest(new Read<List<Item>>() {
                        @Override
                        public List<Item> perform(ReadGraph graph) throws DatabaseException {
                                Plant3D p3d = Plant3D.getInstance(graph);
@@ -188,7 +189,8 @@ public class P3DUtil {
                Plant3D p3d = Plant3D.getInstance(graph);
                String name = graph.getRelatedValue(r, l0.HasName);
                String uri = graph.getURI(r);
-               Item item = new Item(uri, name);
+               String label = graph.getPossibleRelatedValue(r, l0.HasLabel);
+               Item item = new Item(uri, name, label);
                if (graph.isInstanceOf(r, p3d.Equipment))
                        item.setType(Type.EQUIPMENT);
                else if (graph.isInstanceOf(r, p3d.InlineComponent))
@@ -207,8 +209,12 @@ public class P3DUtil {
                if (graph.hasStatement(r, p3d.VariableAngleTurnComponent) ||
                        graph.hasStatement(r, p3d.VariableLengthInlineComponent))
                        item.setVariable(true);
+               if (graph.hasStatement(r, p3d.AdjustableLengthInlineComponent))
+                   item.setModifiable(true);
                if (graph.hasStatement(r, p3d.SizeChangeComponent))
                        item.setSizeChange(true);
+               if (graph.hasStatement(r, p3d.RotateComponent))
+            item.setRotated(true);
                return item;
        }
        
@@ -225,11 +231,15 @@ public class P3DUtil {
        public static void finalizeDBLoad(P3DRootNode rootNode) throws Exception{
                for (INode node : rootNode.getChild()) {
                        if (node instanceof PipeRun) {
-                               for (PipelineComponent pc : ((PipeRun) node).getChild())
+                               for (PipelineComponent pc : ((PipeRun) node).getChild()) {
                                        pc.sync();
+                                       pc.updateParameters();
+                               }
                        } else if (node instanceof Equipment) {
-                               for (PipelineComponent pc : ((Equipment) node).getChild())
+                               for (PipelineComponent pc : ((Equipment) node).getChild()) {
                                        pc.sync();
+                                       pc.updateParameters();
+                               }
                        }
                }
                
@@ -249,16 +259,17 @@ public class P3DUtil {
                }
        }
        
-   public static void finalizeDBLoad2(P3DRootNode rootNode) throws Exception{
-       PipingRules.setEnabled(true);
+    public static void finalizeDBLoad2(P3DRootNode rootNode) throws Exception {
+        PipingRules.setEnabled(true);
         for (INode node : rootNode.getChild()) {
             if (node instanceof PipeRun) {
-                PipeRun run = (PipeRun)node;
+                PipeRun run = (PipeRun) node;
                 for (PipeControlPoint pcp : run.getControlPoints())
-                    PipingRules.positionUpdate(pcp);
-                    //PipingRules.requestUpdate(pcp);
+                    if (pcp.asPathLegEnd())
+                        PipingRules.requestUpdate(pcp);
             }
         }
-   }
+        PipingRules.update();
+    }
 
 }