]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleBaseView.cxx
fd8fa4c6e79967859dadefe381e4b8cf39a52d50
[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 < _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     vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
240
241         imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
242         imageViewer->GetRenderer()->DisplayToWorld();
243         double fP[4];
244         imageViewer->GetRenderer()->GetWorldPoint( fP );
245
246         if ( fP[3] ){
247                 fP[0] /= fP[3];
248                 fP[1] /= fP[3];
249                 fP[2] /= fP[3];
250         }
251
252 // EEDx5
253         ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
254
255         X=fP[0];
256         Y=fP[1];
257         Z=fP[2];
258 }
259 //---------------------------------------------------------------------------
260 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
261 {
262         _wxvtkbaseview = wxvtkbaseview;
263 }
264 //---------------------------------------------------------------------------
265 /*JCP 13/05/2009
266 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
267 {
268         return (wxVtk2DBaseView*)_wxvtkbaseview;
269 }
270 //---------------------------------------------------------------------------
271 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
272 {
273         return (wxVtk3DBaseView*)_wxvtkbaseview;
274 }JCP 13/05/2009*/
275 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
276 {
277         return _wxvtkbaseview;
278 }
279 //---------------------------------------------------------------------------
280 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
281 {
282         return _wxvtkbaseview;
283 }
284 //---------------------------------------------------------------------------
285 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
286 {
287         InteractorStyleMaracas *intStyMar;
288         int i,size=_lstInteractorStyleMaracas.size();
289         for (i=0;i<size;i++)
290         {
291                 intStyMar = _lstInteractorStyleMaracas[i];
292                 intStyMar->SetActive(ok);
293         }
294
295 }
296 //---------------------------------------------------------------------------
297 void vtkInteractorStyleBaseView::SetRefresh_waiting()
298 {
299         _refresh_waiting=true;
300 }
301 //---------------------------------------------------------------------------
302 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
303 {
304         return _refresh_waiting;
305 }
306 //---------------------------------------------------------------------------
307 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
308 {
309         _parent_refresh_waiting=true;
310 }
311 //---------------------------------------------------------------------------
312 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
313 {
314         return _parent_refresh_waiting;
315 }
316 //---------------------------------------------------------------------------
317 void vtkInteractorStyleBaseView::EvaluateToRefresh()
318 {
319
320         if  ( _blockRefresh==false )
321         {
322                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
323                 {
324                         _refresh_waiting                = false;
325                         this->_wxvtkbaseview->Refresh();
326                 }
327                 if (_parent_refresh_waiting==true)
328                 {
329                         _parent_refresh_waiting = false;
330                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
331                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
332                 }
333         }
334 }
335 //---------------------------------------------------------------------------
336 void vtkInteractorStyleBaseView::BlockRefresh()
337 {
338         _blockRefresh=true;
339 }
340 //---------------------------------------------------------------------------
341 void vtkInteractorStyleBaseView::UnBlockRefresh()
342 {
343         _blockRefresh=false;
344 }
345