manualContourBaseControler.cpp

Go to the documentation of this file.
00001 #include "manualContourBaseControler.h"
00002 
00003 
00004 // ----------------------------------------------------------------------------
00005 // ----------------------------------------------------------------------------
00006 // ----------------------------------------------------------------------------
00007 
00008 manualContourBaseControler::manualContourBaseControler()
00009 {
00010         _manViewBaseCont        = NULL;
00011         _manContModel           = NULL;
00012         _state                          = 0;
00013         _z                                      = 900;
00014         _editable                       = true;
00015         _posibleToMove          = true;
00016         _moving                         = false;
00017         _created                        = false;
00018         _keyBoardMoving         = false;
00019 }
00020 // ----------------------------------------------------------------------------
00021 manualContourBaseControler::~manualContourBaseControler()
00022 {
00023 }
00024 
00025 // ----------------------------------------------------------------------------
00026 manualContourBaseControler * manualContourBaseControler :: Clone()  // virtual
00027 {
00028         manualContourBaseControler * clone = new manualContourBaseControler();
00029         CopyAttributesTo(clone);
00030         return clone;
00031 }
00032 
00033 // ---------------------------------------------------------------------------
00034 
00035 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
00036 {
00037         // Fathers object
00038         InteractorStyleMaracas::CopyAttributesTo(cloneObject);
00039         cloneObject->SetZ( this->GetZ() );
00040         cloneObject->SetState( this->GetState() );
00041         cloneObject->SetEditable( this->IsEditable() );
00042         cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
00043         cloneObject->SetMoving( this->IsMoving() );
00044         cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
00045         cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
00046 }
00047 
00048 // ----------------------------------------------------------------------------
00049 void manualContourBaseControler::Configure() //virtual
00050 {
00051 }
00052 
00053 // ----------------------------------------------------------------------------
00054 bool manualContourBaseControler::OnChar()
00055 {
00056         if ( _vtkInteractorStyleBaseView!=NULL )
00057         {
00058                 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
00059 
00060                 int X,Y;
00061                 wxVTKRenderWindowInteractor *_wxVTKiren;
00062                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00063                 _wxVTKiren->GetEventPosition(X, Y);
00064                 //int Z = GetZ(); // JPRx
00065                 // Delete Point
00066                 if ((keyCode==8) || (keyCode==127))
00067                 {
00068 
00069                         if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
00070                         {
00071                                 DeleteActualMousePoint(X,Y);
00072                         }
00073                         GetManualViewBaseContour()->Refresh();
00074                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
00075                 }
00076                 else
00077                 {
00078                         // Magnet
00079                         if (keyCode==32)
00080                         {
00081                                 Magnet(X,Y);
00082                                 GetManualViewBaseContour()->Refresh();
00083                                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
00084                         }
00085                         else if( !IsEditable() )
00086                         {
00087                                 if ( keyCode == 'L' )
00088                                 {
00089                                         GetManualViewBaseContour()->MoveContour( -1, 0 );
00090                                         SetKeyBoardMoving( true );
00091                                 }
00092                                 else if ( keyCode == 'R' )
00093                                 {
00094                                         GetManualViewBaseContour()->MoveContour( 1, 0 );
00095                                         SetKeyBoardMoving( true );
00096                                 }
00097                                 else if ( keyCode == 'U' )
00098                                 {
00099                                         GetManualViewBaseContour()->MoveContour( 0, -1 );
00100                                         SetKeyBoardMoving( true );
00101                                 }
00102                                 else if ( keyCode == 'D' )
00103                                 {
00104                                         GetManualViewBaseContour()->MoveContour( 0, 1 );
00105                                         SetKeyBoardMoving( true );
00106                                 }
00107                                 else if ( keyCode == 'W' )//Diagonal left down
00108                                 {
00109                                         GetManualViewBaseContour()->MoveContour( -1, 1 );
00110                                         SetKeyBoardMoving( true );
00111                                 }
00112                                 else if ( keyCode == 'Q' )//Diagonal left up
00113                                 {
00114                                         GetManualViewBaseContour()->MoveContour( -1, -1 );
00115                                         SetKeyBoardMoving( true );
00116                                 }
00117                                 else if( keyCode == 'P' )//Diagonal right up
00118                                 {
00119                                         GetManualViewBaseContour()->MoveContour( 1, -1 );
00120                                         SetKeyBoardMoving( true );
00121                                 }
00122                                 else if( keyCode == 'M' )//Diagonal right down
00123                                 {
00124                                         GetManualViewBaseContour()->MoveContour( 1, 1 );
00125                                         SetKeyBoardMoving( true );
00126                                 }
00127                                 if( GetKeyBoardMoving() )
00128                                 {
00129                                         GetManualViewBaseContour()->Refresh();
00130                                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
00131                                 }
00132                         }
00133                 }
00134         }
00135         return true;
00136 }
00137 // ----------------------------------------------------------------------------
00138 bool manualContourBaseControler::OnMouseMove()
00139 {
00140         
00141         if ( _vtkInteractorStyleBaseView!=NULL)
00142         {
00143                 int X,Y;
00144                 wxVTKRenderWindowInteractor *_wxVTKiren;
00145                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00146                 _wxVTKiren->GetEventPosition( X , Y );
00147 
00148 
00149                 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
00150                         (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
00151                         MouseMove(X,Y);
00152                 }
00153         }
00154         return true;
00155 }
00156 // ----------------------------------------------------------------------------
00157 bool manualContourBaseControler::OnLeftButtonDown()
00158 {
00159         SetKeyBoardMoving( false );
00160         if ( _vtkInteractorStyleBaseView!=NULL )
00161         {
00162                 int X,Y;
00163                 wxVTKRenderWindowInteractor *wxVTKiren;
00164                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00165                 wxVTKiren->GetEventPosition(X,Y);
00166 
00167                 MouseClickLeft(X,Y);
00168         }
00169         return true;
00170 }
00171 // ----------------------------------------------------------------------------
00172 bool manualContourBaseControler::OnLeftButtonUp()
00173 {
00174         if ( _vtkInteractorStyleBaseView!=NULL )
00175         {
00176                 int X,Y;
00177                 wxVTKRenderWindowInteractor *wxVTKiren;
00178                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00179                 wxVTKiren->GetEventPosition(X,Y);
00180                 MouseReleaseLeft(X,Y);
00181         }
00182         return true;
00183 }
00184 // ----------------------------------------------------------------------------
00185 bool manualContourBaseControler::OnLeftDClick()
00186 {
00187         if ( _vtkInteractorStyleBaseView!=NULL )
00188         {
00189                 int X,Y;
00190                 wxVTKRenderWindowInteractor *wxVTKiren;
00191                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00192                 wxVTKiren->GetEventPosition(X,Y);
00193 
00194                 this->MouseDLeft(X,Y);
00195         }
00196         return true;
00197 }
00198 // ----------------------------------------------------------------------------
00199 bool manualContourBaseControler::OnMiddleButtonDown()
00200 {
00201 //      SetKeyBoardMoving( false );
00202         if ( _vtkInteractorStyleBaseView!=NULL )
00203         {
00204                 int X,Y;
00205                 wxVTKRenderWindowInteractor *wxVTKiren;
00206                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00207                 wxVTKiren->GetEventPosition(X,Y);
00208                 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
00209         }
00210         return true;
00211 }
00212 // ----------------------------------------------------------------------------
00213 bool manualContourBaseControler::OnMiddleButtonUp()
00214 {
00215         return true;
00216 }
00217 // ----------------------------------------------------------------------------
00218 bool manualContourBaseControler::OnRightButtonDown()
00219 {
00220         if( _vtkInteractorStyleBaseView!= NULL )
00221         {
00222                 int X,Y;
00223                 wxVTKRenderWindowInteractor *wxVTKiren;
00224                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
00225                 wxVTKiren->GetEventPosition(X, Y);
00226 
00227                 SetCompleteCreation( true );
00228                 SetKeyBoardMoving( false );
00229                 this->GetManualContourModel()->SetCloseContour(true);
00230                 MouseClickRight(X,Y);
00231         }
00232         return true;
00233 }
00234 // ----------------------------------------------------------------------------
00235 bool manualContourBaseControler::OnRightButtonUp()
00236 {
00237         return true;
00238 }
00239 // ----------------------------------------------------------------------------
00240 void manualContourBaseControler::SetModelView(manualContourModel *manContModel, manualViewBaseContour *manViewBaseCont){
00241         _manContModel           =       manContModel;
00242         _manViewBaseCont        =       manViewBaseCont;
00243         _manViewBaseCont->SetEditable( &_editable );
00244 }
00245 // ----------------------------------------------------------------------------
00246 manualContourModel* manualContourBaseControler::GetManualContourModel()
00247 {
00248         return _manContModel;
00249 }
00250 // ----------------------------------------------------------------------------
00251 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
00252 {
00253         return _manViewBaseCont;
00254 }
00255 // ----------------------------------------------------------------------------
00256 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
00257 {
00258 
00259 }
00260 // ----------------------------------------------------------------------------
00261 void manualContourBaseControler::MouseClickRight(int x, int y)
00262 {
00263 //      if (_state==1)
00264 //      {
00265 //              _state=0;
00266 //      }
00267         SetEditable( false );
00268         SetPosibleToMove( false );
00269         _state = 0;
00270 
00271 //EED 24Avril2009       _state=7;
00272 }
00273 // ----------------------------------------------------------------------------
00274 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
00275 {
00276         if (_state==5){ _state = 0; }
00277         if (_state==6){ _state = 0; }
00278         if (_state==7){ _state = 0; }
00279         SetMoving( false );
00280         GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
00281         if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1)  )
00282         {
00283                 SetEditable( false );
00284                 SetPosibleToMove( false );
00285         }
00286 }
00287 // ----------------------------------------------------------------------------
00288 void manualContourBaseControler::MouseDLeft(int x, int y )
00289 {
00290         if (_state==0)
00291         {
00292                 int z=GetZ();
00293                 GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
00294                 GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
00295                 if ( GetManualViewBaseContour()->GetPosibleSelected() )
00296                 {
00297                         _editable = true;
00298                 }
00299         }
00300 }
00301 // ----------------------------------------------------------------------------
00302 void manualContourBaseControler::MouseMove(int x, int y) // virtual
00303 {
00304 }
00305 // ----------------------------------------------------------------------------
00306 void manualContourBaseControler::SetState(int state)
00307 {
00308         _state=state;
00309 }
00310 // ----------------------------------------------------------------------------
00311 int manualContourBaseControler::GetState()
00312 {
00313         return _state;
00314 }
00315 // ----------------------------------------------------------------------------
00316 bool manualContourBaseControler::IsEditable( )
00317 {
00318         return _editable;
00319 }
00320 // ----------------------------------------------------------------------------
00321 void manualContourBaseControler::SetEditable(  bool condition  )
00322 {
00323         if (GetManualViewBaseContour()!=NULL) {
00324                 if( !condition )
00325                 {
00326                         GetManualViewBaseContour()->RemoveControlPoints();
00327                 }
00328                 GetManualViewBaseContour()->SetSelected( condition );
00329         }
00330         _editable = condition;
00331 }
00332 
00333 // ----------------------------------------------------------------------------
00334 bool manualContourBaseControler::GetPosibleToMove()
00335 {
00336         return _posibleToMove;
00337 }
00338 // ----------------------------------------------------------------------------
00339 void manualContourBaseControler::SetPosibleToMove( bool condition )
00340 {
00341         _posibleToMove = condition;
00342 }
00343 // ----------------------------------------------------------------------------
00344 bool manualContourBaseControler::IsMoving()
00345 {
00346         return _moving;
00347 }
00348 // ----------------------------------------------------------------------------
00349 void manualContourBaseControler::SetMoving( bool condition )
00350 {
00351         _moving = condition;
00352 }
00353 // ----------------------------------------------------------------------------
00354 void manualContourBaseControler::SetCompleteCreation( bool condition )
00355 {
00356         _created = condition;
00357 }
00358 // ----------------------------------------------------------------------------
00359 bool manualContourBaseControler::GetIfCompleteCreation ( )
00360 {
00361         return _created;
00362 }
00363 // ----------------------------------------------------------------------------
00364 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
00365 {
00366         _keyBoardMoving = condition;
00367 }
00368 // ----------------------------------------------------------------------------
00369 bool manualContourBaseControler::GetKeyBoardMoving(  )
00370 {
00371         return _keyBoardMoving;
00372 }
00373 // ----------------------------------------------------------------------------
00374 void manualContourBaseControler::CreateNewManualContour(){
00375         _manViewBaseCont->CreateNewContour();
00376 }
00377 // ----------------------------------------------------------------------------
00378 int     manualContourBaseControler::GetNumberOfPointsManualContour(){
00379         return _manViewBaseCont->GetNumberOfPoints();
00380 }
00381 // ----------------------------------------------------------------------------
00382 
00383 //JSTG - 25-02-08 -------------------------------------------------------------
00384 int     manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
00385         //return _manViewBaseCont->GetNumberOfPointsSpline();
00386         return _manContModel->GetNumberOfPointsSpline();
00387 }
00388 // ----------------------------------------------------------------------------
00389 
00390 double* manualContourBaseControler::GetVectorPointsXManualContour(){
00391         return _manViewBaseCont->GetVectorPointsXManualContour();
00392 }
00393 // ----------------------------------------------------------------------------
00394 double* manualContourBaseControler::GetVectorPointsYManualContour(){
00395         return _manViewBaseCont->GetVectorPointsYManualContour();
00396 }
00397 // ----------------------------------------------------------------------------
00398 void manualContourBaseControler::DeleteContour(){
00399         _manViewBaseCont->DeleteContour();
00400         _manContModel->DeleteAllPoints();
00401 }
00402 // ----------------------------------------------------------------------------
00403 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
00404 {
00405         if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
00406         {
00407                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
00408                 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
00409                         _manContModel->DeletePoint(id);
00410                         _manViewBaseCont->DeletePoint(id);
00411                 }
00412         }
00413         _state = 0;
00414 }
00415 
00416 // ----------------------------------------------------------------------------
00417 void manualContourBaseControler::Magnet(int x, int y)
00418 {
00419         if( IsEditable())
00420         {
00421                 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
00422                 if (GetManualContourModel()!=NULL){
00423                         double  xx      = x;
00424                         double  yy      = y;
00425                         double  zz      = GetZ();
00426                         GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00427                         int                     id      = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
00428                         if (id!=-1)
00429                         {
00430                                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
00431                                 mp->SetPoint(xx,yy,zz);
00432                         }
00433         //              GetManualViewBaseContour()->UpdateViewPoint(id);
00434                 }
00435                 _state = 0;
00436         }
00437 }
00438 
00439 // ----------------------------------------------------------------------------
00440 void manualContourBaseControler::SetZ(int z)
00441 {
00442         _z=z;
00443 }
00444 // ----------------------------------------------------------------------------
00445 int manualContourBaseControler::GetZ()
00446 {
00447         return _z;
00448 }
00449 // ----------------------------------------------------------------------------
00450 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
00451 {
00452         if (GetManualContourModel()!=NULL){
00453                 double  xx      = x;
00454                 double  yy      = y;
00455                 double  zz      = z;
00456                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00457                 /*int   id              =*/  GetManualContourModel()->AddPoint(xx,yy,zz);  // JPRx
00458                 GetManualViewBaseContour()->AddPoint();
00459 //              GetManualViewBaseContour()->UpdateViewPoint(id);
00460         }
00461 }
00462 // ----------------------------------------------------------------------------
00463 void manualContourBaseControler::InsertPoint(int x,int y,int z)  // virtual
00464 {
00465 //EEDzz
00466         int id=-1;
00467         if (GetManualContourModel()!=NULL){
00468                 double                          xx              = x;
00469                 double                          yy              = y;
00470                 double                          zz              = z;
00471                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00472                 if (GetManualContourModel()->GetSizeLstPoints()>1){
00473                         id = GetManualContourModel()->InsertPoint(xx,yy,zz);
00474                         GetManualViewBaseContour()->InsertPoint(id);
00475 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
00476                 } else {
00477                         GetManualContourModel()->AddPoint(xx,yy,zz);
00478                         GetManualViewBaseContour()->AddPoint();
00479 //                      AddPoint(x,y,z);
00480 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
00481                 }
00482         }
00483 }
00484 
00485 // ----------------------------------------------------------------------------
00486 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
00487         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
00488                 double xx = x;
00489                 double yy = y;
00490                 double zz = z;
00491                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00492                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
00493                 mp->SetPoint(xx,yy,zz);
00494                 GetManualViewBaseContour()->UpdateViewPoint(id);
00495         }
00496 }
00497 // ----------------------------------------------------------------------------
00498 void manualContourBaseControler::SetPointX( int id ,int x  ){
00499         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
00500                 double xx = x;
00501                 double yy = 0;
00502                 double zz = 0;
00503                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00504                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
00505                 mp->SetPointX(xx);
00506                 GetManualViewBaseContour()->UpdateViewPoint(id);
00507         }
00508 }
00509 // ----------------------------------------------------------------------------
00510 void manualContourBaseControler::SetPointY( int id ,int y  ){
00511         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
00512                 double xx = 0;
00513                 double yy = y;
00514                 double zz = 0;
00515                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00516                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
00517                 mp->SetPointY(yy);
00518                 GetManualViewBaseContour()->UpdateViewPoint(id);
00519         }
00520 }
00521 // ----------------------------------------------------------------------------
00522 void manualContourBaseControler::SetPointZ( int id ,int z  ){
00523         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
00524                 double xx = 0;
00525                 double yy = 0;
00526                 double zz = z;
00527                 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
00528                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
00529                 mp->SetPointZ(zz);
00530                 GetManualViewBaseContour()->UpdateViewPoint(id);
00531         }
00532 }
00533 // ----------------------------------------------------------------------------
00534 void manualContourBaseControler::ResetContour() // virtual
00535 {
00536         this->DeleteContour();
00537         GetManualViewBaseContour()->CreateNewContour();
00538         this->SetState(0);
00539 }
00540 

Generated on Wed Jul 29 16:35:28 2009 for creaMaracasVisu_lib by  doxygen 1.5.3