]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Support for reversible in-line components 59/3059/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 5 Aug 2019 12:32:55 +0000 (15:32 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 5 Aug 2019 12:32:55 +0000 (15:32 +0300)
gitlab #13

Change-Id: I2348320a5bba2b8d86b7a0bcc118d85f81023186

org.simantics.plant3d.ontology/graph/plant3d.pgraph
org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java

index d7dce09ee57cb2c5856987bc352022323cac3240..46a6a34bd0476b1c238c332ef84ae519012e84d4 100644 (file)
@@ -69,7 +69,9 @@ P3D.SizeChangeComponent <R P3D.PipelineComponentTag
 P3D.OffsetComponent<R P3D.PipelineComponentTag
     L0.HasDescription "Component that offsets the center of piperun." : L0.String
 P3D.RotateComponent<R P3D.PipelineComponentTag
-    L0.HasDescription "Inline Component that can be rotated around pipe axis." : L0.String    
+    L0.HasDescription "Inline Component that can be rotated around pipe axis." : L0.String
+P3D.ReverseComponent<R P3D.PipelineComponentTag
+    L0.HasDescription "Inline Component that can be reversed (rotated 180 deg)" : L0.String    
 P3D.CodeComponent <T P3D.PipelineComponentTag
     L0.HasDescription "Component that cannot be added directly by user" : L0.String
 P3D.NonVisibleComponent <R P3D.PipelineComponentTag
index a8f2a5bbe25f78aa9c4429426b7a061c7605720e..6ab68fcc5c5aa9fcd347604deffaad9f4df1260e 100644 (file)
@@ -112,6 +112,7 @@ P3D.Builtin.BallValve <T P3D.InlineComponent : P3D.InlineComponent
 P3D.Builtin.CheckValve <T P3D.InlineComponent : P3D.InlineComponent
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.FixedLengthInlineComponent
+    @L0.tag P3D.ReverseComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.CheckValveGeometryProvider
     @L0.assert P3D.hasParameter
          _ :P3D.Parameter
index e098de63a637303a787aca53f85db0259380f845..6590c73d2cc3f34de38a24c1fc1e835fc086d34f 100644 (file)
@@ -82,6 +82,34 @@ public class InlineComponent extends PipelineComponent {
                }       
        }
        
