1 package org.simantics.plant3d.scenegraph;
3 import java.util.HashMap;
6 import org.simantics.g3d.math.MathTools;
7 import org.simantics.g3d.property.annotations.GetPropertyValue;
8 import org.simantics.g3d.property.annotations.SetPropertyValue;
9 import org.simantics.g3d.scenegraph.base.ParentNode;
10 import org.simantics.objmap.graph.annotations.DynamicGraphType;
11 import org.simantics.objmap.graph.annotations.GetType;
12 import org.simantics.objmap.graph.annotations.RelatedGetValue;
13 import org.simantics.objmap.graph.annotations.RelatedSetValue;
14 import org.simantics.objmap.graph.annotations.SetType;
15 import org.simantics.plant3d.ontology.Plant3D;
16 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
17 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
18 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
20 @DynamicGraphType(Plant3D.URIs.InlineComponent)
21 public class InlineComponent extends PipelineComponent {
24 private PipeControlPoint controlPoint;
25 private boolean componentCalculatedOffset = false;
27 @GetType(Plant3D.URIs.InlineComponent)
28 public String getType() {
32 @SetType(Plant3D.URIs.InlineComponent)
33 public void setType(String type) throws Exception{
35 controlPoint = ControlPointFactory.create(this);
40 public PipeControlPoint getControlPoint() {
45 public void setParent(ParentNode<?> parent, String name) {
46 super.setParent(parent, name);
47 setPipeRun((PipeRun)parent);
50 public boolean isVariableLength() {
51 return !controlPoint.isFixed();
54 public boolean isSizeChange() {
55 return controlPoint.isSizeChange();
58 @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
59 @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
60 public Double getRotationAngle() {
61 if (!controlPoint.isRotate())
63 Double d = controlPoint.getRotationAngle();
66 return MathTools.radToDeg(d);
68 @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
69 @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
70 public void setRotationAngle(Double angle) {
71 if (!controlPoint.isRotate())
74 if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
77 angle = MathTools.degToRad(angle);
78 if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
80 controlPoint.setRotationAngle(angle);
82 PipingRules.requestUpdate(getControlPoint());
83 } catch (Exception e) {
84 // TODO Auto-generated catch block
89 @RelatedGetValue(Plant3D.URIs.IsReversed)
90 @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
91 public Boolean isReversed() {
92 if (!controlPoint.isReverse())
94 Boolean d = controlPoint.getReversed();
99 @RelatedSetValue(Plant3D.URIs.IsReversed)
100 @SetPropertyValue(value=Plant3D.URIs.IsReversed)
101 public void setReversed(Boolean reverse) {
102 if (!controlPoint.isReverse())
105 if (reverse == null) {
108 controlPoint.setReversed(reverse);
110 PipingRules.requestUpdate(getControlPoint());
111 } catch (Exception e) {
112 // TODO Auto-generated catch block
118 public void updateParameters() {
119 super.updateParameters();
120 if (!isVariableLength()) {
121 Map<String,Object> calculated = getCalculatedParameters();
122 if (calculated.containsKey("length")) {
123 controlPoint.setLength((Double)calculated.get("length"));
125 if (calculated.containsKey("offset")) {
126 controlPoint.setOffset((Double)calculated.get("offset"));
127 componentCalculatedOffset = true;
129 componentCalculatedOffset = false;
135 public void setPipeRun(PipeRun pipeRun) {
136 // TODO Auto-generated method stub
137 super.setPipeRun(pipeRun);
138 if (getPipeRun() != null && getAlternativePipeRun() != null) {
144 public void setAlternativePipeRun(PipeRun pipeRun) {
145 // TODO Auto-generated method stub
146 super.setAlternativePipeRun(pipeRun);
147 if (getPipeRun() != null && getAlternativePipeRun() != null) {
152 private void updateOffset() {
153 if (!componentCalculatedOffset && getControlPoint().isOffset()) {
154 getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
159 public Map<String, Object> updateParameterMap() {
160 Map<String,Object> map = new HashMap<String, Object>();
161 if (controlPoint != null) {
162 if (!Double.isNaN(controlPoint.getLength()))
163 map.put("length", controlPoint.getLength());
164 if (controlPoint.isDualInline()) {
165 PipeControlPoint sub = controlPoint.getSubPoint().get(0);
166 PipeRun pipeRun2 = sub.getPipeRun();
167 if (pipeRun2 != null) {
168 map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
170 if (controlPoint.isOffset() && !componentCalculatedOffset) {
171 map.put("offset", controlPoint.getOffset());
176 PipeRun pipeRun = getPipeRun();
177 if (pipeRun != null) {
178 map.put("radius", pipeRun.getPipeDiameter() * 0.5);