1 package org.simantics.plant3d.scenegraph;
3 import java.util.HashMap;
6 import javax.vecmath.Point3d;
7 import javax.vecmath.Vector3d;
9 import org.simantics.g3d.math.MathTools;
10 import org.simantics.g3d.property.annotations.GetPropertyValue;
11 import org.simantics.g3d.property.annotations.SetPropertyValue;
12 import org.simantics.g3d.scenegraph.base.ParentNode;
13 import org.simantics.objmap.graph.annotations.DynamicGraphType;
14 import org.simantics.objmap.graph.annotations.GetType;
15 import org.simantics.objmap.graph.annotations.RelatedGetValue;
16 import org.simantics.objmap.graph.annotations.RelatedSetValue;
17 import org.simantics.objmap.graph.annotations.SetType;
18 import org.simantics.plant3d.ontology.Plant3D;
19 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
20 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
21 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
23 @DynamicGraphType(Plant3D.URIs.InlineComponent)
24 public class InlineComponent extends PipelineComponent {
27 private PipeControlPoint controlPoint;
28 private boolean componentCalculatedOffset = false;
30 @GetType(Plant3D.URIs.InlineComponent)
31 public String getType() {
35 @SetType(Plant3D.URIs.InlineComponent)
36 public void setType(String type) throws Exception{
38 controlPoint = ControlPointFactory.create(this);
43 public PipeControlPoint getControlPoint() {
48 public void setParent(ParentNode<?> parent, String name) {
49 super.setParent(parent, name);
50 setPipeRun((PipeRun)parent);
53 public boolean isVariableLength() {
54 return !controlPoint.isFixed();
57 public boolean isSizeChange() {
58 return controlPoint.isSizeChange();
61 @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
62 @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
63 public Double getRotationAngle() {
64 if (!controlPoint.isRotate())
66 Double d = controlPoint.getRotationAngle();
69 return MathTools.radToDeg(d);
72 @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
73 @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
74 public void setRotationAngle(Double angle) {
75 if (!controlPoint.isRotate())
78 if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
81 angle = MathTools.degToRad(angle);
82 if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
84 controlPoint.setRotationAngle(angle);
86 PipingRules.requestUpdate(getControlPoint());
87 } catch (Exception e) {
88 // TODO Auto-generated catch block
93 @RelatedGetValue(Plant3D.URIs.IsReversed)
94 @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
95 public Boolean isReversed() {
96 if (!controlPoint.isReverse())
98 Boolean d = controlPoint._getReversed();
101 @RelatedSetValue(Plant3D.URIs.IsReversed)
102 @SetPropertyValue(value=Plant3D.URIs.IsReversed)
103 public void setReversed(Boolean reverse) {
104 if (!controlPoint.isReverse())
107 if (reverse == null) {
110 controlPoint.setReversed(reverse);
112 PipingRules.requestUpdate(getControlPoint());
113 } catch (Exception e) {
114 // TODO Auto-generated catch block
120 public void updateParameters() {
121 super.updateParameters();
122 if (!isVariableLength()) {
123 Map<String,Object> calculated = getCalculatedParameters();
124 if (calculated.containsKey("length")) {
125 controlPoint.setLength((Double)calculated.get("length"));
127 if (calculated.containsKey("offset")) {
128 controlPoint.setOffset((Double)calculated.get("offset"));
129 componentCalculatedOffset = true;
131 componentCalculatedOffset = false;
137 public void setPipeRun(PipeRun pipeRun) {
138 // TODO Auto-generated method stub
139 super.setPipeRun(pipeRun);
140 if (getPipeRun() != null && getAlternativePipeRun() != null) {
146 public void setAlternativePipeRun(PipeRun pipeRun) {
147 // TODO Auto-generated method stub
148 super.setAlternativePipeRun(pipeRun);
149 if (getPipeRun() != null && getAlternativePipeRun() != null) {
154 private void updateOffset() {
155 if (!componentCalculatedOffset && getControlPoint().isOffset()) {
156 getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
161 public Map<String, Object> updateParameterMap() {
162 Map<String,Object> map = new HashMap<String, Object>();
163 if (controlPoint != null) {
164 if (!Double.isNaN(controlPoint.getLength()))
165 map.put("length", controlPoint.getLength());
166 if (controlPoint.isDualInline()) {
167 PipeControlPoint sub = controlPoint.getSubPoint().get(0);
168 PipeRun pipeRun2 = sub.getPipeRun();
169 if (pipeRun2 != null) {
170 map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
172 if (controlPoint.isOffset() && !componentCalculatedOffset) {
173 map.put("offset", controlPoint.getOffset());
178 PipeRun pipeRun = getPipeRun();
179 if (pipeRun != null) {
180 map.put("radius", pipeRun.getPipeDiameter() * 0.5);
185 @SetPropertyValue("flowlength")
186 public void setFlowLength(double l) {
187 // Not allowed, if not at the end of a run
188 if (getNext() != null)
189 throw new IllegalStateException("Cannot edit length of a connected component");
191 double length = getFlowLength();
192 Point3d p1 = new Point3d(), p2 = new Point3d();
193 controlPoint.getControlPointEnds(p1, p2);
194 Vector3d dir = new Vector3d();
197 dir.scale((l - length)/2);
198 Vector3d pos = new Vector3d(getPosition());