]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java
3bac765c4a88754a7add24df614db98d70965280
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / Equipment.java
1 package org.simantics.plant3d.scenegraph;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
8 import javax.vecmath.Quat4d;
9 import javax.vecmath.Vector3d;
10
11 import org.simantics.g3d.math.MathTools;
12 import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
13 import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
14 import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue;
15 import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue;
16 import org.simantics.objmap.graph.annotations.DynamicGraphType;
17 import org.simantics.objmap.graph.annotations.GetType;
18 import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
19 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
20 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
21 import org.simantics.objmap.graph.annotations.SetType;
22 import org.simantics.plant3d.ontology.Plant3D;
23 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
24
25
26 @DynamicGraphType(Plant3D.URIs.Equipment)
27 public class Equipment extends P3DParentGeometryNode<Nozzle> {
28
29         private String type;
30         
31         @GetType(Plant3D.URIs.Equipment)
32         public String getType() {
33                 return type;
34         }
35         
36         @SetType(Plant3D.URIs.Equipment)
37         public void setType(String type) {
38                 this.type = type;
39         }
40         
41         
42         @RelatedElementsAdd(Plant3D.URIs.HasNozzle)
43         public void addChild(Nozzle node) {
44                 Set<Integer> ids = new HashSet<Integer>();
45                 for (Nozzle n : getChild()) {
46                         ids.add(n.getNozzleId());
47                 }
48                 int newId = 0;
49                 while (ids.contains(newId))
50                         newId++;
51                 addNode(Plant3D.URIs.HasNozzle,node);
52                 node.setNozzleId(newId);
53         }
54         
55         @RelatedElementsGet(Plant3D.URIs.HasNozzle)
56         public Collection<Nozzle> getChild() {
57                 return getNodes(Plant3D.URIs.HasNozzle);
58         }
59         
60         @RelatedElementsRem(Plant3D.URIs.HasNozzle)
61         public void remChild(Nozzle node) {
62                 removeNode(Plant3D.URIs.HasNozzle, node);
63         }
64         
65         @Override
66         @CompoundRelatedGetValue(objRelation=Plant3D.URIs.hasParameter,objType=Plant3D.URIs.Parameter,valRelation=Plant3D.URIs.hasParameterValue)
67         @CompoundGetPropertyValue(name="Parameters",tabId="Parameters",value="parameters")
68         public Map<String, Object> getParameterMap() {
69                 return super.getParameterMap();
70         }
71         
72         @Override
73         @CompoundRelatedSetValue(Plant3D.URIs.hasParameter)
74         @CompoundSetPropertyValue(value="parameters")
75         public void setParameterMap(Map<String, Object> parameters) {
76                 super.setParameterMap(parameters);
77         }
78         
79         @Override
80         protected double[] getColor() {
81                 return new double[]{1,0,0};
82         }
83         
84         @Override
85         protected double[] getSelectedColor() {
86                 return new double[]{0.5,0,0.5};
87         }
88         
89         @Override
90         public void setPosition(Vector3d position) {
91                 if (MathTools.equals(position, getPosition()))
92                         return;
93                 super.setPosition(position);
94                 for (Nozzle n : getChild()) {
95                         n.getControlPoint()._setWorldPosition(n.getWorldPosition());
96                         n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
97                 }
98                 for (Nozzle n : getChild()) {
99                         try {
100                                 PipingRules.requestUpdate(n.getControlPoint());
101                         } catch (Exception e) {
102                                 e.printStackTrace();
103                         }
104                 }
105         }
106         
107         @Override
108         public void setOrientation(Quat4d orientation) {
109                 if (MathTools.equals(orientation, getOrientation()))
110                         return;
111                 super.setOrientation(orientation);
112                 for (Nozzle n : getChild()) {
113                         n.getControlPoint()._setWorldPosition(n.getWorldPosition());
114                         n.getControlPoint()._setWorldOrientation(n.getWorldOrientation());
115                 }
116                 for (Nozzle n : getChild()) {
117                         try {
118                                 PipingRules.requestUpdate(n.getControlPoint());
119                         } catch (Exception e) {
120                                 e.printStackTrace();
121                         }
122                 }
123         }
124
125 }