1 #include "manualContourBaseControler.h"
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
8 manualContourBaseControler::manualContourBaseControler()
10 _manViewBaseCont = NULL;
15 _posibleToMove = true;
18 _keyBoardMoving = false;
20 // ----------------------------------------------------------------------------
21 manualContourBaseControler::~manualContourBaseControler()
25 // ----------------------------------------------------------------------------
26 manualContourBaseControler * manualContourBaseControler :: Clone() // virtual
28 manualContourBaseControler * clone = new manualContourBaseControler();
29 CopyAttributesTo(clone);
33 // ---------------------------------------------------------------------------
35 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
38 InteractorStyleMaracas::CopyAttributesTo(cloneObject);
39 cloneObject->SetZ( this->GetZ() );
40 cloneObject->SetState( this->GetState() );
41 cloneObject->SetEditable( this->IsEditable() );
42 cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
43 cloneObject->SetMoving( this->IsMoving() );
44 cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
45 cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
48 // ----------------------------------------------------------------------------
49 void manualContourBaseControler::Configure() //virtual
53 // ----------------------------------------------------------------------------
54 bool manualContourBaseControler::OnChar()
56 if ( _vtkInteractorStyleBaseView!=NULL )
58 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
61 wxVTKRenderWindowInteractor *_wxVTKiren;
62 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
63 _wxVTKiren->GetEventPosition(X, Y);
64 //int Z = GetZ(); // JPRx
66 if ((keyCode==8) || (keyCode==127))
69 if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
71 DeleteActualMousePoint(X,Y);
73 GetManualViewBaseContour()->Refresh();
74 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
82 GetManualViewBaseContour()->Refresh();
83 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
85 else if( !IsEditable() )
89 GetManualViewBaseContour()->MoveContour( -1, 0 );
90 SetKeyBoardMoving( true );
92 else if ( keyCode == 'R' )
94 GetManualViewBaseContour()->MoveContour( 1, 0 );
95 SetKeyBoardMoving( true );
97 else if ( keyCode == 'U' )
99 GetManualViewBaseContour()->MoveContour( 0, -1 );
100 SetKeyBoardMoving( true );
102 else if ( keyCode == 'D' )
104 GetManualViewBaseContour()->MoveContour( 0, 1 );
105 SetKeyBoardMoving( true );
107 else if ( keyCode == 'W' )//Diagonal left down
109 GetManualViewBaseContour()->MoveContour( -1, 1 );
110 SetKeyBoardMoving( true );
112 else if ( keyCode == 'Q' )//Diagonal left up
114 GetManualViewBaseContour()->MoveContour( -1, -1 );
115 SetKeyBoardMoving( true );
117 else if( keyCode == 'P' )//Diagonal right up
119 GetManualViewBaseContour()->MoveContour( 1, -1 );
120 SetKeyBoardMoving( true );
122 else if( keyCode == 'M' )//Diagonal right down
124 GetManualViewBaseContour()->MoveContour( 1, 1 );
125 SetKeyBoardMoving( true );
127 if( GetKeyBoardMoving() )
129 GetManualViewBaseContour()->Refresh();
130 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
137 // ----------------------------------------------------------------------------
138 bool manualContourBaseControler::OnMouseMove()
141 if ( _vtkInteractorStyleBaseView!=NULL)
144 wxVTKRenderWindowInteractor *_wxVTKiren;
145 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
146 _wxVTKiren->GetEventPosition( X , Y );
149 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
150 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
156 // ----------------------------------------------------------------------------
157 bool manualContourBaseControler::OnLeftButtonDown()
159 printf("EED %p manualContourBaseControler::OnLeftButtonDown \n",this);
160 SetKeyBoardMoving( false );
161 if ( _vtkInteractorStyleBaseView!=NULL )
164 wxVTKRenderWindowInteractor *wxVTKiren;
165 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
166 wxVTKiren->GetEventPosition(X,Y);
172 // ----------------------------------------------------------------------------
173 bool manualContourBaseControler::OnLeftButtonUp()
175 printf("EED %p manualContourBaseControler::OnLeftButtonUp \n",this);
176 if ( _vtkInteractorStyleBaseView!=NULL )
179 wxVTKRenderWindowInteractor *wxVTKiren;
180 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
181 wxVTKiren->GetEventPosition(X,Y);
182 MouseReleaseLeft(X,Y);
186 // ----------------------------------------------------------------------------
187 bool manualContourBaseControler::OnLeftDClick()
189 printf("EED %p manualContourBaseControler::OnLeftDClick \n",this);
190 if ( _vtkInteractorStyleBaseView!=NULL )
193 wxVTKRenderWindowInteractor *wxVTKiren;
194 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
195 wxVTKiren->GetEventPosition(X,Y);
197 this->MouseDLeft(X,Y);
201 // ----------------------------------------------------------------------------
202 bool manualContourBaseControler::OnMiddleButtonDown()
204 // SetKeyBoardMoving( false );
205 if ( _vtkInteractorStyleBaseView!=NULL )
208 wxVTKRenderWindowInteractor *wxVTKiren;
209 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
210 wxVTKiren->GetEventPosition(X,Y);
211 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
215 // ----------------------------------------------------------------------------
216 bool manualContourBaseControler::OnMiddleButtonUp()
220 // ----------------------------------------------------------------------------
221 bool manualContourBaseControler::OnRightButtonDown()
223 printf("EED %p manualContourBaseControler::OnRightButtonDown \n",this);
224 if( _vtkInteractorStyleBaseView!= NULL )
227 wxVTKRenderWindowInteractor *wxVTKiren;
228 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
229 wxVTKiren->GetEventPosition(X, Y);
231 MouseClickRight(X,Y);
235 // ----------------------------------------------------------------------------
236 bool manualContourBaseControler::OnRightButtonUp()
238 printf("EED %p manualContourBaseControler::OnRightButtonUp \n",this);
241 // ----------------------------------------------------------------------------
242 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
243 _manContModel = manContModel;
244 _manViewBaseCont = manViewBaseCont;
245 _manViewBaseCont->SetEditable( &_editable );
247 // ----------------------------------------------------------------------------
248 manualBaseModel* manualContourBaseControler::GetManualContourModel()
250 return _manContModel;
252 // ----------------------------------------------------------------------------
253 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
255 return _manViewBaseCont;
257 // ----------------------------------------------------------------------------
258 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
262 // ----------------------------------------------------------------------------
263 void manualContourBaseControler::MouseClickRight(int x, int y)
266 SetCompleteCreation( true );
267 SetKeyBoardMoving( false );
268 this->GetManualContourModel()->SetCloseContour(true);
274 SetEditable( false );
275 SetPosibleToMove( false );
278 //EED 24Avril2009 _state=7;
280 // ----------------------------------------------------------------------------
281 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
283 if (_state==5){ _state = 0; }
284 if (_state==6){ _state = 0; }
285 if (_state==7){ _state = 0; }
287 GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
288 if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1) )
290 SetEditable( false );
291 SetPosibleToMove( false );
294 // ----------------------------------------------------------------------------
295 void manualContourBaseControler::MouseDLeft(int x, int y )
301 bool temp = _manViewBaseCont->SelectPosibleContour(x,y,z);
303 _manViewBaseCont->SelectPosiblePoint(x,y,z);
305 if ( _manViewBaseCont->GetPosibleSelected() )
311 // ----------------------------------------------------------------------------
312 void manualContourBaseControler::MouseMove(int x, int y) // virtual
315 // ----------------------------------------------------------------------------
316 void manualContourBaseControler::SetState(int state)
320 // ----------------------------------------------------------------------------
321 int manualContourBaseControler::GetState()
325 // ----------------------------------------------------------------------------
326 bool manualContourBaseControler::IsEditable( )
330 // ----------------------------------------------------------------------------
331 void manualContourBaseControler::SetEditable( bool condition )
333 if (GetManualViewBaseContour()!=NULL) {
336 GetManualViewBaseContour()->RemoveControlPoints();
338 GetManualViewBaseContour()->SetSelected( condition );
340 _editable = condition;
343 // ----------------------------------------------------------------------------
344 bool manualContourBaseControler::GetPosibleToMove()
346 return _posibleToMove;
348 // ----------------------------------------------------------------------------
349 void manualContourBaseControler::SetPosibleToMove( bool condition )
351 _posibleToMove = condition;
353 // ----------------------------------------------------------------------------
354 bool manualContourBaseControler::IsMoving()
358 // ----------------------------------------------------------------------------
359 void manualContourBaseControler::SetMoving( bool condition )
363 // ----------------------------------------------------------------------------
364 void manualContourBaseControler::SetCompleteCreation( bool condition )
366 _created = condition;
368 // ----------------------------------------------------------------------------
369 bool manualContourBaseControler::GetIfCompleteCreation ( )
373 // ----------------------------------------------------------------------------
374 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
376 _keyBoardMoving = condition;
378 // ----------------------------------------------------------------------------
379 bool manualContourBaseControler::GetKeyBoardMoving( )
381 return _keyBoardMoving;
383 // ----------------------------------------------------------------------------
384 void manualContourBaseControler::CreateNewManualContour(){
385 _manViewBaseCont->CreateNewContour();
387 // ----------------------------------------------------------------------------
388 int manualContourBaseControler::GetNumberOfPointsManualContour(){
389 return _manViewBaseCont->GetNumberOfPoints();
391 // ----------------------------------------------------------------------------
393 //JSTG - 25-02-08 -------------------------------------------------------------
394 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
395 //return _manViewBaseCont->GetNumberOfPointsSpline();
396 return _manContModel->GetNumberOfPointsSpline();
398 // ----------------------------------------------------------------------------
400 double* manualContourBaseControler::GetVectorPointsXManualContour(){
401 return _manViewBaseCont->GetVectorPointsXManualContour();
403 // ----------------------------------------------------------------------------
404 double* manualContourBaseControler::GetVectorPointsYManualContour(){
405 return _manViewBaseCont->GetVectorPointsYManualContour();
407 // ----------------------------------------------------------------------------
408 void manualContourBaseControler::DeleteContour(){
409 _manViewBaseCont->DeleteContour();
410 _manContModel->DeleteAllPoints();
412 // ----------------------------------------------------------------------------
413 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
415 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
417 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
418 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
419 _manContModel->DeletePoint(id);
420 _manViewBaseCont->DeletePoint(id);
426 // ----------------------------------------------------------------------------
427 void manualContourBaseControler::Magnet(int x, int y)
431 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
432 if (GetManualContourModel()!=NULL){
436 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
437 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
440 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
441 mp->SetPoint(xx,yy,zz);
443 // GetManualViewBaseContour()->UpdateViewPoint(id);
449 // ----------------------------------------------------------------------------
450 void manualContourBaseControler::SetZ(int z)
454 // ----------------------------------------------------------------------------
455 int manualContourBaseControler::GetZ()
459 // ----------------------------------------------------------------------------
460 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
462 if (GetManualContourModel()!=NULL){
468 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
469 printf("EED %p manualContourBaseControler::AddPoint \n", this);
470 GetManualContourModel()->AddPoint(xx,yy,zz);
471 GetManualViewBaseContour()->AddPoint();
472 // GetManualViewBaseContour()->UpdateViewPoint(id);
475 // ----------------------------------------------------------------------------
476 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
480 if (GetManualContourModel()!=NULL){
484 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
485 if (GetManualContourModel()->GetSizeLstPoints()>1){
486 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
487 GetManualViewBaseContour()->InsertPoint(id);
488 // GetManualViewBaseContour()->UpdateViewPoint(id);
490 GetManualContourModel()->AddPoint(xx,yy,zz);
491 GetManualViewBaseContour()->AddPoint();
493 // GetManualViewBaseContour()->UpdateViewPoint(id);
498 // ----------------------------------------------------------------------------
499 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
500 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
505 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
506 manualPoint *mp = _manContModel->GetManualPoint(id);
507 mp->SetPoint(xx,yy,zz);
508 GetManualViewBaseContour()->UpdateViewPoint(id);
511 // ----------------------------------------------------------------------------
512 void manualContourBaseControler::SetPointX( int id ,int x ){
513 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
517 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
518 manualPoint *mp = _manContModel->GetManualPoint(id);
520 GetManualViewBaseContour()->UpdateViewPoint(id);
523 // ----------------------------------------------------------------------------
524 void manualContourBaseControler::SetPointY( int id ,int y ){
525 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
529 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
530 manualPoint *mp = _manContModel->GetManualPoint(id);
532 GetManualViewBaseContour()->UpdateViewPoint(id);
535 // ----------------------------------------------------------------------------
536 void manualContourBaseControler::SetPointZ( int id ,int z ){
537 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
541 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
542 manualPoint *mp = _manContModel->GetManualPoint(id);
544 GetManualViewBaseContour()->UpdateViewPoint(id);
547 // ----------------------------------------------------------------------------
548 void manualContourBaseControler::ResetContour() // virtual
550 this->DeleteContour();
551 GetManualViewBaseContour()->CreateNewContour();