]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java
White space clean-up
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / Equipment.java
index 3bac765c4a88754a7add24df614db98d70965280..214b632fdde54657d89e16b3c4321e451615a6c6 100644 (file)
@@ -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<Nozzle> {
 
        private String type;
+       private FixedNozzleProvider fnp;
        
        @GetType(Plant3D.URIs.Equipment)
        public String getType() {
@@ -41,8 +45,12 @@ public class Equipment extends P3DParentGeometryNode<Nozzle> {
        
        @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;
@@ -50,6 +58,8 @@ public class Equipment extends P3DParentGeometryNode<Nozzle> {
                        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<Nozzle> {
        @CompoundSetPropertyValue(value="parameters")
        public void setParameterMap(Map<String, Object> 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<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