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 synchronized (ruleMutex) {
143 currentUpdates.clear();
148 public static boolean isEnabled() {
152 public static class ExpandIterInfo {
153 // these two are turn control points
154 private PipeControlPoint start;
155 private PipeControlPoint end;
158 public ExpandIterInfo() {
162 public ExpandIterInfo(PipeControlPoint tcp, int type) {
163 if (type == REMOVE_START)
170 public ExpandIterInfo(PipeControlPoint start, PipeControlPoint end) {
173 this.type = REMOVE_BOTH;
176 public PipeControlPoint getEnd() {
180 public void setEnd(PipeControlPoint end) {
184 public PipeControlPoint getStart() {
188 public void setStart(PipeControlPoint start) {
192 public int getType() {
196 public void setType(int type) {
202 private static void updatePathLegEndControlPoint(PipeControlPoint pcp) throws Exception {
204 System.out.println("PipingRules.updatePathLegEndControlPoint() " + pcp);
205 if (pcp.getNext() != null) {
206 updatePathLegNext(pcp, pcp, PathLegUpdateType.NEXT_S);
208 if (pcp.getPrevious() != null) {
209 updatePathLegPrev(pcp, pcp, PathLegUpdateType.PREV_S);
214 private static void updateInlineControlPoint(PipeControlPoint pcp) throws Exception {
216 System.out.println("PipingRules.updateInlineControlPoint() " + pcp);
217 PipeControlPoint start = pcp.findPreviousEnd();
218 updatePathLegNext(start, pcp, PathLegUpdateType.NONE);
221 private static PipeControlPoint insertElbow(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos) throws Exception{
223 System.out.println("PipingRules.insertElbow() " + pcp1 + " " + pcp2 + " " + pos);
224 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
226 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
227 pcp1 = pcp1.getDualSub();
228 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
229 PipeControlPoint t = pcp1;
232 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
233 PipeControlPoint t = pcp1;
234 pcp1 = pcp2.getDualSub();
237 throw new RuntimeException();
239 TurnComponent elbow = ComponentUtils.createTurn((P3DRootNode)pcp1.getRootNode());
240 PipeControlPoint pcp = elbow.getControlPoint();
241 if (pcp1.isDualInline())
242 pcp1 = pcp1.getDualSub();
243 String name = pcp1.getPipeRun().getUniqueName("Elbow");
245 pcp1.getPipeRun().addChild(elbow);
247 pcp.insert(pcp1, pcp2);
249 pcp.setWorldPosition(pos);
250 validate(pcp.getPipeRun());
254 private static PipeControlPoint insertStraight(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos, double length) throws Exception {
256 System.out.println("PipingRules.insertStraight() " + pcp1 + " " + pcp2 + " " + pos);
257 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
259 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
260 pcp1 = pcp1.getDualSub();
261 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
262 PipeControlPoint t = pcp1;
265 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
266 PipeControlPoint t = pcp1;
267 pcp1 = pcp2.getDualSub();
270 throw new RuntimeException();
272 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp1.getRootNode());
273 PipeControlPoint scp = component.getControlPoint();
274 if (pcp1.isDualInline())
275 pcp1 = pcp1.getDualSub();
276 String name = pcp1.getPipeRun().getUniqueName("Pipe");
277 component.setName(name);
278 pcp1.getPipeRun().addChild(component);
280 scp.insert(pcp1, pcp2);
282 scp.setWorldPosition(pos);
283 Vector3d dir = new Vector3d();
284 dir.sub(pcp2.getWorldPosition(), pcp1.getWorldPosition());
285 updateControlPointOrientation(scp, dir);
286 scp.setLength(length);
287 validate(scp.getPipeRun());
291 private static PipeControlPoint insertStraight(PipeControlPoint pcp, Direction direction , Vector3d pos, double length) throws Exception {
293 System.out.println("PipingRules.insertStraight() " + pcp + " " + direction + " " + pos);
295 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp.getRootNode());
296 PipeControlPoint scp = component.getControlPoint();
297 if (pcp.isDualInline() && direction == Direction.NEXT)
298 pcp = pcp.getDualSub();
299 String name = pcp.getPipeRun().getUniqueName("Pipe");
300 component.setName(name);
301 pcp.getPipeRun().addChild(component);
303 scp.insert(pcp,direction);
305 scp.setWorldPosition(pos);
306 scp.setLength(length);
307 validate(scp.getPipeRun());
311 private static void updatePathLegNext(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
312 UpdateStruct2 us = createUS(start, Direction.NEXT, 0, new ArrayList<ExpandIterInfo>(), updated);
314 System.out.println("Null update struct " + start);
317 updatePathLeg(us, lengthChange);
320 private static void updatePathLegPrev(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
321 UpdateStruct2 us = createUS(start, Direction.PREVIOUS, 0, new ArrayList<ExpandIterInfo>(), updated);
323 System.out.println("Null update struct " + start);
326 updatePathLeg(us, lengthChange);
329 private static class UpdateStruct2 {
330 public PipeControlPoint start;
331 public Vector3d startPoint;
332 public ArrayList<PipeControlPoint> list;
333 public PipeControlPoint end;
334 public Vector3d endPoint;
336 public Vector3d offset;
337 public boolean hasOffsets;
339 public boolean reversed;
340 public ArrayList<ExpandIterInfo> toRemove;
341 public PipeControlPoint updated;
343 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) {
344 if (start == null || end == null)
345 throw new NullPointerException();
347 this.startPoint = startPoint;
350 this.endPoint = endPoint;
352 this.offset = offset;
353 this.hasOffsets = hasOffsets;
355 this.reversed = reversed;
356 this.toRemove = toRemove;
357 this.updated = updated;
359 if (!MathTools.isValid(startPoint) ||
360 !MathTools.isValid(endPoint) ||
361 !MathTools.isValid(dir)) {
362 throw new RuntimeException();
366 public String toString() {
367 return start + " " + end+ " " + dir + " " + hasOffsets + " " + offset + " " + iter + " " + toRemove.size();
372 public static boolean calculateDirectedOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
373 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, true);
376 public static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
377 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, false);
380 private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset, boolean directed) {
381 List<PipeControlPoint> offsets = getOffsetPoints(start, list);
382 if (offsets.size() == 0) {
383 setZeroOffset(startPoint, endPoint, dir, offset);
386 Vector3d sp = new Vector3d(startPoint);
387 Point3d ep = new Point3d(endPoint);
390 double l = dir.lengthSquared();
391 if (l > MathTools.NEAR_ZERO)
392 dir.scale(1.0/Math.sqrt(l));
397 offset.set(0.0, 0.0, 0.0);
399 for (PipeControlPoint icp : offsets) {
400 Vector3d v = icp.getSizeChangeOffsetVector(dir);
407 Point3d nep = new Point3d(endPoint);
409 if (nep.distance(ep) < 0.0000000001) {
416 l = dir.lengthSquared();
417 if (l > MathTools.NEAR_ZERO)
418 dir.scale(1.0/Math.sqrt(l));
422 System.out.println("calcOffset s:"+ startPoint + " e:" + endPoint + " d:" + dir + " o:"+offset) ;
428 public static void setZeroOffset(Vector3d startPoint, Vector3d endPoint, Vector3d dir, Vector3d offset) {
431 double l = dir.lengthSquared();
432 if (l > MathTools.NEAR_ZERO)
433 dir.scale(1.0/Math.sqrt(l));
434 offset.set(0.0, 0.0, 0.0);
437 public static List<PipeControlPoint> getOffsetPoints(PipeControlPoint start, ArrayList<PipeControlPoint> list) {
438 List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
439 // Only start offset affects the calculation
440 if (start.isOffset())
442 for (PipeControlPoint icp : list) {
443 if (icp.isOffset()) {
445 } else if (icp.isDualSub())
446 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
451 private static UpdateStruct2 createUS(PipeControlPoint start, Direction direction, int iter, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) {
452 ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
453 PipeControlPoint end = null;
454 if (direction == Direction.NEXT) {
455 end = start.findNextEnd(list);
457 ArrayList<PipeControlPoint> prevList = new ArrayList<PipeControlPoint>();
458 PipeControlPoint tend = start.findPreviousEnd(prevList);
459 for (PipeControlPoint icp : prevList) {
460 if (icp.isDualSub()) {
461 list.add(0, icp.getParentPoint());
471 boolean hasOffsets = false;
472 Vector3d offset = new Vector3d();
473 Vector3d startPoint = start.getWorldPosition();
474 Vector3d endPoint = end.getWorldPosition();
475 Vector3d dir = new Vector3d();
476 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
477 return new UpdateStruct2(start, startPoint, list, end, endPoint, dir, offset, hasOffsets, iter, direction == Direction.PREVIOUS, toRemove, updated);
480 private static boolean asDirected(PipeControlPoint pcp, Direction direction) {
481 if (pcp.isDirected())
483 if (pcp.asFixedAngle()) {
484 if (!pcp._getReversed())
485 return direction == Direction.NEXT;
487 return direction == Direction.PREVIOUS;
492 private static Vector3d direction(PipeControlPoint pcp, Direction direction) {
493 return pcp.getDirection(direction);
496 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
499 if (lengthChange == PathLegUpdateType.NONE) {
503 updatePathLeg(u, lengthChange, rs, re);
506 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean rs, boolean re) throws Exception {
508 if (asDirected(u.start, Direction.NEXT))
510 if (asDirected(u.end, Direction.PREVIOUS))
513 setErrorForce(u.start, null);
515 setErrorForce(u.end, null);
516 for (PipeControlPoint pcp : u.list)
517 setErrorForce(pcp, null);
520 updateFreePathLeg(u, lengthChange);
523 updateDirectedPathLeg(u, lengthChange);
526 updateDualDirectedPathLeg(u, lengthChange);
532 private static void updateFreePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
534 System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange);
535 checkExpandPathLeg(u, lengthChange);
536 if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle())
537 processPathLeg(u, true, false);
540 private static void updateInlineControlPoints(UpdateStruct2 u, boolean checkSizes) throws Exception{
542 System.out.println("PipingRules.updateInlineControlPoints() " + u);
544 Vector3d start = new Vector3d(u.startPoint);
545 Vector3d end = new Vector3d(u.endPoint);
548 // create offsets for leg ends.
549 if (u.start.isTurn())
550 MathTools.mad(start, u.dir, u.start.getInlineLength());
552 MathTools.mad(end, u.dir, -u.end.getInlineLength());
555 boolean recalcline = false;
557 Vector3d sp = new Vector3d(start);
558 Vector3d ep = new Vector3d(end);
561 if (u.start.isOffset()) {
562 Vector3d offset = u.start.getSizeChangeOffsetVector(u.dir);
563 updateOffsetPoint(u.start, offset);
568 for (PipeControlPoint icp : u.list) {
569 updateInlineControlPoint(icp, sp, ep, u.dir);
570 if (icp.isOffset()) {
571 // TODO : offset vector is already calculated and should be cached
572 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
573 updateOffsetPoint(icp, offset);
582 // Collect all path leg points for updating variable length components. This list will also contain leg ends (usually turns)
583 ArrayList<PipeControlPoint> pathLegPoints = new ArrayList<>();
584 // Collect all fixed length components with their offsets.
585 ArrayList<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints = new ArrayList<>();
587 pathLegPoints.add(u.start);
588 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.start, new Vector3d()));
589 Vector3d off = new Vector3d();
590 for (PipeControlPoint icp : u.list) {
591 pathLegPoints.add(icp);
592 updateBranchControlPointBranches(icp);
593 if (icp.isOffset()) {
594 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
595 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
597 } else if (!icp.isVariableLength()) {
598 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
601 pathLegPoints.add(u.end);
602 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.end, new Vector3d(off)));
604 sp = new Vector3d(start);
605 ep = new Vector3d(end);
608 updateFixedLengths(fixedLengthPoints, sp, ep, u.dir);
610 for (int i = 0; i < pathLegPoints.size(); i++) {
611 PipeControlPoint icp = pathLegPoints.get(i);
613 PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
614 PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
616 if (prev != null && prev.isDualInline())
617 prev = prev.getDualSub();
619 if (icp.isVariableLength()) {
620 if (prev != null && next != null) {
621 recalcline = recalcline | updateVariableLength(icp, prev, next);
624 // this is variable length component at the end of the piperun.
625 // the problem is that we want to keep unconnected end of the component in the same
626 // place, but center of the component must be moved.
627 updateVariableLengthEnd(icp, prev != null ? prev : next);
629 } else if (prev != null && !prev.isVariableLength()) {
630 // If this and previous control point are not variable length pcps,
631 // we'll have to check if there is no empty space between them.
632 // I there is, we'll have to create new variable length component between them.
633 recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
635 if (icp.isOffset()) {
636 // TODO : offset vector is already calculated and should be cached
637 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
645 u.start.findNextEnd(u.list);
648 sp = new Vector3d(u.startPoint);
649 ep = new Vector3d(u.endPoint);
651 double pathLegLength = MathTools.distance(sp, ep);
652 double availableLength = pathLegLength;
653 if (u.start.isTurn())
654 availableLength -= u.start.getInlineLength();
656 availableLength -= u.end.getInlineLength();
657 for (PipeControlPoint pcp : u.list) {
658 if (!pcp.isVariableLength())
659 availableLength-= pcp.getLength();
661 if (availableLength < 0.0) {
662 setError(u.start, "Not enough available space");
663 setError(u.end, "Not enough available space");
664 for (PipeControlPoint pcp : u.list)
665 setError(pcp, "Not enough available space");
667 // System.out.println(u.start.getPipelineComponent().toString() + " " + pathLegLength + " " + availableLength + " " + u.end.getPipelineComponent().toString() + " " + u.start.getInlineLength() + " " + u.end.getInlineLength());
671 private enum Gap{ATTACHED,OVERLAP,SPACE};
673 private static class GapObj {
677 Pair<PipeControlPoint,Vector3d> pcp1;
678 Pair<PipeControlPoint,Vector3d> pcp2;
681 private static void updateFixedLengths(List<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints, Vector3d s, Vector3d e, Vector3d dir) {
682 double totalLength = MathTools.distance(s, e);
683 double reservedLength = 0.0;
684 List<Double> distances = new ArrayList<>(fixedLengthPoints.size());
686 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
687 Pair<PipeControlPoint,Vector3d> pcp = fixedLengthPoints.get(i);
688 reservedLength += pcp.first.getLength();
689 Vector3d p = pcp.first.getWorldPosition();
691 double d= MathTools.distance(s, p);
694 distances.add(totalLength);
696 if (totalLength >= reservedLength) {
697 // There is enough space for all fixed length components.
698 List<GapObj> gaps = new ArrayList<>(fixedLengthPoints.size()-1);
700 // Analyze gaps between components
701 for (int i = 0; i < fixedLengthPoints.size()-1; i++) {
702 Pair<PipeControlPoint,Vector3d> pcp1 = fixedLengthPoints.get(i);
703 Pair<PipeControlPoint,Vector3d> pcp2 = fixedLengthPoints.get(i+1);
704 double d1 = distances.get(i);
705 double d2 = distances.get(i+1);
706 double ld1 = i == 0 ? 0.0 :pcp1.first.getInlineLength();
707 double ld2 = i == fixedLengthPoints.size()-2 ? 0.0 : pcp2.first.getInlineLength();
709 double e1 = d1 + ld1; // End of comp1
710 double s2 = d2 - ld2; // Start of comp2
711 double diff =s2 - e1;
712 GapObj obj = new GapObj();
716 if (diff < -MIN_INLINE_LENGTH) {
717 obj.gap = Gap.OVERLAP;
719 } else if (diff > MIN_INLINE_LENGTH) {
722 obj.gap = Gap.ATTACHED;
726 // If there are no overlaps, there is nothing to do.
729 // Get rid of overlapping components by using closest available free spaces.
730 for (int i = 0; i < gaps.size(); i++) {
731 GapObj gapObj = gaps.get(i);
732 if (gapObj.gap != Gap.OVERLAP)
734 double curr = gapObj.d;
736 while (curr < -MIN_INLINE_LENGTH) {
737 GapObj next = i+d >= 0 ? gaps.get(i+d) : null;
738 GapObj prev = i-d >= 0 ? gaps.get(i-d) : null;
739 if (next != null && next.gap == Gap.SPACE) {
740 double move = Math.min(-curr, next.d);
743 if (next.d < MIN_INLINE_LENGTH)
744 next.gap = Gap.ATTACHED;
745 Vector3d mv = new Vector3d(dir);
748 for (int j = i ; j < i+d; j++) {
749 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp2;
750 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
752 pcp.first.setWorldPosition(p);
755 if (curr < -MIN_INLINE_LENGTH && prev != null && prev.gap == Gap.SPACE) {
756 double move = Math.min(-curr, prev.d);
759 if (next.d < MIN_INLINE_LENGTH)
760 next.gap = Gap.ATTACHED;
761 Vector3d mv = new Vector3d(dir);
764 for (int j = i ; j > i-d; j--) {
765 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp1;
766 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
768 pcp.first.setWorldPosition(p);
774 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
775 Pair<PipeControlPoint,Vector3d> prev = i == 0 ? null : fixedLengthPoints.get(i-1);
776 Pair<PipeControlPoint,Vector3d> curr = fixedLengthPoints.get(i);
777 Pair<PipeControlPoint,Vector3d> next = i == fixedLengthPoints.size() -1 ? null : fixedLengthPoints.get(i+1);
778 updateFixedLength(curr, prev, next, s,e, dir);
783 private static void updateFixedLength(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> prev, Pair<PipeControlPoint,Vector3d> next, Vector3d s, Vector3d e, Vector3d dir) {
785 checkOverlap(prev, icp, dir,true);
788 checkOverlap(icp, next, dir,true);
791 private static boolean checkOverlap(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> icp2, Vector3d dir, boolean se) {
792 Vector3d p1 = icp.first.getWorldPosition();
793 Vector3d p2 = icp2.first.getWorldPosition();
796 double u[] = new double[1];
797 MathTools.closestPointOnStraight(p2, p1, dir, u);
802 MathTools.mad(p2, dir, MIN_INLINE_LENGTH);
803 icp2.first.setWorldPosition(p2);
805 double d = MathTools.distance(p1, p2);
806 double r = icp.first.getInlineLength() + icp2.first.getInlineLength();
808 if ((d-r) < - MIN_INLINE_LENGTH) {
810 setError(icp.first, "Overlapping");
811 setError(icp2.first, "Overlapping");
819 * Overrides current error of a component
823 private static void setErrorForce(PipeControlPoint pcp, String error) {
824 PipelineComponent comp = pcp.getPipelineComponent();
827 comp.setError(error);
831 * Sets error for a component, if there is no existing error.
835 private static void setError(PipeControlPoint pcp, String error) {
836 PipelineComponent comp = pcp.getPipelineComponent();
839 if (comp.getError() != null)
841 comp.setError(error);
844 private static boolean updateVariableLength(PipeControlPoint icp, PipeControlPoint prev, PipeControlPoint next) {
845 Vector3d prevPos = prev.getWorldPosition();
846 Vector3d nextPos = next.getWorldPosition();
848 Vector3d dir = new Vector3d(nextPos);
850 double l = dir.length(); // distance between control points
851 double l2prev = prev.getInlineLength(); // distance taken by components
852 double l2next = next.getInlineLength();
853 double l2 = l2prev + l2next;
854 double length = l - l2; // true length of the variable length component
855 if (length >= MIN_INLINE_LENGTH) { // check if there is enough space for variable length component.
858 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
860 icp.setWorldPosition(dir);
861 icp.setLength(length);
864 // components leave no space to the component and it must be removed
865 if (icp.isDeletable()) {
866 if (!allowInsertRemove) {
867 icp.setLength(MIN_INLINE_LENGTH);
868 setError(icp, "Not enough available space");
873 System.out.println("PipingRules.updateVariableLength removing " + icp);
877 icp.setLength(MIN_INLINE_LENGTH);
878 icp.getPipelineComponent().setError("Not enough available space");
884 private static boolean possibleVaribleLengthInsert(PipeControlPoint icp, PipeControlPoint prev) throws Exception{
885 Vector3d currentPos = icp.getWorldPosition();
886 Vector3d prevPos = prev.getWorldPosition();
887 Vector3d dir = new Vector3d(currentPos);
889 double l = dir.lengthSquared();
890 double l2prev = prev.getInlineLength();
891 double l2next = icp.getInlineLength();
892 double l2 = l2prev + l2next;
893 double l2s = l2 * l2;
894 double diff = l - l2s;
895 if (diff >= MIN_INLINE_LENGTH) {
896 if (allowInsertRemove) {
898 double length = Math.sqrt(l) - l2; // true length of the variable length component
899 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
901 insertStraight(prev, icp, dir, length);
910 private static void updateVariableLengthEnd(PipeControlPoint icp, PipeControlPoint prev) {
911 Vector3d currentPos = icp.getWorldPosition();
912 Vector3d prevPos = prev.getWorldPosition();
914 Vector3d dir = new Vector3d();
915 dir.sub(currentPos, prevPos);
918 synchronized (ruleMutex) {
919 simple = currentUpdates.contains(icp);
923 // Update based on position -> adjust length
924 double currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
925 icp.setLength(currentLength);
927 // Update based on neighbour movement -> adjust length and position, so that free end stays in place.
928 double currentLength = icp.getLength();
929 if (currentLength < MathTools.NEAR_ZERO) {
930 currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
933 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
935 Point3d endPos = new Point3d(dir);
936 endPos.scale(currentLength * 0.5);
937 endPos.add(currentPos); // this is the free end of the component
939 double offset = prev.getInlineLength();
940 Point3d beginPos = new Point3d(dir);
941 beginPos.scale(offset);
942 beginPos.add(prevPos); // this is the connected end of the component
944 double l = beginPos.distance(endPos);
947 System.out.println("Length for " + icp + " is NaN");
950 beginPos.add(dir); // center position
953 System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
956 icp.setWorldPosition(new Vector3d(beginPos));
961 * Recalculates offset vector based on current direction, and calls checkExpandPathLeg
966 private static void ppNoOffset(UpdateStruct2 u, boolean updateEnds) throws Exception {
968 System.out.println("PipingRules.ppNoOffset() " + u);
969 Vector3d offset = new Vector3d();
971 for (PipeControlPoint icp : u.list) {
972 if (icp.isOffset()) {
973 offset.add(icp.getSizeChangeOffsetVector(u.dir));
974 } else if (icp.isDualSub())
975 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
979 checkExpandPathLeg(u, PathLegUpdateType.NONE, updateEnds);
982 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 {
984 System.out.println("PipingRules.ppNoDir() " + start + " " + end + " " + iter + " " + toRemove.size());
985 // FIXME : extra loop (dir should be calculated here)
986 Vector3d dir = new Vector3d();
987 Vector3d offset = new Vector3d();
988 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
989 ppNoOffset(new UpdateStruct2(start, startPoint, list, end, endPoint, dir, null, hasOffsets, iter, reversed, toRemove, updated),true);
992 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
993 checkExpandPathLeg(u, lengthChange, u.updated.isInline() && u.updated.isOffset());
996 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean updateEnds) throws Exception {
998 System.out.println("PipingRules.checkExpandPathLeg() " + u + " " + lengthChange);
999 if (lengthChange != PathLegUpdateType.NONE) {
1000 // FIXME : turns cannot be checked before inline cps are updated,
1001 // since their position affects calculation of turns
1002 processPathLeg(u, updateEnds, false);
1003 int type = checkTurns(u, lengthChange);
1004 if (type == REMOVE_NONE) {
1005 processPathLeg(u, updateEnds, true);
1007 expandPathLeg(u, type);
1010 processPathLeg(u, updateEnds, true);
1014 private static void updateDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1016 System.out.println("PipingRules.updateDirectedPipeRun() " + u + " " + lengthChange);
1017 PipeControlPoint dcp;
1018 PipeControlPoint other;
1019 boolean canMoveOther = false;
1020 boolean dcpStart = false;
1021 boolean inlineEnd = false;
1023 if (asDirected(u.start, Direction.NEXT)) {
1026 position = u.startPoint;
1029 canMoveOther = true;
1030 inlineEnd = u.end.isInline();
1035 position = u.endPoint;
1037 canMoveOther = true;
1038 inlineEnd = u.start.isInline();
1041 Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1042 if (directedDirection == null) {
1043 //updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
1044 updateTurnControlPointTurn(dcp, null, null);
1045 directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1046 if (directedDirection == null) {
1050 Point3d directedEndPoint = new Point3d(u.endPoint);
1052 directedEndPoint.sub(u.offset);
1054 double mu[] = new double[2];
1057 Vector3d t = new Vector3d();
1060 closest = MathTools.closestPointOnStraight(directedEndPoint, u.startPoint, directedDirection, mu);
1061 t.sub(closest, directedEndPoint);
1063 closest = MathTools.closestPointOnStraight(u.startPoint, directedEndPoint, directedDirection, mu);
1064 t.sub(closest, u.startPoint);
1067 double distance = t.length();
1068 boolean aligned = (distance < ALLOWED_OFFSET);
1069 double requiredSpace = 0.0;
1070 if (other.isVariableAngle()) {
1071 requiredSpace = spaceForTurn(other, dcp);
1073 if (mu[0] < requiredSpace) {
1074 // At the moment, if next component is directly behind the nozzle, we must force moving the other component.
1075 // Trying to solve the situation by adding new turn creates infinite loop...
1077 canMoveOther = true;
1080 //if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
1081 // processPathLeg(u, true, false);
1082 checkExpandPathLeg(u, lengthChange, inlineEnd || u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle());
1087 PipeControlPoint nextToMoved;
1089 if (u.list.size() > 0)
1091 nextToMoved = u.list.get(0);
1093 nextToMoved = u.list.get(u.list.size() - 1);
1095 nextToMoved = u.end;
1097 nextToMoved = u.start;
1098 if (other.isVariableAngle()) {
1100 // TODO calculate needed space from next run end.
1101 if (mu[0] < requiredSpace) {
1103 closest.set(u.startPoint);
1105 closest.set(u.endPoint);
1107 Vector3d v = new Vector3d(directedDirection);
1108 v.scale(requiredSpace);
1114 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + closest);
1116 // Not aligned - we need to recalculate the offset to reflect new end points.
1119 offset = new Vector3d();
1120 Vector3d newDir = new Vector3d();
1121 calculateDirectedOffset(position, closest, u.start, u.list, u.end, newDir, offset);
1122 closest.add(offset);
1124 offset = new Vector3d();
1127 other.setWorldPosition(closest);
1130 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);
1131 if (u.end.getNext() != null)
1132 updatePathLegNext(u.end, u.updated, PathLegUpdateType.NEXT);
1134 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);
1135 if (u.start.getPrevious() != null)
1136 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.PREV);
1139 // TODO : calculate needed space from next run end.
1140 if (allowInsertRemove)
1141 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1146 } else if (other.isNonDirected() && other.getParentPoint() != null) {
1147 // FIXME : this code was for updating branches
1148 Vector3d bintersect = new Vector3d();
1149 PipeControlPoint bcp = other.getParentPoint();
1150 if (bcp != null && canMoveOther) {
1151 Point3d bstart = new Point3d();
1152 Point3d bend = new Point3d();
1153 Vector3d bdir = new Vector3d();
1154 bcp.getInlineControlPointEnds(bstart, bend, bdir);
1155 Vector3d nintersect = new Vector3d();
1157 MathTools.intersectStraightStraight(position, directedDirection, bend, bdir, nintersect, bintersect, mu);
1158 Vector3d dist = new Vector3d(nintersect);
1159 dist.sub(bintersect);
1160 canMoveOther = mu[1] > 0.0 && mu[1] < 1.0 && dist.lengthSquared() < 0.01;
1162 // TODO : endControlPoints are undirected: calculcate
1163 // correct position for it
1164 throw new UnsupportedOperationException("not implemented");
1168 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + bintersect);
1169 // is required branch position is in possible range
1170 bcp.setWorldPosition(bintersect);
1172 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);
1174 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);
1177 // branch cannot be moved into right position, new turn
1178 // / elbow must be inserted
1179 if (allowInsertRemove)
1180 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1185 } else { // assume that control point cannot be moved, but can
1187 if (allowInsertRemove)
1188 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1198 private static void updateDualDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1200 System.out.println("PipingRules.updateDualDirectedPipeRun() " + u + " " + lengthChange);
1202 PipeControlPoint dcp1 = u.start;
1203 PipeControlPoint dcp2 = u.end;
1204 Point3d position1 = new Point3d(u.startPoint);
1205 Point3d position2 = new Point3d(u.endPoint);
1207 Vector3d dir = new Vector3d(), offset = new Vector3d();
1208 calculateDirectedOffset(new Vector3d(position1), new Vector3d(position2), u.start, u.list, u.end, dir, offset);
1210 Point3d position1offset = new Point3d(position1);
1211 position1offset.add(offset);
1212 Point3d position2offset = new Point3d(position2);
1213 position2offset.sub(offset);
1214 Vector3d dir1 = direction(dcp1, Direction.NEXT);
1215 Vector3d dir2 = direction(dcp2, Direction.PREVIOUS);
1217 Vector3d p1 = MathTools.closestPointOnStraight(position1, position2offset, dir2);
1218 Vector3d p2 = MathTools.closestPointOnStraight(position2, position1offset, dir1);
1219 double d1 = position1.distance(new Point3d(p1));
1220 double d2 = position2.distance(new Point3d(p2));
1222 boolean aligned = (d1 < ALLOWED_OFFSET && d2 < ALLOWED_OFFSET);
1228 } else if (allowInsertRemove){
1229 PipeControlPoint dcp;
1230 PipeControlPoint next;
1233 if (u.list.size() > 0)
1234 next = u.list.get(0);
1239 if (u.list.size() > 0)
1240 next = u.list.get(u.list.size() - 1);
1245 p1 = dcp.getWorldPosition();
1246 Vector3d v = new Vector3d();
1252 // Reserve space for 90 deg elbow
1253 double off = dcp1.getPipeRun().getTurnRadius();
1258 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position2offset, dir2);
1260 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position1offset, dir1);
1262 // By default, the elbows are placed next to each other, by using 90 deg angles.
1263 // If the distance between elbows is not enough, we must move the other elbow (and create more shallow angle elbows)
1264 if (MathTools.distance(p1, p2) < off*2.05) {
1268 PipeControlPoint tcp1 = insertElbow(dcp, next, p1);
1269 PipeControlPoint tcp2 = insertElbow(tcp1, next, p2);
1272 System.out.println("PipingRules.updateDualDirectedPipeRun() created two turns " + tcp1 + " " + tcp2);
1275 Vector3d dd = new Vector3d(p2);
1278 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1279 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1281 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1283 updatePathLegPrev(tcp2, u.updated, PathLegUpdateType.NONE);
1285 Vector3d dd = new Vector3d(p1);
1288 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1289 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1291 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1293 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.NONE);
1302 private static double spaceForTurn(PipeControlPoint tcp, PipeControlPoint dcp) {
1303 // TODO : if the path legs contain offset, using just positions of opposite path leg ends is not enough.
1304 // TODO : current iterative way for calculating required space may return longer length that is required.
1305 double tr = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1307 return tr; // space for 90 deg
1308 PipeControlPoint ne = tcp.findNextEnd();
1309 PipeControlPoint pe = tcp.findPreviousEnd();
1310 PipeControlPoint other = null;
1316 return tr; // space for 90 deg
1318 return tr; // space for 90 deg
1319 Vector3d dir = dcp.getDirectedControlPointDirection();
1320 Vector3d dp = dcp.getWorldPosition();
1321 Vector3d op = other.getWorldPosition();
1322 double u[] = new double[1];
1323 Vector3d closest = MathTools.closestPointOnStraight(op, dp, dir,u);
1324 if (MathTools.distanceSquared(closest, op) <= MIN_INLINE_LENGTH) {
1325 if (u[0] > -MIN_INLINE_LENGTH)
1326 return 0.0; // point following turn is directly in the front of the nozzle.
1328 return tr*2.0; // point following turn is directly behind the nozzle, in theory, we should return Double.Inf...
1330 double curr = tr*0.1;
1332 Vector3d v1 = new Vector3d();
1333 Vector3d v2 = new Vector3d();
1335 Vector3d tp = new Vector3d(dp);
1336 MathTools.mad(tp, dir, curr);
1337 v1.sub(tp, dp); // Vector from nozzle to turn
1338 v2.sub(op,tp); // Vector from turn to other
1339 double a = v1.angle(v2);
1340 double t = Math.tan((Math.PI - a) * 0.5);
1342 if (t > MathTools.NEAR_ZERO)
1352 private static void insertElbowUpdate(UpdateStruct2 u, PipeControlPoint dcp, PipeControlPoint next, boolean dcpStart, Vector3d position, Vector3d directedDirection) throws Exception{
1355 // Vector3d closest = new Vector3d(position);
1356 // closest.add(directedDirection);
1358 PipeControlPoint tcp = null;
1361 closest = MathTools.closestPointOnStraight(next.getWorldPosition(), position, directedDirection);
1362 tcp = insertElbow(dcp, next, closest);
1364 closest = MathTools.closestPointOnStraight(dcp.getWorldPosition(), position, directedDirection);
1365 tcp = insertElbow(next, dcp, closest);
1367 double d = MathTools.distance(position, closest);
1368 double s = spaceForTurn(tcp,dcp);
1371 Vector3d p = new Vector3d(directedDirection);
1381 System.out.println("PipingRules.updateDirectedPipeRun() inserted " + tcp);
1384 // update pipe run from new turn to other end
1385 ppNoDir(tcp, new Vector3d(closest), u.list, u.end, u.endPoint, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1386 // update pipe run from directed to new turn
1387 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));
1389 // update pipe run from other end to new turn
1390 ppNoDir(u.start, u.startPoint, u.list, tcp, new Vector3d(closest), u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1391 // update pipe run from new turn to directed
1392 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));
1397 * Checks if turns can be removed (turn angle near zero)
1399 private static int checkTurns(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1401 System.out.println("PipingRules.checkTurns() " + u.start + " " + u.end);
1402 boolean startRemoved = false;
1403 boolean endRemoved = false;
1404 if (u.start.isVariableAngle()) {
1405 // this won't work properly if inline control points are not updated
1406 PipeControlPoint startPrev = u.start.getPrevious();
1407 if (startPrev != null) {
1408 double a = updateTurnControlPointTurn(u.start, null, u.dir);
1409 if (a < MIN_TURN_ANGLE && u.start.isDeletable())
1410 startRemoved = true;
1411 else if (lengthChange == PathLegUpdateType.PREV || lengthChange == PathLegUpdateType.PREV_S) {
1412 PathLegUpdateType type;
1413 if (lengthChange == PathLegUpdateType.PREV_S)
1414 type = PathLegUpdateType.PREV;
1416 type = PathLegUpdateType.NONE;
1417 updatePathLegPrev(u.start, u.start, type);
1421 if (u.end.isVariableAngle()) {
1423 PipeControlPoint endNext = u.end.getNext();
1424 if (endNext != null) {
1425 // TODO: u.end, u.dir, null
1426 double a = updateTurnControlPointTurn(u.end, null, null);
1427 if (a < MIN_TURN_ANGLE && u.end.isDeletable())
1429 else if (lengthChange == PathLegUpdateType.NEXT || lengthChange == PathLegUpdateType.NEXT_S) {
1430 PathLegUpdateType type;
1431 if (lengthChange == PathLegUpdateType.NEXT_S)
1432 type = PathLegUpdateType.NEXT;
1434 type = PathLegUpdateType.NONE;
1435 updatePathLegNext(u.end, u.end, type);
1440 System.out.println("PipingRules.checkTurns() res " + startRemoved + " " + endRemoved);
1441 if (!startRemoved && !endRemoved)
1443 if (startRemoved && endRemoved)
1446 return REMOVE_START;
1451 * Expands piperun search over turns that are going to be removed
1454 private static void expandPathLeg(UpdateStruct2 u, int type) throws Exception {
1456 System.out.println("PipingRules.expandPipeline " + u.start + " " + u.end);
1457 ArrayList<PipeControlPoint> newList = new ArrayList<PipeControlPoint>();
1460 throw new RuntimeException("Error in piping rules");
1462 u.toRemove.add(new ExpandIterInfo(u.start, REMOVE_START));
1463 u.start = u.start.findPreviousEnd();
1464 u.startPoint = u.start.getPosition();
1465 u.start.findNextEnd(newList);
1466 newList.addAll(u.list);
1470 u.toRemove.add(new ExpandIterInfo(u.end, REMOVE_END));
1471 u.end = u.end.findNextEnd(newList);
1472 u.endPoint = u.end.getPosition();
1473 u.list.addAll(newList);
1476 u.toRemove.add(new ExpandIterInfo(u.start, u.end));
1477 u.start = u.start.findPreviousEnd();
1478 u.startPoint = u.start.getPosition();
1479 u.start.findNextEnd(newList);
1480 newList.addAll(u.list);
1482 newList = new ArrayList<PipeControlPoint>();
1483 u.end = u.end.findNextEnd(newList);
1484 u.endPoint = u.end.getPosition();
1485 u.list.addAll(newList);
1488 throw new RuntimeException("Error in piping rules");
1491 u.offset = new Vector3d();
1494 for (PipeControlPoint icp : u.list) {
1495 if (icp.isOffset()) {
1496 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1497 } else if (icp.isDualSub())
1498 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1502 System.out.println("PipingRules.expandPipeline expanded " + u.start + " " + u.end);
1504 updatePathLeg(u, PathLegUpdateType.NONE);
1508 * reverts one iteration of turn removing back)
1510 private static void backIter(UpdateStruct2 u) throws Exception {
1513 System.out.println("PipingRules.backIter" + u.start + " " + u.end);
1515 throw new RuntimeException("Error in piping rules");
1516 ExpandIterInfo info = u.toRemove.get(u.toRemove.size() - 1);
1517 u.toRemove.remove(u.toRemove.size() - 1);
1518 if (info.getType() == REMOVE_START || info.getType() == REMOVE_BOTH) {
1519 while (u.list.size() > 0) {
1520 PipeControlPoint icp = u.list.get(0);
1521 if (icp.getPrevious().equals(info.getStart()))
1525 u.start = info.getStart();
1527 if (info.getType() == REMOVE_END || info.getType() == REMOVE_BOTH) {
1528 while (u.list.size() > 0) {
1529 PipeControlPoint icp = u.list.get(u.list.size() - 1);
1530 if (icp.getNext().equals(info.getEnd()))
1534 u.end = info.getEnd();
1536 u.offset = new Vector3d();
1539 for (PipeControlPoint icp : u.list) {
1540 if (icp.isOffset()) {
1541 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1542 } else if (icp.isDualSub())
1543 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1551 * Processes pipe run (removes necessary turns and updates run ends)
1553 // private static void processPathLeg(PipeControlPoint start, Point3d
1554 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1555 // end,Point3d endPoint, Vector3d dir,Vector3d offset, boolean
1556 // hasOffsets,int iter, boolean reversed, ArrayList<ExpandIterInfo>
1557 // toRemove) throws TransactionException {
1559 private static void processPathLeg(UpdateStruct2 u) throws Exception {
1561 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1562 processPathLeg(u, true, true);
1565 private static void processPathLeg(UpdateStruct2 u, boolean updateEnds, boolean updateInline) throws Exception {
1567 System.out.println("PipingRules.processPathLeg " + (updateEnds ? "ends " : "") + (updateInline ? "inline " : "") + u.start + " " + u.end);
1569 if (u.toRemove.size() > 0) {
1570 for (ExpandIterInfo info : u.toRemove) {
1571 if (info.getStart() != null) {
1573 System.out.println("PipingRules.processPathLeg removing start " + info.getStart());
1574 info.getStart()._remove();
1576 if (info.getEnd() != null) {
1578 System.out.println("PipingRules.processPathLeg removing end " + info.getEnd());
1579 info.getEnd()._remove();
1582 // ControlPointTools.removeControlPoint may remove more than one CP;
1583 // we must populate inline CP list again.
1585 u.start.findNextEnd( u.list);
1587 // FIXME : inline CPs are update twice because their positions must be
1588 // updated before and after ends.
1589 updateInlineControlPoints(u, false);
1592 if (u.start.isTurn()) {
1593 //updateTurnControlPointTurn(u.start, u.start.getPrevious(), u.start.getNext());
1594 updateTurnControlPointTurn(u.start, null, null);
1595 // updatePathLegPrev(u.start, u.start, PathLegUpdateType.NONE);
1596 } else if (u.start.isEnd()) {
1597 updateEndComponentControlPoint(u.start, u.dir);
1598 } else if (u.start.isInline()) {
1599 updateControlPointOrientation(u.start, u.dir);
1601 if (u.end.isTurn()) {
1602 //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext());
1603 updateTurnControlPointTurn(u.end, null, null);
1604 // updatePathLegNext(u.end, u.end, PathLegUpdateType.NONE);
1605 } else if (u.end.isEnd()) {
1606 updateEndComponentControlPoint(u.end, u.dir);
1607 } else if (u.end.isInline()) {
1608 updateControlPointOrientation(u.end, u.dir);
1612 if (u.start.isEnd()) {
1613 updateEndComponentControlPoint(u.start, u.dir);
1615 if (u.end.isEnd()) {
1616 updateEndComponentControlPoint(u.end, u.dir);
1620 updateInlineControlPoints(u, true);
1625 * Processes pipe run and recalculates offset
1627 // private static void processPathLeg(PipeControlPoint start, Point3d
1628 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1629 // end,Point3d endPoint, Vector3d dir, boolean hasOffsets,int iter, boolean
1630 // reversed, ArrayList<ExpandIterInfo> toRemove) throws TransactionException
1632 @SuppressWarnings("unused")
1633 private static void processPathLegNoOffset(UpdateStruct2 u) throws Exception {
1635 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1636 Vector3d offset = new Vector3d();
1639 for (PipeControlPoint icp : u.list) {
1640 if (icp.isOffset()) {
1641 offset.add(icp.getSizeChangeOffsetVector(u.dir));
1642 } else if (icp.isDualSub()) {
1643 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1650 private static void updateOffsetPoint(PipeControlPoint sccp, Vector3d offset) {
1651 Vector3d world = sccp.getWorldPosition();
1653 PipeControlPoint ocp = sccp.getDualSub();
1654 ocp.setWorldPosition(world);
1658 * Updates InlineControlPoints position when straight pipe's end(s) have
1666 private static void updateInlineControlPoint(PipeControlPoint icp, Vector3d prev, Vector3d next, Vector3d dir) {
1668 System.out.println("PipingRules.updateInlineControlPoint() " + icp);
1670 Vector3d inlinePoint = icp.getWorldPosition();
1671 Vector3d prevPoint = new Vector3d(prev);
1672 Vector3d nextPoint = new Vector3d(next);
1673 if (!icp.isVariableLength()) {
1674 // Reserve space for fixed length components.
1675 MathTools.mad(prevPoint, dir, icp.getInlineLength());
1676 MathTools.mad(nextPoint, dir, -icp.getInlineLength());
1677 if (MathTools.distance(prevPoint, nextPoint) < ALLOWED_OFFSET) {
1682 boolean canCalc = MathTools.distance(prevPoint, nextPoint) > ALLOWED_OFFSET;
1684 System.out.print("InlineControlPoint update " + icp + " " + inlinePoint + " " + prevPoint + " " + nextPoint);
1685 Vector3d newInlinePoint = null;
1687 boolean branchUpdate = false;
1688 PipeControlPoint becp = null;
1689 for (PipeControlPoint pcp : icp.getChildPoints())
1690 if (pcp.isNonDirected()) {
1691 branchUpdate = true;
1696 if (DUMMY || !branchUpdate) {
1697 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1701 // FIXME : can only handle one branch
1702 PipeControlPoint p = null;
1703 if (becp.getNext() != null) {
1704 p = becp.findNextEnd();
1705 } else if (becp.getPrevious() != null) {
1706 p = becp.findPreviousEnd();
1709 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1710 } else if (canCalc){
1711 Vector3d branchLegEnd = p.getWorldPosition();
1712 Vector3d dir2 = new Vector3d(inlinePoint);
1713 dir2.sub(branchLegEnd);
1714 Vector3d dir1 = new Vector3d(nextPoint);
1715 dir1.sub(prevPoint);
1716 newInlinePoint = new Vector3d();
1717 double mu[] = new double[2];
1718 MathTools.intersectStraightStraight(new Vector3d(prevPoint), dir1, new Vector3d(branchLegEnd), dir2, newInlinePoint, new Vector3d(), mu);
1720 System.out.println(mu[0]);
1721 // FIXME : reserve space
1723 newInlinePoint = new Vector3d(prevPoint);
1724 } else if (mu[0] > 1.0) {
1725 newInlinePoint = new Vector3d(nextPoint);
1730 // prevPoint == nextPoint
1731 newInlinePoint = new Vector3d(prevPoint);
1734 System.out.println(" " + newInlinePoint);
1736 icp.setWorldPosition(newInlinePoint);
1737 updateControlPointOrientation(icp, dir);
1741 * Updates InlineControlPoints position when straight pipe's end(s) have
1749 private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d dir) throws Exception {
1751 System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
1753 if (!ecp.isFixed()) // prevent overriding nozzle orientations..
1754 updateControlPointOrientation(ecp, dir);
1756 for (PipeControlPoint pcp : ecp.getChildPoints()) {
1757 // TODO update position
1758 updatePathLegEndControlPoint(pcp);
1762 private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) {
1763 Double angleO = pcp.getRotationAngle();
1767 boolean reversed = pcp._getReversed();
1770 q = pcp.getControlPointOrientationQuat(dir, angle, reversed);
1772 q = pcp.getControlPointOrientationQuat(angle, reversed);
1774 pcp.setWorldOrientation(q);
1778 * Updates all branches when branch's position has been changed
1782 private static void updateBranchControlPointBranches(PipeControlPoint bcp) throws Exception {
1784 System.out.println("PipingRules.updateBranchControlPointBranches() " + bcp);
1785 if (bcp.isDualInline())
1787 Collection<PipeControlPoint> branches = bcp.getChildPoints();
1788 if (branches.size() == 0) {
1790 System.out.println("No Branches found");
1794 for (PipeControlPoint pcp : branches) {
1795 updatePathLegEndControlPoint(pcp);
1799 private static double updateTurnControlPointTurn(PipeControlPoint tcp, Vector3d prev, Vector3d next) {
1801 UpdateStruct2 us = createUS(tcp, Direction.NEXT, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1806 UpdateStruct2 us = createUS(tcp, Direction.PREVIOUS, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1812 if (!tcp.asFixedAngle()) {
1815 if (next == null || prev == null) {
1816 if (tcp.getTurnAngle() != null)
1817 return tcp.getTurnAngle();
1818 return Math.PI; // FIXME : argh
1820 double turnAngle = prev.angle(next);
1822 double angle = Math.PI - turnAngle;
1824 Vector3d turnAxis = new Vector3d();
1825 turnAxis.cross(prev, next);
1826 if (turnAxis.lengthSquared() > MathTools.NEAR_ZERO) {
1827 double elbowRadius = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1828 double R = elbowRadius / Math.tan(angle * 0.5);
1830 turnAxis.normalize();
1831 tcp.setTurnAngle(turnAngle);
1832 tcp.setLength(R);// setComponentOffsetValue(R);
1833 tcp.setTurnAxis(turnAxis);
1834 // tcp.setPosition(tcp.getPosition());
1837 tcp.setTurnAngle(0.0);
1839 tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
1842 updateControlPointOrientation(tcp,prev);
1845 System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
1849 if (prev != null && next != null) {
1851 } else if (prev == null) {
1852 if (!tcp._getReversed())
1853 tcp.setReversed(true);
1854 } else if (next == null) {
1855 if (tcp._getReversed())
1856 tcp.setReversed(false);
1859 Vector3d dir = null;
1860 if (!tcp._getReversed()) {
1867 return Math.PI; // FIXME : argh
1870 Quat4d q = PipeControlPoint.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
1871 Vector3d v = new Vector3d();
1872 MathTools.rotate(q, MathTools.Y_AXIS,v);
1874 tcp.setWorldOrientation(q);
1875 if (tcp.getTurnAngle() != null)
1876 return tcp.getTurnAngle();
1877 return Math.PI; // FIXME : argh
1883 public static List<PipeControlPoint> getControlPoints(PipeRun pipeRun) {
1884 List<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
1885 if (pipeRun.getControlPoints().size() == 0)
1887 PipeControlPoint pcp = pipeRun.getControlPoints().iterator().next();
1888 while (pcp.getPrevious() != null) {
1889 PipeControlPoint prev = pcp.getPrevious();
1890 if (prev.getPipeRun() != pipeRun && prev.getPipeRun() != null) { // bypass possible corruption
1895 if (pcp.isDualSub()) {
1896 pcp = pcp.getParentPoint();
1899 while (pcp.getNext() != null) {
1900 pcp = pcp.getNext();
1901 if (pcp.getPipeRun() != pipeRun)
1908 public static void reverse(PipeRun pipeRun) {
1911 List<PipeControlPoint> points = getControlPoints(pipeRun);
1912 PipeControlPoint pcp = points.get(0);
1913 if (pcp.isSizeChange() && pcp.getChildPoints().size() > 0) {
1914 PipeRun pr = pcp.getPipeRun();
1922 List<PipeRun> all = new ArrayList<PipeRun>();
1923 List<List<PipeControlPoint>> pcps = new ArrayList<List<PipeControlPoint>>();
1926 List<PipeControlPoint> points = getControlPoints(pipeRun);
1928 PipeControlPoint pcp = points.get(points.size()-1);
1929 if (pcp.getChildPoints().size() > 0) {
1930 PipeRun pipeRun2 = pcp.getChildPoints().get(0).getPipeRun();
1931 if (pipeRun == pipeRun2)
1939 for (int i = 0 ; i < all.size(); i++) {
1940 List<PipeControlPoint> list = pcps.get(i);
1943 for (int i = 0 ; i < all.size(); i++) {
1944 boolean last = i == all.size() - 1;
1945 List<PipeControlPoint> list = pcps.get(i);
1948 List<PipeControlPoint> list2 = pcps.get(i+1);
1949 PipeControlPoint prev = list.get(list.size()-1);
1950 PipeControlPoint next = list2.get(0);
1952 // Reverse the component on the boundary.
1953 InlineComponent ic = (InlineComponent)prev.getPipelineComponent();
1954 PipeRun r1 = ic.getPipeRun();
1955 PipeRun r2 = ic.getAlternativePipeRun();
1956 if (r1 == null || r2 == null)
1957 throw new RuntimeException("Components on PipeRun changes should refer to bot PipeRuns");
1961 ic.setAlternativePipeRun(r1);
1963 throw new RuntimeException("PipeRun changes should contain shared control points");
1971 private static void _reverse(List<PipeControlPoint> list) {
1972 if (list.size() <= 1)
1973 return; // nothing to do.
1975 for (int i = 0 ; i < list.size(); i++) {
1976 boolean first = i == 0;
1977 boolean last = i == list.size() - 1;
1978 PipeControlPoint current = list.get(i);
1979 PipeControlPoint currentSub = null;
1980 if (current.isDualInline())
1981 currentSub = current.getDualSub();
1983 PipeControlPoint next = list.get(i+1);
1984 if (next.isDualInline())
1985 next = next.getDualSub();
1986 if (current.getNext() == next)
1987 current.setNext(null);
1988 current.setPrevious(next);
1989 if (currentSub != null) {
1990 if (currentSub.getNext() == next)
1991 currentSub.setNext(null);
1992 currentSub.setPrevious(next);
1995 PipeControlPoint prev = list.get(i-1);
1997 if (current.getPrevious() == prev)
1998 current.setPrevious(null);
1999 current.setNext(prev);
2001 if (currentSub != null) {
2002 if (currentSub.getPrevious() == prev)
2003 currentSub.setPrevious(null);
2004 currentSub.setNext(prev);
2007 PipeControlPoint prev = list.get(i-1);
2008 PipeControlPoint next = list.get(i+1);
2009 if (next.isDualInline())
2010 next = next.getDualSub();
2013 current.setPrevious(next);
2014 current.setNext(prev);
2016 if (currentSub != null) {
2017 currentSub.setPrevious(next);
2018 currentSub.setNext(prev);
2022 //if (current.isTurn() && current.isFixed()) {
2023 if (current.asFixedAngle()) {
2024 current.setReversed(!current._getReversed());
2026 if (current.isInline() && current.isReverse()) {
2027 current.setReversed(!current._getReversed());
2034 public static void validate(PipeRun pipeRun) {
2035 if (pipeRun == null)
2037 Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
2039 //System.out.println("Validate " + pipeRun.getName());
2040 for (PipeControlPoint pcp : pcps) {
2041 if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
2044 List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
2045 if (runPcps.size() != count) {
2046 System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
2047 for (PipeControlPoint pcp : pcps) {
2048 if (!runPcps.contains(pcp)) {
2049 System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
2053 for (PipeControlPoint pcp : pcps) {
2054 if (pcp.getPipeRun() == null) {
2055 System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
2057 if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
2058 System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
2060 for (PipeControlPoint pcp : pcps) {
2061 if (pcp.getParentPoint() == null) {
2062 PipeControlPoint sub = null;
2063 if (pcp.isDualInline())
2064 sub = pcp.getDualSub();
2065 PipeControlPoint next = pcp.getNext();
2066 PipeControlPoint prev = pcp.getPrevious();
2068 if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
2069 System.out.println("Inconsistency between " + pcp + " -> " +next );
2073 PipeControlPoint prevParent = null;
2074 if (prev.isDualSub()) {
2075 prevParent = prev.getParentPoint();
2076 } else if (prev.isDualInline()) {
2077 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2079 if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
2080 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2087 public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{
2088 assert(!splittingComponent.getControlPoint().isFixedLength());
2089 assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixedLength()));
2090 PipeControlPoint newCP = newComponent.getControlPoint();
2091 PipeControlPoint splittingCP = splittingComponent.getControlPoint();
2092 PipeControlPoint nextCP = splittingCP.getNext();
2093 PipeControlPoint prevCP = splittingCP.getPrevious();
2095 /* there are many different cases to insert new component when
2096 it splits existing VariableLengthinlineComponent.
2098 1. VariableLengthComponet is connected from both sides:
2099 - insert new component between VariableLength component and component connected to it
2100 - insert new VariableLengthComponent between inserted component and component selected in previous step
2102 2. VariableLengthComponent is connected from one side
2103 - Use previous case or:
2104 - Insert new component to empty end
2105 - Insert new VariableLength component to inserted components empty end
2107 3. VariableLength is not connected to any component.
2108 - Should not be possible, at least in current implementation.
2109 - Could be done using second case
2113 if (nextCP == null && prevCP == null) {
2114 // this should not be possible
2115 throw new RuntimeException("VariableLengthComponent " + splittingComponent + " is not connected to anything.");
2117 double newLength = newComponent.getControlPoint().getLength();
2120 Point3d next = new Point3d();
2121 Point3d prev = new Point3d();
2122 splittingCP.getInlineControlPointEnds(prev, next);
2124 Vector3d newPos = null;
2126 newPos = new Vector3d(prev);
2127 Vector3d dir = new Vector3d(next);
2131 newComponent.setWorldPosition(newPos);
2133 newPos = newComponent.getWorldPosition();
2138 Vector3d dir = new Vector3d(next);
2141 dir.scale(newLength * 0.5);
2142 Point3d vn = new Point3d(newPos);
2143 Point3d vp = new Point3d(newPos);
2146 double ln = vn.distance(next);
2147 double lp = vp.distance(prev);
2148 vp.interpolate(prev, 0.5);
2149 vn.interpolate(next, 0.5);
2152 if (nextCP == null) {
2153 newCP.insert(splittingCP, Direction.NEXT);
2154 insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
2155 splittingCP.setWorldPosition(new Vector3d(vp));
2156 // ControlPointTools.setWorldPosition(splittingCP, vp);
2157 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2158 } else if (prevCP == null) {
2159 newCP.insert(splittingCP, Direction.PREVIOUS);
2160 insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
2161 splittingCP.setWorldPosition(new Vector3d(vn));
2162 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, ln);
2164 newCP.insert(splittingCP, nextCP);
2165 insertStraight(newCP, nextCP, new Vector3d(vn), ln);
2166 splittingCP.setWorldPosition(new Vector3d(vp));
2167 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2169 positionUpdate(newCP);
2173 public static void addSizeChange(boolean reversed, PipeRun pipeRun, PipeRun other, InlineComponent reducer, PipeControlPoint previous, PipeControlPoint next) {
2174 PipeControlPoint pcp = reducer.getControlPoint();
2175 PipeControlPoint ocp = pcp.getDualSub();
2177 String name = pipeRun.getUniqueName("Reducer");
2178 reducer.setName(name);
2179 pipeRun.addChild(reducer);
2180 other.addChild(ocp);
2181 reducer.setAlternativePipeRun(other);
2183 previous.setNext(pcp);
2184 pcp.setPrevious(previous);
2185 ocp.setPrevious(previous);
2189 next.setPrevious(ocp);
2192 String name = other.getUniqueName("Reducer");
2193 reducer.setName(name);
2194 other.addChild(reducer);
2195 pipeRun.addChild(ocp);
2196 reducer.setAlternativePipeRun(pipeRun);
2200 pcp.setPrevious(next);
2201 ocp.setPrevious(next);
2203 pcp.setNext(previous);
2204 ocp.setNext(previous);
2205 previous.setPrevious(ocp);