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