1 package org.simantics.plant3d.gizmo;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import javax.vecmath.AxisAngle4d;
7 import javax.vecmath.Point3d;
8 import javax.vecmath.Tuple3d;
9 import javax.vecmath.Vector2d;
10 import javax.vecmath.Vector3d;
12 import org.eclipse.swt.events.MouseMoveListener;
13 import org.simantics.g3d.math.MathTools;
14 import org.simantics.g3d.math.Ray;
15 import org.simantics.g3d.scenegraph.RenderListener;
16 import org.simantics.g3d.shape.Color4d;
17 import org.simantics.g3d.shape.Cone;
18 import org.simantics.g3d.shape.Cylinder;
19 import org.simantics.g3d.shape.Mesh;
20 import org.simantics.g3d.vtk.common.VtkView;
21 import org.simantics.g3d.vtk.gizmo.vtkGizmo;
22 import org.simantics.g3d.vtk.shape.MeshActor;
23 import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
24 import org.simantics.g3d.vtk.utils.vtkUtil;
28 public class SplitPointSelectionGizmo extends vtkGizmo {
33 private RenderListener listener;
34 //private MouseMotionListener mouseListener;
35 private MouseMoveListener mouseListener;
41 Vector2d mousePos = new Vector2d();
43 Vector3d pa = new Vector3d();
44 Vector3d pb = new Vector3d();
46 Tuple3d splitPoint = null;
48 public SplitPointSelectionGizmo(VtkView panel) {
53 Mesh cone_x = Cone.create(0.1, res);
54 cone_x.rotate(MathTools.getQuat(new AxisAngle4d(0,0,-1,Math.PI*0.5)));
55 cone_x.translate(new Vector3d(0.8,0,0));
57 Mesh tube_x = Cylinder.create(MathTools.ORIGIN, new Vector3d(0.8,0,0), 0.05, res);
60 Color4d z_col = new Color4d(0,1,0,1);
61 tube_x.setColor(z_col);
63 actor = new MeshActor();
64 actor.setMesh(tube_x);
65 panel.addDeletable(actor);
67 this.listener = new RenderListener() {
69 public void preRender() {
70 Ray ray = vtkUtil.createMouseRay(SplitPointSelectionGizmo.this.panel.getRenderer(), mousePos.x, mousePos.y);
71 //ray.dir.add(ray.pos);
72 //if (MathTools.intersectLineLine(start, end, ray.pos, ray.dir, pa, pb)) {
73 double mu[] = new double[2];
74 if (MathTools.intersectStraightStraight(start, dir, ray.pos, ray.dir, pa, pb,mu)) {
80 Vector3d dir = new Vector3d(splitPoint);
82 double length = dir.length();
83 dir.scale(1.0/length);
84 AxisAngle4d aa = MathTools.createRotation(MathTools.X_AXIS, dir);
88 actor.SetVisibility(1);
91 actor.SetVisibility(0);
97 public void postRender() {
102 // this.mouseListener = new MouseMotionListener() {
105 // public void mouseMoved(MouseEvent e) {
106 // mousePos.x = e.getX();
107 // mousePos.y = e.getY();
108 // SplitPointSelectionGizmo.this.panel.refresh();
112 // public void mouseDragged(MouseEvent e) {
113 // mousePos.x = e.getX();
114 // mousePos.y = e.getY();
115 // SplitPointSelectionGizmo.this.panel.refresh();
118 this.mouseListener = new MouseMoveListener() {
121 public void mouseMove(org.eclipse.swt.events.MouseEvent e) {
124 SplitPointSelectionGizmo.this.panel.refresh();
131 public void setSplit(Point3d start, Point3d end) {
134 dir = new Vector3d(end);
139 public void attach(VtkView renderingPart) {
140 super.attach(renderingPart);
141 panel.addListener(listener);
143 //panel.addMouseMotionListener(mouseListener);
144 ((InteractiveVtkComposite)panel).getComponent().addMouseMoveListener(mouseListener);
148 public void deattach() {
149 panel.removeListener(listener);
151 //panel.removeMouseMotionListener(mouseListener);
156 public Collection<vtkProp> getGizmo() {
157 Collection<vtkProp> coll = new ArrayList<vtkProp>();
162 public Tuple3d getSplitPoint() {