X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Futils%2FComponentUtils.java;h=fdd5b5bbe8d89c3c4c8a3f4204ae6c618a36186d;hb=1c986f49dd51037e0a189df77a76abce890ae8ae;hp=af64f180b5d1fde1fb14a70cd02f76ccce91f8b0;hpb=a460e609147d064dd3da464bcf1626845e0f93b4;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index af64f180..fdd5b5bb 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -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> clazzes = new HashMap>(); - private static Map providers = new HashMap(); + private static Map providers = new HashMap(); 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 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; + } }