X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;fp=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Factions%2FAddComponentAction.java;h=a4398a5455b582fab3c3192800593c9f921e5c7d;hb=8b06e290cf681e2157824428395988063686e7b3;hp=5187025fc58c88fc42fa91e81812c38537d023e3;hpb=63f2f953315938928e5a232a619fa9bb5d694580;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java index 5187025f..a4398a54 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java @@ -159,26 +159,50 @@ public class AddComponentAction extends vtkSwtAction { PipeControlPoint newPcp = newComponent.getControlPoint(); PipeControlPoint toPcp = component.getControlPoint(); + PipeRun pipeRun = toPcp.getPipeRun(); + Vector3d dir = null; + Vector3d pos = null; + - switch (position) { - case NEXT: - if (toPcp.isDualInline()) - toPcp = toPcp.getSubPoint().get(0); - - break; - case PREVIOUS: - if (toPcp.isDualSub()) - toPcp = toPcp.parent; + if (toPcp.isInline()) { + switch (position) { + case NEXT: + if (toPcp.isDualInline()) + toPcp = toPcp.getSubPoint().get(0); + + break; + case PREVIOUS: + if (toPcp.isDualSub()) + toPcp = toPcp.parent; + } + Vector3d start = new Vector3d(); + Vector3d end = new Vector3d(); + dir = new Vector3d(); + toPcp.getInlineControlPointEnds(start, end, dir); + dir.normalize(); + switch (position) { + case NEXT: + pos = new Vector3d(end); + break; + case PREVIOUS: + pos = new Vector3d(start); + break; + case SPLIT: + break; + } + + } else if (toPcp.isDirected()) { + dir = new Vector3d(toPcp.getDirection(Direction.NEXT)); + pos = new Vector3d(toPcp.getWorldPosition()); + } else if (toPcp.isTurn() && toPcp.isFixed()) { + dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS)); + pos = new Vector3d(toPcp.getWorldPosition()); + Vector3d v = new Vector3d(dir); + v.scale(toPcp.getInlineLength()); + pos.add(v); } - Vector3d start = new Vector3d(); - Vector3d end = new Vector3d(); - Vector3d dir = new Vector3d(); - toPcp.getInlineControlPointEnds(start, end, dir); - dir.normalize(); - - PipeRun pipeRun = toPcp.getPipeRun(); if (!toAdd.isSizeChange()) { String name = component.getPipeRun().getUniqueName(toAdd.getName()); @@ -196,29 +220,37 @@ public class AddComponentAction extends vtkSwtAction { } } newComponent.updateParameters(); - - dir.scale(newComponent.getControlPoint().getLength()*0.5); - start.sub(dir); - end.add(dir); + + Vector3d v = new Vector3d(dir); + v.scale(newComponent.getControlPoint().getInlineLength()); + switch (position) { + case NEXT: + pos.add(v); + break; + case PREVIOUS: + pos.sub(v); + break; + case SPLIT: + break; + } + switch (position) { case NEXT: if (toPcp.isDualInline()) toPcp = toPcp.getSubPoint().get(0); newPcp.insert(toPcp, Direction.NEXT); - newPcp.setWorldPosition(end); + newPcp.setWorldPosition(pos); break; case PREVIOUS: if (toPcp.isDualSub()) toPcp = toPcp.parent; newPcp.insert(toPcp, Direction.PREVIOUS); - newPcp.setWorldPosition(start); + newPcp.setWorldPosition(pos); break; case SPLIT: PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, true); } } else { - - PipeRun other = new PipeRun(); String n = root.getUniqueName("PipeRun"); other.setName(n); @@ -227,24 +259,28 @@ public class AddComponentAction extends vtkSwtAction { root.addChild(other); - if (position == PositionType.NEXT) { PipingRules.addSizeChange(false, pipeRun, other, (InlineComponent)newComponent, toPcp, null); - newPcp.setWorldPosition(end); } else if (position == PositionType.PREVIOUS){ PipingRules.addSizeChange(true, pipeRun, other, (InlineComponent)newComponent, toPcp, null); - newPcp.setWorldPosition(start); } + newPcp.setWorldPosition(pos); // TODO : chicken-egg problem newComponent.updateParameters(); - dir.scale(newComponent.getControlPoint().getLength()*0.5); - start.sub(dir); - end.add(dir); - if (position == PositionType.NEXT) { - newPcp.setWorldPosition(end); - } else if (position == PositionType.PREVIOUS){ - newPcp.setWorldPosition(start); - } + Vector3d v = new Vector3d(dir); + v.scale(newComponent.getControlPoint().getLength()*0.5); + switch (position) { + case NEXT: + pos.add(v); + break; + case PREVIOUS: + pos.sub(v); + break; + case SPLIT: + break; + } + newPcp.setWorldPosition(pos); + }