]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleBaseView.cxx
89aee7044a585291e338a9306db000adccbc0f12
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkInteractorStyleBaseView.cxx
1 #include "vtkInteractorStyleBaseView.h"
2
3 #include "wxVtk3DBaseView.h"
4 #include "wxVtk2DBaseView.h"
5
6 #include "vtkObjectFactory.h"
7
8 #include "InteractorStyleMaracas.h"
9
10 vtkStandardNewMacro(vtkInteractorStyleBaseView);
11 //---------------------------------------------------------------------------
12 //---------------------------------------------------------------------------
13 //---------------------------------------------------------------------------
14
15 vtkInteractorStyleBaseView::vtkInteractorStyleBaseView()
16 {
17         _refresh_waiting                = false;
18         _parent_refresh_waiting = false;
19         _blockRefresh                   = false;
20         
21         //EED27Juillet2011
22         SetMouseWheelMotionFactor(0.5);
23 }
24 //---------------------------------------------------------------------------
25 vtkInteractorStyleBaseView::~vtkInteractorStyleBaseView()
26 {
27 }
28 //---------------------------------------------------------------------------
29 void vtkInteractorStyleBaseView::OnMouseMove() // virtual 
30 {
31         CallLstInteractorStyleMaracas(3);
32 }
33 //---------------------------------------------------------------------------
34 void vtkInteractorStyleBaseView::OnLeftButtonDown()  // virtual 
35 {
36         CallLstInteractorStyleMaracas(4);
37 }
38 //---------------------------------------------------------------------------
39 void vtkInteractorStyleBaseView::OnLeftButtonUp() // virtual 
40 {
41         CallLstInteractorStyleMaracas(5);
42 }
43
44 //---------------------------------------------------------------------------
45 void vtkInteractorStyleBaseView::OnLeftDClick()  // virtual
46 {
47         CallLstInteractorStyleMaracas( 11 );
48 }
49
50 //---------------------------------------------------------------------------
51 void vtkInteractorStyleBaseView::OnMiddleButtonDown()  // virtual 
52 {
53         CallLstInteractorStyleMaracas(6);
54 }
55 //---------------------------------------------------------------------------
56 void vtkInteractorStyleBaseView::OnMiddleButtonUp() // virtual 
57 {
58         CallLstInteractorStyleMaracas(7);
59 }
60 //---------------------------------------------------------------------------
61 void vtkInteractorStyleBaseView::OnMiddleDClick()  // virtual
62 {
63         CallLstInteractorStyleMaracas( 13 );
64 }
65
66 //---------------------------------------------------------------------------
67 void vtkInteractorStyleBaseView::OnRightButtonDown() // virtual 
68 {
69         CallLstInteractorStyleMaracas(1);
70 }
71 //---------------------------------------------------------------------------
72 void vtkInteractorStyleBaseView::OnRightButtonUp() // virtual 
73 {
74         CallLstInteractorStyleMaracas(2);
75 }
76 //---------------------------------------------------------------------------
77 void vtkInteractorStyleBaseView::OnRightDClick()  // virtual
78 {
79         CallLstInteractorStyleMaracas( 12 );
80 }
81 //---------------------------------------------------------------------------
82 //EED27Juillet2011
83 void vtkInteractorStyleBaseView::OnMouseWheel()  // virtual
84 {
85         printf("EED vtkInteractorStyleBaseView::OnMouseWheel\n");
86         CallLstInteractorStyleMaracas( 14 );
87 }
88
89 void  vtkInteractorStyleBaseView::OnMouseWheelForward()  // virtual
90 {
91         printf("EED.. vtkInteractorStyleBaseView::OnMouseWheelForward\n");
92         CallLstInteractorStyleMaracas( 15 );
93 }
94
95 void vtkInteractorStyleBaseView::OnMouseWheelBackward() // virtual
96 {
97         printf("EED.. vtkInteractorStyleBaseView::OnMouseWheelBackward\n");
98         CallLstInteractorStyleMaracas( 16 );
99 }
100
101
102
103
104 //---------------------------------------------------------------------------
105 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
106 {
107         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
108         _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
109 }
110 //---------------------------------------------------------------------------
111 void  vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
112 {
113         interactorStyleMaracas->RemoveVtkInteractorStyleBaseView();
114         int i, size = _lstInteractorStyleMaracas.size();
115         std::vector< InteractorStyleMaracas* >::iterator iter = _lstInteractorStyleMaracas.begin();
116         bool removed = false;
117         for (i=0; !removed && i<size; i++)
118         {
119                 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
120                 {
121                         _lstInteractorStyleMaracas.erase(iter);
122                         removed = true;
123                 } else {
124                   iter++;
125                 }
126         }               
127 }
128 //---------------------------------------------------------------------------
129 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
130 {
131         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
132         _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
133 }
134 //---------------------------------------------------------------------------
135 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
136 {
137
138         InteractorStyleMaracas *intStyMar;
139
140         int i,size=_lstInteractorStyleMaracas.size();
141
142 //EED Borrame
143 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
144 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
145 //for (i=0;i<size;i++)
146 //{
147 //fprintf(ff,"    %p\n" , _lstInteractorStyleMaracas[i] );
148 //}
149 //fclose(ff);
150
151
152
153         for (i=0;i<size;i++)
154         {
155                 if (i < (int)_lstInteractorStyleMaracas.size() )
156                 {
157                         intStyMar = _lstInteractorStyleMaracas[i];
158                 } else {
159                         intStyMar=NULL;
160                 }
161                 if (intStyMar!=NULL && intStyMar->GetActive()==true){
162                         if (type ==1)
163                         {  // OnRightButtonDown
164                                 if (intStyMar->OnRightButtonDown()==false)
165                                 {
166                                         i=size;
167                                 }
168                         }
169                         if (type ==2)
170                         {  // OnRightButtonUp
171                                 if (intStyMar->OnRightButtonUp()==false)
172                                 {
173                                         i=size;
174                                 }
175                         }
176                         if (type==3)
177                         {  // OnMouseMouve
178                                 if (intStyMar->OnMouseMove()==false)
179                                 {
180                                         i=size;
181                                 }
182                         }
183                         if (type==4)
184                         {  // OnLeftButtonDown
185                                 if (intStyMar->OnLeftButtonDown()==false)
186                                 {
187                                         i=size;
188                                 }
189                         }
190                         if (type==5)
191                         {  // OnLeftButtonUp
192                                 if (intStyMar->OnLeftButtonUp()==false)
193                                 {
194                                         i=size;
195                                 }
196                         }
197                         if (type==6)
198                         {  // OnMiddleButtonDown
199                                 if (intStyMar->OnMiddleButtonDown()==false)
200                                 {
201                                         i=size;
202                                 }
203                         }
204                         if (type==7)
205                         {  // OnMiddleButtonUp
206                                 if (intStyMar->OnMiddleButtonUp()==false)
207                                 {
208                                         i=size;
209                                 }
210                         }
211                         if (type==10)
212                         {  // OnMiddleButtonUp
213                                 if (intStyMar->OnChar()==false)
214                                 {
215                                         i=size;
216                                 }
217                         }
218                         if (type==11)
219                         {  // OnLeftDClick
220                                 if (intStyMar->OnLeftDClick()==false)
221                                 {
222                                         i=size;
223                                 }
224                         }
225                         if (type==12)
226                         {  // OnRightDClick
227                                 if (intStyMar->OnRightDClick()==false)
228                                 {
229                                         i=size;
230                                 }
231                         }
232                         if (type==13)
233                         {  // OnMiddleDClick
234                                 if (intStyMar-> OnMiddleDClick()==false)
235                                 {
236                                         i=size;
237                                 }
238                         }
239                         
240                         //EED ?????  27Juillet2011      
241                         if (type==14)
242                         {  // OnMouseWheel
243                                 if (intStyMar->OnMouseWheel()==false)
244                                 {
245                                         i=size;
246                                 }
247                         }
248                         if (type==15)
249                         {  // OnMouseWheelForward
250                                 if (intStyMar->OnMouseWheelForward()==false)
251                                 {
252                                         i=size;
253                                 }
254                         }
255                         if (type==16)
256                         {  // OnMouseWheelBackward
257                                 if (intStyMar->OnMouseWheelBackward()==false)
258                                 {
259                                         i=size;
260                                 }
261                         }
262                         
263                         
264                 } // if active
265         } // for
266
267         EvaluateToRefresh();
268 }
269 //---------------------------------------------------------------------------
270 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
271 {    
272 //      char a=GetInteractor()->GetKeyCode();
273         CallLstInteractorStyleMaracas(10);
274 }
275 //---------------------------------------------------------------------------
276 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
277 {
278         if(((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ){
279                 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
280
281                 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
282                 imageViewer->GetRenderer()->DisplayToWorld();
283                 double fP[4];
284                 imageViewer->GetRenderer()->GetWorldPoint( fP );
285
286                 if ( fP[3] ){
287                         fP[0] /= fP[3];
288                         fP[1] /= fP[3];
289                         fP[2] /= fP[3];
290                 }
291
292         // EEDx5
293                 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
294
295                 X=fP[0];
296                 Y=fP[1];
297                 Z=fP[2];
298         }
299 }
300 //---------------------------------------------------------------------------
301 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
302 {
303         _wxvtkbaseview = wxvtkbaseview;
304 }
305 //---------------------------------------------------------------------------
306 /*JCP 13/05/2009
307 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
308 {
309         return (wxVtk2DBaseView*)_wxvtkbaseview;
310 }
311 //---------------------------------------------------------------------------
312 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
313 {
314         return (wxVtk3DBaseView*)_wxvtkbaseview;
315 }JCP 13/05/2009*/
316 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
317 {
318         return _wxvtkbaseview;
319 }
320 //---------------------------------------------------------------------------
321 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
322 {
323         return _wxvtkbaseview;
324 }
325 //---------------------------------------------------------------------------
326 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
327 {
328         InteractorStyleMaracas *intStyMar;
329         int i,size=_lstInteractorStyleMaracas.size();
330         for (i=0;i<size;i++)
331         {
332                 intStyMar = _lstInteractorStyleMaracas[i];
333                 intStyMar->SetActive(ok);
334         }
335
336 }
337 //---------------------------------------------------------------------------
338 void vtkInteractorStyleBaseView::SetRefresh_waiting()
339 {
340         _refresh_waiting=true;
341 }
342 //---------------------------------------------------------------------------
343 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
344 {
345         return _refresh_waiting;
346 }
347 //---------------------------------------------------------------------------
348 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
349 {
350         _parent_refresh_waiting=true;
351 }
352 //---------------------------------------------------------------------------
353 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
354 {
355         return _parent_refresh_waiting;
356 }
357 //---------------------------------------------------------------------------
358 void vtkInteractorStyleBaseView::EvaluateToRefresh()
359 {
360
361         if  ( _blockRefresh==false )
362         {
363                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
364                 {
365                         _refresh_waiting                = false;
366                         this->_wxvtkbaseview->Refresh();
367                 }
368                 if (_parent_refresh_waiting==true)
369                 {
370                         _parent_refresh_waiting = false;
371                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
372 //CPR 13/01/2010
373                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
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 }