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)
155 InteractorStyleMaracas *intStyMar;
157 int i,size=_lstInteractorStyleMaracas.size();
160 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
161 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
162 //for (i=0;i<size;i++)
164 //fprintf(ff," %p\n" , _lstInteractorStyleMaracas[i] );
172 if (i < (int)_lstInteractorStyleMaracas.size() )
174 intStyMar = _lstInteractorStyleMaracas[i];
178 if (intStyMar!=NULL && intStyMar->GetActive()==true){
180 { // OnRightButtonDown
181 if (intStyMar->OnRightButtonDown()==false)
188 if (intStyMar->OnRightButtonUp()==false)
195 if (intStyMar->OnMouseMove()==false)
201 { // OnLeftButtonDown
202 if (intStyMar->OnLeftButtonDown()==false)
209 if (intStyMar->OnLeftButtonUp()==false)
215 { // OnMiddleButtonDown
216 if (intStyMar->OnMiddleButtonDown()==false)
222 { // OnMiddleButtonUp
223 if (intStyMar->OnMiddleButtonUp()==false)
229 { // OnMiddleButtonUp
230 if (intStyMar->OnChar()==false)
237 if (intStyMar->OnLeftDClick()==false)
244 if (intStyMar->OnRightDClick()==false)
251 if (intStyMar-> OnMiddleDClick()==false)
256 // 14 ... old OnMouseWheelFordward
258 { // OnMouseWheelForward
259 if (intStyMar->OnMouseWheelForward()==false)
265 { // OnMouseWheelBackward
266 if (intStyMar->OnMouseWheelBackward()==false)
278 //---------------------------------------------------------------------------
279 void vtkInteractorStyleBaseView::OnChar() // virtual
281 // char a=GetInteractor()->GetKeyCode();
282 CallLstInteractorStyleMaracas(10);
284 //---------------------------------------------------------------------------
285 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
287 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
288 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
290 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
291 imageViewer->GetRenderer()->DisplayToWorld();
293 imageViewer->GetRenderer()->GetWorldPoint( fP );
302 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
309 //---------------------------------------------------------------------------
310 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
312 _wxvtkbaseview = wxvtkbaseview;
314 //---------------------------------------------------------------------------
316 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
318 return (wxVtk2DBaseView*)_wxvtkbaseview;
320 //---------------------------------------------------------------------------
321 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
323 return (wxVtk3DBaseView*)_wxvtkbaseview;
325 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
327 return _wxvtkbaseview;
329 //---------------------------------------------------------------------------
330 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
332 return _wxvtkbaseview;
334 //---------------------------------------------------------------------------
335 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
337 InteractorStyleMaracas *intStyMar;
338 int i,size=_lstInteractorStyleMaracas.size();
341 intStyMar = _lstInteractorStyleMaracas[i];
342 intStyMar->SetActive(ok);
346 //---------------------------------------------------------------------------
347 void vtkInteractorStyleBaseView::SetRefresh_waiting()
349 _refresh_waiting=true;
351 //---------------------------------------------------------------------------
352 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
354 return _refresh_waiting;
356 //---------------------------------------------------------------------------
357 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
359 _parent_refresh_waiting=true;
361 //---------------------------------------------------------------------------
362 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
364 return _parent_refresh_waiting;
366 //---------------------------------------------------------------------------
367 void vtkInteractorStyleBaseView::EvaluateToRefresh()
370 if ( _blockRefresh==false )
372 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
374 _refresh_waiting = false;
375 this->_wxvtkbaseview->Refresh();
377 if (_parent_refresh_waiting==true)
379 _parent_refresh_waiting = false;
380 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
382 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
384 int size = _lstParentToReport.size();
385 for(i = 0; i<size; i++)
387 _lstParentToReport[i]->ProcessEvent(newevent1);
392 //---------------------------------------------------------------------------
393 void vtkInteractorStyleBaseView::BlockRefresh()
397 //---------------------------------------------------------------------------
398 void vtkInteractorStyleBaseView::UnBlockRefresh()
403 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
405 wxEvtHandler* parentToReport = NULL;
406 if(i>=0 && i<_lstParentToReport.size())
408 parentToReport = _lstParentToReport[i];
410 return parentToReport;
414 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
416 _lstParentToReport.push_back(parentToReport);