]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourControler.cpp
33665fb521d4844125a77f29b8aa448a3290b5af
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualContourControler.cpp
1 #include "manualContourControler.h"
2
3 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6
7 // _state = 0  // ..nothing..
8 // _state = 1  // move with add point
9 // _state = 5  // move
10 // _state = 6  // move with insert point
11 // _state = 7  // move with non selection
12
13 manualContourControler::manualContourControler()
14 {
15         _easyCreation = true;
16
17 }
18 // ----------------------------------------------------------------------------
19 manualContourControler::~manualContourControler()
20 {
21 }
22 // ----------------------------------------------------------------------------
23 manualContourControler * manualContourControler :: Clone()  // virtual
24 {
25         manualContourControler * clone = new manualContourControler();
26         CopyAttributesTo(clone);
27         return clone;
28 }
29 // ---------------------------------------------------------------------------
30 void manualContourControler::CopyAttributesTo( manualContourControler * cloneObject)
31 {
32         // Fathers object
33         manualContourBaseControler::CopyAttributesTo(cloneObject);
34         cloneObject->SetEasyCreation( this->GetEasyCreation() );
35 }
36
37 // ----------------------------------------------------------------------------
38 void manualContourControler::Configure() //virtual
39 {
40  //     this->_manContModel->SetNumberOfPointsSpline(100);
41 }
42
43 // ----------------------------------------------------------------------------
44 void manualContourControler::MouseClickLeft(int x, int y){
45
46         bool ok = false;
47         int z   = GetZ();
48         int size= GetManualViewBaseContour()->GetNumberOfPoints();
49
50         // Insert a Control Point with shift+ClickLeft
51         vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
52
53         if( IsEditable() )
54         {
55                 if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) )
56                 {
57                         ok=true;
58                         InsertPoint(x,y,z);
59                         size++;
60                 }
61                 // Start to Insert Control Points with ClickLeft (Empty contour)
62                 if ((GetState()==0) && (size==0) && (_easyCreation==true) )
63                 {
64                         ok=true;
65                         SetState(1);
66                         GetManualContourModel()->SetCloseContour(false);
67                         AddPoint(x,y,z);
68                 }
69                 // Continuie to Insert Control Points with ClickLeft (After being empty the contour)
70                 if ((GetState()==1) && (_easyCreation==true) )
71                 {
72                         ok=true;
73                         AddPoint(x,y,z);
74                         _bakIdPoint=GetNumberOfPointsManualContour() - 1;
75                 }
76                 // Insert Control Points IF Contour si Selected
77                 if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
78                 {
79                         ok=true;
80                         InsertPoint(x,y,z);
81                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
82                         SetState(6);
83                 }
84                 // Chose id of Control Point to be move
85                 if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
86                 {
87                         ok=true;
88                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
89                         SetState(5);
90                 }
91                 // If nothing selected _state=7
92                 if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
93                 {
94                         //ok=true;
95                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
96                         SetState(7);
97                 }
98         }else{
99                 SetPosibleToMove( true );
100                 GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
101         } // IsEditable
102         
103         if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
104         {
105                 SetMoving( true );
106                 ok=true;
107                 GetManualViewBaseContour()->InitMove(x,y,z);
108                 SetState(6);
109         }
110         if (ok==true)
111         {
112                 GetManualViewBaseContour()->Refresh();
113         }
114 }
115 // ----------------------------------------------------------------------------
116 void manualContourControler::MouseMove(int x, int y) // virtual
117 {
118         int z=GetZ();
119         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
120         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
121         if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
122         if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
123         if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
124         {
125                 GetManualViewBaseContour()->MoveContour(x,y,z);
126         }
127         if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
128                 GetManualViewBaseContour()->Refresh();
129                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
130         }
131         if (!IsEditable())
132         {
133                 GetManualViewBaseContour()->RemoveControlPoints();
134 //              GetManualViewBaseContour()->RemoveTextActor();
135                 GetManualViewBaseContour()->Refresh();
136                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
137         }
138
139 }
140
141 // ----------------------------------------------------------------------------
142 void manualContourControler::MouseDLeft( int x, int y)//virtual
143 {
144         manualContourBaseControler::MouseDLeft( x, y);
145         if ( IsEditable() )
146         {
147                 
148                 GetManualViewBaseContour()->AddControlPoints();
149                 GetManualViewBaseContour()->AddTextActor();
150                 GetManualViewBaseContour()->Refresh();
151                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
152         }
153 }
154 // ----------------------------------------------------------------------------
155 void manualContourControler::SetEasyCreation(bool easyCreation)
156 {
157         _easyCreation=easyCreation;
158 }
159 // ----------------------------------------------------------------------------
160 bool manualContourControler::GetEasyCreation()
161 {
162         return _easyCreation;
163 }
164