X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Futils%2FComponentUtils.java;h=913fceb9178276045828d04d9546000e39b62dd2;hb=bf8d749e159470552b86484450b8b227b7985559;hp=2cef7060c14ede3b748ddb821146d26d8bc6ecdb;hpb=d207cfa3235339e7d7b894494be400160b121bd5;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 2cef7060..913fceb9 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -281,6 +281,7 @@ public class ComponentUtils { // Reducer requires pipe specs public Double diameter; + public Double thickness; public Double turnRadius; // Variable length @@ -331,6 +332,14 @@ public class ComponentUtils { public void setDiameter(Double diameter) { this.diameter = diameter; } + + public double getThickness() { + return thickness; + } + + public void setThickness(double thickness) { + this.thickness = thickness; + } public Double getTurnRadius() { return turnRadius; @@ -369,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(); @@ -399,6 +405,8 @@ public class ComponentUtils { sizeChange = ((InlineComponent)newComponent).isSizeChange(); } + // Calculate component position and direction vectors + // 'dir' is a unit vector that represents the direction from 'component' to 'newComponent' if (toPcp.isInline()) { switch (position) { case NEXT: @@ -428,6 +436,7 @@ public class ComponentUtils { break; case PREVIOUS: pos = new Vector3d(start); + dir.negate(); break; case SPLIT: pos = new Vector3d(toPcp.getWorldPosition()); @@ -435,9 +444,9 @@ public class ComponentUtils { default: break; } - } else if (toPcp.isDirected()) { - dir = new Vector3d(toPcp.getDirection(Direction.NEXT)); + // 'dir' always points out of a nozzle regardless of insertion direction + dir = new Vector3d(toPcp.getDirectedControlPointDirection()); pos = new Vector3d(toPcp.getWorldPosition()); } else if (toPcp.isTurn() && toPcp.asFixedAngle()) { dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS)); @@ -460,8 +469,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()) @@ -478,18 +491,22 @@ 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) ((TurnComponent) newComponent).setRotationAngle(inst.rotationAngle); } - newComponent.updateParameters(); Vector3d v = new Vector3d(dir); if (insertAdjustable) { + // Prevent moving of adjacent components - always insert at end of a connected variable length component + if (position == PositionType.NEXT && component.getNext() != null || + position == PositionType.PREVIOUS && component.getPrevious() != null) + insertPosition = PositionType.PREVIOUS; + if (insertPosition == PositionType.NEXT) v.scale(newComponent.getControlPoint().getInlineLength()); else if (insertPosition == PositionType.SPLIT) @@ -499,12 +516,11 @@ public class ComponentUtils { } else { v.scale(newComponent.getControlPoint().getInlineLength()); } + switch (position) { case NEXT: - pos.add(v); - break; case PREVIOUS: - pos.sub(v); + pos.add(v); break; case SPLIT: break; @@ -516,14 +532,20 @@ public class ComponentUtils { case NEXT: if (toPcp.isDualInline()) toPcp = toPcp.getDualSub(); - newPcp.insert(toPcp, Direction.NEXT); newPcp.setWorldPosition(pos); + if (toPcp.getNext() != null) + PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, false); + else + newPcp.insert(toPcp, Direction.NEXT); break; case PREVIOUS: if (toPcp.isDualSub()) toPcp = toPcp.parent; - newPcp.insert(toPcp, Direction.PREVIOUS); newPcp.setWorldPosition(pos); + if (toPcp.getPrevious() != null) + PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, false); + else + newPcp.insert(toPcp, Direction.PREVIOUS); break; case SPLIT: PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, true); @@ -537,6 +559,7 @@ public class ComponentUtils { String n = root.getUniqueName("PipeRun"); other.setName(n); other.setPipeDiameter(inst.diameter); + other.setPipeThickness(inst.thickness); other.setTurnRadius(inst.turnRadius); root.addChild(other);