]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java
First version of fixed nozzle positions
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / utils / ComponentUtils.java
index af64f180b5d1fde1fb14a70cd02f76ccce91f8b0..fdd5b5bbe8d89c3c4c8a3f4204ae6c618a36186d 100644 (file)
@@ -10,13 +10,15 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.layer0.Layer0;
-import org.simantics.opencascade.SolidModelProvider;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.EndComponent;
+import org.simantics.plant3d.scenegraph.Equipment;
 import org.simantics.plant3d.scenegraph.InlineComponent;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
+import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 import org.simantics.plant3d.scenegraph.TurnComponent;
 
@@ -24,7 +26,7 @@ public class ComponentUtils {
 
        
        private static Map<String,Class<? extends PipelineComponent>> clazzes = new HashMap<String, Class<? extends PipelineComponent>>();
-       private static Map<String,SolidModelProvider> providers = new HashMap<String,SolidModelProvider>();
+       private static Map<String,GeometryProvider> providers = new HashMap<String,GeometryProvider>();
        
        public static void preloadCache() {
                Simantics.getSession().asyncRequest(new ReadRequest() {
@@ -36,7 +38,7 @@ public class ComponentUtils {
                                types.add(Plant3D.URIs.Builtin_Elbow);
                                types.add(Plant3D.URIs.Builtin_ConcentricReducer);
                                types.add(Plant3D.URIs.Builtin_BranchSplitComponent);
-//                             types.add(Plant3D.URIs.Builtin_EccentricReducer);
+                               types.add(Plant3D.URIs.Builtin_EccentricReducer);
                                
                                for (String typeURI : types) {
                                        load(graph, typeURI);
@@ -45,7 +47,7 @@ public class ComponentUtils {
                });
        }
        
-       private static SolidModelProvider getProvider(ReadGraph graph, Resource type) throws DatabaseException {
+       private static GeometryProvider getProvider(ReadGraph graph, Resource type) throws DatabaseException {
                
                Layer0 l0 = Layer0.getInstance(graph);
                Plant3D p3d = Plant3D.getInstance(graph);
@@ -59,7 +61,7 @@ public class ComponentUtils {
                        }
                }
                if (geom != null) {
-                       SolidModelProvider provider = graph.adapt(geom, SolidModelProvider.class);
+                       GeometryProvider provider = graph.adapt(geom, GeometryProvider.class);
                        return provider;
                }
                return null;
@@ -82,10 +84,10 @@ public class ComponentUtils {
                Plant3D p3d = Plant3D.getInstance(graph);
                Resource type = graph.getResource(typeURI);
                
-               SolidModelProvider provider = getProvider(graph, type);
+               GeometryProvider provider = getProvider(graph, type);
                if (provider != null || graph.hasStatement(type,p3d.NonVisibleComponent)) {
                        providers.put(typeURI, provider);
-                       ComponentUtils.clazzes.put(typeURI,getClazz(graph, type));
+                       clazzes.put(typeURI,getClazz(graph, type));
                        return;
                }
                throw new DatabaseException("Cannot find component for " + typeURI);
@@ -103,7 +105,7 @@ public class ComponentUtils {
        
        public static PipelineComponent createComponent(P3DRootNode root, String typeURI) throws Exception {
                Class<? extends PipelineComponent> type = clazzes.get(typeURI);
-               SolidModelProvider provider = providers.get(typeURI);
+               GeometryProvider provider = providers.get(typeURI);
                if (type == null || provider == null) {
                        load(typeURI);
                        type = clazzes.get(typeURI);
@@ -151,4 +153,33 @@ public class ComponentUtils {
                component.setType(Plant3D.URIs.Builtin_BranchSplitComponent);
                return component;
        }
+       
+       public static Equipment createEquipment(P3DRootNode root, Item equipmentType) throws Exception {
+           Equipment equipment = root.createEquipment();
+        equipment.setType(equipmentType.getUri());
+        String n = root.getUniqueName(equipmentType.getName());
+        equipment.setName(n);
+        root.addChild(equipment);
+        return equipment;
+       }
+       
+       public static Nozzle createDefaultNozzle(P3DRootNode root, Equipment equipment) throws Exception {
+           return createNozzle(root, equipment, new Item(Plant3D.URIs.Builtin_Nozzle, "Nozzle"));
+       }
+       
+       public static Nozzle createNozzle(P3DRootNode root, Equipment equipment, Item nozzleType) throws Exception {
+           Nozzle nozzle = root.createNozzle();
+        nozzle.setType(nozzleType.getUri());
+        String n = root.getUniqueName(nozzleType.getName());
+        nozzle.setName(n);
+        PipeRun pipeRun = new PipeRun();
+        n = root.getUniqueName("PipeRun");
+        pipeRun.setName(n);
+        nozzle.setPipeRun(pipeRun);
+        
+        equipment.addChild(nozzle);
+        root.addChild(pipeRun);
+        // root.getNodeMap().commit("Add nozzle " + n);
+        return nozzle;
+       }
 }