]> Creatis software - crea.git/blob - src/creawxVTKRenderWindowInteractor.h
Clean code
[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$
32   Language:  C++
33   Date:      $Date$
34   Version:   $Revision$
35
36   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
37   All rights reserved.
38   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
39
40      This software is distributed WITHOUT ANY WARRANTY; without even 
41      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
42      PURPOSE.  See the above copyright notice for more information.
43
44 =========================================================================*/
45
46 // .NAME  wxVTKRenderWindowInteractor - class to enable VTK to render to 
47 // and interact with wxWindow.
48 // .SECTION Description
49 //  wxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class
50 // was completely rewrote to have the 'Look & Feel' of the python version:
51 // wxVTKRenderWindowInteractor.py
52 // .SECTION Caveats 
53 //  - There is a know bug that prevent this class to works for more info see 
54 // WX_USE_X_CAPTURE. This bug only affect wxGTK from 2.3.2 to wxGTK 2.4.0.
55 //  - Furthermore this class is tempated over either wxWindows or wxGLCanvas,
56 // in wxWindows 2.3.1 and earlier, the wxGLCanvas had scroll bars, you can avoid
57 // this effect by playing with WX_BASE_CLASS at your risk (you might end up with
58 // lot of flickering.)
59 //  - This class might not be easily readable as it tried to work with VTK 3.2
60 //  and 4.x. This class doesn't support reparenting with VTK 4.2 and earlier.
61 // .SECTION see also
62 // wxVTKRenderWindowInteractor.py wxVTKRenderWindow.py
63
64 #ifndef _wxVTKRenderWindowInteractor_h_
65 #define _wxVTKRenderWindowInteractor_h_
66
67 // For compilers that support precompilation, includes "wx/wx.h".
68 #include "wx/wxprec.h"
69
70 #ifdef __BORLANDC__
71 #  pragma hdrstop
72 #endif
73
74 #ifndef WX_PRECOMP
75 #include <wx/wx.h>
76 #endif
77
78 #include <wx/timer.h>
79 #include <wx/dcclient.h>
80
81 // vtk includes
82 #include <vtkVersionMacros.h>
83 #include "vtkRenderWindowInteractor.h"
84 #include "vtkRenderWindow.h"
85
86 #define USE_WXGLCANVAS
87
88 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
89 #  if wxUSE_GLCANVAS
90 #    include <wx/glcanvas.h>
91 #  else
92 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
93 #  endif //wxUSE_GLCANVAS
94 #endif //__WXGTK__
95
96 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
97 #if defined(__WXMOTIF__) 
98 # error This GUI is not supported by wxVTKRenderWindowInteractor for now
99 #endif
100
101 #include "creaSystem.h"
102
103 #include "vtkTDxConfigure.h" // defines VTK_USE_TDX
104 #ifdef VTK_USE_TDX
105 class vtkTDxMacDevice;
106 #endif
107
108
109
110 // wx forward declarations
111 class wxPaintEvent;
112 class wxMouseEvent;
113 class wxTimerEvent;
114 class wxKeyEvent;
115 class wxSizeEvent;
116
117 //=======================================================================
118 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
119 namespace crea
120 {
121
122
123 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
124 class wxVTKRenderWindowInteractor : public wxGLCanvas, public vtkRenderWindowInteractor
125 #else
126 class CREA_EXPORT wxVTKRenderWindowInteractor : public wxWindow, public vtkRenderWindowInteractor
127 #endif //__WXGTK__
128 {
129 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
130 #if wxMAJOR_VERSION <= 2
131   DECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor)
132 #else
133   wxDECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor);
134 #endif
135   
136   public:
137     //constructors
138     wxVTKRenderWindowInteractor();
139
140     wxVTKRenderWindowInteractor(wxWindow *parent,
141                                 wxWindowID id,
142                                 const wxPoint &pos = wxDefaultPosition,
143                                 const wxSize &size = wxDefaultSize,
144                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
145                                 const wxString &name = wxPanelNameStr);
146   //EED win Compilation why ??:    vtkTypeRevisionMacro(wxVTKRenderWindowInteractor,vtkRenderWindowInteractor);
147     static wxVTKRenderWindowInteractor * New();
148     void PrintSelf(ostream& os, vtkIndent indent);
149
150           //destructor
151     ~wxVTKRenderWindowInteractor();
152
153     // vtkRenderWindowInteractor overrides
154     void Initialize();
155     void Enable();
156     bool Enable(bool enable);
157     void Disable();
158     void Start();
159     void UpdateSize(int x, int y);
160     int CreateTimer(int timertype);
161     int DestroyTimer();
162     void TerminateApp() {};
163
164     // event handlers
165     void OnPaint(wxPaintEvent &event);
166     void OnEraseBackground (wxEraseEvent& event);
167     void OnMotion(wxMouseEvent &event);
168
169     void OnButtonDown(wxMouseEvent &event);
170     void OnButtonUp(wxMouseEvent &event);
171 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
172     void OnEnter(wxMouseEvent &event);
173     void OnLeave(wxMouseEvent &event);
174     void OnMouseWheel(wxMouseEvent& event);
175 #if wxCHECK_VERSION(2, 8, 0)
176     void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
177 #endif
178     void OnKeyDown(wxKeyEvent &event);
179     void OnKeyUp(wxKeyEvent &event);
180     void OnChar(wxKeyEvent &event);
181 #endif
182     void OnTimer(wxTimerEvent &event);
183     void OnSize(wxSizeEvent &event);
184
185     void Render();
186     void SetRenderWhenDisabled(int newValue);
187
188     // Description:
189     // Prescribe that the window be created in a stereo-capable mode. This
190     // method must be called before the window is realized. Default if off.
191     vtkGetMacro(Stereo,int);
192     vtkBooleanMacro(Stereo,int);
193     virtual void SetStereo(int capable);
194
195     // Description:
196     // As CaptureMouse could be a problem sometimes on a window box
197     // This method allow to set or not the CaptureMouse.
198     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
199     vtkSetMacro(UseCaptureMouse,int);
200     vtkBooleanMacro(UseCaptureMouse,int);
201
202 #if VTK_MAJOR_VERSION > 5 || (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION >= 2)
203   protected:
204     virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
205     virtual int InternalDestroyTimer(int platformTimerId);
206 #endif
207
208   protected:
209 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
210     wxGLContext *context;
211 #endif
212     wxTimer timer;
213     int ActiveButton;
214     long GetHandleHack();
215     int Stereo;
216     
217 #ifdef VTK_USE_TDX
218   vtkTDxMacDevice *Device;
219 #endif
220
221     
222   private:
223     long Handle;
224     bool Created;
225     int RenderWhenDisabled;
226     int UseCaptureMouse;
227
228     DECLARE_EVENT_TABLE()
229 };
230
231
232 // LG : EO namespace bbwxvtk
233 //======================================================================
234
235 #endif //_wxVTKRenderWindowInteractor_h_