]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleBaseView.cxx
21f323355704a8f0f3dfa44691286b4d6c9ada41
[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         InteractorStyleMaracas *intStyMar;
155
156         int i,size=_lstInteractorStyleMaracas.size();
157
158 //EED Borrame
159 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
160 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
161 //for (i=0;i<size;i++)
162 //{
163 //fprintf(ff,"    %p\n" , _lstInteractorStyleMaracas[i] );
164 //}
165 //fclose(ff);
166
167
168
169         for (i=0;i<size;i++)
170         {
171                 if (i < (int)_lstInteractorStyleMaracas.size() )
172                 {
173                         intStyMar = _lstInteractorStyleMaracas[i];
174                 } else {
175                         intStyMar=NULL;
176                 }
177                 if (intStyMar!=NULL && intStyMar->GetActive()==true){
178                         if (type ==1)
179                         {  // OnRightButtonDown
180                                 if (intStyMar->OnRightButtonDown()==false)
181                                 {
182                                         i=size;
183                                 }
184                         }
185                         if (type ==2)
186                         {  // OnRightButtonUp
187                                 if (intStyMar->OnRightButtonUp()==false)
188                                 {
189                                         i=size;
190                                 }
191                         }
192                         if (type==3)
193                         {  // OnMouseMouve
194                                 if (intStyMar->OnMouseMove()==false)
195                                 {
196                                         i=size;
197                                 }
198                         }
199                         if (type==4)
200                         {  // OnLeftButtonDown
201                                 if (intStyMar->OnLeftButtonDown()==false)
202                                 {
203                                         i=size;
204                                 }
205                         }
206                         if (type==5)
207                         {  // OnLeftButtonUp
208                                 if (intStyMar->OnLeftButtonUp()==false)
209                                 {
210                                         i=size;
211                                 }
212                         }
213                         if (type==6)
214                         {  // OnMiddleButtonDown
215                                 if (intStyMar->OnMiddleButtonDown()==false)
216                                 {
217                                         i=size;
218                                 }
219                         }
220                         if (type==7)
221                         {  // OnMiddleButtonUp
222                                 if (intStyMar->OnMiddleButtonUp()==false)
223                                 {
224                                         i=size;
225                                 }
226                         }
227                         if (type==10)
228                         {  // OnMiddleButtonUp
229                                 if (intStyMar->OnChar()==false)
230                                 {
231                                         i=size;
232                                 }
233                         }
234                         if (type==11)
235                         {  // OnLeftDClick
236                                 if (intStyMar->OnLeftDClick()==false)
237                                 {
238                                         i=size;
239                                 }
240                         }
241                         if (type==12)
242                         {  // OnRightDClick
243                                 if (intStyMar->OnRightDClick()==false)
244                                 {
245                                         i=size;
246                                 }
247                         }
248                         if (type==13)
249                         {  // OnMiddleDClick
250                                 if (intStyMar-> OnMiddleDClick()==false)
251                                 {
252                                         i=size;
253                                 }
254                         }
255                         // 14 ... old OnMouseWheelFordward
256                         if (type==15)
257                         {  // OnMouseWheelForward
258                                 if (intStyMar->OnMouseWheelForward()==false)
259                                 {
260                                         i=size;
261                                 }
262                         }
263                         if (type==16)
264                         {  // OnMouseWheelBackward
265                                 if (intStyMar->OnMouseWheelBackward()==false)
266                                 {
267                                         i=size;
268                                 }
269                         }
270                         
271                         
272                 } // if active
273         } // for
274
275         EvaluateToRefresh();
276 }
277 //---------------------------------------------------------------------------
278 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
279 {    
280 //      char a=GetInteractor()->GetKeyCode();
281         CallLstInteractorStyleMaracas(10);
282 }
283 //---------------------------------------------------------------------------
284 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
285 {
286         if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
287                 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
288
289                 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
290                 imageViewer->GetRenderer()->DisplayToWorld();
291                 double fP[4];
292                 imageViewer->GetRenderer()->GetWorldPoint( fP );
293
294                 if ( fP[3] ){
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         if  ( _blockRefresh==false )
369         {
370                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
371                 {
372                         _refresh_waiting                = false;
373                         this->_wxvtkbaseview->Refresh();
374                 }
375                 if (_parent_refresh_waiting==true)
376                 {
377                         _parent_refresh_waiting = false;
378                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
379 //CPR 13/01/2010
380                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
381                         int i;
382                         int size = _lstParentToReport.size();
383                         for(i = 0; i<size; i++)
384                         {       
385                                 _lstParentToReport[i]->ProcessEvent(newevent1);
386                         }//for
387                 }//if
388         }//if _blockRefresh
389 }
390 //---------------------------------------------------------------------------
391 void vtkInteractorStyleBaseView::BlockRefresh()
392 {
393         _blockRefresh=true;
394 }
395 //---------------------------------------------------------------------------
396 void vtkInteractorStyleBaseView::UnBlockRefresh()
397 {
398         _blockRefresh=false;
399 }
400
401 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
402 {
403         wxEvtHandler* parentToReport = NULL;
404         if(i>=0 && i<_lstParentToReport.size())
405         {       
406                 parentToReport = _lstParentToReport[i];
407         }
408         return parentToReport;
409
410 }
411
412 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
413 {
414         _lstParentToReport.push_back(parentToReport);
415 }