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);
90 public void setGeometry(GeometryProvider provider) {
91 super.setGeometry(provider);
92 if (provider instanceof FixedNozzleProvider) {
93 fnp = (FixedNozzleProvider)provider;
98 public int numberOfFixedNozzles() {
101 return fnp.numberOfNozzles();
105 * Synchronizes fixed nozzles.
107 * Note: this method does not create nozzles, just sets their positions and names.
109 public void syncNozzles() {
113 int count = fnp.numberOfNozzles();
114 List<Nozzle> currentNozzles = getNodes();
115 for (int i = 0; i < count; i++) {
116 if (i < currentNozzles.size()) {
117 Nozzle nozzle = currentNozzles.get(i);
118 nozzle.setName(fnp.getNozzleName(i));
119 fnp.updateNozzlePosition(i, nozzle);
120 nozzle.setFixed(true);
126 protected double[] getColor() {
127 return new double[]{1,0,0};
131 protected double[] getSelectedColor() {
132 return new double[]{0.5,0,0.5};
136 public void setPosition(Vector3d position) {
137 if (MathTools.equals(position, getPosition()))
139 super.setPosition(position);
140 for (Nozzle n : getChild()) {
141 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
142 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
144 for (Nozzle n : getChild()) {
146 PipingRules.requestUpdate(n.getControlPoint());
147 } catch (Exception e) {
154 public void setOrientation(Quat4d orientation) {
155 if (MathTools.equals(orientation, getOrientation()))
157 super.setOrientation(orientation);
158 for (Nozzle n : getChild()) {
159 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
160 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
162 for (Nozzle n : getChild()) {
164 PipingRules.requestUpdate(n.getControlPoint());
165 } catch (Exception e) {