]> Creatis software - bbtk.git/blob - packages/wxvtk/src/wxVTKRenderWindowInteractor.h
Viewer2D Viewer3D Linux
[bbtk.git] / packages / wxvtk / src / wxVTKRenderWindowInteractor.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: wxVTKRenderWindowInteractor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/06/26 18:45:58 $
7   Version:   $Revision: 1.2 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18
19 // .NAME  wxVTKRenderWindowInteractor - class to enable VTK to render to 
20 // and interact with wxWindow.
21 // .SECTION Description
22 //  wxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class
23 // was completely rewrote to have the 'Look & Feel' of the python version:
24 // wxVTKRenderWindowInteractor.py
25 // .SECTION Caveats 
26 //  - There is a know bug that prevent this class to works for more info see 
27 // WX_USE_X_CAPTURE. This bug only affect wxGTK from 2.3.2 to wxGTK 2.4.0.
28 //  - Furthermore this class is tempated over either wxWindows or wxGLCanvas,
29 // in wxWindows 2.3.1 and earlier, the wxGLCanvas had scroll bars, you can avoid
30 // this effect by playing with WX_BASE_CLASS at your risk (you might end up with
31 // lot of flickering.)
32 //  - This class might not be easily readable as it tried to work with VTK 3.2
33 //  and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier.
34 // .SECTION see also
35 // wxVTKRenderWindowInteractor.py wxVTKRenderWindow.py
36
37 #ifndef _wxVTKRenderWindowInteractor_h_
38 #define _wxVTKRenderWindowInteractor_h_
39
40 // For compilers that support precompilation, includes "wx/wx.h".
41 #include "wx/wxprec.h"
42
43 #ifdef __BORLANDC__
44 #  pragma hdrstop
45 #endif
46
47 #ifndef WX_PRECOMP
48 #include <wx/wx.h>
49 #endif
50
51 #include <wx/timer.h>
52 #include <wx/dcclient.h>
53
54 // vtk includes
55 #include "vtkRenderWindowInteractor.h"
56 #include "vtkRenderWindow.h"
57
58 // Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any
59 // other port):
60 #if (!wxCHECK_VERSION(2, 8, 0))
61 #define USE_WXGLCANVAS
62 #endif
63
64
65 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
66 # if wxUSE_GLCANVAS
67 #    include <wx/glcanvas.h>
68 # else
69 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
70 # endif //wxUSE_GLCANVAS
71 #endif //__WXGTK__
72
73 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
74 #if defined(__WXMOTIF__) 
75 # error This GUI is not supported by wxVTKRenderWindowInteractor for now
76 #endif
77
78
79 // wx forward declarations
80 class wxPaintEvent;
81 class wxMouseEvent;
82 class wxTimerEvent;
83 class wxKeyEvent;
84 class wxSizeEvent;
85
86 //=======================================================================
87 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
88 namespace bbwxvtk
89 {
90
91
92 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
93 class VTK_RENDERING_EXPORT wxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor
94 #else
95 class /*VTK_RENDERING_EXPORT*/ wxVTKRenderWindowInteractor : public wxWindow, virtual public vtkRenderWindowInteractor
96 #endif //__WXGTK__
97 {
98   DECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor)
99   
100   public:
101     //constructors
102     wxVTKRenderWindowInteractor();
103
104     wxVTKRenderWindowInteractor(wxWindow *parent,
105                                 wxWindowID id,
106                                 const wxPoint &pos = wxDefaultPosition,
107                                 const wxSize &size = wxDefaultSize,
108                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
109                                 const wxString &name = wxPanelNameStr);
110         //vtk ::New()
111     static wxVTKRenderWindowInteractor * New();
112     void PrintSelf(ostream& os, vtkIndent indent);
113
114           //destructor
115     ~wxVTKRenderWindowInteractor();
116
117 #if defined(_WIN32)
118     const char * wxVTKRenderWindowInteractor::GetClassName() const;
119 #endif //_WIN32
120
121
122     // vtkRenderWindowInteractor overrides
123     void Initialize();
124     void Enable();
125     bool Enable(bool enable);
126     void Disable();
127     void Start();
128     void UpdateSize(int x, int y);
129     int CreateTimer(int timertype);
130     int DestroyTimer();
131     void TerminateApp() {};
132
133     // event handlers
134     void OnPaint(wxPaintEvent &event);
135     void OnEraseBackground (wxEraseEvent& event);
136     void OnMotion(wxMouseEvent &event);
137
138     void OnButtonDown(wxMouseEvent &event);
139     void OnButtonUp(wxMouseEvent &event);
140 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
141     void OnEnter(wxMouseEvent &event);
142     void OnLeave(wxMouseEvent &event);
143     void OnKeyDown(wxKeyEvent &event);
144     void OnKeyUp(wxKeyEvent &event);
145 #endif
146     void OnTimer(wxTimerEvent &event);
147     void OnSize(wxSizeEvent &event);
148     void OnMouseWheel(wxMouseEvent& event);
149
150     void Render();
151     void SetRenderWhenDisabled(int newValue);
152
153     // Description:
154     // Prescribe that the window be created in a stereo-capable mode. This
155     // method must be called before the window is realized. Default if off.
156     vtkGetMacro(Stereo,int);
157     vtkBooleanMacro(Stereo,int);
158     virtual void SetStereo(int capable);
159
160     // Description:
161     // As CaptureMouse could be a problem sometimes on a window box
162     // This method allow to set or not the CaptureMouse.
163     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
164     vtkSetMacro(UseCaptureMouse,int);
165     vtkBooleanMacro(UseCaptureMouse,int);
166
167     virtual void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
168
169   protected:
170     wxTimer timer;
171     int ActiveButton;
172     int RenderAllowed;
173     long GetHandleHack();
174     int Stereo;
175     
176   private:
177     long Handle;
178     bool Created;
179     int RenderWhenDisabled;
180     int UseCaptureMouse;
181
182     DECLARE_EVENT_TABLE()
183 };
184
185
186 // LG : EO namespace bbwxvtk
187 //======================================================================
188
189 #endif //_wxVTKRenderWindowInteractor_h_