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