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 || iter <= 0) {
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 Vector3d pathLegDirection(PipeControlPoint start) {
481 ArrayList<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
482 PipeControlPoint end = start.findNextEnd(list);
484 return start.getDirection(Direction.NEXT);
487 Vector3d offset = new Vector3d();
488 Vector3d startPoint = start.getWorldPosition();
489 Vector3d endPoint = end.getWorldPosition();
490 Vector3d dir = new Vector3d();
491 calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
495 private static boolean asDirected(PipeControlPoint pcp, Direction direction) {
496 if (pcp.isDirected())
498 if (pcp.asFixedAngle()) {
499 if (!pcp._getReversed())
500 return direction == Direction.NEXT;
502 return direction == Direction.PREVIOUS;
507 private static Vector3d direction(PipeControlPoint pcp, Direction direction) {
508 return pcp.getDirection(direction);
511 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
514 if (lengthChange == PathLegUpdateType.NONE) {
518 updatePathLeg(u, lengthChange, rs, re);
521 private static void updatePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean rs, boolean re) throws Exception {
523 if (asDirected(u.start, Direction.NEXT))
525 if (asDirected(u.end, Direction.PREVIOUS))
528 setErrorForce(u.start, null);
530 setErrorForce(u.end, null);
531 for (PipeControlPoint pcp : u.list)
532 setErrorForce(pcp, null);
535 updateFreePathLeg(u, lengthChange);
538 updateDirectedPathLeg(u, lengthChange);
541 updateDualDirectedPathLeg(u, lengthChange);
547 private static void updateFreePathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
549 System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange);
550 checkExpandPathLeg(u, lengthChange);
551 if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle())
552 processPathLeg(u, true, false);
555 private static void updateInlineControlPoints(UpdateStruct2 u, boolean checkSizes) throws Exception{
557 System.out.println("PipingRules.updateInlineControlPoints() " + u);
559 Vector3d start = new Vector3d(u.startPoint);
560 Vector3d end = new Vector3d(u.endPoint);
563 // create offsets for leg ends.
564 if (u.start.isTurn())
565 MathTools.mad(start, u.dir, u.start.getInlineLength());
567 MathTools.mad(end, u.dir, -u.end.getInlineLength());
570 boolean recalcline = false;
572 Vector3d sp = new Vector3d(start);
573 Vector3d ep = new Vector3d(end);
576 if (u.start.isOffset()) {
577 Vector3d offset = u.start.getSizeChangeOffsetVector(u.dir);
578 updateOffsetPoint(u.start, offset);
583 for (PipeControlPoint icp : u.list) {
584 updateInlineControlPoint(icp, sp, ep, u.dir);
585 if (icp.isOffset()) {
586 // TODO : offset vector is already calculated and should be cached
587 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
588 updateOffsetPoint(icp, offset);
597 // Collect all path leg points for updating variable length components. This list will also contain leg ends (usually turns)
598 ArrayList<PipeControlPoint> pathLegPoints = new ArrayList<>();
599 // Collect all fixed length components with their offsets.
600 ArrayList<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints = new ArrayList<>();
602 pathLegPoints.add(u.start);
603 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.start, new Vector3d()));
604 Vector3d off = new Vector3d();
605 for (PipeControlPoint icp : u.list) {
606 pathLegPoints.add(icp);
607 updateBranchControlPointBranches(icp);
608 if (icp.isOffset()) {
609 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
610 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
612 } else if (!icp.isVariableLength()) {
613 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(icp, new Vector3d(off)));
616 pathLegPoints.add(u.end);
617 fixedLengthPoints.add(new Pair<PipeControlPoint, Vector3d>(u.end, new Vector3d(off)));
619 sp = new Vector3d(start);
620 ep = new Vector3d(end);
623 updateFixedLengths(fixedLengthPoints, sp, ep, u.dir);
625 for (int i = 0; i < pathLegPoints.size(); i++) {
626 PipeControlPoint icp = pathLegPoints.get(i);
628 PipeControlPoint prev = i > 0 ? pathLegPoints.get(i - 1) : null;
629 PipeControlPoint next = i < pathLegPoints.size() - 1 ? pathLegPoints.get(i + 1) : null;
631 if (prev != null && prev.isDualInline())
632 prev = prev.getDualSub();
634 if (icp.isVariableLength()) {
635 if (prev != null && next != null) {
636 recalcline = recalcline | updateVariableLength(icp, prev, next);
639 // this is variable length component at the end of the piperun.
640 // the problem is that we want to keep unconnected end of the component in the same
641 // place, but center of the component must be moved.
642 updateVariableLengthEnd(icp, prev != null ? prev : next);
644 } else if (prev != null && !prev.isVariableLength()) {
645 // If this and previous control point are not variable length pcps,
646 // we'll have to check if there is no empty space between them.
647 // I there is, we'll have to create new variable length component between them.
648 recalcline = recalcline | possibleVaribleLengthInsert(icp, prev);
650 if (icp.isOffset()) {
651 // TODO : offset vector is already calculated and should be cached
652 Vector3d offset = icp.getSizeChangeOffsetVector(u.dir);
660 u.start.findNextEnd(u.list);
663 sp = new Vector3d(u.startPoint);
664 ep = new Vector3d(u.endPoint);
666 double pathLegLength = MathTools.distance(sp, ep);
667 double availableLength = pathLegLength;
668 if (u.start.isTurn())
669 availableLength -= u.start.getInlineLength();
671 availableLength -= u.end.getInlineLength();
672 for (PipeControlPoint pcp : u.list) {
673 if (!pcp.isVariableLength())
674 availableLength-= pcp.getLength();
676 if (availableLength < 0.0) {
677 setError(u.start, "Not enough available space");
678 setError(u.end, "Not enough available space");
679 for (PipeControlPoint pcp : u.list)
680 setError(pcp, "Not enough available space");
682 // System.out.println(u.start.getPipelineComponent().toString() + " " + pathLegLength + " " + availableLength + " " + u.end.getPipelineComponent().toString() + " " + u.start.getInlineLength() + " " + u.end.getInlineLength());
686 private enum Gap{ATTACHED,OVERLAP,SPACE};
688 private static class GapObj {
692 Pair<PipeControlPoint,Vector3d> pcp1;
693 Pair<PipeControlPoint,Vector3d> pcp2;
696 private static void updateFixedLengths(List<Pair<PipeControlPoint,Vector3d>> fixedLengthPoints, Vector3d s, Vector3d e, Vector3d dir) {
697 double totalLength = MathTools.distance(s, e);
698 double reservedLength = 0.0;
699 List<Double> distances = new ArrayList<>(fixedLengthPoints.size());
701 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
702 Pair<PipeControlPoint,Vector3d> pcp = fixedLengthPoints.get(i);
703 reservedLength += pcp.first.getLength();
704 Vector3d p = pcp.first.getWorldPosition();
706 double d= MathTools.distance(s, p);
709 distances.add(totalLength);
711 if (totalLength >= reservedLength) {
712 // There is enough space for all fixed length components.
713 List<GapObj> gaps = new ArrayList<>(fixedLengthPoints.size()-1);
715 // Analyze gaps between components
716 for (int i = 0; i < fixedLengthPoints.size()-1; i++) {
717 Pair<PipeControlPoint,Vector3d> pcp1 = fixedLengthPoints.get(i);
718 Pair<PipeControlPoint,Vector3d> pcp2 = fixedLengthPoints.get(i+1);
719 double d1 = distances.get(i);
720 double d2 = distances.get(i+1);
721 double ld1 = i == 0 ? 0.0 :pcp1.first.getInlineLength();
722 double ld2 = i == fixedLengthPoints.size()-2 ? 0.0 : pcp2.first.getInlineLength();
724 double e1 = d1 + ld1; // End of comp1
725 double s2 = d2 - ld2; // Start of comp2
726 double diff =s2 - e1;
727 GapObj obj = new GapObj();
731 if (diff < -MIN_INLINE_LENGTH) {
732 obj.gap = Gap.OVERLAP;
734 } else if (diff > MIN_INLINE_LENGTH) {
737 obj.gap = Gap.ATTACHED;
741 // If there are no overlaps, there is nothing to do.
744 // Get rid of overlapping components by using closest available free spaces.
745 for (int i = 0; i < gaps.size(); i++) {
746 GapObj gapObj = gaps.get(i);
747 if (gapObj.gap != Gap.OVERLAP)
749 double curr = gapObj.d;
751 while (curr < -MIN_INLINE_LENGTH) {
752 GapObj next = i+d >= 0 ? gaps.get(i+d) : null;
753 GapObj prev = i-d >= 0 ? gaps.get(i-d) : null;
754 if (next != null && next.gap == Gap.SPACE) {
755 double move = Math.min(-curr, next.d);
758 if (next.d < MIN_INLINE_LENGTH)
759 next.gap = Gap.ATTACHED;
760 Vector3d mv = new Vector3d(dir);
763 for (int j = i ; j < i+d; j++) {
764 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp2;
765 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
767 pcp.first.setWorldPosition(p);
770 if (curr < -MIN_INLINE_LENGTH && prev != null && prev.gap == Gap.SPACE) {
771 double move = Math.min(-curr, prev.d);
774 if (next.d < MIN_INLINE_LENGTH)
775 next.gap = Gap.ATTACHED;
776 Vector3d mv = new Vector3d(dir);
779 for (int j = i ; j > i-d; j--) {
780 Pair<PipeControlPoint,Vector3d> pcp = gaps.get(j).pcp1;
781 Vector3d p = new Vector3d(pcp.first.getWorldPosition());
783 pcp.first.setWorldPosition(p);
789 for (int i = 1; i < fixedLengthPoints.size()-1; i++) {
790 Pair<PipeControlPoint,Vector3d> prev = i == 0 ? null : fixedLengthPoints.get(i-1);
791 Pair<PipeControlPoint,Vector3d> curr = fixedLengthPoints.get(i);
792 Pair<PipeControlPoint,Vector3d> next = i == fixedLengthPoints.size() -1 ? null : fixedLengthPoints.get(i+1);
793 updateFixedLength(curr, prev, next, s,e, dir);
798 private static void updateFixedLength(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> prev, Pair<PipeControlPoint,Vector3d> next, Vector3d s, Vector3d e, Vector3d dir) {
800 checkOverlap(prev, icp, dir,true);
803 checkOverlap(icp, next, dir,true);
806 private static boolean checkOverlap(Pair<PipeControlPoint,Vector3d> icp, Pair<PipeControlPoint,Vector3d> icp2, Vector3d dir, boolean se) {
807 Vector3d p1 = icp.first.getWorldPosition();
808 Vector3d p2 = icp2.first.getWorldPosition();
811 double u[] = new double[1];
812 MathTools.closestPointOnStraight(p2, p1, dir, u);
817 MathTools.mad(p2, dir, MIN_INLINE_LENGTH);
818 icp2.first.setWorldPosition(p2);
820 double d = MathTools.distance(p1, p2);
821 double r = icp.first.getInlineLength() + icp2.first.getInlineLength();
823 if ((d-r) < - MIN_INLINE_LENGTH) {
825 setError(icp.first, "Overlapping");
826 setError(icp2.first, "Overlapping");
834 * Overrides current error of a component
838 private static void setErrorForce(PipeControlPoint pcp, String error) {
839 PipelineComponent comp = pcp.getPipelineComponent();
842 comp.setError(error);
846 * Sets error for a component, if there is no existing error.
850 private static void setError(PipeControlPoint pcp, String error) {
851 PipelineComponent comp = pcp.getPipelineComponent();
854 if (comp.getError() != null)
856 comp.setError(error);
859 private static boolean updateVariableLength(PipeControlPoint icp, PipeControlPoint prev, PipeControlPoint next) {
860 Vector3d prevPos = prev.getWorldPosition();
861 Vector3d nextPos = next.getWorldPosition();
863 Vector3d dir = new Vector3d(nextPos);
865 double l = dir.length(); // distance between control points
866 double l2prev = prev.getInlineLength(); // distance taken by components
867 double l2next = next.getInlineLength();
868 double l2 = l2prev + l2next;
869 double length = l - l2; // true length of the variable length component
870 if (length >= MIN_INLINE_LENGTH) { // check if there is enough space for variable length component.
873 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
875 icp.setWorldPosition(dir);
876 icp.setLength(length);
879 // components leave no space to the component and it must be removed
880 if (icp.isDeletable()) {
881 if (!allowInsertRemove) {
882 icp.setLength(MIN_INLINE_LENGTH);
883 setError(icp, "Not enough available space");
888 System.out.println("PipingRules.updateVariableLength removing " + icp);
892 icp.setLength(MIN_INLINE_LENGTH);
893 icp.getPipelineComponent().setError("Not enough available space");
899 private static boolean possibleVaribleLengthInsert(PipeControlPoint icp, PipeControlPoint prev) throws Exception{
900 Vector3d currentPos = icp.getWorldPosition();
901 Vector3d prevPos = prev.getWorldPosition();
902 Vector3d dir = new Vector3d(currentPos);
904 double l = dir.lengthSquared();
905 double l2prev = prev.getInlineLength();
906 double l2next = icp.getInlineLength();
907 double l2 = l2prev + l2next;
908 double l2s = l2 * l2;
909 double diff = l - l2s;
910 if (diff >= MIN_INLINE_LENGTH) {
911 if (allowInsertRemove) {
913 double length = Math.sqrt(l) - l2; // true length of the variable length component
914 dir.scale(length * 0.5 + l2prev); // calculate center position of the component
916 insertStraight(prev, icp, dir, length);
925 private static void updateVariableLengthEnd(PipeControlPoint icp, PipeControlPoint prev) {
926 Vector3d currentPos = icp.getWorldPosition();
927 Vector3d prevPos = prev.getWorldPosition();
929 Vector3d dir = new Vector3d();
930 dir.sub(currentPos, prevPos);
933 synchronized (ruleMutex) {
934 simple = currentUpdates.contains(icp);
938 // Update based on position -> adjust length
939 double currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
940 icp.setLength(currentLength);
942 // Update based on neighbour movement -> adjust length and position, so that free end stays in place.
943 double currentLength = icp.getLength();
944 if (currentLength < MathTools.NEAR_ZERO) {
945 currentLength = (dir.length() - prev.getInlineLength()) * 2.0;
948 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
950 Point3d endPos = new Point3d(dir);
951 endPos.scale(currentLength * 0.5);
952 endPos.add(currentPos); // this is the free end of the component
954 double offset = prev.getInlineLength();
955 Point3d beginPos = new Point3d(dir);
956 beginPos.scale(offset);
957 beginPos.add(prevPos); // this is the connected end of the component
959 double l = beginPos.distance(endPos);
962 System.out.println("Length for " + icp + " is NaN");
965 beginPos.add(dir); // center position
968 System.out.println("PipingRules.updateInlineControlPoints() setting variable length to " + l);
971 icp.setWorldPosition(new Vector3d(beginPos));
976 * Recalculates offset vector based on current direction, and calls checkExpandPathLeg
981 private static void ppNoOffset(UpdateStruct2 u, boolean updateEnds) throws Exception {
983 System.out.println("PipingRules.ppNoOffset() " + u);
984 Vector3d offset = new Vector3d();
986 for (PipeControlPoint icp : u.list) {
987 if (icp.isOffset()) {
988 offset.add(icp.getSizeChangeOffsetVector(u.dir));
989 } else if (icp.isDualSub())
990 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
994 checkExpandPathLeg(u, PathLegUpdateType.NONE, updateEnds);
997 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 {
999 System.out.println("PipingRules.ppNoDir() " + start + " " + end + " " + iter + " " + toRemove.size());
1000 // FIXME : extra loop (dir should be calculated here)
1001 Vector3d dir = new Vector3d();
1002 Vector3d offset = new Vector3d();
1003 hasOffsets = calculateOffset(startPoint, endPoint, start, list, end, dir, offset);
1004 ppNoOffset(new UpdateStruct2(start, startPoint, list, end, endPoint, dir, null, hasOffsets, iter, reversed, toRemove, updated),true);
1007 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1008 checkExpandPathLeg(u, lengthChange, u.updated.isInline() && u.updated.isOffset());
1011 private static void checkExpandPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange, boolean updateEnds) throws Exception {
1013 System.out.println("PipingRules.checkExpandPathLeg() " + u + " " + lengthChange);
1014 if (lengthChange != PathLegUpdateType.NONE) {
1015 // FIXME : turns cannot be checked before inline cps are updated,
1016 // since their position affects calculation of turns
1017 processPathLeg(u, updateEnds, false);
1018 int type = checkTurns(u, lengthChange);
1019 if (type == REMOVE_NONE) {
1020 processPathLeg(u, updateEnds, true);
1022 expandPathLeg(u, type);
1025 processPathLeg(u, updateEnds, true);
1029 private static void updateDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1031 System.out.println("PipingRules.updateDirectedPipeRun() " + u + " " + lengthChange);
1032 PipeControlPoint dcp;
1033 PipeControlPoint other;
1034 boolean canMoveOther = false;
1035 boolean dcpStart = false;
1036 boolean inlineEnd = false;
1038 if (asDirected(u.start, Direction.NEXT)) {
1041 position = u.startPoint;
1044 canMoveOther = true;
1045 inlineEnd = u.end.isInline();
1050 position = u.endPoint;
1052 canMoveOther = true;
1053 inlineEnd = u.start.isInline();
1056 Vector3d directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1057 if (directedDirection == null) {
1058 //updateTurnControlPointTurn(dcp, dcp.getPrevious(), dcp.getNext());
1059 updateTurnControlPointTurn(dcp, null, null);
1060 directedDirection = direction(dcp, dcpStart ? Direction.NEXT : Direction.PREVIOUS);
1061 if (directedDirection == null) {
1066 Point3d otherPosition = new Point3d(dcpStart ? u.endPoint : u.startPoint);
1068 Vector3d dir = new Vector3d(), offset = new Vector3d();
1069 calculateDirectedOffset(u.startPoint, u.endPoint, u.start, u.list, u.end, dir, offset);
1074 otherPosition.add(offset);
1076 otherPosition.sub(offset);
1079 double mu[] = new double[2];
1082 Vector3d t = new Vector3d();
1084 closest = MathTools.closestPointOnStraight(otherPosition, position, directedDirection, mu);
1085 t.sub(closest, otherPosition);
1087 double distance = t.length();
1088 boolean aligned = (distance < ALLOWED_OFFSET);
1089 double requiredSpace = 0.0;
1090 if (other.isVariableAngle()) {
1091 requiredSpace = spaceForTurn(other, dcp);
1093 if (mu[0] < requiredSpace) {
1094 // At the moment, if next component is directly behind the nozzle, we must force moving the other component.
1095 // Trying to solve the situation by adding new turn creates infinite loop...
1097 canMoveOther = true;
1100 //if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle())
1101 // processPathLeg(u, true, false);
1102 checkExpandPathLeg(u, lengthChange, inlineEnd || u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle());
1107 PipeControlPoint nextToMoved;
1109 if (u.list.size() > 0)
1111 nextToMoved = u.list.get(0);
1113 nextToMoved = u.list.get(u.list.size() - 1);
1115 nextToMoved = u.end;
1117 nextToMoved = u.start;
1118 if (other.isVariableAngle()) {
1120 // TODO calculate needed space from next run end.
1121 if (mu[0] < requiredSpace) {
1123 closest.set(u.startPoint);
1125 closest.set(u.endPoint);
1127 Vector3d v = new Vector3d(directedDirection);
1128 v.scale(requiredSpace);
1134 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + closest);
1136 // Not aligned - we need to recalculate the offset to reflect new end points.
1139 offset = new Vector3d();
1140 Vector3d newDir = new Vector3d();
1141 calculateDirectedOffset(position, closest, u.start, u.list, u.end, newDir, offset);
1142 closest.add(offset);
1144 offset = new Vector3d();
1147 other.setWorldPosition(closest);
1150 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);
1151 if (u.end.getNext() != null)
1152 updatePathLegNext(u.end, u.updated, PathLegUpdateType.NEXT);
1154 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);
1155 if (u.start.getPrevious() != null)
1156 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.PREV);
1159 // TODO : calculate needed space from next run end.
1160 if (allowInsertRemove)
1161 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1165 } else if (other.isNonDirected() && other.getParentPoint() != null) {
1166 // FIXME : this code was for updating branches
1167 Vector3d bintersect = new Vector3d();
1168 PipeControlPoint bcp = other.getParentPoint();
1169 if (bcp != null && canMoveOther) {
1170 Point3d bstart = new Point3d();
1171 Point3d bend = new Point3d();
1172 Vector3d bdir = new Vector3d();
1173 bcp.getInlineControlPointEnds(bstart, bend, bdir);
1174 Vector3d nintersect = new Vector3d();
1176 MathTools.intersectStraightStraight(position, directedDirection, bend, bdir, nintersect, bintersect, mu);
1177 Vector3d dist = new Vector3d(nintersect);
1178 dist.sub(bintersect);
1179 canMoveOther = mu[1] > 0.0 && mu[1] < 1.0 && dist.lengthSquared() < 0.01;
1181 // TODO : endControlPoints are undirected: calculcate
1182 // correct position for it
1183 throw new UnsupportedOperationException("not implemented");
1187 System.out.println("PipingRules.updateDirectedPipeRun() moved end " + other + " to " + bintersect);
1188 // is required branch position is in possible range
1189 bcp.setWorldPosition(bintersect);
1191 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);
1193 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);
1196 // branch cannot be moved into right position, new turn
1197 // / elbow must be inserted
1198 if (allowInsertRemove)
1199 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1204 } else { // assume that control point cannot be moved, but can
1206 if (allowInsertRemove)
1207 insertElbowUpdate(u, dcp, nextToMoved, dcpStart, position, directedDirection);
1215 private static void updateDualDirectedPathLeg(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1217 System.out.println("PipingRules.updateDualDirectedPipeRun() " + u + " " + lengthChange);
1219 PipeControlPoint dcp1 = u.start;
1220 PipeControlPoint dcp2 = u.end;
1221 Point3d position1 = new Point3d(u.startPoint);
1222 Point3d position2 = new Point3d(u.endPoint);
1224 Vector3d dir = new Vector3d(), offset = new Vector3d();
1225 calculateDirectedOffset(new Vector3d(position1), new Vector3d(position2), u.start, u.list, u.end, dir, offset);
1227 Point3d position1offset = new Point3d(position1);
1228 position1offset.add(offset);
1229 Point3d position2offset = new Point3d(position2);
1230 position2offset.sub(offset);
1231 Vector3d dir1 = direction(dcp1, Direction.NEXT);
1232 Vector3d dir2 = direction(dcp2, Direction.PREVIOUS);
1234 Vector3d p1 = MathTools.closestPointOnStraight(position1, position2offset, dir2);
1235 Vector3d p2 = MathTools.closestPointOnStraight(position2, position1offset, dir1);
1236 double d1 = position1.distance(new Point3d(p1));
1237 double d2 = position2.distance(new Point3d(p2));
1239 boolean aligned = (d1 < ALLOWED_OFFSET && d2 < ALLOWED_OFFSET);
1245 } else if (allowInsertRemove){
1246 PipeControlPoint dcp;
1247 PipeControlPoint next;
1250 if (u.list.size() > 0)
1251 next = u.list.get(0);
1256 if (u.list.size() > 0)
1257 next = u.list.get(u.list.size() - 1);
1262 p1 = dcp.getWorldPosition();
1263 Vector3d v = new Vector3d();
1269 // Reserve space for 90 deg elbow
1270 double off = dcp1.getPipeRun().getTurnRadius();
1275 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position2offset, dir2);
1277 p2 = MathTools.closestPointOnStraight(new Point3d(p1), position1offset, dir1);
1279 // By default, the elbows are placed next to each other, by using 90 deg angles.
1280 // If the distance between elbows is not enough, we must move the other elbow (and create more shallow angle elbows)
1281 if (MathTools.distance(p1, p2) < off*2.05) {
1285 PipeControlPoint tcp1 = insertElbow(dcp, next, p1);
1286 PipeControlPoint tcp2 = insertElbow(tcp1, next, p2);
1289 System.out.println("PipingRules.updateDualDirectedPipeRun() created two turns " + tcp1 + " " + tcp2);
1292 Vector3d dd = new Vector3d(p2);
1295 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1296 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1298 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1300 updatePathLegPrev(tcp2, u.updated, PathLegUpdateType.NONE);
1302 Vector3d dd = new Vector3d(p1);
1305 updatePathLegNext(tcp1, u.updated, PathLegUpdateType.NONE);
1306 updatePathLegNext(tcp2, u.updated, PathLegUpdateType.NONE);
1308 updatePathLegNext(u.start, u.updated, PathLegUpdateType.NONE);
1310 updatePathLegPrev(u.start, u.updated, PathLegUpdateType.NONE);
1319 private static double spaceForTurn(PipeControlPoint tcp, PipeControlPoint dcp) {
1320 // TODO : if the path legs contain offset, using just positions of opposite path leg ends is not enough.
1321 // TODO : current iterative way for calculating required space may return longer length that is required.
1322 double tr = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1324 return tr; // space for 90 deg
1325 PipeControlPoint ne = tcp.findNextEnd();
1326 PipeControlPoint pe = tcp.findPreviousEnd();
1327 PipeControlPoint other = null;
1333 return tr; // space for 90 deg
1335 return tr; // space for 90 deg
1336 Vector3d dir = dcp.getDirectedControlPointDirection();
1339 dir2 = pathLegDirection(tcp);
1341 dir2 = pathLegDirection(pe);
1345 double d = dir.dot(dir2);
1347 return 0.0; // point following turn is directly in the front of the nozzle.
1348 else if (d < -0.9999)
1349 return tr*2.0; // point following turn is directly behind the nozzle, in theory, we should return Double.Inf...
1351 double curr = tr*0.1;
1353 Vector3d tp0 = tcp.getPosition();
1355 Vector3d dp = dcp.getWorldPosition();
1357 Vector3d tp = new Vector3d(dir);
1358 tp.scaleAdd(curr, dp);
1359 tcp.setPosition(tp);
1361 dir2 = pathLegDirection(tcp);
1363 dir2 = pathLegDirection(pe);
1367 double a = dir.angle(dir2);
1368 double t = Math.tan(a * 0.5);
1370 if (t > MathTools.NEAR_ZERO)
1379 tcp.setPosition(tp0);
1384 private static void insertElbowUpdate(UpdateStruct2 u, PipeControlPoint dcp, PipeControlPoint next, boolean dcpStart, Vector3d position, Vector3d directedDirection) throws Exception{
1387 // Vector3d closest = new Vector3d(position);
1388 // closest.add(directedDirection);
1390 PipeControlPoint tcp = null;
1391 Vector3d closest = new Vector3d(directedDirection);
1392 closest.scaleAdd(dcp.getPipeRun().getTurnRadius(), position);
1394 tcp = insertElbow(dcp, next, closest);
1396 tcp = insertElbow(next, dcp, closest);
1399 double s = spaceForTurn(tcp,dcp);
1400 Vector3d p = new Vector3d(directedDirection);
1401 p.scaleAdd(s, position);
1406 System.out.println("PipingRules.updateDirectedPipeRun() inserted " + tcp);
1409 // update pipe run from new turn to other end
1410 ppNoDir(tcp, new Vector3d(closest), u.list, u.end, u.endPoint, u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1411 // update pipe run from directed to new turn
1412 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));
1414 // update pipe run from other end to new turn
1415 ppNoDir(u.start, u.startPoint, u.list, tcp, new Vector3d(closest), u.hasOffsets, u.iter, u.reversed, u.toRemove, u.updated);
1416 // update pipe run from new turn to directed
1417 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));
1422 * Checks if turns can be removed (turn angle near zero)
1424 private static int checkTurns(UpdateStruct2 u, PathLegUpdateType lengthChange) throws Exception {
1426 System.out.println("PipingRules.checkTurns() " + u.start + " " + u.end);
1427 boolean startRemoved = false;
1428 boolean endRemoved = false;
1429 if (u.start.isVariableAngle()) {
1430 // this won't work properly if inline control points are not updated
1431 PipeControlPoint startPrev = u.start.getPrevious();
1432 if (startPrev != null) {
1433 double a = updateTurnControlPointTurn(u.start, null, u.dir);
1434 if (a < MIN_TURN_ANGLE && u.start.isDeletable())
1435 startRemoved = true;
1436 else if (lengthChange == PathLegUpdateType.PREV || lengthChange == PathLegUpdateType.PREV_S) {
1437 PathLegUpdateType type;
1438 if (lengthChange == PathLegUpdateType.PREV_S)
1439 type = PathLegUpdateType.PREV;
1441 type = PathLegUpdateType.NONE;
1442 updatePathLegPrev(u.start, u.start, type);
1446 if (u.end.isVariableAngle()) {
1448 PipeControlPoint endNext = u.end.getNext();
1449 if (endNext != null) {
1450 // TODO: u.end, u.dir, null
1451 double a = updateTurnControlPointTurn(u.end, null, null);
1452 if (a < MIN_TURN_ANGLE && u.end.isDeletable())
1454 else if (lengthChange == PathLegUpdateType.NEXT || lengthChange == PathLegUpdateType.NEXT_S) {
1455 PathLegUpdateType type;
1456 if (lengthChange == PathLegUpdateType.NEXT_S)
1457 type = PathLegUpdateType.NEXT;
1459 type = PathLegUpdateType.NONE;
1460 updatePathLegNext(u.end, u.end, type);
1465 System.out.println("PipingRules.checkTurns() res " + startRemoved + " " + endRemoved);
1466 if (!startRemoved && !endRemoved)
1468 if (startRemoved && endRemoved)
1471 return REMOVE_START;
1476 * Expands piperun search over turns that are going to be removed
1479 private static void expandPathLeg(UpdateStruct2 u, int type) throws Exception {
1481 System.out.println("PipingRules.expandPipeline " + u.start + " " + u.end);
1482 ArrayList<PipeControlPoint> newList = new ArrayList<PipeControlPoint>();
1485 throw new RuntimeException("Error in piping rules");
1487 u.toRemove.add(new ExpandIterInfo(u.start, REMOVE_START));
1488 u.start = u.start.findPreviousEnd();
1489 u.startPoint = u.start.getPosition();
1490 u.start.findNextEnd(newList);
1491 newList.addAll(u.list);
1495 u.toRemove.add(new ExpandIterInfo(u.end, REMOVE_END));
1496 u.end = u.end.findNextEnd(newList);
1497 u.endPoint = u.end.getPosition();
1498 u.list.addAll(newList);
1501 u.toRemove.add(new ExpandIterInfo(u.start, u.end));
1502 u.start = u.start.findPreviousEnd();
1503 u.startPoint = u.start.getPosition();
1504 u.start.findNextEnd(newList);
1505 newList.addAll(u.list);
1507 newList = new ArrayList<PipeControlPoint>();
1508 u.end = u.end.findNextEnd(newList);
1509 u.endPoint = u.end.getPosition();
1510 u.list.addAll(newList);
1513 throw new RuntimeException("Error in piping rules");
1516 u.offset = new Vector3d();
1519 for (PipeControlPoint icp : u.list) {
1520 if (icp.isOffset()) {
1521 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1522 } else if (icp.isDualSub())
1523 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1527 System.out.println("PipingRules.expandPipeline expanded " + u.start + " " + u.end);
1529 updatePathLeg(u, PathLegUpdateType.NONE);
1533 * reverts one iteration of turn removing back)
1535 private static void backIter(UpdateStruct2 u) throws Exception {
1538 System.out.println("PipingRules.backIter" + u.start + " " + u.end);
1540 throw new RuntimeException("Error in piping rules");
1541 ExpandIterInfo info = u.toRemove.get(u.toRemove.size() - 1);
1542 u.toRemove.remove(u.toRemove.size() - 1);
1543 if (info.getType() == REMOVE_START || info.getType() == REMOVE_BOTH) {
1544 while (u.list.size() > 0) {
1545 PipeControlPoint icp = u.list.get(0);
1546 if (icp.getPrevious().equals(info.getStart()))
1550 u.start = info.getStart();
1552 if (info.getType() == REMOVE_END || info.getType() == REMOVE_BOTH) {
1553 while (u.list.size() > 0) {
1554 PipeControlPoint icp = u.list.get(u.list.size() - 1);
1555 if (icp.getNext().equals(info.getEnd()))
1559 u.end = info.getEnd();
1561 u.offset = new Vector3d();
1564 for (PipeControlPoint icp : u.list) {
1565 if (icp.isOffset()) {
1566 u.offset.add(icp.getSizeChangeOffsetVector(u.dir));
1567 } else if (icp.isDualSub())
1568 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1576 * Processes pipe run (removes necessary turns and updates run ends)
1578 // private static void processPathLeg(PipeControlPoint start, Point3d
1579 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1580 // end,Point3d endPoint, Vector3d dir,Vector3d offset, boolean
1581 // hasOffsets,int iter, boolean reversed, ArrayList<ExpandIterInfo>
1582 // toRemove) throws TransactionException {
1584 private static void processPathLeg(UpdateStruct2 u) throws Exception {
1586 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1587 processPathLeg(u, true, true);
1590 private static void processPathLeg(UpdateStruct2 u, boolean updateEnds, boolean updateInline) throws Exception {
1592 System.out.println("PipingRules.processPathLeg " + (updateEnds ? "ends " : "") + (updateInline ? "inline " : "") + u.start + " " + u.end);
1594 if (u.toRemove.size() > 0) {
1595 for (ExpandIterInfo info : u.toRemove) {
1596 if (info.getStart() != null) {
1598 System.out.println("PipingRules.processPathLeg removing start " + info.getStart());
1599 info.getStart()._remove();
1601 if (info.getEnd() != null) {
1603 System.out.println("PipingRules.processPathLeg removing end " + info.getEnd());
1604 info.getEnd()._remove();
1607 // ControlPointTools.removeControlPoint may remove more than one CP;
1608 // we must populate inline CP list again.
1610 u.start.findNextEnd( u.list);
1612 // FIXME : inline CPs are update twice because their positions must be
1613 // updated before and after ends.
1614 updateInlineControlPoints(u, false);
1617 if (u.start.isTurn()) {
1618 //updateTurnControlPointTurn(u.start, u.start.getPrevious(), u.start.getNext());
1619 updateTurnControlPointTurn(u.start, null, null);
1620 // updatePathLegPrev(u.start, u.start, PathLegUpdateType.NONE);
1621 } else if (u.start.isEnd()) {
1622 updateEndComponentControlPoint(u.start, u.dir);
1623 } else if (u.start.isInline()) {
1624 updateControlPointOrientation(u.start, u.dir);
1626 if (u.end.isTurn()) {
1627 //updateTurnControlPointTurn(u.end, u.end.getPrevious(), u.end.getNext());
1628 updateTurnControlPointTurn(u.end, null, null);
1629 // updatePathLegNext(u.end, u.end, PathLegUpdateType.NONE);
1630 } else if (u.end.isEnd()) {
1631 updateEndComponentControlPoint(u.end, u.dir);
1632 } else if (u.end.isInline()) {
1633 updateControlPointOrientation(u.end, u.dir);
1637 if (u.start.isEnd()) {
1638 updateEndComponentControlPoint(u.start, u.dir);
1640 if (u.end.isEnd()) {
1641 updateEndComponentControlPoint(u.end, u.dir);
1645 updateInlineControlPoints(u, true);
1650 * Processes pipe run and recalculates offset
1652 // private static void processPathLeg(PipeControlPoint start, Point3d
1653 // startPoint,ArrayList<InlineControlPoint> list, PipeControlPoint
1654 // end,Point3d endPoint, Vector3d dir, boolean hasOffsets,int iter, boolean
1655 // reversed, ArrayList<ExpandIterInfo> toRemove) throws TransactionException
1657 @SuppressWarnings("unused")
1658 private static void processPathLegNoOffset(UpdateStruct2 u) throws Exception {
1660 System.out.println("PipingRules.processPathLeg " + u.start + " " + u.end);
1661 Vector3d offset = new Vector3d();
1664 for (PipeControlPoint icp : u.list) {
1665 if (icp.isOffset()) {
1666 offset.add(icp.getSizeChangeOffsetVector(u.dir));
1667 } else if (icp.isDualSub()) {
1668 ErrorLogger.defaultLogError("Updating pipe run, found offset controlpoint " + icp, new Exception("ASSERT!"));
1675 private static void updateOffsetPoint(PipeControlPoint sccp, Vector3d offset) {
1676 Vector3d world = sccp.getWorldPosition();
1678 PipeControlPoint ocp = sccp.getDualSub();
1679 ocp.setWorldPosition(world);
1683 * Updates InlineControlPoints position when straight pipe's end(s) have
1691 private static void updateInlineControlPoint(PipeControlPoint icp, Vector3d prev, Vector3d next, Vector3d dir) {
1693 System.out.println("PipingRules.updateInlineControlPoint() " + icp);
1695 Vector3d inlinePoint = icp.getWorldPosition();
1696 Vector3d prevPoint = new Vector3d(prev);
1697 Vector3d nextPoint = new Vector3d(next);
1698 if (!icp.isVariableLength()) {
1699 // Reserve space for fixed length components.
1700 MathTools.mad(prevPoint, dir, icp.getInlineLength());
1701 MathTools.mad(nextPoint, dir, -icp.getInlineLength());
1702 if (MathTools.distance(prevPoint, nextPoint) < ALLOWED_OFFSET) {
1707 boolean canCalc = MathTools.distance(prevPoint, nextPoint) > ALLOWED_OFFSET;
1709 System.out.print("InlineControlPoint update " + icp + " " + inlinePoint + " " + prevPoint + " " + nextPoint);
1710 Vector3d newInlinePoint = null;
1712 boolean branchUpdate = false;
1713 PipeControlPoint becp = null;
1714 for (PipeControlPoint pcp : icp.getChildPoints())
1715 if (pcp.isNonDirected()) {
1716 branchUpdate = true;
1721 if (DUMMY || !branchUpdate) {
1722 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1726 // FIXME : can only handle one branch
1727 PipeControlPoint p = null;
1728 if (becp.getNext() != null) {
1729 p = becp.findNextEnd();
1730 } else if (becp.getPrevious() != null) {
1731 p = becp.findPreviousEnd();
1734 newInlinePoint = MathTools.closestPointOnEdge(new Vector3d(inlinePoint), prevPoint, nextPoint);
1735 } else if (canCalc){
1736 Vector3d branchLegEnd = p.getWorldPosition();
1737 Vector3d dir2 = new Vector3d(inlinePoint);
1738 dir2.sub(branchLegEnd);
1739 Vector3d dir1 = new Vector3d(nextPoint);
1740 dir1.sub(prevPoint);
1741 newInlinePoint = new Vector3d();
1742 double mu[] = new double[2];
1743 MathTools.intersectStraightStraight(new Vector3d(prevPoint), dir1, new Vector3d(branchLegEnd), dir2, newInlinePoint, new Vector3d(), mu);
1745 System.out.println(mu[0]);
1746 // FIXME : reserve space
1748 newInlinePoint = new Vector3d(prevPoint);
1749 } else if (mu[0] > 1.0) {
1750 newInlinePoint = new Vector3d(nextPoint);
1755 // prevPoint == nextPoint
1756 newInlinePoint = new Vector3d(prevPoint);
1759 System.out.println(" " + newInlinePoint);
1761 icp.setWorldPosition(newInlinePoint);
1762 updateControlPointOrientation(icp, dir);
1766 * Updates InlineControlPoints position when straight pipe's end(s) have
1774 private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d dir) throws Exception {
1776 System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp);
1778 if (!ecp.isFixed()) // prevent overriding nozzle orientations..
1779 updateControlPointOrientation(ecp, dir);
1781 for (PipeControlPoint pcp : ecp.getChildPoints()) {
1782 // TODO update position
1783 updatePathLegEndControlPoint(pcp);
1787 private static void updateControlPointOrientation(PipeControlPoint pcp, Vector3d dir) {
1788 Double angleO = pcp.getRotationAngle();
1792 boolean reversed = pcp._getReversed();
1795 q = pcp.getControlPointOrientationQuat(dir, angle, reversed);
1797 q = pcp.getControlPointOrientationQuat(angle, reversed);
1799 pcp.setWorldOrientation(q);
1803 * Updates all branches when branch's position has been changed
1807 private static void updateBranchControlPointBranches(PipeControlPoint bcp) throws Exception {
1809 System.out.println("PipingRules.updateBranchControlPointBranches() " + bcp);
1810 if (bcp.isDualInline())
1812 Collection<PipeControlPoint> branches = bcp.getChildPoints();
1813 if (branches.size() == 0) {
1815 System.out.println("No Branches found");
1819 for (PipeControlPoint pcp : branches) {
1820 updatePathLegEndControlPoint(pcp);
1824 private static double updateTurnControlPointTurn(PipeControlPoint tcp, Vector3d prev, Vector3d next) {
1826 UpdateStruct2 us = createUS(tcp, Direction.NEXT, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1831 UpdateStruct2 us = createUS(tcp, Direction.PREVIOUS, 0, new ArrayList<PipingRules.ExpandIterInfo>(), tcp);
1837 if (!tcp.asFixedAngle()) {
1840 if (next == null || prev == null) {
1841 if (tcp.getTurnAngle() != null)
1842 return tcp.getTurnAngle();
1843 return Math.PI; // FIXME : argh
1845 double turnAngle = prev.angle(next);
1847 Vector3d turnAxis = new Vector3d();
1848 turnAxis.cross(prev, next);
1849 if (turnAxis.lengthSquared() > MathTools.NEAR_ZERO) {
1850 double elbowRadius = ((TurnComponent)tcp.getPipelineComponent()).getTurnRadius();
1851 double R = elbowRadius * Math.tan(turnAngle * 0.5);
1853 turnAxis.normalize();
1854 tcp.setTurnAngle(turnAngle);
1855 tcp.setLength(R);// setComponentOffsetValue(R);
1856 tcp.setTurnAxis(turnAxis);
1857 // tcp.setPosition(tcp.getPosition());
1860 tcp.setTurnAngle(0.0);
1862 tcp.setTurnAxis(new Vector3d(MathTools.Y_AXIS));
1865 updateControlPointOrientation(tcp,prev);
1868 System.out.println("PipingTools.updateTurnControlPointTurn " + prev + " " + next + " " + turnAngle + " " + turnAxis);
1872 if (prev != null && next != null) {
1874 } else if (prev == null) {
1875 if (!tcp._getReversed())
1876 tcp.setReversed(true);
1877 } else if (next == null) {
1878 if (tcp._getReversed())
1879 tcp.setReversed(false);
1882 Vector3d dir = null;
1883 if (!tcp._getReversed()) {
1890 return Math.PI; // FIXME : argh
1893 Quat4d q = PipeControlPoint.getControlPointOrientationQuat(dir, tcp.getRotationAngle() != null ? tcp.getRotationAngle() : 0.0);
1894 Vector3d v = new Vector3d();
1895 MathTools.rotate(q, MathTools.Y_AXIS,v);
1897 tcp.setWorldOrientation(q);
1898 if (tcp.getTurnAngle() != null)
1899 return tcp.getTurnAngle();
1900 return Math.PI; // FIXME : argh
1906 public static List<PipeControlPoint> getControlPoints(PipeRun pipeRun) {
1907 List<PipeControlPoint> list = new ArrayList<PipeControlPoint>();
1908 if (pipeRun.getControlPoints().size() == 0)
1910 PipeControlPoint pcp = pipeRun.getControlPoints().iterator().next();
1911 while (pcp.getPrevious() != null) {
1912 PipeControlPoint prev = pcp.getPrevious();
1913 if (prev.getPipeRun() != pipeRun && prev.getPipeRun() != null) { // bypass possible corruption
1918 if (pcp.isDualSub()) {
1919 pcp = pcp.getParentPoint();
1922 while (pcp.getNext() != null) {
1923 pcp = pcp.getNext();
1924 if (pcp.getPipeRun() != pipeRun)
1931 public static void reverse(PipeRun pipeRun) {
1934 List<PipeControlPoint> points = getControlPoints(pipeRun);
1935 PipeControlPoint pcp = points.get(0);
1936 if (pcp.isSizeChange() && pcp.getChildPoints().size() > 0) {
1937 PipeRun pr = pcp.getPipeRun();
1945 List<PipeRun> all = new ArrayList<PipeRun>();
1946 List<List<PipeControlPoint>> pcps = new ArrayList<List<PipeControlPoint>>();
1949 List<PipeControlPoint> points = getControlPoints(pipeRun);
1951 PipeControlPoint pcp = points.get(points.size()-1);
1952 if (pcp.getChildPoints().size() > 0) {
1953 PipeRun pipeRun2 = pcp.getChildPoints().get(0).getPipeRun();
1954 if (pipeRun == pipeRun2)
1962 for (int i = 0 ; i < all.size(); i++) {
1963 List<PipeControlPoint> list = pcps.get(i);
1966 for (int i = 0 ; i < all.size(); i++) {
1967 boolean last = i == all.size() - 1;
1968 List<PipeControlPoint> list = pcps.get(i);
1971 List<PipeControlPoint> list2 = pcps.get(i+1);
1972 PipeControlPoint prev = list.get(list.size()-1);
1973 PipeControlPoint next = list2.get(0);
1975 // Reverse the component on the boundary.
1976 InlineComponent ic = (InlineComponent)prev.getPipelineComponent();
1977 PipeRun r1 = ic.getPipeRun();
1978 PipeRun r2 = ic.getAlternativePipeRun();
1979 if (r1 == null || r2 == null)
1980 throw new RuntimeException("Components on PipeRun changes should refer to bot PipeRuns");
1984 ic.setAlternativePipeRun(r1);
1986 throw new RuntimeException("PipeRun changes should contain shared control points");
1994 private static void _reverse(List<PipeControlPoint> list) {
1995 if (list.size() <= 1)
1996 return; // nothing to do.
1998 for (int i = 0 ; i < list.size(); i++) {
1999 boolean first = i == 0;
2000 boolean last = i == list.size() - 1;
2001 PipeControlPoint current = list.get(i);
2002 PipeControlPoint currentSub = null;
2003 if (current.isDualInline())
2004 currentSub = current.getDualSub();
2006 PipeControlPoint next = list.get(i+1);
2007 if (next.isDualInline())
2008 next = next.getDualSub();
2009 if (current.getNext() == next)
2010 current.setNext(null);
2011 current.setPrevious(next);
2012 if (currentSub != null) {
2013 if (currentSub.getNext() == next)
2014 currentSub.setNext(null);
2015 currentSub.setPrevious(next);
2018 PipeControlPoint prev = list.get(i-1);
2020 if (current.getPrevious() == prev)
2021 current.setPrevious(null);
2022 current.setNext(prev);
2024 if (currentSub != null) {
2025 if (currentSub.getPrevious() == prev)
2026 currentSub.setPrevious(null);
2027 currentSub.setNext(prev);
2030 PipeControlPoint prev = list.get(i-1);
2031 PipeControlPoint next = list.get(i+1);
2032 if (next.isDualInline())
2033 next = next.getDualSub();
2036 current.setPrevious(next);
2037 current.setNext(prev);
2039 if (currentSub != null) {
2040 currentSub.setPrevious(next);
2041 currentSub.setNext(prev);
2045 //if (current.isTurn() && current.isFixed()) {
2046 if (current.asFixedAngle()) {
2047 current.setReversed(!current._getReversed());
2049 if (current.isInline() && current.isReverse()) {
2050 current.setReversed(!current._getReversed());
2057 public static void validate(PipeRun pipeRun) {
2058 if (pipeRun == null)
2060 Collection<PipeControlPoint> pcps = pipeRun.getControlPoints();
2062 //System.out.println("Validate " + pipeRun.getName());
2063 for (PipeControlPoint pcp : pcps) {
2064 if (pcp.getParentPoint() == null || pcp.getParentPoint().getPipeRun() != pipeRun)
2067 List<PipeControlPoint> runPcps = getControlPoints(pipeRun);
2068 if (runPcps.size() != count) {
2069 System.out.println("Run " + pipeRun.getName() + " contains unconnected control points, found " + runPcps.size() + " connected, " + pcps.size() + " total.");
2070 for (PipeControlPoint pcp : pcps) {
2071 if (!runPcps.contains(pcp)) {
2072 System.out.println("Unconnected " + pcp + " " + pcp.getPipelineComponent());
2076 for (PipeControlPoint pcp : pcps) {
2077 if (pcp.getPipeRun() == null) {
2078 System.out.println("PipeRun ref missing " + pcp + " " + pcp.getPipelineComponent());
2080 if (!pcp.isDirected() && pcp.getNext() == null && pcp.getPrevious() == null)
2081 System.out.println("Orphan undirected " + pcp + " " + pcp.getPipelineComponent());
2083 for (PipeControlPoint pcp : pcps) {
2084 if (pcp.getParentPoint() == null) {
2085 PipeControlPoint sub = null;
2086 if (pcp.isDualInline())
2087 sub = pcp.getDualSub();
2088 PipeControlPoint next = pcp.getNext();
2089 PipeControlPoint prev = pcp.getPrevious();
2091 if (!(next.getPrevious() == pcp || next.getPrevious() == sub)) {
2092 System.out.println("Inconsistency between " + pcp + " -> " +next );
2096 PipeControlPoint prevParent = null;
2097 if (prev.isDualSub()) {
2098 prevParent = prev.getParentPoint();
2099 } else if (prev.isDualInline()) {
2100 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2102 if (!(prev.getNext() == pcp && (prevParent == null || prevParent.getNext() == pcp))) {
2103 System.out.println("Inconsistency between " + pcp + " <-- " +prev );
2110 public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{
2111 assert(!splittingComponent.getControlPoint().isFixedLength());
2112 assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixedLength()));
2113 PipeControlPoint newCP = newComponent.getControlPoint();
2114 PipeControlPoint splittingCP = splittingComponent.getControlPoint();
2115 PipeControlPoint nextCP = splittingCP.getNext();
2116 PipeControlPoint prevCP = splittingCP.getPrevious();
2118 /* there are many different cases to insert new component when
2119 it splits existing VariableLengthinlineComponent.
2121 1. VariableLengthComponet is connected from both sides:
2122 - insert new component between VariableLength component and component connected to it
2123 - insert new VariableLengthComponent between inserted component and component selected in previous step
2125 2. VariableLengthComponent is connected from one side
2126 - Use previous case or:
2127 - Insert new component to empty end
2128 - Insert new VariableLength component to inserted components empty end
2130 3. VariableLength is not connected to any component.
2131 - Should not be possible, at least in current implementation.
2132 - Could be done using second case
2136 if (nextCP == null && prevCP == null) {
2137 // this should not be possible
2138 throw new RuntimeException("VariableLengthComponent " + splittingComponent + " is not connected to anything.");
2140 double newLength = newComponent.getControlPoint().getLength();
2143 Point3d next = new Point3d();
2144 Point3d prev = new Point3d();
2145 splittingCP.getInlineControlPointEnds(prev, next);
2147 Vector3d newPos = null;
2149 newPos = new Vector3d(prev);
2150 Vector3d dir = new Vector3d(next);
2154 newComponent.setWorldPosition(newPos);
2156 newPos = newComponent.getWorldPosition();
2161 Vector3d dir = new Vector3d(next);
2164 dir.scale(newLength * 0.5);
2165 Point3d vn = new Point3d(newPos);
2166 Point3d vp = new Point3d(newPos);
2169 double ln = vn.distance(next);
2170 double lp = vp.distance(prev);
2171 vp.interpolate(prev, 0.5);
2172 vn.interpolate(next, 0.5);
2175 if (nextCP == null) {
2176 newCP.insert(splittingCP, Direction.NEXT);
2177 insertStraight(newCP, Direction.NEXT, new Vector3d(vn), ln);
2178 splittingCP.setWorldPosition(new Vector3d(vp));
2179 // ControlPointTools.setWorldPosition(splittingCP, vp);
2180 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2181 } else if (prevCP == null) {
2182 newCP.insert(splittingCP, Direction.PREVIOUS);
2183 insertStraight(newCP, Direction.PREVIOUS, new Vector3d(vp), lp);
2184 splittingCP.setWorldPosition(new Vector3d(vn));
2185 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, ln);
2187 newCP.insert(splittingCP, nextCP);
2188 insertStraight(newCP, nextCP, new Vector3d(vn), ln);
2189 splittingCP.setWorldPosition(new Vector3d(vp));
2190 // splittingCP.setRelatedScalarDouble(ProcessResource.plant3Dresource.HasLength, lp);
2192 positionUpdate(newCP);
2196 public static void addSizeChange(boolean reversed, PipeRun pipeRun, PipeRun other, InlineComponent reducer, PipeControlPoint previous, PipeControlPoint next) {
2197 PipeControlPoint pcp = reducer.getControlPoint();
2198 PipeControlPoint ocp = pcp.getDualSub();
2200 String name = pipeRun.getUniqueName("Reducer");
2201 reducer.setName(name);
2202 pipeRun.addChild(reducer);
2203 other.addChild(ocp);
2204 reducer.setAlternativePipeRun(other);
2206 previous.setNext(pcp);
2207 pcp.setPrevious(previous);
2208 ocp.setPrevious(previous);
2212 next.setPrevious(ocp);
2215 String name = other.getUniqueName("Reducer");
2216 reducer.setName(name);
2217 other.addChild(reducer);
2218 pipeRun.addChild(ocp);
2219 reducer.setAlternativePipeRun(pipeRun);
2223 pcp.setPrevious(next);
2224 ocp.setPrevious(next);
2226 pcp.setNext(previous);
2227 ocp.setNext(previous);
2228 previous.setPrevious(ocp);