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