1 package org.simantics.plant3d.scenegraph;
3 import java.util.HashMap;
6 import javax.vecmath.Vector3d;
8 import org.simantics.g3d.math.MathTools;
9 import org.simantics.g3d.property.annotations.GetPropertyValue;
10 import org.simantics.g3d.property.annotations.SetPropertyValue;
11 import org.simantics.g3d.scenegraph.base.ParentNode;
12 import org.simantics.objmap.graph.annotations.DynamicGraphType;
13 import org.simantics.objmap.graph.annotations.GetType;
14 import org.simantics.objmap.graph.annotations.RelatedGetValue;
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 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
22 @DynamicGraphType(Plant3D.URIs.TurnComponent)
23 public class TurnComponent extends PipelineComponent {
27 private PipeControlPoint controlPoint;
28 private Integer turnRadiusIndex;
30 @GetType(Plant3D.URIs.TurnComponent)
31 public String getType() {
35 @SetType(Plant3D.URIs.TurnComponent)
36 public void setType(String type) throws Exception{
38 controlPoint = ControlPointFactory.create(this);
42 public PipeControlPoint getControlPoint() {
47 public void setParent(ParentNode<?> parent, String name) {
48 super.setParent(parent, name);
49 setPipeRun((PipeRun)parent);
53 public Map<String, Object> updateParameterMap() {
54 Map<String,Object> map = new HashMap<String, Object>();
56 if (getPipeRun() != null) {
57 map.put("turnRadius", getTurnRadius());
58 map.put("radius", getDiameter() * 0.5);
60 if (controlPoint != null && controlPoint.getTurnAngle() != null && !Double.isNaN(controlPoint.getTurnAngle())) {
61 map.put("turnAngle", controlPoint.getTurnAngle());
66 public boolean isVariableAngle() {
67 return !controlPoint.isFixed();
71 public void updateParameters() {
72 super.updateParameters();
73 if (!isVariableAngle()) {
74 Map<String,Object> calculated = getCalculatedParameters();
75 if (calculated.containsKey("length")) {
76 controlPoint.setLength((Double)calculated.get("length"));
78 PipingRules.requestUpdate(getControlPoint());
82 @RelatedGetValue(Plant3D.URIs.HasTurnAngle)
83 public Double getTurnAngle() {
84 return getControlPoint().getTurnAngle();
87 @RelatedSetValue(Plant3D.URIs.HasTurnAngle)
88 public void setTurnAngle(Double a) {
89 if (!getControlPoint().isFixed())
91 getControlPoint().setTurnAngle(a);
94 @GetPropertyValue(name="Turn Angle", value="turn angle", tabId = "Default")
95 public Double getTurnAngleDeg() {
96 Double d = getControlPoint().getTurnAngle();
99 return MathTools.radToDeg(d);
102 public Vector3d getTurnAxis() {
103 return getControlPoint().getTurnAxis();
106 @GetPropertyValue(name="Turn Radius", value=Plant3D.URIs.HasTurnRadius, tabId = "Default")
107 public Double getTurnRadius() {
108 if (turnRadiusIndex != null)
109 return getPipeRun().getTurnRadiusArray()[turnRadiusIndex];
110 return getPipeRun().getTurnRadiusArray()[0];
113 @RelatedGetValue(Plant3D.URIs.HasTurnRadiusIndex)
114 @GetPropertyValue(name="Turn Radius Index", value=Plant3D.URIs.HasTurnRadiusIndex, tabId = "Default")
115 public Integer getTurnRadiusIndex()
117 // TODO: For backwards compatibility, we do not accept null values.
118 // One development path would allow null index, and setting custom turn radius for the component.
119 if (turnRadiusIndex == null)
121 return turnRadiusIndex;
124 @RelatedSetValue(Plant3D.URIs.HasTurnRadiusIndex)
125 @SetPropertyValue(value=Plant3D.URIs.HasTurnRadiusIndex)
126 public void setTurnRadiusIndex(Integer turnRadiusIndex) {
127 if (this.turnRadiusIndex == turnRadiusIndex)
129 if (turnRadiusIndex == null)
131 if (turnRadiusIndex != null) {
132 if (getPipeRun().getTurnRadiusArray().length <= turnRadiusIndex)
135 this.turnRadiusIndex = turnRadiusIndex;
136 firePropertyChanged(Plant3D.URIs.HasTurnRadiusIndex);
137 PipingRules.requestUpdate(getControlPoint());
140 @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
141 @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
142 public Double getRotationAngle() {
143 if (!controlPoint.isFixed())
145 Double d = controlPoint.getRotationAngle();
148 return MathTools.radToDeg(d);
150 @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
151 @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
152 public void setRotationAngle(Double angle) {
153 if (!controlPoint.isFixed())
156 if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
159 angle = MathTools.degToRad(angle);
160 if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
162 controlPoint.setRotationAngle(angle);
163 PipingRules.requestUpdate(getControlPoint());
166 @RelatedGetValue(Plant3D.URIs.IsReversed)
167 @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
168 public Boolean isReversed() {
169 if (!controlPoint.isFixed())
171 Boolean d = controlPoint._getReversed();
174 @RelatedSetValue(Plant3D.URIs.IsReversed)
175 public void setReversed(Boolean reverse) {
176 if (!controlPoint.isFixed())
179 if (reverse == null) {
182 controlPoint.setReversed(reverse);
183 PipingRules.requestUpdate(getControlPoint());
187 protected double[] getColor() {
188 if (getControlPoint() == null || !getControlPoint().isFixed())
189 return new double[]{0.6,0.6,0.6};
191 return new double[]{1.0,0.0,0.0};