]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.h
*** empty log message ***
[crea.git] / src / creawxVTKRenderWindowInteractor.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: creawxVTKRenderWindowInteractor.h,v $
5   Language:  C++
6   Date:      $Date: 2011/02/21 07:30:01 $
7   Version:   $Revision: 1.5 $
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  creawxVTKRenderWindowInteractor - class to enable VTK to render to 
20 // and interact with wxWindow.
21 // .SECTION Description
22 //  creawxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class
23 // was completely rewrote to have the 'Look & Feel' of the python version:
24 // creawxVTKRenderWindowInteractor.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 // creawxVTKRenderWindowInteractor.py wxVTKRenderWindow.py
36
37 #ifndef _creawxVTKRenderWindowInteractor_h_
38 #define _creawxVTKRenderWindowInteractor_h_
39
40 #ifdef USE_WXWIDGETS
41 #ifdef USE_VTK
42
43
44 // For compilers that support precompilation, includes "wx/wx.h".
45 #include "wx/wxprec.h"
46
47 #ifdef __BORLANDC__
48 #  pragma hdrstop
49 #endif
50
51 #ifndef WX_PRECOMP
52 #include <wx/wx.h>
53 #endif
54
55 #include <wx/timer.h>
56 #include <wx/dcclient.h>
57
58 // vtk includes
59 #include "vtkRenderWindowInteractor.h"
60 #include "vtkRenderWindow.h"
61
62 // Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any
63 // other port):
64 // MM: tested on 2008/04/08: experienced some heavy flickering with wx-widget 2.6.0
65 // using a wxWindow instead of wxGLCanvas fixed the symptoms
66 //#if (!wxCHECK_VERSION(2, 6, 0))
67 #if (!wxCHECK_VERSION(2, 8, 0))
68 #define USE_WXGLCANVAS
69 #endif
70
71 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
72 #  if wxUSE_GLCANVAS
73 #    include <wx/glcanvas.h>
74 #  else
75 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
76 #  endif //wxUSE_GLCANVAS
77 #endif //__WXGTK__
78
79 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
80 #if defined(__WXMOTIF__) 
81 # error This GUI is not supported by creawxVTKRenderWindowInteractor for now
82 #endif
83
84 // wx forward declarations
85 class wxPaintEvent;
86 class wxMouseEvent;
87 class wxTimerEvent;
88 class wxKeyEvent;
89 class wxSizeEvent;
90
91 //=======================================================================
92 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
93 namespace crea
94 {
95
96
97 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
98 class CREA_EXPORT creawxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor
99 #else
100 class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWindowInteractor, public wxWindow
101 #endif //__WXGTK__
102 {
103   DECLARE_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor)
104   
105   public:
106     //constructors
107     creawxVTKRenderWindowInteractor();
108
109     creawxVTKRenderWindowInteractor(wxWindow *parent,
110                                 wxWindowID id,
111                                 const wxPoint &pos = wxDefaultPosition,
112                                 const wxSize &size = wxDefaultSize,
113                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
114                                 const wxString &name = wxPanelNameStr);
115     vtkTypeRevisionMacro(creawxVTKRenderWindowInteractor,vtkRenderWindowInteractor);
116     static creawxVTKRenderWindowInteractor * New();
117     void PrintSelf(ostream& os, vtkIndent indent);
118
119           //destructor
120     ~creawxVTKRenderWindowInteractor();
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     void OnChar(wxKeyEvent &event);
146 #endif
147     void OnTimer(wxTimerEvent &event);
148     void OnSize(wxSizeEvent &event);
149     void OnMouseWheel(wxMouseEvent& event);
150
151     void Render();
152     void SetRenderWhenDisabled(int newValue);
153
154     // Description:
155     // Prescribe that the window be created in a stereo-capable mode. This
156     // method must be called before the window is realized. Default if off.
157     vtkGetMacro(Stereo,int);
158     vtkBooleanMacro(Stereo,int);
159     virtual void SetStereo(int capable);
160
161     // Description:
162     // As CaptureMouse could be a problem sometimes on a window box
163     // This method allow to set or not the CaptureMouse.
164     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
165     vtkSetMacro(UseCaptureMouse,int);
166     vtkBooleanMacro(UseCaptureMouse,int);
167
168   protected:
169     wxTimer timer;
170     int ActiveButton;
171     int RenderAllowed;
172     long GetHandleHack();
173     int Stereo;
174     
175   private:
176     long Handle;
177     bool Created;
178     int RenderWhenDisabled;
179     int UseCaptureMouse;
180
181     DECLARE_EVENT_TABLE()
182 };
183
184
185
186 // LG : EO namespace crea
187 //======================================================================
188
189 #endif // USE_WX
190 #endif // USE_VTK
191
192
193 #endif //_creawxVTKRenderWindowInteractor_h_