]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx
a1c234a00b5a20ed5d2b3a7ecc2aa3abae128bc6
[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                 int z=GetZ();
59                 GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
60                 GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
61                 if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
62                 if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
63                 if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
64                 {
65                         //GetManualViewBaseContour()->MoveContour(x,y,z);
66                 }
67                 if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
68                         GetManualViewBaseContour()->Refresh();
69                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
70                 }
71                 if (!IsEditable())
72                 {
73                         GetManualViewBaseContour()->RemoveControlPoints();
74                         GetManualViewBaseContour()->Refresh();
75                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
76                 }
77
78         }
79
80         //=========================================================================
81
82         void manualConnectorContourController::MouseClickRight(int x, int y)
83         {
84                 SetCompleteCreation( true );
85                 SetKeyBoardMoving( false );
86                 GetManualContourModel()->SetCloseContour(false);
87
88                 SetEditable( false );
89                 SetPosibleToMove( false );
90                 SetState(0);
91                 
92         }
93
94         //=========================================================================
95
96         void manualConnectorContourController::MouseClickLeft(int x, int y)
97         {
98
99                 bool ok = false;
100                 int z   = GetZ();
101                 int size= GetManualViewBaseContour()->GetNumberOfPoints();
102
103                 // Insert a Control Point with shift+ClickLeft
104                 vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
105                 if( IsEditable() )
106                 {
107                         if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) )
108                         {
109                                 ok=true;
110                                 InsertPoint(x,y,z);
111                                 size++;
112                         }
113                         // Start to Insert Control Points with ClickLeft (Empty contour)
114                         if ((GetState()==0) && (size==0) && (_easyCreation==true) )
115                         {
116                                 ok=true;
117                                 SetState(1);
118                                 GetManualContourModel()->SetCloseContour(false);
119                                 AddPoint(x,y,z);
120                         }
121
122                         // RaC Just create 2 points
123                         if ((GetState()==1) && (_easyCreation==true) && GetNumberOfPointsManualContour()==2)
124                         {
125                                 ok=true;
126                                 endContourCreation();
127                         }
128
129                         // Continue to Insert Control Points with ClickLeft (After being empty the contour)
130                         if ((GetState()==1) && (_easyCreation==true) )
131                         {
132                                 ok=true;
133                                 AddPoint(x,y,z);
134                                 _bakIdPoint=GetNumberOfPointsManualContour() - 1;
135                         }
136
137                         // Insert Control Points IF Contour si Selected
138                         if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
139                         {
140                                 ok=true;
141                                 InsertPoint(x,y,z);
142                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
143                                 SetState(6);
144                         }
145                         // Chose id of Control Point to be move
146                         if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
147                         {
148                                 ok=true;
149                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
150                                 if(_bakIdPoint!=0 && _bakIdPoint!=GetManualViewBaseContour()->GetNumberOfPoints()-1)
151                                 {
152                                         SetState(5);
153                                 }
154                         }
155                         // If nothing selected _state=7
156                         if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
157                         {
158                                 //ok=true;
159                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
160                                 SetState(7);
161                         }
162                 }else{
163                         SetPosibleToMove( true );
164                         GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
165                 } // IsEditable
166                 
167                 if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
168                 {
169                         SetMoving( true );
170                         ok=true;
171                         GetManualViewBaseContour()->InitMove(x,y,z);
172                         SetState(6);
173                 }
174                 if (ok==true)
175                 {
176                         GetManualViewBaseContour()->Refresh();
177                 }
178         }
179         
180         //=========================================================================
181         
182         void manualConnectorContourController::endContourCreation()
183         {
184                 SetCompleteCreation( true );
185                 SetKeyBoardMoving( false );
186                 GetManualContourModel()->SetCloseContour(false);
187
188                 SetEditable( false );
189                 SetPosibleToMove( false );
190                 SetState(0);
191         }
192
193
194         //=========================================================================
195
196 }  // EO namespace bbtk
197
198 // EOF
199