]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourControler.cpp
creaButtonContainer & creaPanelButtonContainer: Updates in doxygen documentation...
[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
47         bool ok = false;
48         int z   = GetZ();
49         int size= GetManualViewBaseContour()->GetNumberOfPoints();
50
51         // Insert a Control Point with shift+ClickLeft
52         vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
53
54         if( IsEditable() )
55         {
56                 if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) )
57                 {
58                         ok=true;
59                         InsertPoint(x,y,z);
60                         size++;
61                 }
62                 // Start to Insert Control Points with ClickLeft (Empty contour)
63                 if ((GetState()==0) && (size==0) && (_easyCreation==true) )
64                 {
65                         ok=true;
66                         SetState(1);
67                         GetManualContourModel()->SetCloseContour(false);
68                         AddPoint(x,y,z);
69                 }
70                 // Continuie to Insert Control Points with ClickLeft (After being empty the contour)
71                 if ((GetState()==1) && (_easyCreation==true) )
72                 {
73                         ok=true;
74                         AddPoint(x,y,z);
75                         _bakIdPoint=GetNumberOfPointsManualContour() - 1;
76                 }
77                 // Insert Control Points IF Contour si Selected
78                 if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )
79                 {
80                         ok=true;
81                         InsertPoint(x,y,z);
82                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
83                         SetState(6);
84                 }
85                 // Chose id of Control Point to be move
86                 if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
87                 {
88                         ok=true;
89                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
90                         SetState(5);
91                 }
92                 // If nothing selected _state=7
93                 if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
94                 {
95                         //ok=true;
96                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
97                         SetState(7);
98                 }
99         }else{
100                 SetPosibleToMove( true );
101                 GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
102         } // IsEditable
103
104         if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
105         {
106                 SetMoving( true );
107                 ok=true;
108                 GetManualViewBaseContour()->InitMove(x,y,z);
109                 SetState(6);
110         }
111         if (ok==true)
112         {
113                 GetManualViewBaseContour()->Refresh();
114         }
115 }
116 // ----------------------------------------------------------------------------
117 void manualContourControler::MouseMove(int x, int y) // virtual
118 {
119         int z=GetZ();
120         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
121         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
122         if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
123         if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
124         if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
125         {
126                 GetManualViewBaseContour()->MoveContour(x,y,z);
127         }
128         if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
129                 GetManualViewBaseContour()->Refresh();
130                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
131         }
132         if (!IsEditable())
133         {
134                 GetManualViewBaseContour()->RemoveControlPoints();
135 //              GetManualViewBaseContour()->RemoveTextActor();
136                 GetManualViewBaseContour()->Refresh();
137                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
138         }
139
140 }
141
142 // ----------------------------------------------------------------------------
143 void manualContourControler::MouseDLeft( int x, int y)//virtual
144 {
145         manualContourBaseControler::MouseDLeft( x, y);
146         if ( IsEditable() )
147         {
148
149                 GetManualViewBaseContour()->AddControlPoints();
150                 GetManualViewBaseContour()->AddTextActor();
151                 GetManualViewBaseContour()->Refresh();
152                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
153         }
154 }
155 // ----------------------------------------------------------------------------
156 void manualContourControler::SetEasyCreation(bool easyCreation)
157 {
158         _easyCreation=easyCreation;
159 }
160 // ----------------------------------------------------------------------------
161 bool manualContourControler::GetEasyCreation()
162 {
163         return _easyCreation;
164 }
165