import org.simantics.plant3d.dialog.ComponentSelectionDialog;
import org.simantics.plant3d.gizmo.TerminalSelectionGizmo;
import org.simantics.plant3d.scenegraph.InlineComponent;
+import org.simantics.plant3d.scenegraph.Nozzle;
import org.simantics.plant3d.scenegraph.P3DRootNode;
import org.simantics.plant3d.scenegraph.PipeRun;
import org.simantics.plant3d.scenegraph.PipelineComponent;
private Set<PositionType> allowed = new HashSet<PositionType>();
private Item toAdd = null;
+ private PositionType insertPosition;
+ private boolean insertAdjustable;
+ private boolean lengthAdjustable;
public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root) {
super(panel);
this.component = component;
allowed.clear();
- if (component.getNext() == null) {
- allowed.add(PositionType.NEXT);
- }
- if (component.getPrevious() == null) {
- allowed.add(PositionType.PREVIOUS);
- }
- if (component instanceof InlineComponent && !component.getControlPoint().isFixed()){
- allowed.add(PositionType.SPLIT);
+ if (component instanceof Nozzle) {
+ if (component.getNext() == null && component.getPrevious() == null) {
+ allowed.add(PositionType.NEXT);
+ }
+ } else {
+ if (component.getNext() == null) {
+ allowed.add(PositionType.NEXT);
+ }
+ if (component.getPrevious() == null) {
+ allowed.add(PositionType.PREVIOUS);
+ }
+ if (component instanceof InlineComponent && !component.getControlPoint().isFixed()){
+ allowed.add(PositionType.SPLIT);
+ }
}
setEnabled(allowed.size() > 0);
}
@Override
public void run() {
- ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed);
+
+ ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component);
if (dialog.open() == ComponentSelectionDialog.CANCEL)
return;
toAdd = dialog.getSelected();
if (toAdd == null)
return;
+ this.insertPosition = dialog.getInsertPosition();
+ this.insertAdjustable = dialog.isInsertAdjustable();
+ this.lengthAdjustable = dialog.isLenghtAdjustable();
this.length = dialog.getLength();
this.angle = dialog.getAngle();
this.diameter = dialog.getDiameter();
public void deattach() {
// deactivate();
component = null;
- nodeMap.commit();
+ nodeMap.commit("Add component");
deattachUI();
super.deattach();
panel.refresh();
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;
- }
+ if (!insertAdjustable || insertPosition == PositionType.NEXT) {
+ switch (position) {
+ case NEXT:
+ pos = new Vector3d(end);
+ break;
+ case PREVIOUS:
+ pos = new Vector3d(start);
+ break;
+ case SPLIT:
+ break;
+ }
+ } else if (insertPosition == PositionType.SPLIT) {
+ pos = new Vector3d(toPcp.getWorldPosition());
+ } else {
+ switch (position) {
+ case NEXT:
+ pos = new Vector3d(start);
+ break;
+ case PREVIOUS:
+ pos = new Vector3d(end);
+ break;
+ case SPLIT:
+ break;
+ }
+ }
} else if (toPcp.isDirected()) {
dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
} 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);
+ if (!lengthAdjustable) {
+ Vector3d v = new Vector3d(dir);
+ v.scale(toPcp.getInlineLength());
+ pos.add(v);
+ } else {
+ if (insertPosition == PositionType.NEXT) {
+ Vector3d v = new Vector3d(dir);
+ v.scale(toPcp.getInlineLength());
+ pos.add(v);
+ } else if (insertPosition == PositionType.SPLIT) {
+ // scale 0.5*length so that we don't remove the length twice from the new component
+ Vector3d v = new Vector3d(dir);
+ v.scale(toPcp.getInlineLength()*0.5);
+ pos.add(v);
+ }
+ }
}
newComponent.updateParameters();
Vector3d v = new Vector3d(dir);
- v.scale(newComponent.getControlPoint().getInlineLength());
+ if (insertAdjustable) {
+ if (insertPosition == PositionType.NEXT)
+ v.scale(newComponent.getControlPoint().getInlineLength());
+ else if (insertPosition == PositionType.SPLIT)
+ v.set(0, 0, 0);
+ else if (insertPosition == PositionType.PREVIOUS)
+ v.scale(-newComponent.getControlPoint().getInlineLength());
+ } else {
+ v.scale(newComponent.getControlPoint().getInlineLength());
+ }
switch (position) {
case NEXT:
pos.add(v);