]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.h
Feature #1763
[crea.git] / src / creawxVTKRenderWindowInteractor.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */ 
24
25 /*=========================================================================
26
27   Program:   Visualization Toolkit
28   Module:    $RCSfile: creawxVTKRenderWindowInteractor.h,v $
29   Language:  C++
30   Date:      $Date: 2012/11/15 09:07:32 $
31   Version:   $Revision: 1.8 $
32
33   This software is distributed WITHOUT ANY WARRANTY; without even 
34   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
35   PURPOSE.  See the above copyright notice for more information.
36
37 =========================================================================*/
38
39 // .NAME  creawxVTKRenderWindowInteractor - class to enable VTK to render to 
40 // and interact with wxWindow.
41 // .SECTION Description
42 //  creawxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class
43 // was completely rewrote to have the 'Look & Feel' of the python version:
44 // creawxVTKRenderWindowInteractor.py
45 // .SECTION Caveats 
46 //  - There is a know bug that prevent this class to works for more info see 
47 // WX_USE_X_CAPTURE. This bug only affect wxGTK from 2.3.2 to wxGTK 2.4.0.
48 //  - Furthermore this class is tempated over either wxWindows or wxGLCanvas,
49 // in wxWindows 2.3.1 and earlier, the wxGLCanvas had scroll bars, you can avoid
50 // this effect by playing with WX_BASE_CLASS at your risk (you might end up with
51 // lot of flickering.)
52 //  - This class might not be easily readable as it tried to work with VTK 3.2
53 //  and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier.
54 // .SECTION see also
55 // creawxVTKRenderWindowInteractor.py wxVTKRenderWindow.py
56
57 #ifndef _creawxVTKRenderWindowInteractor_h_
58 #define _creawxVTKRenderWindowInteractor_h_
59
60 #ifdef USE_WXWIDGETS
61 #ifdef USE_VTK
62
63 #include <creaSystem.h>
64 #include <creaWx.h>
65
66 // For compilers that support precompilation, includes "wx/wx.h".
67 #include "wx/wxprec.h"
68
69 #ifdef __BORLANDC__
70 #  pragma hdrstop
71 #endif
72
73 #ifndef WX_PRECOMP
74 #include <wx/wx.h>
75 #endif
76
77 #include <wx/timer.h>
78 #include <wx/dcclient.h>
79
80 // vtk includes
81 #include "vtkRenderWindowInteractor.h"
82 #include "vtkRenderWindow.h"
83
84 // Apparently since wxGTK 2.8.0 one can finally use wxWindow (just as in any
85 // other port):
86 // MM: tested on 2008/04/08: experienced some heavy flickering with wx-widget 2.6.0
87 // using a wxWindow instead of wxGLCanvas fixed the symptoms
88 //#if (!wxCHECK_VERSION(2, 6, 0))
89 #if (!wxCHECK_VERSION(2, 8, 0))
90 #define USE_WXGLCANVAS
91 #endif
92
93 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
94 #  if wxUSE_GLCANVAS
95 #    include <wx/glcanvas.h>
96 #  else
97 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
98 #  endif //wxUSE_GLCANVAS
99 #endif //__WXGTK__
100
101 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
102 #if defined(__WXMOTIF__) 
103 # error This GUI is not supported by creawxVTKRenderWindowInteractor for now
104 #endif
105
106 // wx forward declarations
107 class wxPaintEvent;
108 class wxMouseEvent;
109 class wxTimerEvent;
110 class wxKeyEvent;
111 class wxSizeEvent;
112
113 //=======================================================================
114 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
115 namespace crea
116 {
117
118
119 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
120 class CREA_EXPORT creawxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor
121 #else
122 class CREA_EXPORT creawxVTKRenderWindowInteractor : virtual public vtkRenderWindowInteractor, public wxWindow
123 #endif //__WXGTK__
124 {
125   DECLARE_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor)
126   
127   public:
128     //constructors
129     creawxVTKRenderWindowInteractor();
130
131     creawxVTKRenderWindowInteractor(wxWindow *parent,
132                                 wxWindowID id,
133                                 const wxPoint &pos = wxDefaultPosition,
134                                 const wxSize &size = wxDefaultSize,
135                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
136                                 const wxString &name = wxPanelNameStr);
137   //EED win Compilation why ??:  vtkTypeRevisionMacro(creawxVTKRenderWindowInteractor,vtkRenderWindowInteractor);
138     static creawxVTKRenderWindowInteractor * New();
139     void PrintSelf(ostream& os, vtkIndent indent);
140
141           //destructor
142     ~creawxVTKRenderWindowInteractor();
143
144     // vtkRenderWindowInteractor overrides
145     void Initialize();
146     void Enable();
147     bool Enable(bool enable);
148     void Disable();
149     void Start();
150     void UpdateSize(int x, int y);
151     int CreateTimer(int timertype);
152     int DestroyTimer();
153     void TerminateApp() {};
154
155     // event handlers
156     void OnPaint(wxPaintEvent &event);
157     void OnEraseBackground (wxEraseEvent& event);
158     void OnMotion(wxMouseEvent &event);
159
160     void OnButtonDown(wxMouseEvent &event);
161     void OnButtonUp(wxMouseEvent &event);
162 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
163     void OnEnter(wxMouseEvent &event);
164     void OnLeave(wxMouseEvent &event);
165     void OnKeyDown(wxKeyEvent &event);
166     void OnKeyUp(wxKeyEvent &event);
167     void OnChar(wxKeyEvent &event);
168 #endif
169     void OnTimer(wxTimerEvent &event);
170     void OnSize(wxSizeEvent &event);
171     void OnMouseWheel(wxMouseEvent& event);
172
173     void Render();
174     void SetRenderWhenDisabled(int newValue);
175
176     // Description:
177     // Prescribe that the window be created in a stereo-capable mode. This
178     // method must be called before the window is realized. Default if off.
179     vtkGetMacro(Stereo,int);
180     vtkBooleanMacro(Stereo,int);
181     virtual void SetStereo(int capable);
182
183     // Description:
184     // As CaptureMouse could be a problem sometimes on a window box
185     // This method allow to set or not the CaptureMouse.
186     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
187     vtkSetMacro(UseCaptureMouse,int);
188     vtkBooleanMacro(UseCaptureMouse,int);
189
190   protected:
191     wxTimer timer;
192     int ActiveButton;
193     int RenderAllowed;
194     long GetHandleHack();
195     int Stereo;
196     
197   private:
198     long Handle;
199     bool Created;
200     int RenderWhenDisabled;
201     int UseCaptureMouse;
202
203     DECLARE_EVENT_TABLE()
204 };
205
206
207
208 // LG : EO namespace crea
209 //======================================================================
210
211 #endif // USE_WX
212 #endif // USE_VTK
213
214
215 #endif //_creawxVTKRenderWindowInteractor_h_