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 @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
55 @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
56 public Double getRotationAngle() {
57 if (!controlPoint.isRotate())
59 Double d = controlPoint.getRotationAngle();
62 return MathTools.radToDeg(d);
64 @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
65 @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
66 public void setRotationAngle(Double angle) {
67 if (!controlPoint.isRotate())
70 if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
73 angle = MathTools.degToRad(angle);
74 if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
76 controlPoint.setRotationAngle(angle);
78 PipingRules.requestUpdate(getControlPoint());
79 } catch (Exception e) {
80 // TODO Auto-generated catch block
85 @RelatedGetValue(Plant3D.URIs.IsReversed)
86 @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
87 public Boolean isReversed() {
88 if (!controlPoint.isReverse())
90 Boolean d = controlPoint.getReversed();
95 @RelatedSetValue(Plant3D.URIs.IsReversed)
96 @SetPropertyValue(value=Plant3D.URIs.IsReversed)
97 public void setReverse(Boolean reverse) {
98 if (!controlPoint.isReverse())
101 if (reverse == null) {
104 controlPoint.setReversed(reverse);
106 PipingRules.requestUpdate(getControlPoint());
107 } catch (Exception e) {
108 // TODO Auto-generated catch block
114 public void updateParameters() {
115 super.updateParameters();
116 if (!isVariableLength()) {
117 Map<String,Object> calculated = getCalculatedParameters();
118 if (calculated.containsKey("length")) {
119 controlPoint.setLength((Double)calculated.get("length"));
121 if (calculated.containsKey("offset")) {
122 controlPoint.setOffset((Double)calculated.get("offset"));
123 componentCalculatedOffset = true;
125 componentCalculatedOffset = false;
131 public void setPipeRun(PipeRun pipeRun) {
132 // TODO Auto-generated method stub
133 super.setPipeRun(pipeRun);
134 if (getPipeRun() != null && getAlternativePipeRun() != null) {
140 public void setAlternativePipeRun(PipeRun pipeRun) {
141 // TODO Auto-generated method stub
142 super.setAlternativePipeRun(pipeRun);
143 if (getPipeRun() != null && getAlternativePipeRun() != null) {
148 private void updateOffset() {
149 if (!componentCalculatedOffset && getControlPoint().isOffset()) {
150 getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
155 public Map<String, Object> updateParameterMap() {
156 Map<String,Object> map = new HashMap<String, Object>();
157 if (controlPoint != null) {
158 if (!Double.isNaN(controlPoint.getLength()))
159 map.put("length", controlPoint.getLength());
160 if (controlPoint.isDualInline()) {
161 PipeControlPoint sub = controlPoint.getSubPoint().get(0);
162 PipeRun pipeRun2 = sub.getPipeRun();
163 if (pipeRun2 != null) {
164 map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
166 if (controlPoint.isOffset() && !componentCalculatedOffset) {
167 map.put("offset", controlPoint.getOffset());
172 PipeRun pipeRun = getPipeRun();
173 if (pipeRun != null) {
174 map.put("radius", pipeRun.getPipeDiameter() * 0.5);