]> 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 23:27:13 $
7   Version:   $Revision: 1.6 $
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 #include <creaSystem.h>
44 #include <creaWx.h>
45
46 // For compilers that support precompilation, includes "wx/wx.h".
47 #include "wx/wxprec.h"
48
49 #ifdef __BORLANDC__
50 #  pragma hdrstop
51 #endif
52
53 #ifndef WX_PRECOMP
54 #include <wx/wx.h>
55 #endif
56
57 #include <wx/timer.h>
58 #include <wx/dcclient.h>
59
60 // vtk includes
61 #include "vtkRenderWindowInteractor.h"
62 #include "vtkRenderWindow.h"
63
64 // Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any
65 // other port):
66 // MM: tested on 2008/04/08: experienced some heavy flickering with wx-widget 2.6.0
67 // using a wxWindow instead of wxGLCanvas fixed the symptoms
68 //#if (!wxCHECK_VERSION(2, 6, 0))
69 #if (!wxCHECK_VERSION(2, 8, 0))
70 #define USE_WXGLCANVAS
71 #endif
72
73 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
74 #  if wxUSE_GLCANVAS
75 #    include <wx/glcanvas.h>
76 #  else
77 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
78 #  endif //wxUSE_GLCANVAS
79 #endif //__WXGTK__
80
81 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
82 #if defined(__WXMOTIF__) 
83 # error This GUI is not supported by creawxVTKRenderWindowInteractor for now
84 #endif
85
86 // wx forward declarations
87 class wxPaintEvent;
88 class wxMouseEvent;
89 class wxTimerEvent;
90 class wxKeyEvent;
91 class wxSizeEvent;
92
93 //=======================================================================
94 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
95 namespace crea
96 {
97
98
99 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
100 class CREA_EXPORT creawxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor
101 #else
102 class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWindowInteractor, public wxWindow
103 #endif //__WXGTK__
104 {
105   DECLARE_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor)
106   
107   public:
108     //constructors
109     creawxVTKRenderWindowInteractor();
110
111     creawxVTKRenderWindowInteractor(wxWindow *parent,
112                                 wxWindowID id,
113                                 const wxPoint &pos = wxDefaultPosition,
114                                 const wxSize &size = wxDefaultSize,
115                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
116                                 const wxString &name = wxPanelNameStr);
117     vtkTypeRevisionMacro(creawxVTKRenderWindowInteractor,vtkRenderWindowInteractor);
118     static creawxVTKRenderWindowInteractor * New();
119     void PrintSelf(ostream& os, vtkIndent indent);
120
121           //destructor
122     ~creawxVTKRenderWindowInteractor();
123
124     // vtkRenderWindowInteractor overrides
125     void Initialize();
126     void Enable();
127     bool Enable(bool enable);
128     void Disable();
129     void Start();
130     void UpdateSize(int x, int y);
131     int CreateTimer(int timertype);
132     int DestroyTimer();
133     void TerminateApp() {};
134
135     // event handlers
136     void OnPaint(wxPaintEvent &event);
137     void OnEraseBackground (wxEraseEvent& event);
138     void OnMotion(wxMouseEvent &event);
139
140     void OnButtonDown(wxMouseEvent &event);
141     void OnButtonUp(wxMouseEvent &event);
142 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
143     void OnEnter(wxMouseEvent &event);
144     void OnLeave(wxMouseEvent &event);
145     void OnKeyDown(wxKeyEvent &event);
146     void OnKeyUp(wxKeyEvent &event);
147     void OnChar(wxKeyEvent &event);
148 #endif
149     void OnTimer(wxTimerEvent &event);
150     void OnSize(wxSizeEvent &event);
151     void OnMouseWheel(wxMouseEvent& event);
152
153     void Render();
154     void SetRenderWhenDisabled(int newValue);
155
156     // Description:
157     // Prescribe that the window be created in a stereo-capable mode. This
158     // method must be called before the window is realized. Default if off.
159     vtkGetMacro(Stereo,int);
160     vtkBooleanMacro(Stereo,int);
161     virtual void SetStereo(int capable);
162
163     // Description:
164     // As CaptureMouse could be a problem sometimes on a window box
165     // This method allow to set or not the CaptureMouse.
166     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
167     vtkSetMacro(UseCaptureMouse,int);
168     vtkBooleanMacro(UseCaptureMouse,int);
169
170   protected:
171     wxTimer timer;
172     int ActiveButton;
173     int RenderAllowed;
174     long GetHandleHack();
175     int Stereo;
176     
177   private:
178     long Handle;
179     bool Created;
180     int RenderWhenDisabled;
181     int UseCaptureMouse;
182
183     DECLARE_EVENT_TABLE()
184 };
185
186
187
188 // LG : EO namespace crea
189 //======================================================================
190
191 #endif // USE_WX
192 #endif // USE_VTK
193
194
195 #endif //_creawxVTKRenderWindowInteractor_h_