]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Merge branch 'release/1.43.0'
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 12 Mar 2020 17:32:40 +0000 (19:32 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 12 Mar 2020 17:32:40 +0000 (19:32 +0200)
org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index da764775d509a3b17185e8ca76fe401c51e640e4..fb5060922a7aaf24678c692686bee4fca59e001e 100644 (file)
@@ -566,7 +566,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                                        rotationAngleText.setEnabled(true);
                                        if (angle == null) {
                                                ok = false;
-                                               if (msg == null) msg = "Please provide a rotation angle";
+                                               if (msg == null) msg = "Please provide a turn angle";
                                        }
                                } else {
                                        // this should not happen, since end components should not have variable, or
index 08fa2622311cc3ed915f6c5f004e51f85f3e8a52..fdb413ee39316b1cbc0652a4e2360c0ceb105b39 100644 (file)
@@ -462,7 +462,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                }
                if (this.rotationAngle != null && Math.abs(this.rotationAngle-rotationAngle) < MathTools.NEAR_ZERO)
                        return;
-               if (Objects.equals(rotationAngle, rotationAngle))
+               if (Objects.equals(this.rotationAngle, rotationAngle))
                        return;
                this.rotationAngle = rotationAngle;
                firePropertyChanged("rotationAngle");
@@ -855,107 +855,70 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
         */
        public Vector3d getPathLegDirection(Direction direction) {
                if (direction == Direction.NEXT) {
-                       if (next != null) {
-                               PipeControlPoint pcp = this;
-                               if (pcp.isDualInline()) {
-                                       pcp = pcp.getDualSub();
-                               }
-                               Vector3d v = new Vector3d();
-                               v.sub(next.getWorldPosition(),pcp.getWorldPosition());
-                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                    v.normalize();
-                else
-                    return null;
-                               return v;
-                       } else {
-                               if (previous == null) {
-                                       if (!isDirected())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
-                                       return getDirectedControlPointDirection();
+                       return getPathLegDirectionNext();
+               } else {
+                       return getPathLegDirectionPrevious();
+               }
+       }
 
-                               } else {
-                                       if (isVariableAngle() && !asFixedAngle())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
-                                       if (isInline()) {
-                                               PipeControlPoint pcp = this;
-                                               if (pcp.isDualSub()) {
-                                                       pcp = pcp.getParentPoint();
-                                               }
-                                               Vector3d v = new Vector3d();
-                                               v.sub(pcp.getWorldPosition(),previous.getWorldPosition());
-                                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                               v.normalize();
-                                               else
-                                                   return null;
-                                               return v;
-                                       } else if (isDirected()) {
-                                               return getDirectedControlPointDirection();
-                                       } else if (isEnd()) {
-                                               Vector3d v = new Vector3d();
-                                               v.sub(getWorldPosition(),previous.getWorldPosition());
-                                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                            v.normalize();
-                        else
-                            return null;
-                                               return v;
-                                       } else if (isTurn() && asFixedAngle() && !_getReversed()) {
-                                               return getDirection(Direction.NEXT);
-                                       }
-                                       throw new RuntimeException("Missing implementation " + this);
-                               }
-                       }
+       public Vector3d getPathLegDirectionPrevious() {
+               if (previous != null) {
+                       PipeControlPoint pcp = this;
+                       if (isDualSub()) 
+                               pcp = getParentPoint();
+                       Vector3d v = new Vector3d();
+                       v.sub(previous.getWorldPosition(),pcp.getWorldPosition());
+                       if (v.lengthSquared() > MathTools.NEAR_ZERO)
+                       v.normalize();
+                   else
+                       return null;
+                       return v;
+               } else if (isDirected()) {
+                       Vector3d v = getDirectedControlPointDirection();
+                       v.negate();
+                       return v;
+               } else if (next == null)  {
+                       throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
+               } else if (isVariableAngle() && !asFixedAngle()) {
+                       throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
+               } else if (isInline() || isEnd()) {
+                       Vector3d v = getPathLegDirectionNext();
+                       if (v != null) v.negate();
+                       return v;
+               } else if (isTurn() && asFixedAngle() && _getReversed()) {
+                       return getDirection(Direction.PREVIOUS);
                } else {
-                       if (previous != null) {
-                               PipeControlPoint pcp = this;
-                               if (isDualSub()) 
-                                       pcp = getParentPoint();
-                               Vector3d v = new Vector3d();
-                               v.sub(previous.getWorldPosition(),pcp.getWorldPosition());
-                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                    v.normalize();
-                else
-                    return null;
-                               return v;
-                       } else {
-                               if (next == null)  {
-                                       if (!isDirected())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
-                                       Vector3d v = getDirectedControlPointDirection();
-                                       v.negate();
-                                       return v;
-                               } else {
-                                       if (isVariableAngle() && !asFixedAngle())
-                                               throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
-                                       if (isInline()) {
-                                               PipeControlPoint pcp = this;
-                                               if (pcp.isDualInline()) {
-                                                       pcp = pcp.getDualSub();
-                                               }
-                                               Vector3d v = new Vector3d();
-                                               v.sub(pcp.getWorldPosition(),next.getWorldPosition());
-                                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                            v.normalize();
-                        else
-                            return null;
-                                               return v;
-                                       } else if (isDirected()) {
-                                               Vector3d v = getDirectedControlPointDirection();
-                                               v.negate();
-                                               return v;
-                                       } else if (isEnd()) {
-                                               Vector3d v = new Vector3d();
-                                               v.sub(getWorldPosition(),next.getWorldPosition());
-                                               if (v.lengthSquared() > MathTools.NEAR_ZERO)
-                            v.normalize();
-                        else
-                            return null;
-                                               return v;
-                                       } else if (isTurn() && asFixedAngle() && _getReversed()) {
-                                               return getDirection(Direction.PREVIOUS);
-                                       }
-                                       throw new RuntimeException("Missing implementation " + this);
-                               }
+                       throw new RuntimeException("Missing implementation " + this);
+               }
+       }
+
+       public Vector3d getPathLegDirectionNext() {
+               if (next != null) {
+                       PipeControlPoint pcp = this;
+                       if (pcp.isDualInline()) {
+                               pcp = pcp.getDualSub();
                        }
+                       Vector3d v = new Vector3d();
+                       v.sub(next.getWorldPosition(),pcp.getWorldPosition());
+                       if (v.lengthSquared() > MathTools.NEAR_ZERO)
+                       v.normalize();
+                   else
+                       return null;
+                       return v;
+               } else if (isDirected()) {
+                       return getDirectedControlPointDirection();
+               } else if (previous == null) {
+                       throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this);
+               } else if (isVariableAngle() && !asFixedAngle()) {
+                       throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this);
+               } else if (isInline() || isEnd()) {
+                       Vector3d v = getPathLegDirectionPrevious();
+                       if (v != null) v.negate();
+                       return v;
+               } else if (isTurn() && asFixedAngle() && !_getReversed()) {
+                       return getDirection(Direction.NEXT);
+               } else {
+                       throw new RuntimeException("Missing implementation " + this);
                }
        }
 
