]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInteractorStyleBaseView.cxx
*** empty log 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 //---------------------------------------------------------------------------
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 printf("EED %p vtkInteractorStyleBaseView A i=%d size=%d sizeLst%d\n", this, i, size, _lstInteractorStyleMaracas.size() );
135                 if (i < _lstInteractorStyleMaracas.size() )
136                 {
137                         intStyMar = _lstInteractorStyleMaracas[i];
138                 } else {
139                         intStyMar=NULL;
140                 }
141 printf("EED %p vtkInteractorStyleBaseView B i=%d size=%d sizeLst%d\n", this, i, size, _lstInteractorStyleMaracas.size() );
142                 if (intStyMar!=NULL && intStyMar->GetActive()==true){
143 printf("EED %p vtkInteractorStyleBaseView C i=%d size=%d sizeLst%d\n", this, i, size, _lstInteractorStyleMaracas.size() );
144                         if (type ==1)
145                         {  // OnRightButtonDown
146                                 if (intStyMar->OnRightButtonDown()==false)
147                                 {
148                                         i=size;
149                                 }
150                         }
151                         if (type ==2)
152                         {  // OnRightButtonUp
153                                 if (intStyMar->OnRightButtonUp()==false)
154                                 {
155                                         i=size;
156                                 }
157                         }
158                         if (type==3)
159                         {  // OnMouseMouve
160                                 if (intStyMar->OnMouseMove()==false)
161                                 {
162                                         i=size;
163                                 }
164                         }
165                         if (type==4)
166                         {  // OnLeftButtonDown
167                                 if (intStyMar->OnLeftButtonDown()==false)
168                                 {
169                                         i=size;
170                                 }
171                         }
172                         if (type==5)
173                         {  // OnLeftButtonUp
174                                 if (intStyMar->OnLeftButtonUp()==false)
175                                 {
176                                         i=size;
177                                 }
178                         }
179                         if (type==6)
180                         {  // OnMiddleButtonDown
181                                 if (intStyMar->OnMiddleButtonDown()==false)
182                                 {
183                                         i=size;
184                                 }
185                         }
186                         if (type==7)
187                         {  // OnMiddleButtonUp
188                                 if (intStyMar->OnMiddleButtonUp()==false)
189                                 {
190                                         i=size;
191                                 }
192                         }
193                         if (type==10)
194                         {  // OnMiddleButtonUp
195                                 if (intStyMar->OnChar()==false)
196                                 {
197                                         i=size;
198                                 }
199                         }
200                         if (type==11)
201                         {  // OnLeftDClick
202                                 if (intStyMar->OnLeftDClick()==false)
203                                 {
204                                         i=size;
205                                 }
206                         }
207                         if (type==12)
208                         {  // OnRightDClick
209                                 if (intStyMar->OnRightDClick()==false)
210                                 {
211                                         i=size;
212                                 }
213                         }
214                         if (type==13)
215                         {  // OnMiddleDClick
216                                 if (intStyMar-> OnMiddleDClick()==false)
217                                 {
218                                         i=size;
219                                 }
220                         }
221                         if (type==14)
222                         {  // OnMouseWheel
223                                 if (intStyMar->OnMouseWheel()==false)
224                                 {
225                                         i=size;
226                                 }
227                         }
228                 } // if active
229         } // for
230
231         EvaluateToRefresh();
232 }
233 //---------------------------------------------------------------------------
234 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
235 {    
236 //      char a=GetInteractor()->GetKeyCode();
237         CallLstInteractorStyleMaracas(10);
238 }
239 //---------------------------------------------------------------------------
240 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
241 {
242     vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
243
244         imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
245         imageViewer->GetRenderer()->DisplayToWorld();
246         double fP[4];
247         imageViewer->GetRenderer()->GetWorldPoint( fP );
248
249         if ( fP[3] ){
250                 fP[0] /= fP[3];
251                 fP[1] /= fP[3];
252                 fP[2] /= fP[3];
253         }
254
255 // EEDx5
256         ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
257
258         X=fP[0];
259         Y=fP[1];
260         Z=fP[2];
261 }
262 //---------------------------------------------------------------------------
263 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
264 {
265         _wxvtkbaseview = wxvtkbaseview;
266 }
267 //---------------------------------------------------------------------------
268 /*JCP 13/05/2009
269 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
270 {
271         return (wxVtk2DBaseView*)_wxvtkbaseview;
272 }
273 //---------------------------------------------------------------------------
274 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
275 {
276         return (wxVtk3DBaseView*)_wxvtkbaseview;
277 }JCP 13/05/2009*/
278 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
279 {
280         return _wxvtkbaseview;
281 }
282 //---------------------------------------------------------------------------
283 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
284 {
285         return _wxvtkbaseview;
286 }
287 //---------------------------------------------------------------------------
288 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
289 {
290         InteractorStyleMaracas *intStyMar;
291         int i,size=_lstInteractorStyleMaracas.size();
292         for (i=0;i<size;i++)
293         {
294                 intStyMar = _lstInteractorStyleMaracas[i];
295                 intStyMar->SetActive(ok);
296         }
297
298 }
299 //---------------------------------------------------------------------------
300 void vtkInteractorStyleBaseView::SetRefresh_waiting()
301 {
302         _refresh_waiting=true;
303 }
304 //---------------------------------------------------------------------------
305 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
306 {
307         return _refresh_waiting;
308 }
309 //---------------------------------------------------------------------------
310 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
311 {
312         _parent_refresh_waiting=true;
313 }
314 //---------------------------------------------------------------------------
315 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
316 {
317         return _parent_refresh_waiting;
318 }
319 //---------------------------------------------------------------------------
320 void vtkInteractorStyleBaseView::EvaluateToRefresh()
321 {
322
323         if  ( _blockRefresh==false )
324         {
325                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
326                 {
327                         _refresh_waiting                = false;
328                         this->_wxvtkbaseview->Refresh();
329                 }
330                 if (_parent_refresh_waiting==true)
331                 {
332                         _parent_refresh_waiting = false;
333                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
334                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
335                 }
336         }
337 }
338 //---------------------------------------------------------------------------
339 void vtkInteractorStyleBaseView::BlockRefresh()
340 {
341         _blockRefresh=true;
342 }
343 //---------------------------------------------------------------------------
344 void vtkInteractorStyleBaseView::UnBlockRefresh()
345 {
346         _blockRefresh=false;
347 }
348