]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk.rendering/src/vtk/rendering/awt/vtkPanelComponent.java
Take values from pipe run as defaults for reducers
[simantics/3d.git] / vtk.rendering / src / vtk / rendering / awt / vtkPanelComponent.java
1 package vtk.rendering.awt;
2
3 import java.awt.event.MouseEvent;
4 import java.awt.event.MouseMotionAdapter;
5 import java.util.concurrent.locks.ReentrantLock;
6
7 import vtk.vtkCamera;
8 import vtk.vtkGenericRenderWindowInteractor;
9 import vtk.vtkInteractorStyle;
10 import vtk.vtkInteractorStyleTrackballCamera;
11 import vtk.vtkPanel;
12 import vtk.vtkRenderWindow;
13 import vtk.vtkRenderer;
14 import vtk.rendering.vtkComponent;
15 import vtk.rendering.vtkInteractorForwarder;
16
17 /**
18  * Provide AWT based vtk rendering component using the vtkPanel class
19  * while exposing everything as a new rendering component.
20  *
21  * @author Sebastien Jourdain - sebastien.jourdain@kitware.com
22  *
23  * Notes: This class should be replaced down the road by the vtkAwtComponent
24  *        but on some platform such as Windows the vtkAwtComponent
25  *        produce a runtime error regarding invalid pixel format while
26  *        the vtkPanelComponent which use vtkPanel works fine.
27  *        For now, this class provide a good substitute with just a minor overhead.
28  */
29
30 public class vtkPanelComponent implements vtkComponent<vtkPanel> {
31   protected vtkPanel panel;
32   protected ReentrantLock lock;
33   protected vtkGenericRenderWindowInteractor windowInteractor;
34   protected vtkInteractorForwarder eventForwarder;
35
36   public vtkPanelComponent() {
37     this.panel = new vtkPanel();
38     this.lock = new ReentrantLock();
39
40     // Init interactor
41     this.windowInteractor = new vtkGenericRenderWindowInteractor();
42     this.windowInteractor.SetRenderWindow(this.panel.GetRenderWindow());
43     this.windowInteractor.TimerEventResetsTimerOff();
44
45     this.windowInteractor.SetSize(200, 200);
46     this.windowInteractor.ConfigureEvent();
47
48     // Update style
49     vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera();
50     this.windowInteractor.SetInteractorStyle(style);
51
52     // Setup event forwarder
53     this.eventForwarder = new vtkInteractorForwarder(this);
54     this.windowInteractor.AddObserver("CreateTimerEvent", this.eventForwarder, "StartTimer");
55     this.windowInteractor.AddObserver("DestroyTimerEvent", this.eventForwarder, "DestroyTimer");
56
57     // Remove unwanted listeners
58     this.panel.removeKeyListener(this.panel);
59     this.panel.removeMouseListener(this.panel);
60     this.panel.removeMouseMotionListener(this.panel);
61     this.panel.removeMouseWheelListener(this.panel);
62
63     // Add mouse listener that update interactor
64     this.panel.addMouseListener(this.eventForwarder);
65     this.panel.addMouseMotionListener(this.eventForwarder);
66     this.panel.addMouseWheelListener(this.eventForwarder);
67
68     // Make sure we update the light position when interacting
69     this.panel.addMouseMotionListener(new MouseMotionAdapter() {
70       public void mouseDragged(MouseEvent e) {
71         panel.UpdateLight();
72       }
73     });
74   }
75
76   public void resetCamera() {
77     this.panel.resetCamera();
78   }
79
80   public void resetCameraClippingRange() {
81     this.panel.resetCameraClippingRange();
82   }
83
84   public vtkCamera getActiveCamera() {
85     return this.panel.GetRenderer().GetActiveCamera();
86   }
87
88   public vtkRenderer getRenderer() {
89     return this.panel.GetRenderer();
90   }
91
92   public vtkRenderWindow getRenderWindow() {
93     return this.panel.GetRenderWindow();
94   }
95
96   public vtkGenericRenderWindowInteractor getRenderWindowInteractor() {
97     return this.windowInteractor;
98   }
99
100   public void setInteractorStyle(vtkInteractorStyle style) {
101     this.getRenderWindowInteractor().SetInteractorStyle(style);
102   }
103
104   public void setSize(int w, int h) {
105     this.panel.setSize(w, h);
106     this.getRenderWindowInteractor().SetSize(w, h);
107   }
108
109   public vtkPanel getComponent() {
110     return this.panel;
111   }
112
113   public void Delete() {
114     this.panel.Delete();
115   }
116
117   public void Render() {
118     this.panel.Render();
119   }
120
121   public vtkInteractorForwarder getInteractorForwarder() {
122     return this.eventForwarder;
123   }
124
125   public ReentrantLock getVTKLock() {
126     return this.lock;
127   }
128 }