vtkInteractorStyleBaseView.cxx
Go to the documentation of this file.00001 #include "vtkInteractorStyleBaseView.h"
00002
00003 #include "wxVtk3DBaseView.h"
00004 #include "wxVtk2DBaseView.h"
00005
00006 #include "vtkObjectFactory.h"
00007
00008 #include "InteractorStyleMaracas.h"
00009
00010 vtkStandardNewMacro(vtkInteractorStyleBaseView);
00011
00012
00013
00014
00015 vtkInteractorStyleBaseView::vtkInteractorStyleBaseView()
00016 {
00017 _refresh_waiting = false;
00018 _parent_refresh_waiting = false;
00019 _blockRefresh = false;
00020 }
00021
00022 vtkInteractorStyleBaseView::~vtkInteractorStyleBaseView()
00023 {
00024 }
00025
00026 void vtkInteractorStyleBaseView::OnMouseMove()
00027 {
00028 CallLstInteractorStyleMaracas(3);
00029 }
00030
00031 void vtkInteractorStyleBaseView::OnLeftButtonDown()
00032 {
00033 CallLstInteractorStyleMaracas(4);
00034 }
00035
00036 void vtkInteractorStyleBaseView::OnLeftButtonUp()
00037 {
00038 CallLstInteractorStyleMaracas(5);
00039 }
00040
00041
00042 void vtkInteractorStyleBaseView::OnLeftDClick()
00043 {
00044 CallLstInteractorStyleMaracas( 11 );
00045 }
00046
00047
00048 void vtkInteractorStyleBaseView::OnMiddleButtonDown()
00049 {
00050 CallLstInteractorStyleMaracas(6);
00051 }
00052
00053 void vtkInteractorStyleBaseView::OnMiddleButtonUp()
00054 {
00055 CallLstInteractorStyleMaracas(7);
00056 }
00057
00058 void vtkInteractorStyleBaseView::OnMiddleDClick()
00059 {
00060 CallLstInteractorStyleMaracas( 13 );
00061 }
00062
00063
00064 void vtkInteractorStyleBaseView::OnRightButtonDown()
00065 {
00066 CallLstInteractorStyleMaracas(1);
00067 }
00068
00069 void vtkInteractorStyleBaseView::OnRightButtonUp()
00070 {
00071 CallLstInteractorStyleMaracas(2);
00072 }
00073
00074 void vtkInteractorStyleBaseView::OnRightDClick()
00075 {
00076 CallLstInteractorStyleMaracas( 12 );
00077 }
00078
00079 void vtkInteractorStyleBaseView::OnMouseWheel()
00080 {
00081 CallLstInteractorStyleMaracas( 14 );
00082 }
00083
00084 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
00085 {
00086 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
00087 _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
00088 }
00089
00090 void vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
00091 {
00092 interactorStyleMaracas->RemoveVtkInteractorStyleBaseView();
00093 int i, size = _lstInteractorStyleMaracas.size();
00094 std::vector< InteractorStyleMaracas* >::iterator iter = _lstInteractorStyleMaracas.begin();
00095 bool removed = false;
00096 for (i=0; !removed && i<size; i++)
00097 {
00098 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
00099 {
00100 _lstInteractorStyleMaracas.erase(iter);
00101 removed = true;
00102 } else {
00103 iter++;
00104 }
00105 }
00106 }
00107
00108 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
00109 {
00110 interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
00111 _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
00112 }
00113
00114 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
00115 {
00116
00117 InteractorStyleMaracas *intStyMar;
00118
00119 int i,size=_lstInteractorStyleMaracas.size();
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 for (i=0;i<size;i++)
00133 {
00134 if (i < _lstInteractorStyleMaracas.size() )
00135 {
00136 intStyMar = _lstInteractorStyleMaracas[i];
00137 } else {
00138 intStyMar=NULL;
00139 }
00140 if (intStyMar!=NULL && intStyMar->GetActive()==true){
00141 if (type ==1)
00142 {
00143 if (intStyMar->OnRightButtonDown()==false)
00144 {
00145 i=size;
00146 }
00147 }
00148 if (type ==2)
00149 {
00150 if (intStyMar->OnRightButtonUp()==false)
00151 {
00152 i=size;
00153 }
00154 }
00155 if (type==3)
00156 {
00157 if (intStyMar->OnMouseMove()==false)
00158 {
00159 i=size;
00160 }
00161 }
00162 if (type==4)
00163 {
00164 if (intStyMar->OnLeftButtonDown()==false)
00165 {
00166 i=size;
00167 }
00168 }
00169 if (type==5)
00170 {
00171 if (intStyMar->OnLeftButtonUp()==false)
00172 {
00173 i=size;
00174 }
00175 }
00176 if (type==6)
00177 {
00178 if (intStyMar->OnMiddleButtonDown()==false)
00179 {
00180 i=size;
00181 }
00182 }
00183 if (type==7)
00184 {
00185 if (intStyMar->OnMiddleButtonUp()==false)
00186 {
00187 i=size;
00188 }
00189 }
00190 if (type==10)
00191 {
00192 if (intStyMar->OnChar()==false)
00193 {
00194 i=size;
00195 }
00196 }
00197 if (type==11)
00198 {
00199 if (intStyMar->OnLeftDClick()==false)
00200 {
00201 i=size;
00202 }
00203 }
00204 if (type==12)
00205 {
00206 if (intStyMar->OnRightDClick()==false)
00207 {
00208 i=size;
00209 }
00210 }
00211 if (type==13)
00212 {
00213 if (intStyMar-> OnMiddleDClick()==false)
00214 {
00215 i=size;
00216 }
00217 }
00218 if (type==14)
00219 {
00220 if (intStyMar->OnMouseWheel()==false)
00221 {
00222 i=size;
00223 }
00224 }
00225 }
00226 }
00227
00228 EvaluateToRefresh();
00229 }
00230
00231 void vtkInteractorStyleBaseView::OnChar()
00232 {
00233
00234 CallLstInteractorStyleMaracas(10);
00235 }
00236
00237 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
00238 {
00239 vtkImageViewer2 *imageViewer = ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
00240
00241 imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
00242 imageViewer->GetRenderer()->DisplayToWorld();
00243 double fP[4];
00244 imageViewer->GetRenderer()->GetWorldPoint( fP );
00245
00246 if ( fP[3] ){
00247 fP[0] /= fP[3];
00248 fP[1] /= fP[3];
00249 fP[2] /= fP[3];
00250 }
00251
00252
00253 ((wxVtk2DBaseView*)GetWxVtk2DBaseView())->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
00254
00255 X=fP[0];
00256 Y=fP[1];
00257 Z=fP[2];
00258 }
00259
00260 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
00261 {
00262 _wxvtkbaseview = wxvtkbaseview;
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
00276 {
00277 return _wxvtkbaseview;
00278 }
00279
00280 wxVtkBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
00281 {
00282 return _wxvtkbaseview;
00283 }
00284
00285 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
00286 {
00287 InteractorStyleMaracas *intStyMar;
00288 int i,size=_lstInteractorStyleMaracas.size();
00289 for (i=0;i<size;i++)
00290 {
00291 intStyMar = _lstInteractorStyleMaracas[i];
00292 intStyMar->SetActive(ok);
00293 }
00294
00295 }
00296
00297 void vtkInteractorStyleBaseView::SetRefresh_waiting()
00298 {
00299 _refresh_waiting=true;
00300 }
00301
00302 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
00303 {
00304 return _refresh_waiting;
00305 }
00306
00307 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
00308 {
00309 _parent_refresh_waiting=true;
00310 }
00311
00312 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
00313 {
00314 return _parent_refresh_waiting;
00315 }
00316
00317 void vtkInteractorStyleBaseView::EvaluateToRefresh()
00318 {
00319
00320 if ( _blockRefresh==false )
00321 {
00322 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
00323 {
00324 _refresh_waiting = false;
00325 this->_wxvtkbaseview->Refresh();
00326 }
00327 if (_parent_refresh_waiting==true)
00328 {
00329 _parent_refresh_waiting = false;
00330 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);
00331
00332 this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
00333 int i;
00334 int size = _lstParentToReport.size();
00335 for(i = 0; i<size; i++)
00336 {
00337 _lstParentToReport[i]->ProcessEvent(newevent1);
00338 }
00339 }
00340 }
00341 }
00342
00343 void vtkInteractorStyleBaseView::BlockRefresh()
00344 {
00345 _blockRefresh=true;
00346 }
00347
00348 void vtkInteractorStyleBaseView::UnBlockRefresh()
00349 {
00350 _blockRefresh=false;
00351 }
00352
00353 wxEvtHandler* vtkInteractorStyleBaseView::GetParentToReport(int i)
00354 {
00355 wxEvtHandler* parentToReport = NULL;
00356 if(i>=0 && i<_lstParentToReport.size())
00357 {
00358 parentToReport = _lstParentToReport[i];
00359 }
00360 return parentToReport;
00361
00362 }
00363
00364 void vtkInteractorStyleBaseView::AddParentToReport(wxEvtHandler* parentToReport)
00365 {
00366 _lstParentToReport.push_back(parentToReport);
00367 }