X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2FEquipment.java;h=214b632fdde54657d89e16b3c4321e451615a6c6;hb=HEAD;hp=3bac765c4a88754a7add24df614db98d70965280;hpb=22bb24d2a7e26c70b0dd4c57080f2c25ac3d40a8;p=simantics%2F3d.git 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..214b632f 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() { @@ -41,8 +45,12 @@ public class Equipment extends P3DParentGeometryNode { @RelatedElementsAdd(Plant3D.URIs.HasNozzle) public void addChild(Nozzle node) { + Collection children = getChild(); + if (numberOfFixedNozzles() > 0 && children.size() >= numberOfFixedNozzles()) + throw new RuntimeException("Equipment has already all fixed nozzles"); + Set ids = new HashSet(); - for (Nozzle n : getChild()) { + for (Nozzle n : children) { ids.add(n.getNozzleId()); } int newId = 0; @@ -50,6 +58,8 @@ public class Equipment extends P3DParentGeometryNode { newId++; addNode(Plant3D.URIs.HasNozzle,node); node.setNozzleId(newId); + if (fnp != null) + syncNozzles(); } @RelatedElementsGet(Plant3D.URIs.HasNozzle) @@ -74,6 +84,43 @@ public class Equipment extends P3DParentGeometryNode { @CompoundSetPropertyValue(value="parameters") public void setParameterMap(Map parameters) { super.setParameterMap(parameters); + syncNozzles(); + } + + @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; + updateParameters(); + 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