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
86 public void updateParameters() {
87 super.updateParameters();
88 if (!isVariableLength()) {
89 Map<String,Object> calculated = getCalculatedParameters();
90 if (calculated.containsKey("length")) {
91 controlPoint.setLength((Double)calculated.get("length"));
93 if (calculated.containsKey("offset")) {
94 controlPoint.setOffset((Double)calculated.get("offset"));
95 componentCalculatedOffset = true;
97 componentCalculatedOffset = false;
103 public void setPipeRun(PipeRun pipeRun) {
104 // TODO Auto-generated method stub
105 super.setPipeRun(pipeRun);
106 if (getPipeRun() != null && getAlternativePipeRun() != null) {
112 public void setAlternativePipeRun(PipeRun pipeRun) {
113 // TODO Auto-generated method stub
114 super.setAlternativePipeRun(pipeRun);
115 if (getPipeRun() != null && getAlternativePipeRun() != null) {
120 private void updateOffset() {
121 if (!componentCalculatedOffset && getControlPoint().isOffset()) {
122 getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5);
127 public Map<String, Object> updateParameterMap() {
128 Map<String,Object> map = new HashMap<String, Object>();
129 if (controlPoint != null) {
130 if (!Double.isNaN(controlPoint.getLength()))
131 map.put("length", controlPoint.getLength());
132 if (controlPoint.isDualInline()) {
133 PipeControlPoint sub = controlPoint.getSubPoint().get(0);
134 PipeRun pipeRun2 = sub.getPipeRun();
135 if (pipeRun2 != null) {
136 map.put("radius2", pipeRun2.getPipeDiameter() * 0.5);
138 if (controlPoint.isOffset() && !componentCalculatedOffset) {
139 map.put("offset", controlPoint.getOffset());
144 PipeRun pipeRun = getPipeRun();
145 if (pipeRun != null) {
146 map.put("radius", pipeRun.getPipeDiameter() * 0.5);