]> Creatis software - crea.git/blob - src/wxVTKRenderWindowInteractor.h
3190c8762549df8852ea9bff933eab389b31e500
[crea.git] / src / wxVTKRenderWindowInteractor.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: wxVTKRenderWindowInteractor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/10/02 12:29:45 $
7   Version:   $Revision: 1.2 $
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  wxVTKRenderWindowInteractor - class to enable VTK to render to 
20 // and interact with wxWindow.
21 // .SECTION Description
22 //  wxVTKRenderWindowInteractor provide a VTK widget for wxWindow. This class
23 // was completely rewrote to have the 'Look & Feel' of the python version:
24 // wxVTKRenderWindowInteractor.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 // wxVTKRenderWindowInteractor.py wxVTKRenderWindow.py
36
37 #ifndef _wxVTKRenderWindowInteractor_h_
38 #define _wxVTKRenderWindowInteractor_h_
39
40 #include <creaSystem.h>
41 #include <creaWx.h>
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 #if (!wxCHECK_VERSION(2, 8, 0))
65 #define USE_WXGLCANVAS
66 #endif
67
68
69 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
70 # if wxUSE_GLCANVAS
71 #    include <wx/glcanvas.h>
72 # else
73 #    error "problem of wxGLCanvas, you need to build wxWidgets with opengl"
74 # endif //wxUSE_GLCANVAS
75 #endif //__WXGTK__
76
77 // Motif version (renamed into wxX11 for wxWindow 2.4 and newer)
78 #if defined(__WXMOTIF__) 
79 # error This GUI is not supported by wxVTKRenderWindowInteractor for now
80 #endif
81
82
83 // wx forward declarations
84 class wxPaintEvent;
85 class wxMouseEvent;
86 class wxTimerEvent;
87 class wxKeyEvent;
88 class wxSizeEvent;
89
90 //=======================================================================
91 // LG : NAMESPACE IS NECESSARY TO AVOID CONFLICTING SYMBOLS IN DYN LIBS
92 namespace crea
93 {
94
95
96 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
97 class CREA_EXPORT wxVTKRenderWindowInteractor : public wxGLCanvas, virtual public vtkRenderWindowInteractor
98 #else
99 class CREA_EXPORT wxVTKRenderWindowInteractor : public wxWindow, virtual public vtkRenderWindowInteractor
100 #endif //__WXGTK__
101 {
102   DECLARE_DYNAMIC_CLASS(wxVTKRenderWindowInteractor)
103   
104   public:
105     //constructors
106     wxVTKRenderWindowInteractor();
107
108     wxVTKRenderWindowInteractor(wxWindow *parent,
109                                 wxWindowID id,
110                                 const wxPoint &pos = wxDefaultPosition,
111                                 const wxSize &size = wxDefaultSize,
112                                 long style = wxWANTS_CHARS | wxNO_FULL_REPAINT_ON_RESIZE,
113                                 const wxString &name = wxPanelNameStr);
114         //vtk ::New()
115     static wxVTKRenderWindowInteractor * New();
116     void PrintSelf(ostream& os, vtkIndent indent);
117
118           //destructor
119     ~wxVTKRenderWindowInteractor();
120
121 #if defined(_WIN32)
122     const char * wxVTKRenderWindowInteractor::GetClassName() const;
123 #endif //_WIN32
124
125
126     // vtkRenderWindowInteractor overrides
127     void Initialize();
128     void Enable();
129     bool Enable(bool enable);
130     void Disable();
131     void Start();
132     void UpdateSize(int x, int y);
133     int CreateTimer(int timertype);
134     int DestroyTimer();
135     void TerminateApp() {};
136
137     // event handlers
138     void OnPaint(wxPaintEvent &event);
139     void OnEraseBackground (wxEraseEvent& event);
140     void OnMotion(wxMouseEvent &event);
141
142     void OnButtonDown(wxMouseEvent &event);
143     void OnButtonUp(wxMouseEvent &event);
144 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
145     void OnEnter(wxMouseEvent &event);
146     void OnLeave(wxMouseEvent &event);
147     void OnKeyDown(wxKeyEvent &event);
148     void OnKeyUp(wxKeyEvent &event);
149 #endif
150     void OnTimer(wxTimerEvent &event);
151     void OnSize(wxSizeEvent &event);
152     void OnMouseWheel(wxMouseEvent& event);
153
154     void Render();
155     void SetRenderWhenDisabled(int newValue);
156
157     // Description:
158     // Prescribe that the window be created in a stereo-capable mode. This
159     // method must be called before the window is realized. Default if off.
160     vtkGetMacro(Stereo,int);
161     vtkBooleanMacro(Stereo,int);
162     virtual void SetStereo(int capable);
163
164     // Description:
165     // As CaptureMouse could be a problem sometimes on a window box
166     // This method allow to set or not the CaptureMouse.
167     // This method actually will works only if WX_USE_X_CAPTURE was set to 1
168     vtkSetMacro(UseCaptureMouse,int);
169     vtkBooleanMacro(UseCaptureMouse,int);
170
171   protected:
172     wxTimer timer;
173     int ActiveButton;
174     int RenderAllowed;
175     long GetHandleHack();
176     int Stereo;
177     
178   private:
179     long Handle;
180     bool Created;
181     int RenderWhenDisabled;
182     int UseCaptureMouse;
183
184     DECLARE_EVENT_TABLE()
185 };
186
187
188 // LG : EO namespace crea
189 //======================================================================
190
191 #endif //_wxVTKRenderWindowInteractor_h_