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