]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewContour.cpp
no message
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewContour.cpp
1 #include "manualViewContour.h"
2
3 // ----------------------------------------------------------------------------
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6
7 manualViewContour::manualViewContour()
8 {
9         _id_viewPoint_for_text  =       0;
10         _mesureScale                    =       1;
11         _initialConoturModel = new manualContourModel();
12 }
13 // ----------------------------------------------------------------------------
14 manualViewContour::~manualViewContour()
15 {
16         delete _initialConoturModel;
17 }
18 // ----------------------------------------------------------------------------
19
20 // ----------------------------------------------------------------------------
21 manualViewContour * manualViewContour :: Clone()
22 {
23         manualViewContour * clone = new manualViewContour();
24         CopyAttributesTo(clone);
25         return clone;
26 }
27
28 // ---------------------------------------------------------------------------
29
30 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
31 {
32         // Call to Fathers object
33         manualViewBaseContour::CopyAttributesTo(cloneObject);
34
35         cloneObject->SetMesureScale(_mesureScale);
36 }
37
38 // ---------------------------------------------------------------------------
39
40 int manualViewContour::GetType() // virtual
41 {
42         return 1;
43 }
44
45 // ----------------------------------------------------------------------------
46
47 void manualViewContour::Save(FILE *pFile)
48 {
49         manualViewBaseContour::Save(pFile);
50 }
51
52 // ----------------------------------------------------------------------------
53
54 void manualViewContour::Open(FILE *pFile)
55 {
56 }
57
58
59
60 // ----------------------------------------------------------------------------
61 void manualViewContour::RefreshContour() // virtual
62 {
63
64         int i,np,nps;
65
66 //JSTG 25-02-08 --------------------
67         //double t,delta, x,y,z;
68         double x,y,z;
69 //----------------------------------
70
71         _manContModel->UpdateSpline();
72     np  = GetNumberOfPoints( );
73         //nps = GetNumberOfPointsSpline();
74     nps = _manContModel->GetNumberOfPointsSpline();
75         //delta=( double ) ( np  ) / ( double ) ( nps-1  );             //JSTG 25-02-08
76
77
78         if ( _pts!=NULL )
79         {
80                 if (np>=2  )
81                 {
82                         for( i = 0; i < nps; i++ )
83                         {
84 //JSTG 25-02-08 ------------------------------------------------
85                                 //t = delta * (double)i;
86                                 //_manContModel->GetSplinePoint(t,x,y,z);
87                                 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
88 //--------------------------------------------------------------
89         // EED 27 sep 2006
90         //                      _pts->SetPoint(i, x,y,z );
91                                 _pts->SetPoint(i , x*_spc[0] , y*_spc[1] , z*_spc[2] );
92
93
94                         }// for
95                 }
96                 else
97                 {
98                                 _pts->SetPoint(0, 0 , 0 , 0);
99                                 _pts->SetPoint(1, 0 , 0 , 0);
100                 } // if
101         }
102 }
103
104 // ----------------------------------------------------------------------------
105 void manualViewContour::RefreshText()  // virtual
106 {
107         if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
108                 int size = GetNumberOfPoints();
109                 char text[50];
110                 char resultText[50];
111                 strcpy(resultText," ");
112                 if (size==2)
113                 {
114                         strcpy(resultText,"L= ");
115                         gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
116                         strcat(resultText,text);
117                 }
118                 if (size>2)
119                 {
120                         if (_manContModel->IfCloseContour()==true)
121                         {
122                                 strcpy(resultText,"P= ");
123                                 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
124                                 strcat(resultText,text);
125                                 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea() , 5, text );
126                                 strcat(resultText,"   A= ");
127                                 strcat(resultText,text);
128                         } else {
129                                 strcpy(resultText,"L= ");
130                                 gcvt (  _mesureScale * this->_manContModel->GetPathSize() , 5, text );
131                                 strcat(resultText,text);
132                         }
133                 }
134
135                 _textActor->SetInput(resultText);
136                 
137                 if (size>=1){
138
139                         int i;
140                         for (i=0; i<size; i++)
141                         {
142                                 if (_lstViewPoints[i]->GetPosibleSelected()==true)
143                                 {
144                                         _id_viewPoint_for_text = i;
145                                 }
146                         }
147
148                         int id = _id_viewPoint_for_text;
149                         double px = _manContModel->GetManualPoint(id)->GetX();
150                         double py = _manContModel->GetManualPoint(id)->GetY();
151
152                         //EED 27 sep 2006
153                         px=px*_spc[0];
154                         py=py*_spc[1];
155
156                         _textActor->SetPosition(px+GetRange()+1,py);
157                 }
158
159         }
160 }
161
162 // ----------------------------------------------------------------------------
163 bool manualViewContour::ifTouchContour(int x,int y,int z){
164         
165         bool result=false;
166         double xx=x;
167         double yy=y;
168         double zz=z;
169         double ppA[3];
170         double ppB[3];
171         double d1,d2,d3;
172         TransfromCoordViewWorld(xx,yy,zz);
173
174 //EED 27 sep 2006
175         xx = xx * _spc[0];
176         yy = yy * _spc[1];
177         zz = zz * _spc[2];
178
179     unsigned int i, nps,nps_t;
180     nps   = _sizePointsContour;
181         
182         if (this->_manContModel->IfCloseContour()==true)
183         {
184                 nps_t = nps;
185         } else {
186                 nps_t = nps-1;
187         }
188
189         
190         for( i = 0; i < nps_t; i++ ) 
191         {
192                 _pts->GetPoint(i%nps, ppA);
193                 _pts->GetPoint((i+1)%nps, ppB);
194                 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
195                 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
196                 d3= sqrt( (ppB[0]-ppA[0])*(ppB[0]-ppA[0]) + (ppB[1]-ppA[1])*(ppB[1]-ppA[1]) + (ppB[2]-ppA[2])*(ppB[2]-ppA[2]));
197
198                 if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) 
199                 {
200                         result=true;
201                         i=nps;
202                 } 
203                 
204                 //EED 25 Sep 2009
205                 if ((d1<=1) || (d2<=1))
206                 {
207                         result=true;
208                         i=nps;
209                 }
210                 
211         }
212         
213         return result;
214 }
215
216 // ----------------------------------------------------------------------------
217 void manualViewContour::DeletePoint(int id) // virtual
218 {
219         if (_lstViewPoints.size()>2)
220         {
221                 manualViewBaseContour::DeletePoint( id );
222         }
223 }
224 // ----------------------------------------------------------------------------
225
226 void manualViewContour::ClearPoint(int id)
227 {
228         manualViewBaseContour::DeletePoint( id );
229 }
230
231 //-------------------------------------------------------------------
232 void manualViewContour::SetMesureScale(double mesureScale)
233 {
234         _mesureScale = mesureScale;
235 }
236 //-------------------------------------------------------------------
237 void manualViewContour::InitMove(int x, int y, int z)
238 {
239         _initialConoturModel->DeleteAllPoints();
240
241         manualPoint *mp = NULL;
242         double XX=x;
243         double YY=y;
244         double ZZ=z;
245         TransfromCoordViewWorld(XX,YY,ZZ);
246
247         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
248         for ( i=0; i<manualPointsSZ; i++ )
249         {
250                 mp = _manContModel->GetManualPoint( i );
251                 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
252         }
253 }
254 //-------------------------------------------------------------------
255 void manualViewContour::MoveContour(int x, int y, int z)
256 {
257         manualPoint *mpOrigin = NULL;
258         manualPoint *mpMoving = NULL;
259         double XX=x;
260         double YY=y;
261         double ZZ=z;
262
263         TransfromCoordViewWorld(XX,YY,ZZ);
264
265         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
266         for ( i=0; i<manualPointsSZ; i++ )
267         {
268                 mpOrigin = _manContModel->GetManualPoint( i );
269                 mpMoving = _initialConoturModel->GetManualPoint(i);
270                 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
271         }
272         UpdateViewPoints();
273 }
274 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
275 {
276         manualPoint *mpOrigin = NULL;
277
278         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
279         for ( i=0; i<manualPointsSZ; i++ )
280         {
281                 mpOrigin = _manContModel->GetManualPoint( i );
282                 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
283         }
284         UpdateViewPoints();
285 }