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()
140 if ( _vtkInteractorStyleBaseView!=NULL)
143 wxVTKRenderWindowInteractor *_wxVTKiren;
144 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
145 _wxVTKiren->GetEventPosition( X , Y );
147 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
148 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
154 // ----------------------------------------------------------------------------
155 bool manualContourBaseControler::OnLeftButtonDown()
157 SetKeyBoardMoving( false );
158 if ( _vtkInteractorStyleBaseView!=NULL )
161 wxVTKRenderWindowInteractor *wxVTKiren;
162 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
163 wxVTKiren->GetEventPosition(X,Y);
169 // ----------------------------------------------------------------------------
170 bool manualContourBaseControler::OnLeftButtonUp()
172 if ( _vtkInteractorStyleBaseView!=NULL )
175 wxVTKRenderWindowInteractor *wxVTKiren;
176 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
177 wxVTKiren->GetEventPosition(X,Y);
178 MouseReleaseLeft(X,Y);
182 // ----------------------------------------------------------------------------
183 bool manualContourBaseControler::OnLeftDClick()
185 if ( _vtkInteractorStyleBaseView!=NULL )
188 wxVTKRenderWindowInteractor *wxVTKiren;
189 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
190 wxVTKiren->GetEventPosition(X,Y);
192 this->MouseDLeft(X,Y);
196 // ----------------------------------------------------------------------------
197 bool manualContourBaseControler::OnMiddleButtonDown()
199 // SetKeyBoardMoving( false );
200 if ( _vtkInteractorStyleBaseView!=NULL )
203 wxVTKRenderWindowInteractor *wxVTKiren;
204 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
205 wxVTKiren->GetEventPosition(X,Y);
206 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
210 // ----------------------------------------------------------------------------
211 bool manualContourBaseControler::OnMiddleButtonUp()
215 // ----------------------------------------------------------------------------
216 bool manualContourBaseControler::OnRightButtonDown()
218 if( _vtkInteractorStyleBaseView!= NULL )
221 wxVTKRenderWindowInteractor *wxVTKiren;
222 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
223 wxVTKiren->GetEventPosition(X, Y);
225 MouseClickRight(X,Y);
229 // ----------------------------------------------------------------------------
230 bool manualContourBaseControler::OnRightButtonUp()
234 // ----------------------------------------------------------------------------
235 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
236 _manContModel = manContModel;
237 _manViewBaseCont = manViewBaseCont;
238 _manViewBaseCont->SetEditable( &_editable );
240 // ----------------------------------------------------------------------------
241 manualBaseModel* manualContourBaseControler::GetManualContourModel()
243 return _manContModel;
245 // ----------------------------------------------------------------------------
246 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
248 return _manViewBaseCont;
250 // ----------------------------------------------------------------------------
251 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
255 // ----------------------------------------------------------------------------
256 void manualContourBaseControler::MouseClickRight(int x, int y)
258 SetCompleteCreation( true );
259 SetKeyBoardMoving( false );
260 this->GetManualContourModel()->SetCloseContour(true);
266 SetEditable( false );
267 SetPosibleToMove( false );
270 //EED 24Avril2009 _state=7;
272 // ----------------------------------------------------------------------------
273 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
275 if (_state==5){ _state = 0; }
276 if (_state==6){ _state = 0; }
277 if (_state==7){ _state = 0; }
279 GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
280 if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1) )
282 SetEditable( false );
283 SetPosibleToMove( false );
286 // ----------------------------------------------------------------------------
287 void manualContourBaseControler::MouseDLeft(int x, int y )
293 /*bool temp = */ _manViewBaseCont->SelectPosibleContour(x,y,z);
295 _manViewBaseCont->SelectPosiblePoint(x,y,z);
297 if ( _manViewBaseCont->GetPosibleSelected() )
303 // ----------------------------------------------------------------------------
304 void manualContourBaseControler::MouseMove(int x, int y) // virtual
307 // ----------------------------------------------------------------------------
308 void manualContourBaseControler::SetState(int state)
312 // ----------------------------------------------------------------------------
313 int manualContourBaseControler::GetState()
317 // ----------------------------------------------------------------------------
318 bool manualContourBaseControler::IsEditable( )
322 // ----------------------------------------------------------------------------
323 void manualContourBaseControler::SetEditable( bool condition )
325 if (GetManualViewBaseContour()!=NULL) {
328 GetManualViewBaseContour()->RemoveControlPoints();
330 GetManualViewBaseContour()->SetSelected( condition );
332 _editable = condition;
335 // ----------------------------------------------------------------------------
336 bool manualContourBaseControler::GetPosibleToMove()
338 return _posibleToMove;
340 // ----------------------------------------------------------------------------
341 void manualContourBaseControler::SetPosibleToMove( bool condition )
343 _posibleToMove = condition;
345 // ----------------------------------------------------------------------------
346 bool manualContourBaseControler::IsMoving()
350 // ----------------------------------------------------------------------------
351 void manualContourBaseControler::SetMoving( bool condition )
355 // ----------------------------------------------------------------------------
356 void manualContourBaseControler::SetCompleteCreation( bool condition )
358 _created = condition;
360 // ----------------------------------------------------------------------------
361 bool manualContourBaseControler::GetIfCompleteCreation ( )
365 // ----------------------------------------------------------------------------
366 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
368 _keyBoardMoving = condition;
370 // ----------------------------------------------------------------------------
371 bool manualContourBaseControler::GetKeyBoardMoving( )
373 return _keyBoardMoving;
375 // ----------------------------------------------------------------------------
376 void manualContourBaseControler::CreateNewManualContour(){
377 _manViewBaseCont->CreateNewContour();
379 // ----------------------------------------------------------------------------
380 int manualContourBaseControler::GetNumberOfPointsManualContour(){
381 return _manViewBaseCont->GetNumberOfPoints();
383 // ----------------------------------------------------------------------------
385 //JSTG - 25-02-08 -------------------------------------------------------------
386 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
387 //return _manViewBaseCont->GetNumberOfPointsSpline();
388 return _manContModel->GetNumberOfPointsSpline();
390 // ----------------------------------------------------------------------------
392 double* manualContourBaseControler::GetVectorPointsXManualContour(){
393 return _manViewBaseCont->GetVectorPointsXManualContour();
395 // ----------------------------------------------------------------------------
396 double* manualContourBaseControler::GetVectorPointsYManualContour(){
397 return _manViewBaseCont->GetVectorPointsYManualContour();
399 // ----------------------------------------------------------------------------
400 void manualContourBaseControler::DeleteContour(){
401 _manViewBaseCont->DeleteContour();
402 _manContModel->DeleteAllPoints();
404 // ----------------------------------------------------------------------------
405 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
407 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
409 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
410 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
411 _manContModel->DeletePoint(id);
412 _manViewBaseCont->DeletePoint(id);
418 // ----------------------------------------------------------------------------
419 void manualContourBaseControler::Magnet(int x, int y)
423 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
424 if (GetManualContourModel()!=NULL){
428 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
429 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
432 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
433 mp->SetPoint(xx,yy,zz);
435 // GetManualViewBaseContour()->UpdateViewPoint(id);
441 // ----------------------------------------------------------------------------
442 void manualContourBaseControler::SetZ(int z)
446 // ----------------------------------------------------------------------------
447 int manualContourBaseControler::GetZ()
451 // ----------------------------------------------------------------------------
452 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
454 if (GetManualContourModel()!=NULL){
459 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
460 GetManualContourModel()->AddPoint(xx,yy,zz);
461 GetManualViewBaseContour()->AddPoint();
462 // GetManualViewBaseContour()->UpdateViewPoint(id);
465 // ----------------------------------------------------------------------------
466 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
470 if (GetManualContourModel()!=NULL){
474 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
475 if (GetManualContourModel()->GetSizeLstPoints()>1){
476 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
477 GetManualViewBaseContour()->InsertPoint(id);
478 // GetManualViewBaseContour()->UpdateViewPoint(id);
480 GetManualContourModel()->AddPoint(xx,yy,zz);
481 GetManualViewBaseContour()->AddPoint();
483 // GetManualViewBaseContour()->UpdateViewPoint(id);
488 // ----------------------------------------------------------------------------
489 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
490 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
495 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
496 manualPoint *mp = _manContModel->GetManualPoint(id);
497 mp->SetPoint(xx,yy,zz);
498 GetManualViewBaseContour()->UpdateViewPoint(id);
501 // ----------------------------------------------------------------------------
502 void manualContourBaseControler::SetPointX( int id ,int x ){
503 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
507 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
508 manualPoint *mp = _manContModel->GetManualPoint(id);
510 GetManualViewBaseContour()->UpdateViewPoint(id);
513 // ----------------------------------------------------------------------------
514 void manualContourBaseControler::SetPointY( int id ,int y ){
515 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
519 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
520 manualPoint *mp = _manContModel->GetManualPoint(id);
522 GetManualViewBaseContour()->UpdateViewPoint(id);
525 // ----------------------------------------------------------------------------
526 void manualContourBaseControler::SetPointZ( int id ,int z ){
527 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
531 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
532 manualPoint *mp = _manContModel->GetManualPoint(id);
534 GetManualViewBaseContour()->UpdateViewPoint(id);
537 // ----------------------------------------------------------------------------
538 void manualContourBaseControler::ResetContour() // virtual
540 this->DeleteContour();
541 GetManualViewBaseContour()->CreateNewContour();