]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Setter for flow length for unconnected inline components. 29/3329/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 15 Oct 2019 10:11:01 +0000 (13:11 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Tue, 15 Oct 2019 10:11:01 +0000 (13:11 +0300)
gitlab #30

Change-Id: Ibb435186075fa7a3ff804b7abac46437e671c3f3

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java

index f01e6c585b36cd96ab75a5ff58baf43adc7d55da..eb5c1a288492326fea3daef4a4a4f8a86aea953e 100644 (file)
@@ -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;
@@ -65,6 +68,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) {
@@ -178,5 +182,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);
+       }
 }