]> 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         InteractorStyleMaracas *intStyMar;
151
152         int i,size=_lstInteractorStyleMaracas.size();
153
154
155         for (i=0;i<size;i++)
156         {
157                 if (i < (int)_lstInteractorStyleMaracas.size() )
158                 {
159                         intStyMar = _lstInteractorStyleMaracas[i];
160                 } else {
161                         intStyMar=NULL;
162                 }
163                 if (intStyMar!=NULL && intStyMar->GetActive()==true){
164                         if (type ==1)
165                         {  // OnRightButtonDown
166                                 if (intStyMar->OnRightButtonDown()==false)
167                                 {
168                                         i=size;
169                                 }
170                         }
171                         if (type ==2)
172                         {  // OnRightButtonUp
173                                 if (intStyMar->OnRightButtonUp()==false)
174                                 {
175                                         i=size;
176                                 }
177                         }
178                         if (type==3)
179                         {  // OnMouseMouve
180                                 if (intStyMar->OnMouseMove()==false)
181                                 {
182                                         i=size;
183                                 }
184                         }
185                         if (type==4)
186                         {  // OnLeftButtonDown
187                                 if (intStyMar->OnLeftButtonDown()==false)
188                                 {
189                                         i=size;
190                                 }
191                         }
192                         if (type==5)
193                         {  // OnLeftButtonUp
194                                 if (intStyMar->OnLeftButtonUp()==false)
195                                 {
196                                         i=size;
197                                 }
198                         }
199                         if (type==6)
200                         {  // OnMiddleButtonDown
201                                 if (intStyMar->OnMiddleButtonDown()==false)
202                                 {
203                                         i=size;
204                                 }
205                         }
206                         if (type==7)
207                         {  // OnMiddleButtonUp
208                                 if (intStyMar->OnMiddleButtonUp()==false)
209                                 {
210                                         i=size;
211                                 }
212                         }
213                         if (type==10)
214                         {  // OnMiddleButtonUp
215                                 if (intStyMar->OnChar()==false)
216                                 {
217                                         i=size;
218                                 }
219                         }
220                         if (type==11)
221                         {  // OnLeftDClick
222                                 if (intStyMar->OnLeftDClick()==false)
223                                 {
224                                         i=size;
225                                 }
226                         }
227                         if (type==12)
228                         {  // OnRightDClick
229                                 if (intStyMar->OnRightDClick()==false)
230                                 {
231                                         i=size;
232                                 }
233                         }
234                         if (type==13)
235                         {  // OnMiddleDClick
236                                 if (intStyMar-> OnMiddleDClick()==false)
237                                 {
238                                         i=size;
239                                 }
240                         }
241                         // 14 ... old OnMouseWheelFordward
242                         if (type==15)
243                         {  // OnMouseWheelForward
244                                 if (intStyMar->OnMouseWheelForward()==false)
245                                 {
246                                         i=size;
247                                 }
248                         }
249                         if (type==16)
250                         {  // OnMouseWheelBackward
251                                 if (intStyMar->OnMouseWheelBackward()==false)
252                                 {
253                                         i=size;
254                                 }
255                         }
256                         
257                         
258                 } // if active
259         } // for
260
261         EvaluateToRefresh();
262 }
263 //---------------------------------------------------------------------------
264 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
265 {    
266 //      char a=GetInteractor()->GetKeyCode();
267         CallLstInteractorStyleMaracas(10);
268 }
269 //---------------------------------------------------------------------------
270 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
271 {
272         if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
273                 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
274
275                 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
276                 imageViewer->GetRenderer()->DisplayToWorld();
277                 double fP[4];
278                 imageViewer->GetRenderer()->GetWorldPoint( fP );
279
280                 if ( fP[3] )
281                 {
282                         fP[0] /= fP[3];
283                         fP[1] /= fP[3];
284                         fP[2] /= fP[3];
285                 }
286
287         // EEDx5
288                 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
289
290                 X=fP[0];
291                 Y=fP[1];
292                 Z=fP[2];
293         }
294 }
295 //---------------------------------------------------------------------------
296 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
297 {
298         _wxvtkbaseview = wxvtkbaseview;
299 }
300 //---------------------------------------------------------------------------
301 /*JCP 13/05/2009
302 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
303 {
304         return (wxVtk2DBaseView*)_wxvtkbaseview;
305 }
306 //---------------------------------------------------------------------------
307 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
308 {
309         return (wxVtk3DBaseView*)_wxvtkbaseview;
310 }JCP 13/05/2009*/
311 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
312 {
313         return _wxvtkbaseview;
314 }
315 //---------------------------------------------------------------------------
316 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
317 {
318         return _wxvtkbaseview;
319 }
320 //---------------------------------------------------------------------------
321 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
322 {
323         InteractorStyleMaracas *intStyMar;
324         int i,size=_lstInteractorStyleMaracas.size();
325         for (i=0;i<size;i++)
326         {
327                 intStyMar = _lstInteractorStyleMaracas[i];
328                 intStyMar->SetActive(ok);
329         }
330
331 }
332 //---------------------------------------------------------------------------
333 void vtkInteractorStyleBaseView::SetRefresh_waiting()
334 {
335         _refresh_waiting=true;
336 }
337 //---------------------------------------------------------------------------
338 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
339 {
340         return _refresh_waiting;
341 }
342 //---------------------------------------------------------------------------
343 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
344 {
345         _parent_refresh_waiting=true;
346 }
347 //---------------------------------------------------------------------------
348 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
349 {
350         return _parent_refresh_waiting;
351 }
352 //---------------------------------------------------------------------------
353 void vtkInteractorStyleBaseView::EvaluateToRefresh()
354 {
355         if  ( _blockRefresh==false )
356         {
357                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
358                 {
359                         _refresh_waiting                = false;
360                         this->_wxvtkbaseview->Refresh();
361                 }
362                 if (_parent_refresh_waiting==true)
363                 {
364                         _parent_refresh_waiting = false;
365                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
366 //CPR 13/01/2010
367 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
368 #if wxMAJOR_VERSION <= 2
369                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
370 #else
371                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
372 #endif
373
374                         int i;
375                         int size = _lstParentToReport.size();
376                         for(i = 0; i<size; i++)
377                         {       
378                                 _lstParentToReport[i]->ProcessEvent(newevent1);
379                         }//for
380                 }//if
381         }//if _blockRefresh
382 }
383 //---------------------------------------------------------------------------
384 void vtkInteractorStyleBaseView::BlockRefresh()
385 {
386         _blockRefresh=true;
387 }
388 //---------------------------------------------------------------------------
389 void vtkInteractorStyleBaseView::UnBlockRefresh()
390 {
391         _blockRefresh=false;
392 }
393
394 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
395 {
396         wxEvtHandler* parentToReport = NULL;
397         if(i>=0 && i<_lstParentToReport.size())
398         {       
399                 parentToReport = _lstParentToReport[i];
400         }
401         return parentToReport;
402
403 }
404
405 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
406 {
407         _lstParentToReport.push_back(parentToReport);
408 }