1 package org.simantics.plant3d.scenegraph.controlpoint;
3 import java.util.ArrayList;
4 import java.util.Collection;
7 import javax.vecmath.Point3d;
8 import javax.vecmath.Quat4d;
9 import javax.vecmath.Vector3d;
11 import org.simantics.g3d.math.MathTools;
12 import org.simantics.plant3d.scenegraph.InlineComponent;
13 import org.simantics.plant3d.scenegraph.P3DRootNode;
14 import org.simantics.plant3d.scenegraph.PipeRun;
15 import org.simantics.plant3d.scenegraph.PipelineComponent;
16 import org.simantics.plant3d.scenegraph.TurnComponent;
17 import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction;
18 import org.simantics.plant3d.utils.ComponentUtils;
19 import org.simantics.utils.datastructures.Pair;
20 import org.simantics.utils.ui.ErrorLogger;
22 public class PipingRules {
23 private static final boolean DEBUG = false;
24 private static final boolean DUMMY = false;
26 private static double MIN_TURN_ANGLE = 0.001; // Threshold for removing turn components.
27 private static double ALLOWED_OFFSET = 0.001; // Allowed offset for directed path legs
28 private static double MIN_INLINE_LENGTH = 0.0005; // Minimum length of inline components, when component removal is not allowed.
30 private static final int REMOVE_NONE = 0;
31 private static final int REMOVE_START = 1;
32 private static final int REMOVE_END = 2;
33 private static final int REMOVE_BOTH = 3;
36 // PathLeg iteration indicator. NEXT_S > NEXT > NONE PREV_S > PREV > NONE
37 private enum PathLegUpdateType {
38 NONE, // Only current path leg needs to be updated (for example, inline comp was moved)
39 PREV, // Current and previous path leg need to be updated
40 NEXT, // Current and next path leg need to be updated
41 PREV_S, // Current and previous two path legs need to be updated (turn was moved, which affect other path leg end turns, and thus following path legs
42 NEXT_S // Current and next two path legs need to be updated
45 private static boolean enabled = true; //
46 private static boolean updating = false;
47 private static boolean allowInsertRemove = true;
48 private static boolean triedIR = false;
51 private static List<PipeControlPoint> requestUpdates = new ArrayList<PipeControlPoint>();
52 private static List<PipeControlPoint> currentUpdates = new ArrayList<PipeControlPoint>();
54 private static Object updateMutex = new Object();
55 private static Object ruleMutex = new Object();
57 public static void requestUpdate(PipeControlPoint pcp) {
58 if (!PipingRules.enabled)
60 if (DEBUG) System.out.println("PipingRules request " + pcp);
61 synchronized (updateMutex) {
62 if (!requestUpdates.contains(pcp))
63 requestUpdates.add(pcp);
67 public static boolean update() throws Exception {
68 if (!PipingRules.enabled)
71 if (requestUpdates.size() == 0)
74 List<PipeControlPoint> temp = new ArrayList<PipeControlPoint>(requestUpdates.size());
75 synchronized(updateMutex) {
76 temp.addAll(requestUpdates);
77 requestUpdates.clear();
79 synchronized (ruleMutex) {
80 currentUpdates.clear();
81 currentUpdates.addAll(temp);
82 // TODO : we should remove already processed control points from currentUpdates after each _positionUpdate call.
83 for (PipeControlPoint pcp : currentUpdates)
84 _positionUpdate(pcp, true);
85 currentUpdates.clear();
87 synchronized(updateMutex) {
88 requestUpdates.removeAll(temp);
94 public static boolean positionUpdate(PipeControlPoint pcp) throws Exception {
96 return positionUpdate(pcp, true);
99 public static boolean positionUpdate(PipeControlPoint pcp, boolean allowIR) throws Exception {
100 synchronized (ruleMutex) {
101 currentUpdates.add(pcp);
102 boolean b = _positionUpdate(pcp, allowIR);
103 currentUpdates.clear();
109 private static boolean _positionUpdate(PipeControlPoint pcp, boolean allowIR) throws Exception {
110 if (updating || !enabled)
112 if (pcp.getPipeRun() == null)
115 if (DEBUG) System.out.println("PipingRules " + pcp);
117 allowInsertRemove = allowIR;
119 validate(pcp.getPipeRun());
120 if (pcp.getParentPoint() != null)
121 pcp = pcp.getParentPoint();
122 if (pcp.asPathLegEnd()) {
123 updatePathLegEndControlPoint(pcp); // FIXME: Rules won't work properly, if they are not run twice.
124 //updatePathLegEndControlPoint(pcp);
126 updateInlineControlPoint(pcp);
127 //updateInlineControlPoint(pcp);
129 validate(pcp.getPipeRun());
130 if (!allowInsertRemove)
135 // System.out.println("PipingRules done " + pcp);
139 public static void setEnabled(boolean enabled) {
140 PipingRules.enabled = enabled;
142 currentUpdates.clear();
145 public static boolean isEnabled() {
149 public static class ExpandIterInfo {
150 // these two are turn control points
151 private PipeControlPoint start;
152 private PipeControlPoint end;
155 public ExpandIterInfo() {
159 public ExpandIterInfo(PipeControlPoint tcp, int type) {
160 if (type == REMOVE_START)
167 public ExpandIterInfo(PipeControlPoint start, PipeControlPoint end) {
170 this.type = REMOVE_BOTH;
173 public PipeControlPoint getEnd() {
177 public void setEnd(PipeControlPoint end) {
181 public PipeControlPoint getStart() {
185 public void setStart(PipeControlPoint start) {
189 public int getType() {
193 public void setType(int type) {
199 private static void updatePathLegEndControlPoint(PipeControlPoint pcp) throws Exception {
201 System.out.println("PipingRules.updatePathLegEndControlPoint() " + pcp);
202 if (pcp.getNext() != null) {
203 updatePathLegNext(pcp, pcp, PathLegUpdateType.NEXT_S);
205 if (pcp.getPrevious() != null) {
206 updatePathLegPrev(pcp, pcp, PathLegUpdateType.PREV_S);
211 private static void updateInlineControlPoint(PipeControlPoint pcp) throws Exception {
213 System.out.println("PipingRules.updateInlineControlPoint() " + pcp);
214 PipeControlPoint start = pcp.findPreviousEnd();
215 updatePathLegNext(start, pcp, PathLegUpdateType.NONE);
218 private static PipeControlPoint insertElbow(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos) throws Exception{
220 System.out.println("PipingRules.insertElbow() " + pcp1 + " " + pcp2 + " " + pos);
221 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
223 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
224 pcp1 = pcp1.getDualSub();
225 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
226 PipeControlPoint t = pcp1;
229 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
230 PipeControlPoint t = pcp1;
231 pcp1 = pcp2.getDualSub();
234 throw new RuntimeException();
236 TurnComponent elbow = ComponentUtils.createTurn((P3DRootNode)pcp1.getRootNode());
237 PipeControlPoint pcp = elbow.getControlPoint();
238 if (pcp1.isDualInline())
239 pcp1 = pcp1.getDualSub();
240 String name = pcp1.getPipeRun().getUniqueName("Elbow");
242 pcp1.getPipeRun().addChild(elbow);
244 pcp.insert(pcp1, pcp2);
246 pcp.setWorldPosition(pos);
247 validate(pcp.getPipeRun());
251 private static PipeControlPoint insertStraight(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos, double length) throws Exception {
253 System.out.println("PipingRules.insertStraight() " + pcp1 + " " + pcp2 + " " + pos);
254 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
256 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
257 pcp1 = pcp1.getDualSub();
258 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
259 PipeControlPoint t = pcp1;
262 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
263 PipeControlPoint t = pcp1;
264 pcp1 = pcp2.getDualSub();
267 throw new RuntimeException();
269 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp1.getRootNode());
270 PipeControlPoint scp = component.getControlPoint();
271 if (pcp1.isDualInline())
272 pcp1 = pcp1.getDualSub();
273 String name = pcp1.getPipeRun().getUniqueName("Pipe");
274 component.setName(name);
275 pcp1.getPipeRun().addChild(component);
277 scp.insert(pcp1, pcp2);
279 scp.setWorldPosition(pos);
280 scp.setLength(length);
281 validate(scp.getPipeRun());
285 private static PipeControlPoint insertStraight(PipeControlPoint pcp, Direction direction , Vector3d pos, double length) throws Exception {
287 System.out.println("PipingRules.insertStraight() " + pcp + " " + direction + " " + pos);
289 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp.getRootNode());
290 PipeControlPoint scp = component.getControlPoint();
291 if (pcp.isDualInline() && direction == Direction.NEXT)
292 pcp = pcp.getDualSub();
293 String name = pcp.getPipeRun().getUniqueName("Pipe");
294 component.setName(name);
295 pcp.getPipeRun().addChild(component);
297 scp.insert(pcp,direction);
299 scp.setWorldPosition(pos);
300 scp.setLength(length);
301 validate(scp.getPipeRun());
305 private static void updatePathLegNext(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
306 UpdateStruct2 us = createUS(start, Direction.NEXT, 0, new ArrayList<ExpandIterInfo>(), updated);
308 System.out.println("Null update struct " + start);
311 updatePathLeg(us, lengthChange);
314 private static void updatePathLegPrev(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
315 UpdateStruct2 us = createUS(start, Direction.PREVIOUS, 0, new ArrayList<ExpandIterInfo>(), updated);
317 System.out.println("Null update struct " + start);
320 updatePathLeg(us, lengthChange);
323 private static class UpdateStruct2 {
324 public PipeControlPoint start;
325 public Vector3d startPoint;
326 public ArrayList<PipeControlPoint> list;
327 public PipeControlPoint end;
328 public Vector3d endPoint;
330 public Vector3d offset;
331 public boolean hasOffsets;
333 public boolean reversed;
334 public ArrayList<ExpandIterInfo> toRemove;
335 public PipeControlPoint updated;
337 public UpdateStruct2(PipeControlPoint start, Vector3d startPoint, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d endPoint, Vector3d dir, Vector3d offset, boolean hasOffsets, int iter, boolean reversed, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) {
338 if (start == null || end == null)
339 throw new NullPointerException();
341 this.startPoint = startPoint;
344 this.endPoint = endPoint;
346 this.offset = offset;
347 this.hasOffsets = hasOffsets;
349 this.reversed = reversed;
350 this.toRemove = toRemove;
351 this.updated = updated;
353 if (!MathTools.isValid(startPoint) ||
354 !MathTools.isValid(endPoint) ||
355 !MathTools.isValid(dir)) {
356 throw new RuntimeException();
360 public String toString() {
361 return start + " " + end+ " " + dir + " " + hasOffsets + " " + offset + " " + iter + " " + toRemove.size();
366 public static boolean calculateDirectedOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
367 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, true);
370 public static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
371 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, false);
374 private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset, boolean directed) {
375 List<PipeControlPoint> offsets = getOffsetPoints(start, list);
376 if (offsets.size() == 0) {
377 setZeroOffset(startPoint, endPoint, dir, offset);
380 Vector3d sp = new Vector3d(startPoint);
381 Point3d ep = new Point3d(endPoint);
384 double l = dir.lengthSquared();
385 if (l > MathTools.NEAR_ZERO)
386 dir.scale(1.0/Math.sqrt(l));
391 offset.set(0.0, 0.0, 0.0);
393 for (PipeControlPoint icp : offsets) {
394 Vector3d v = icp.getSizeChangeOffsetVector(dir);
401 Point3d nep = new Point3d(endPoint);
403 if (nep.distance(ep) < 0.0000000001) {
410 l = dir.lengthSquared();
411 if (l > MathTools.NEAR_ZERO)
412 dir.scale(1.0/Math.sqrt(l));
416 System.out.println("calcOffset s:"+ startPoint + " e:" + endPoint + " d:" + dir + " o:"+offset) ;
422 public static void setZeroOffset(Vector3d startPoint, Vector3d endPoint, Vector3d dir, Vector3d offset) {
425 double l = dir.lengthSquared();
426 if (l > MathTools.NEAR_ZERO)
427 dir.scale(1.0/Math.sqrt(l));
428 offset.set(0.0, 0.0, 0.0);
431 public static List<PipeControlPoint> getOffsetPoints(PipeControlPoint start, ArrayList<PipeControlPoint> list) {
432 List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
433 // Only start offset affects the calculation
434 if (start.isOffset())
436 for (PipeControlPoint icp : list) {
437 if (icp.isOffset()) {
439 } else if (icp.isDualSub())
440 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
445 private static UpdateStruct2 createUS(PipeControlPoint start, Direction direction, int iter, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) {
446 ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
447 PipeControlPoint end = null;
448 if (direction == Direction.NEXT) {
449 end = start.findNextEnd(list);
451 ArrayList<PipeControlPoint> prevList = new ArrayList<PipeControlPoint>();
452 PipeControlPoint tend = start.findPreviousEnd(prevList);
453 for (PipeControlPoint icp : prevList) {
454 if (icp.isDualSub()) {
455 list.add(0, icp.getParentPoint());
465 boolean hasOffsets = false;
466 Vector3d offset = new Vector3d();
467 Vector3d startPoint = start.getWorldPosition();
468 Vector3d endPoint = end.getWorldPosition();
469 Vector3d dir = new Vector3d();
470 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
471 return new UpdateStruct2(start, startPoint, list, end, endPoint, dir, offset, hasOffsets, iter, direction == Direction.PREVIOUS, toRemove, updated);
474 private static boolean asDirected(PipeControlPoint pcp, Direction direction) {
475 if (pcp.isDirected())
477 if (pcp.asFixedAngle()) {
478 if (!pcp._getReversed())
479 return direction == Direction.NEXT;
481 return direction == Direction.PREVIOUS;
486 private static Vector3d direction(PipeControlPoint pcp, Direction direction) {
487 return pcp.getDirection(direction);
490 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
493 if (lengthChange == PathLegUpdateType.NONE) {
497 updatePathLeg(u, lengthChange, rs, re);
500 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean rs, boolean re) throws Exception {
502 if (asDirected(u.start, Direction.NEXT))
504 if (asDirected(u.end, Direction.PREVIOUS))
507 setErrorForce(u.start, null);
509 setErrorForce(u.end, null);
510 for (PipeControlPoint pcp : u.list)
511 setErrorForce(pcp, null);
514 updateFreePathLeg(u, lengthChange);
517 updateDirectedPathLeg(u, lengthChange);
520 updateDualDirectedPathLeg(u, lengthChange);
526 private static void updateFreePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
528 System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange);
529 checkExpandPathLeg(u, lengthChange);
530 if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle())
531 processPathLeg(u, true, false);
534 private static void updateInlineControlPoints(UpdateStruct2 u, boolean checkSizes) throws Exception{
536 System.out.println("PipingRules.updateInlineControlPoints() " + u);
538 Vector3d start = new Vector3d(u.startPoint);
539 Vector3d end = new Vector3d(u.endPoint);
542 // create offsets for leg ends.
543 if (u.start.isTurn())
544 MathTools.mad(start, u.dir, u.start.getInlineLength());
546 MathTools.mad(end, u.dir, -u.end.getInlineLength());
549 boolean recalcline = false;
551 Vector3d sp = new Vector3d(start);
552 Vector3d ep = new Vector3d(end);
555 if (u.start.isOffset()) {
556 Vector3d offset = u.start.getSizeChangeOffsetVector(u.dir);
557 updateOffsetPoint(u.start, offset);
562 for (PipeControlPoint icp : u.list) {
563 updateInlineControlPoint(icp, sp, ep, u.dir);
564 if (icp.isOffset()) {
565 // TODO : offset vector is already calculated and should be cached
566 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
567 updateOffsetPoint(icp, offset);
576 // Collect all path leg points for updating variable length components. This list will also contain leg ends (usually turns)
577 ArrayList<PipeControlPoint> pathLegPoints = new ArrayList<>();
578 // Collect all fixed length components with their offsets.
579 ArrayList<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints = new ArrayList<>();
581 pathLegPoints.add(u.start);
582 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.start, new Vector3d()));
583 Vector3d off = new Vector3d();
584 for (PipeControlPoint icp : u.list) {
585 pathLegPoints.add(icp);
586 updateBranchControlPointBranches(icp);
587 if (icp.isOffset()) {
588 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
589 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
591 } else if (!icp.isVariableLength()) {
592 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
595 pathLegPoints.add(u.end);
596 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.end, new Vector3d(off)));
598 sp = new Vector3d(start);
599 ep = new Vector3d(end);
602 updateFixedLengths(fixedLengthPoints, sp, ep, u.dir);
604 for (int i = 0; i < pathLegPoints.size(); i++) {
605 PipeControlPoint icp = pathLegPoints.get(i);
607 PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
608 PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
610 if (prev != null && prev.isDualInline())
611 prev = prev.getDualSub();
613 if (icp.isVariableLength()) {
614 if (prev != null && next != null) {
615 recalcline = recalcline | updateVariableLength(icp, prev, next);
618 // this is variable length component at the end of the piperun.
619 // the problem is that we want to keep unconnected end of the component in the same
620 // place, but center of the component must be moved.
621 updateVariableLengthEnd(icp, prev != null ? prev : next);
623 } else if (prev != null && !prev.isVariableLength()) {
624 // If this and previous control point are not variable length pcps,
625 // we'll have to check if there is no empty space between them.
626 // I there is, we'll have to create new variable length component between them.
627 recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
629 if (icp.isOffset()) {
630 // TODO : offset vector is already calculated and should be cached
631 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
639 u.start.findNextEnd(u.list);
642 sp = new Vector3d(u.startPoint);
643 ep = new Vector3d(u.endPoint);
645 double pathLegLength = MathTools.distance(sp, ep);
646 double availableLength = pathLegLength;
647 if (u.start.isTurn())
648 availableLength -= u.start.getInlineLength();
650 availableLength -= u.end.getInlineLength();
651 for (PipeControlPoint pcp : u.list) {
652 if (!pcp.isVariableLength())
653 availableLength-= pcp.getLength();
655 if (availableLength < 0.0) {
656 setError(u.start, "Not enough available space");
657 setError(u.end, "Not enough available space");
658 for (PipeControlPoint pcp : u.list)
659 setError(pcp, "Not enough available space");
661 // System.out.println(u.start.getPipelineComponent().toString() + " " + pathLegLength + " " + availableLength + " " + u.end.getPipelineComponent().toString() + " " + u.start.getInlineLength() + " " + u.end.getInlineLength());
665 private enum Gap{ATTACHED,OVERLAP,SPACE};
667 private static class GapObj {
671 Pair<PipeControlPoint,Vector3d> pcp1;
672 Pair<PipeControlPoint,Vector3d> pcp2;
675 private static void updateFixedLengths(List<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints, Vector3d s, Vector3d e, Vector3d dir) {
676 double totalLength = MathTools.distance(s, e);
677 double reservedLength = 0.0;
678 List<Double> distances = new ArrayList<>(fixedLengthPoints.size());
680 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
681 Pair<PipeControlPoint,Vector3d> pcp = fixedLengthPoints.get(i);
682 reservedLength += pcp.first.getLength();
683 Vector3d p = pcp.first.getWorldPosition();
685 double d= MathTools.distance(s, p);
688 distances.add(totalLength);
690 if (totalLength >= reservedLength) {
691 // There is enough space for all fixed length components.
692 List<GapObj> gaps = new ArrayList<>(fixedLengthPoints.size()-1);
694 // Analyze gaps between components
695 for (int i = 0; i < fixedLengthPoints.size()-1; i++) {
696 Pair<PipeControlPoint,Vector3d> pcp1 = fixedLengthPoints.get(i);
697 Pair<PipeControlPoint,Vector3d> pcp2 = fixedLengthPoints.get(i+1);
698 double d1 = distances.get(i);
699 double d2 = distances.get(i+1);
700 double ld1 = i == 0 ? 0.0 :pcp1.first.getInlineLength();
701 double ld2 = i == fixedLengthPoints.size()-2 ? 0.0 : pcp2.first.getInlineLength();
703 double e1 = d1 + ld1; // End of comp1
704 double s2 = d2 - ld2; // Start of comp2
705 double diff =s2 - e1;
706 GapObj obj = new GapObj();
710 if (diff < -MIN_INLINE_LENGTH) {
711 obj.gap = Gap.OVERLAP;
713 } else if (diff > MIN_INLINE_LENGTH) {
716 obj.gap = Gap.ATTACHED;
720 // If there are no overlaps, there is nothing to do.
723 // Get rid of overlapping components by using closest available free spaces.
724 for (int i = 0; i < gaps.size(); i++) {
725 GapObj gapObj = gaps.get(i);
726 if (gapObj.gap != Gap.OVERLAP)
728 double curr = gapObj.d;
730 while (curr < -MIN_INLINE_LENGTH) {
731 GapObj next = i+d >= 0 ? gaps.get(i+d) : null;
732 GapObj prev = i-d >= 0 ? gaps.get(i-d) : null;
733 if (next != null && next.gap == Gap.SPACE) {
734 double move = Math.min(-curr, next.d);
737 if (next.d < MIN_INLINE_LENGTH)
738 next.gap = Gap.ATTACHED;
739 Vector3d mv = new Vector3d(dir);
742 for (int j = i ; j < i+d; j++) {
743 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp2;
744 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
746 pcp.first.setWorldPosition(p);
749 if (curr < -MIN_INLINE_LENGTH && prev != null && prev.gap == Gap.SPACE) {
750 double move = Math.min(-curr, prev.d);
753 if (next.d < MIN_INLINE_LENGTH)
754 next.gap = Gap.ATTACHED;
755 Vector3d mv = new Vector3d(dir);
758 for (int j = i ; j > i-d; j--) {
759 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp1;
760 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
762 pcp.first.setWorldPosition(p);
768 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
769 Pair<PipeControlPoint,Vector3d> prev = i == 0 ? null : fixedLengthPoints.get(i-1);
770 Pair<PipeControlPoint,Vector3d> curr = fixedLengthPoints.get(i);
771 Pair<PipeControlPoint,Vector3d> next = i == fixedLengthPoints.size() -1 ? null : fixedLengthPoints.get(i+1);
772 updateFixedLength(curr, prev, next, s,e, dir);
777 private static void updateFixedLength(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> prev, Pair<PipeControlPoint,Vector3d> next, Vector3d s, Vector3d e, Vector3d dir) {
779 checkOverlap(prev, icp, dir,true);
782 checkOverlap(icp, next, dir,true);
785 private static boolean checkOverlap(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> icp2, Vector3d dir, boolean se) {
786 Vector3d p1 = icp.first.getWorldPosition();
787 Vector3d p2 = icp2.first.getWorldPosition();
790 double u[] = new double[1];
791 MathTools.closestPointOnStraight(p2, p1, dir, u);
796 MathTools.mad(p2, dir, MIN_INLINE_LENGTH);
797 icp2.first.setWorldPosition(p2);
799 double d = MathTools.distance(p1, p2);
800 double r = icp.first.getInlineLength() + icp2.first.getInlineLength();
802 if ((d-r) < - MIN_INLINE_LENGTH) {
804 setError(icp.first, "Overlapping");
805 setError(icp2.first, "Overlapping");
813 * Overrides current error of a component
817 private static void setErrorForce(PipeControlPoint pcp, String error) {
818 PipelineComponent comp = pcp.getPipelineComponent();
821 comp.setError(error);
825 * Sets error for a component, if there is no existing error.
829 private static void setError(PipeControlPoint pcp, String error) {
830 PipelineComponent comp = pcp.getPipelineComponent();
833 if (comp.getError() != null)
835 comp.setError(error);
838 private static boolean updateVariableLength(PipeControlPoint icp, PipeControlPoint prev, PipeControlPoint next) {
839 Vector3d prevPos = prev.getWorldPosition();
840 Vector3d nextPos = next.getWorldPosition();
842 Vector3d dir = new Vector3d(nextPos);
844 double l = dir.length(); // distance between control points
845 double l2prev = prev.getInlineLength(); // distance taken by components
846 double l2next = next.getInlineLength();
847 double l2 = l2prev + l2next;
848 double length = l - l2; // true length of the variable length component
849 if (length >= MIN_INLINE_LENGTH) { // check if there is enough space for variable length component.
852 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
854 icp.setWorldPosition(dir);
855 icp.setLength(length);
858 // components leave no space to the component and it must be removed
859 if (icp.isDeletable()) {
860 if (!allowInsertRemove) {
861 icp.setLength(MIN_INLINE_LENGTH);
862 setError(icp, "Not enough available space");
867 System.out.println("PipingRules.updateVariableLength removing " + icp);
871 icp.setLength(MIN_INLINE_LENGTH);
872 icp.getPipelineComponent().setError("Not enough available space");
878 private static boolean possibleVaribleLengthInsert(PipeControlPoint icp, PipeControlPoint prev) throws Exception{
879 Vector3d currentPos = icp.getWorldPosition();
880 Vector3d prevPos = prev.getWorldPosition();
881 Vector3d dir = new Vector3d(currentPos);
883 double l = dir.lengthSquared();
884 double l2prev = prev.getInlineLength();
885 double l2next = icp.getInlineLength();
886 double l2 = l2prev + l2next;
887 double l2s = l2 * l2;
888 double diff = l - l2s;
889 if (diff >= MIN_INLINE_LENGTH) {
890 if (allowInsertRemove) {
892 double length = Math.sqrt(l) - l2; // true length of the variable length component
893 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
895 insertStraight(prev, icp, dir, length);
904 private static void updateVariableLengthEnd(PipeControlPoint icp, PipeControlPoint prev) {
905 Vector3d currentPos = icp.getWorldPosition();
906 Vector3d prevPos = prev.getWorldPosition();
908 Vector3d dir = new Vector3d();
909 dir.sub(currentPos, prevPos);
911 boolean simple = currentUpdates.contains(icp);
913 // Update based on position -> adjust length
914 double currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
915 icp.setLength(currentLength);
917 // Update based on neighbour movement -> adjust length and position, so that free end stays in place.
918 double currentLength = icp.getLength();
919 if (currentLength < MathTools.NEAR_ZERO) {
920 currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
923 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
925 Point3d endPos = new Point3d(dir);
926 endPos.scale(currentLength * 0.5);
927 endPos.add(currentPos); // this is the free end of the component
929 double offset = prev.getInlineLength();
930 Point3d beginPos = new Point3d(dir);
931 beginPos.scale(offset);
932 beginPos.add(prevPos); // this is the connected end of the component
934 double l = beginPos.distance(endPos);
937 System.out.println("Length for " + icp + " is NaN");
940 beginPos.add(dir); // center position
943 System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
946 icp.setWorldPosition(new Vector3d(beginPos));
951 * Recalculates offset vector based on current direction, and calls checkExpandPathLeg
956 private static void ppNoOffset(UpdateStruct2 u, boolean updateEnds) throws Exception {
958 System.out.println("PipingRules.ppNoOffset() " + u);
959 Vector3d offset = new Vector3d();
961 for (PipeControlPoint icp : u.list) {
962 if (icp.isOffset()) {
963 offset.add(icp.getSizeChangeOffsetVector(u.dir));
964 } else if (icp.isDualSub())
965 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
969 checkExpandPathLeg(u, PathLegUpdateType.NONE, updateEnds);
972 private static void ppNoDir(PipeControlPoint start, Vector3d startPoint, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d endPoint, boolean hasOffsets, int iter, boolean reversed, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) throws Exception {
974 System.out.println("PipingRules.ppNoDir() " + start + " " + end + " " + iter + " " + toRemove.size());
975 // FIXME : extra loop (dir should be calculated here)
976 Vector3d dir = new Vector3d();
977 Vector3d offset = new Vector3d();
978 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
979 ppNoOffset(new UpdateStruct2(start, startPoint, list, end, endPoint, dir, null, hasOffsets, iter, reversed, toRemove, updated),true);
982 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
983 checkExpandPathLeg(u, lengthChange, u.updated.isInline() && u.updated.isOffset());
986 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean updateEnds) throws Exception {
988 System.out.println("PipingRules.checkExpandPathLeg() " + u + " " + lengthChange);
989 if (lengthChange != PathLegUpdateType.NONE) {
990 // FIXME : turns cannot be checked before inline cps are updated,
991 // since their position affects calculation of turns
992 processPathLeg(u, updateEnds, false);
993 int type = checkTurns(u, lengthChange);
994 if (type == REMOVE_NONE) {
995 processPathLeg(u, updateEnds, true);
997 expandPathLeg(u, type);
1000 processPathLeg(u, updateEnds, true);
1004 private static void updateDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1006 System.out.println("PipingRules.updateDirectedPipeRun() " + u + " " + lengthChange);
1007 PipeControlPoint dcp;
1008 PipeControlPoint other;
1009 boolean canMoveOther = false;
1010 boolean dcpStart = false;
1011 boolean inlineEnd = false;
1013 if (asDirected(u.start, Direction.NEXT)) {
1016 position = u.startPoint;
1019 canMoveOther = true;
1020 inlineEnd = u.end.isInline();
1025 position = u.endPoint;
1027 canMoveOther = true;
1028 inlineEnd = u.start.isInline();
1031 Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1032 if (directedDirection == null) {
1033 //updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
1034 updateTurnControlPointTurn(dcp, null, null);
1035 directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1036 if (directedDirection == null) {
1040 Point3d directedEndPoint = new Point3d(u.endPoint);
1042 directedEndPoint.sub(u.offset);
1044 double mu[] = new double[2];
1047 Vector3d t = new Vector3d();
1050 closest = MathTools.closestPointOnStraight(directedEndPoint, u.startPoint, directedDirection, mu);
1051 t.sub(closest, directedEndPoint);
1053 closest = MathTools.closestPointOnStraight(u.startPoint, directedEndPoint, directedDirection, mu);
1054 t.sub(closest, u.startPoint);
1057 double distance = t.length();
1058 boolean aligned = (distance < ALLOWED_OFFSET);
1059 double requiredSpace = 0.0;
1060 if (other.isVariableAngle()) {
1061 requiredSpace = spaceForTurn(other, dcp);
1063 if (mu[0] < requiredSpace) {
1064 // At the moment, if next component is directly behind the nozzle, we must force moving the other component.
1065 // Trying to solve the situation by adding new turn creates infinite loop...
1067 canMoveOther = true;
1070 //if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
1071 // processPathLeg(u, true, false);
1072 checkExpandPathLeg(u, lengthChange, inlineEnd || u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle());
1077 PipeControlPoint nextToMoved;
1079 if (u.list.size() > 0)
1081 nextToMoved = u.list.get(0);
1083 nextToMoved = u.list.get(u.list.size() - 1);
1085 nextToMoved = u.end;
1087 nextToMoved = u.start;
1088 if (other.isVariableAngle()) {
1090 // TODO calculate needed space from next run end.
1091 if (mu[0] < requiredSpace) {
1093 closest.set(u.startPoint);
1095 closest.set(u.endPoint);
1097 Vector3d v = new Vector3d(directedDirection);
1098 v.scale(requiredSpace);
1104 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + closest);
1106 // Not aligned - we need to recalculate the offset to reflect new end points.
1109 offset = new Vector3d();
1110 Vector3d newDir = new Vector3d();
1111 calculateDirectedOffset(position, closest, u.start, u.list, u.end, newDir, offset);
1112 closest.add(offset);
1114 offset = new Vector3d();
1117 other.setWorldPosition(closest);
1120 checkExpandPathLeg(new UpdateStruct2(u.start, u.startPoint, u.list, u.end, new Vector3d(closest), directedDirection, offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), PathLegUpdateType.NONE, true);
1121 if (u.end.getNext() != null)
1122 updatePathLegNext(u.end, u.updated, PathLegUpdateType.NEXT);
1124 checkExpandPathLeg(new UpdateStruct2(u.start, new Vector3d(closest), u.list, u.end, u.endPoint, directedDirection, offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), PathLegUpdateType.NONE, true);
1125 if (u.start.getPrevious() != null)
1126 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.PREV);
1129 // TODO : calculate needed space from next run end.
1130 if (allowInsertRemove)
1131 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1136 } else if (other.isNonDirected() && other.getParentPoint() != null) {
1137 // FIXME : this code was for updating branches
1138 Vector3d bintersect = new Vector3d();
1139 PipeControlPoint bcp = other.getParentPoint();
1140 if (bcp != null && canMoveOther) {
1141 Point3d bstart = new Point3d();
1142 Point3d bend = new Point3d();
1143 Vector3d bdir = new Vector3d();
1144 bcp.getInlineControlPointEnds(bstart, bend, bdir);
1145 Vector3d nintersect = new Vector3d();
1147 MathTools.intersectStraightStraight(position, directedDirection, bend, bdir, nintersect, bintersect, mu);
1148 Vector3d dist = new Vector3d(nintersect);
1149 dist.sub(bintersect);
1150 canMoveOther = mu[1] > 0.0 && mu[1] < 1.0 && dist.lengthSquared() < 0.01;
1152 // TODO : endControlPoints are undirected: calculcate
1153 // correct position for it
1154 throw new UnsupportedOperationException("not implemented");
1158 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + bintersect);
1159 // is required branch position is in possible range
1160 bcp.setWorldPosition(bintersect);
1162 checkExpandPathLeg(new UpdateStruct2(u.start, u.startPoint, u.list, u.end, new Vector3d(bintersect), directedDirection, u.offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), lengthChange);
1164 checkExpandPathLeg(new UpdateStruct2(u.start, new Vector3d(bintersect), u.list, u.end, u.endPoint, directedDirection, u.offset, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated), lengthChange);
1167 // branch cannot be moved into right position, new turn
1168 // / elbow must be inserted
1169 if (allowInsertRemove)
1170 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1175 } else { // assume that control point cannot be moved, but can
1177 if (allowInsertRemove)
1178 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1188 private static void updateDualDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1190 System.out.println("PipingRules.updateDualDirectedPipeRun() " + u + " " + lengthChange);
1192 PipeControlPoint dcp1 = u.start;
1193 PipeControlPoint dcp2 = u.end;
1194 Point3d position1 = new Point3d(u.startPoint);
1195 Point3d position2 = new Point3d(u.endPoint);
1196 Point3d position1offset = new Point3d(position1);
1197 position1offset.sub(u.offset);
1198 Point3d position2offset = new Point3d(position2);
1199 position2offset.add(u.offset);
1200 Vector3d dir1 = direction(dcp1, Direction.NEXT);
1201 Vector3d dir2 = direction(dcp2, Direction.PREVIOUS);
1202 Vector3d p1 = MathTools.closestPointOnStraight(position1offset, position2, dir2);
1203 Vector3d p2 = MathTools.closestPointOnStraight(position2offset, position1, dir1);
1204 double d1 = position1.distance(new Point3d(p1));
1205 double d2 = position2.distance(new Point3d(p2));
1207 boolean aligned = (d1 < ALLOWED_OFFSET && d2 < ALLOWED_OFFSET);
1213 } else if (allowInsertRemove){
1214 PipeControlPoint dcp;
1215 PipeControlPoint next;
1218 if (u.list.size() > 0)
1219 next = u.list.get(0);
1224 if (u.list.size() > 0)
1225 next = u.list.get(u.list.size() - 1);
1230 p1 = dcp.getWorldPosition();
1231 Vector3d v = new Vector3d();
1237 // Reserve space for 90 deg elbow
1238 double off = dcp1.getPipeRun().getTurnRadius();
1243 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position2, dir2);
1245 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position1, dir1);
1247 // By default, the elbows are placed next to each other, by using 90 deg angles.
1248 // If the distance between elbows is not enough, we must move the other elbow (and create more shallow angle elbows)
1249 if (MathTools.distance(p1, p2) < off*2.05) {
1253 PipeControlPoint tcp1 = insertElbow(dcp, next, p1);
1254 PipeControlPoint tcp2 = insertElbow(tcp1, next, p2);
1257 System.out.println("PipingRules.updateDualDirectedPipeRun() created two turns " + tcp1 + " " + tcp2);
1260 Vector3d dd = new Vector3d(p2);
1263 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1264 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1266 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1268 updatePathLegPrev(tcp2, u.updated, PathLegUpdateType.NONE);
1270 Vector3d dd = new Vector3d(p1);
1273 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1274 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1276 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1278 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.NONE);
1287 private static double spaceForTurn(PipeControlPoint tcp, PipeControlPoint dcp) {
1288 // TODO : if the path legs contain offset, using just positions of opposite path leg ends is not enough.
1289 // TODO : current iterative way for calculating required space may return longer length that is required.
1290 double tr = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1292 return tr; // space for 90 deg
1293 PipeControlPoint ne = tcp.findNextEnd();
1294 PipeControlPoint pe = tcp.findPreviousEnd();
1295 PipeControlPoint other = null;
1301 return tr; // space for 90 deg
1303 return tr; // space for 90 deg
1304 Vector3d dir = dcp.getDirectedControlPointDirection();
1305 Vector3d dp = dcp.getWorldPosition();
1306 Vector3d op = other.getWorldPosition();
1307 double u[] = new double[1];
1308 Vector3d closest = MathTools.closestPointOnStraight(op, dp, dir,u);
1309 if (MathTools.distanceSquared(closest, op) <= MIN_INLINE_LENGTH) {
1310 if (u[0] > -MIN_INLINE_LENGTH)
1311 return 0.0; // point following turn is directly in the front of the nozzle.
1313 return tr*2.0; // point following turn is directly behind the nozzle, in theory, we should return Double.Inf...
1315 double curr = tr*0.1;
1317 Vector3d v1 = new Vector3d();
1318 Vector3d v2 = new Vector3d();
1320 Vector3d tp = new Vector3d(dp);
1321 MathTools.mad(tp, dir, curr);
1322 v1.sub(tp, dp); // Vector from nozzle to turn
1323 v2.sub(op,tp); // Vector from turn to other
1324 double a = v1.angle(v2);
1325 double t = Math.tan((Math.PI - a) * 0.5);
1327 if (t > MathTools.NEAR_ZERO)
1337 private static void insertElbowUpdate(UpdateStruct2 u, PipeControlPoint dcp, PipeControlPoint next, boolean dcpStart, Vector3d position, Vector3d directedDirection) throws Exception{
1340 // Vector3d closest = new Vector3d(position);
1341 // closest.add(directedDirection);
1343 PipeControlPoint tcp = null;
1346 closest = MathTools.closestPointOnStraight(next.getWorldPosition(), position, directedDirection);
1347 tcp = insertElbow(dcp, next, closest);
1349 closest = MathTools.closestPointOnStraight(dcp.getWorldPosition(), position, directedDirection);
1350 tcp = insertElbow(next, dcp, closest);
1352 double d = MathTools.distance(position, closest);
1353 double s = spaceForTurn(tcp,dcp);
1356 Vector3d p = new Vector3d(directedDirection);
1366 System.out.println("PipingRules.updateDirectedPipeRun() inserted " + tcp);
1369 // update pipe run from new turn to other end
1370 ppNoDir(tcp, new Vector3d(closest), u.list, u.end, u.endPoint, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1371 // update pipe run from directed to new turn
1372 processPathLeg(new UpdateStruct2(u.start, u.startPoint, new ArrayList<PipeControlPoint>(), tcp, new Vector3d(closest), directedDirection, new Vector3d(), false, 0, false, new ArrayList<ExpandIterInfo>(), u.updated));
1374 // update pipe run from other end to new turn
1375 ppNoDir(u.start, u.startPoint, u.list, tcp, new Vector3d(closest), u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1376 // update pipe run from new turn to directed
1377 processPathLeg(new UpdateStruct2(tcp, new Vector3d(closest), new ArrayList<PipeControlPoint>(), u.end, u.endPoint, directedDirection, new Vector3d(), false, 0, false, new ArrayList<ExpandIterInfo>(), u.updated));
1382 * Checks if turns can be removed (turn angle near zero)
1384 private static int checkTurns(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1386 System.out.println("PipingRules.checkTurns() " + u.start + " " + u.end);
1387 boolean startRemoved = false;
1388 boolean endRemoved = false;
1389 if (u.start.isVariableAngle()) {
1390 // this won't work properly if inline control points are not updated
1391 PipeControlPoint startPrev = u.start.getPrevious();
1392 if (startPrev != null) {
1393 double a = updateTurnControlPointTurn(u.start, null, u.dir);
1394 if (a < MIN_TURN_ANGLE && u.start.isDeletable())
1395 startRemoved = true;
1396 else if (lengthChange == PathLegUpdateType.PREV || lengthChange == PathLegUpdateType.PREV_S) {
1397 PathLegUpdateType type;
1398 if (lengthChange == PathLegUpdateType.PREV_S)
1399 type = PathLegUpdateType.PREV;
1401 type = PathLegUpdateType.NONE;
1402 updatePathLegPrev(u.start, u.start, type);
1406 if (u.end.isVariableAngle()) {
1408 PipeControlPoint endNext = u.end.getNext();
1409 if (endNext != null) {
1410 // TODO: u.end, u.dir, null
1411 double a = updateTurnControlPointTurn(u.end, null, null);
1412 if (a < MIN_TURN_ANGLE && u.end.isDeletable())
1414 else if (lengthChange == PathLegUpdateType.NEXT || lengthChange == PathLegUpdateType.NEXT_S) {
1415 PathLegUpdateType type;
1416 if (lengthChange == PathLegUpdateType.NEXT_S)
1417 type = PathLegUpdateType.NEXT;
1419 type = PathLegUpdateType.NONE;
1420 updatePathLegNext(u.end, u.end, type);
1425 System.out.println("PipingRules.checkTurns() res " + startRemoved + " " + endRemoved);
1426 if (!startRemoved && !endRemoved)
1428 if (startRemoved && endRemoved)
1431 return REMOVE_START;
1436 * Expands piperun search over turns that are going to be removed
1439 private static void expandPathLeg(UpdateStruct2 u, int type) throws Exception {
1441 System.out.println("PipingRules.expandPipeline " + u.start + " " + u.end);
1442 ArrayList<PipeControlPoint> newList = new ArrayList<PipeControlPoint>();
1445 throw new RuntimeException("Error in piping rules");
1447 u.toRemove.add(new ExpandIterInfo(u.start, REMOVE_START));
1448 u.start = u.start.findPreviousEnd();
1449 u.startPoint = u.start.getPosition();
1450 u.start.findNextEnd(newList);
1451 newList.addAll(u.list);
1455 u.toRemove.add(new ExpandIterInfo(u.end, REMOVE_END));
1456 u.end = u.end.findNextEnd(newList);
1457 u.endPoint = u.end.getPosition();
1458 u.list.addAll(newList);
1461 u.toRemove.add(new ExpandIterInfo(u.start, u.end));
1462 u.start = u.start.findPreviousEnd();
1463 u.startPoint = u.start.getPosition();
1464 u.start.findNextEnd(newList);
1465 newList.addAll(u.list);
1467 newList = new ArrayList<PipeControlPoint>();
1468 u.end = u.end.findNextEnd(newList);
1469 u.endPoint = u.end.getPosition();
1470 u.list.addAll(newList);
1473 throw new RuntimeException("Error in piping rules");
1476 u.offset = new Vector3d();
1479 for (PipeControlPoint icp : u.list) {
1480 if (icp.isOffset()) {
1481 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1482 } else if (icp.isDualSub())
1483 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1487 System.out.println("PipingRules.expandPipeline expanded " + u.start + " " + u.end);
1489 updatePathLeg(u, PathLegUpdateType.NONE);
1493 * reverts one iteration of turn removing back)
1495 private static void backIter(UpdateStruct2 u) throws Exception {
1498 System.out.println("PipingRules.backIter" + u.start + " " + u.end);
1500 throw new RuntimeException("Error in piping rules");
1501 ExpandIterInfo info = u.toRemove.get(u.toRemove.size() - 1);
1502 u.toRemove.remove(u.toRemove.size() - 1);
1503 if (info.getType() == REMOVE_START || info.getType() == REMOVE_BOTH) {
1504 while (u.list.size() > 0) {
1505 PipeControlPoint icp = u.list.get(0);
1506 if (icp.getPrevious().equals(info.getStart()))
1510 u.start = info.getStart();
1512 if (info.getType() == REMOVE_END || info.getType() == REMOVE_BOTH) {
1513 while (u.list.size() > 0) {
1514 PipeControlPoint icp = u.list.get(u.list.size() - 1);
1515 if (icp.getNext().equals(info.getEnd()))
1519 u.end = info.getEnd();
1521 u.offset = new Vector3d();
1524 for (PipeControlPoint icp : u.list) {
1525 if (icp.isOffset()) {
1526 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1527 } else if (icp.isDualSub())
1528 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1536 * Processes pipe run (removes necessary turns and updates run ends)
1538 // private static void processPathLeg(PipeControlPoint start, Point3d
1539 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1540 // end,Point3d endPoint, Vector3d dir,Vector3d offset, boolean
1541 // hasOffsets,int iter, boolean reversed, ArrayList<ExpandIterInfo>
1542 // toRemove) throws TransactionException {
1544 private static void processPathLeg(UpdateStruct2 u) throws Exception {
1546 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1547 processPathLeg(u, true, true);
1550 private static void processPathLeg(UpdateStruct2 u, boolean updateEnds, boolean updateInline) throws Exception {
1552 System.out.println("PipingRules.processPathLeg " + (updateEnds ? "ends " : "") + (updateInline ? "inline " : "") + u.start + " " + u.end);
1554 if (u.toRemove.size() > 0) {
1555 for (ExpandIterInfo info : u.toRemove) {
1556 if (info.getStart() != null) {
1558 System.out.println("PipingRules.processPathLeg removing start " + info.getStart());
1559 info.getStart()._remove();
1561 if (info.getEnd() != null) {
1563 System.out.println("PipingRules.processPathLeg removing end " + info.getEnd());
1564 info.getEnd()._remove();
1567 // ControlPointTools.removeControlPoint may remove more than one CP;
1568 // we must populate inline CP list again.
1570 u.start.findNextEnd( u.list);
1572 // FIXME : inline CPs are update twice because their positions must be
1573 // updated before and after ends.
1574 updateInlineControlPoints(u, false);
1577 if (u.start.isTurn()) {
1578 //updateTurnControlPointTurn(u.start, u.start.getPrevious(), u.start.getNext());
1579 updateTurnControlPointTurn(u.start, null, null);
1580 // updatePathLegPrev(u.start, u.start, PathLegUpdateType.NONE);
1581 } else if (u.start.isEnd()) {
1582 updateEndComponentControlPoint(u.start, u.dir);
1583 } else if (u.start.isInline()) {
1584 updateControlPointOrientation(u.start, u.dir);
1586 if (u.end.isTurn()) {
1587 //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext());
1588 updateTurnControlPointTurn(u.end, null, null);
1589 // updatePathLegNext(u.end, u.end, PathLegUpdateType.NONE);
1590 } else if (u.end.isEnd()) {
1591 updateEndComponentControlPoint(u.end, u.dir);
1592 } else if (u.end.isInline()) {
1593 updateControlPointOrientation(u.end, u.dir);
1597 if (u.start.isEnd()) {
1598 updateEndComponentControlPoint(u.start, u.dir);
1600 if (u.end.isEnd()) {
1601 updateEndComponentControlPoint(u.end, u.dir);
1605 updateInlineControlPoints(u, true);
1610 * Processes pipe run and recalculates offset
1612 // private static void processPathLeg(PipeControlPoint start, Point3d
1613 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1614 // end,Point3d endPoint, Vector3d dir, boolean hasOffsets,int iter, boolean
1615 // reversed, ArrayList<ExpandIterInfo> toRemove) throws TransactionException
1617 @SuppressWarnings("unused")
1618 private static void processPathLegNoOffset(UpdateStruct2 u) throws Exception {
1620 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1621 Vector3d offset = new Vector3d();
1624 for (PipeControlPoint icp : u.list) {
1625 if (icp.isOffset()) {
1626 offset.add(icp.getSizeChangeOffsetVector(u.dir));
1627 } else if (icp.isDualSub()) {
1628 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1635 private static void updateOffsetPoint(PipeControlPoint sccp, Vector3d offset) {
1636 Vector3d world = sccp.getWorldPosition();
1638 PipeControlPoint ocp = sccp.getDualSub();
1639 ocp.setWorldPosition(world);
1643 * Updates InlineControlPoints position when straight pipe's end(s) have
1651 private static void updateInlineControlPoint(PipeControlPoint icp, Vector3d prev, Vector3d next, Vector3d dir) {
1653 System.out.println("PipingRules.updateInlineControlPoint() " + icp);
1655 Vector3d inlinePoint = icp.getWorldPosition();
1656 Vector3d prevPoint = new Vector3d(prev);
1657 Vector3d nextPoint = new Vector3d(next);
1658 if (!icp.isVariableLength()) {
1659 // Reserve space for fixed length components.
1660 MathTools.mad(prevPoint, dir, icp.getInlineLength());
1661 MathTools.mad(nextPoint, dir, -icp.getInlineLength());
1662 if (MathTools.distance(prevPoint, nextPoint) < ALLOWED_OFFSET) {
1667 boolean canCalc = MathTools.distance(prevPoint, nextPoint) > ALLOWED_OFFSET;
1669 System.out.print("InlineControlPoint update " + icp + " " + inlinePoint + " " + prevPoint + " " + nextPoint);
1670 Vector3d newInlinePoint = null;
1672 boolean branchUpdate = false;
1673 PipeControlPoint becp = null;
1674 for (PipeControlPoint pcp : icp.getChildPoints())
1675 if (pcp.isNonDirected()) {
1676 branchUpdate = true;
1681 if (DUMMY || !branchUpdate) {
1682 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1686 // FIXME : can only handle one branch
1687 PipeControlPoint p = null;
1688 if (becp.getNext() != null) {
1689 p = becp.findNextEnd();
1690 } else if (becp.getPrevious() != null) {
1691 p = becp.findPreviousEnd();
1694 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1695 } else if (canCalc){
1696 Vector3d branchLegEnd = p.getWorldPosition();
1697 Vector3d dir2 = new Vector3d(inlinePoint);
1698 dir2.sub(branchLegEnd);
1699 Vector3d dir1 = new Vector3d(nextPoint);
1700 dir1.sub(prevPoint);
1701 newInlinePoint = new Vector3d();
1702 double mu[] = new double[2];
1703 MathTools.intersectStraightStraight(new Vector3d(prevPoint), dir1, new Vector3d(branchLegEnd), dir2, newInlinePoint, new Vector3d(), mu);
1705 System.out.println(mu[0]);
1706 // FIXME : reserve space
1708 newInlinePoint = new Vector3d(prevPoint);
1709 } else if (mu[0] > 1.0) {
1710 newInlinePoint = new Vector3d(nextPoint);
1715 // prevPoint == nextPoint
1716 newInlinePoint = new Vector3d(prevPoint);
1719 System.out.println(" " + newInlinePoint);
1721 icp.setWorldPosition(newInlinePoint);
1722 updateControlPointOrientation(icp, dir);
1726 * Updates InlineControlPoints position when straight pipe's end(s) have
1734 private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d dir) throws Exception {
1736 System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
1738 if (!ecp.isFixed()) // prevent overriding nozzle orientations..
1739 updateControlPointOrientation(ecp, dir);
1741 for (PipeControlPoint pcp : ecp.getChildPoints()) {
1742 // TODO update position
1743 updatePathLegEndControlPoint(pcp);
1747 private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) {
1748 Double angleO = pcp.getRotationAngle();
1752 boolean reversed = pcp._getReversed();
1755 q = pcp.getControlPointOrientationQuat(dir, angle, reversed);
1757 q = pcp.getControlPointOrientationQuat(angle, reversed);
1759 pcp.setWorldOrientation(q);
1763 * Updates all branches when branch's position has been changed
1767 private static void updateBranchControlPointBranches(PipeControlPoint bcp) throws Exception {
1769 System.out.println("PipingRules.updateBranchControlPointBranches() " + bcp);
1770 if (bcp.isDualInline())
1772 Collection<PipeControlPoint> branches = bcp.getChildPoints();
1773 if (branches.size() == 0) {
1775 System.out.println("No Branches found");
1779 for (PipeControlPoint pcp : branches) {
1780 updatePathLegEndControlPoint(pcp);
1784 private static double updateTurnControlPointTurn(PipeControlPoint tcp, Vector3d prev, Vector3d next) {
1786 UpdateStruct2 us = createUS(tcp, Direction.NEXT, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1791 UpdateStruct2 us = createUS(tcp, Direction.PREVIOUS, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1797 if (!tcp.asFixedAngle()) {
1800 if (next == null || prev == null) {
1801 if (tcp.getTurnAngle() != null)
1802 return tcp.getTurnAngle();
1803 return Math.PI; // FIXME : argh
1805 double turnAngle = prev.angle(next);
1807 double angle = Math.PI - turnAngle;
1809 Vector3d turnAxis = new Vector3d();
1810 turnAxis.cross(prev, next);
1811 if (turnAxis.lengthSquared() > MathTools.NEAR_ZERO) {
1812 double elbowRadius = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1813 double R = elbowRadius / Math.tan(angle * 0.5);
1815 turnAxis.normalize();
1816 tcp.setTurnAngle(turnAngle);
1817 tcp.setLength(R);// setComponentOffsetValue(R);
1818 tcp.setTurnAxis(turnAxis);
1819 // tcp.setPosition(tcp.getPosition());
1822 tcp.setTurnAngle(0.0);
1824 tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
1827 updateControlPointOrientation(tcp,prev);
1830 System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
1834 if (prev != null && next != null) {
1836 } else if (prev == null) {
1837 if (!tcp._getReversed())
1838 tcp.setReversed(true);
1839 } else if (next == null) {
1840 if (tcp._getReversed())
1841 tcp.setReversed(false);
1844 Vector3d dir = null;
1845 if (!tcp._getReversed()) {
1852 return Math.PI; // FIXME : argh
1855 Quat4d q = PipeControlPoint.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
1856 Vector3d v = new Vector3d();
1857 MathTools.rotate(q, MathTools.Y_AXIS,v);
1859 tcp.setWorldOrientation(q);
1860 if (tcp.getTurnAngle() != null)
1861 return tcp.getTurnAngle();
1862 return Math.PI; // FIXME : argh
1868 public static List<PipeControlPoint> getControlPoints(PipeRun pipeRun) {
1869 List<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
1870 if (pipeRun.getControlPoints().size() == 0)
1872 PipeControlPoint pcp = pipeRun.getControlPoints().iterator().next();
1873 while (pcp.getPrevious() != null) {
1874 PipeControlPoint prev = pcp.getPrevious();
1875 if (prev.getPipeRun() != pipeRun && prev.getPipeRun() != null) { // bypass possible corruption
1880 if (pcp.isDualSub()) {
1881 pcp = pcp.getParentPoint();
1884 while (pcp.getNext() != null) {
1885 pcp = pcp.getNext();
1886 if (pcp.getPipeRun() != pipeRun)
1893 public static void reverse(PipeRun pipeRun) {
1896 List<PipeControlPoint> points = getControlPoints(pipeRun);
1897 PipeControlPoint pcp = points.get(0);
1898 if (pcp.isSizeChange() && pcp.getChildPoints().size() > 0) {
1899 PipeRun pr = pcp.getPipeRun();
1907 List<PipeRun> all = new ArrayList<PipeRun>();
1908 List<List<PipeControlPoint>> pcps = new ArrayList<List<PipeControlPoint>>();
1911 List<PipeControlPoint> points = getControlPoints(pipeRun);
1913 PipeControlPoint pcp = points.get(points.size()-1);
1914 if (pcp.getChildPoints().size() > 0) {
1915 PipeRun pipeRun2 = pcp.getChildPoints().get(0).getPipeRun();
1916 if (pipeRun == pipeRun2)
1924 for (int i = 0 ; i < all.size(); i++) {
1925 List<PipeControlPoint> list = pcps.get(i);
1928 for (int i = 0 ; i < all.size(); i++) {
1929 boolean last = i == all.size() - 1;
1930 List<PipeControlPoint> list = pcps.get(i);
1933 List<PipeControlPoint> list2 = pcps.get(i+1);
1934 PipeControlPoint prev = list.get(list.size()-1);
1935 PipeControlPoint next = list2.get(0);
1937 // Reverse the component on the boundary.
1938 InlineComponent ic = (InlineComponent)prev.getPipelineComponent();
1939 PipeRun r1 = ic.getPipeRun();
1940 PipeRun r2 = ic.getAlternativePipeRun();
1941 if (r1 == null || r2 == null)
1942 throw new RuntimeException("Components on PipeRun changes should refer to bot PipeRuns");
1946 ic.setAlternativePipeRun(r1);
1948 throw new RuntimeException("PipeRun changes should contain shared control points");
1956 private static void _reverse(List<PipeControlPoint> list) {
1957 if (list.size() <= 1)
1958 return; // nothing to do.
1960 for (int i = 0 ; i < list.size(); i++) {
1961 boolean first = i == 0;
1962 boolean last = i == list.size() - 1;
1963 PipeControlPoint current = list.get(i);
1964 PipeControlPoint currentSub = null;
1965 if (current.isDualInline())
1966 currentSub = current.getDualSub();
1968 PipeControlPoint next = list.get(i+1);
1969 if (next.isDualInline())
1970 next = next.getDualSub();
1971 if (current.getNext() == next)
1972 current.setNext(null);
1973 current.setPrevious(next);
1974 if (currentSub != null) {
1975 if (currentSub.getNext() == next)
1976 currentSub.setNext(null);
1977 currentSub.setPrevious(next);
1980 PipeControlPoint prev = list.get(i-1);
1982 if (current.getPrevious() == prev)
1983 current.setPrevious(null);
1984 current.setNext(prev);
1986 if (currentSub != null) {
1987 if (currentSub.getPrevious() == prev)
1988 currentSub.setPrevious(null);
1989 currentSub.setNext(prev);
1992 PipeControlPoint prev = list.get(i-1);
1993 PipeControlPoint next = list.get(i+1);
1994 if (next.isDualInline())
1995 next = next.getDualSub();
1998 current.setPrevious(next);
1999 current.setNext(prev);
2001 if (currentSub != null) {
2002 currentSub.setPrevious(next);
2003 currentSub.setNext(prev);
2007 //if (current.isTurn() && current.isFixed()) {
2008 if (current.asFixedAngle()) {
2009 current.setReversed(!current._getReversed());
2011 if (current.isInline() && current.isReverse()) {
2012 current.setReversed(!current._getReversed());
2019 public static void validate(PipeRun pipeRun) {
2020 if (pipeRun == null)
2022 Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
2024 //System.out.println("Validate " + pipeRun.getName());
2025 for (PipeControlPoint pcp : pcps) {
2026 if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
2029 List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
2030 if (runPcps.size() != count) {
2031 System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
2032 for (PipeControlPoint pcp : pcps) {
2033 if (!runPcps.contains(pcp)) {
2034 System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
2038 for (PipeControlPoint pcp : pcps) {
2039 if (pcp.getPipeRun() == null) {
2040 System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
2042 if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
2043 System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
2045 for (PipeControlPoint pcp : pcps) {
2046 if (pcp.getParentPoint() == null) {
2047 PipeControlPoint sub = null;
2048 if (pcp.isDualInline())
2049 sub = pcp.getDualSub();
2050 PipeControlPoint next = pcp.getNext();
2051 PipeControlPoint prev = pcp.getPrevious();
2053 if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
2054 System.out.println("Inconsistency between " + pcp + " -> " +next );
2058 PipeControlPoint prevParent = null;
2059 if (prev.isDualSub()) {
2060 prevParent = prev.getParentPoint();
2061 } else if (prev.isDualInline()) {
2062 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2064 if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
2065 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2072 public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{
2073 assert(!splittingComponent.getControlPoint().isFixedLength());
2074 assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixedLength()));
2075 PipeControlPoint newCP = newComponent.getControlPoint();
2076 PipeControlPoint splittingCP = splittingComponent.getControlPoint();
2077 PipeControlPoint nextCP = splittingCP.getNext();
2078 PipeControlPoint prevCP = splittingCP.getPrevious();
2080 /* there are many different cases to insert new component when
2081 it splits existing VariableLengthinlineComponent.
2083 1. VariableLengthComponet is connected from both sides:
2084 - insert new component between VariableLength component and component connected to it
2085 - insert new VariableLengthComponent between inserted component and component selected in previous step
2087 2. VariableLengthComponent is connected from one side
2088 - Use previous case or:
2089 - Insert new component to empty end
2090 - Insert new VariableLength component to inserted components empty end
2092 3. VariableLength is not connected to any component.
2093 - Should not be possible, at least in current implementation.
2094 - Could be done using second case
2098 if (nextCP == null && prevCP == null) {
2099 // this should not be possible
2100 throw new RuntimeException("VariableLengthComponent " + splittingComponent + " is not connected to anything.");
2102 double newLength = newComponent.getControlPoint().getLength();
2105 Point3d next = new Point3d();
2106 Point3d prev = new Point3d();
2107 splittingCP.getInlineControlPointEnds(prev, next);
2109 Vector3d newPos = null;
2111 newPos = new Vector3d(prev);
2112 Vector3d dir = new Vector3d(next);
2116 newComponent.setWorldPosition(newPos);
2118 newPos = newComponent.getWorldPosition();
2123 Vector3d dir = new Vector3d(next);
2126 dir.scale(newLength * 0.5);
2127 Point3d vn = new Point3d(newPos);
2128 Point3d vp = new Point3d(newPos);
2131 double ln = vn.distance(next);
2132 double lp = vp.distance(prev);
2133 vp.interpolate(prev, 0.5);
2134 vn.interpolate(next, 0.5);
2137 if (nextCP == null) {
2138 newCP.insert(splittingCP, Direction.NEXT);
2139 insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
2140 splittingCP.setWorldPosition(new Vector3d(vp));
2141 // ControlPointTools.setWorldPosition(splittingCP, vp);
2142 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2143 } else if (prevCP == null) {
2144 newCP.insert(splittingCP, Direction.PREVIOUS);
2145 insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
2146 splittingCP.setWorldPosition(new Vector3d(vn));
2147 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, ln);
2149 newCP.insert(splittingCP, nextCP);
2150 insertStraight(newCP, nextCP, new Vector3d(vn), ln);
2151 splittingCP.setWorldPosition(new Vector3d(vp));
2152 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2154 positionUpdate(newCP);
2158 public static void addSizeChange(boolean reversed, PipeRun pipeRun, PipeRun other, InlineComponent reducer, PipeControlPoint previous, PipeControlPoint next) {
2159 PipeControlPoint pcp = reducer.getControlPoint();
2160 PipeControlPoint ocp = pcp.getDualSub();
2162 String name = pipeRun.getUniqueName("Reducer");
2163 reducer.setName(name);
2164 pipeRun.addChild(reducer);
2165 other.addChild(ocp);
2166 reducer.setAlternativePipeRun(other);
2168 previous.setNext(pcp);
2169 pcp.setPrevious(previous);
2170 ocp.setPrevious(previous);
2174 next.setPrevious(ocp);
2177 String name = other.getUniqueName("Reducer");
2178 reducer.setName(name);
2179 other.addChild(reducer);
2180 pipeRun.addChild(ocp);
2181 reducer.setAlternativePipeRun(pipeRun);
2185 pcp.setPrevious(next);
2186 ocp.setPrevious(next);
2188 pcp.setNext(previous);
2189 ocp.setNext(previous);
2190 previous.setPrevious(ocp);