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