]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java
Added support for eccentric reducers
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / scenegraph / Nozzle.java
1 package org.simantics.plant3d.scenegraph;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.vecmath.Quat4d;
7 import javax.vecmath.Vector3d;
8
9 import org.simantics.g3d.property.annotations.GetPropertyValue;
10 import org.simantics.objmap.graph.annotations.DynamicGraphType;
11 import org.simantics.objmap.graph.annotations.GetType;
12 import org.simantics.objmap.graph.annotations.RelatedGetObj;
13 import org.simantics.objmap.graph.annotations.RelatedGetValue;
14 import org.simantics.objmap.graph.annotations.RelatedSetObj;
15 import org.simantics.objmap.graph.annotations.RelatedSetValue;
16 import org.simantics.objmap.graph.annotations.SetType;
17 import org.simantics.plant3d.ontology.Plant3D;
18 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
19 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
20
21
22 @DynamicGraphType(Plant3D.URIs.Nozzle)
23 public class Nozzle extends PipelineComponent {
24         
25         private String type;
26         private PipeControlPoint controlPoint;
27         
28         @GetType(Plant3D.URIs.Nozzle)
29         public String getType() {
30                 return type;
31         }
32         
33         @SetType(Plant3D.URIs.Nozzle)
34         public void setType(String type) throws Exception{
35                 this.type = type;
36                 _createCP();
37                 
38         }
39         
40         private int id = 0;
41         
42         @RelatedGetValue(Plant3D.URIs.HasNozzleId)
43         @GetPropertyValue(name="Nozzle ID", value=Plant3D.URIs.HasNozzleId, tabId="Default")
44         public int getNozzleId() {
45                 return id;
46         }
47         
48         @RelatedSetValue(Plant3D.URIs.HasNozzleId)
49         public void setNozzleId(int id) {
50                 if (id == this.id)
51                         return;
52                 this.id = id;
53                 firePropertyChanged(Plant3D.URIs.HasNozzleId);
54         }
55         
56         private void _createCP() throws Exception{
57                 if (controlPoint != null)
58                         return;
59                 if (getPipeRun() != null) {
60                         controlPoint = ControlPointFactory.create(this);
61                         // TODO : these should not be needed.
62                         controlPoint.setDeletable(false);
63                         controlPoint.setFixed(true);
64                 }
65         }
66         
67         @RelatedSetObj(Plant3D.URIs.HasPipeRun)
68         @Override
69         public void setPipeRun(PipeRun pipeRun) {
70                 super.setPipeRun(pipeRun);
71                 try {
72                         _createCP();
73                 } catch (Exception e) {
74                         // TODO Auto-generated catch block
75                         e.printStackTrace();
76                 }
77                 
78                 firePropertyChanged(Plant3D.URIs.HasPipeRun);
79         }
80         
81         @RelatedGetObj(Plant3D.URIs.HasPipeRun)
82         @Override
83         public PipeRun getPipeRun() {
84                 return super.getPipeRun();
85         }
86         
87         @Override
88         public PipeControlPoint getControlPoint() {
89                 return controlPoint;
90         }
91         
92         
93         @Override
94         public void setPosition(Vector3d position) {
95                 super.setPosition(position);
96                 updateCP();
97         }
98         
99         @Override
100         public void setOrientation(Quat4d orientation) {
101                 super.setOrientation(orientation);
102                 updateCP();
103         }
104         
105         private void updateCP() {
106                 if (controlPoint == null)
107                         return;
108                 if (controlPoint.getPipeRun() == null)
109                         return;
110                 controlPoint._setWorldPosition(getWorldPosition());
111                 controlPoint._setWorldOrientation(getWorldOrientation());
112         }
113         
114         
115         @Override
116         public Map<String, Object> updateParameterMap() {
117                 Map<String,Object> map = new HashMap<String, Object>();
118                 
119                 PipeRun pipeRun = getPipeRun();
120                 if (pipeRun != null) {
121                         map.put("length", pipeRun.getPipeDiameter() * 2.0);
122                         map.put("radius", pipeRun.getPipeDiameter() * 0.5);
123                 }
124                 return map;
125         }
126         
127         @Override
128         protected double[] getColor() {
129                 return new double[]{0.7,0.7,0.7};
130         }
131         
132         @Override
133         protected double[] getSelectedColor() {
134                 return new double[]{0.5,0,0.5};
135         }
136         
137         public boolean isConnected() {
138                 PipeControlPoint pcp = getControlPoint();
139                 return (pcp.getNext() != null || pcp.getPrevious() != null);
140         }
141         
142         public boolean isNextConnected() {
143                 PipeControlPoint pcp = getControlPoint();
144                 return (pcp.getNext() != null);
145         }
146         
147         public boolean isPrevConnected() {
148                 PipeControlPoint pcp = getControlPoint();
149                 return (pcp.getNext() != null);
150         }
151         
152
153 }