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