]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourControler.cpp
#2989 creaMaracasVisu Bug New Normal - ManualContourModel duplicate last point...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualContourControler.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "manualContourControler.h"
27
28 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31
32 // _state = 0  // ..nothing..
33 // _state = 1  // move with add point
34 // _state = 5  // move
35 // _state = 6  // move with insert point
36 // _state = 7  // move with non selection
37
38 manualContourControler::manualContourControler()
39 {
40         _easyCreation = true;
41
42 }
43 // ----------------------------------------------------------------------------
44 manualContourControler::~manualContourControler()
45 {
46 }
47 // ----------------------------------------------------------------------------
48 manualContourControler * manualContourControler :: Clone()  // virtual
49 {
50         manualContourControler * clone = new manualContourControler();
51         CopyAttributesTo(clone);
52         return clone;
53 }
54 // ---------------------------------------------------------------------------
55 void manualContourControler::CopyAttributesTo( manualContourControler * cloneObject)
56 {
57         // Fathers object
58         manualContourBaseControler::CopyAttributesTo(cloneObject);
59         cloneObject->SetEasyCreation( this->GetEasyCreation() );
60 }
61
62 // ----------------------------------------------------------------------------
63 void manualContourControler::Configure() //virtual
64 {
65  //     this->_manContModel->SetNumberOfPointsSpline(100);
66 }
67
68 // ----------------------------------------------------------------------------
69 void manualContourControler::MouseClickLeft(int x, int y)
70 {
71
72         bool ok = false;
73         int z   = GetZ();
74         int size= GetManualViewBaseContour()->GetNumberOfPoints();
75
76         // Insert a Control Point with shift+ClickLeft
77         vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
78
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                 // Continuie to Insert Control Points with ClickLeft (After being empty the contour)
96                 if ((GetState()==1) && (_easyCreation==true) )
97                 {
98                         ok=true;
99                         AddPoint(x,y,z);
100                         _bakIdPoint=GetNumberOfPointsManualContour() - 1;
101                 }
102                 // Insert Control Points IF Contour si Selected
103                 if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
104                 {
105                         ok=true;
106                         InsertPoint(x,y,z);
107                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
108                         SetState(6);
109                 }
110                 // Chose id of Control Point to be move
111                 if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
112                 {
113                         ok=true;
114                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
115                         SetState(5);
116                 }
117                 // If nothing selected _state=7
118                 if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
119                 {
120                         //ok=true;
121                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
122                         SetState(7);
123                 }
124         }else{
125                 SetPosibleToMove( true );
126                 GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
127         } // IsEditable
128
129         if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
130         {
131                 SetMoving( true );
132                 ok=true;
133                 GetManualViewBaseContour()->InitMove(x,y,z);
134                 SetState(6);
135         }
136         if (ok==true)
137         {
138                 GetManualViewBaseContour()->Refresh();
139         }
140 }
141 // ----------------------------------------------------------------------------
142 void manualContourControler::MouseMove(int x, int y) // virtual
143 {
144         int z=GetZ();
145         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
146         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
147         if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
148         if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
149         if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
150         {
151                 GetManualViewBaseContour()->MoveContour(x,y,z);
152         }
153         if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
154                 GetManualViewBaseContour()->Refresh();
155                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
156         }
157         if (!IsEditable())
158         {
159                 GetManualViewBaseContour()->RemoveControlPoints();
160 //              GetManualViewBaseContour()->RemoveTextActor();
161                 GetManualViewBaseContour()->Refresh();
162                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
163         }
164
165 }
166
167 // ----------------------------------------------------------------------------
168 void manualContourControler::MouseDLeft( int x, int y)//virtual
169 {
170         manualContourBaseControler::MouseDLeft( x, y);
171         if ( IsEditable() )
172         {
173
174                 GetManualViewBaseContour()->AddControlPoints();
175                 GetManualViewBaseContour()->AddTextActor();
176                 GetManualViewBaseContour()->Refresh();
177                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
178         }
179 }
180 // ----------------------------------------------------------------------------
181 void manualContourControler::SetEasyCreation(bool easyCreation)
182 {
183         _easyCreation=easyCreation;
184 }
185 // ----------------------------------------------------------------------------
186 bool manualContourControler::GetEasyCreation()
187 {
188         return _easyCreation;
189 }
190