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