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 printf("EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas Start \n ");
151 InteractorStyleMaracas *intStyMar;
153 int i,size=_lstInteractorStyleMaracas.size();
156 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
157 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
158 //for (i=0;i<size;i++)
160 //fprintf(ff," %p\n" , _lstInteractorStyleMaracas[i] );
168 if (i < (int)_lstInteractorStyleMaracas.size() )
170 intStyMar = _lstInteractorStyleMaracas[i];
174 if (intStyMar!=NULL && intStyMar->GetActive()==true){
176 { // OnRightButtonDown
177 if (intStyMar->OnRightButtonDown()==false)
184 if (intStyMar->OnRightButtonUp()==false)
191 if (intStyMar->OnMouseMove()==false)
197 { // OnLeftButtonDown
198 if (intStyMar->OnLeftButtonDown()==false)
205 if (intStyMar->OnLeftButtonUp()==false)
211 { // OnMiddleButtonDown
212 if (intStyMar->OnMiddleButtonDown()==false)
218 { // OnMiddleButtonUp
219 if (intStyMar->OnMiddleButtonUp()==false)
225 { // OnMiddleButtonUp
226 if (intStyMar->OnChar()==false)
233 if (intStyMar->OnLeftDClick()==false)
240 if (intStyMar->OnRightDClick()==false)
247 if (intStyMar-> OnMiddleDClick()==false)
252 // 14 ... old OnMouseWheelFordward
254 { // OnMouseWheelForward
255 if (intStyMar->OnMouseWheelForward()==false)
261 { // OnMouseWheelBackward
262 if (intStyMar->OnMouseWheelBackward()==false)
273 printf("EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas End \n ");
276 //---------------------------------------------------------------------------
277 void vtkInteractorStyleBaseView::OnChar() // virtual
279 // char a=GetInteractor()->GetKeyCode();
280 CallLstInteractorStyleMaracas(10);
282 //---------------------------------------------------------------------------
283 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
285 if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
286 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
288 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
289 imageViewer->GetRenderer()->DisplayToWorld();
291 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 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh Start \n ");
369 if ( _blockRefresh==false )
371 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
373 _refresh_waiting = false;
374 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 1.0 \n ");
375 this->_wxvtkbaseview->Refresh();
376 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 1.1 \n ");
378 if (_parent_refresh_waiting==true)
380 _parent_refresh_waiting = false;
381 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
383 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
384 #if wxMAJOR_VERSION <= 2
385 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
387 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 2.0 \n ");
388 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
389 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 2.1 \n ");
393 int size = _lstParentToReport.size();
394 for(i = 0; i<size; i++)
396 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 3.0 \n ");
397 _lstParentToReport[i]->ProcessEvent(newevent1);
398 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 3.1 \n ");
402 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh End\n");
404 //---------------------------------------------------------------------------
405 void vtkInteractorStyleBaseView::BlockRefresh()
409 //---------------------------------------------------------------------------
410 void vtkInteractorStyleBaseView::UnBlockRefresh()
415 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
417 wxEvtHandler* parentToReport = NULL;
418 if(i>=0 && i<_lstParentToReport.size())
420 parentToReport = _lstParentToReport[i];
422 return parentToReport;
426 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
428 _lstParentToReport.push_back(parentToReport);