1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "manualContourBaseControler.h"
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 manualContourBaseControler::manualContourBaseControler()
35 _manViewBaseCont = NULL;
39 //EED 21 mars 2012 FLIP probleme ..PLOP..
44 _posibleToMove = true;
47 _keyBoardMoving = false;
49 // ----------------------------------------------------------------------------
50 manualContourBaseControler::~manualContourBaseControler()
54 // ----------------------------------------------------------------------------
55 manualContourBaseControler * manualContourBaseControler :: Clone() // virtual
57 manualContourBaseControler * clone = new manualContourBaseControler();
58 CopyAttributesTo(clone);
62 // ---------------------------------------------------------------------------
64 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
67 InteractorStyleMaracas::CopyAttributesTo(cloneObject);
68 cloneObject->SetZ( this->GetZ() );
69 cloneObject->SetState( this->GetState() );
70 cloneObject->SetEditable( this->IsEditable() );
71 cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
72 cloneObject->SetMoving( this->IsMoving() );
73 cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
74 cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
77 // ----------------------------------------------------------------------------
78 void manualContourBaseControler::Configure() //virtual
82 // ----------------------------------------------------------------------------
83 bool manualContourBaseControler::OnChar()
85 if ( _vtkInteractorStyleBaseView!=NULL )
87 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
90 crea::wxVTKRenderWindowInteractor *_wxVTKiren;
91 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
92 _wxVTKiren->GetEventPosition(X, Y);
93 //int Z = GetZ(); // JPRx
95 if ((keyCode==8) || (keyCode==127))
98 if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
100 DeleteActualMousePoint(X,Y);
102 GetManualViewBaseContour()->Refresh();
103 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
111 GetManualViewBaseContour()->Refresh();
112 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
114 else if( !IsEditable() )
116 if ( keyCode == 'L' )
118 GetManualViewBaseContour()->MoveContour( -1, 0 );
119 SetKeyBoardMoving( true );
121 else if ( keyCode == 'R' )
123 GetManualViewBaseContour()->MoveContour( 1, 0 );
124 SetKeyBoardMoving( true );
126 else if ( keyCode == 'U' )
128 GetManualViewBaseContour()->MoveContour( 0, -1 );
129 SetKeyBoardMoving( true );
131 else if ( keyCode == 'D' )
133 GetManualViewBaseContour()->MoveContour( 0, 1 );
134 SetKeyBoardMoving( true );
136 else if ( keyCode == 'W' )//Diagonal left down
138 GetManualViewBaseContour()->MoveContour( -1, 1 );
139 SetKeyBoardMoving( true );
141 else if ( keyCode == 'Q' )//Diagonal left up
143 GetManualViewBaseContour()->MoveContour( -1, -1 );
144 SetKeyBoardMoving( true );
146 else if( keyCode == 'P' )//Diagonal right up
148 GetManualViewBaseContour()->MoveContour( 1, -1 );
149 SetKeyBoardMoving( true );
151 else if( keyCode == 'M' )//Diagonal right down
153 GetManualViewBaseContour()->MoveContour( 1, 1 );
154 SetKeyBoardMoving( true );
156 if( GetKeyBoardMoving() )
158 GetManualViewBaseContour()->Refresh();
159 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
166 // ----------------------------------------------------------------------------
167 bool manualContourBaseControler::OnMouseMove()
169 if ( _vtkInteractorStyleBaseView!=NULL)
172 crea::wxVTKRenderWindowInteractor *_wxVTKiren;
173 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
174 _wxVTKiren->GetEventPosition( X , Y );
176 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
177 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
183 // ----------------------------------------------------------------------------
184 bool manualContourBaseControler::OnLeftButtonDown()
186 SetKeyBoardMoving( false );
187 if ( _vtkInteractorStyleBaseView!=NULL )
190 crea::wxVTKRenderWindowInteractor *wxVTKiren;
191 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
192 wxVTKiren->GetEventPosition(X,Y);
198 // ----------------------------------------------------------------------------
199 bool manualContourBaseControler::OnLeftButtonUp()
201 if ( _vtkInteractorStyleBaseView!=NULL )
204 crea::wxVTKRenderWindowInteractor *wxVTKiren;
205 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
206 wxVTKiren->GetEventPosition(X,Y);
207 MouseReleaseLeft(X,Y);
211 // ----------------------------------------------------------------------------
212 bool manualContourBaseControler::OnLeftDClick()
214 if ( _vtkInteractorStyleBaseView!=NULL )
217 crea::wxVTKRenderWindowInteractor *wxVTKiren;
218 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
219 wxVTKiren->GetEventPosition(X,Y);
221 this->MouseDLeft(X,Y);
225 // ----------------------------------------------------------------------------
226 bool manualContourBaseControler::OnMiddleButtonDown()
228 // SetKeyBoardMoving( false );
229 if ( _vtkInteractorStyleBaseView!=NULL )
232 crea::wxVTKRenderWindowInteractor *wxVTKiren;
233 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
234 wxVTKiren->GetEventPosition(X,Y);
235 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
239 // ----------------------------------------------------------------------------
240 bool manualContourBaseControler::OnMiddleButtonUp()
244 // ----------------------------------------------------------------------------
245 bool manualContourBaseControler::OnRightButtonDown()
247 if( _vtkInteractorStyleBaseView!= NULL )
250 crea::wxVTKRenderWindowInteractor *wxVTKiren;
251 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
252 wxVTKiren->GetEventPosition(X, Y);
254 MouseClickRight(X,Y);
258 // ----------------------------------------------------------------------------
259 bool manualContourBaseControler::OnRightButtonUp()
263 // ----------------------------------------------------------------------------
264 void manualContourBaseControler::SetModelView(manualBaseModel *manContModel, manualViewBaseContour *manViewBaseCont){
265 _manContModel = manContModel;
266 _manViewBaseCont = manViewBaseCont;
267 _manViewBaseCont->SetEditable( &_editable );
269 // ----------------------------------------------------------------------------
270 manualBaseModel* manualContourBaseControler::GetManualContourModel()
272 return _manContModel;
274 // ----------------------------------------------------------------------------
275 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
277 return _manViewBaseCont;
279 // ----------------------------------------------------------------------------
280 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
284 // ----------------------------------------------------------------------------
285 void manualContourBaseControler::MouseClickRight(int x, int y)
287 SetCompleteCreation( true );
288 SetKeyBoardMoving( false );
289 this->GetManualContourModel()->SetCloseContour(true);
295 SetEditable( false );
296 SetPosibleToMove( false );
299 //EED 24Avril2009 _state=7;
301 // ----------------------------------------------------------------------------
302 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
304 if (_state==5){ _state = 0; }
305 if (_state==6){ _state = 0; }
306 if (_state==7){ _state = 0; }
308 GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
309 if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1) )
311 SetEditable( false );
312 SetPosibleToMove( false );
315 // ----------------------------------------------------------------------------
316 void manualContourBaseControler::MouseDLeft(int x, int y )
322 /*bool temp = */ _manViewBaseCont->SelectPosibleContour(x,y,z);
324 _manViewBaseCont->SelectPosiblePoint(x,y,z);
326 if ( _manViewBaseCont->GetPosibleSelected() )
332 // ----------------------------------------------------------------------------
333 void manualContourBaseControler::MouseMove(int x, int y) // virtual
336 // ----------------------------------------------------------------------------
337 void manualContourBaseControler::SetState(int state)
341 // ----------------------------------------------------------------------------
342 int manualContourBaseControler::GetState()
346 // ----------------------------------------------------------------------------
347 bool manualContourBaseControler::IsEditable( )
351 // ----------------------------------------------------------------------------
352 void manualContourBaseControler::SetEditable( bool condition )
354 if (GetManualViewBaseContour()!=NULL) {
357 GetManualViewBaseContour()->RemoveControlPoints();
359 GetManualViewBaseContour()->SetSelected( condition );
361 _editable = condition;
364 // ----------------------------------------------------------------------------
365 bool manualContourBaseControler::GetPosibleToMove()
367 return _posibleToMove;
369 // ----------------------------------------------------------------------------
370 void manualContourBaseControler::SetPosibleToMove( bool condition )
372 _posibleToMove = condition;
374 // ----------------------------------------------------------------------------
375 bool manualContourBaseControler::IsMoving()
379 // ----------------------------------------------------------------------------
380 void manualContourBaseControler::SetMoving( bool condition )
384 // ----------------------------------------------------------------------------
385 void manualContourBaseControler::SetCompleteCreation( bool condition )
387 _created = condition;
389 // ----------------------------------------------------------------------------
390 bool manualContourBaseControler::GetIfCompleteCreation ( )
394 // ----------------------------------------------------------------------------
395 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
397 _keyBoardMoving = condition;
399 // ----------------------------------------------------------------------------
400 bool manualContourBaseControler::GetKeyBoardMoving( )
402 return _keyBoardMoving;
404 // ----------------------------------------------------------------------------
405 void manualContourBaseControler::CreateNewManualContour(){
406 _manViewBaseCont->CreateNewContour();
408 // ----------------------------------------------------------------------------
409 int manualContourBaseControler::GetNumberOfPointsManualContour(){
410 return _manViewBaseCont->GetNumberOfPoints();
412 // ----------------------------------------------------------------------------
414 //JSTG - 25-02-08 -------------------------------------------------------------
415 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
416 //return _manViewBaseCont->GetNumberOfPointsSpline();
417 return _manContModel->GetNumberOfPointsSpline();
419 // ----------------------------------------------------------------------------
421 double* manualContourBaseControler::GetVectorPointsXManualContour(){
422 return _manViewBaseCont->GetVectorPointsXManualContour();
424 // ----------------------------------------------------------------------------
425 double* manualContourBaseControler::GetVectorPointsYManualContour(){
426 return _manViewBaseCont->GetVectorPointsYManualContour();
428 // ----------------------------------------------------------------------------
429 void manualContourBaseControler::DeleteContour(){
430 _manViewBaseCont->DeleteContour();
431 _manContModel->DeleteAllPoints();
433 // ----------------------------------------------------------------------------
434 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
436 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
438 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
439 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
440 _manContModel->DeletePoint(id);
441 _manViewBaseCont->DeletePoint(id);
447 // ----------------------------------------------------------------------------
448 void manualContourBaseControler::Magnet(int x, int y)
452 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
453 if (GetManualContourModel()!=NULL){
457 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
458 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
461 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
462 mp->SetPoint(xx,yy,zz);
464 // GetManualViewBaseContour()->UpdateViewPoint(id);
470 // ----------------------------------------------------------------------------
471 void manualContourBaseControler::SetZ(int z)
475 // ----------------------------------------------------------------------------
476 int manualContourBaseControler::GetZ()
480 // ----------------------------------------------------------------------------
481 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
483 if (GetManualContourModel()!=NULL){
488 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
489 GetManualContourModel()->AddPoint(xx,yy,zz);
490 GetManualViewBaseContour()->AddPoint();
491 // GetManualViewBaseContour()->UpdateViewPoint(id);
494 // ----------------------------------------------------------------------------
495 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
499 if (GetManualContourModel()!=NULL){
503 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
504 if (GetManualContourModel()->GetSizeLstPoints()>1){
505 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
506 GetManualViewBaseContour()->InsertPoint(id);
507 // GetManualViewBaseContour()->UpdateViewPoint(id);
509 GetManualContourModel()->AddPoint(xx,yy,zz);
510 GetManualViewBaseContour()->AddPoint();
512 // GetManualViewBaseContour()->UpdateViewPoint(id);
517 // ----------------------------------------------------------------------------
518 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
519 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
524 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
525 manualPoint *mp = _manContModel->GetManualPoint(id);
526 mp->SetPoint(xx,yy,zz);
527 GetManualViewBaseContour()->UpdateViewPoint(id);
530 // ----------------------------------------------------------------------------
531 void manualContourBaseControler::SetPointX( int id ,int x ){
532 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
536 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
537 manualPoint *mp = _manContModel->GetManualPoint(id);
539 GetManualViewBaseContour()->UpdateViewPoint(id);
542 // ----------------------------------------------------------------------------
543 void manualContourBaseControler::SetPointY( int id ,int y ){
544 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
548 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
549 manualPoint *mp = _manContModel->GetManualPoint(id);
551 GetManualViewBaseContour()->UpdateViewPoint(id);
554 // ----------------------------------------------------------------------------
555 void manualContourBaseControler::SetPointZ( int id ,int z ){
556 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
560 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
561 manualPoint *mp = _manContModel->GetManualPoint(id);
563 GetManualViewBaseContour()->UpdateViewPoint(id);
566 // ----------------------------------------------------------------------------
567 void manualContourBaseControler::ResetContour() // virtual
569 this->DeleteContour();
570 GetManualViewBaseContour()->CreateNewContour();