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