@@ -1651,6 +1614,21 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                updateSubPoint();
        }
 
+       public void orientToDirection(Vector3d dir) {
+               Double angleO = getRotationAngle();
+               double angle = 0.0;
+               if (angleO != null)
+                       angle = angleO;
+               boolean reversed = _getReversed();
+               Quat4d q = null;
+               if (dir != null) {
+                   q = getControlPointOrientationQuat(dir, angle, reversed);
+               } else {
+                   q = getControlPointOrientationQuat(angle, reversed);
+               }
+               setWorldOrientation(q);
+       }
+
        @Override
        public String toString() {
                return getClass().getName() + "@" + Integer.toHexString(hashCode());
index 542534c3eebf983af835d4deefc7d735f70a5ee4..776d38ab860791abbfb8f488a3271990509c0be8 100644 (file)
@@ -294,7 +294,7 @@ public class PipingRules {
                scp.setWorldPosition(pos);
                Vector3d dir = new Vector3d();
                dir.sub(pcp2.getWorldPosition(), pcp1.getWorldPosition());
-               updateControlPointOrientation(scp, dir);
+               scp.orientToDirection(dir);
                scp.setLength(length);
                validate(scp.getPipeRun());
                return scp;
@@ -1638,7 +1638,7 @@ public class PipingRules {
                        } else if (u.start.isEnd()) {
                                updateEndComponentControlPoint(u.start, u.dir);
                        } else if (u.start.isInline()) {
-                               updateControlPointOrientation(u.start, u.dir);
+                               u.start.orientToDirection(u.dir);
                        }
                        if (u.end.isTurn()) {
                                //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext());
@@ -1647,7 +1647,7 @@ public class PipingRules {
                        } else if (u.end.isEnd()) {
                                updateEndComponentControlPoint(u.end, u.dir);
                        } else if (u.end.isInline()) {
-                               updateControlPointOrientation(u.end, u.dir);
+                               u.end.orientToDirection(u.dir);
                        }
 
                } else {
@@ -1776,7 +1776,7 @@ public class PipingRules {
                        System.out.println(" " + newInlinePoint);
 
                icp.setWorldPosition(newInlinePoint);
-               updateControlPointOrientation(icp, dir);
+               icp.orientToDirection(dir);
        }
 
        /**
@@ -1793,7 +1793,7 @@ public class PipingRules {
                        System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
                
                if (!ecp.isFixed()) // prevent overriding nozzle orientations..
-                  updateControlPointOrientation(ecp, dir);
+                       ecp.orientToDirection(dir);
 
                for (PipeControlPoint pcp : ecp.getChildPoints()) {
                        // TODO update position
@@ -1801,21 +1801,6 @@ public class PipingRules {
                }
        }
 
-       private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) {
-               Double angleO = pcp.getRotationAngle();
-               double angle = 0.0;
-               if (angleO != null)
-                       angle = angleO;
-               boolean reversed = pcp._getReversed();
-               Quat4d q = null;
-               if (dir != null) {
-                   q = pcp.getControlPointOrientationQuat(dir, angle, reversed);
-               } else {
-                   q = pcp.getControlPointOrientationQuat(angle, reversed);
-               }
-               pcp.setWorldOrientation(q);
-       }
-
        /**
         * Updates all branches when branch's position has been changed
         * 
@@ -1881,7 +1866,7 @@ public class PipingRules {
                                tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
                        }
                        
-                       updateControlPointOrientation(tcp,prev);
+                       tcp.orientToDirection(prev);
                        
                        if (DEBUG)
                                System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
index 438e0bd6a96eae87cf8121640a11bfd350409161..78f4166547b8740367cc3c18eaccb5523d0a3148 100644 (file)
@@ -378,9 +378,6 @@ public class ComponentUtils {
        public static PipelineComponent addComponent(P3DRootNode root, PipelineComponent component,  InsertInstruction inst) throws Exception {
                
                PipelineComponent newComponent = ComponentUtils.createComponent(root, inst.typeUri);
-               if (inst.name != null)
-                       newComponent.setName(inst.name);
-               
                PipeControlPoint newPcp = newComponent.getControlPoint();
                
                PipeControlPoint toPcp = component.getControlPoint();
@@ -447,6 +444,8 @@ public class ComponentUtils {
 
                } else if (toPcp.isDirected()) {
                        dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
+                       if (position == PositionType.PREVIOUS)
+                               dir.negate();
                        pos = new Vector3d(toPcp.getWorldPosition());
                } else if (toPcp.isTurn() && toPcp.asFixedAngle()) {
                        dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
@@ -469,8 +468,12 @@ public class ComponentUtils {
                        }
                }
                
-               String name = component.getPipeRun().getUniqueName(typeName);
-               newComponent.setName(name);
+               if (inst.name != null) {
+                       newComponent.setName(inst.name);
+               } else {
+                       String name = component.getPipeRun().getUniqueName(typeName);
+                       newComponent.setName(name);
+               }
 
                pipeRun.addChild(newComponent);
                if (newPcp.isSizeChange())
@@ -487,7 +490,7 @@ public class ComponentUtils {
                } else if (newComponent instanceof TurnComponent) {
                    TurnComponent turnComponent = (TurnComponent)newComponent;
                    if  (turnComponent.isVariableAngle()) {
-                               newPcp.setTurnAngle(inst.angle);
+                               newPcp.setTurnAngle(Math.toRadians(inst.angle));
                                newComponent.setParameter("turnAngle", inst.angle);
                    }
                    if (inst.rotationAngle != null)