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