]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx
v1.1.0 BUG: 1400
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsVtkGUIEditorGraphic / manualConnectorContourController.cxx
1 /*=========================================================================                                                                               
2 Program:   bbtk
3 Module:    $RCSfile$
4 Language:  C++
5 Date:      $Date$
6 Version:   $Revision$
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32 *  \file 
33 *  \brief Class bbtk::manualConnectorContourController 
34 */
35
36
37 #include "manualConnectorContourController.h"
38
39 namespace bbtk
40 {
41
42
43         //=========================================================================
44         manualConnectorContourController::manualConnectorContourController()
45         {               
46         }
47
48         //=========================================================================
49         
50         manualConnectorContourController::~manualConnectorContourController()
51         {
52         }
53
54         //=========================================================================
55
56         void manualConnectorContourController::MouseMove(int x, int y) // virtual
57         {
58                 
59                 int z=GetZ();
60                                 
61                 printf("EED MACHETE con int z=-GetZ(); en manualConnectorContourController::MouseMove z=%d\n", z );
62                 z=-z;
63                 
64                 GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
65                 GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
66                 if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
67                 if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
68                 if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
69                 {
70                         //GetManualViewBaseContour()->MoveContour(x,y,z);
71                 }
72                 if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
73                         GetManualViewBaseContour()->Refresh();
74                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
75                 }
76                 if (!IsEditable())
77                 {
78                         GetManualViewBaseContour()->RemoveControlPoints();
79                         GetManualViewBaseContour()->Refresh();
80                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
81                 }
82
83         }
84
85         //=========================================================================
86
87         void manualConnectorContourController::MouseClickRight(int x, int y)
88         {
89                 SetCompleteCreation( true );
90                 SetKeyBoardMoving( false );
91                 GetManualContourModel()->SetCloseContour(false);
92
93                 SetEditable( false );
94                 SetPosibleToMove( false );
95                 SetState(0);
96                 
97         }
98
99         //=========================================================================
100
101         void manualConnectorContourController::MouseClickLeft(int x, int y)
102         {
103
104                 bool ok = false;
105                 int z   = -GetZ();
106                 int size= GetManualViewBaseContour()->GetNumberOfPoints();
107
108                 
109                 printf("\nEED manualConnectorContourController::MouseClickLeft   z=%d   estado=%d\n", z,GetState());
110                 if (IsEditable())
111                 {
112                         printf(" Editable\n");
113                 } else          {
114                         printf(" NO Editable\n");
115                 }
116                 
117                  
118                 if (GetManualViewBaseContour()->GetPosibleSelected())
119                 {
120                         printf(" PosibleSelected\n");
121                 } else          {
122                         printf(" NO PosibleSelected\n");
123                 }
124                 
125                 
126                 // Insert a Control Point with shift+ClickLeft
127                 vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
128                 if( IsEditable() )
129                 {
130                         if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) )
131                         {
132                                 ok=true;
133                                 InsertPoint(x,y,z);
134                                 size++;
135                         }
136                         // Start to Insert Control Points with ClickLeft (Empty contour)
137                         if ((GetState()==0) && (size==0) && (_easyCreation==true) )
138                         {
139                                 ok=true;
140                                 SetState(1);
141                                 GetManualContourModel()->SetCloseContour(false);
142                                 AddPoint(x,y,z);
143                         }
144
145                         // RaC Just create 2 points
146                         if ((GetState()==1) && (_easyCreation==true) && GetNumberOfPointsManualContour()==2)
147                         {
148                                 ok=true;
149                                 endContourCreation();
150                         }
151
152                         // Continue to Insert Control Points with ClickLeft (After being empty the contour)
153                         if ((GetState()==1) && (_easyCreation==true) )
154                         {
155                                 ok=true;
156                                 AddPoint(x,y,z);
157                                 _bakIdPoint=GetNumberOfPointsManualContour() - 1;
158                         }
159
160                         // Insert Control Points IF Contour si Selected
161                         if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
162                         {
163                                 ok=true;
164                                 InsertPoint(x,y,z);
165                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
166                                 SetState(6);
167                         }
168                         // Chose id of Control Point to be move
169                         if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
170                         {
171                                 ok=true;
172                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
173                                 if(_bakIdPoint!=0 && _bakIdPoint!=GetManualViewBaseContour()->GetNumberOfPoints()-1)
174                                 {
175                                         SetState(5);
176                                 }
177                         }
178                         // If nothing selected _state=7
179                         if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
180                         {
181                                 //ok=true;
182                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
183                                 SetState(7);
184                         }
185                 }else{
186                         SetPosibleToMove( true );
187                         GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
188                 } // IsEditable
189                 
190                 if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
191                 {
192                         SetMoving( true );
193                         ok=true;
194                         GetManualViewBaseContour()->InitMove(x,y,z);
195                         SetState(6);
196                 }
197                 
198                 if (ok==true)
199                 {
200                         GetManualViewBaseContour()->Refresh();
201                 }// ok
202                 
203         }
204         
205         //=========================================================================
206         
207         void manualConnectorContourController::endContourCreation()
208         {
209                 SetCompleteCreation( true );
210                 SetKeyBoardMoving( false );
211                 GetManualContourModel()->SetCloseContour(false);
212
213                 SetEditable( false );
214                 SetPosibleToMove( false );
215                 SetState(0);
216         }
217
218
219         //=========================================================================
220
221 }  // EO namespace bbtk
222
223 // EOF
224