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 )
321 /*bool temp = */ _manViewBaseCont->SelectPosibleContour(x,y,z);
322 _manViewBaseCont->SelectPosiblePoint(x,y,z);
323 if ( _manViewBaseCont->GetPosibleSelected() )
329 // ----------------------------------------------------------------------------
330 void manualContourBaseControler::MouseMove(int x, int y) // virtual
333 // ----------------------------------------------------------------------------
334 void manualContourBaseControler::SetState(int state)
338 // ----------------------------------------------------------------------------
339 int manualContourBaseControler::GetState()
343 // ----------------------------------------------------------------------------
344 bool manualContourBaseControler::IsEditable( )
348 // ----------------------------------------------------------------------------
349 void manualContourBaseControler::SetEditable( bool condition )
351 if (GetManualViewBaseContour()!=NULL) {
354 GetManualViewBaseContour()->RemoveControlPoints();
356 GetManualViewBaseContour()->SetSelected( condition );
358 _editable = condition;
361 // ----------------------------------------------------------------------------
362 bool manualContourBaseControler::GetPosibleToMove()
364 return _posibleToMove;
366 // ----------------------------------------------------------------------------
367 void manualContourBaseControler::SetPosibleToMove( bool condition )
369 _posibleToMove = condition;
371 // ----------------------------------------------------------------------------
372 bool manualContourBaseControler::IsMoving()
376 // ----------------------------------------------------------------------------
377 void manualContourBaseControler::SetMoving( bool condition )
381 // ----------------------------------------------------------------------------
382 void manualContourBaseControler::SetCompleteCreation( bool condition )
384 _created = condition;
386 // ----------------------------------------------------------------------------
387 bool manualContourBaseControler::GetIfCompleteCreation ( )
391 // ----------------------------------------------------------------------------
392 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
394 _keyBoardMoving = condition;
396 // ----------------------------------------------------------------------------
397 bool manualContourBaseControler::GetKeyBoardMoving( )
399 return _keyBoardMoving;
401 // ----------------------------------------------------------------------------
402 void manualContourBaseControler::CreateNewManualContour(){
403 _manViewBaseCont->CreateNewContour();
405 // ----------------------------------------------------------------------------
406 int manualContourBaseControler::GetNumberOfPointsManualContour(){
407 return _manViewBaseCont->GetNumberOfPoints();
409 // ----------------------------------------------------------------------------
411 //JSTG - 25-02-08 -------------------------------------------------------------
412 int manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
413 //return _manViewBaseCont->GetNumberOfPointsSpline();
414 return _manContModel->GetNumberOfPointsSpline();
416 // ----------------------------------------------------------------------------
418 double* manualContourBaseControler::GetVectorPointsXManualContour(){
419 return _manViewBaseCont->GetVectorPointsXManualContour();
421 // ----------------------------------------------------------------------------
422 double* manualContourBaseControler::GetVectorPointsYManualContour(){
423 return _manViewBaseCont->GetVectorPointsYManualContour();
425 // ----------------------------------------------------------------------------
426 void manualContourBaseControler::DeleteContour(){
427 _manViewBaseCont->DeleteContour();
428 _manContModel->DeleteAllPoints();
430 // ----------------------------------------------------------------------------
431 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
433 if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
435 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
436 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
437 _manContModel->DeletePoint(id);
438 _manViewBaseCont->DeletePoint(id);
444 // ----------------------------------------------------------------------------
445 void manualContourBaseControler::Magnet(int x, int y)
449 /*int id= */ _manViewBaseCont->GetIdPoint(x,y,GetZ()); // JPRx
450 if (GetManualContourModel()!=NULL){
454 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
455 int id = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
458 manualPoint *mp = GetManualContourModel()->GetManualPoint(id);
459 mp->SetPoint(xx,yy,zz);
461 // GetManualViewBaseContour()->UpdateViewPoint(id);
467 // ----------------------------------------------------------------------------
468 void manualContourBaseControler::SetZ(int z)
472 // ----------------------------------------------------------------------------
473 int manualContourBaseControler::GetZ()
477 // ----------------------------------------------------------------------------
478 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
480 if (GetManualContourModel()!=NULL){
485 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
486 GetManualContourModel()->AddPoint(xx,yy,zz);
487 GetManualViewBaseContour()->AddPoint();
488 // GetManualViewBaseContour()->UpdateViewPoint(id);
491 // ----------------------------------------------------------------------------
492 void manualContourBaseControler::InsertPoint(int x,int y,int z) // virtual
496 if (GetManualContourModel()!=NULL){
500 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
501 if (GetManualContourModel()->GetSizeLstPoints()>1){
502 id = GetManualContourModel()->InsertPoint(xx,yy,zz);
503 GetManualViewBaseContour()->InsertPoint(id);
504 // GetManualViewBaseContour()->UpdateViewPoint(id);
506 GetManualContourModel()->AddPoint(xx,yy,zz);
507 GetManualViewBaseContour()->AddPoint();
509 // GetManualViewBaseContour()->UpdateViewPoint(id);
514 // ----------------------------------------------------------------------------
515 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
516 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
521 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
522 manualPoint *mp = _manContModel->GetManualPoint(id);
523 mp->SetPoint(xx,yy,zz);
524 GetManualViewBaseContour()->UpdateViewPoint(id);
527 // ----------------------------------------------------------------------------
528 void manualContourBaseControler::SetPointX( int id ,int x ){
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::SetPointY( int id ,int y ){
541 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
545 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
546 manualPoint *mp = _manContModel->GetManualPoint(id);
548 GetManualViewBaseContour()->UpdateViewPoint(id);
551 // ----------------------------------------------------------------------------
552 void manualContourBaseControler::SetPointZ( int id ,int z ){
553 if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
557 GetManualViewBaseContour()->TransfromCoordViewWorld(xx,yy,zz);
558 manualPoint *mp = _manContModel->GetManualPoint(id);
560 GetManualViewBaseContour()->UpdateViewPoint(id);
563 // ----------------------------------------------------------------------------
564 void manualContourBaseControler::ResetContour() // virtual
566 this->DeleteContour();
567 GetManualViewBaseContour()->CreateNewContour();