From: Marko Luukkainen Date: Thu, 15 Aug 2019 09:16:39 +0000 (+0300) Subject: First version of fixed nozzle positions X-Git-Tag: v1.43.0~221^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1c986f49dd51037e0a189df77a76abce890ae8ae;p=simantics%2F3d.git First version of fixed nozzle positions Fixed nozzles are not added to equipment automatically. gitlab #27 Change-Id: I675bee1132131fd9033f9054ea654c33ab60ffc6 --- diff --git a/org.simantics.plant3d.ontology/graph/plant3d.pgraph b/org.simantics.plant3d.ontology/graph/plant3d.pgraph index 040dd889..f589bf37 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d.pgraph @@ -127,21 +127,31 @@ P3D.IsReversed 0) { + int currentNozzles = equipment.getNodes().size(); + setEnabled(currentNozzles < fixedNozzles); + } else { + setEnabled(true); + } } @Override public void run() { try { - Nozzle nozzle = root.createNozzle(); - nozzle.setType(item.getUri()); - String n = root.getUniqueName(item.getName()); - nozzle.setName(n); - PipeRun pipeRun = new PipeRun(); - n = root.getUniqueName("PipeRun"); - pipeRun.setName(n); - nozzle.setPipeRun(pipeRun); - - equipment.addChild(nozzle); - //root.addChild(nozzle); - root.addChild(pipeRun); - root.getNodeMap().commit("Add nozzle " + n); + Nozzle nozzle = ComponentUtils.createNozzle(root, equipment, item); + root.getNodeMap().commit("Add nozzle " + nozzle.getName()); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot create equipment",e); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index b1bb5000..159a239d 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -353,9 +353,11 @@ public class Plant3DEditor extends ResourceEditorPart { m.add(add); } } else if (node instanceof Nozzle) { - m.add(translateAction); - m.add(rotateAction); - Nozzle nozzle = (Nozzle)node; + Nozzle nozzle = (Nozzle)node; + if (!nozzle.isFixed()) { + m.add(translateAction); + m.add(rotateAction); + } m.add(routePipeAction); routePipeAction.setComponent(nozzle); routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java new file mode 100644 index 00000000..bf30437c --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java @@ -0,0 +1,11 @@ +package org.simantics.plant3d.geometry; + +import org.simantics.plant3d.scenegraph.Nozzle; + +public interface FixedNozzleProvider { + + int numberOfNozzles(); + void updateNozzlePosition(int index, Nozzle nozzle); + String getNozzleName(int index); + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java index 451abe1e..47b2d2d1 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java @@ -4,12 +4,16 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import javax.vecmath.AxisAngle4d; +import javax.vecmath.Vector3d; + import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.opencascade.OccTriangulator; +import org.simantics.plant3d.scenegraph.Nozzle; -public class PumpGeometryProvider extends BuiltinGeometryProvider { +public class PumpGeometryProvider extends BuiltinGeometryProvider implements FixedNozzleProvider{ public PumpGeometryProvider(Resource resource) { super(resource); @@ -62,5 +66,34 @@ public class PumpGeometryProvider extends BuiltinGeometryProvider { } } + + @Override + public int numberOfNozzles() { + return 2; + } + + @Override + public void updateNozzlePosition(int index, Nozzle nozzle) { + Double fl = nozzle.getFlowLength(); + if (fl == null) + fl = 0.1; + if (index == 0) { + nozzle.setPosition(new Vector3d(-length*0.5- fl,width*0.6,0.0)); + nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,1,0,Math.PI))); + } else if (index == 1) { + nozzle.setPosition(new Vector3d(-length*0.4,width*1.1+ fl,0.0)); + nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,0,1,Math.PI*0.5))); + } + + } + + @Override + public String getNozzleName(int index) { + switch (index) { + case 0 : return "Input"; + case 1: return "Output"; + default: return null; + } + } } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java index 3bac765c..27a76067 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java @@ -2,6 +2,7 @@ package org.simantics.plant3d.scenegraph; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -11,6 +12,7 @@ import javax.vecmath.Vector3d; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.CompoundGetPropertyValue; import org.simantics.g3d.property.annotations.CompoundSetPropertyValue; +import org.simantics.g3d.scenegraph.GeometryProvider; import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue; import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue; import org.simantics.objmap.graph.annotations.DynamicGraphType; @@ -19,6 +21,7 @@ import org.simantics.objmap.graph.annotations.RelatedElementsAdd; import org.simantics.objmap.graph.annotations.RelatedElementsGet; import org.simantics.objmap.graph.annotations.RelatedElementsRem; import org.simantics.objmap.graph.annotations.SetType; +import org.simantics.plant3d.geometry.FixedNozzleProvider; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; @@ -27,6 +30,7 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; public class Equipment extends P3DParentGeometryNode { private String type; + private FixedNozzleProvider fnp; @GetType(Plant3D.URIs.Equipment) public String getType() { @@ -50,6 +54,8 @@ public class Equipment extends P3DParentGeometryNode { newId++; addNode(Plant3D.URIs.HasNozzle,node); node.setNozzleId(newId); + if (fnp != null) + syncNozzles(); } @RelatedElementsGet(Plant3D.URIs.HasNozzle) @@ -76,6 +82,42 @@ public class Equipment extends P3DParentGeometryNode { super.setParameterMap(parameters); } + @Override + public void setGeometry(GeometryProvider provider) { + super.setGeometry(provider); + if (provider instanceof FixedNozzleProvider) { + fnp = (FixedNozzleProvider)provider; + syncNozzles(); + } + } + + public int numberOfFixedNozzles() { + if (fnp == null) + return 0; + return fnp.numberOfNozzles(); + } + + /** + * Synchronizes fixed nozzles. + * + * Note: this method does not create nozzles, just sets their positions and names. + */ + public void syncNozzles() { + if (fnp == null) + return; + + int count = fnp.numberOfNozzles(); + List currentNozzles = getNodes(); + for (int i = 0; i < count; i++) { + if (i < currentNozzles.size()) { + Nozzle nozzle = currentNozzles.get(i); + nozzle.setName(fnp.getNozzleName(i)); + fnp.updateNozzlePosition(i, nozzle); + nozzle.setFixed(true); + } + } + } + @Override protected double[] getColor() { return new double[]{1,0,0}; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java index 9c4ad6f6..fec8c084 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java @@ -53,6 +53,22 @@ public class Nozzle extends PipelineComponent { firePropertyChanged(Plant3D.URIs.HasNozzleId); } + private boolean fixed = false; + + @RelatedGetValue(Plant3D.URIs.IsFixedNozzle) + @GetPropertyValue(name="Fixed", value=Plant3D.URIs.IsFixedNozzle, tabId="Default") + public boolean isFixed() { + return fixed; + } + + @RelatedSetValue(Plant3D.URIs.IsFixedNozzle) + public void setFixed(boolean fixed) { + if (fixed == this.fixed) + return; + this.fixed = fixed; + firePropertyChanged(Plant3D.URIs.IsFixedNozzle); + } + private void _createCP() throws Exception{ if (controlPoint != null) return; 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 2644ab0f..fdd5b5bb 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -14,9 +14,11 @@ import org.simantics.g3d.scenegraph.GeometryProvider; import org.simantics.layer0.Layer0; 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; @@ -85,7 +87,7 @@ public class ComponentUtils { 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); @@ -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; + } }