]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleBaseView.cxx
#3473 Stuck Render macOS
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkInteractorStyleBaseView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "vtkInteractorStyleBaseView.h"
27
28 #include "wxVtk3DBaseView.h"
29 #include "wxVtk2DBaseView.h"
30
31 #include "vtkObjectFactory.h"
32
33 #include "InteractorStyleMaracas.h"
34
35 vtkStandardNewMacro(vtkInteractorStyleBaseView);
36 //---------------------------------------------------------------------------
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
39
40 vtkInteractorStyleBaseView::vtkInteractorStyleBaseView()
41 {
42         _refresh_waiting                = false;
43         _parent_refresh_waiting = false;
44         _blockRefresh                   = false;
45         
46         //EED27Juillet2011
47         SetMouseWheelMotionFactor(0.5);
48 }
49 //---------------------------------------------------------------------------
50 vtkInteractorStyleBaseView::~vtkInteractorStyleBaseView()
51 {
52 }
53 //---------------------------------------------------------------------------
54 void vtkInteractorStyleBaseView::OnMouseMove() // virtual 
55 {
56         CallLstInteractorStyleMaracas(3);
57 }
58 //---------------------------------------------------------------------------
59 void vtkInteractorStyleBaseView::OnLeftButtonDown()  // virtual 
60 {
61         CallLstInteractorStyleMaracas(4);
62 }
63 //---------------------------------------------------------------------------
64 void vtkInteractorStyleBaseView::OnLeftButtonUp() // virtual 
65 {
66         CallLstInteractorStyleMaracas(5);
67 }
68
69 //---------------------------------------------------------------------------
70 void vtkInteractorStyleBaseView::OnLeftDClick()  // virtual
71 {
72         CallLstInteractorStyleMaracas( 11 );
73 }
74
75 //---------------------------------------------------------------------------
76 void vtkInteractorStyleBaseView::OnMiddleButtonDown()  // virtual 
77 {
78         CallLstInteractorStyleMaracas(6);
79 }
80 //---------------------------------------------------------------------------
81 void vtkInteractorStyleBaseView::OnMiddleButtonUp() // virtual 
82 {
83         CallLstInteractorStyleMaracas(7);
84 }
85 //---------------------------------------------------------------------------
86 void vtkInteractorStyleBaseView::OnMiddleDClick()  // virtual
87 {
88         CallLstInteractorStyleMaracas( 13 );
89 }
90
91 //---------------------------------------------------------------------------
92 void vtkInteractorStyleBaseView::OnRightButtonDown() // virtual 
93 {
94         CallLstInteractorStyleMaracas(1);
95 }
96 //---------------------------------------------------------------------------
97 void vtkInteractorStyleBaseView::OnRightButtonUp() // virtual 
98 {
99         CallLstInteractorStyleMaracas(2);
100 }
101 //---------------------------------------------------------------------------
102 void vtkInteractorStyleBaseView::OnRightDClick()  // virtual
103 {
104         CallLstInteractorStyleMaracas( 12 );
105 }
106
107
108 void  vtkInteractorStyleBaseView::OnMouseWheelForward()  // virtual
109 {
110         CallLstInteractorStyleMaracas( 15 );
111 }
112
113 void vtkInteractorStyleBaseView::OnMouseWheelBackward() // virtual
114 {
115         CallLstInteractorStyleMaracas( 16 );
116 }
117 //---------------------------------------------------------------------------
118 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
119 {
120         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
121         _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
122 }
123 //---------------------------------------------------------------------------
124 void  vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
125 {
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++)
131         {
132                 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
133                 {
134                         _lstInteractorStyleMaracas.erase(iter);
135                         removed = true;
136                 } else {
137                   iter++;
138                 }               
139         }               
140 }
141 //---------------------------------------------------------------------------
142 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
143 {
144         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
145         _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
146 }
147 //---------------------------------------------------------------------------
148 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
149 {
150 printf("EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas Start \n ");
151         InteractorStyleMaracas *intStyMar;
152
153         int i,size=_lstInteractorStyleMaracas.size();
154
155 //EED Borrame
156 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
157 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
158 //for (i=0;i<size;i++)
159 //{
160 //fprintf(ff,"    %p\n" , _lstInteractorStyleMaracas[i] );
161 //}
162 //fclose(ff);
163
164
165
166         for (i=0;i<size;i++)
167         {
168                 if (i < (int)_lstInteractorStyleMaracas.size() )
169                 {
170                         intStyMar = _lstInteractorStyleMaracas[i];
171                 } else {
172                         intStyMar=NULL;
173                 }
174                 if (intStyMar!=NULL && intStyMar->GetActive()==true){
175                         if (type ==1)
176                         {  // OnRightButtonDown
177                                 if (intStyMar->OnRightButtonDown()==false)
178                                 {
179                                         i=size;
180                                 }
181                         }
182                         if (type ==2)
183                         {  // OnRightButtonUp
184                                 if (intStyMar->OnRightButtonUp()==false)
185                                 {
186                                         i=size;
187                                 }
188                         }
189                         if (type==3)
190                         {  // OnMouseMouve
191                                 if (intStyMar->OnMouseMove()==false)
192                                 {
193                                         i=size;
194                                 }
195                         }
196                         if (type==4)
197                         {  // OnLeftButtonDown
198                                 if (intStyMar->OnLeftButtonDown()==false)
199                                 {
200                                         i=size;
201                                 }
202                         }
203                         if (type==5)
204                         {  // OnLeftButtonUp
205                                 if (intStyMar->OnLeftButtonUp()==false)
206                                 {
207                                         i=size;
208                                 }
209                         }
210                         if (type==6)
211                         {  // OnMiddleButtonDown
212                                 if (intStyMar->OnMiddleButtonDown()==false)
213                                 {
214                                         i=size;
215                                 }
216                         }
217                         if (type==7)
218                         {  // OnMiddleButtonUp
219                                 if (intStyMar->OnMiddleButtonUp()==false)
220                                 {
221                                         i=size;
222                                 }
223                         }
224                         if (type==10)
225                         {  // OnMiddleButtonUp
226                                 if (intStyMar->OnChar()==false)
227                                 {
228                                         i=size;
229                                 }
230                         }
231                         if (type==11)
232                         {  // OnLeftDClick
233                                 if (intStyMar->OnLeftDClick()==false)
234                                 {
235                                         i=size;
236                                 }
237                         }
238                         if (type==12)
239                         {  // OnRightDClick
240                                 if (intStyMar->OnRightDClick()==false)
241                                 {
242                                         i=size;
243                                 }
244                         }
245                         if (type==13)
246                         {  // OnMiddleDClick
247                                 if (intStyMar-> OnMiddleDClick()==false)
248                                 {
249                                         i=size;
250                                 }
251                         }
252                         // 14 ... old OnMouseWheelFordward
253                         if (type==15)
254                         {  // OnMouseWheelForward
255                                 if (intStyMar->OnMouseWheelForward()==false)
256                                 {
257                                         i=size;
258                                 }
259                         }
260                         if (type==16)
261                         {  // OnMouseWheelBackward
262                                 if (intStyMar->OnMouseWheelBackward()==false)
263                                 {
264                                         i=size;
265                                 }
266                         }
267                         
268                         
269                 } // if active
270         } // for
271
272         EvaluateToRefresh();
273 printf("EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas End \n ");
274
275 }
276 //---------------------------------------------------------------------------
277 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
278 {    
279 //      char a=GetInteractor()->GetKeyCode();
280         CallLstInteractorStyleMaracas(10);
281 }
282 //---------------------------------------------------------------------------
283 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
284 {
285         if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
286                 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
287
288                 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
289                 imageViewer->GetRenderer()->DisplayToWorld();
290                 double fP[4];
291                 imageViewer->GetRenderer()->GetWorldPoint( fP );
292
293                 if ( fP[3] )
294                 {
295                         fP[0] /= fP[3];
296                         fP[1] /= fP[3];
297                         fP[2] /= fP[3];
298                 }
299
300         // EEDx5
301                 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
302
303                 X=fP[0];
304                 Y=fP[1];
305                 Z=fP[2];
306         }
307 }
308 //---------------------------------------------------------------------------
309 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
310 {
311         _wxvtkbaseview = wxvtkbaseview;
312 }
313 //---------------------------------------------------------------------------
314 /*JCP 13/05/2009
315 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
316 {
317         return (wxVtk2DBaseView*)_wxvtkbaseview;
318 }
319 //---------------------------------------------------------------------------
320 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
321 {
322         return (wxVtk3DBaseView*)_wxvtkbaseview;
323 }JCP 13/05/2009*/
324 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
325 {
326         return _wxvtkbaseview;
327 }
328 //---------------------------------------------------------------------------
329 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
330 {
331         return _wxvtkbaseview;
332 }
333 //---------------------------------------------------------------------------
334 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
335 {
336         InteractorStyleMaracas *intStyMar;
337         int i,size=_lstInteractorStyleMaracas.size();
338         for (i=0;i<size;i++)
339         {
340                 intStyMar = _lstInteractorStyleMaracas[i];
341                 intStyMar->SetActive(ok);
342         }
343
344 }
345 //---------------------------------------------------------------------------
346 void vtkInteractorStyleBaseView::SetRefresh_waiting()
347 {
348         _refresh_waiting=true;
349 }
350 //---------------------------------------------------------------------------
351 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
352 {
353         return _refresh_waiting;
354 }
355 //---------------------------------------------------------------------------
356 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
357 {
358         _parent_refresh_waiting=true;
359 }
360 //---------------------------------------------------------------------------
361 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
362 {
363         return _parent_refresh_waiting;
364 }
365 //---------------------------------------------------------------------------
366 void vtkInteractorStyleBaseView::EvaluateToRefresh()
367 {
368 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh Start \n ");
369         if  ( _blockRefresh==false )
370         {
371                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
372                 {
373                         _refresh_waiting                = false;
374             printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 1.0 \n ");
375                         this->_wxvtkbaseview->Refresh();
376             printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 1.1 \n ");
377                 }
378                 if (_parent_refresh_waiting==true)
379                 {
380                         _parent_refresh_waiting = false;
381                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
382 //CPR 13/01/2010
383 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
384 #if wxMAJOR_VERSION <= 2
385                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
386 #else
387             printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 2.0 \n ");
388                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
389             printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 2.1 \n ");
390 #endif
391
392                         int i;
393                         int size = _lstParentToReport.size();
394                         for(i = 0; i<size; i++)
395                         {       
396                 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 3.0 \n ");
397                                 _lstParentToReport[i]->ProcessEvent(newevent1);
398                 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh 3.1 \n ");
399                         }//for
400                 }//if
401         }//if _blockRefresh
402 printf("EED vtkInteractorStyleBaseView::EvaluateToRefresh End\n");
403 }
404 //---------------------------------------------------------------------------
405 void vtkInteractorStyleBaseView::BlockRefresh()
406 {
407         _blockRefresh=true;
408 }
409 //---------------------------------------------------------------------------
410 void vtkInteractorStyleBaseView::UnBlockRefresh()
411 {
412         _blockRefresh=false;
413 }
414
415 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
416 {
417         wxEvtHandler* parentToReport = NULL;
418         if(i>=0 && i<_lstParentToReport.size())
419         {       
420                 parentToReport = _lstParentToReport[i];
421         }
422         return parentToReport;
423
424 }
425
426 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
427 {
428         _lstParentToReport.push_back(parentToReport);
429 }