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();
155 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
156 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
157 //for (i=0;i<size;i++)
159 //fprintf(ff," %p\n" , _lstInteractorStyleMaracas[i] );
167 if (i < (int)_lstInteractorStyleMaracas.size() )
169 intStyMar = _lstInteractorStyleMaracas[i];
173 if (intStyMar!=NULL && intStyMar->GetActive()==true){
175 { // OnRightButtonDown
176 if (intStyMar->OnRightButtonDown()==false)
183 if (intStyMar->OnRightButtonUp()==false)
190 if (intStyMar->OnMouseMove()==false)
196 { // OnLeftButtonDown
197 if (intStyMar->OnLeftButtonDown()==false)
204 if (intStyMar->OnLeftButtonUp()==false)
210 { // OnMiddleButtonDown
211 if (intStyMar->OnMiddleButtonDown()==false)
217 { // OnMiddleButtonUp
218 if (intStyMar->OnMiddleButtonUp()==false)
224 { // OnMiddleButtonUp
225 if (intStyMar->OnChar()==false)
232 if (intStyMar->OnLeftDClick()==false)
239 if (intStyMar->OnRightDClick()==false)
246 if (intStyMar-> OnMiddleDClick()==false)
251 // 14 ... old OnMouseWheelFordward
253 { // OnMouseWheelForward
254 if (intStyMar->OnMouseWheelForward()==false)
260 { // OnMouseWheelBackward
261 if (intStyMar->OnMouseWheelBackward()==false)
273 //---------------------------------------------------------------------------
274 void vtkInteractorStyleBaseView::OnChar() // virtual
276 // char a=GetInteractor()->GetKeyCode();
277 CallLstInteractorStyleMaracas(10);
279 //---------------------------------------------------------------------------
280 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
282 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
283 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
285 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
286 imageViewer->GetRenderer()->DisplayToWorld();
288 imageViewer->GetRenderer()->GetWorldPoint( fP );
297 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
304 //---------------------------------------------------------------------------
305 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
307 _wxvtkbaseview = wxvtkbaseview;
309 //---------------------------------------------------------------------------
311 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
313 return (wxVtk2DBaseView*)_wxvtkbaseview;
315 //---------------------------------------------------------------------------
316 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
318 return (wxVtk3DBaseView*)_wxvtkbaseview;
320 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
322 return _wxvtkbaseview;
324 //---------------------------------------------------------------------------
325 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
327 return _wxvtkbaseview;
329 //---------------------------------------------------------------------------
330 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
332 InteractorStyleMaracas *intStyMar;
333 int i,size=_lstInteractorStyleMaracas.size();
336 intStyMar = _lstInteractorStyleMaracas[i];
337 intStyMar->SetActive(ok);
341 //---------------------------------------------------------------------------
342 void vtkInteractorStyleBaseView::SetRefresh_waiting()
344 _refresh_waiting=true;
346 //---------------------------------------------------------------------------
347 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
349 return _refresh_waiting;
351 //---------------------------------------------------------------------------
352 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
354 _parent_refresh_waiting=true;
356 //---------------------------------------------------------------------------
357 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
359 return _parent_refresh_waiting;
361 //---------------------------------------------------------------------------
362 void vtkInteractorStyleBaseView::EvaluateToRefresh()
364 if ( _blockRefresh==false )
366 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
368 _refresh_waiting = false;
369 this->_wxvtkbaseview->Refresh();
371 if (_parent_refresh_waiting==true)
373 _parent_refresh_waiting = false;
374 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
376 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
378 int size = _lstParentToReport.size();
379 for(i = 0; i<size; i++)
381 _lstParentToReport[i]->ProcessEvent(newevent1);
386 //---------------------------------------------------------------------------
387 void vtkInteractorStyleBaseView::BlockRefresh()
391 //---------------------------------------------------------------------------
392 void vtkInteractorStyleBaseView::UnBlockRefresh()
397 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
399 wxEvtHandler* parentToReport = NULL;
400 if(i>=0 && i<_lstParentToReport.size())
402 parentToReport = _lstParentToReport[i];
404 return parentToReport;
408 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
410 _lstParentToReport.push_back(parentToReport);