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