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);
220 if (pcp.isOffset()) {
221 // Adjusting the rotation angle of an offset component may change variable angle turns
222 PipeControlPoint end = pcp.findNextEnd();
223 if (end.isVariableAngle()) {
224 updatePathLegNext(end, end, PathLegUpdateType.NONE);
226 if (start.isVariableAngle()) {
227 updatePathLegPrev(start, start, PathLegUpdateType.NONE);
232 private static PipeControlPoint insertElbow(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos) throws Exception{
234 System.out.println("PipingRules.insertElbow() " + pcp1 + " " + pcp2 + " " + pos);
235 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
237 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
238 pcp1 = pcp1.getDualSub();
239 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
240 PipeControlPoint t = pcp1;
243 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
244 PipeControlPoint t = pcp1;
245 pcp1 = pcp2.getDualSub();
248 throw new RuntimeException();
250 TurnComponent elbow = ComponentUtils.createTurn((P3DRootNode)pcp1.getRootNode());
251 PipeControlPoint pcp = elbow.getControlPoint();
252 if (pcp1.isDualInline())
253 pcp1 = pcp1.getDualSub();
254 String name = pcp1.getPipeRun().getUniqueName("Elbow");
256 pcp1.getPipeRun().addChild(elbow);
258 pcp.insert(pcp1, pcp2);
260 pcp.setWorldPosition(pos);
261 validate(pcp.getPipeRun());
265 private static PipeControlPoint insertStraight(PipeControlPoint pcp1, PipeControlPoint pcp2, Vector3d pos, double length) throws Exception {
267 System.out.println("PipingRules.insertStraight() " + pcp1 + " " + pcp2 + " " + pos);
268 if (pcp1.getNext() == pcp2 && pcp2.getPrevious() == pcp1) {
270 } else if (pcp1.getNext() == pcp2 && pcp1.isDualInline() && pcp2.getPrevious() == pcp1.getDualSub()) {
271 pcp1 = pcp1.getDualSub();
272 } else if (pcp1.getPrevious() == pcp2 && pcp2.getNext() == pcp1) {
273 PipeControlPoint t = pcp1;
276 } else if (pcp2.isDualInline() && pcp1.getPrevious() == pcp2.getDualSub() && pcp2.getNext() == pcp1) {
277 PipeControlPoint t = pcp1;
278 pcp1 = pcp2.getDualSub();
281 throw new RuntimeException();
283 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp1.getRootNode());
284 PipeControlPoint scp = component.getControlPoint();
285 if (pcp1.isDualInline())
286 pcp1 = pcp1.getDualSub();
287 String name = pcp1.getPipeRun().getUniqueName("Pipe");
288 component.setName(name);
289 pcp1.getPipeRun().addChild(component);
291 scp.insert(pcp1, pcp2);
293 scp.setWorldPosition(pos);
294 Vector3d dir = new Vector3d();
295 dir.sub(pcp2.getWorldPosition(), pcp1.getWorldPosition());
296 updateControlPointOrientation(scp, dir);
297 scp.setLength(length);
298 validate(scp.getPipeRun());
302 private static PipeControlPoint insertStraight(PipeControlPoint pcp, Direction direction , Vector3d pos, double length) throws Exception {
304 System.out.println("PipingRules.insertStraight() " + pcp + " " + direction + " " + pos);
306 InlineComponent component = ComponentUtils.createStraight((P3DRootNode)pcp.getRootNode());
307 PipeControlPoint scp = component.getControlPoint();
308 if (pcp.isDualInline() && direction == Direction.NEXT)
309 pcp = pcp.getDualSub();
310 String name = pcp.getPipeRun().getUniqueName("Pipe");
311 component.setName(name);
312 pcp.getPipeRun().addChild(component);
314 scp.insert(pcp,direction);
316 scp.setWorldPosition(pos);
317 scp.setLength(length);
318 validate(scp.getPipeRun());
322 private static void updatePathLegNext(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
323 UpdateStruct2 us = createUS(start, Direction.NEXT, 0, new ArrayList<ExpandIterInfo>(), updated);
325 System.out.println("Null update struct " + start);
328 updatePathLeg(us, lengthChange);
331 private static void updatePathLegPrev(PipeControlPoint start, PipeControlPoint updated, PathLegUpdateType lengthChange) throws Exception {
332 UpdateStruct2 us = createUS(start, Direction.PREVIOUS, 0, new ArrayList<ExpandIterInfo>(), updated);
334 System.out.println("Null update struct " + start);
337 updatePathLeg(us, lengthChange);
340 private static class UpdateStruct2 {
341 public PipeControlPoint start;
342 public Vector3d startPoint;
343 public ArrayList<PipeControlPoint> list;
344 public PipeControlPoint end;
345 public Vector3d endPoint;
347 public Vector3d offset;
348 public boolean hasOffsets;
350 public boolean reversed;
351 public ArrayList<ExpandIterInfo> toRemove;
352 public PipeControlPoint updated;
354 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) {
355 if (start == null || end == null)
356 throw new NullPointerException();
358 this.startPoint = startPoint;
361 this.endPoint = endPoint;
363 this.offset = offset;
364 this.hasOffsets = hasOffsets;
366 this.reversed = reversed;
367 this.toRemove = toRemove;
368 this.updated = updated;
370 if (!MathTools.isValid(startPoint) ||
371 !MathTools.isValid(endPoint) ||
372 !MathTools.isValid(dir)) {
373 throw new RuntimeException();
377 public String toString() {
378 return start + " " + end+ " " + dir + " " + hasOffsets + " " + offset + " " + iter + " " + toRemove.size();
383 public static boolean calculateDirectedOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
384 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, true);
387 public static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset) {
388 return calculateOffset(startPoint, endPoint, start, list, end, dir, offset, false);
391 private static boolean calculateOffset(Vector3d startPoint, Vector3d endPoint, PipeControlPoint start, ArrayList<PipeControlPoint> list, PipeControlPoint end, Vector3d dir, Vector3d offset, boolean directed) {
392 List<PipeControlPoint> offsets = getOffsetPoints(start, list);
393 if (offsets.size() == 0) {
394 setZeroOffset(startPoint, endPoint, dir, offset);
397 Vector3d sp = new Vector3d(startPoint);
398 Point3d ep = new Point3d(endPoint);
401 double l = dir.lengthSquared();
402 if (l > MathTools.NEAR_ZERO)
403 dir.scale(1.0/Math.sqrt(l));
408 offset.set(0.0, 0.0, 0.0);
410 for (PipeControlPoint icp : offsets) {
411 Vector3d v = icp.getSizeChangeOffsetVector(dir);
418 Point3d nep = new Point3d(endPoint);
420 if (nep.distance(ep) < 0.0000000001 || iter <= 0) {
427 l = dir.lengthSquared();
428 if (l > MathTools.NEAR_ZERO)
429 dir.scale(1.0/Math.sqrt(l));
433 System.out.println("calcOffset s:"+ startPoint + " e:" + endPoint + " d:" + dir + " o:"+offset) ;
439 public static void setZeroOffset(Vector3d startPoint, Vector3d endPoint, Vector3d dir, Vector3d offset) {
442 double l = dir.lengthSquared();
443 if (l > MathTools.NEAR_ZERO)
444 dir.scale(1.0/Math.sqrt(l));
445 offset.set(0.0, 0.0, 0.0);
448 public static List<PipeControlPoint> getOffsetPoints(PipeControlPoint start, ArrayList<PipeControlPoint> list) {
449 List<PipeControlPoint> offsets = new ArrayList<PipeControlPoint>(list.size());
450 // Only start offset affects the calculation
451 if (start.isOffset())
453 for (PipeControlPoint icp : list) {
454 if (icp.isOffset()) {
456 } else if (icp.isDualSub())
457 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
462 private static UpdateStruct2 createUS(PipeControlPoint start, Direction direction, int iter, ArrayList<ExpandIterInfo> toRemove, PipeControlPoint updated) {
463 ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
464 PipeControlPoint end = null;
465 if (direction == Direction.NEXT) {
466 end = start.findNextEnd(list);
468 ArrayList<PipeControlPoint> prevList = new ArrayList<PipeControlPoint>();
469 PipeControlPoint tend = start.findPreviousEnd(prevList);
470 for (PipeControlPoint icp : prevList) {
471 if (icp.isDualSub()) {
472 list.add(0, icp.getParentPoint());
482 boolean hasOffsets = false;
483 Vector3d offset = new Vector3d();
484 Vector3d startPoint = start.getWorldPosition();
485 Vector3d endPoint = end.getWorldPosition();
486 Vector3d dir = new Vector3d();
487 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
488 return new UpdateStruct2(start, startPoint, list, end, endPoint, dir, offset, hasOffsets, iter, direction == Direction.PREVIOUS, toRemove, updated);
491 private static Vector3d pathLegDirection(PipeControlPoint start) {
492 ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
493 PipeControlPoint end = start.findNextEnd(list);
495 return start.getDirection(Direction.NEXT);
498 Vector3d offset = new Vector3d();
499 Vector3d startPoint = start.getWorldPosition();
500 Vector3d endPoint = end.getWorldPosition();
501 Vector3d dir = new Vector3d();
502 calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
506 private static boolean asDirected(PipeControlPoint pcp, Direction direction) {
507 if (pcp.isDirected())
509 if (pcp.asFixedAngle()) {
510 if (!pcp._getReversed())
511 return direction == Direction.NEXT;
513 return direction == Direction.PREVIOUS;
518 private static Vector3d direction(PipeControlPoint pcp, Direction direction) {
519 return pcp.getDirection(direction);
522 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
525 if (lengthChange == PathLegUpdateType.NONE) {
529 updatePathLeg(u, lengthChange, rs, re);
532 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean rs, boolean re) throws Exception {
534 if (asDirected(u.start, Direction.NEXT))
536 if (asDirected(u.end, Direction.PREVIOUS))
539 setErrorForce(u.start, null);
541 setErrorForce(u.end, null);
542 for (PipeControlPoint pcp : u.list)
543 setErrorForce(pcp, null);
546 updateFreePathLeg(u, lengthChange);
549 updateDirectedPathLeg(u, lengthChange);
552 updateDualDirectedPathLeg(u, lengthChange);
558 private static void updateFreePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
560 System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange);
561 checkExpandPathLeg(u, lengthChange);
562 if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle())
563 processPathLeg(u, true, false);
566 private static void updateInlineControlPoints(UpdateStruct2 u, boolean checkSizes) throws Exception{
568 System.out.println("PipingRules.updateInlineControlPoints() " + u);
570 Vector3d start = new Vector3d(u.startPoint);
571 Vector3d end = new Vector3d(u.endPoint);
574 // create offsets for leg ends.
575 if (u.start.isTurn())
576 MathTools.mad(start, u.dir, u.start.getInlineLength());
578 MathTools.mad(end, u.dir, -u.end.getInlineLength());
581 boolean recalcline = false;
583 Vector3d sp = new Vector3d(start);
584 Vector3d ep = new Vector3d(end);
587 if (u.start.isOffset()) {
588 Vector3d offset = u.start.getSizeChangeOffsetVector(u.dir);
589 updateOffsetPoint(u.start, offset);
594 for (PipeControlPoint icp : u.list) {
595 updateInlineControlPoint(icp, sp, ep, u.dir);
596 if (icp.isOffset()) {
597 // TODO : offset vector is already calculated and should be cached
598 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
599 updateOffsetPoint(icp, offset);
608 // Collect all path leg points for updating variable length components. This list will also contain leg ends (usually turns)
609 ArrayList<PipeControlPoint> pathLegPoints = new ArrayList<>();
610 // Collect all fixed length components with their offsets.
611 ArrayList<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints = new ArrayList<>();
613 pathLegPoints.add(u.start);
614 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.start, new Vector3d()));
615 Vector3d off = new Vector3d();
616 for (PipeControlPoint icp : u.list) {
617 pathLegPoints.add(icp);
618 updateBranchControlPointBranches(icp);
619 if (icp.isOffset()) {
620 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
621 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
623 } else if (!icp.isVariableLength()) {
624 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
627 pathLegPoints.add(u.end);
628 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.end, new Vector3d(off)));
630 sp = new Vector3d(start);
631 ep = new Vector3d(end);
634 updateFixedLengths(fixedLengthPoints, sp, ep, u.dir);
636 for (int i = 0; i < pathLegPoints.size(); i++) {
637 PipeControlPoint icp = pathLegPoints.get(i);
639 PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
640 PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
642 if (prev != null && prev.isDualInline())
643 prev = prev.getDualSub();
645 if (icp.isVariableLength()) {
646 if (prev != null && next != null) {
647 recalcline = recalcline | updateVariableLength(icp, prev, next);
650 // this is variable length component at the end of the piperun.
651 // the problem is that we want to keep unconnected end of the component in the same
652 // place, but center of the component must be moved.
653 updateVariableLengthEnd(icp, prev != null ? prev : next);
655 } else if (prev != null && !prev.isVariableLength()) {
656 // If this and previous control point are not variable length pcps,
657 // we'll have to check if there is no empty space between them.
658 // I there is, we'll have to create new variable length component between them.
659 recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
661 if (icp.isOffset()) {
662 // TODO : offset vector is already calculated and should be cached
663 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
671 u.start.findNextEnd(u.list);
674 sp = new Vector3d(u.startPoint);
675 ep = new Vector3d(u.endPoint);
677 double pathLegLength = MathTools.distance(sp, ep);
678 double availableLength = pathLegLength;
679 if (u.start.isTurn())
680 availableLength -= u.start.getInlineLength();
682 availableLength -= u.end.getInlineLength();
683 for (PipeControlPoint pcp : u.list) {
684 if (!pcp.isVariableLength())
685 availableLength-= pcp.getLength();
687 if (availableLength < 0.0) {
688 setError(u.start, "Not enough available space");
689 setError(u.end, "Not enough available space");
690 for (PipeControlPoint pcp : u.list)
691 setError(pcp, "Not enough available space");
693 // System.out.println(u.start.getPipelineComponent().toString() + " " + pathLegLength + " " + availableLength + " " + u.end.getPipelineComponent().toString() + " " + u.start.getInlineLength() + " " + u.end.getInlineLength());
697 private enum Gap{ATTACHED,OVERLAP,SPACE};
699 private static class GapObj {
703 Pair<PipeControlPoint,Vector3d> pcp1;
704 Pair<PipeControlPoint,Vector3d> pcp2;
707 private static void updateFixedLengths(List<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints, Vector3d s, Vector3d e, Vector3d dir) {
708 double totalLength = MathTools.distance(s, e);
709 double reservedLength = 0.0;
710 List<Double> distances = new ArrayList<>(fixedLengthPoints.size());
712 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
713 Pair<PipeControlPoint,Vector3d> pcp = fixedLengthPoints.get(i);
714 reservedLength += pcp.first.getLength();
715 Vector3d p = pcp.first.getWorldPosition();
717 double d= MathTools.distance(s, p);
720 distances.add(totalLength);
722 if (totalLength >= reservedLength) {
723 // There is enough space for all fixed length components.
724 List<GapObj> gaps = new ArrayList<>(fixedLengthPoints.size()-1);
726 // Analyze gaps between components
727 for (int i = 0; i < fixedLengthPoints.size()-1; i++) {
728 Pair<PipeControlPoint,Vector3d> pcp1 = fixedLengthPoints.get(i);
729 Pair<PipeControlPoint,Vector3d> pcp2 = fixedLengthPoints.get(i+1);
730 double d1 = distances.get(i);
731 double d2 = distances.get(i+1);
732 double ld1 = i == 0 ? 0.0 :pcp1.first.getInlineLength();
733 double ld2 = i == fixedLengthPoints.size()-2 ? 0.0 : pcp2.first.getInlineLength();
735 double e1 = d1 + ld1; // End of comp1
736 double s2 = d2 - ld2; // Start of comp2
737 double diff =s2 - e1;
738 GapObj obj = new GapObj();
742 if (diff < -MIN_INLINE_LENGTH) {
743 obj.gap = Gap.OVERLAP;
745 } else if (diff > MIN_INLINE_LENGTH) {
748 obj.gap = Gap.ATTACHED;
752 // If there are no overlaps, there is nothing to do.
755 // Get rid of overlapping components by using closest available free spaces.
756 for (int i = 0; i < gaps.size(); i++) {
757 GapObj gapObj = gaps.get(i);
758 if (gapObj.gap != Gap.OVERLAP)
760 double curr = gapObj.d;
762 while (d < gaps.size() && curr < -MIN_INLINE_LENGTH) {
763 GapObj next = i+d >= 0 ? gaps.get(i+d) : null;
764 GapObj prev = i-d >= 0 ? gaps.get(i-d) : null;
765 if (next != null && next.gap == Gap.SPACE) {
766 double move = Math.min(-curr, next.d);
769 if (next.d < MIN_INLINE_LENGTH)
770 next.gap = Gap.ATTACHED;
771 Vector3d mv = new Vector3d(dir);
774 for (int j = i ; j < i+d; j++) {
775 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp2;
776 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
778 pcp.first.setWorldPosition(p);
781 else if (prev != null && prev.gap == Gap.SPACE) {
782 double move = Math.min(-curr, prev.d);
785 if (prev.d < MIN_INLINE_LENGTH)
786 prev.gap = Gap.ATTACHED;
787 Vector3d mv = new Vector3d(dir);
790 for (int j = i ; j > i-d; j--) {
791 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp1;
792 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
794 pcp.first.setWorldPosition(p);
803 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
804 Pair<PipeControlPoint,Vector3d> prev = i == 0 ? null : fixedLengthPoints.get(i-1);
805 Pair<PipeControlPoint,Vector3d> curr = fixedLengthPoints.get(i);
806 Pair<PipeControlPoint,Vector3d> next = i == fixedLengthPoints.size() -1 ? null : fixedLengthPoints.get(i+1);
807 updateFixedLength(curr, prev, next, s,e, dir);
812 private static void updateFixedLength(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> prev, Pair<PipeControlPoint,Vector3d> next, Vector3d s, Vector3d e, Vector3d dir) {
814 checkOverlap(prev, icp, dir,true);
817 checkOverlap(icp, next, dir,true);
820 private static boolean checkOverlap(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> icp2, Vector3d dir, boolean se) {
821 Vector3d p1 = icp.first.getWorldPosition();
822 Vector3d p2 = icp2.first.getWorldPosition();
825 double u[] = new double[1];
826 MathTools.closestPointOnStraight(p2, p1, dir, u);
831 MathTools.mad(p2, dir, MIN_INLINE_LENGTH);
832 icp2.first.setWorldPosition(p2);
834 double d = MathTools.distance(p1, p2);
835 double r = icp.first.getInlineLength() + icp2.first.getInlineLength();
837 if ((d-r) < - MIN_INLINE_LENGTH) {
839 setError(icp.first, "Overlapping");
840 setError(icp2.first, "Overlapping");
848 * Overrides current error of a component
852 private static void setErrorForce(PipeControlPoint pcp, String error) {
853 PipelineComponent comp = pcp.getPipelineComponent();
856 comp.setError(error);
860 * Sets error for a component, if there is no existing error.
864 private static void setError(PipeControlPoint pcp, String error) {
865 PipelineComponent comp = pcp.getPipelineComponent();
868 if (comp.getError() != null)
870 comp.setError(error);
873 private static boolean updateVariableLength(PipeControlPoint icp, PipeControlPoint prev, PipeControlPoint next) {
874 Vector3d prevPos = prev.getWorldPosition();
875 Vector3d nextPos = next.getWorldPosition();
877 Vector3d dir = new Vector3d(nextPos);
879 double l = dir.length(); // distance between control points
880 double l2prev = prev.getInlineLength(); // distance taken by components
881 double l2next = next.getInlineLength();
882 double l2 = l2prev + l2next;
883 double length = l - l2; // true length of the variable length component
884 if (length >= MIN_INLINE_LENGTH) { // check if there is enough space for variable length component.
887 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
889 icp.setWorldPosition(dir);
890 icp.setLength(length);
893 // components leave no space to the component and it must be removed
894 if (icp.isDeletable()) {
895 if (!allowInsertRemove) {
896 icp.setLength(MIN_INLINE_LENGTH);
897 setError(icp, "Not enough available space");
902 System.out.println("PipingRules.updateVariableLength removing " + icp);
906 icp.setLength(MIN_INLINE_LENGTH);
907 icp.getPipelineComponent().setError("Not enough available space");
913 private static boolean possibleVaribleLengthInsert(PipeControlPoint icp, PipeControlPoint prev) throws Exception{
914 Vector3d currentPos = icp.getWorldPosition();
915 Vector3d prevPos = prev.getWorldPosition();
916 Vector3d dir = new Vector3d(currentPos);
918 double l = dir.lengthSquared();
919 double l2prev = prev.getInlineLength();
920 double l2next = icp.getInlineLength();
921 double l2 = l2prev + l2next;
922 double l2s = l2 * l2;
923 double diff = l - l2s;
924 if (diff >= MIN_INLINE_LENGTH) {
925 if (allowInsertRemove) {
927 double length = Math.sqrt(l) - l2; // true length of the variable length component
928 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
930 insertStraight(prev, icp, dir, length);
939 private static void updateVariableLengthEnd(PipeControlPoint icp, PipeControlPoint prev) {
940 Vector3d currentPos = icp.getWorldPosition();
941 Vector3d prevPos = prev.getWorldPosition();
943 Vector3d dir = new Vector3d();
944 dir.sub(currentPos, prevPos);
947 synchronized (ruleMutex) {
948 simple = currentUpdates.contains(icp);
952 // Update based on position -> adjust length
953 double currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
954 icp.setLength(currentLength);
956 // Update based on neighbour movement -> adjust length and position, so that free end stays in place.
957 double currentLength = icp.getLength();
958 if (currentLength < MathTools.NEAR_ZERO) {
959 currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
962 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
964 Point3d endPos = new Point3d(dir);
965 endPos.scale(currentLength * 0.5);
966 endPos.add(currentPos); // this is the free end of the component
968 double offset = prev.getInlineLength();
969 Point3d beginPos = new Point3d(dir);
970 beginPos.scale(offset);
971 beginPos.add(prevPos); // this is the connected end of the component
973 double l = beginPos.distance(endPos);
976 System.out.println("Length for " + icp + " is NaN");
979 beginPos.add(dir); // center position
982 System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
985 icp.setWorldPosition(new Vector3d(beginPos));
990 * Recalculates offset vector based on current direction, and calls checkExpandPathLeg
995 private static void ppNoOffset(UpdateStruct2 u, boolean updateEnds) throws Exception {
997 System.out.println("PipingRules.ppNoOffset() " + u);
998 Vector3d offset = new Vector3d();
1000 for (PipeControlPoint icp : u.list) {
1001 if (icp.isOffset()) {
1002 offset.add(icp.getSizeChangeOffsetVector(u.dir));
1003 } else if (icp.isDualSub())
1004 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1008 checkExpandPathLeg(u, PathLegUpdateType.NONE, updateEnds);
1011 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 {
1013 System.out.println("PipingRules.ppNoDir() " + start + " " + end + " " + iter + " " + toRemove.size());
1014 // FIXME : extra loop (dir should be calculated here)
1015 Vector3d dir = new Vector3d();
1016 Vector3d offset = new Vector3d();
1017 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
1018 ppNoOffset(new UpdateStruct2(start, startPoint, list, end, endPoint, dir, null, hasOffsets, iter, reversed, toRemove, updated),true);
1021 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1022 checkExpandPathLeg(u, lengthChange, u.updated.isInline() && u.updated.isOffset());
1025 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean updateEnds) throws Exception {
1027 System.out.println("PipingRules.checkExpandPathLeg() " + u + " " + lengthChange);
1028 if (lengthChange != PathLegUpdateType.NONE) {
1029 // FIXME : turns cannot be checked before inline cps are updated,
1030 // since their position affects calculation of turns
1031 processPathLeg(u, updateEnds, false);
1032 int type = checkTurns(u, lengthChange);
1033 if (type == REMOVE_NONE) {
1034 processPathLeg(u, updateEnds, true);
1036 expandPathLeg(u, type);
1039 processPathLeg(u, updateEnds, true);
1043 private static void updateDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1045 System.out.println("PipingRules.updateDirectedPipeRun() " + u + " " + lengthChange);
1046 PipeControlPoint dcp;
1047 PipeControlPoint other;
1048 boolean canMoveOther = false;
1049 boolean dcpStart = false;
1050 boolean inlineEnd = false;
1052 if (asDirected(u.start, Direction.NEXT)) {
1055 position = u.startPoint;
1058 canMoveOther = true;
1059 inlineEnd = u.end.isInline();
1064 position = u.endPoint;
1066 canMoveOther = true;
1067 inlineEnd = u.start.isInline();
1070 Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1071 if (directedDirection == null) {
1072 //updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
1073 updateTurnControlPointTurn(dcp, null, null);
1074 directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1075 if (directedDirection == null) {
1080 Point3d otherPosition = new Point3d(dcpStart ? u.endPoint : u.startPoint);
1082 Vector3d dir = new Vector3d(), offset = new Vector3d();
1083 calculateDirectedOffset(u.startPoint, u.endPoint, u.start, u.list, u.end, dir, offset);
1088 otherPosition.add(offset);
1090 otherPosition.sub(offset);
1093 double mu[] = new double[2];
1096 Vector3d t = new Vector3d();
1098 closest = MathTools.closestPointOnStraight(otherPosition, position, directedDirection, mu);
1099 t.sub(closest, otherPosition);
1101 double distance = t.length();
1102 boolean aligned = (distance < ALLOWED_OFFSET);
1103 double requiredSpace = 0.0;
1104 if (other.isVariableAngle()) {
1105 requiredSpace = spaceForTurn(other, dcp);
1107 if (mu[0] < requiredSpace) {
1108 // At the moment, if next component is directly behind the nozzle, we must force moving the other component.
1109 // Trying to solve the situation by adding new turn creates infinite loop...
1111 canMoveOther = true;
1114 //if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
1115 // processPathLeg(u, true, false);
1116 checkExpandPathLeg(u, lengthChange, inlineEnd || u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle());
1121 PipeControlPoint nextToMoved;
1123 if (u.list.size() > 0)
1125 nextToMoved = u.list.get(0);
1127 nextToMoved = u.list.get(u.list.size() - 1);
1129 nextToMoved = u.end;
1131 nextToMoved = u.start;
1132 if (other.isVariableAngle()) {
1134 // TODO calculate needed space from next run end.
1135 if (mu[0] < requiredSpace) {
1137 closest.set(u.startPoint);
1139 closest.set(u.endPoint);
1141 Vector3d v = new Vector3d(directedDirection);
1142 v.scale(requiredSpace);
1148 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + closest);
1150 // Not aligned - we need to recalculate the offset to reflect new end points.
1153 offset = new Vector3d();
1154 Vector3d newDir = new Vector3d();
1155 calculateDirectedOffset(position, closest, u.start, u.list, u.end, newDir, offset);
1156 closest.add(offset);
1158 offset = new Vector3d();
1161 other.setWorldPosition(closest);
1164 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);
1165 if (u.end.getNext() != null)
1166 updatePathLegNext(u.end, u.updated, PathLegUpdateType.NEXT);
1168 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);
1169 if (u.start.getPrevious() != null)
1170 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.PREV);
1173 // TODO : calculate needed space from next run end.
1174 if (allowInsertRemove)
1175 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1179 } else if (other.isNonDirected() && other.getParentPoint() != null) {
1180 // FIXME : this code was for updating branches
1181 Vector3d bintersect = new Vector3d();
1182 PipeControlPoint bcp = other.getParentPoint();
1183 if (bcp != null && canMoveOther) {
1184 Point3d bstart = new Point3d();
1185 Point3d bend = new Point3d();
1186 Vector3d bdir = new Vector3d();
1187 bcp.getInlineControlPointEnds(bstart, bend, bdir);
1188 Vector3d nintersect = new Vector3d();
1190 MathTools.intersectStraightStraight(position, directedDirection, bend, bdir, nintersect, bintersect, mu);
1191 Vector3d dist = new Vector3d(nintersect);
1192 dist.sub(bintersect);
1193 canMoveOther = mu[1] > 0.0 && mu[1] < 1.0 && dist.lengthSquared() < 0.01;
1195 // TODO : endControlPoints are undirected: calculcate
1196 // correct position for it
1197 throw new UnsupportedOperationException("not implemented");
1201 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + bintersect);
1202 // is required branch position is in possible range
1203 bcp.setWorldPosition(bintersect);
1205 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);
1207 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);
1210 // branch cannot be moved into right position, new turn
1211 // / elbow must be inserted
1212 if (allowInsertRemove)
1213 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1218 } else { // assume that control point cannot be moved, but can
1220 if (allowInsertRemove)
1221 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1229 private static void updateDualDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1231 System.out.println("PipingRules.updateDualDirectedPipeRun() " + u + " " + lengthChange);
1233 PipeControlPoint dcp1 = u.start;
1234 PipeControlPoint dcp2 = u.end;
1235 Point3d position1 = new Point3d(u.startPoint);
1236 Point3d position2 = new Point3d(u.endPoint);
1238 Vector3d dir = new Vector3d(), offset = new Vector3d();
1239 calculateDirectedOffset(new Vector3d(position1), new Vector3d(position2), u.start, u.list, u.end, dir, offset);
1241 Point3d position1offset = new Point3d(position1);
1242 position1offset.add(offset);
1243 Point3d position2offset = new Point3d(position2);
1244 position2offset.sub(offset);
1245 Vector3d dir1 = direction(dcp1, Direction.NEXT);
1246 Vector3d dir2 = direction(dcp2, Direction.PREVIOUS);
1248 Vector3d p1 = MathTools.closestPointOnStraight(position1, position2offset, dir2);
1249 Vector3d p2 = MathTools.closestPointOnStraight(position2, position1offset, dir1);
1250 double d1 = position1.distance(new Point3d(p1));
1251 double d2 = position2.distance(new Point3d(p2));
1253 boolean aligned = (d1 < ALLOWED_OFFSET && d2 < ALLOWED_OFFSET);
1259 } else if (allowInsertRemove){
1260 PipeControlPoint dcp;
1261 PipeControlPoint next;
1264 if (u.list.size() > 0)
1265 next = u.list.get(0);
1270 if (u.list.size() > 0)
1271 next = u.list.get(u.list.size() - 1);
1276 p1 = dcp.getWorldPosition();
1277 Vector3d v = new Vector3d();
1283 // Reserve space for 90 deg elbow
1284 double off = dcp1.getPipeRun().getTurnRadius();
1289 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position2offset, dir2);
1291 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position1offset, dir1);
1293 // By default, the elbows are placed next to each other, by using 90 deg angles.
1294 // If the distance between elbows is not enough, we must move the other elbow (and create more shallow angle elbows)
1295 if (MathTools.distance(p1, p2) < off*2.05) {
1299 PipeControlPoint tcp1 = insertElbow(dcp, next, p1);
1300 PipeControlPoint tcp2 = insertElbow(tcp1, next, p2);
1303 System.out.println("PipingRules.updateDualDirectedPipeRun() created two turns " + tcp1 + " " + tcp2);
1306 Vector3d dd = new Vector3d(p2);
1309 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1310 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1312 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1314 updatePathLegPrev(tcp2, u.updated, PathLegUpdateType.NONE);
1316 Vector3d dd = new Vector3d(p1);
1319 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1320 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1322 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1324 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.NONE);
1333 private static double spaceForTurn(PipeControlPoint tcp, PipeControlPoint dcp) {
1334 // TODO : if the path legs contain offset, using just positions of opposite path leg ends is not enough.
1335 // TODO : current iterative way for calculating required space may return longer length that is required.
1336 double tr = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1338 return tr; // space for 90 deg
1339 PipeControlPoint ne = tcp.findNextEnd();
1340 PipeControlPoint pe = tcp.findPreviousEnd();
1341 PipeControlPoint other = null;
1347 return tr; // space for 90 deg
1349 return tr; // space for 90 deg
1350 Vector3d dir = dcp.getDirectedControlPointDirection();
1353 dir2 = pathLegDirection(tcp);
1355 dir2 = pathLegDirection(pe);
1359 double d = dir.dot(dir2);
1361 return 0.0; // point following turn is directly in the front of the nozzle.
1362 else if (d < -0.9999)
1363 return tr*2.0; // point following turn is directly behind the nozzle, in theory, we should return Double.Inf...
1367 Vector3d tp0 = tcp.getPosition();
1369 Vector3d dp = dcp.getWorldPosition();
1371 Vector3d tp = new Vector3d(dir);
1372 tp.scaleAdd(curr, dp);
1373 tcp._setPosition(tp); // no firing of listeners here
1375 dir2 = pathLegDirection(tcp);
1377 dir2 = pathLegDirection(pe);
1381 double a = dir.angle(dir2);
1383 // other is directly between dcp and tcp, a zero angle turn should do
1384 if (Math.PI - a <= MathTools.NEAR_ZERO)
1387 double R = tr * Math.tan(a * 0.5);
1395 tcp._setPosition(tp0); // return the original value
1400 private static void insertElbowUpdate(UpdateStruct2 u, PipeControlPoint dcp, PipeControlPoint next, boolean dcpStart, Vector3d position, Vector3d directedDirection) throws Exception{
1403 // Vector3d closest = new Vector3d(position);
1404 // closest.add(directedDirection);
1406 PipeControlPoint tcp = null;
1407 Vector3d closest = new Vector3d(directedDirection);
1408 closest.scaleAdd(dcp.getPipeRun().getTurnRadius(), position);
1410 tcp = insertElbow(dcp, next, closest);
1412 tcp = insertElbow(next, dcp, closest);
1415 double s = spaceForTurn(tcp,dcp);
1416 Vector3d p = new Vector3d(directedDirection);
1417 p.scaleAdd(s, position);
1422 System.out.println("PipingRules.updateDirectedPipeRun() inserted " + tcp);
1425 // update pipe run from new turn to other end
1426 ppNoDir(tcp, new Vector3d(closest), u.list, u.end, u.endPoint, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1427 // update pipe run from directed to new turn
1428 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));
1430 // update pipe run from other end to new turn
1431 ppNoDir(u.start, u.startPoint, u.list, tcp, new Vector3d(closest), u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1432 // update pipe run from new turn to directed
1433 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));
1438 * Checks if turns can be removed (turn angle near zero)
1440 private static int checkTurns(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1442 System.out.println("PipingRules.checkTurns() " + u.start + " " + u.end);
1443 boolean startRemoved = false;
1444 boolean endRemoved = false;
1445 if (u.start.isVariableAngle()) {
1446 // this won't work properly if inline control points are not updated
1447 PipeControlPoint startPrev = u.start.getPrevious();
1448 if (startPrev != null) {
1449 double a = updateTurnControlPointTurn(u.start, null, u.dir);
1450 if (a < MIN_TURN_ANGLE && u.start.isDeletable())
1451 startRemoved = true;
1452 else if (lengthChange == PathLegUpdateType.PREV || lengthChange == PathLegUpdateType.PREV_S) {
1453 PathLegUpdateType type;
1454 if (lengthChange == PathLegUpdateType.PREV_S)
1455 type = PathLegUpdateType.PREV;
1457 type = PathLegUpdateType.NONE;
1458 updatePathLegPrev(u.start, u.start, type);
1462 if (u.end.isVariableAngle()) {
1464 PipeControlPoint endNext = u.end.getNext();
1465 if (endNext != null) {
1466 // TODO: u.end, u.dir, null
1467 double a = updateTurnControlPointTurn(u.end, null, null);
1468 if (a < MIN_TURN_ANGLE && u.end.isDeletable())
1470 else if (lengthChange == PathLegUpdateType.NEXT || lengthChange == PathLegUpdateType.NEXT_S) {
1471 PathLegUpdateType type;
1472 if (lengthChange == PathLegUpdateType.NEXT_S)
1473 type = PathLegUpdateType.NEXT;
1475 type = PathLegUpdateType.NONE;
1476 updatePathLegNext(u.end, u.end, type);
1481 System.out.println("PipingRules.checkTurns() res " + startRemoved + " " + endRemoved);
1482 if (!startRemoved && !endRemoved)
1484 if (startRemoved && endRemoved)
1487 return REMOVE_START;
1492 * Expands piperun search over turns that are going to be removed
1495 private static void expandPathLeg(UpdateStruct2 u, int type) throws Exception {
1497 System.out.println("PipingRules.expandPipeline " + u.start + " " + u.end);
1498 ArrayList<PipeControlPoint> newList = new ArrayList<PipeControlPoint>();
1501 throw new RuntimeException("Error in piping rules");
1503 u.toRemove.add(new ExpandIterInfo(u.start, REMOVE_START));
1504 u.start = u.start.findPreviousEnd();
1505 u.startPoint = u.start.getPosition();
1506 u.start.findNextEnd(newList);
1507 newList.addAll(u.list);
1511 u.toRemove.add(new ExpandIterInfo(u.end, REMOVE_END));
1512 u.end = u.end.findNextEnd(newList);
1513 u.endPoint = u.end.getPosition();
1514 u.list.addAll(newList);
1517 u.toRemove.add(new ExpandIterInfo(u.start, u.end));
1518 u.start = u.start.findPreviousEnd();
1519 u.startPoint = u.start.getPosition();
1520 u.start.findNextEnd(newList);
1521 newList.addAll(u.list);
1523 newList = new ArrayList<PipeControlPoint>();
1524 u.end = u.end.findNextEnd(newList);
1525 u.endPoint = u.end.getPosition();
1526 u.list.addAll(newList);
1529 throw new RuntimeException("Error in piping rules");
1532 u.offset = new Vector3d();
1535 for (PipeControlPoint icp : u.list) {
1536 if (icp.isOffset()) {
1537 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1538 } else if (icp.isDualSub())
1539 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1543 System.out.println("PipingRules.expandPipeline expanded " + u.start + " " + u.end);
1545 updatePathLeg(u, PathLegUpdateType.NONE);
1549 * reverts one iteration of turn removing back)
1551 private static void backIter(UpdateStruct2 u) throws Exception {
1554 System.out.println("PipingRules.backIter" + u.start + " " + u.end);
1556 throw new RuntimeException("Error in piping rules");
1557 ExpandIterInfo info = u.toRemove.get(u.toRemove.size() - 1);
1558 u.toRemove.remove(u.toRemove.size() - 1);
1559 if (info.getType() == REMOVE_START || info.getType() == REMOVE_BOTH) {
1560 while (u.list.size() > 0) {
1561 PipeControlPoint icp = u.list.get(0);
1562 if (icp.getPrevious().equals(info.getStart()))
1566 u.start = info.getStart();
1568 if (info.getType() == REMOVE_END || info.getType() == REMOVE_BOTH) {
1569 while (u.list.size() > 0) {
1570 PipeControlPoint icp = u.list.get(u.list.size() - 1);
1571 if (icp.getNext().equals(info.getEnd()))
1575 u.end = info.getEnd();
1577 u.offset = new Vector3d();
1580 for (PipeControlPoint icp : u.list) {
1581 if (icp.isOffset()) {
1582 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1583 } else if (icp.isDualSub())
1584 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1592 * Processes pipe run (removes necessary turns and updates run ends)
1594 // private static void processPathLeg(PipeControlPoint start, Point3d
1595 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1596 // end,Point3d endPoint, Vector3d dir,Vector3d offset, boolean
1597 // hasOffsets,int iter, boolean reversed, ArrayList<ExpandIterInfo>
1598 // toRemove) throws TransactionException {
1600 private static void processPathLeg(UpdateStruct2 u) throws Exception {
1602 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1603 processPathLeg(u, true, true);
1606 private static void processPathLeg(UpdateStruct2 u, boolean updateEnds, boolean updateInline) throws Exception {
1608 System.out.println("PipingRules.processPathLeg " + (updateEnds ? "ends " : "") + (updateInline ? "inline " : "") + u.start + " " + u.end);
1610 if (u.toRemove.size() > 0) {
1611 for (ExpandIterInfo info : u.toRemove) {
1612 if (info.getStart() != null) {
1614 System.out.println("PipingRules.processPathLeg removing start " + info.getStart());
1615 info.getStart()._remove();
1617 if (info.getEnd() != null) {
1619 System.out.println("PipingRules.processPathLeg removing end " + info.getEnd());
1620 info.getEnd()._remove();
1623 // ControlPointTools.removeControlPoint may remove more than one CP;
1624 // we must populate inline CP list again.
1626 u.start.findNextEnd( u.list);
1628 // FIXME : inline CPs are update twice because their positions must be
1629 // updated before and after ends.
1630 updateInlineControlPoints(u, false);
1633 if (u.start.isTurn()) {
1634 //updateTurnControlPointTurn(u.start, u.start.getPrevious(), u.start.getNext());
1635 updateTurnControlPointTurn(u.start, null, null);
1636 // updatePathLegPrev(u.start, u.start, PathLegUpdateType.NONE);
1637 } else if (u.start.isEnd()) {
1638 updateEndComponentControlPoint(u.start, u.dir);
1639 } else if (u.start.isInline()) {
1640 updateControlPointOrientation(u.start, u.dir);
1642 if (u.end.isTurn()) {
1643 //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext());
1644 updateTurnControlPointTurn(u.end, null, null);
1645 // updatePathLegNext(u.end, u.end, PathLegUpdateType.NONE);
1646 } else if (u.end.isEnd()) {
1647 updateEndComponentControlPoint(u.end, u.dir);
1648 } else if (u.end.isInline()) {
1649 updateControlPointOrientation(u.end, u.dir);
1653 if (u.start.isEnd()) {
1654 updateEndComponentControlPoint(u.start, u.dir);
1656 if (u.end.isEnd()) {
1657 updateEndComponentControlPoint(u.end, u.dir);
1661 updateInlineControlPoints(u, true);
1666 * Processes pipe run and recalculates offset
1668 // private static void processPathLeg(PipeControlPoint start, Point3d
1669 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1670 // end,Point3d endPoint, Vector3d dir, boolean hasOffsets,int iter, boolean
1671 // reversed, ArrayList<ExpandIterInfo> toRemove) throws TransactionException
1673 @SuppressWarnings("unused")
1674 private static void processPathLegNoOffset(UpdateStruct2 u) throws Exception {
1676 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1677 Vector3d offset = new Vector3d();
1680 for (PipeControlPoint icp : u.list) {
1681 if (icp.isOffset()) {
1682 offset.add(icp.getSizeChangeOffsetVector(u.dir));
1683 } else if (icp.isDualSub()) {
1684 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1691 private static void updateOffsetPoint(PipeControlPoint sccp, Vector3d offset) {
1692 Vector3d world = sccp.getWorldPosition();
1694 PipeControlPoint ocp = sccp.getDualSub();
1695 ocp.setWorldPosition(world);
1699 * Updates InlineControlPoints position when straight pipe's end(s) have
1707 private static void updateInlineControlPoint(PipeControlPoint icp, Vector3d prev, Vector3d next, Vector3d dir) {
1709 System.out.println("PipingRules.updateInlineControlPoint() " + icp);
1711 Vector3d inlinePoint = icp.getWorldPosition();
1712 Vector3d prevPoint = new Vector3d(prev);
1713 Vector3d nextPoint = new Vector3d(next);
1714 if (!icp.isVariableLength()) {
1715 // Reserve space for fixed length components.
1716 MathTools.mad(prevPoint, dir, icp.getInlineLength());
1717 MathTools.mad(nextPoint, dir, -icp.getInlineLength());
1718 if (MathTools.distance(prevPoint, nextPoint) < ALLOWED_OFFSET) {
1723 boolean canCalc = MathTools.distance(prevPoint, nextPoint) > ALLOWED_OFFSET;
1725 System.out.print("InlineControlPoint update " + icp + " " + inlinePoint + " " + prevPoint + " " + nextPoint);
1726 Vector3d newInlinePoint = null;
1728 boolean branchUpdate = false;
1729 PipeControlPoint becp = null;
1730 for (PipeControlPoint pcp : icp.getChildPoints())
1731 if (pcp.isNonDirected()) {
1732 branchUpdate = true;
1737 if (DUMMY || !branchUpdate) {
1738 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1742 // FIXME : can only handle one branch
1743 PipeControlPoint p = null;
1744 if (becp.getNext() != null) {
1745 p = becp.findNextEnd();
1746 } else if (becp.getPrevious() != null) {
1747 p = becp.findPreviousEnd();
1750 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1751 } else if (canCalc){
1752 Vector3d branchLegEnd = p.getWorldPosition();
1753 Vector3d dir2 = new Vector3d(inlinePoint);
1754 dir2.sub(branchLegEnd);
1755 Vector3d dir1 = new Vector3d(nextPoint);
1756 dir1.sub(prevPoint);
1757 newInlinePoint = new Vector3d();
1758 double mu[] = new double[2];
1759 MathTools.intersectStraightStraight(new Vector3d(prevPoint), dir1, new Vector3d(branchLegEnd), dir2, newInlinePoint, new Vector3d(), mu);
1761 System.out.println(mu[0]);
1762 // FIXME : reserve space
1764 newInlinePoint = new Vector3d(prevPoint);
1765 } else if (mu[0] > 1.0) {
1766 newInlinePoint = new Vector3d(nextPoint);
1771 // prevPoint == nextPoint
1772 newInlinePoint = new Vector3d(prevPoint);
1775 System.out.println(" " + newInlinePoint);
1777 icp.setWorldPosition(newInlinePoint);
1778 updateControlPointOrientation(icp, dir);
1782 * Updates InlineControlPoints position when straight pipe's end(s) have
1790 private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d dir) throws Exception {
1792 System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
1794 if (!ecp.isFixed()) // prevent overriding nozzle orientations..
1795 updateControlPointOrientation(ecp, dir);
1797 for (PipeControlPoint pcp : ecp.getChildPoints()) {
1798 // TODO update position
1799 updatePathLegEndControlPoint(pcp);
1803 private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) {
1804 Double angleO = pcp.getRotationAngle();
1808 boolean reversed = pcp._getReversed();
1811 q = pcp.getControlPointOrientationQuat(dir, angle, reversed);
1813 q = pcp.getControlPointOrientationQuat(angle, reversed);
1815 pcp.setWorldOrientation(q);
1819 * Updates all branches when branch's position has been changed
1823 private static void updateBranchControlPointBranches(PipeControlPoint bcp) throws Exception {
1825 System.out.println("PipingRules.updateBranchControlPointBranches() " + bcp);
1826 if (bcp.isDualInline())
1828 Collection<PipeControlPoint> branches = bcp.getChildPoints();
1829 if (branches.size() == 0) {
1831 System.out.println("No Branches found");
1835 for (PipeControlPoint pcp : branches) {
1836 updatePathLegEndControlPoint(pcp);
1840 private static double updateTurnControlPointTurn(PipeControlPoint tcp, Vector3d prev, Vector3d next) {
1842 UpdateStruct2 us = createUS(tcp, Direction.NEXT, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1847 UpdateStruct2 us = createUS(tcp, Direction.PREVIOUS, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1853 if (!tcp.asFixedAngle()) {
1856 if (next == null || prev == null) {
1857 if (tcp.getTurnAngle() != null)
1858 return tcp.getTurnAngle();
1859 return Math.PI; // FIXME : argh
1862 final boolean isDegenerate = prev.lengthSquared() < MathTools.NEAR_ZERO || next.lengthSquared() < MathTools.NEAR_ZERO;
1863 double turnAngle = isDegenerate ? 0.0 : prev.angle(next);
1865 Vector3d turnAxis = new Vector3d();
1866 turnAxis.cross(prev, next);
1867 if (turnAxis.lengthSquared() > MathTools.NEAR_ZERO) {
1868 double elbowRadius = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1869 double R = elbowRadius * Math.tan(turnAngle * 0.5);
1871 turnAxis.normalize();
1872 tcp.setTurnAngle(turnAngle);
1873 tcp.setLength(R);// setComponentOffsetValue(R);
1874 tcp.setTurnAxis(turnAxis);
1875 // tcp.setPosition(tcp.getPosition());
1878 tcp.setTurnAngle(0.0);
1880 tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
1883 updateControlPointOrientation(tcp,prev);
1886 System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
1890 if (prev != null && next != null) {
1892 } else if (prev == null) {
1893 if (!tcp._getReversed())
1894 tcp.setReversed(true);
1895 } else if (next == null) {
1896 if (tcp._getReversed())
1897 tcp.setReversed(false);
1900 Vector3d dir = null;
1901 if (!tcp._getReversed()) {
1908 return Math.PI; // FIXME : argh
1911 Quat4d q = tcp.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
1912 Vector3d v = new Vector3d();
1913 MathTools.rotate(q, MathTools.Y_AXIS,v);
1915 tcp.setWorldOrientation(q);
1916 if (tcp.getTurnAngle() != null)
1917 return tcp.getTurnAngle();
1918 return Math.PI; // FIXME : argh
1924 public static List<PipeControlPoint> getControlPoints(PipeRun pipeRun) {
1925 List<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
1926 if (pipeRun.getControlPoints().size() == 0)
1928 PipeControlPoint pcp = pipeRun.getControlPoints().iterator().next();
1929 while (pcp.getPrevious() != null) {
1930 PipeControlPoint prev = pcp.getPrevious();
1931 if (prev.getPipeRun() != pipeRun && prev.getPipeRun() != null) { // bypass possible corruption
1936 if (pcp.isDualSub()) {
1937 pcp = pcp.getParentPoint();
1940 while (pcp.getNext() != null) {
1941 pcp = pcp.getNext();
1942 if (pcp.getPipeRun() != pipeRun)
1949 public static void reverse(PipeRun pipeRun) {
1952 List<PipeControlPoint> points = getControlPoints(pipeRun);
1953 PipeControlPoint pcp = points.get(0);
1954 if (pcp.isSizeChange() && pcp.getChildPoints().size() > 0) {
1955 PipeRun pr = pcp.getPipeRun();
1963 List<PipeRun> all = new ArrayList<PipeRun>();
1964 List<List<PipeControlPoint>> pcps = new ArrayList<List<PipeControlPoint>>();
1967 List<PipeControlPoint> points = getControlPoints(pipeRun);
1969 PipeControlPoint pcp = points.get(points.size()-1);
1970 if (pcp.getChildPoints().size() > 0) {
1971 PipeRun pipeRun2 = pcp.getChildPoints().get(0).getPipeRun();
1972 if (pipeRun == pipeRun2)
1980 for (int i = 0 ; i < all.size(); i++) {
1981 List<PipeControlPoint> list = pcps.get(i);
1984 for (int i = 0 ; i < all.size(); i++) {
1985 boolean last = i == all.size() - 1;
1986 List<PipeControlPoint> list = pcps.get(i);
1989 List<PipeControlPoint> list2 = pcps.get(i+1);
1990 PipeControlPoint prev = list.get(list.size()-1);
1991 PipeControlPoint next = list2.get(0);
1993 // Reverse the component on the boundary.
1994 InlineComponent ic = (InlineComponent)prev.getPipelineComponent();
1995 PipeRun r1 = ic.getPipeRun();
1996 PipeRun r2 = ic.getAlternativePipeRun();
1997 if (r1 == null || r2 == null)
1998 throw new RuntimeException("Components on PipeRun changes should refer to bot PipeRuns");
2002 ic.setAlternativePipeRun(r1);
2004 throw new RuntimeException("PipeRun changes should contain shared control points");
2012 private static void _reverse(List<PipeControlPoint> list) {
2013 if (list.size() <= 1)
2014 return; // nothing to do.
2016 for (int i = 0 ; i < list.size(); i++) {
2017 boolean first = i == 0;
2018 boolean last = i == list.size() - 1;
2019 PipeControlPoint current = list.get(i);
2020 PipeControlPoint currentSub = null;
2021 if (current.isDualInline())
2022 currentSub = current.getDualSub();
2024 PipeControlPoint next = list.get(i+1);
2025 if (next.isDualInline())
2026 next = next.getDualSub();
2027 if (current.getNext() == next)
2028 current.setNext(null);
2029 current.setPrevious(next);
2030 if (currentSub != null) {
2031 if (currentSub.getNext() == next)
2032 currentSub.setNext(null);
2033 currentSub.setPrevious(next);
2036 PipeControlPoint prev = list.get(i-1);
2038 if (current.getPrevious() == prev)
2039 current.setPrevious(null);
2040 current.setNext(prev);
2042 if (currentSub != null) {
2043 if (currentSub.getPrevious() == prev)
2044 currentSub.setPrevious(null);
2045 currentSub.setNext(prev);
2048 PipeControlPoint prev = list.get(i-1);
2049 PipeControlPoint next = list.get(i+1);
2050 if (next.isDualInline())
2051 next = next.getDualSub();
2054 current.setPrevious(next);
2055 current.setNext(prev);
2057 if (currentSub != null) {
2058 currentSub.setPrevious(next);
2059 currentSub.setNext(prev);
2063 //if (current.isTurn() && current.isFixed()) {
2064 if (current.asFixedAngle()) {
2065 current.setReversed(!current._getReversed());
2067 if (current.isInline() && current.isReverse()) {
2068 current.setReversed(!current._getReversed());
2075 public static void validate(PipeRun pipeRun) {
2076 if (pipeRun == null)
2078 Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
2080 //System.out.println("Validate " + pipeRun.getName());
2081 for (PipeControlPoint pcp : pcps) {
2082 if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
2085 List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
2086 if (runPcps.size() != count) {
2087 System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
2088 for (PipeControlPoint pcp : pcps) {
2089 if (!runPcps.contains(pcp)) {
2090 System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
2094 for (PipeControlPoint pcp : pcps) {
2095 if (pcp.getPipeRun() == null) {
2096 System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
2098 if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
2099 System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
2101 for (PipeControlPoint pcp : pcps) {
2102 if (pcp.getParentPoint() == null) {
2103 PipeControlPoint sub = null;
2104 if (pcp.isDualInline())
2105 sub = pcp.getDualSub();
2106 PipeControlPoint next = pcp.getNext();
2107 PipeControlPoint prev = pcp.getPrevious();
2109 if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
2110 System.out.println("Inconsistency between " + pcp + " -> " +next );
2114 PipeControlPoint prevParent = null;
2115 if (prev.isDualSub()) {
2116 prevParent = prev.getParentPoint();
2117 } else if (prev.isDualInline()) {
2118 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2120 if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
2121 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2128 public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{
2129 assert(!splittingComponent.getControlPoint().isFixedLength());
2130 assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixedLength()));
2131 PipeControlPoint newCP = newComponent.getControlPoint();
2132 PipeControlPoint splittingCP = splittingComponent.getControlPoint();
2133 PipeControlPoint nextCP = splittingCP.getNext();
2134 PipeControlPoint prevCP = splittingCP.getPrevious();
2136 /* there are many different cases to insert new component when
2137 it splits existing VariableLengthinlineComponent.
2139 1. VariableLengthComponet is connected from both sides:
2140 - insert new component between VariableLength component and component connected to it
2141 - insert new VariableLengthComponent between inserted component and component selected in previous step
2143 2. VariableLengthComponent is connected from one side
2144 - Use previous case or:
2145 - Insert new component to empty end
2146 - Insert new VariableLength component to inserted components empty end
2148 3. VariableLength is not connected to any component.
2149 - Should not be possible, at least in current implementation.
2150 - Could be done using second case
2154 if (nextCP == null && prevCP == null) {
2155 // this should not be possible
2156 throw new RuntimeException("VariableLengthComponent " + splittingComponent + " is not connected to anything.");
2158 double newLength = newComponent.getControlPoint().getLength();
2161 Point3d next = new Point3d();
2162 Point3d prev = new Point3d();
2163 splittingCP.getInlineControlPointEnds(prev, next);
2165 Vector3d newPos = null;
2167 newPos = new Vector3d(prev);
2168 Vector3d dir = new Vector3d(next);
2172 newComponent.setWorldPosition(newPos);
2174 newPos = newComponent.getWorldPosition();
2179 Vector3d dir = new Vector3d(next);
2182 dir.scale(newLength * 0.5);
2183 Point3d vn = new Point3d(newPos);
2184 Point3d vp = new Point3d(newPos);
2187 double ln = vn.distance(next);
2188 double lp = vp.distance(prev);
2189 vp.interpolate(prev, 0.5);
2190 vn.interpolate(next, 0.5);
2193 if (nextCP == null) {
2194 newCP.insert(splittingCP, Direction.NEXT);
2195 insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
2196 splittingCP.setWorldPosition(new Vector3d(vp));
2197 // ControlPointTools.setWorldPosition(splittingCP, vp);
2198 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2199 } else if (prevCP == null) {
2200 newCP.insert(splittingCP, Direction.PREVIOUS);
2201 insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
2202 splittingCP.setWorldPosition(new Vector3d(vn));
2203 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, ln);
2205 newCP.insert(splittingCP, nextCP);
2206 insertStraight(newCP, nextCP, new Vector3d(vn), ln);
2207 splittingCP.setWorldPosition(new Vector3d(vp));
2208 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2210 positionUpdate(newCP);
2214 public static void addSizeChange(boolean reversed, PipeRun pipeRun, PipeRun other, InlineComponent reducer, PipeControlPoint previous, PipeControlPoint next) {
2215 PipeControlPoint pcp = reducer.getControlPoint();
2216 PipeControlPoint ocp = pcp.getDualSub();
2218 String name = pipeRun.getUniqueName("Reducer");
2219 reducer.setName(name);
2220 pipeRun.addChild(reducer);
2221 other.addChild(ocp);
2222 reducer.setAlternativePipeRun(other);
2224 previous.setNext(pcp);
2225 pcp.setPrevious(previous);
2226 ocp.setPrevious(previous);
2230 next.setPrevious(ocp);
2233 String name = other.getUniqueName("Reducer");
2234 reducer.setName(name);
2235 other.addChild(reducer);
2236 pipeRun.addChild(ocp);
2237 reducer.setAlternativePipeRun(pipeRun);
2241 pcp.setPrevious(next);
2242 ocp.setPrevious(next);
2244 pcp.setNext(previous);
2245 ocp.setNext(previous);
2246 previous.setPrevious(ocp);