1 package org.simantics.plant3d.scenegraph;
3 import java.util.Collection;
4 import java.util.HashSet;
9 import javax.vecmath.Quat4d;
10 import javax.vecmath.Vector3d;
12 import org.simantics.g3d.math.MathTools;
13 import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
14 import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
15 import org.simantics.g3d.scenegraph.GeometryProvider;
16 import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue;
17 import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue;
18 import org.simantics.objmap.graph.annotations.DynamicGraphType;
19 import org.simantics.objmap.graph.annotations.GetType;
20 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
21 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
22 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
23 import org.simantics.objmap.graph.annotations.SetType;
24 import org.simantics.plant3d.geometry.FixedNozzleProvider;
25 import org.simantics.plant3d.ontology.Plant3D;
26 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
29 @DynamicGraphType(Plant3D.URIs.Equipment)
30 public class Equipment extends P3DParentGeometryNode<Nozzle> {
33 private FixedNozzleProvider fnp;
35 @GetType(Plant3D.URIs.Equipment)
36 public String getType() {
40 @SetType(Plant3D.URIs.Equipment)
41 public void setType(String type) {
46 @RelatedElementsAdd(Plant3D.URIs.HasNozzle)
47 public void addChild(Nozzle node) {
48 Collection<Nozzle> children = getChild();
49 if (numberOfFixedNozzles() > 0 && children.size() >= numberOfFixedNozzles())
50 throw new RuntimeException("Equipment has already all fixed nozzles");
52 Set<Integer> ids = new HashSet<Integer>();
53 for (Nozzle n : children) {
54 ids.add(n.getNozzleId());
57 while (ids.contains(newId))
59 addNode(Plant3D.URIs.HasNozzle,node);
60 node.setNozzleId(newId);
65 @RelatedElementsGet(Plant3D.URIs.HasNozzle)
66 public Collection<Nozzle> getChild() {
67 return getNodes(Plant3D.URIs.HasNozzle);
70 @RelatedElementsRem(Plant3D.URIs.HasNozzle)
71 public void remChild(Nozzle node) {
72 removeNode(Plant3D.URIs.HasNozzle, node);
76 @CompoundRelatedGetValue(objRelation=Plant3D.URIs.hasParameter,objType=Plant3D.URIs.Parameter,valRelation=Plant3D.URIs.hasParameterValue)
77 @CompoundGetPropertyValue(name="Parameters",tabId="Parameters",value="parameters")
78 public Map<String, Object> getParameterMap() {
79 return super.getParameterMap();
83 @CompoundRelatedSetValue(Plant3D.URIs.hasParameter)
84 @CompoundSetPropertyValue(value="parameters")
85 public void setParameterMap(Map<String, Object> parameters) {
86 super.setParameterMap(parameters);
91 public void setGeometry(GeometryProvider provider) {
92 super.setGeometry(provider);
93 if (provider instanceof FixedNozzleProvider) {
94 fnp = (FixedNozzleProvider)provider;
99 public int numberOfFixedNozzles() {
102 return fnp.numberOfNozzles();
106 * Synchronizes fixed nozzles.
108 * Note: this method does not create nozzles, just sets their positions and names.
110 public void syncNozzles() {
114 int count = fnp.numberOfNozzles();
115 List<Nozzle> currentNozzles = getNodes();
116 for (int i = 0; i < count; i++) {
117 if (i < currentNozzles.size()) {
118 Nozzle nozzle = currentNozzles.get(i);
119 nozzle.setName(fnp.getNozzleName(i));
120 fnp.updateNozzlePosition(i, nozzle);
121 nozzle.setFixed(true);
127 protected double[] getColor() {
128 return new double[]{1,0,0};
132 protected double[] getSelectedColor() {
133 return new double[]{0.5,0,0.5};
137 public void setPosition(Vector3d position) {
138 if (MathTools.equals(position, getPosition()))
140 super.setPosition(position);
141 for (Nozzle n : getChild()) {
142 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
143 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
145 for (Nozzle n : getChild()) {
147 PipingRules.requestUpdate(n.getControlPoint());
148 } catch (Exception e) {
155 public void setOrientation(Quat4d orientation) {
156 if (MathTools.equals(orientation, getOrientation()))
158 super.setOrientation(orientation);
159 for (Nozzle n : getChild()) {
160 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
161 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
163 for (Nozzle n : getChild()) {
165 PipingRules.requestUpdate(n.getControlPoint());
166 } catch (Exception e) {