From: Marko Luukkainen Date: Tue, 12 Nov 2019 16:54:47 +0000 (+0200) Subject: Editor internal toolbar for Plant3D editor X-Git-Tag: v1.43.0~125 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F3510%2F2;p=simantics%2F3d.git Editor internal toolbar for Plant3D editor gitlab #54 Change-Id: I68dece53eaad866e10d67e5920248c187a66b1ad --- diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java index 9cf39eff..f9ea1877 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java @@ -21,8 +21,13 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.EulerTools; import org.simantics.g3d.math.EulerTools.Order; import org.simantics.g3d.math.MathTools; @@ -31,6 +36,7 @@ import org.simantics.g3d.preferences.PreferenceConstants; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.RotateAxisGizmo; @@ -77,6 +83,9 @@ public class RotateAction extends vtkSwtAction{ //AxisAngle4d rotation = new AxisAngle4d(); Quat4d worldOrientation = new Quat4d(); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -105,12 +114,12 @@ public class RotateAction extends vtkSwtAction{ return node; } - public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_rotate_clockwise.png")); setText("Rotate"); this.nodeMap = nodeMap; - + this.toolComposite = toolComposite; steps = 36; angles = new double[steps+1]; @@ -122,10 +131,41 @@ public class RotateAction extends vtkSwtAction{ dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_CROSS); } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Rotate axis:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + public void attach() { if (node == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -139,7 +179,10 @@ public class RotateAction extends vtkSwtAction{ } public void deattach() { - + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; nodeMap.commit("Rotate"); deattachUI(); @@ -184,11 +227,19 @@ public class RotateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); - panel.refresh(); + + updateLock(); + return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } + @Override public boolean keyReleased(KeyEvent e) { return false; @@ -227,7 +278,7 @@ public class RotateAction extends vtkSwtAction{ private void update() { Vector3d nodePos = node.getWorldPosition(); - System.out.println(nodePos); +// System.out.println(nodePos); gizmo.setPosition(nodePos); if (worldCoord) { gizmo.setRotation(new AxisAngle4d()); @@ -408,7 +459,7 @@ public class RotateAction extends vtkSwtAction{ // intersection point j.set(i2); i.cross(j, axis); - System.out.println("I,J " + i + " " + j); +// System.out.println("I,J " + i + " " + j); double angleI = i2.angle(i); double angleJ = i2.angle(j); prevAngle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); @@ -436,7 +487,7 @@ public class RotateAction extends vtkSwtAction{ taxis = new Vector3d(axis); MathTools.rotate(parentWorldOrientation, axis, axis); } - System.out.println(inputType); +// System.out.println(inputType); if (inputType == InputType.INTERSECT) { double s[] = new double[2]; @@ -446,7 +497,7 @@ public class RotateAction extends vtkSwtAction{ double angleI = i2.angle(i); double angleJ = i2.angle(j); double angle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); - System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); +// System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); if(!worldCoord) axis = taxis; if (useStep) { @@ -475,7 +526,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -530,7 +581,7 @@ public class RotateAction extends vtkSwtAction{ //Quat4d q = MathTools.getQuat(euler); Quat4d q = EulerTools.getQuatFromEuler(order, euler); setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); } else { setOrientation(qrot); } @@ -614,8 +665,7 @@ public class RotateAction extends vtkSwtAction{ case Z: return new Vector3d(0.0, 0.0, 1.0); case P: - Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera() - .GetDirectionOfProjection()); + Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera().GetDirectionOfProjection()); axis.normalize(); return axis; default: diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java index 32b97c1b..682112cf 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java @@ -22,13 +22,19 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.TranslateAxisGizmo; @@ -57,6 +63,9 @@ public class TranslateAction extends vtkSwtAction{ private Cursor activeCursor;// = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); private Cursor dragCursor;// = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -70,7 +79,7 @@ public class TranslateAction extends vtkSwtAction{ return node; } - public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public TranslateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_out.png")); setText("Translate"); @@ -78,11 +87,46 @@ public class TranslateAction extends vtkSwtAction{ activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL); + this.toolComposite = toolComposite; + } + + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Translate direction:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("XY"); + axisCombo.add("XZ"); + axisCombo.add("YZ"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); } public void attach() { if (node == null) return; + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { @@ -91,12 +135,13 @@ public class TranslateAction extends vtkSwtAction{ update(); } }); - - - } public void deattach() { + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; nodeMap.commit("Translate"); @@ -142,13 +187,19 @@ public class TranslateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); + updateLock(); update(); //panel.repaint(); return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } @Override @@ -422,65 +473,65 @@ public class TranslateAction extends vtkSwtAction{ translate.x = s[0]; break; - case Y : - dir = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.y = s[0]; - break; - case Z : - dir = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.z = s[0]; - break; - case XY : - normal = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.y = r.y; - } - break; - case XZ : - normal = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.z = r.z; - } - break; - case YZ : - normal = new Vector3d(1.0,0.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.y = r.y; - translate.z = r.z; - } - break; - default : - - return null; + case Y : + dir = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.y = s[0]; + break; + case Z : + dir = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.z = s[0]; + break; + case XY : + normal = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.y = r.y; + } + break; + case XZ : + normal = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.z = r.z; + } + break; + case YZ : + normal = new Vector3d(1.0,0.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.y = r.y; + translate.z = r.z; } - translate.sub(offset); - return translate; + break; + default : + + return null; + } + translate.sub(offset); + return translate; } } diff --git a/org.simantics.g3d/META-INF/MANIFEST.MF b/org.simantics.g3d/META-INF/MANIFEST.MF index 7e889b35..d89a00f5 100644 --- a/org.simantics.g3d/META-INF/MANIFEST.MF +++ b/org.simantics.g3d/META-INF/MANIFEST.MF @@ -35,6 +35,7 @@ Export-Package: org.simantics.g3d, org.simantics.g3d.scenegraph.structural, org.simantics.g3d.scl, org.simantics.g3d.shape, + org.simantics.g3d.toolbar, org.simantics.g3d.tools, org.simantics.g3d.ui, org.simantics.g3d.wizard diff --git a/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java b/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java new file mode 100644 index 00000000..2fabeeee --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/toolbar/ToolComposite.java @@ -0,0 +1,31 @@ +package org.simantics.g3d.toolbar; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class ToolComposite extends Composite{ + + public ToolComposite(Composite parent, int style) { + super(parent, style|SWT.BORDER); + RowLayout layout = new RowLayout(); + layout.center = true; + layout.marginBottom = 1; + layout.marginTop = 1; + setLayout(layout); + } + + public void clear() { + Control children[] = getChildren(); + for (Control c : children) + c.dispose(); + relayout(); + } + + public void relayout() { + getParent().layout(true); + layout(true); + } + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java index 9f523c95..389f3be5 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java @@ -13,11 +13,18 @@ import javax.vecmath.Point3d; import javax.vecmath.Tuple3d; import javax.vecmath.Vector3d; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Label; import org.simantics.db.Resource; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.tools.ConstraintDetector; import org.simantics.g3d.vtk.gizmo.TranslateAxisGizmo; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; @@ -47,7 +54,7 @@ import vtk.vtkTextActor; public class RoutePipeAction extends vtkSwtAction { enum LockType { - X, Y, Z, XY, YZ, XZ, NONE, CUSTOM + X, Y, Z, XY, XZ, YZ, NONE, CUSTOM }; LockType lock = LockType.NONE; @@ -91,11 +98,15 @@ public class RoutePipeAction extends vtkSwtAction { private Set allowed = new HashSet(); - public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root) { - this(panel,root, true); + protected ToolComposite toolComposite; + protected Combo axisCombo; + protected Button cameraButton; + + public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite) { + this(panel,root, toolComposite, true); } - public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, boolean allowBranches) { + public RoutePipeAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite, boolean allowBranches) { super(panel); this.root = root; this.allowBranches = allowBranches; @@ -106,6 +117,7 @@ public class RoutePipeAction extends vtkSwtAction { terminalSelectionGizmo = new TerminalSelectionGizmo(panel); constraintPointGizmo = new ConstraintPointGizmo(panel); detector = new org.simantics.g3d.vtk.swt.ConstraintDetector(panel); + this.toolComposite = toolComposite; } public void setComponent(PipelineComponent component) { @@ -120,19 +132,69 @@ public class RoutePipeAction extends vtkSwtAction { setEnabled(allowed.size() > 0); } - public void deattach() { - deactivate(); - startComponent = null; - - deattachUI(); - super.deattach(); - panel.refresh(); - } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Route direction:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("XY"); + axisCombo.add("XZ"); + axisCombo.add("YZ"); + axisCombo.add("None"); + axisCombo.add("Custom"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + setLockType(LockType.values()[c.getSelectionIndex()],false); + panel.getComponent().setFocus(); + + } + }); + axisCombo.select(lock.ordinal()); + cameraButton = new Button(toolComposite, SWT.TOGGLE); + cameraButton.setText("Camera"); + cameraButton.setSelection(useDefault); + cameraButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setUseDefault(((Button)e.getSource()).getSelection()); + panel.getComponent().setFocus(); + } + }); + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + + public void deattach() { + deactivate(); + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + cameraButton = null; + } + + startComponent = null; + + deattachUI(); + super.deattach(); + panel.refresh(); + } public void attach() { if (startComponent == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -236,19 +298,21 @@ public class RoutePipeAction extends vtkSwtAction { } } if (e.getKeyCode() == KeyEvent.VK_C) { - useDefault = !useDefault; - if (useDefault) - setInfoText("Rotating camera"); - System.out.println("UseDefault " + useDefault); + setUseDefault(!useDefault); } - - - update(); return true; } + private void setUseDefault(boolean b) { + useDefault = b; + if (useDefault) + setInfoText("Rotating camera"); + if (cameraButton != null) + cameraButton.setSelection(useDefault); + } + private void update() { panel.refresh(); @@ -387,6 +451,7 @@ public class RoutePipeAction extends vtkSwtAction { translateAxisGizmo.attach(panel); setPreviousPosition(previousPosition); updateCurrentPoint(); + updateWidget(); } protected void setPreviousPosition(Vector3d v) { @@ -433,6 +498,7 @@ public class RoutePipeAction extends vtkSwtAction { translateAxisGizmo.attach(panel); setPreviousPosition(previousPosition); updateCurrentPoint(); + updateWidget(); } private void activateSplit(PipeControlPoint start) throws Exception{ @@ -482,7 +548,10 @@ public class RoutePipeAction extends vtkSwtAction { } private void setLockType(LockType type, boolean force) { - if (force || (lock != LockType.CUSTOM || !lockForced) ) { + if (type == LockType.CUSTOM && (direction == null || added.size() > 0)) { + // nothing to do.. + } else if (force || (lock != LockType.CUSTOM || !lockForced || added.size() > 0) ) { + lock = type; switch (lock) { @@ -510,7 +579,16 @@ public class RoutePipeAction extends vtkSwtAction { break; } + } + updateWidget(); + } + + private void updateWidget() { + if (axisCombo != null) { + axisCombo.select(lock.ordinal()); + axisCombo.setEnabled(!lockForced || lock != LockType.CUSTOM); + } } @Override @@ -557,7 +635,7 @@ public class RoutePipeAction extends vtkSwtAction { addPoint(); } } else { - throw new RuntimeException("RoutePipeAction initlialization has been failed, no added components found"); + throw new RuntimeException("RoutePipeAction initialization has failed, no added components found"); // // user was selecting position of branch // lastPoint.set(startPoint); // controlPoints.add(new Point3d(startPoint)); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java index b76989e1..c9bdea17 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java @@ -7,6 +7,7 @@ import javax.vecmath.Vector3d; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; import org.simantics.g3d.vtk.utils.vtkUtil; import org.simantics.plant3d.Activator; @@ -23,8 +24,8 @@ public class TranslateFreeVariableLengthAction extends RoutePipeAction{ private InlineComponent component; - public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root) { - super(panel, root, false); + public TranslateFreeVariableLengthAction(InteractiveVtkComposite panel, P3DRootNode root, ToolComposite toolComposite) { + super(panel, root, toolComposite, false); setText("Translate"); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java index 3c5886d8..9001d0a7 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -10,6 +10,7 @@ import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.swt.InteractiveVtkComposite; import org.simantics.g3d.vtk.swt.TranslateAction; @@ -27,8 +28,8 @@ public class TranslateInlineAction extends TranslateAction{ private Vector3d e; private Vector3d dir; - public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { - super(panel, nodeMap); + public TranslateInlineAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { + super(panel, nodeMap, toolComposite); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_refresh.png")); } @@ -89,6 +90,11 @@ public class TranslateInlineAction extends TranslateAction{ } } + @Override + protected void createTools(ToolComposite toolComposite) { + + } + @Override public boolean keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 5d755d06..4059d938 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -8,9 +8,12 @@ import java.util.Set; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.layout.FillLayout; @@ -25,6 +28,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.RenderListener; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.action.RemoveAction; import org.simantics.g3d.vtk.common.HoverHighlighter; import org.simantics.g3d.vtk.common.NodeSelectionProvider2; @@ -89,10 +93,12 @@ import vtk.vtkSimpleMotionBlurPass; public class Plant3DEditor extends ResourceEditorPart { private Composite parent; + protected ToolComposite toolComposite; private Resource input; // private InteractiveVtkPanel panel; // private SWTAWTComponent component; private InteractiveVtkComposite panel; + private P3DRootNode rootNode; private IMapping mapping; @@ -117,7 +123,9 @@ public class Plant3DEditor extends ResourceEditorPart { @Override public void createPartControl(Composite parent) { this.parent = parent; - parent.setLayout (new FillLayout ()); + //parent.setLayout (new FillLayout ()); + + // component = new SWTAWTComponent(parent,SWT.NONE) { // // @Override @@ -134,9 +142,17 @@ public class Plant3DEditor extends ResourceEditorPart { IResourceEditorInput rei = (IResourceEditorInput)getEditorInput(); input = rei.getResource(); + toolComposite = new ToolComposite(parent, SWT.BORDER); + toolComposite.setVisible(true); + panel = new InteractiveVtkComposite(parent); + GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(parent); + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(getPanel().getComponent()); + + GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(toolComposite); + //IActionBars actionBars = getEditorSite().getActionBars(); hookContextMenu(); @@ -246,13 +262,13 @@ public class Plant3DEditor extends ResourceEditorPart { protected void createActions() { focusAction = new FocusAction(panel, cameraAction); - translateAction = new TranslateAction(panel,nodeMap); - translateInlineAction = new TranslateInlineAction(panel, nodeMap); - translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode()); - rotateAction = new RotateAction(panel,nodeMap); + translateAction = new TranslateAction(panel,nodeMap,toolComposite); + translateInlineAction = new TranslateInlineAction(panel, nodeMap,toolComposite); + translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode(), toolComposite); + rotateAction = new RotateAction(panel,nodeMap,toolComposite); removeAction = new RemoveAction(nodeMap); removeSplitAction = new RemoveAndSplitAction(nodeMap); - routePipeAction = new RoutePipeAction(panel,rootNode); + routePipeAction = new RoutePipeAction(panel,rootNode, toolComposite); addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri()); reversePipeRunAction = new ReversePipeRunAction(nodeMap); }