import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
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;
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;
public class Equipment extends P3DParentGeometryNode<Nozzle> {
private String type;
+ private FixedNozzleProvider fnp;
@GetType(Plant3D.URIs.Equipment)
public String getType() {
@RelatedElementsAdd(Plant3D.URIs.HasNozzle)
public void addChild(Nozzle node) {
+ Collection<Nozzle> children = getChild();
+ if (numberOfFixedNozzles() > 0 && children.size() >= numberOfFixedNozzles())
+ throw new RuntimeException("Equipment has already all fixed nozzles");
+
Set<Integer> ids = new HashSet<Integer>();
- for (Nozzle n : getChild()) {
+ for (Nozzle n : children) {
ids.add(n.getNozzleId());
}
int newId = 0;
newId++;
addNode(Plant3D.URIs.HasNozzle,node);
node.setNozzleId(newId);
+ if (fnp != null)
+ syncNozzles();
}
@RelatedElementsGet(Plant3D.URIs.HasNozzle)
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<Nozzle> 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};