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