X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2FInlineComponent.java;h=695f1fa698e040b657655e8ddf67b62b687695d5;hb=refs%2Fchanges%2F85%2F4085%2F1;hp=1fd83da110d3f36bf8739db214d325444d8e74e9;hpb=11cf079ab699e65f6c97b86745a3c8cbd65817b8;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java index 1fd83da1..695f1fa6 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java @@ -3,6 +3,9 @@ package org.simantics.plant3d.scenegraph; import java.util.HashMap; import java.util.Map; +import javax.vecmath.Point3d; +import javax.vecmath.Vector3d; + import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.property.annotations.SetPropertyValue; @@ -33,6 +36,9 @@ public class InlineComponent extends PipelineComponent { public void setType(String type) throws Exception{ this.type = type; controlPoint = ControlPointFactory.create(this); + syncNext(); + syncPrevious(); + syncBranch0(); } @@ -51,8 +57,12 @@ public class InlineComponent extends PipelineComponent { return !controlPoint.isFixed(); } + public boolean isModifialble() { + return controlPoint.isMod(); + } + public boolean isSizeChange() { - return controlPoint.isSizeChange(); + return controlPoint.isSizeChange(); } @RelatedGetValue(Plant3D.URIs.HasRotationAngle) @@ -65,6 +75,7 @@ public class InlineComponent extends PipelineComponent { return 0.0; return MathTools.radToDeg(d); } + @RelatedSetValue(Plant3D.URIs.HasRotationAngle) @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle) public void setRotationAngle(Double angle) { @@ -78,12 +89,8 @@ public class InlineComponent extends PipelineComponent { 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(); - } + PipingRules.requestUpdate(getControlPoint()); + } @RelatedGetValue(Plant3D.URIs.IsReversed) @@ -91,9 +98,7 @@ public class InlineComponent extends PipelineComponent { public Boolean isReversed() { if (!controlPoint.isReverse()) return null; - Boolean d = controlPoint.getReversed(); - if (d == null) - return false; + Boolean d = controlPoint._getReversed(); return d; } @RelatedSetValue(Plant3D.URIs.IsReversed) @@ -106,12 +111,7 @@ public class InlineComponent extends PipelineComponent { return; } controlPoint.setReversed(reverse); - try { - PipingRules.requestUpdate(getControlPoint()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + PipingRules.requestUpdate(getControlPoint()); } @Override @@ -119,15 +119,21 @@ public class InlineComponent extends PipelineComponent { super.updateParameters(); if (!isVariableLength()) { Map calculated = getCalculatedParameters(); - if (calculated.containsKey("length")) { - controlPoint.setLength((Double)calculated.get("length")); - } + if (calculated.containsKey("offset")) { controlPoint.setOffset((Double)calculated.get("offset")); componentCalculatedOffset = true; } else { componentCalculatedOffset = false; } + + Map total = getTotalParameters(); + + if (total.containsKey("length")) { + controlPoint.setLength((Double)total.get("length")); + } + + PipingRules.requestUpdate(getControlPoint()); } } @@ -151,7 +157,7 @@ public class InlineComponent extends PipelineComponent { private void updateOffset() { if (!componentCalculatedOffset && getControlPoint().isOffset()) { - getControlPoint().setOffset(getPipeRun().getPipeDiameter()*0.5 - getAlternativePipeRun().getPipeDiameter()*0.5); + getControlPoint().setOffset(getPipeRun().getInsideDiameter()*0.5 - getAlternativePipeRun().getInsideDiameter()*0.5); } } @@ -159,15 +165,16 @@ public class InlineComponent extends PipelineComponent { public Map updateParameterMap() { Map map = new HashMap(); if (controlPoint != null) { - if (!Double.isNaN(controlPoint.getLength())) + if (!Double.isNaN(controlPoint.getLength()) && controlPoint.isVariableLength()) map.put("length", controlPoint.getLength()); if (controlPoint.isDualInline()) { - PipeControlPoint sub = controlPoint.getSubPoint().get(0); + PipeControlPoint sub = controlPoint.getDualSub(); PipeRun pipeRun2 = sub.getPipeRun(); if (pipeRun2 != null) { map.put("radius2", pipeRun2.getPipeDiameter() * 0.5); } if (controlPoint.isOffset() && !componentCalculatedOffset) { + updateOffset(); map.put("offset", controlPoint.getOffset()); } } @@ -180,5 +187,21 @@ public class InlineComponent extends PipelineComponent { return map; } - + @SetPropertyValue("flowlength") + public void setFlowLength(double l) { + // Not allowed, if not at the end of a run + if (getNext() != null) + throw new IllegalStateException("Cannot edit length of a connected component"); + + double length = getFlowLength(); + Point3d p1 = new Point3d(), p2 = new Point3d(); + controlPoint.getControlPointEnds(p1, p2); + Vector3d dir = new Vector3d(); + dir.sub(p2, p1); + dir.normalize(); + dir.scale((l - length)/2); + Vector3d pos = new Vector3d(getPosition()); + pos.add(dir); + setPosition(pos); + } }