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)
156 printf("EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas Start --------\n");
157 InteractorStyleMaracas *intStyMar;
159 int i,size=_lstInteractorStyleMaracas.size();
162 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
163 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
164 //for (i=0;i<size;i++)
166 //fprintf(ff," %p\n" , _lstInteractorStyleMaracas[i] );
174 if (i < (int)_lstInteractorStyleMaracas.size() )
176 intStyMar = _lstInteractorStyleMaracas[i];
180 if (intStyMar!=NULL && intStyMar->GetActive()==true){
182 { // OnRightButtonDown
183 if (intStyMar->OnRightButtonDown()==false)
190 if (intStyMar->OnRightButtonUp()==false)
197 if (intStyMar->OnMouseMove()==false)
203 { // OnLeftButtonDown
204 if (intStyMar->OnLeftButtonDown()==false)
211 if (intStyMar->OnLeftButtonUp()==false)
217 { // OnMiddleButtonDown
218 if (intStyMar->OnMiddleButtonDown()==false)
224 { // OnMiddleButtonUp
225 if (intStyMar->OnMiddleButtonUp()==false)
231 { // OnMiddleButtonUp
232 if (intStyMar->OnChar()==false)
239 if (intStyMar->OnLeftDClick()==false)
246 if (intStyMar->OnRightDClick()==false)
253 if (intStyMar-> OnMiddleDClick()==false)
258 // 14 ... old OnMouseWheelFordward
260 { // OnMouseWheelForward
261 if (intStyMar->OnMouseWheelForward()==false)
267 { // OnMouseWheelBackward
268 if (intStyMar->OnMouseWheelBackward()==false)
280 //---------------------------------------------------------------------------
281 void vtkInteractorStyleBaseView::OnChar() // virtual
283 // char a=GetInteractor()->GetKeyCode();
284 CallLstInteractorStyleMaracas(10);
286 //---------------------------------------------------------------------------
287 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
289 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
290 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
292 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
293 imageViewer->GetRenderer()->DisplayToWorld();
295 imageViewer->GetRenderer()->GetWorldPoint( fP );
304 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
311 //---------------------------------------------------------------------------
312 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
314 _wxvtkbaseview = wxvtkbaseview;
316 //---------------------------------------------------------------------------
318 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
320 return (wxVtk2DBaseView*)_wxvtkbaseview;
322 //---------------------------------------------------------------------------
323 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
325 return (wxVtk3DBaseView*)_wxvtkbaseview;
327 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
329 return _wxvtkbaseview;
331 //---------------------------------------------------------------------------
332 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
334 return _wxvtkbaseview;
336 //---------------------------------------------------------------------------
337 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
339 InteractorStyleMaracas *intStyMar;
340 int i,size=_lstInteractorStyleMaracas.size();
343 intStyMar = _lstInteractorStyleMaracas[i];
344 intStyMar->SetActive(ok);
348 //---------------------------------------------------------------------------
349 void vtkInteractorStyleBaseView::SetRefresh_waiting()
351 _refresh_waiting=true;
353 //---------------------------------------------------------------------------
354 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
356 return _refresh_waiting;
358 //---------------------------------------------------------------------------
359 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
361 _parent_refresh_waiting=true;
363 //---------------------------------------------------------------------------
364 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
366 return _parent_refresh_waiting;
368 //---------------------------------------------------------------------------
369 void vtkInteractorStyleBaseView::EvaluateToRefresh()
371 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh start 1\n");
372 if ( _blockRefresh==false )
374 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
376 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh start 2\n");
377 _refresh_waiting = false;
378 this->_wxvtkbaseview->Refresh();
380 if (_parent_refresh_waiting==true)
382 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh start 3\n");
383 _parent_refresh_waiting = false;
384 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
386 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
388 int size = _lstParentToReport.size();
389 for(i = 0; i<size; i++)
391 _lstParentToReport[i]->ProcessEvent(newevent1);
396 //---------------------------------------------------------------------------
397 void vtkInteractorStyleBaseView::BlockRefresh()
401 //---------------------------------------------------------------------------
402 void vtkInteractorStyleBaseView::UnBlockRefresh()
407 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
409 wxEvtHandler* parentToReport = NULL;
410 if(i>=0 && i<_lstParentToReport.size())
412 parentToReport = _lstParentToReport[i];
414 return parentToReport;
418 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
420 _lstParentToReport.push_back(parentToReport);