2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
28 /*=========================================================================
30 Program: Visualization Toolkit
31 Module: $RCSfile: creawxVTKRenderWindowInteractor.cxx,v $
33 Date: $Date: 2012/11/15 10:43:26 $
34 Version: $Revision: 1.11 $
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.
40 =========================================================================*/
47 #include "creawxVTKRenderWindowInteractor.h"
49 //This is needed for vtk 3.1 :
50 #ifndef VTK_MAJOR_VERSION
51 # include "vtkVersion.h"
54 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
55 # include "vtkCommand.h"
57 # include "vtkInteractorStyle.h"
59 #include "vtkDebugLeaks.h"
63 #include "vtkCocoaRenderWindow.h"
65 #include "vtkCarbonRenderWindow.h"
70 //Keep this for compatibilty reason, this was introduced in wxGTK 2.4.0
71 #if (!wxCHECK_VERSION(2, 4, 0))
72 wxWindow* wxGetTopLevelParent(wxWindow *win)
74 while ( win && !win->IsTopLevel() )
75 win = win->GetParent();
80 // To access objc calls on cocoa
83 #import <Cocoa/Cocoa.h>
84 // This trick is no longer need in VTK CVS, should get rid of that:
87 #error Build mismatch you need both wxWidgets and VTK to be configure against Cocoa to work
88 #endif //VTK_USE_COCOA
92 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
93 #if wxMAJOR_VERSION <= 2
95 #include <gdk/gdkx.h> // GDK_WINDOW_XWINDOW is found here in wxWidgets 2.8.0
96 #include "gdk/gdkprivate.h"
97 #if wxCHECK_VERSION(2, 8, 0)
99 #include <wx/gtk/win_gtk.h>
101 #include <wx/gtk1/win_gtk.h>
104 #include <wx/gtk/win_gtk.h>
106 #define GetXWindow(wxwin) (wxwin)->m_wxwindow ? \
107 GDK_WINDOW_XWINDOW(GTK_PIZZA((wxwin)->m_wxwindow)->bin_window) : \
108 GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
112 #include <gdk/gdkx.h>
120 #include "wx/x11/privx.h"
121 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
125 //For more info on this class please go to:
126 //http://wxvtk.sf.net
127 //This hack is for some buggy wxGTK version:
128 #if wxCHECK_VERSION(2, 3, 2) && !wxCHECK_VERSION(2, 4, 1) && defined(__WXGTK__)
129 # define WX_USE_X_CAPTURE 0
131 # define WX_USE_X_CAPTURE 1
134 #define ID_creawxVTKRenderWindowInteractor_TIMER 1001
139 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
140 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxGLCanvas)
143 IMPLEMENT_DYNAMIC_CLASS(creawxVTKRenderWindowInteractor, wxWindow)
146 //---------------------------------------------------------------------------
147 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
148 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxGLCanvas)
150 BEGIN_EVENT_TABLE(creawxVTKRenderWindowInteractor, wxWindow)
152 //refresh window by doing a Render
153 EVT_PAINT (creawxVTKRenderWindowInteractor::OnPaint)
154 EVT_ERASE_BACKGROUND(creawxVTKRenderWindowInteractor::OnEraseBackground)
155 EVT_MOTION (creawxVTKRenderWindowInteractor::OnMotion)
157 //Bind the events to the event converters
158 EVT_LEFT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
159 EVT_MIDDLE_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
160 EVT_RIGHT_DOWN (creawxVTKRenderWindowInteractor::OnButtonDown)
161 EVT_LEFT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
162 EVT_MIDDLE_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
163 EVT_RIGHT_UP (creawxVTKRenderWindowInteractor::OnButtonUp)
164 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
165 EVT_ENTER_WINDOW(creawxVTKRenderWindowInteractor::OnEnter)
166 EVT_LEAVE_WINDOW(creawxVTKRenderWindowInteractor::OnLeave)
167 EVT_MOUSEWHEEL (creawxVTKRenderWindowInteractor::OnMouseWheel)
168 EVT_KEY_DOWN (creawxVTKRenderWindowInteractor::OnKeyDown)
169 EVT_KEY_UP (creawxVTKRenderWindowInteractor::OnKeyUp)
170 EVT_CHAR (creawxVTKRenderWindowInteractor::OnChar)
172 EVT_TIMER (ID_creawxVTKRenderWindowInteractor_TIMER, creawxVTKRenderWindowInteractor::OnTimer)
173 EVT_SIZE (creawxVTKRenderWindowInteractor::OnSize)
176 //EED win Compilation why??: vtkCxxRevisionMacro(creawxVTKRenderWindowInteractor, "$Revision: 1.11 $")
177 vtkInstantiatorNewMacro(creawxVTKRenderWindowInteractor)
179 //---------------------------------------------------------------------------
180 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
181 #if (wxCHECK_VERSION(2, 8, 0))
182 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(0, -1, wxDefaultPosition), vtkRenderWindowInteractor()
184 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxGLCanvas(), vtkRenderWindowInteractor()
187 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor() : wxWindow(), vtkRenderWindowInteractor()
189 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
190 , ActiveButton(wxEVT_NULL)
195 , RenderWhenDisabled(1)
198 #ifdef VTK_DEBUG_LEAKS
199 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
201 this->RenderWindow = NULL;
202 this->SetRenderWindow(vtkRenderWindow::New());
203 this->RenderWindow->Delete();
205 //---------------------------------------------------------------------------
206 creawxVTKRenderWindowInteractor::creawxVTKRenderWindowInteractor(wxWindow *parent,
211 const wxString &name)
212 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
213 : wxGLCanvas(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
215 : wxWindow(parent, id, pos, size, style, name), vtkRenderWindowInteractor()
217 , timer(this, ID_creawxVTKRenderWindowInteractor_TIMER)
218 , ActiveButton(wxEVT_NULL)
223 , RenderWhenDisabled(1)
226 #ifdef VTK_DEBUG_LEAKS
227 vtkDebugLeaks::ConstructClass("creawxVTKRenderWindowInteractor");
229 this->RenderWindow = NULL;
230 this->SetRenderWindow(vtkRenderWindow::New());
231 this->RenderWindow->Delete();
233 // On Mac (Carbon) we don't get notified of the initial window size with an EVT_SIZE event,
234 // so we update the size information of the interactor/renderwindow here
235 this->UpdateSize(size.x, size.y);
238 //---------------------------------------------------------------------------
239 creawxVTKRenderWindowInteractor::~creawxVTKRenderWindowInteractor()
241 SetRenderWindow(NULL);
242 SetInteractorStyle(NULL);
244 //---------------------------------------------------------------------------
245 creawxVTKRenderWindowInteractor * creawxVTKRenderWindowInteractor::New()
247 // we don't make use of the objectfactory, because we're not registered
248 return new creawxVTKRenderWindowInteractor;
250 //---------------------------------------------------------------------------
251 void creawxVTKRenderWindowInteractor::Initialize()
253 int *size = RenderWindow->GetSize();
254 // enable everything and start rendering
256 //RenderWindow->Start();
258 // set the size in the render window interactor
262 // this is initialized
265 //---------------------------------------------------------------------------
266 void creawxVTKRenderWindowInteractor::Enable()
268 // if already enabled then done
274 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
279 //---------------------------------------------------------------------------
280 bool creawxVTKRenderWindowInteractor::Enable(bool enable)
282 #if defined(__WXGTK__) && defined(USE_WXGLCANVAS)
283 return wxGLCanvas::Enable(enable);
285 return wxWindow::Enable(enable);
288 //---------------------------------------------------------------------------
289 void creawxVTKRenderWindowInteractor::Disable()
291 // if already disabled then done
295 // that's it (we can't remove the event handler like it should be...)
299 //---------------------------------------------------------------------------
300 void creawxVTKRenderWindowInteractor::Start()
302 // the interactor cannot control the event loop
303 vtkErrorMacro( << "creawxVTKRenderWindowInteractor::Start() "
304 "interactor cannot control event loop.");
306 //---------------------------------------------------------------------------
307 void creawxVTKRenderWindowInteractor::UpdateSize(int x, int y)
311 // if the size changed tell render window
312 if ( x != Size[0] || y != Size[1] )
314 // adjust our (vtkRenderWindowInteractor size)
317 // and our RenderWindow's size
318 RenderWindow->SetSize(x, y);
322 //---------------------------------------------------------------------------
323 int creawxVTKRenderWindowInteractor::CreateTimer(int WXUNUSED(timertype))
325 // it's a one shot timer
326 if (!timer.Start(10, TRUE))
332 //---------------------------------------------------------------------------
333 int creawxVTKRenderWindowInteractor::DestroyTimer()
338 //---------------------------------------------------------------------------
339 void creawxVTKRenderWindowInteractor::OnTimer(wxTimerEvent& WXUNUSED(event))
344 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
346 InvokeEvent(vtkCommand::TimerEvent, NULL);
349 InteractorStyle->OnTimer();
353 //---------------------------------------------------------------------------
354 // NOTE on implementation:
355 // Bad luck you ended up in the only tricky place of this code.
356 // A few note, wxWidgets still refuse to provide such convenient method
357 // so I have to maintain it myself, eventhough this is completely integrated
359 // Anyway if this happen to break for you then compare to a recent version of wxPython
360 // and look for the function long wxPyGetWinHandle(wxWindow* win)
361 // in wxPython/src/helpers.cpp
362 long creawxVTKRenderWindowInteractor::GetHandleHack()
364 //helper function to hide the MSW vs GTK stuff
367 // __WXMSW__ is for Win32
368 //__WXMAC__ stands for using Carbon C-headers, using either the CarbonLib/CFM or the native Mach-O builds (which then also use the latest features available)
369 // __WXGTK__ is for both gtk 1.2.x and gtk 2.x
370 #if defined(__WXMSW__) || defined(__WXMAC__)
371 handle_tmp = (long)this->GetHandle();
374 //__WXCOCOA__ stands for using the objective-c Cocoa API
376 // Here is how to find the NSWindow
377 wxTopLevelWindow* toplevel = dynamic_cast<wxTopLevelWindow*>(
378 wxGetTopLevelParent( this ) );
379 if (toplevel != NULL )
381 handle_tmp = (long)toplevel->GetNSWindow();
383 // The NSView will be deducted from
384 // [(NSWindow*)Handle contentView]
385 // if only I knew how to write that in c++
388 // Find and return the actual X-Window.
389 #if defined(__WXGTK__) || defined(__WXX11__)
391 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
392 #if wxMAJOR_VERSION <= 2
393 return (long)GetXWindow(this);
395 GdkWindow* Win = gtk_widget_get_window( (GtkWidget *) GetHandle() );
396 return (long int)GDK_WINDOW_XDISPLAY(Win);
402 // handle_tmp = (long)this->GetXWindow();
407 //---------------------------------------------------------------------------
408 void creawxVTKRenderWindowInteractor::OnPaint(wxPaintEvent& WXUNUSED(event))
410 //must always be here
413 //do it here rather than in the cstor: this is safer.
416 Handle = GetHandleHack();
417 RenderWindow->SetWindowId(reinterpret_cast<void *>(Handle));
419 RenderWindow->SetParentId(reinterpret_cast<void *>(this->GetParent()->GetHWND()));
422 // get vtk to render to the wxWindows
427 vtkCocoaRenderWindow* rwin = vtkCocoaRenderWindow::SafeDownCast(RenderWindow);
430 rwin->UpdateContext();
433 // This solves a problem with repainting after a window resize
434 // See also: http://sourceforge.net/mailarchive/forum.php?thread_id=31690967&forum_id=41789
435 vtkCarbonRenderWindow* rwin = vtkCarbonRenderWindow::SafeDownCast(RenderWindow);
438 rwin->UpdateGLRegion();
444 //---------------------------------------------------------------------------
445 void creawxVTKRenderWindowInteractor::OnEraseBackground(wxEraseEvent &event)
447 //turn off background erase to reduce flickering on MSW
450 //---------------------------------------------------------------------------
451 void creawxVTKRenderWindowInteractor::OnSize(wxSizeEvent& WXUNUSED(event))
454 GetClientSize(&w, &h);
462 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
463 InvokeEvent(vtkCommand::ConfigureEvent, NULL);
465 //this will check for Handle
468 //---------------------------------------------------------------------------
469 void creawxVTKRenderWindowInteractor::OnMotion(wxMouseEvent &event)
475 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
476 SetEventInformationFlipY(event.GetX(), event.GetY(),
477 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
479 InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
481 InteractorStyle->OnMouseMove(event.ControlDown(), event.ShiftDown(),
482 event.GetX(), Size[1] - event.GetY() - 1);
485 //---------------------------------------------------------------------------
486 #if !(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
487 void creawxVTKRenderWindowInteractor::OnEnter(wxMouseEvent &event)
494 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
496 SetEventInformationFlipY(event.GetX(), event.GetY(),
497 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
499 InvokeEvent(vtkCommand::EnterEvent, NULL);
502 InteractorStyle->OnEnter(event.ControlDown(), event.ShiftDown(),
503 event.GetX(), Size[1] - event.GetY() - 1);
506 //---------------------------------------------------------------------------
507 void creawxVTKRenderWindowInteractor::OnLeave(wxMouseEvent &event)
514 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
516 SetEventInformationFlipY(event.GetX(), event.GetY(),
517 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
519 InvokeEvent(vtkCommand::LeaveEvent, NULL);
522 InteractorStyle->OnLeave(event.ControlDown(), event.ShiftDown(),
523 event.GetX(), Size[1] - event.GetY() - 1);
526 //---------------------------------------------------------------------------
527 void creawxVTKRenderWindowInteractor::OnKeyDown(wxKeyEvent &event)
534 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
536 int keycode = event.GetKeyCode();
538 if (((unsigned int)keycode) < 256)
540 // TODO: Unicode in non-Unicode mode ??
544 // we don't get a valid mouse position inside the key event on every platform
545 // so we retrieve the mouse position explicitly and pass it along
546 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
547 SetEventInformationFlipY(mousePos.x, mousePos.y,
548 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
549 InvokeEvent(vtkCommand::KeyPressEvent, NULL);
551 InteractorStyle->OnKeyDown(event.ControlDown(), event.ShiftDown(),
552 event.GetKeyCode(), 1);
556 //---------------------------------------------------------------------------
557 void creawxVTKRenderWindowInteractor::OnKeyUp(wxKeyEvent &event)
564 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
566 int keycode = event.GetKeyCode();
568 if (((unsigned int)keycode) < 256)
570 // TODO: Unicode in non-Unicode mode ??
574 // we don't get a valid mouse position inside the key event on every platform
575 // so we retrieve the mouse position explicitly and pass it along
576 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
577 SetEventInformationFlipY(mousePos.x, mousePos.y,
578 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
579 InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
581 InteractorStyle->OnKeyUp(event.ControlDown(), event.ShiftDown(),
582 event.GetKeyCode(), 1);
586 #endif //!(VTK_MAJOR_VERSION == 3 && VTK_MINOR_VERSION == 1)
587 //---------------------------------------------------------------------------
588 void creawxVTKRenderWindowInteractor::OnChar(wxKeyEvent &event)
595 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
597 int keycode = event.GetKeyCode();
599 if (((unsigned int)keycode) < 256)
601 // TODO: Unicode in non-Unicode mode ??
605 // we don't get a valid mouse position inside the key event on every platform
606 // so we retrieve the mouse position explicitly and pass it along
607 wxPoint mousePos = ScreenToClient(wxGetMousePosition());
608 SetEventInformationFlipY(mousePos.x, mousePos.y,
609 event.ControlDown(), event.ShiftDown(), key, 0, NULL);
610 InvokeEvent(vtkCommand::CharEvent, NULL);
614 //---------------------------------------------------------------------------
615 void creawxVTKRenderWindowInteractor::OnButtonDown(wxMouseEvent &event)
617 if (!Enabled || (ActiveButton != wxEVT_NULL))
621 ActiveButton = event.GetEventType();
623 // On Mac (Carbon) and Windows we don't automatically get the focus when
624 // you click inside the window
625 // we therefore set the focus explicitly
626 // Apparently we need that on linux (GTK) too:
629 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
630 SetEventInformationFlipY(event.GetX(), event.GetY(),
631 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
634 if(event.RightDown())
636 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
638 InvokeEvent(vtkCommand::RightButtonPressEvent, NULL);
641 InteractorStyle->OnRightButtonDown(event.ControlDown(), event.ShiftDown(),
642 event.GetX(), Size[1] - event.GetY() - 1);
645 else if(event.LeftDown())
647 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
649 InvokeEvent(vtkCommand::LeftButtonPressEvent, NULL);
652 InteractorStyle->OnLeftButtonDown(event.ControlDown(), event.ShiftDown(),
653 event.GetX(), Size[1] - event.GetY() - 1);
656 else if(event.MiddleDown())
658 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
660 InvokeEvent(vtkCommand::MiddleButtonPressEvent, NULL);
663 InteractorStyle->OnMiddleButtonDown(event.ControlDown(), event.ShiftDown(),
664 event.GetX(), Size[1] - event.GetY() - 1);
667 //save the button and capture mouse until the button is released
669 //1. it is possible (WX_USE_X_CAPTURE)
670 //2. user decided to.
671 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
676 //---------------------------------------------------------------------------
677 void creawxVTKRenderWindowInteractor::OnButtonUp(wxMouseEvent &event)
679 //EVT_xxx_DOWN == EVT_xxx_UP - 1
680 //This is only needed if two mouse buttons are pressed at the same time.
681 //In wxWindows 2.4 and later: better use of wxMOUSE_BTN_RIGHT or
682 //wxEVT_COMMAND_RIGHT_CLICK
683 if (!Enabled || (ActiveButton != (event.GetEventType()-1)))
688 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
689 SetEventInformationFlipY(event.GetX(), event.GetY(),
690 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
693 if(ActiveButton == wxEVT_RIGHT_DOWN)
695 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
697 InvokeEvent(vtkCommand::RightButtonReleaseEvent, NULL);
700 InteractorStyle->OnRightButtonUp(event.ControlDown(), event.ShiftDown(),
701 event.GetX(), Size[1] - event.GetY() - 1);
704 else if(ActiveButton == wxEVT_LEFT_DOWN)
706 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
708 InvokeEvent(vtkCommand::LeftButtonReleaseEvent, NULL);
711 InteractorStyle->OnLeftButtonUp(event.ControlDown(), event.ShiftDown(),
712 event.GetX(), Size[1] - event.GetY() - 1);
715 else if(ActiveButton == wxEVT_MIDDLE_DOWN)
717 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 0)
719 InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, NULL);
722 InteractorStyle->OnMiddleButtonUp(event.ControlDown(), event.ShiftDown(),
723 event.GetX(), Size[1] - event.GetY() - 1);
726 //if the ActiveButton is realeased, then release mouse capture
727 if ((ActiveButton != wxEVT_NULL) && WX_USE_X_CAPTURE && UseCaptureMouse)
731 ActiveButton = wxEVT_NULL;
733 //---------------------------------------------------------------------------
734 void creawxVTKRenderWindowInteractor::OnMouseWheel(wxMouseEvent& event)
736 // Mouse wheel was only added after VTK 4.4 (I think...)
737 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
739 //Set vtk event information ... The numebr of wheel rotations is stored in
740 //the x varible. y varible is zero
741 SetEventInformationFlipY(event.GetWheelRotation() / event.GetWheelDelta(), 0,
742 event.ControlDown(), event.ShiftDown(), '\0', 0, NULL);
743 if(event.GetWheelRotation() > 0)
746 InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
751 InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
757 //---------------------------------------------------------------------------
758 void creawxVTKRenderWindowInteractor::Render()
761 if (!RenderWhenDisabled)
763 //the user doesn't want us to render when the toplevel frame
764 //is disabled - first find the top level parent
765 wxWindow *topParent = wxGetTopLevelParent(this);
768 //if it exists, check whether it's enabled
769 //if it's not enabeld, RenderAllowed will be false
770 RenderAllowed = topParent->IsEnabled();
776 if(Handle && (Handle == GetHandleHack()) )
778 RenderWindow->Render();
780 #if VTK_MAJOR_VERSION > 4 || (VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION > 2)
781 else if(GetHandleHack())
783 //this means the user has reparented us; let's adapt to the
784 //new situation by doing the WindowRemap dance
785 //store the new situation
786 Handle = GetHandleHack();
787 RenderWindow->SetNextWindowId(reinterpret_cast<void *>(Handle));
788 RenderWindow->WindowRemap();
789 RenderWindow->Render();
794 //---------------------------------------------------------------------------
795 void creawxVTKRenderWindowInteractor::SetRenderWhenDisabled(int newValue)
797 //Change value of __RenderWhenDisabled ivar.
798 //If __RenderWhenDisabled is false (the default), this widget will not
799 //call Render() on the RenderWindow if the top level frame (i.e. the
800 //containing frame) has been disabled.
802 //This prevents recursive rendering during wxSafeYield() calls.
803 //wxSafeYield() can be called during the ProgressMethod() callback of
804 //a VTK object to have progress bars and other GUI elements updated -
805 //it does this by disabling all windows (disallowing user-input to
806 //prevent re-entrancy of code) and then handling all outstanding
809 //However, this often triggers an OnPaint() method for wxVTKRWIs,
810 //resulting in a Render(), resulting in Update() being called whilst
813 RenderWhenDisabled = newValue != 0;
815 //---------------------------------------------------------------------------
817 // Set the variable that indicates that we want a stereo capable window
818 // be created. This method can only be called before a window is realized.
820 void creawxVTKRenderWindowInteractor::SetStereo(int capable)
822 if (Stereo != capable)
825 RenderWindow->StereoCapableWindowOn();
826 RenderWindow->SetStereoTypeToCrystalEyes();
831 //---------------------------------------------------------------------------
834 void creawxVTKRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
836 this->Superclass::PrintSelf(os, indent);
843 //=======================================================================