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 SetKeyBoardMoving( false );
160 if ( _vtkInteractorStyleBaseView!=NULL )
163 wxVTKRenderWindowInteractor *wxVTKiren;
164 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
165 wxVTKiren->GetEventPosition(X,Y);
171 // ----------------------------------------------------------------------------
172 bool manualContourBaseControler::OnLeftButtonUp()
174 if ( _vtkInteractorStyleBaseView!=NULL )
177 wxVTKRenderWindowInteractor *wxVTKiren;
178 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
179 wxVTKiren->GetEventPosition(X,Y);
180 MouseReleaseLeft(X,Y);
184 // ----------------------------------------------------------------------------
185 bool manualContourBaseControler::OnLeftDClick()
187 if ( _vtkInteractorStyleBaseView!=NULL )
190 wxVTKRenderWindowInteractor *wxVTKiren;
191 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
192 wxVTKiren->GetEventPosition(X,Y);
194 this->MouseDLeft(X,Y);
198 // ----------------------------------------------------------------------------
199 bool manualContourBaseControler::OnMiddleButtonDown()
201 // SetKeyBoardMoving( false );
202 if ( _vtkInteractorStyleBaseView!=NULL )
205 wxVTKRenderWindowInteractor *wxVTKiren;
206 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
207 wxVTKiren->GetEventPosition(X,Y);
208 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
212 // ----------------------------------------------------------------------------
213 bool manualContourBaseControler::OnMiddleButtonUp()
217 // ----------------------------------------------------------------------------
218 bool manualContourBaseControler::OnRightButtonDown()
220 if( _vtkInteractorStyleBaseView!= NULL )
223 wxVTKRenderWindowInteractor *wxVTKiren;
224 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
225 wxVTKiren->GetEventPosition(X, Y);
227 SetCompleteCreation( true );
228 SetKeyBoardMoving( false );
229 this->GetManualContourModel()->SetCloseContour(true);
230 MouseClickRight(X,Y);
234 // ----------------------------------------------------------------------------
235 bool manualContourBaseControler::OnRightButtonUp()
239 // ----------------------------------------------------------------------------
240 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
241 _manContModel = manContModel;
242 _manViewBaseCont = manViewBaseCont;
243 _manViewBaseCont->SetEditable( &_editable );
245 // ----------------------------------------------------------------------------
246 manualBaseModel* manualContourBaseControler::GetManualContourModel()
248 return _manContModel;
250 // ----------------------------------------------------------------------------
251 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
253 return _manViewBaseCont;
255 // ----------------------------------------------------------------------------
256 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
260 // ----------------------------------------------------------------------------
261 void manualContourBaseControler::MouseClickRight(int x, int y)
267 SetEditable( false );
268 SetPosibleToMove( false );
271 //EED 24Avril2009 _state=7;
273 // ----------------------------------------------------------------------------
274 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
276 if (_state==5){ _state = 0; }
277 if (_state==6){ _state = 0; }
278 if (_state==7){ _state = 0; }
280 GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
281 if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1) )
283 SetEditable( false );
284 SetPosibleToMove( false );
287 // ----------------------------------------------------------------------------
288 void manualContourBaseControler::MouseDLeft(int x, int y )
294 bool temp = _manViewBaseCont->SelectPosibleContour(x,y,z);
296 _manViewBaseCont->SelectPosiblePoint(x,y,z);
298 if ( _manViewBaseCont->GetPosibleSelected() )
304 // ----------------------------------------------------------------------------
305 void manualContourBaseControler::MouseMove(int x, int y) // virtual
308 // ----------------------------------------------------------------------------
309 void manualContourBaseControler::SetState(int state)
313 // ----------------------------------------------------------------------------
314 int manualContourBaseControler::GetState()
318 // ----------------------------------------------------------------------------
319 bool manualContourBaseControler::IsEditable( )
323 // ----------------------------------------------------------------------------
324 void manualContourBaseControler::SetEditable( bool condition )
326 if (GetManualViewBaseContour()!=NULL) {
329 GetManualViewBaseContour()->RemoveControlPoints();
331 GetManualViewBaseContour()->SetSelected( condition );
333 _editable = condition;
336 // ----------------------------------------------------------------------------
337 bool manualContourBaseControler::GetPosibleToMove()
339 return _posibleToMove;
341 // ----------------------------------------------------------------------------
342 void manualContourBaseControler::SetPosibleToMove( bool condition )
344 _posibleToMove = condition;
346 // ----------------------------------------------------------------------------
347 bool manualContourBaseControler::IsMoving()
351 // ----------------------------------------------------------------------------
352 void manualContourBaseControler::SetMoving( bool condition )
356 // ----------------------------------------------------------------------------
357 void manualContourBaseControler::SetCompleteCreation( bool condition )
359 _created = condition;
361 // ----------------------------------------------------------------------------
362 bool manualContourBaseControler::GetIfCompleteCreation ( )
366 // ----------------------------------------------------------------------------
367 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
369 _keyBoardMoving = condition;
371 // ----------------------------------------------------------------------------
372 bool manualContourBaseControler::GetKeyBoardMoving( )
374 return _keyBoardMoving;
376 // ----------------------------------------------------------------------------
377 void manualContourBaseControler::CreateNewManualContour(){
378 _manViewBaseCont->CreateNewContour();
380 // ----------------------------------------------------------------------------
381 int manualContourBaseControler::GetNumberOfPointsManualContour(){
382 return _manViewBaseCont->GetNumberOfPoints();
384 // ----------------------------------------------------------------------------
386 //JSTG - 25-02-08 -------------------------------------------------------------
387 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
388 //return _manViewBaseCont->GetNumberOfPointsSpline();
389 return _manContModel->GetNumberOfPointsSpline();
391 // ----------------------------------------------------------------------------
393 double* manualContourBaseControler::GetVectorPointsXManualContour(){
394 return _manViewBaseCont->GetVectorPointsXManualContour();
396 // ----------------------------------------------------------------------------
397 double* manualContourBaseControler::GetVectorPointsYManualContour(){
398 return _manViewBaseCont->GetVectorPointsYManualContour();
400 // ----------------------------------------------------------------------------
401 void manualContourBaseControler::DeleteContour(){
402 _manViewBaseCont->DeleteContour();
403 _manContModel->DeleteAllPoints();
405 // ----------------------------------------------------------------------------
406 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
408 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
410 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
411 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
412 _manContModel->DeletePoint(id);
413 _manViewBaseCont->DeletePoint(id);
419 // ----------------------------------------------------------------------------
420 void manualContourBaseControler::Magnet(int x, int y)
424 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
425 if (GetManualContourModel()!=NULL){
429 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
430 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
433 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
434 mp->SetPoint(xx,yy,zz);
436 // GetManualViewBaseContour()->UpdateViewPoint(id);
442 // ----------------------------------------------------------------------------
443 void manualContourBaseControler::SetZ(int z)
447 // ----------------------------------------------------------------------------
448 int manualContourBaseControler::GetZ()
452 // ----------------------------------------------------------------------------
453 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
455 if (GetManualContourModel()!=NULL){
461 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
462 /*int id =*/ GetManualContourModel()->AddPoint(xx,yy,zz); // JPRx
463 GetManualViewBaseContour()->AddPoint();
464 // GetManualViewBaseContour()->UpdateViewPoint(id);
467 // ----------------------------------------------------------------------------
468 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
472 if (GetManualContourModel()!=NULL){
476 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
477 if (GetManualContourModel()->GetSizeLstPoints()>1){
478 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
479 GetManualViewBaseContour()->InsertPoint(id);
480 // GetManualViewBaseContour()->UpdateViewPoint(id);
482 GetManualContourModel()->AddPoint(xx,yy,zz);
483 GetManualViewBaseContour()->AddPoint();
485 // GetManualViewBaseContour()->UpdateViewPoint(id);
490 // ----------------------------------------------------------------------------
491 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
492 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
497 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
498 manualPoint *mp = _manContModel->GetManualPoint(id);
499 mp->SetPoint(xx,yy,zz);
500 GetManualViewBaseContour()->UpdateViewPoint(id);
503 // ----------------------------------------------------------------------------
504 void manualContourBaseControler::SetPointX( int id ,int x ){
505 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
509 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
510 manualPoint *mp = _manContModel->GetManualPoint(id);
512 GetManualViewBaseContour()->UpdateViewPoint(id);
515 // ----------------------------------------------------------------------------
516 void manualContourBaseControler::SetPointY( int id ,int y ){
517 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
521 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
522 manualPoint *mp = _manContModel->GetManualPoint(id);
524 GetManualViewBaseContour()->UpdateViewPoint(id);
527 // ----------------------------------------------------------------------------
528 void manualContourBaseControler::SetPointZ( int id ,int z ){
529 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
533 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
534 manualPoint *mp = _manContModel->GetManualPoint(id);
536 GetManualViewBaseContour()->UpdateViewPoint(id);
539 // ----------------------------------------------------------------------------
540 void manualContourBaseControler::ResetContour() // virtual
542 this->DeleteContour();
543 GetManualViewBaseContour()->CreateNewContour();