Additionally, re-using pipe routing for translating free ends.
gitlab #36
Change-Id: Ife8fc5ca4e5bae505bb95c488c3e2d263a29a188
@Override
public boolean mouseDragged(MouseEvent e) {
- if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) {
+ //if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) {
+ if (e.getButton() == MouseEvent.BUTTON1 && valid) {
Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate);
//System.out.println("translate " + translate);
private int decimals = 2;
private P3DRootNode root;
- private PipelineComponent startComponent;
- private PipeRun pipeRun;
+ protected PipelineComponent startComponent;
+ protected PipeRun pipeRun;
+ private boolean allowBranches;
- private TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
+ protected TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
private SplitPointSelectionGizmo splitPointSelectionGizmo;
private ConstraintPointGizmo constraintPointGizmo;
private TerminalSelectionGizmo terminalSelectionGizmo;
private NodeMap<Resource,vtkProp,INode> nodeMap;
- private enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING};
- private ToolState state = ToolState.NOT_ACTIVE;
+ protected enum ToolState{NOT_ACTIVE, INITIALIZING, SELECTING_POSITION, SELECTING_SPLIT, ROUTING};
+ protected ToolState state = ToolState.NOT_ACTIVE;
private ConstraintDetector detector;// = new DummyConstraintDetector();
- private boolean useDefault = false;
- private Vector3d direction = null;
- private Vector3d previousPosition = null;
- private Vector3d currentPosition = null;
+ protected boolean useDefault = false;
+ protected Vector3d direction = null;
+ protected Vector3d previousPosition = null;
+ protected Vector3d currentPosition = null;
boolean step = false;
private Set<PositionType> allowed = new HashSet<PositionType>();
-
public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) {
+ this(panel,root, true);
+ }
+
+ public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) {
super(panel);
this.root = root;
+ this.allowBranches = allowBranches;
setText("Route Pipe");
setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Straight.png"));
nodeMap = root.getNodeMap();
allowed.add(PositionType.NEXT);
if (this.startComponent.getPrevious() == null && !(this.startComponent instanceof Nozzle))
allowed.add(PositionType.PREVIOUS);
- if (this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixed())
+ if (allowBranches && this.startComponent instanceof InlineComponent && !this.startComponent.getControlPoint().isFixed())
allowed.add(PositionType.SPLIT);
setEnabled(allowed.size() > 0);
}
panel.unlock();
}
- private List<PipelineComponent> added = new ArrayList<PipelineComponent>();
+ protected List<PipelineComponent> added = new ArrayList<PipelineComponent>();
@Override
public boolean keyPressed(KeyEvent e) {
boolean startRemovable = false;
- private void activate() throws Exception {
+ protected void activate() throws Exception {
state = ToolState.INITIALIZING;
added.clear();
- private void activateNextPrev(PipeControlPoint start) throws Exception{
+ protected void activateNextPrev(PipeControlPoint start) throws Exception{
if (!reversed && start.isDualInline())
start = start.getSubPoint().get(0);
else if (reversed && start.isDualSub())
updateCurrentPoint();
}
- private void setPreviousPosition(Vector3d v) {
+ protected void setPreviousPosition(Vector3d v) {
previousPosition = new Vector3d(v);
if (translateAxisGizmo.isAttached())
translateAxisGizmo.setPosition(previousPosition);
addPoint();
}
} else {
- throw new RuntimeException("kjf");
+ throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found");
// // user was selecting position of branch
// lastPoint.set(startPoint);
// controlPoints.add(new Point3d(startPoint));
INode hoverObject = null;
- private void updateRouting(double x, double y) {
-// if(input.keyPressed(KeyEvent.VK_ESCAPE)) {
-// controlPoints.clear();
-// end();
-// return;
-// }
-// if (input.keyPressed(KeyEvent.VK_C)) {
-// useCamera = !useCamera;
-// cameraAction.setChecked(useCamera);
-// }
+ protected void updateRouting(double x, double y) {
if (useDefault) {
//panel.getDefaultAction().update();
return;
panel.refresh();
}
- private boolean updateCurrentPoint(Vector3d o, Vector3d d) {
+ protected boolean updateCurrentPoint(Vector3d o, Vector3d d) {
Vector3d point = new Vector3d(this.previousPosition);
return null;
}
- private void updateRoute(Vector3d o, Vector3d d) {
+ protected void updateRoute(Vector3d o, Vector3d d) {
detector.clearConstraintHighlights();
Point3d previousPipePoint = new Point3d(previousPosition);
String s = "";
}
private PositionType endingToStraight(INode straightNode, double mu[], Vector3d o, Vector3d d) {
+ if (!allowBranches) {
+ updateCurrentPoint();
+ return null;
+ }
InlineComponent s = (InlineComponent)straightNode;
String info = "";
Point3d sStart = new Point3d();
}
private PositionType endingLockToStraight(INode straightNode, double mu[]) {
+ if (!allowBranches) {
+ updateCurrentPoint();
+ return null;
+ }
InlineComponent s = (InlineComponent)straightNode;
Point3d sStart = new Point3d();
Point3d sEnd = new Point3d();
return null;
}
- private void addPoint() throws Exception {
+ protected void addPoint() throws Exception {
InlineComponent previous = (InlineComponent)getLast();
PipeControlPoint previousCP = previous.getControlPoint();
TurnComponent turn = ComponentUtils.createTurn(root);
/**
* Updates tool graphics for current point
*/
- private void updateCurrentPoint() {
+ protected void updateCurrentPoint() {
InlineComponent straight = (InlineComponent)added.get(added.size()-1);
// TODO: the inline length is from previous update step.
double l;
}
- private void endPiping() throws Exception {
+ protected void endPiping() throws Exception {
state = ToolState.NOT_ACTIVE;
if (endTo != null) {
--- /dev/null
+package org.simantics.plant3d.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.math.Ray;
+import org.simantics.g3d.scenegraph.IG3DNode;
+import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
+import org.simantics.g3d.vtk.utils.vtkUtil;
+import org.simantics.plant3d.Activator;
+import org.simantics.plant3d.actions.RoutePipeAction.LockType;
+import org.simantics.plant3d.actions.RoutePipeAction.ToolState;
+import org.simantics.plant3d.scenegraph.EndComponent;
+import org.simantics.plant3d.scenegraph.InlineComponent;
+import org.simantics.plant3d.scenegraph.Nozzle;
+import org.simantics.plant3d.scenegraph.P3DRootNode;
+import org.simantics.plant3d.scenegraph.PipelineComponent;
+import org.simantics.plant3d.scenegraph.TurnComponent;
+import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
+import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
+import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint.Direction;
+import org.simantics.plant3d.utils.ComponentUtils;
+
+public class TranslateFreeVariableLengthAction extends RoutePipeAction{
+
+ private InlineComponent component;
+
+ public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root) {
+ super(panel, root, false);
+ setText("Translate");
+ setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png"));
+ }
+
+
+ public void setNode(IG3DNode node) {
+ if (node instanceof InlineComponent) {
+ component = (InlineComponent)node;
+ if (component.isVariableLength() && (component.getNext() == null || component.getPrevious() == null)) {
+ PipelineComponent pathLegStart;
+ if (component.getNext() == null) {
+ pathLegStart = component.getControlPoint().findPreviousEnd().getPipelineComponent();
+ } else {
+ pathLegStart = component.getControlPoint().findNextEnd().getPipelineComponent();
+ }
+ setComponent(pathLegStart);
+
+ setEnabled(true);
+ } else {
+ setEnabled(false);
+ }
+ } else {
+ component = null;
+ setEnabled(false);
+ }
+ }
+
+ @Override
+ protected void activate() throws Exception {
+ state = ToolState.INITIALIZING;
+ added.clear();
+ pipeRun = startComponent.getPipeRun();
+ PipeControlPoint start = startComponent.getControlPoint();
+ activateNextPrev(start);
+ }
+
+ @Override
+ protected void activateNextPrev(PipeControlPoint start) throws Exception {
+ if (!reversed && start.isDualInline())
+ start = start.getSubPoint().get(0);
+ else if (reversed && start.isDualSub())
+ start = start.parent;
+
+ pipeRun = component.getPipeRun();
+
+ List<PipeControlPoint> cps = new ArrayList<PipeControlPoint>();
+ PipeControlPoint s = null;
+ if (component.getNext() == null) {
+ s = component.getControlPoint().findPreviousEnd(cps);
+ } else {
+ s = component.getControlPoint().findNextEnd(cps);
+ }
+ if (s.getPipelineComponent() != startComponent) {
+ throw new Exception("Path leg start mismatch");
+ }
+
+
+
+ setPreviousPosition(start.getWorldPosition());
+ currentPosition = component.getPosition();
+
+ if (startComponent instanceof Nozzle) {
+ direction = startComponent.getControlPoint().getDirectedControlPointDirection();
+ lock = LockType.CUSTOM;
+ } else if (startComponent instanceof PipelineComponent){
+ if (startComponent instanceof InlineComponent) {
+ direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT);
+ lock = LockType.CUSTOM;
+ if (((InlineComponent) startComponent).isVariableLength()) {
+ direction = null;
+ lock = LockType.NONE;
+ }
+ Vector3d v = new Vector3d();
+ if (!reversed) {
+ start.getControlPointEnds(v, previousPosition);
+ } else {
+ start.getControlPointEnds(previousPosition,v);
+ }
+ } else if (startComponent instanceof TurnComponent) {
+ if (start.isFixed()) {
+ direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT);
+ lock = LockType.CUSTOM;
+ } else {
+ direction = null;
+ lock = LockType.NONE;
+ }
+ } else if (startComponent instanceof EndComponent) {
+ throw new Exception("Not supported");
+ }
+
+ } else {
+ throw new Exception("Not supported");
+ }
+ currentPosition = new Vector3d(previousPosition);
+ state = ToolState.ROUTING;
+ if (direction != null) {
+ direction.normalize();
+
+ }
+ startRemovable = start.isDeletable();
+ start.setDeletable(false);
+ for (PipeControlPoint pcp : cps) {
+ added.add(pcp.getPipelineComponent());
+ pcp.setDeletable(false);
+ }
+ added.add(component);
+
+
+ translateAxisGizmo.attach(panel);
+ setPreviousPosition(previousPosition);
+ updateCurrentPoint();
+ }
+
+ @Override
+ public void deactivate() {
+ // TODO Auto-generated method stub
+ super.deactivate();
+ }
+
+ protected void addPoint() throws Exception {
+ // Translate action is not supposed to add points
+ return;
+ }
+
+ @Override
+ protected void endPiping() throws Exception {
+ state = ToolState.NOT_ACTIVE;
+ panel.useDefaultAction();
+ }
+
+ protected void updateRouting(double x, double y) {
+ if (useDefault) {
+ //panel.getDefaultAction().update();
+ return;
+ }
+
+ endTo = null;
+ endType = null;
+ endPort = null;
+
+ Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y);
+ Vector3d o = new Vector3d(ray.pos);
+ Vector3d d = ray.dir;
+
+
+ updateCurrentPoint(o, d);
+ updateRoute(o,d);
+ panel.refresh();
+ }
+
+
+}
public class TranslateInlineAction extends TranslateAction{
+ private boolean inline;
+
private Vector3d s;
private Vector3d e;
private Vector3d dir;
if (node instanceof InlineComponent) {
InlineComponent comp = (InlineComponent)node;
if (comp.isVariableLength()) {
- setEnabled(false);
- } else {
+ setEnabled(false);
+ } else if (comp.getNext() == null || comp.getPrevious() == null) {
+ setEnabled(true);
+ inline = false;
+ dir = comp.getControlPoint().getPathLegDirection(Direction.NEXT);
+ dir.normalize();
+ } else {
setEnabled(true);
-
+ inline = true;
PipelineComponent prev = comp.getPrevious();
PipelineComponent next = comp.getNext();
if (prev == null || next == null) {
public boolean keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
panel.useDefaultAction();
- if (valid)
- return true;
-
- update();
- return true;
+ if (!inline) {
+ return super.keyPressed(e);
+ } else {
+ if (valid)
+ return true;
+
+ update();
+ return true;
+ }
}
@Override
@Override
public boolean mouseDragged(MouseEvent e) {
- if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) {
-
- Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate);
- //System.out.println("translate " + translate);
- if (translate == null)
- return true;
- //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0);
- Vector3d pos = new Vector3d(node.getWorldPosition());
- //pos.add(translate);
- pos.set(translate);
- //pos = constaints(pos, step);
- setWorldPos(pos);
-
- //mapping.rangeModified(node);
-
- //nodeMap.modified(node);
- update();
+ //if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) {
+ if (e.getButton() == MouseEvent.BUTTON1 && valid) {
+ if (inline) {
+ Vector3d translate = getTranslate(e.getX(), e.getY(), prevTranslate);
+ //System.out.println("translate " + translate);
+ if (translate == null)
+ return true;
+ //boolean step = ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0);
+ Vector3d pos = new Vector3d(node.getWorldPosition());
+
+ System.out.println(pos + " " + translate);
+ //pos.add(translate);
+ pos.set(translate);
+ //pos = constaints(pos, step);
+ setWorldPos(pos);
+ update();
+ } else {
+ super.mouseDragged(e);
+ }
} else {
getDefaultAction().mouseDragged(e);
update();
- }
+ }
return true;
}
-
-
protected Vector3d getTranslate(double x, double y, Vector3d offset) {
Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y);
Vector3d p = node.getWorldPosition();
- Vector3d i1 = new Vector3d();
- Vector3d i2 = new Vector3d();
-
- double mu[] = new double[2];
- MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,mu);
-
- Vector3d t = MathTools.closestPointOnEdge(i1, s, e);
- return t;
+ if (inline) {
+ Vector3d i1 = new Vector3d();
+ Vector3d i2 = new Vector3d();
+
+ double mu[] = new double[2];
+ MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,mu);
+
+ Vector3d t = MathTools.closestPointOnEdge(i1, s, e);
+ return t;
+ } else {
+ return super.getTranslate(x, y, offset);
+ }
}
import org.simantics.plant3d.actions.AddNozzleAction;
import org.simantics.plant3d.actions.RemoveAndSplitAction;
import org.simantics.plant3d.actions.RoutePipeAction;
+import org.simantics.plant3d.actions.TranslateFreeVariableLengthAction;
import org.simantics.plant3d.actions.TranslateInlineAction;
import org.simantics.plant3d.ontology.Plant3D;
import org.simantics.plant3d.scenegraph.EndComponent;
private NodeSelectionProvider2<Resource,Object> selectionProvider;
- private vtkCameraAndSelectorAction cameraAction;
- private TranslateAction translateAction;
- private TranslateInlineAction translateInlineAction;
- private RotateAction rotateAction;
- private RemoveAction removeAction;
- private RemoveAndSplitAction removeSplitAction;
- private RoutePipeAction routePipeAction;
- private AddComponentAction addComponentAction;
+ protected vtkCameraAndSelectorAction cameraAction;
+ protected TranslateAction translateAction;
+ protected TranslateInlineAction translateInlineAction;
+ protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction;
+ protected RotateAction rotateAction;
+ protected RemoveAction removeAction;
+ protected RemoveAndSplitAction removeSplitAction;
+ protected RoutePipeAction routePipeAction;
+ protected AddComponentAction addComponentAction;
private P3DNodeMap nodeMap;
hookContextMenu();
createScene();
-
- //component.syncPopulate();
new ContextMenuListener(panel, contextMenu);
rootNode = (P3DRootNode)mapping.map(graph, input);
// update control points.
// TODO : this should be optimized.
-
-
-
+
try {
P3DUtil.finalizeDBLoad(rootNode);
nodeMap = createNodeMap(getSession(), mapping, panel,rootNode);
protected void createActions() {
translateAction = new TranslateAction(panel,nodeMap);
translateInlineAction = new TranslateInlineAction(panel, nodeMap);
+ translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode());
rotateAction = new RotateAction(panel,nodeMap);
removeAction = new RemoveAction(nodeMap) {
public void setNode(IG3DNode node) {
} else if (node instanceof InlineComponent) {
//m.add(translateInlineAction);
InlineComponent component = (InlineComponent)node;
- m.add(translateInlineAction);
+ if (component.isVariableLength())
+ m.add(translateFreeVariableLengthAction);
+ else
+ m.add(translateInlineAction);
m.add(routePipeAction);
routePipeAction.setComponent(component);
m.add(addComponentAction);
translateAction.setNode(node);
translateInlineAction.setNode(node);
+ translateFreeVariableLengthAction.setNode(node);
rotateAction.setNode(node);
removeAction.setNode(node);