1 package org.simantics.plant3d.scenegraph.controlpoint;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collection;
8 import javax.vecmath.AxisAngle4d;
9 import javax.vecmath.Matrix3d;
10 import javax.vecmath.Quat4d;
11 import javax.vecmath.Tuple3d;
12 import javax.vecmath.Vector3d;
14 import org.simantics.g3d.math.MathTools;
15 import org.simantics.g3d.property.annotations.GetPropertyValue;
16 import org.simantics.g3d.scenegraph.G3DNode;
17 import org.simantics.plant3d.scenegraph.IP3DNode;
18 import org.simantics.plant3d.scenegraph.PipeRun;
19 import org.simantics.plant3d.scenegraph.PipelineComponent;
21 import vtk.vtkRenderer;
24 public class PipeControlPoint extends G3DNode implements IP3DNode {
26 public enum Type{INLINE,TURN,END};
27 public enum Direction{NEXT,PREVIOUS};
28 public enum PositionType {SPLIT,NEXT,PREVIOUS,PORT}
30 private PipelineComponent component;
33 private boolean fixed = true;
34 private boolean rotate = false;
35 private boolean reverse = false;
36 private boolean deletable = true;
37 private boolean sub = false;
39 public PipeControlPoint(PipelineComponent component) {
40 this.component = component;
41 if (component.getPipeRun() != null)
42 component.getPipeRun().addChild(this);
46 public PipeControlPoint(PipelineComponent component, PipeRun piperun) {
47 this.component = component;
48 piperun.addChild(this);
52 public void update(vtkRenderer ren) {
54 PipingRules.requestUpdate(this);
55 } catch (Exception e) {
61 public PipeRun getPipeRun() {
62 return (PipeRun)getParent();
65 public PipelineComponent getPipelineComponent() {
69 public Type getType() {
73 public void setType(Type type) {
77 @GetPropertyValue(name="Fixed",tabId="Debug",value="fixed")
78 public boolean isFixed() {
83 public void setFixed(boolean fixed) {
87 @GetPropertyValue(name="Rotate",tabId="Debug",value="rotate")
88 public boolean isRotate() {
92 public void setRotate(boolean rotate) {
96 @GetPropertyValue(name="Reverse",tabId="Debug",value="reverse")
97 public boolean isReverse() {
101 public void setReverse(boolean reverse) {
102 this.reverse = reverse;
105 public void setSub(boolean sub) {
109 @GetPropertyValue(name="Deletable",tabId="Debug",value="deletable")
110 public boolean isDeletable() {
114 public void setDeletable(boolean deletable) {
115 this.deletable = deletable;
118 public boolean isPathLegEnd() {
119 return type != Type.INLINE;
122 public boolean isEnd() {
123 return type == Type.END;
126 public boolean isTurn() {
127 return type == Type.TURN;
130 public boolean isInline() {
131 return type == Type.INLINE;
134 public boolean isDirected() {
135 return fixed && isEnd();
138 public boolean isNonDirected() {
139 return !fixed && isEnd();
142 public boolean isVariableLength() {
143 return !fixed && isInline();
146 public boolean isVariableAngle() {
147 return !fixed && isTurn();
150 public boolean isBranchEnd() {
151 return deletable && isEnd();
154 public boolean isOffset() {
155 return offset != null;
158 public boolean isDualSub() {
159 return parent != null && sub;
162 public boolean isDualInline() {
163 return children.size() == 1 && children.get(0).isDualSub();
166 public boolean isSizeChange() {
167 if (children.size() == 0)
171 return getPipeRun() != children.get(0).getPipeRun();
175 private PipeControlPoint next;
176 private PipeControlPoint previous;
178 public PipeControlPoint getNext() {
182 public PipeControlPoint getPrevious() {
186 public void setNext(PipeControlPoint next) {
187 if (isEnd() && previous != null && next != null)
188 throw new RuntimeException("End control points are allowed to have only one connection");
189 // if (next != null && getPipeRun() == null)
190 // throw new RuntimeException("Cannot connect control point befor piperun has been set");
192 if (component != null) {
193 if (parent == null || sub)
194 component.setNext(next != null ? next.component : null);
196 component.setBranch0(next != null ? next.component : null);
202 public void setPrevious(PipeControlPoint previous) {
203 if (isEnd() && next != null && previous != null)
204 throw new RuntimeException("End control points are allowed to have only one connection");
205 // if (previous != null && getPipeRun() == null)
206 // throw new RuntimeException("Cannot connect control point befor piperun has been set");
207 this.previous = previous;
208 if (component != null) {
209 if (parent == null || sub)
210 component.setPrevious(previous != null ? previous.component : null);
212 component.setBranch0(previous != null ? previous.component : null);
218 public PipeControlPoint parent;
219 public List<PipeControlPoint> children = new ArrayList<PipeControlPoint>();
221 public List<PipeControlPoint> getSubPoint() {
225 public PipeControlPoint getParentPoint() {
236 private double length;
237 private Double turnAngle;
238 private Vector3d turnAxis;
240 private Double offset;
241 private Double rotationAngle;
242 private Boolean reversed;
244 @GetPropertyValue(name="Length",tabId="Debug",value="length")
245 public double getLength() {
249 public void setLength(double l) {
250 if (Double.isInfinite(l) || Double.isNaN(l)) {
253 if (Math.abs(this.length-l) < MathTools.NEAR_ZERO)
256 firePropertyChanged("length");
258 getSubPoint().get(0).setLength(l);
261 @GetPropertyValue(name="Turn Angle",tabId="Debug",value="turnAngle")
262 public Double getTurnAngle() {
266 @GetPropertyValue(name="Turn Axis",tabId="Debug",value="turnAxis")
267 public Vector3d getTurnAxis() {
271 @GetPropertyValue(name="Offset",tabId="Debug",value="offset")
272 public Double getOffset() {
276 @GetPropertyValue(name="Rotation Angle",tabId="Debug",value="rotationAngle")
277 public Double getRotationAngle() {
278 return rotationAngle;
281 @GetPropertyValue(name="Reversed",tabId="Debug",value="reversed")
282 public Boolean getReversed() {
286 public void setTurnAngle(Double turnAngle) {
287 if (Double.isInfinite(turnAngle) || Double.isNaN(turnAngle)) {
290 if (this.turnAngle != null && Math.abs(this.turnAngle-turnAngle) < MathTools.NEAR_ZERO)
292 this.turnAngle = turnAngle;
293 firePropertyChanged("turnAngle");
296 public void setTurnAxis(Vector3d turnAxis) {
297 this.turnAxis = turnAxis;
298 firePropertyChanged("turnAxis");
301 public void setOffset(Double offset) {
302 if (Double.isInfinite(offset) || Double.isNaN(offset)) {
305 if (this.offset != null && Math.abs(this.offset-offset) < MathTools.NEAR_ZERO)
307 this.offset = offset;
308 firePropertyChanged("offset");
311 public void setRotationAngle(Double rotationAngle) {
312 if (Double.isInfinite(rotationAngle) || Double.isNaN(rotationAngle)) {
315 if (this.rotationAngle != null && Math.abs(this.rotationAngle-rotationAngle) < MathTools.NEAR_ZERO)
317 this.rotationAngle = rotationAngle;
318 firePropertyChanged("rotationAngle");
321 public void setReversed(Boolean reversed) {
322 this.reversed = reversed;
323 firePropertyChanged("rotationAngle");
326 public Vector3d getSizeChangeOffsetVector(Vector3d dir) {
328 if (rotationAngle == null)
329 q = getControlPointOrientationQuat(dir, 0.0);
331 q = getControlPointOrientationQuat(dir, rotationAngle);
332 Vector3d v = new Vector3d(0.0,offset,0.0);
333 Vector3d offset = new Vector3d();
334 MathTools.rotate(q, v, offset);
338 public Vector3d getSizeChangeOffsetVector() {
340 if (rotationAngle == null)
341 q = getControlPointOrientationQuat(0.0);
343 q = getControlPointOrientationQuat(rotationAngle);
344 Vector3d v = new Vector3d(0.0,offset,0.0);
345 Vector3d offset = new Vector3d();
346 MathTools.rotate(q, v, offset);
350 @GetPropertyValue(name="Next",tabId="Debug",value="next")
351 private String getNextString() {
354 return next.toString();
357 @GetPropertyValue(name="Previous",tabId="Debug",value="previous")
358 private String getPrevString() {
359 if (previous == null)
361 return previous.toString();
364 @GetPropertyValue(name="Sub",tabId="Debug",value="sub")
365 private String getSubString() {
366 if (children.size() == 0)
368 return Arrays.toString(children.toArray());
371 @GetPropertyValue(name="Type",tabId="Debug",value="type")
372 public String getTypeString() {
376 public Quat4d getControlPointOrientationQuat(double angle) {
378 if (turnAxis == null) {
379 Vector3d dir = getPathLegDirection(Direction.NEXT);
380 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
382 return getControlPointOrientationQuat(dir, angle);
384 Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
386 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
388 return getControlPointOrientationQuat(dir, turnAxis, angle);
392 public Quat4d getControlPointOrientationQuat(double angle, boolean reversed) {
394 if (turnAxis == null) {
395 Vector3d dir = getPathLegDirection(Direction.NEXT);
396 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
398 Quat4d q = getControlPointOrientationQuat(dir, angle);
400 Quat4d q2 = new Quat4d();
401 q2.set(new AxisAngle4d(MathTools.Y_AXIS, Math.PI));
406 Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
408 if (dir.lengthSquared() > MathTools.NEAR_ZERO)
410 return getControlPointOrientationQuat(dir, turnAxis, angle);
416 public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
417 if (dir.lengthSquared() < MathTools.NEAR_ZERO)
418 return MathTools.getIdentityQuat();
421 Vector3d up = new Vector3d(0.0, 1.0, 0.0);
422 double a = up.angle(dir);
423 if (a < 0.1 || (Math.PI - a) < 0.1) {
424 up.set(1.0, 0.0, 0.0);
428 return getControlPointOrientationQuat(dir, up, angle);
431 public static Quat4d getControlPointOrientationQuat(Vector3d dir, Vector3d up, double angle) {
432 if (dir.lengthSquared() < MathTools.NEAR_ZERO)
433 return MathTools.getIdentityQuat();
435 final Vector3d front = new Vector3d(1.0,0.0,0.0);
437 Quat4d q1 = new Quat4d();
440 Vector3d right = new Vector3d();
442 right.cross(dir, up);
443 up.cross(right, dir);
447 Matrix3d m = new Matrix3d();
458 //q1.set(m); MathTools contains more stable conversion
459 MathTools.getQuat(m, q1);
461 // if (DEBUG) System.out.println("PipingTools.getPipeComponentOrientationQuat() " + dir+ " " + up + " " + right);
463 Quat4d q2 = new Quat4d();
464 q2.set(new AxisAngle4d(front, angle));
469 public Vector3d getDirection() {
470 return getDirectedControlPointDirection();
479 public void insert(PipeControlPoint previous, PipeControlPoint next) {
480 // inserting an offsetpoint is error,
482 throw new RuntimeException();
483 // size change control point cannot be inserted this way, because it ends PipeRun
485 throw new RuntimeException();
486 PipeRun piperun = previous.getPipeRun();
487 // and just to make sure that control point structure is not corrupted
488 if (getPipeRun() != null) {
489 if (piperun != getPipeRun() || piperun != next.getPipeRun())
490 throw new RuntimeException();
492 piperun.addChild(this);
495 // insert new BranchControlPoint between straight's control points
496 PipeControlPoint previousNext = previous.getNext();
497 PipeControlPoint previousPrevious = previous.getPrevious();
499 PipeControlPoint offsetCP = null;
501 offsetCP = getSubPoint().get(0);
503 if (previousNext != null && previousNext == next) {
504 if (previous.isDualInline()) {
505 throw new RuntimeException();
507 if (next.isDualSub()) {
508 throw new RuntimeException();
510 previous.setNext(this);
511 this.setPrevious(previous);
512 if (previous.isDualSub()) {
513 previous.getParentPoint().setNext(this);
517 if (offsetCP == null) {
518 next.setPrevious(this);
520 next.setPrevious(offsetCP);
521 offsetCP.setNext(next);
522 offsetCP.setPrevious(previous);
525 if (next.isDualInline()) {
526 next.getSubPoint().get(0).setPrevious(this);
528 } else if (previousPrevious != null && previousPrevious == next) {
529 // control point were given in reverse order
530 if (next.isDualInline())
531 throw new RuntimeException();
532 if (previous.isDualSub())
533 throw new RuntimeException();
535 this.setNext(previous);
536 if (offsetCP == null) {
537 previous.setNext(this);
539 previous.setPrevious(offsetCP);
540 offsetCP.setNext(previous);
541 offsetCP.setPrevious(next);
543 if (previous.isDualInline()) {
544 previous.getSubPoint().get(0).setPrevious(this);
546 this.setPrevious(next);
548 if (next.isDualSub()) {
549 next.getParentPoint().setNext(this);
553 throw new RuntimeException();
556 PipingRules.validate(piperun);
561 public void insert(PipeControlPoint pcp, Direction direction) {
563 throw new RuntimeException();
564 if (direction == Direction.NEXT) {
565 // if direction is next, user must have given OffsetPoint
566 if (pcp.isDualInline())
567 throw new RuntimeException();
568 // basic next/prev links
570 this.setPrevious(pcp);
571 // and last take care of sizechange / offset points
572 if (pcp.isDualSub()) {
573 pcp.getParentPoint().setNext(this);
575 if (isDualInline()) {
576 getSubPoint().get(0).setPrevious(this);
579 // if direction is previous, user must have given sizechange
581 throw new RuntimeException();
582 // previous direction is more complicated, since if newCP is SizeChangeControlPoint,
583 // we must link pcp to newCP's OffsetPoint
584 PipeControlPoint nocp = null;
585 if (isDualInline()) {
586 nocp = getSubPoint().get(0);
590 pcp.setPrevious(this);
592 pcp.setPrevious(nocp);
595 if (pcp.isDualInline()) {
596 PipeControlPoint ocp = pcp.getSubPoint().get(0);
598 ocp.setPrevious(this);
600 ocp.setPrevious(nocp);
604 PipingRules.validate(getPipeRun());
607 public Vector3d getDirectedControlPointDirection() {
608 assert (isDirected());
609 Vector3d dir = new Vector3d();
610 MathTools.rotate(getWorldOrientation(), new Vector3d(1.0, 0.0, 0.0), dir);
615 public Vector3d getPathLegDirection(Direction direction) {
616 if (direction == Direction.NEXT) {
618 PipeControlPoint pcp = this;
619 if (pcp.isDualInline()) {
620 pcp = pcp.getSubPoint().get(0);
622 Vector3d v = new Vector3d();
623 v.sub(next.getWorldPosition(),pcp.getWorldPosition());
626 if (isVariableAngle())
627 throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point");
628 if (previous == null) {
630 throw new RuntimeException("Cannot calculate path leg direction for unconnected control point");
631 return getDirectedControlPointDirection();
635 PipeControlPoint pcp = this;
636 if (pcp.isDualSub()) {
637 pcp = pcp.getParentPoint();
639 Vector3d v = new Vector3d();
640 v.sub(pcp.getWorldPosition(),previous.getWorldPosition());
642 } else if (isDirected()) {
643 return getDirectedControlPointDirection();
644 } else if (isEnd()) {
645 Vector3d v = new Vector3d();
646 v.sub(getWorldPosition(),previous.getWorldPosition());
649 throw new RuntimeException("Missing implementation");
653 if (previous != null) {
654 PipeControlPoint pcp = this;
656 pcp = getParentPoint();
657 Vector3d v = new Vector3d();
658 v.sub(previous.getWorldPosition(),pcp.getWorldPosition());
661 if (isVariableAngle())
662 throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point");
665 throw new RuntimeException("Cannot calculate path leg direction for unconnected control point");
666 Vector3d v = getDirectedControlPointDirection();
671 PipeControlPoint pcp = this;
672 if (pcp.isDualInline()) {
673 pcp = pcp.getSubPoint().get(0);
675 Vector3d v = new Vector3d();
676 v.sub(pcp.getWorldPosition(),next.getWorldPosition());
678 } else if (isDirected()) {
679 Vector3d v = getDirectedControlPointDirection();
682 } else if (isEnd()) {
683 Vector3d v = new Vector3d();
684 v.sub(getWorldPosition(),next.getWorldPosition());
687 throw new RuntimeException("Missing implementation");
693 public void getInlineControlPointEnds(Tuple3d p1, Tuple3d p2) {
696 Vector3d pos = getWorldPosition();
697 Vector3d dir = getPathLegDirection(Direction.NEXT);
699 dir.scale(length * 0.5);
706 public void getControlPointEnds(Tuple3d p1, Tuple3d p2) {
707 Vector3d pos = getWorldPosition();
708 Vector3d dir1 = getPathLegDirection(Direction.PREVIOUS);
710 Vector3d dir2 = getPathLegDirection(Direction.NEXT);
713 dir1.scale(length * 0.5);
714 dir2.scale(length * 0.5);
725 public void getInlineControlPointEnds(Tuple3d p1, Tuple3d p2, Vector3d dir) {
728 Vector3d pos = getWorldPosition();
729 dir.set(getPathLegDirection(Direction.NEXT));
731 dir.scale(length * 0.5);
738 public void getInlineControlPointEnds(Tuple3d center, Tuple3d p1, Tuple3d p2, Vector3d dir) {
741 Vector3d pos = getWorldPosition();
743 dir.set(getPathLegDirection(Direction.NEXT));
745 dir.scale(length * 0.5);
752 public double getInlineLength() {
753 if (type == Type.TURN)
755 else if (type == Type.INLINE)
760 public Vector3d getRealPosition(PositionType type) {
761 Vector3d pos = getWorldPosition();
764 Vector3d dir = getPathLegDirection(Direction.NEXT);
765 double length = getInlineLength();
772 Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
773 double length = getInlineLength();
780 // IEntity portDir = pcp.getSingleRelatedObject(ProcessResource.plant3Dresource.HasDirection);
781 // TODO : how we calculated needed space for a port; does it has an offset from control point's position or not?
791 public void getInlineMovement(Tuple3d start, Tuple3d end) {
792 // FIXME : check type of neighbor components and allow movement on top of variable length components,
793 // find proper range for movement (pcp's position is not)
794 PipeControlPoint p = previous.getPrevious();
795 PipeControlPoint n = next.getNext();
796 start.set(p.getWorldPosition());
797 end.set(n.getWorldPosition());
800 public PipeControlPoint findNextEnd() {
801 ArrayList<PipeControlPoint> t = new ArrayList<PipeControlPoint>();
802 return findNextEnd( t);
805 public PipeControlPoint findPreviousEnd() {
806 ArrayList<PipeControlPoint> t = new ArrayList<PipeControlPoint>();
807 return findPreviousEnd(t);
810 public PipeControlPoint findNextEnd(List<PipeControlPoint> nextList) {
812 PipeControlPoint pcp = null;
813 PipeControlPoint p = null;
814 if (nextList.size() == 0)
818 p = nextList.get(nextList.size() - 1);
823 if (nextList.size() > 0)
824 nextList.remove(nextList.size() - 1);
825 // if (DEBUG) System.out.println(" " + pcp.getResource() + " not full");
829 if (pcp.isPathLegEnd()) {
830 //if (DEBUG) System.out.println(" " + pcp.getResource());
834 // if (DEBUG) System.out.print(" " + pcp.getResource());
839 public PipeControlPoint findPreviousEnd(List<PipeControlPoint> prevList) {
841 PipeControlPoint pcp = null;
842 PipeControlPoint p = null;
843 if (prevList.size() == 0)
847 p = prevList.get(prevList.size() - 1);
849 pcp = p.getPrevious();
852 if (prevList.size() > 0)
853 prevList.remove(prevList.size() - 1);
854 // if (DEBUG) System.out.println(" " + pcp.getResource() + " not full");
857 if (pcp.isPathLegEnd()) {
858 // if (DEBUG) System.out.println(" " + pcp.getResource());
862 // if (DEBUG)System.out.print(" " + pcp.getResource());
867 public void _remove() {
868 if (component == null && next == null && previous == null)
870 if (isDualInline() || isDualSub()) {
874 PipeRun pipeRun = getPipeRun();
878 PipeControlPoint additionalRemove = null;
879 if (!PipingRules.isEnabled()) {
884 PipeControlPoint currentPrev = previous;
885 PipeControlPoint currentNext = next;
886 if (currentNext == null && currentPrev == null) {
888 pipeRun.remChild(this);
891 if (currentNext != null && currentPrev != null) {
893 if (currentNext.isBranchEnd()) {
895 // currentNext.setPrevious(null);
896 // currentNext.setNext(null);
897 currentNext.remove();
901 if (currentPrev.isBranchEnd()) {
903 // currentPrev.setPrevious(null);
904 // currentPrev.setNext(null);
905 currentPrev.remove();
909 if (link && currentPrev.isDirected() && currentNext.isDirected()) {
912 if (currentNext == null) {
914 } else if (currentNext.isDualInline()) {
915 PipeControlPoint sccp = currentNext;
916 PipeControlPoint ocp = sccp.getSubPoint().get(0);
918 throw new RuntimeException("Removing PipeControlPoint " + this+ " structure damaged, no offset control point");
921 sccp.setPrevious(currentPrev);
922 ocp.setPrevious(currentPrev);
924 sccp.setPrevious(null);
925 ocp.setPrevious(null);
928 } else if (currentNext.isDualSub()) {
929 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, next control point is offset control point");
930 } else if (currentNext.previous == this) {
932 currentNext.setPrevious(currentPrev);
934 currentNext.setPrevious(null);
938 throw new RuntimeException("Removing PipeControlPoint "+ this+ " structure damaged");
940 if (currentPrev == null) {
942 } else if (currentPrev.isDualInline()) {
943 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, previous control point is size change control point");
944 } else if (currentPrev.isDualSub()) {
945 PipeControlPoint ocp = currentPrev;
946 PipeControlPoint sccp = ocp.getParentPoint();
948 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, no size change control point");
950 ocp.setNext(currentNext);
951 sccp.setNext(currentNext);
957 } else if (currentPrev.next == this) {
959 currentPrev.setNext(currentNext);
961 currentPrev.setNext(null);
965 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged");
968 if (currentNext.isVariableLength() && currentPrev.isVariableLength()) {
969 // we have to join them into single variable length component.
970 additionalRemove = currentPrev;
971 //currentPrev.remove();
974 // FIXME : pipe run must be split into two parts, since the control point structure is no more continuous.
976 } else if (next != null) {
977 if (next.isDualInline()) {
978 PipeControlPoint sccp = next;
979 PipeControlPoint ocp = sccp.getSubPoint().get(0);
981 throw new RuntimeException("Removing PipeControlPoint " + this+ " structure damaged, no offset control point");
983 sccp.setPrevious(null);
984 ocp.setPrevious(null);
985 } else if (next.isDualSub()) {
986 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, next control point is offset control point");
987 } else if (next.previous == this) {
988 next.setPrevious(null);
990 throw new RuntimeException("Removing PipeControlPoint "+ this+ " structure damaged");
993 } else { //(previous != null)
994 if(previous.isDualInline()) {
995 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, previous control point is size change control point");
996 } else if (previous.isDualSub()) {
997 PipeControlPoint ocp = previous;
998 PipeControlPoint sccp = ocp.getParentPoint();
1000 throw new RuntimeException("Removing PipeControlPoint " + this + " structure damaged, no size change control point");
1004 } else if (previous.next == this) {
1005 previous.setNext(null);
1007 throw new RuntimeException("Removing PipeControlPoint "+ this+ " structure damaged");
1011 if (children.size() > 0 ) {
1013 } else if (parent!= null) {
1014 removeParentPoint();
1020 pipeRun.remChild(this);
1021 checkRemove(pipeRun);
1022 if (PipingRules.isEnabled() && pipeRun.getParent() != null && pipeRun.getControlPoints().size() > 0)
1023 PipingRules.validate(pipeRun);
1024 if (additionalRemove != null)
1025 additionalRemove.remove();
1028 public void remove() {
1029 PipeControlPoint currentPrev = previous;
1030 PipeControlPoint currentNext = next;
1033 if (currentNext != null)
1034 PipingRules.requestUpdate(currentNext);
1035 if (currentPrev != null)
1036 PipingRules.requestUpdate(currentPrev);
1037 } catch (Exception e) {
1038 e.printStackTrace();
1042 private void checkRemove(PipeRun pipeRun) {
1043 Collection<PipeControlPoint> points = pipeRun.getControlPoints();
1044 if (points.size() == 0) {
1046 } else if (points.size() == 1) {
1047 PipeControlPoint pcp = points.iterator().next();
1048 if (pcp.isDeletable())
1053 private void removeDualPoint() {
1054 if (previous != null)
1055 previous.setNext(null);
1057 next.setPrevious(null);
1058 PipeControlPoint ocp;
1059 PipeControlPoint sccp;
1060 if (isDualInline()) {
1062 ocp = getSubPoint().get(0);
1065 sccp = getParentPoint();
1067 PipeRun p1 = ocp.getPipeRun();
1068 PipeRun p2 = sccp.getPipeRun();
1070 ocp.removeComponent();
1071 sccp.removeComponent();
1076 // TODO : now we assume that this is size change, and we do
1077 if (ocp.next != null)
1078 ocp.next.setPrevious(null);
1079 if (ocp.previous != null)
1080 ocp.previous.setNext(null);
1081 if (sccp.next != null)
1082 sccp.next.setPrevious(null);
1083 if (sccp.previous != null)
1084 sccp.previous.setNext(null);
1086 ocp.setPrevious(null);
1088 sccp.setPrevious(null);
1094 private void removeSubPoints() {
1095 for (PipeControlPoint p : children) {
1096 // TODO : this may affect delete routine, since classification of the point changes.
1103 private void removeParentPoint() {
1104 throw new RuntimeException("Child points cannot be removed directly");
1107 private void removeComponent() {
1108 if (component == null)
1110 PipelineComponent next = component.getNext();
1111 PipelineComponent prev = component.getNext();
1113 if (next.getNext() == component)
1115 else if (next.getPrevious() == component)
1116 next.setPrevious(null);
1119 if (prev.getNext() == component)
1121 else if (prev.getPrevious() == component)
1122 prev.setPrevious(null);
1124 PipelineComponent comp = component;
1131 public void setOrientation(Quat4d orientation) {
1132 if (MathTools.equals(orientation, getOrientation()))
1134 super.setOrientation(orientation);
1135 if (getParentPoint() == null && component != null)
1136 component._setWorldOrientation(getWorldOrientation());
1141 public void setPosition(Vector3d position) {
1142 if (MathTools.equals(position, getPosition()))
1144 if (Double.isNaN(position.x) || Double.isNaN(position.y) || Double.isNaN(position.z))
1145 throw new IllegalArgumentException("NaN is not supported");
1146 super.setPosition(position);
1147 if (getParentPoint() == null && component != null)
1148 component._setWorldPosition(getWorldPosition());
1152 private void updateSubPoint() {
1154 if (next == null && previous == null) {
1155 for (PipeControlPoint sub : getSubPoint()) {
1156 sub.setWorldPosition(getWorldPosition());
1157 sub.setWorldOrientation(getWorldOrientation());
1161 for (PipeControlPoint sub : getSubPoint()) {
1162 Vector3d wp = getWorldPosition();
1163 wp.add(getSizeChangeOffsetVector());
1164 sub.setWorldPosition(wp);
1165 sub.setWorldOrientation(getWorldOrientation());
1168 for (PipeControlPoint sub : getSubPoint()) {
1169 sub.setWorldPosition(getWorldPosition());
1170 sub.setWorldOrientation(getWorldOrientation());
1176 public void _setWorldPosition(Vector3d position) {
1177 Vector3d localPos = getLocalPosition(position);
1178 super.setPosition(localPos);
1182 public void _setWorldOrientation(Quat4d orientation) {
1183 Quat4d localOr = getLocalOrientation(orientation);
1184 super.setOrientation(localOr);
1189 public String toString() {
1190 return getClass().getName() + "@" + Integer.toHexString(hashCode());