package org.simantics.plant3d.scenegraph; import java.util.HashMap; import java.util.Map; import javax.vecmath.Vector3d; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.objmap.graph.annotations.DynamicGraphType; import org.simantics.objmap.graph.annotations.GetType; import org.simantics.objmap.graph.annotations.RelatedGetValue; import org.simantics.objmap.graph.annotations.RelatedSetValue; import org.simantics.objmap.graph.annotations.SetType; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory; import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; @DynamicGraphType(Plant3D.URIs.TurnComponent) public class TurnComponent extends PipelineComponent { private String type; private PipeControlPoint controlPoint; @GetType(Plant3D.URIs.TurnComponent) public String getType() { return type; } @SetType(Plant3D.URIs.TurnComponent) public void setType(String type) throws Exception{ this.type = type; controlPoint = ControlPointFactory.create(this); } @Override public PipeControlPoint getControlPoint() { return controlPoint; } @Override public void setParent(ParentNode parent, String name) { super.setParent(parent, name); setPipeRun((PipeRun)parent); } @Override public Map updateParameterMap() { Map map = new HashMap(); PipeRun pipeRun = getPipeRun(); if (pipeRun != null) { map.put("turnRadius", pipeRun.getTurnRadius()); map.put("radius", pipeRun.getPipeDiameter() * 0.5); } if (controlPoint != null && controlPoint.getTurnAngle() != null && !Double.isNaN(controlPoint.getTurnAngle())) { map.put("turnAngle", controlPoint.getTurnAngle()); } return map; } public boolean isVariableAngle() { return !controlPoint.isFixed(); } @Override public void updateParameters() { super.updateParameters(); if (!isVariableAngle()) { Map calculated = getCalculatedParameters(); if (calculated.containsKey("length")) { controlPoint.setLength((Double)calculated.get("length")); } PipingRules.requestUpdate(getControlPoint()); } } @RelatedGetValue(Plant3D.URIs.HasTurnAngle) public Double getTurnAngle() { return getControlPoint().getTurnAngle(); } @RelatedSetValue(Plant3D.URIs.HasTurnAngle) public void setTurnAngle(Double a) { if (!getControlPoint().isFixed()) return; getControlPoint().setTurnAngle(a); } @GetPropertyValue(name="Turn Angle", value="turn angle", tabId = "Default") public Double getTurnAngleDeg() { Double d = getControlPoint().getTurnAngle(); if (d == null) return null; return MathTools.radToDeg(d); } public Vector3d getTurnAxis() { return getControlPoint().getTurnAxis(); } @RelatedGetValue(Plant3D.URIs.HasRotationAngle) @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default") public Double getRotationAngle() { if (!controlPoint.isFixed()) return null; Double d = controlPoint.getRotationAngle(); if (d == null) return 0.0; return MathTools.radToDeg(d); } @RelatedSetValue(Plant3D.URIs.HasRotationAngle) @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle) public void setRotationAngle(Double angle) { if (!controlPoint.isFixed()) return; if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) { return; } angle = MathTools.degToRad(angle); if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO) return; controlPoint.setRotationAngle(angle); try { PipingRules.requestUpdate(getControlPoint()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @RelatedGetValue(Plant3D.URIs.IsReversed) @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default") public Boolean isReversed() { if (!controlPoint.isFixed()) return null; Boolean d = controlPoint._getReversed(); return d; } @RelatedSetValue(Plant3D.URIs.IsReversed) //@SetPropertyValue(value=Plant3D.URIs.IsReversed) public void setReversed(Boolean reverse) { if (!controlPoint.isFixed()) return; if (reverse == null) { return; } controlPoint.setReversed(reverse); try { PipingRules.requestUpdate(getControlPoint()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected double[] getColor() { if (getControlPoint() == null || !getControlPoint().isFixed()) return new double[]{0.6,0.6,0.6}; else return new double[]{1.0,0.0,0.0}; } }