]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewContour.cpp
Insert a space before contour label at display time
[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
113 //CMRU 19-08-09 ----------------------------------
114                 std::string label;
115                 label = _manContModel->GetLabel();
116 // ------------------------------------
117
118                 if (size==2)
119                 {
120                         strcpy(resultText,"L= ");
121                         gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
122                         strcat(resultText,text);
123
124 //CMRU 19-08-09 ----------------------------------
125                         strcat(resultText," ");
126                         strcat(resultText,label.c_str());
127 //------------------------------------------------
128                 }
129                 if (size>2)
130                 {
131                         if (_manContModel->IfCloseContour()==true)
132                         {
133                                 strcpy(resultText,"P= ");
134                                 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
135                                 strcat(resultText,text);
136                                 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea() , 5, text );
137                                 strcat(resultText,"   A= ");
138                                 strcat(resultText,text);
139                                 strcat(resultText," ");
140                         } else {
141                                 strcpy(resultText,"L= ");
142                                 gcvt (  _mesureScale * this->_manContModel->GetPathSize() , 5, text );
143                                 strcat(resultText,text);
144                         }
145 //CMRU 19-08-09 ----------------------------------
146                         strcat(resultText,label.c_str());
147 //------------------------------------------------
148                 }
149
150                 _textActor->SetInput(resultText);
151                 
152                 if (size>=1){
153
154                         int i;
155                         for (i=0; i<size; i++)
156                         {
157                                 if (_lstViewPoints[i]->GetPosibleSelected()==true)
158                                 {
159                                         _id_viewPoint_for_text = i;
160                                 }
161                         }
162
163                         if (_id_viewPoint_for_text>=size) 
164                         {
165                                 _id_viewPoint_for_text=0;
166                         }
167                         
168                         double px = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetX();
169                         double py = _manContModel->GetManualPoint(_id_viewPoint_for_text)->GetY();
170
171                         //EED 27 sep 2006
172                         px=px*_spc[0];
173                         py=py*_spc[1];
174
175                         _textActor->SetPosition(px+GetRange()+1,py);
176                 }
177
178         }
179 }
180
181 // ----------------------------------------------------------------------------
182 bool manualViewContour::ifTouchContour(int x,int y,int z){
183         bool result=false;
184         double xx=x;
185         double yy=y;
186         double zz=z;
187         double ppA[3];
188         double ppB[3];
189         double d1,d2,d3;
190         TransfromCoordViewWorld(xx,yy,zz);
191
192 //EED 27 sep 2006
193         xx = xx * _spc[0];
194         yy = yy * _spc[1];
195         zz = zz * _spc[2];
196
197     unsigned int i, nps,nps_t;
198     nps   = _sizePointsContour;
199         
200         if (this->_manContModel->IfCloseContour()==true)
201         {
202                 nps_t = nps;
203         } else {
204                 nps_t = nps-1;
205         }
206
207         
208         for( i = 0; i < nps_t; i++ ) 
209         {
210                 _pts->GetPoint(i%nps, ppA);
211                 _pts->GetPoint((i+1)%nps, ppB);
212                 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
213                 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
214                 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]));
215
216
217                 if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) 
218                 {
219                         result=true;
220                         i=nps;
221                 }
222         }
223         
224         return result;
225 }
226
227 // ----------------------------------------------------------------------------
228 void manualViewContour::DeletePoint(int id) // virtual
229 {
230         if (_lstViewPoints.size()>2)
231         {
232                 manualViewBaseContour::DeletePoint( id );
233         }
234 }
235 // ----------------------------------------------------------------------------
236
237 void manualViewContour::ClearPoint(int id)
238 {
239         manualViewBaseContour::DeletePoint( id );
240 }
241
242 //-------------------------------------------------------------------
243 void manualViewContour::SetMesureScale(double mesureScale)
244 {
245         _mesureScale = mesureScale;
246 }
247 //-------------------------------------------------------------------
248 void manualViewContour::InitMove(int x, int y, int z)
249 {
250         _initialConoturModel->DeleteAllPoints();
251
252         manualPoint *mp = NULL;
253         double XX=x;
254         double YY=y;
255         double ZZ=z;
256         TransfromCoordViewWorld(XX,YY,ZZ);
257
258         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
259         for ( i=0; i<manualPointsSZ; i++ )
260         {
261                 mp = _manContModel->GetManualPoint( i );
262                 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
263         }
264 }
265 //-------------------------------------------------------------------
266 void manualViewContour::MoveContour(int x, int y, int z)
267 {
268         manualPoint *mpOrigin = NULL;
269         manualPoint *mpMoving = NULL;
270         double XX=x;
271         double YY=y;
272         double ZZ=z;
273
274         TransfromCoordViewWorld(XX,YY,ZZ);
275
276         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
277         for ( i=0; i<manualPointsSZ; i++ )
278         {
279                 mpOrigin = _manContModel->GetManualPoint( i );
280                 mpMoving = _initialConoturModel->GetManualPoint(i);
281                 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
282         }
283         UpdateViewPoints();
284 }
285 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
286 {
287         manualPoint *mpOrigin = NULL;
288
289         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
290         for ( i=0; i<manualPointsSZ; i++ )
291         {
292                 mpOrigin = _manContModel->GetManualPoint( i );
293                 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
294         }
295         UpdateViewPoints();
296 }