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 );
121 //---------------------------------------------------------------------------
122 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
124 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
125 _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
127 //---------------------------------------------------------------------------
128 void vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
130 interactorStyleMaracas->RemoveVtkInteractorStyleBaseView();
131 int i, size = _lstInteractorStyleMaracas.size();
132 std::vector< InteractorStyleMaracas* >::iterator iter = _lstInteractorStyleMaracas.begin();
133 bool removed = false;
134 for (i=0; !removed && i<size; i++)
136 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
138 _lstInteractorStyleMaracas.erase(iter);
145 //---------------------------------------------------------------------------
146 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
148 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
149 _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
151 //---------------------------------------------------------------------------
152 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
154 InteractorStyleMaracas *intStyMar;
156 int i,size=_lstInteractorStyleMaracas.size();
159 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
160 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
161 //for (i=0;i<size;i++)
163 //fprintf(ff," %p\n" , _lstInteractorStyleMaracas[i] );
171 if (i < (int)_lstInteractorStyleMaracas.size() )
173 intStyMar = _lstInteractorStyleMaracas[i];
177 if (intStyMar!=NULL && intStyMar->GetActive()==true){
179 { // OnRightButtonDown
180 if (intStyMar->OnRightButtonDown()==false)
187 if (intStyMar->OnRightButtonUp()==false)
194 if (intStyMar->OnMouseMove()==false)
200 { // OnLeftButtonDown
201 if (intStyMar->OnLeftButtonDown()==false)
208 if (intStyMar->OnLeftButtonUp()==false)
214 { // OnMiddleButtonDown
215 if (intStyMar->OnMiddleButtonDown()==false)
221 { // OnMiddleButtonUp
222 if (intStyMar->OnMiddleButtonUp()==false)
228 { // OnMiddleButtonUp
229 if (intStyMar->OnChar()==false)
236 if (intStyMar->OnLeftDClick()==false)
243 if (intStyMar->OnRightDClick()==false)
250 if (intStyMar-> OnMiddleDClick()==false)
255 // 14 ... old OnMouseWheelFordward
257 { // OnMouseWheelForward
258 if (intStyMar->OnMouseWheelForward()==false)
264 { // OnMouseWheelBackward
265 if (intStyMar->OnMouseWheelBackward()==false)
277 //---------------------------------------------------------------------------
278 void vtkInteractorStyleBaseView::OnChar() // virtual
280 // char a=GetInteractor()->GetKeyCode();
281 CallLstInteractorStyleMaracas(10);
283 //---------------------------------------------------------------------------
284 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
286 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
287 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
289 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
290 imageViewer->GetRenderer()->DisplayToWorld();
292 imageViewer->GetRenderer()->GetWorldPoint( fP );
301 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
308 //---------------------------------------------------------------------------
309 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
311 _wxvtkbaseview = wxvtkbaseview;
313 //---------------------------------------------------------------------------
315 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
317 return (wxVtk2DBaseView*)_wxvtkbaseview;
319 //---------------------------------------------------------------------------
320 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
322 return (wxVtk3DBaseView*)_wxvtkbaseview;
324 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
326 return _wxvtkbaseview;
328 //---------------------------------------------------------------------------
329 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
331 return _wxvtkbaseview;
333 //---------------------------------------------------------------------------
334 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
336 InteractorStyleMaracas *intStyMar;
337 int i,size=_lstInteractorStyleMaracas.size();
340 intStyMar = _lstInteractorStyleMaracas[i];
341 intStyMar->SetActive(ok);
345 //---------------------------------------------------------------------------
346 void vtkInteractorStyleBaseView::SetRefresh_waiting()
348 _refresh_waiting=true;
350 //---------------------------------------------------------------------------
351 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
353 return _refresh_waiting;
355 //---------------------------------------------------------------------------
356 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
358 _parent_refresh_waiting=true;
360 //---------------------------------------------------------------------------
361 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
363 return _parent_refresh_waiting;
365 //---------------------------------------------------------------------------
366 void vtkInteractorStyleBaseView::EvaluateToRefresh()
368 if ( _blockRefresh==false )
370 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
372 _refresh_waiting = false;
373 this->_wxvtkbaseview->Refresh();
375 if (_parent_refresh_waiting==true)
377 _parent_refresh_waiting = false;
378 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
380 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
382 int size = _lstParentToReport.size();
383 for(i = 0; i<size; i++)
385 _lstParentToReport[i]->ProcessEvent(newevent1);
390 //---------------------------------------------------------------------------
391 void vtkInteractorStyleBaseView::BlockRefresh()
395 //---------------------------------------------------------------------------
396 void vtkInteractorStyleBaseView::UnBlockRefresh()
401 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
403 wxEvtHandler* parentToReport = NULL;
404 if(i>=0 && i<_lstParentToReport.size())
406 parentToReport = _lstParentToReport[i];
408 return parentToReport;
412 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
414 _lstParentToReport.push_back(parentToReport);