X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=vtk%2Fsrc%2Fvtk%2FvtkCanvas.java;h=6fcfb7fb0c47105b945fff2cbe95c026f7a253aa;hb=c39250eb0521cf4e6d69f472f4fdf9e8b877c6e4;hp=660b903d39524919255556b006db26f2a903f811;hpb=471c46e9a685e20de958d77166461aebc7a7b6ee;p=simantics%2F3d.git diff --git a/vtk/src/vtk/vtkCanvas.java b/vtk/src/vtk/vtkCanvas.java index 660b903d..6fcfb7fb 100644 --- a/vtk/src/vtk/vtkCanvas.java +++ b/vtk/src/vtk/vtkCanvas.java @@ -10,6 +10,8 @@ import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import javax.swing.Timer; @@ -20,248 +22,263 @@ import javax.swing.Timer; * @see vtkPanel * @author Kitware */ -public class vtkCanvas extends vtkPanel implements MouseListener, MouseMotionListener, KeyListener { - private static final long serialVersionUID = 1L; - protected vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor(); - protected Timer timer = new Timer(10, new DelayAction()); - protected int ctrlPressed = 0; - protected int shiftPressed = 0; - protected vtkPlaneWidget pw = new vtkPlaneWidget(); - protected vtkBoxWidget bw = new vtkBoxWidget(); - - static { - // load up hybrid for 3d widgets - vtkNativeLibrary.HYBRID.LoadLibrary(); - vtkNativeLibrary.WIDGETS.LoadLibrary(); +public class vtkCanvas extends vtkPanel implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener { + private static final long serialVersionUID = 1L; + protected vtkGenericRenderWindowInteractor iren = new vtkGenericRenderWindowInteractor(); + protected Timer timer = new Timer(10, new DelayAction()); + protected int ctrlPressed = 0; + protected int shiftPressed = 0; + protected vtkPlaneWidget pw = new vtkPlaneWidget(); + protected vtkBoxWidget bw = new vtkBoxWidget(); + + public void Delete() { + iren = null; + pw = null; + bw = null; + super.Delete(); + } + + public vtkCanvas() { + super(); + Initialize(); + } + + public vtkCanvas(vtkRenderWindow renwin) { + super(renwin); + Initialize(); + } + + protected void Initialize() { + iren.SetRenderWindow(rw); + iren.TimerEventResetsTimerOff(); + iren.AddObserver("CreateTimerEvent", this, "StartTimer"); + iren.AddObserver("DestroyTimerEvent", this, "DestroyTimer"); + iren.SetSize(200, 200); + iren.ConfigureEvent(); + pw.AddObserver("EnableEvent", this, "BeginPlaneInteraction"); + bw.AddObserver("EnableEvent", this, "BeginBoxInteraction"); + pw.SetKeyPressActivationValue('l'); + bw.SetKeyPressActivationValue('b'); + pw.SetInteractor(iren); + bw.SetInteractor(iren); + + addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent event) { + // The Canvas is being resized, get the new size + int width = getWidth(); + int height = getHeight(); + setSize(width, height); + } + }); + + ren.SetBackground(0.0, 0.0, 0.0); + + // Setup same interactor style than vtkPanel + vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); + iren.SetInteractorStyle(style); + } + + public void StartTimer() { + if (timer.isRunning()) + timer.stop(); + + timer.setRepeats(true); + timer.start(); + } + + public void DestroyTimer() { + if (timer.isRunning()) + timer.stop(); + } + + /** + * Replace by getRenderWindowInteractor() + */ + @Deprecated + public vtkGenericRenderWindowInteractor getIren() { + return this.iren; + } + + public vtkGenericRenderWindowInteractor getRenderWindowInteractor() { + return this.iren; + } + + public void setInteractorStyle(vtkInteractorStyle style) { + iren.SetInteractorStyle(style); + } + + public void addToPlaneWidget(vtkProp3D prop) { + pw.SetProp3D(prop); + pw.PlaceWidget(); + } + + public void addToBoxWidget(vtkProp3D prop) { + bw.SetProp3D(prop); + bw.PlaceWidget(); + } + + public void BeginPlaneInteraction() { + System.out.println("Plane widget begin interaction"); + } + + public void BeginBoxInteraction() { + System.out.println("Box widget begin interaction"); + } + + public void setSize(int x, int y) { + super.setSize(x, y); + if (windowset == 1) { + Lock(); + rw.SetSize(x, y); + iren.SetSize(x, y); + iren.ConfigureEvent(); + UnLock(); } - - public void Delete() { - iren = null; - pw = null; - bw = null; - super.Delete(); - } - - public vtkCanvas() { - super(); - Initialize(); - } - - public vtkCanvas(vtkRenderWindow renwin) { - super(renwin); - Initialize(); + } + + public void mouseClicked(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + if (ren.VisibleActorCount() == 0) + return; + Lock(); + rw.SetDesiredUpdateRate(5.0); + lastX = e.getX(); + lastY = e.getY(); + + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; + + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { + iren.LeftButtonPressEvent(); + } else if ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { + iren.MiddleButtonPressEvent(); + } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { + iren.RightButtonPressEvent(); } + UnLock(); + } - protected void Initialize() { - iren.SetRenderWindow(rw); - iren.TimerEventResetsTimerOff(); - iren.AddObserver("CreateTimerEvent", this, "StartTimer"); - iren.AddObserver("DestroyTimerEvent", this, "DestroyTimer"); - iren.SetSize(200, 200); - iren.ConfigureEvent(); - pw.AddObserver("EnableEvent", this, "BeginPlaneInteraction"); - bw.AddObserver("EnableEvent", this, "BeginBoxInteraction"); - pw.SetKeyPressActivationValue('l'); - bw.SetKeyPressActivationValue('b'); - pw.SetInteractor(iren); - bw.SetInteractor(iren); - - addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent event) { - // The Canvas is being resized, get the new size - int width = getWidth(); - int height = getHeight(); - setSize(width, height); - } - }); - - ren.SetBackground(0.0, 0.0, 0.0); - - // Setup same interactor style than vtkPanel - vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera(); - iren.SetInteractorStyle(style); - } + public void mouseReleased(MouseEvent e) { + rw.SetDesiredUpdateRate(0.01); - public void StartTimer() { - if (timer.isRunning()) - timer.stop(); + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - timer.setRepeats(true); - timer.start(); - } + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); - public void DestroyTimer() { - if (timer.isRunning()) - timer.stop(); + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { + Lock(); + iren.LeftButtonReleaseEvent(); + UnLock(); } - /** - * Replace by getRenderWindowInteractor() - */ - @Deprecated - public vtkGenericRenderWindowInteractor getIren() { - return this.iren; + if ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { + Lock(); + iren.MiddleButtonReleaseEvent(); + UnLock(); } - public vtkGenericRenderWindowInteractor getRenderWindowInteractor() { - return this.iren; + if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { + Lock(); + iren.RightButtonReleaseEvent(); + UnLock(); } + } - public void setInteractorStyle(vtkInteractorStyle style) { - iren.SetInteractorStyle(style); - } + public void mouseEntered(MouseEvent e) { + this.requestFocus(); + iren.SetEventInformationFlipY(e.getX(), e.getY(), 0, 0, '0', 0, "0"); + iren.EnterEvent(); + } - public void addToPlaneWidget(vtkProp3D prop) { - pw.SetProp3D(prop); - pw.PlaceWidget(); - } + public void mouseExited(MouseEvent e) { + iren.SetEventInformationFlipY(e.getX(), e.getY(), 0, 0, '0', 0, "0"); + iren.LeaveEvent(); + } - public void addToBoxWidget(vtkProp3D prop) { - bw.SetProp3D(prop); - bw.PlaceWidget(); - } + public void mouseMoved(MouseEvent e) { + lastX = e.getX(); + lastY = e.getY(); - public void BeginPlaneInteraction() { - System.out.println("Plane widget begin interaction"); - } + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - public void BeginBoxInteraction() { - System.out.println("Box widget begin interaction"); - } + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); - public void setSize(int x, int y) { - super.setSize(x, y); - if (windowset == 1) { - Lock(); - rw.SetSize(x, y); - iren.SetSize(x, y); - iren.ConfigureEvent(); - UnLock(); - } - } + Lock(); + iren.MouseMoveEvent(); + UnLock(); + } - public void mouseClicked(MouseEvent e) { - } + public void mouseDragged(MouseEvent e) { + if (ren.VisibleActorCount() == 0) + return; - public void mousePressed(MouseEvent e) { - if (ren.VisibleActorCount() == 0) - return; - Lock(); - rw.SetDesiredUpdateRate(5.0); - lastX = e.getX(); - lastY = e.getY(); - - ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; - shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - - iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); - - if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { - iren.LeftButtonPressEvent(); - } else if ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { - iren.MiddleButtonPressEvent(); - } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - iren.RightButtonPressEvent(); - } - UnLock(); - } + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - public void mouseReleased(MouseEvent e) { - rw.SetDesiredUpdateRate(0.01); + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); - ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; - shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; + Lock(); + iren.MouseMoveEvent(); + UnLock(); - iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + UpdateLight(); + } - if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { - Lock(); - iren.LeftButtonReleaseEvent(); - UnLock(); - } + public void mouseWheelMoved(MouseWheelEvent e) { + if (ren.VisibleActorCount() == 0) + return; - if ((e.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { - Lock(); - iren.MiddleButtonReleaseEvent(); - UnLock(); - } + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - Lock(); - iren.RightButtonReleaseEvent(); - UnLock(); - } + Lock(); + if (e.getWheelRotation() > 0) { + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + iren.MouseWheelBackwardEvent(); } - - public void mouseEntered(MouseEvent e) { - this.requestFocus(); - iren.SetEventInformationFlipY(e.getX(), e.getY(), 0, 0, '0', 0, "0"); - iren.EnterEvent(); + else if (e.getWheelRotation() < 0) { + iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + iren.MouseWheelForwardEvent(); } + UnLock(); - public void mouseExited(MouseEvent e) { - iren.SetEventInformationFlipY(e.getX(), e.getY(), 0, 0, '0', 0, "0"); - iren.LeaveEvent(); - } - - public void mouseMoved(MouseEvent e) { - lastX = e.getX(); - lastY = e.getY(); - - ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; - shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - - iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + UpdateLight(); + } - Lock(); - iren.MouseMoveEvent(); - UnLock(); - } - - public void mouseDragged(MouseEvent e) { - if (ren.VisibleActorCount() == 0) - return; + public void keyTyped(KeyEvent e) { + } - ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; - shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; + public void keyPressed(KeyEvent e) { + if (ren.VisibleActorCount() == 0) + return; + char keyChar = e.getKeyChar(); - iren.SetEventInformationFlipY(e.getX(), e.getY(), ctrlPressed, shiftPressed, '0', 0, "0"); + ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; + shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - Lock(); - iren.MouseMoveEvent(); - UnLock(); + iren.SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, keyChar, 0, String.valueOf(keyChar)); - UpdateLight(); - } + Lock(); + iren.KeyPressEvent(); + iren.CharEvent(); + UnLock(); + } - public void keyTyped(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - if (ren.VisibleActorCount() == 0) - return; - char keyChar = e.getKeyChar(); - - ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0; - shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0; - - iren.SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, keyChar, 0, String.valueOf(keyChar)); - - Lock(); - iren.KeyPressEvent(); - iren.CharEvent(); - UnLock(); - } - - public void keyReleased(KeyEvent e) { - } + public void keyReleased(KeyEvent e) { + } - private class DelayAction implements ActionListener { - public void actionPerformed(ActionEvent evt) { - Lock(); - iren.TimerEvent(); - UpdateLight(); - UnLock(); - } + private class DelayAction implements ActionListener { + public void actionPerformed(ActionEvent evt) { + Lock(); + iren.TimerEvent(); + UpdateLight(); + UnLock(); } + } }