1 #include "manualContourBaseControler.h"
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 // ----------------------------------------------------------------------------
8 manualContourBaseControler::manualContourBaseControler()
10 _manViewBaseCont = NULL;
14 //EED 21 mars 2012 FLIP probleme ..PLOP..
19 _posibleToMove = true;
22 _keyBoardMoving = false;
24 // ----------------------------------------------------------------------------
25 manualContourBaseControler::~manualContourBaseControler()
29 // ----------------------------------------------------------------------------
30 manualContourBaseControler * manualContourBaseControler :: Clone() // virtual
32 manualContourBaseControler * clone = new manualContourBaseControler();
33 CopyAttributesTo(clone);
37 // ---------------------------------------------------------------------------
39 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
42 InteractorStyleMaracas::CopyAttributesTo(cloneObject);
43 cloneObject->SetZ( this->GetZ() );
44 cloneObject->SetState( this->GetState() );
45 cloneObject->SetEditable( this->IsEditable() );
46 cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
47 cloneObject->SetMoving( this->IsMoving() );
48 cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
49 cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
52 // ----------------------------------------------------------------------------
53 void manualContourBaseControler::Configure() //virtual
57 // ----------------------------------------------------------------------------
58 bool manualContourBaseControler::OnChar()
60 if ( _vtkInteractorStyleBaseView!=NULL )
62 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
65 wxVTKRenderWindowInteractor *_wxVTKiren;
66 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
67 _wxVTKiren->GetEventPosition(X, Y);
68 //int Z = GetZ(); // JPRx
70 if ((keyCode==8) || (keyCode==127))
73 if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
75 DeleteActualMousePoint(X,Y);
77 GetManualViewBaseContour()->Refresh();
78 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
86 GetManualViewBaseContour()->Refresh();
87 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
89 else if( !IsEditable() )
93 GetManualViewBaseContour()->MoveContour( -1, 0 );
94 SetKeyBoardMoving( true );
96 else if ( keyCode == 'R' )
98 GetManualViewBaseContour()->MoveContour( 1, 0 );
99 SetKeyBoardMoving( true );
101 else if ( keyCode == 'U' )
103 GetManualViewBaseContour()->MoveContour( 0, -1 );
104 SetKeyBoardMoving( true );
106 else if ( keyCode == 'D' )
108 GetManualViewBaseContour()->MoveContour( 0, 1 );
109 SetKeyBoardMoving( true );
111 else if ( keyCode == 'W' )//Diagonal left down
113 GetManualViewBaseContour()->MoveContour( -1, 1 );
114 SetKeyBoardMoving( true );
116 else if ( keyCode == 'Q' )//Diagonal left up
118 GetManualViewBaseContour()->MoveContour( -1, -1 );
119 SetKeyBoardMoving( true );
121 else if( keyCode == 'P' )//Diagonal right up
123 GetManualViewBaseContour()->MoveContour( 1, -1 );
124 SetKeyBoardMoving( true );
126 else if( keyCode == 'M' )//Diagonal right down
128 GetManualViewBaseContour()->MoveContour( 1, 1 );
129 SetKeyBoardMoving( true );
131 if( GetKeyBoardMoving() )
133 GetManualViewBaseContour()->Refresh();
134 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
141 // ----------------------------------------------------------------------------
142 bool manualContourBaseControler::OnMouseMove()
144 if ( _vtkInteractorStyleBaseView!=NULL)
147 wxVTKRenderWindowInteractor *_wxVTKiren;
148 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
149 _wxVTKiren->GetEventPosition( X , Y );
151 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
152 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
158 // ----------------------------------------------------------------------------
159 bool manualContourBaseControler::OnLeftButtonDown()
161 SetKeyBoardMoving( false );
162 if ( _vtkInteractorStyleBaseView!=NULL )
165 wxVTKRenderWindowInteractor *wxVTKiren;
166 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
167 wxVTKiren->GetEventPosition(X,Y);
173 // ----------------------------------------------------------------------------
174 bool manualContourBaseControler::OnLeftButtonUp()
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 if ( _vtkInteractorStyleBaseView!=NULL )
192 wxVTKRenderWindowInteractor *wxVTKiren;
193 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
194 wxVTKiren->GetEventPosition(X,Y);
196 this->MouseDLeft(X,Y);
200 // ----------------------------------------------------------------------------
201 bool manualContourBaseControler::OnMiddleButtonDown()
203 // SetKeyBoardMoving( false );
204 if ( _vtkInteractorStyleBaseView!=NULL )
207 wxVTKRenderWindowInteractor *wxVTKiren;
208 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
209 wxVTKiren->GetEventPosition(X,Y);
210 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
214 // ----------------------------------------------------------------------------
215 bool manualContourBaseControler::OnMiddleButtonUp()
219 // ----------------------------------------------------------------------------
220 bool manualContourBaseControler::OnRightButtonDown()
222 if( _vtkInteractorStyleBaseView!= NULL )
225 wxVTKRenderWindowInteractor *wxVTKiren;
226 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
227 wxVTKiren->GetEventPosition(X, Y);
229 MouseClickRight(X,Y);
233 // ----------------------------------------------------------------------------
234 bool manualContourBaseControler::OnRightButtonUp()
238 // ----------------------------------------------------------------------------
239 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
240 _manContModel = manContModel;
241 _manViewBaseCont = manViewBaseCont;
242 _manViewBaseCont->SetEditable( &_editable );
244 // ----------------------------------------------------------------------------
245 manualBaseModel* manualContourBaseControler::GetManualContourModel()
247 return _manContModel;
249 // ----------------------------------------------------------------------------
250 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
252 return _manViewBaseCont;
254 // ----------------------------------------------------------------------------
255 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
259 // ----------------------------------------------------------------------------
260 void manualContourBaseControler::MouseClickRight(int x, int y)
262 SetCompleteCreation( true );
263 SetKeyBoardMoving( false );
264 this->GetManualContourModel()->SetCloseContour(true);
270 SetEditable( false );
271 SetPosibleToMove( false );
274 //EED 24Avril2009 _state=7;
276 // ----------------------------------------------------------------------------
277 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
279 if (_state==5){ _state = 0; }
280 if (_state==6){ _state = 0; }
281 if (_state==7){ _state = 0; }
283 GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
284 if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1) )
286 SetEditable( false );
287 SetPosibleToMove( false );
290 // ----------------------------------------------------------------------------
291 void manualContourBaseControler::MouseDLeft(int x, int y )
297 /*bool temp = */ _manViewBaseCont->SelectPosibleContour(x,y,z);
299 _manViewBaseCont->SelectPosiblePoint(x,y,z);
301 if ( _manViewBaseCont->GetPosibleSelected() )
307 // ----------------------------------------------------------------------------
308 void manualContourBaseControler::MouseMove(int x, int y) // virtual
311 // ----------------------------------------------------------------------------
312 void manualContourBaseControler::SetState(int state)
316 // ----------------------------------------------------------------------------
317 int manualContourBaseControler::GetState()
321 // ----------------------------------------------------------------------------
322 bool manualContourBaseControler::IsEditable( )
326 // ----------------------------------------------------------------------------
327 void manualContourBaseControler::SetEditable( bool condition )
329 if (GetManualViewBaseContour()!=NULL) {
332 GetManualViewBaseContour()->RemoveControlPoints();
334 GetManualViewBaseContour()->SetSelected( condition );
336 _editable = condition;
339 // ----------------------------------------------------------------------------
340 bool manualContourBaseControler::GetPosibleToMove()
342 return _posibleToMove;
344 // ----------------------------------------------------------------------------
345 void manualContourBaseControler::SetPosibleToMove( bool condition )
347 _posibleToMove = condition;
349 // ----------------------------------------------------------------------------
350 bool manualContourBaseControler::IsMoving()
354 // ----------------------------------------------------------------------------
355 void manualContourBaseControler::SetMoving( bool condition )
359 // ----------------------------------------------------------------------------
360 void manualContourBaseControler::SetCompleteCreation( bool condition )
362 _created = condition;
364 // ----------------------------------------------------------------------------
365 bool manualContourBaseControler::GetIfCompleteCreation ( )
369 // ----------------------------------------------------------------------------
370 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
372 _keyBoardMoving = condition;
374 // ----------------------------------------------------------------------------
375 bool manualContourBaseControler::GetKeyBoardMoving( )
377 return _keyBoardMoving;
379 // ----------------------------------------------------------------------------
380 void manualContourBaseControler::CreateNewManualContour(){
381 _manViewBaseCont->CreateNewContour();
383 // ----------------------------------------------------------------------------
384 int manualContourBaseControler::GetNumberOfPointsManualContour(){
385 return _manViewBaseCont->GetNumberOfPoints();
387 // ----------------------------------------------------------------------------
389 //JSTG - 25-02-08 -------------------------------------------------------------
390 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
391 //return _manViewBaseCont->GetNumberOfPointsSpline();
392 return _manContModel->GetNumberOfPointsSpline();
394 // ----------------------------------------------------------------------------
396 double* manualContourBaseControler::GetVectorPointsXManualContour(){
397 return _manViewBaseCont->GetVectorPointsXManualContour();
399 // ----------------------------------------------------------------------------
400 double* manualContourBaseControler::GetVectorPointsYManualContour(){
401 return _manViewBaseCont->GetVectorPointsYManualContour();
403 // ----------------------------------------------------------------------------
404 void manualContourBaseControler::DeleteContour(){
405 _manViewBaseCont->DeleteContour();
406 _manContModel->DeleteAllPoints();
408 // ----------------------------------------------------------------------------
409 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
411 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
413 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
414 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
415 _manContModel->DeletePoint(id);
416 _manViewBaseCont->DeletePoint(id);
422 // ----------------------------------------------------------------------------
423 void manualContourBaseControler::Magnet(int x, int y)
427 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
428 if (GetManualContourModel()!=NULL){
432 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
433 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
436 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
437 mp->SetPoint(xx,yy,zz);
439 // GetManualViewBaseContour()->UpdateViewPoint(id);
445 // ----------------------------------------------------------------------------
446 void manualContourBaseControler::SetZ(int z)
450 // ----------------------------------------------------------------------------
451 int manualContourBaseControler::GetZ()
455 // ----------------------------------------------------------------------------
456 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
458 if (GetManualContourModel()!=NULL){
463 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
464 GetManualContourModel()->AddPoint(xx,yy,zz);
465 GetManualViewBaseContour()->AddPoint();
466 // GetManualViewBaseContour()->UpdateViewPoint(id);
469 // ----------------------------------------------------------------------------
470 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
474 if (GetManualContourModel()!=NULL){
478 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
479 if (GetManualContourModel()->GetSizeLstPoints()>1){
480 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
481 GetManualViewBaseContour()->InsertPoint(id);
482 // GetManualViewBaseContour()->UpdateViewPoint(id);
484 GetManualContourModel()->AddPoint(xx,yy,zz);
485 GetManualViewBaseContour()->AddPoint();
487 // GetManualViewBaseContour()->UpdateViewPoint(id);
492 // ----------------------------------------------------------------------------
493 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
494 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
499 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
500 manualPoint *mp = _manContModel->GetManualPoint(id);
501 mp->SetPoint(xx,yy,zz);
502 GetManualViewBaseContour()->UpdateViewPoint(id);
505 // ----------------------------------------------------------------------------
506 void manualContourBaseControler::SetPointX( int id ,int x ){
507 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
511 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
512 manualPoint *mp = _manContModel->GetManualPoint(id);
514 GetManualViewBaseContour()->UpdateViewPoint(id);
517 // ----------------------------------------------------------------------------
518 void manualContourBaseControler::SetPointY( int id ,int y ){
519 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
523 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
524 manualPoint *mp = _manContModel->GetManualPoint(id);
526 GetManualViewBaseContour()->UpdateViewPoint(id);
529 // ----------------------------------------------------------------------------
530 void manualContourBaseControler::SetPointZ( int id ,int z ){
531 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
535 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
536 manualPoint *mp = _manContModel->GetManualPoint(id);
538 GetManualViewBaseContour()->UpdateViewPoint(id);
541 // ----------------------------------------------------------------------------
542 void manualContourBaseControler::ResetContour() // virtual
544 this->DeleteContour();
545 GetManualViewBaseContour()->CreateNewContour();