1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "vtkInteractorStyleBaseView.h"
28 #include "wxVtk3DBaseView.h"
29 #include "wxVtk2DBaseView.h"
31 #include "vtkObjectFactory.h"
33 #include "InteractorStyleMaracas.h"
35 vtkStandardNewMacro(vtkInteractorStyleBaseView);
36 //---------------------------------------------------------------------------
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
40 vtkInteractorStyleBaseView::vtkInteractorStyleBaseView()
42 _refresh_waiting = false;
43 _parent_refresh_waiting = false;
44 _blockRefresh = false;
47 SetMouseWheelMotionFactor(0.5);
49 //---------------------------------------------------------------------------
50 vtkInteractorStyleBaseView::~vtkInteractorStyleBaseView()
53 //---------------------------------------------------------------------------
54 void vtkInteractorStyleBaseView::OnMouseMove() // virtual
56 CallLstInteractorStyleMaracas(3);
58 //---------------------------------------------------------------------------
59 void vtkInteractorStyleBaseView::OnLeftButtonDown() // virtual
61 CallLstInteractorStyleMaracas(4);
63 //---------------------------------------------------------------------------
64 void vtkInteractorStyleBaseView::OnLeftButtonUp() // virtual
66 CallLstInteractorStyleMaracas(5);
69 //---------------------------------------------------------------------------
70 void vtkInteractorStyleBaseView::OnLeftDClick() // virtual
72 CallLstInteractorStyleMaracas( 11 );
75 //---------------------------------------------------------------------------
76 void vtkInteractorStyleBaseView::OnMiddleButtonDown() // virtual
78 CallLstInteractorStyleMaracas(6);
80 //---------------------------------------------------------------------------
81 void vtkInteractorStyleBaseView::OnMiddleButtonUp() // virtual
83 CallLstInteractorStyleMaracas(7);
85 //---------------------------------------------------------------------------
86 void vtkInteractorStyleBaseView::OnMiddleDClick() // virtual
88 CallLstInteractorStyleMaracas( 13 );
91 //---------------------------------------------------------------------------
92 void vtkInteractorStyleBaseView::OnRightButtonDown() // virtual
94 CallLstInteractorStyleMaracas(1);
96 //---------------------------------------------------------------------------
97 void vtkInteractorStyleBaseView::OnRightButtonUp() // virtual
99 CallLstInteractorStyleMaracas(2);
101 //---------------------------------------------------------------------------
102 void vtkInteractorStyleBaseView::OnRightDClick() // virtual
104 CallLstInteractorStyleMaracas( 12 );
108 void vtkInteractorStyleBaseView::OnMouseWheelForward() // virtual
110 CallLstInteractorStyleMaracas( 15 );
113 void vtkInteractorStyleBaseView::OnMouseWheelBackward() // virtual
115 CallLstInteractorStyleMaracas( 16 );
117 //---------------------------------------------------------------------------
118 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
120 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
121 _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
123 //---------------------------------------------------------------------------
124 void vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
126 interactorStyleMaracas->RemoveVtkInteractorStyleBaseView();
127 int i, size = _lstInteractorStyleMaracas.size();
128 std::vector< InteractorStyleMaracas* >::iterator iter = _lstInteractorStyleMaracas.begin();
129 bool removed = false;
130 for (i=0; !removed && i<size; i++)
132 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
134 _lstInteractorStyleMaracas.erase(iter);
141 //---------------------------------------------------------------------------
142 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
144 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
145 _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
147 //---------------------------------------------------------------------------
148 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
150 InteractorStyleMaracas *intStyMar;
152 int i,size=_lstInteractorStyleMaracas.size();
157 if (i < (int)_lstInteractorStyleMaracas.size() )
159 intStyMar = _lstInteractorStyleMaracas[i];
163 if (intStyMar!=NULL && intStyMar->GetActive()==true){
165 { // OnRightButtonDown
166 if (intStyMar->OnRightButtonDown()==false)
173 if (intStyMar->OnRightButtonUp()==false)
180 if (intStyMar->OnMouseMove()==false)
186 { // OnLeftButtonDown
187 if (intStyMar->OnLeftButtonDown()==false)
194 if (intStyMar->OnLeftButtonUp()==false)
200 { // OnMiddleButtonDown
201 if (intStyMar->OnMiddleButtonDown()==false)
207 { // OnMiddleButtonUp
208 if (intStyMar->OnMiddleButtonUp()==false)
214 { // OnMiddleButtonUp
215 if (intStyMar->OnChar()==false)
222 if (intStyMar->OnLeftDClick()==false)
229 if (intStyMar->OnRightDClick()==false)
236 if (intStyMar-> OnMiddleDClick()==false)
241 // 14 ... old OnMouseWheelFordward
243 { // OnMouseWheelForward
244 if (intStyMar->OnMouseWheelForward()==false)
250 { // OnMouseWheelBackward
251 if (intStyMar->OnMouseWheelBackward()==false)
263 //---------------------------------------------------------------------------
264 void vtkInteractorStyleBaseView::OnChar() // virtual
266 // char a=GetInteractor()->GetKeyCode();
267 CallLstInteractorStyleMaracas(10);
269 //---------------------------------------------------------------------------
270 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
272 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
273 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
275 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
276 imageViewer->GetRenderer()->DisplayToWorld();
278 imageViewer->GetRenderer()->GetWorldPoint( fP );
288 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
295 //---------------------------------------------------------------------------
296 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
298 _wxvtkbaseview = wxvtkbaseview;
300 //---------------------------------------------------------------------------
302 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
304 return (wxVtk2DBaseView*)_wxvtkbaseview;
306 //---------------------------------------------------------------------------
307 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
309 return (wxVtk3DBaseView*)_wxvtkbaseview;
311 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
313 return _wxvtkbaseview;
315 //---------------------------------------------------------------------------
316 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
318 return _wxvtkbaseview;
320 //---------------------------------------------------------------------------
321 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
323 InteractorStyleMaracas *intStyMar;
324 int i,size=_lstInteractorStyleMaracas.size();
327 intStyMar = _lstInteractorStyleMaracas[i];
328 intStyMar->SetActive(ok);
332 //---------------------------------------------------------------------------
333 void vtkInteractorStyleBaseView::SetRefresh_waiting()
335 _refresh_waiting=true;
337 //---------------------------------------------------------------------------
338 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
340 return _refresh_waiting;
342 //---------------------------------------------------------------------------
343 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
345 _parent_refresh_waiting=true;
347 //---------------------------------------------------------------------------
348 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
350 return _parent_refresh_waiting;
352 //---------------------------------------------------------------------------
353 void vtkInteractorStyleBaseView::EvaluateToRefresh()
355 if ( _blockRefresh==false )
357 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
359 _refresh_waiting = false;
360 this->_wxvtkbaseview->Refresh();
362 if (_parent_refresh_waiting==true)
364 _parent_refresh_waiting = false;
365 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
367 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
368 #if wxMAJOR_VERSION <= 2
369 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
371 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
375 int size = _lstParentToReport.size();
376 for(i = 0; i<size; i++)
378 _lstParentToReport[i]->ProcessEvent(newevent1);
383 //---------------------------------------------------------------------------
384 void vtkInteractorStyleBaseView::BlockRefresh()
388 //---------------------------------------------------------------------------
389 void vtkInteractorStyleBaseView::UnBlockRefresh()
394 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
396 wxEvtHandler* parentToReport = NULL;
397 if(i>=0 && i<_lstParentToReport.size())
399 parentToReport = _lstParentToReport[i];
401 return parentToReport;
405 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
407 _lstParentToReport.push_back(parentToReport);