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 isModifialble() {
58 return controlPoint.isMod();
61 public boolean isSizeChange() {
62 return controlPoint.isSizeChange();
65 @RelatedGetValue(Plant3D.URIs.HasRotationAngle)
66 @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default")
67 public Double getRotationAngle() {
68 if (!controlPoint.isRotate())
70 Double d = controlPoint.getRotationAngle();
73 return MathTools.radToDeg(d);
76 @RelatedSetValue(Plant3D.URIs.HasRotationAngle)
77 @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle)
78 public void setRotationAngle(Double angle) {
79 if (!controlPoint.isRotate())
82 if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) {
85 angle = MathTools.degToRad(angle);
86 if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
88 controlPoint.setRotationAngle(angle);
90 PipingRules.requestUpdate(getControlPoint());
91 } catch (Exception e) {
92 // TODO Auto-generated catch block
97 @RelatedGetValue(Plant3D.URIs.IsReversed)
98 @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
99 public Boolean isReversed() {
100 if (!controlPoint.isReverse())
102 Boolean d = controlPoint._getReversed();
105 @RelatedSetValue(Plant3D.URIs.IsReversed)
106 @SetPropertyValue(value=Plant3D.URIs.IsReversed)
107 public void setReversed(Boolean reverse) {
108 if (!controlPoint.isReverse())
111 if (reverse == null) {
114 controlPoint.setReversed(reverse);
116 PipingRules.requestUpdate(getControlPoint());
117 } catch (Exception e) {
118 // TODO Auto-generated catch block
124 public void updateParameters() {
125 super.updateParameters();
126 if (!isVariableLength()) {
127 Map<String,Object> calculated = getCalculatedParameters();
129 if (calculated.containsKey("offset")) {
130 controlPoint.setOffset((Double)calculated.get("offset"));
131 componentCalculatedOffset = true;
133 componentCalculatedOffset = false;
136 Map<String,Object> total = getTotalParameters();
138 if (total.containsKey("length")) {
139 controlPoint.setLength((Double)total.get("length"));
142 PipingRules.requestUpdate(getControlPoint());
147 public void setPipeRun(PipeRun pipeRun) {
148 // TODO Auto-generated method stub
149 super.setPipeRun(pipeRun);
150 if (getPipeRun() != null && getAlternativePipeRun() != null) {
156 public void setAlternativePipeRun(PipeRun pipeRun) {
157 // TODO Auto-generated method stub
158 super.setAlternativePipeRun(pipeRun);
159 if (getPipeRun() != null && getAlternativePipeRun() != null) {
164 private void updateOffset() {
165 if (!componentCalculatedOffset && getControlPoint().isOffset()) {
166 getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
171 public Map<String, Object> updateParameterMap() {
172 Map<String,Object> map = new HashMap<String, Object>();
173 if (controlPoint != null) {
174 if (!Double.isNaN(controlPoint.getLength()) && controlPoint.isVariableLength())
175 map.put("length", controlPoint.getLength());
176 if (controlPoint.isDualInline()) {
177 PipeControlPoint sub = controlPoint.getDualSub();
178 PipeRun pipeRun2 = sub.getPipeRun();
179 if (pipeRun2 != null) {
180 map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
182 if (controlPoint.isOffset() && !componentCalculatedOffset) {
183 map.put("offset", controlPoint.getOffset());
188 PipeRun pipeRun = getPipeRun();
189 if (pipeRun != null) {
190 map.put("radius", pipeRun.getPipeDiameter() * 0.5);
195 @SetPropertyValue("flowlength")
196 public void setFlowLength(double l) {
197 // Not allowed, if not at the end of a run
198 if (getNext() != null)
199 throw new IllegalStateException("Cannot edit length of a connected component");
201 double length = getFlowLength();
202 Point3d p1 = new Point3d(), p2 = new Point3d();
203 controlPoint.getControlPointEnds(p1, p2);
204 Vector3d dir = new Vector3d();
207 dir.scale((l - length)/2);
208 Vector3d pos = new Vector3d(getPosition());