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 Set<Integer> ids = new HashSet<Integer>();
49 for (Nozzle n : getChild()) {
50 ids.add(n.getNozzleId());
53 while (ids.contains(newId))
55 addNode(Plant3D.URIs.HasNozzle,node);
56 node.setNozzleId(newId);
61 @RelatedElementsGet(Plant3D.URIs.HasNozzle)
62 public Collection<Nozzle> getChild() {
63 return getNodes(Plant3D.URIs.HasNozzle);
66 @RelatedElementsRem(Plant3D.URIs.HasNozzle)
67 public void remChild(Nozzle node) {
68 removeNode(Plant3D.URIs.HasNozzle, node);
72 @CompoundRelatedGetValue(objRelation=Plant3D.URIs.hasParameter,objType=Plant3D.URIs.Parameter,valRelation=Plant3D.URIs.hasParameterValue)
73 @CompoundGetPropertyValue(name="Parameters",tabId="Parameters",value="parameters")
74 public Map<String, Object> getParameterMap() {
75 return super.getParameterMap();
79 @CompoundRelatedSetValue(Plant3D.URIs.hasParameter)
80 @CompoundSetPropertyValue(value="parameters")
81 public void setParameterMap(Map<String, Object> parameters) {
82 super.setParameterMap(parameters);
86 public void setGeometry(GeometryProvider provider) {
87 super.setGeometry(provider);
88 if (provider instanceof FixedNozzleProvider) {
89 fnp = (FixedNozzleProvider)provider;
94 public int numberOfFixedNozzles() {
97 return fnp.numberOfNozzles();
101 * Synchronizes fixed nozzles.
103 * Note: this method does not create nozzles, just sets their positions and names.
105 public void syncNozzles() {
109 int count = fnp.numberOfNozzles();
110 List<Nozzle> currentNozzles = getNodes();
111 for (int i = 0; i < count; i++) {
112 if (i < currentNozzles.size()) {
113 Nozzle nozzle = currentNozzles.get(i);
114 nozzle.setName(fnp.getNozzleName(i));
115 fnp.updateNozzlePosition(i, nozzle);
116 nozzle.setFixed(true);
122 protected double[] getColor() {
123 return new double[]{1,0,0};
127 protected double[] getSelectedColor() {
128 return new double[]{0.5,0,0.5};
132 public void setPosition(Vector3d position) {
133 if (MathTools.equals(position, getPosition()))
135 super.setPosition(position);
136 for (Nozzle n : getChild()) {
137 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
138 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
140 for (Nozzle n : getChild()) {
142 PipingRules.requestUpdate(n.getControlPoint());
143 } catch (Exception e) {
150 public void setOrientation(Quat4d orientation) {
151 if (MathTools.equals(orientation, getOrientation()))
153 super.setOrientation(orientation);
154 for (Nozzle n : getChild()) {
155 n.getControlPoint()._setWorldPosition(n.getWorldPosition());
156 n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
158 for (Nozzle n : getChild()) {
160 PipingRules.requestUpdate(n.getControlPoint());
161 } catch (Exception e) {