+       @RelatedGetValue(Plant3D.URIs.IsReversed)
+       @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default")
+       public Boolean isReversed() {
+               if (!controlPoint.isReverse())
+                       return null;
+               Boolean d = controlPoint.getReversed();
+               if (d == null)
+                       return false;
+               return d;
+       }
+       @RelatedSetValue(Plant3D.URIs.IsReversed)
+       @SetPropertyValue(value=Plant3D.URIs.IsReversed)
+       public void setReverse(Boolean reverse) {
+               if (!controlPoint.isReverse())
+                       return;
+               
+               if (reverse == null) {
+                       return;
+               }
+               controlPoint.setReversed(reverse);
+               try {
+                       PipingRules.requestUpdate(getControlPoint());
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }       
+       }
+       
        @Override
        public void updateParameters() {
                super.updateParameters();
index 0967f38b77981bc12b618ad9309b8827f1715ddb..71602dcc0ff163220a36b741a78ec9c4d082111d 100644 (file)
@@ -46,6 +46,7 @@ public class ControlPointFactory {
                pcp.setType(inst.type);
                pcp.setFixed(inst.fixed);
                pcp.setRotate(inst.isRotate);
+               pcp.setReverse(inst.isReverse);
                switch(inst.type) {
                case END:
                        
@@ -78,6 +79,7 @@ public class ControlPointFactory {
                boolean isOffset;
                boolean isSizeChange;
                boolean isRotate;
+               boolean isReverse;
                
        }
        
@@ -92,6 +94,7 @@ public class ControlPointFactory {
                                i.isOffset = false;
                                i.isSizeChange = false;
                                i.isRotate = false;
+                               i.isReverse = false;
                                i.type = Type.INLINE;
                                if (graph.isInheritedFrom(res, p3d.Nozzle)) {
                                        i.fixed = true;
@@ -118,6 +121,10 @@ public class ControlPointFactory {
                                                i.isRotate = true;
                                        }
                                        
+                                       if (graph.hasStatement(res,p3d.ReverseComponent)) {
+                                               i.isReverse = true;
+                                       }
+                                       
                                } else if (graph.isInheritedFrom(res, p3d.TurnComponent)) {
                                        i.type = Type.TURN;
                                        if (graph.hasStatement(res,p3d.VariableAngleTurnComponent)) {
index b14b298bcf26d0060ea91ec09521f740fc596b45..ecaeb7ae7c41d2b70017d4de433dfac968270ecc 100644 (file)
@@ -32,6 +32,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
        private Type type;
        private boolean fixed = true;
        private boolean rotate = false;
+       private boolean reverse = false;
        private boolean deletable = true;
        private boolean sub = false;
        
@@ -88,11 +89,19 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return rotate;
        }
        
-       
        public void setRotate(boolean rotate) {
                this.rotate = rotate;
        }
        
+       @GetPropertyValue(name="Reverse",tabId="Debug",value="reverse")
+       public boolean isReverse() {
+               return reverse;
+       }
+       
+       public void setReverse(boolean reverse) {
+               this.reverse = reverse;
+       }
+       
        public void setSub(boolean sub) {
                this.sub = sub;
        }
@@ -230,6 +239,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
        private Double offset;
        private Double rotationAngle;
+       private Boolean reversed;
        
        @GetPropertyValue(name="Length",tabId="Debug",value="length")
        public double getLength() {
@@ -268,6 +278,11 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return rotationAngle;
        }
        
+       @GetPropertyValue(name="Reversed",tabId="Debug",value="reversed")
+       public Boolean getReversed() {
+               return reversed;
+       }
+       
        public void setTurnAngle(Double turnAngle) {
                if (Double.isInfinite(turnAngle) || Double.isNaN(turnAngle)) {
                        return;
@@ -303,6 +318,11 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                firePropertyChanged("rotationAngle");
        }
        
+       public void setReversed(Boolean reversed) {
+               this.reversed = reversed;
+               firePropertyChanged("rotationAngle");
+       }
+       
        public Vector3d getSizeChangeOffsetVector(Vector3d dir) {
                Quat4d q;
                if (rotationAngle == null)
@@ -353,7 +373,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                return type.name();
        }
        
-        public Quat4d getControlPointOrientationQuat(double angle) {
+       public Quat4d getControlPointOrientationQuat(double angle) {
                 
                 if (turnAxis == null) {
                         Vector3d dir = getPathLegDirection(Direction.NEXT);
@@ -367,11 +387,33 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                                 dir.normalize();
                         return getControlPointOrientationQuat(dir, turnAxis, angle);
                 }
-        }
+       }
+        
+    public Quat4d getControlPointOrientationQuat(double angle, boolean reversed) {
+                
+                if (turnAxis == null) {
+                        Vector3d dir = getPathLegDirection(Direction.NEXT);
+                        if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+                                dir.normalize();
+                        Quat4d q =  getControlPointOrientationQuat(dir, angle);
+                        if (reversed) {
+                                Quat4d q2 = new Quat4d();
+                               q2.set(new AxisAngle4d(MathTools.Y_AXIS, Math.PI));
+                               q.mulInverse(q2);
+                        }
+                        return q;
+                } else {
+                        Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
+                        dir.negate();
+                        if (dir.lengthSquared() > MathTools.NEAR_ZERO)
+                                dir.normalize();
+                        return getControlPointOrientationQuat(dir, turnAxis, angle);
+                }
+       }
         
        
        
-        public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
+       public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
                        if (dir.lengthSquared() < MathTools.NEAR_ZERO)
                                return MathTools.getIdentityQuat();
                
index ea8a512bcd8d0aac247d0df0881286e5dfdb6b75..3fc0488105fe8a24a8bd7197a188fb448ec3bfe7 100644 (file)
@@ -1476,8 +1476,11 @@ public class PipingRules {
                double angle = 0.0;
                if (angleO != null)
                        angle = angleO;
-
-               Quat4d q = pcp.getControlPointOrientationQuat(angle);
+               Boolean reversedO = pcp.getReversed();
+               boolean reversed = false;
+               if (reversedO != null)
+                       reversed = reversedO;
+               Quat4d q = pcp.getControlPointOrientationQuat(angle, reversed);
                pcp.setWorldOrientation(q);
        }