]> Creatis software - bbtkGEditor.git/blob - lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/manualConnectorContourController.cxx
0a352646e70a6e3d9d6a279def8c2232808c94fa
[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         manualConnectorContourController::~manualConnectorContourController()
50         {
51         }
52         //=========================================================================
53
54         void manualConnectorContourController::MouseClickRight(int x, int y)
55         {
56                 SetCompleteCreation( true );
57                 SetKeyBoardMoving( false );
58                 GetManualContourModel()->SetCloseContour(false);
59
60                 SetEditable( false );
61                 SetPosibleToMove( false );
62                 SetState(0);
63
64                 if(!_created)
65                 {
66                         //DeleteContour();
67                 }
68         }
69
70         //=========================================================================
71         void manualConnectorContourController::MouseClickLeft(int x, int y){
72
73                 bool ok = false;
74                 int z   = GetZ();
75                 int size= GetManualViewBaseContour()->GetNumberOfPoints();
76
77                 // Insert a Control Point with shift+ClickLeft
78                 vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
79                 if( IsEditable() )
80                 {
81                         if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) )
82                         {
83                                 ok=true;
84                                 InsertPoint(x,y,z);
85                                 size++;
86                         }
87                         // Start to Insert Control Points with ClickLeft (Empty contour)
88                         if ((GetState()==0) && (size==0) && (_easyCreation==true) )
89                         {
90                                 ok=true;
91                                 SetState(1);
92                                 GetManualContourModel()->SetCloseContour(false);
93                                 AddPoint(x,y,z);
94                         }
95
96                         // RaC Just create 2 points
97                         if ((GetState()==1) && (_easyCreation==true) && GetNumberOfPointsManualContour()==2)
98                         {
99                                 ok=true;
100
101                                 SetCompleteCreation( true );
102                                 SetKeyBoardMoving( false );
103                                 GetManualContourModel()->SetCloseContour(false);
104
105                                 SetEditable( false );
106                                 SetPosibleToMove( false );
107                                 SetState(0);
108                         }
109
110                         // Continue to Insert Control Points with ClickLeft (After being empty the contour)
111                         if ((GetState()==1) && (_easyCreation==true) )
112                         {
113                                 ok=true;
114                                 AddPoint(x,y,z);
115                                 _bakIdPoint=GetNumberOfPointsManualContour() - 1;
116                         }
117
118                         // Insert Control Points IF Contour si Selected
119                         if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
120                         {
121                                 ok=true;
122                                 InsertPoint(x,y,z);
123                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
124                                 SetState(6);
125                         }
126                         // Chose id of Control Point to be move
127                         if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
128                         {
129                                 ok=true;
130                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
131                                 if(_bakIdPoint!=0 && _bakIdPoint!=GetManualViewBaseContour()->GetNumberOfPoints()-1)
132                                 {
133                                         SetState(5);
134                                 }
135                         }
136                         // If nothing selected _state=7
137                         if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
138                         {
139                                 //ok=true;
140                                 _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
141                                 SetState(7);
142                         }
143                 }else{
144                         SetPosibleToMove( true );
145                         GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
146                 } // IsEditable
147                 
148                 if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
149                 {
150                         SetMoving( true );
151                         ok=true;
152                         GetManualViewBaseContour()->InitMove(x,y,z);
153                         SetState(6);
154                 }
155                 if (ok==true)
156                 {
157                         GetManualViewBaseContour()->Refresh();
158                 }
159         }
160         //=========================================================================
161
162 }  // EO namespace bbtk
163
164 // EOF
165