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