X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fscenegraph%2Fcontrolpoint%2FPipeControlPoint.java;h=6c932ad853fac389f56c2a444264151afb76705e;hb=195e8e68bac6c952d65f31dd40dcac0a4eb11cd4;hp=6e6a595bc3cefddd0fdab8864efec31666ea3618;hpb=c07ac416dfbe99201084e71c53dc95c9c41d906c;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index 6e6a595b..6c932ad8 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -16,6 +16,8 @@ import org.simantics.g3d.math.MathTools; import org.simantics.g3d.property.annotations.GetPropertyValue; import org.simantics.g3d.scenegraph.G3DNode; import org.simantics.plant3d.scenegraph.IP3DNode; +import org.simantics.plant3d.scenegraph.Nozzle; +import org.simantics.plant3d.scenegraph.P3DRootNode; import org.simantics.plant3d.scenegraph.PipeRun; import org.simantics.plant3d.scenegraph.PipelineComponent; @@ -487,51 +489,6 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { return q1; } - public Vector3d getDirection(Direction direction) { - if (isDirected()) - return getDirectedControlPointDirection(); - if (isTurn() && isFixed()) { - if (direction == Direction.NEXT) { - if (previous != null) { - PipeControlPoint pcp = this; - Vector3d dir = new Vector3d(); - dir.sub(pcp.getWorldPosition(),previous.getWorldPosition()); - if (dir.lengthSquared() > MathTools.NEAR_ZERO) - dir.normalize(); - else - return null; - Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0); - AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle()); - Quat4d q2 = MathTools.getQuat(aa); - Vector3d v = new Vector3d(1.,0.,0.); - Vector3d offset = new Vector3d(); - MathTools.rotate(q2, v, offset); - MathTools.rotate(q, offset, dir); - return dir; - } - } else { - if (next != null) { - PipeControlPoint pcp = this; - Vector3d dir = new Vector3d(); - dir.sub(next.getWorldPosition(),pcp.getWorldPosition()); - if (dir.lengthSquared() > MathTools.NEAR_ZERO) - dir.normalize(); - else - return null; - Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0); - AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle()); - Quat4d q2 = MathTools.getQuat(aa); - Vector3d v = new Vector3d(1.,0.,0.); - Vector3d offset = new Vector3d(); - MathTools.rotate(q2, v, offset); - MathTools.rotate(q, offset, dir); - return dir; - } - } - } - return null; - } - public void insert(PipeControlPoint previous, PipeControlPoint next) { // inserting an offsetpoint is error, if (isDualSub()) @@ -667,6 +624,51 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { dir.normalize(); return dir; } + + public Vector3d getDirection(Direction direction) { + if (isDirected()) + return getDirectedControlPointDirection(); + if (isTurn() && isFixed()) { + if (direction == Direction.NEXT) { + if (previous != null) { + PipeControlPoint pcp = this; + Vector3d dir = new Vector3d(); + dir.sub(pcp.getWorldPosition(),previous.getWorldPosition()); + if (dir.lengthSquared() > MathTools.NEAR_ZERO) + dir.normalize(); + else + return null; + Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0); + AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle()); + Quat4d q2 = MathTools.getQuat(aa); + Vector3d v = new Vector3d(1.,0.,0.); + Vector3d offset = new Vector3d(); + MathTools.rotate(q2, v, offset); + MathTools.rotate(q, offset, dir); + return dir; + } + } else { + if (next != null) { + PipeControlPoint pcp = this; + Vector3d dir = new Vector3d(); + dir.sub(next.getWorldPosition(),pcp.getWorldPosition()); + if (dir.lengthSquared() > MathTools.NEAR_ZERO) + dir.normalize(); + else + return null; + Quat4d q = getControlPointOrientationQuat(dir, pcp.getRotationAngle() != null ? pcp.getRotationAngle() : 0.0); + AxisAngle4d aa = new AxisAngle4d(MathTools.Y_AXIS,pcp.getTurnAngle() == null ? 0.0 : pcp.getTurnAngle()); + Quat4d q2 = MathTools.getQuat(aa); + Vector3d v = new Vector3d(1.,0.,0.); + Vector3d offset = new Vector3d(); + MathTools.rotate(q2, v, offset); + MathTools.rotate(q, offset, dir); + return dir; + } + } + } + return null; + } public Vector3d getPathLegDirection(Direction direction) { if (direction == Direction.NEXT) { @@ -681,12 +683,12 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } else { if (previous == null) { if (!isDirected()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected control point"); + throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); return getDirectedControlPointDirection(); } else { if (isVariableAngle()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point"); + throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); if (isInline()) { PipeControlPoint pcp = this; if (pcp.isDualSub()) { @@ -704,7 +706,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } else if (isTurn() && isFixed() && !_getReversed()) { return getDirection(Direction.NEXT); } - throw new RuntimeException("Missing implementation"); + throw new RuntimeException("Missing implementation " + this); } } } else { @@ -718,13 +720,13 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } else { if (next == null) { if (!isDirected()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected control point"); + throw new RuntimeException("Cannot calculate path leg direction for unconnected control point " + this); Vector3d v = getDirectedControlPointDirection(); v.negate(); return v; } else { if (isVariableAngle()) - throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point"); + throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); if (isInline()) { PipeControlPoint pcp = this; if (pcp.isDualInline()) { @@ -744,7 +746,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } else if (isTurn() && isFixed() && _getReversed()) { return getDirection(Direction.PREVIOUS); } - throw new RuntimeException("Missing implementation"); + throw new RuntimeException("Missing implementation " + this); } } } @@ -766,7 +768,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } public void getControlPointEnds(Tuple3d p1, Tuple3d p2) { - PipeControlPoint sub = isAxial() ? this : getSubPoint().get(0); + PipeControlPoint sub = isAxial() || isDirected() || isTurn() ? this : getSubPoint().get(0); Vector3d pos = getWorldPosition(), pos2 = sub == this ? pos : sub.getWorldPosition(); Vector3d dir1 = getPathLegDirection(Direction.PREVIOUS); @@ -938,14 +940,22 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { } } } - + public void _remove() { + _remove(true); + } + + public void _remove(boolean renconnect) { if (component == null && next == null && previous == null) return; + if (DEBUG) System.out.println(this + " Remove " + renconnect); if (isDualInline() || isDualSub()) { removeDualPoint(); return; } + if (getParentPoint() != null) { + getParentPoint()._remove(renconnect); + } PipeRun pipeRun = getPipeRun(); if (pipeRun == null) return; @@ -964,7 +974,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { return; } if (currentNext != null && currentPrev != null) { - boolean link = true; + boolean link = renconnect; if (currentNext.isBranchEnd()) { link = false; // currentNext.setPrevious(null); @@ -1112,19 +1122,92 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { additionalRemove.remove(); } + /** + * Removes control point and attempts to reconnect next/prev + * + * If this point is size change (PipeRuns are different on both sides), then reconnection cannot be made. + */ public void remove() { PipeControlPoint currentPrev = previous; PipeControlPoint currentNext = next; _remove(); try { if (currentNext != null) - PipingRules.requestUpdate(currentNext); + if (!currentNext.checkRemove()) + PipingRules.requestUpdate(currentNext); if (currentPrev != null) - PipingRules.requestUpdate(currentPrev); + if (!currentPrev.checkRemove()) + PipingRules.requestUpdate(currentPrev); } catch (Exception e) { e.printStackTrace(); } } + + + /** + * Removes control point without attempting to reconnect next/prev. + * This usually leads to creation of another PipeRun for the control points after this point. + */ + public void removeAndSplit() { + PipeControlPoint currentPrev = previous; + PipeControlPoint currentNext = next; + + if (next != null && previous != null) { + P3DRootNode root = (P3DRootNode)getPipelineComponent().getRootNode(); + PipeRun nextPipeRun = new PipeRun(); + nextPipeRun.setName(root.getUniqueName("PipeRun")); + root.addChild(nextPipeRun); + + PipeRun previousRun = previous.getPipeRun(); + nextPipeRun.setPipeDiameter(previousRun.getPipeDiameter()); + nextPipeRun.setTurnRadius(previousRun.getTurnRadius()); + + PipelineComponent n = next.getPipelineComponent(); + while (n != null) { + if (! (n instanceof Nozzle)) { + n.deattach(); + nextPipeRun.addChild(n); + } else + n.setPipeRun(nextPipeRun); + n = n.getNext(); + } + } + _remove(false); + try { + if (currentNext != null) + if (!currentNext.checkRemove()) + PipingRules.requestUpdate(currentNext); + if (currentPrev != null) + if (!currentPrev.checkRemove()) + PipingRules.requestUpdate(currentPrev); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * This is called when adjacent control point is removed. + * + * This call should remove the give point, if the point cannot exist alone. + * At the moment there is one such case: branch. + * + * @return + */ + protected boolean checkRemove() { + if (getParentPoint() != null) { + return getParentPoint().checkRemove(); + } else { + if (getPipelineComponent() == null) + return true; // already removed + if (getPipelineComponent().getType().equals("Plant3D.URIs.Builtin_BranchSplitComponent")) { + if (getSubPoint().get(0).getNext() == null && getSubPoint().get(0).getPrevious() == null) { + remove(); + return true; + } + } + return false; + } + } private void checkRemove(PipeRun pipeRun) { Collection points = pipeRun.getControlPoints();