- PipelineComponent newComponent = ComponentUtils.createComponent(root,toAdd.getUri());
- PipeControlPoint newPcp = newComponent.getControlPoint();
-
- PipeControlPoint toPcp = component.getControlPoint();
-
-
- switch (position) {
- case NEXT:
- if (toPcp.isDualInline())
- toPcp = toPcp.getSubPoint().get(0);
-
- break;
- case PREVIOUS:
- if (toPcp.isDualSub())
- toPcp = toPcp.parent;
- }
-
- Vector3d start = new Vector3d();
- Vector3d end = new Vector3d();
- Vector3d dir = new Vector3d();
- toPcp.getInlineControlPointEnds(start, end, dir);
- dir.normalize();
-
- PipeRun pipeRun = toPcp.getPipeRun();
-
- if (!toAdd.isSizeChange()) {
- String name = component.getPipeRun().getUniqueName(toAdd.getName());
- newComponent.setName(name);
-
- pipeRun.addChild(newComponent);
- if (toAdd.isVariable()) {
- // TODO: these options are not stored into DB. Should they?!
- if (toAdd.getType() == Type.INLINE) {
- newPcp.setLength(length);
-// newPcp.setFixed(true);
- } else if (toAdd.getType() == Type.TURN) {
- newPcp.setTurnAngle(angle);
-// newPcp.setFixed(true);
- }
- }
- newComponent.updateParameters();
-
- dir.scale(newComponent.getControlPoint().getLength()*0.5);
- start.sub(dir);
- end.add(dir);
- switch (position) {
- case NEXT:
- if (toPcp.isDualInline())
- toPcp = toPcp.getSubPoint().get(0);
- newPcp.insert(toPcp, Direction.NEXT);
- newPcp.setWorldPosition(end);
- break;
- case PREVIOUS:
- if (toPcp.isDualSub())
- toPcp = toPcp.parent;
- newPcp.insert(toPcp, Direction.PREVIOUS);
- newPcp.setWorldPosition(start);
- break;
- case SPLIT:
- PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, true);
- }
- } else {
-
-
- PipeRun other = new PipeRun();
- String n = root.getUniqueName("PipeRun");
- other.setName(n);
- other.setPipeDiameter(diameter);
- other.setTurnRadius(turnRadius);
- root.addChild(other);
-
-
-
- if (position == PositionType.NEXT) {
- PipingRules.addSizeChange(false, pipeRun, other, (InlineComponent)newComponent, toPcp, null);
- newPcp.setWorldPosition(end);
- } else if (position == PositionType.PREVIOUS){
- PipingRules.addSizeChange(true, pipeRun, other, (InlineComponent)newComponent, toPcp, null);
- newPcp.setWorldPosition(start);
- }
- // TODO : chicken-egg problem
- newComponent.updateParameters();
- dir.scale(newComponent.getControlPoint().getLength()*0.5);
- start.sub(dir);
- end.add(dir);
- if (position == PositionType.NEXT) {
- newPcp.setWorldPosition(end);
- } else if (position == PositionType.PREVIOUS){
- newPcp.setWorldPosition(start);
- }
- }
-
-
+ InsertInstruction inst = new InsertInstruction();
+ inst.typeUri = toAdd.getUri();
+ inst.angle = angle != null ? MathTools.degToRad(angle) : null;
+ inst.diameter = diameter;
+ inst.length = length;
+ inst.turnRadius = turnRadius;
+ inst.insertPosition = insertPosition;
+ inst.rotationAngle = rotationAngle;
+ inst.position = position;
+ ComponentUtils.addComponent(root, component, inst);