]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java
Remove listener calls when property values not updated.
[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                 if (this.getPipeRun() == pipeRun)
87                         return;
88                 
89                 super.setPipeRun(pipeRun);
90                 try {
91                         _createCP();
92                 } catch (Exception e) {
93                         // TODO Auto-generated catch block
94                         e.printStackTrace();
95                 }
96                 
97                 firePropertyChanged(Plant3D.URIs.HasPipeRun);
98         }
99         
100         @RelatedGetObj(Plant3D.URIs.HasPipeRun)
101         @Override
102         public PipeRun getPipeRun() {
103                 return super.getPipeRun();
104         }
105         
106         @Override
107         public PipeControlPoint getControlPoint() {
108                 return controlPoint;
109         }
110         
111         
112         @Override
113         public void setPosition(Vector3d position) {
114                 super.setPosition(position);
115                 updateCP();
116         }
117         
118         @Override
119         public void setOrientation(Quat4d orientation) {
120                 super.setOrientation(orientation);
121                 updateCP();
122         }
123         
124         private void updateCP() {
125                 if (controlPoint == null)
126                         return;
127                 if (controlPoint.getPipeRun() == null)
128                         return;
129                 controlPoint._setWorldPosition(getWorldPosition());
130                 controlPoint._setWorldOrientation(getWorldOrientation());
131         }
132         
133         
134         @Override
135         public Map<String, Object> updateParameterMap() {
136                 Map<String,Object> map = new HashMap<String, Object>();
137                 
138                 PipeRun pipeRun = getPipeRun();
139                 if (pipeRun != null) {
140                         //map.put("length", pipeRun.getPipeDiameter() * 2.0);
141                         map.put("radius", pipeRun.getPipeDiameter() * 0.5);
142                 }
143                 return map;
144         }
145         
146         @Override
147         protected double[] getColor() {
148                 return new double[]{0.7,0.7,0.7};
149         }
150         
151         @Override
152         protected double[] getSelectedColor() {
153                 return new double[]{0.5,0,0.5};
154         }
155         
156         public boolean isConnected() {
157                 PipeControlPoint pcp = getControlPoint();
158                 return (pcp.getNext() != null || pcp.getPrevious() != null);
159         }
160         
161         public boolean isNextConnected() {
162                 PipeControlPoint pcp = getControlPoint();
163                 return (pcp.getNext() != null);
164         }
165         
166         public boolean isPrevConnected() {
167                 PipeControlPoint pcp = getControlPoint();
168                 return (pcp.getNext() != null);
169         }
170         
171
172 }