]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java
Fix orientation of new straight components in insertStraight
[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 boolean fixed = false;
57         
58         @RelatedGetValue(Plant3D.URIs.IsFixedNozzle)
59         @GetPropertyValue(name="Fixed", value=Plant3D.URIs.IsFixedNozzle, tabId="Default")
60         public boolean isFixed() {
61                 return fixed;
62         }
63         
64         @RelatedSetValue(Plant3D.URIs.IsFixedNozzle)
65         public void setFixed(boolean fixed) {
66                 if (fixed == this.fixed)
67                         return;
68                 this.fixed = fixed;
69                 firePropertyChanged(Plant3D.URIs.IsFixedNozzle);
70         }
71         
72         private void _createCP() throws Exception{
73                 if (controlPoint != null)
74                         return;
75                 controlPoint = ControlPointFactory.create(this);
76                 // TODO : these should not be needed.
77                 controlPoint.setDeletable(false);
78                 controlPoint.setFixed(true);
79                 syncNext();
80         syncPrevious();
81         }
82         
83         @RelatedSetObj(Plant3D.URIs.HasPipeRun)
84         @Override
85         public void setPipeRun(PipeRun pipeRun) {
86                 super.setPipeRun(pipeRun);
87                 try {
88                         _createCP();
89                 } catch (Exception e) {
90                         // TODO Auto-generated catch block
91                         e.printStackTrace();
92                 }
93                 
94                 firePropertyChanged(Plant3D.URIs.HasPipeRun);
95         }
96         
97         @RelatedGetObj(Plant3D.URIs.HasPipeRun)
98         @Override
99         public PipeRun getPipeRun() {
100                 return super.getPipeRun();
101         }
102         
103         @Override
104         public PipeControlPoint getControlPoint() {
105                 return controlPoint;
106         }
107         
108         
109         @Override
110         public void setPosition(Vector3d position) {
111                 super.setPosition(position);
112                 updateCP();
113         }
114         
115         @Override
116         public void setOrientation(Quat4d orientation) {
117                 super.setOrientation(orientation);
118                 updateCP();
119         }
120         
121         private void updateCP() {
122                 if (controlPoint == null)
123                         return;
124                 if (controlPoint.getPipeRun() == null)
125                         return;
126                 controlPoint._setWorldPosition(getWorldPosition());
127                 controlPoint._setWorldOrientation(getWorldOrientation());
128         }
129         
130         
131         @Override
132         public Map<String, Object> updateParameterMap() {
133                 Map<String,Object> map = new HashMap<String, Object>();
134                 
135                 PipeRun pipeRun = getPipeRun();
136                 if (pipeRun != null) {
137                         //map.put("length", pipeRun.getPipeDiameter() * 2.0);
138                         map.put("radius", pipeRun.getPipeDiameter() * 0.5);
139                 }
140                 return map;
141         }
142         
143         @Override
144         protected double[] getColor() {
145                 return new double[]{0.7,0.7,0.7};
146         }
147         
148         @Override
149         protected double[] getSelectedColor() {
150                 return new double[]{0.5,0,0.5};
151         }
152         
153         public boolean isConnected() {
154                 PipeControlPoint pcp = getControlPoint();
155                 return (pcp.getNext() != null || pcp.getPrevious() != null);
156         }
157         
158         public boolean isNextConnected() {
159                 PipeControlPoint pcp = getControlPoint();
160                 return (pcp.getNext() != null);
161         }
162         
163         public boolean isPrevConnected() {
164                 PipeControlPoint pcp = getControlPoint();
165                 return (pcp.getNext() != null);
166         }
167         
168
169 }