0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TestTopOpeDraw / TestTopOpeDraw_DrawableMesure.cxx
CommitLineData
7fd59977 1// File: TestTopOpeDraw_DrawableMesure.cxx
2// Created: Thu Mar 13 16:23:47 1997
3// Author: Prestataire Mary FABIEN
4// <fbi@langdox.paris1.matra-dtv.fr>
5
6
7#include <TestTopOpeDraw_DrawableMesure.ixx>
8#include <TestTopOpeDraw_DrawableMesure.hxx>
9#include <TestTopOpeDraw_DrawableP3D.hxx>
10#include <TestTopOpeTools_Mesure.hxx>
11#include <Geom_Curve.hxx>
12#include <TopOpeBRepTool_CurveTool.hxx>
13#include <Standard_CString.hxx>
14#include <TColgp_Array1OfPnt.hxx>
15#include <TColgp_HArray1OfPnt.hxx>
16#include <string.h>
17#include <Draw_Interpretor.hxx>
18
19
20static gp_Pnt PScale(const gp_Pnt& P,
21 const Standard_Real ScaleX,
22 const Standard_Real ScaleY)
23{
24 gp_Pnt Pnt;
25 Pnt.SetX(P.X() * ScaleX);
26 Pnt.SetY(P.Y() * ScaleY);
27 Pnt.SetZ(0.);
28 return Pnt;
29}
30
31static TColgp_Array1OfPnt& Scale(const TColgp_Array1OfPnt& AP,
32 const Standard_Real ScaleX,
33 const Standard_Real ScaleY)
34{
35 Standard_Integer i,up = AP.Upper();
36 TColgp_Array1OfPnt *aAP = new TColgp_Array1OfPnt(1, up);
37 for (i = 1; i <= up;i++) {
38 aAP->SetValue(i, PScale(AP.Value(i), ScaleX, ScaleY));
39 }
40 return *aAP;
41}
42
43Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M,
44 Handle(TColgp_HArray1OfPnt) T)
45
46{
47 Standard_Integer up = T->Upper();
48 TColgp_Array1OfPnt& AOP = T->ChangeArray1();
49 const TColgp_Array1OfPnt& MAOP = M.Pnts();
50 for(Standard_Integer i= 1; i <= up; i++) {
51 AOP.SetValue(i,MAOP.Value(i));
52 }
53 return T;
54}
55
56Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M)
57
58{
59 Standard_Integer up = M.NPnts();
60 Handle(TColgp_HArray1OfPnt) T = new TColgp_HArray1OfPnt(1,up);
61 TColgp_Array1OfPnt& AOP = T->ChangeArray1();
62 const TColgp_Array1OfPnt& MAOP = M.Pnts();
63 for(Standard_Integer i= 1; i <= up; i++) {
64 AOP.SetValue(i,MAOP.Value(i));
65 }
66 return T;
67}
68
69Handle(Geom_Curve) makecurvescale (const Handle(TColgp_HArray1OfPnt)& HP,
70 const Standard_Real ScaleX,
71 const Standard_Real ScaleY)
72{
73 Handle(Geom_Curve) C;
74 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(Scale(HP->Array1(),ScaleX,ScaleY));
75 return C;
76}
77
78Handle(Geom_Curve) makecurve(const Handle(TColgp_HArray1OfPnt)& HP)
79{
80 Handle(Geom_Curve) C;
81 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(HP->Array1());
82 return C;
83}
84
85
86static Standard_CString makename(const TCollection_AsciiString C)
87{
88 char * temp = new char[C.Length()+2];
89 temp[0] = ' ' ;
90 temp[C.Length()+1] = 0;
91 strncpy(&temp[1], C.ToCString(), C.Length());
92 return temp;
93}
94
95static Standard_CString makename1(const gp_Pnt& P)
96{
97 TCollection_AsciiString C((Standard_Integer)P.Coord(1));
98
99 char * temp = new char[C.Length()+2];
100 temp[0]=' ';
101 temp[C.Length()+1]=0;
102 strncpy(&temp[1], C.ToCString(), C.Length());
103 return temp;
104}
105
106static Standard_CString makename2(const gp_Pnt& P)
107{
108 TCollection_AsciiString C;
109
110 C = "";C = C + P.Coord(2);
111 TCollection_AsciiString S1 = C.Token(".",1);
7fd59977 112 S1.RightJustify(15, ' ');
113 TCollection_AsciiString S2 = C.Token(".",2);
114 S2.Trunc(2);
115 C = " ";C = C + S1 + "." + S2;
116
117 char * temp = new char[C.Length()+1];
118 temp[C.Length()]=0;
119 strncpy(&temp[0], C.ToCString(), C.Length());
120 return temp;
121}
122
123#ifdef DEB
124static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T)
125{
126 Standard_Integer up = T.Upper();
127 TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
128 for(Standard_Integer i= 1; i <= up; i++) {
129 gp_Pnt pnt(T.Value(i).Coord(1), 0, 0);
130 (*AOP).SetValue(i, pnt);
131 }
132 Handle(Geom_Curve) C;
133 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
134 return C;
135}
136#endif
137
138#ifdef DEB
139static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T)
140{
141 Standard_Integer up = T.Upper();
142 TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
143 for(Standard_Integer i= 1; i <= up; i++) {
144 gp_Pnt pnt(0, T.Value(i).Coord(2), 0);
145 (*AOP).SetValue(i, pnt);
146 }
147 Handle(Geom_Curve) C;
148 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
149 return C;
150}
151#endif
152
153static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T,
154 const Standard_Real ScaleX)
155{
156 Standard_Integer up = T.Upper();
157 TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
158 for(Standard_Integer i= 1; i <= up; i++) {
159 gp_Pnt pnt(T.Value(i).Coord(1) * ScaleX, 0, 0);
160 (*AOP).SetValue(i, pnt);
161 }
162 Handle(Geom_Curve) C;
163 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
164 return C;
165}
166
167static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T,
168 const Standard_Real ScaleY)
169{
170 Standard_Integer up = T.Upper();
171 TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
172 for(Standard_Integer i= 1; i <= up; i++) {
173 gp_Pnt pnt(0, T.Value(i).Coord(2) * ScaleY, 0);
174 (*AOP).SetValue(i, pnt);
175 }
176 Handle(Geom_Curve) C;
177 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
178 return C;
179}
180
181//=======================================================================
182//function : TestTopOpeDraw_DrawableMesure
183//purpose :
184//=======================================================================
185
186TestTopOpeDraw_DrawableMesure::TestTopOpeDraw_DrawableMesure
187(const TestTopOpeTools_Mesure& M,
188 const Draw_Color& CurveColor,
189 const Draw_Color& TextColor,
190 const Standard_Real ScaleX,
191 const Standard_Real ScaleY) :
192 TestTopOpeDraw_DrawableC3D(::makecurvescale(makepnt(M),ScaleX,ScaleY),
193 CurveColor, ::makename(M.Name())
194 , TextColor)
195 ,myP(makepnt(M))
196 ,myAXE1(new TestTopOpeDraw_DrawableC3D(DrawAxe1(myP->Array1(), ScaleX),
197 Draw_saumon))
198 ,myAXE2(new TestTopOpeDraw_DrawableC3D(DrawAxe2(myP->Array1(), ScaleY),
199 Draw_saumon))
200 ,myScaleX(ScaleX)
201 ,myScaleY(ScaleY)
202{
203 Standard_Integer up = myP->Upper(), i;
204 myHDP = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
205 myHADP1 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
206 myHADP2 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
207 for(i = 1; i <= up; i++) {
208 Handle(TestTopOpeDraw_DrawableP3D) DP
209 = new TestTopOpeDraw_DrawableP3D(PScale(myP->Value(i), ScaleX, ScaleY),
210 Draw_rouge);
211 myHDP->SetValue(i,DP);
212 gp_Pnt PA1(myP->Value(i).Coord(1), 0, 0);
213 gp_Pnt PA1Sc(myP->Value(i).Coord(1) * ScaleX, 0, 0);
214 Handle(TestTopOpeDraw_DrawableP3D) DPA1
215 = new TestTopOpeDraw_DrawableP3D(PA1Sc,Draw_rose,
216 makename1(PA1),Draw_rose,-7,15);
217 myHADP1->SetValue(i,DPA1);
218 gp_Pnt PA2(0,myP->Value(i).Coord(2), 0);
219 gp_Pnt PA2Sc(0,myP->Value(i).Coord(2) * myScaleY, 0);
220 Handle(TestTopOpeDraw_DrawableP3D) DPA2
221 = new TestTopOpeDraw_DrawableP3D(PA2Sc,Draw_rose,
222 makename2(PA2),Draw_rose,-120,5);
223 myHADP2->SetValue(i,DPA2);
224 }
225}
226
227//=======================================================================
228//function : SetScaleX
229//purpose :
230//=======================================================================
231
232void TestTopOpeDraw_DrawableMesure::SetScaleX(const Standard_Real ScaleX)
233{
234 SetScale(ScaleX, myScaleY);
235}
236
237//=======================================================================
238//function : SetScaleY
239//purpose :
240//=======================================================================
241
242void TestTopOpeDraw_DrawableMesure::SetScaleY(const Standard_Real ScaleY)
243{
244 SetScale(myScaleX, ScaleY);
245}
246
247//=======================================================================
248//function : SetScale
249//purpose :
250//=======================================================================
251
252void TestTopOpeDraw_DrawableMesure::SetScale(const Standard_Real ScaleX,
253 const Standard_Real ScaleY)
254{
255 myScaleX = ScaleX;
256 myScaleY = ScaleY;
257 Handle(Geom_Curve) GC = ::makecurvescale(myP, myScaleX, myScaleY);
258 ChangeCurve(GC);
259 ChangePnt(Pnt());
260 GC = DrawAxe1(myP->Array1(), myScaleX);
261 myAXE1->ChangeCurve(GC);
262 myAXE1->ChangePnt(Pnt());
263 GC = DrawAxe2(myP->Array1(), myScaleY);
264 myAXE2->ChangeCurve(GC);
265 myAXE2->ChangePnt(Pnt());
266 Standard_Integer up = myP->Upper(), i;
267 for(i = 1; i <= up; i++) {
268 Handle(TestTopOpeDraw_DrawableP3D) DP = myHDP->Value(i);
269 gp_Pnt P = PScale(myP->Value(i), myScaleX, myScaleY);
270 DP->ChangePnt(P);
271 myHDP->SetValue(i,DP);
272
273 Handle(TestTopOpeDraw_DrawableP3D) DPA1 = myHADP1->Value(i);
274 gp_Pnt PA1(myP->Value(i).Coord(1) * myScaleX, 0, 0);
275 DPA1->ChangePnt(PA1);
276 myHADP1->SetValue(i,DPA1);
277
278 Handle(TestTopOpeDraw_DrawableP3D) DPA2 = myHADP2->Value(i);
279 gp_Pnt PA2(0, myP->Value(i).Coord(2) * myScaleY, 0);
280 DPA2->ChangePnt(PA2);
281 myHADP2->SetValue(i,DPA2);
282 }
283}
284
285//=======================================================================
286//function : Pnt
287//purpose :
288//=======================================================================
289
290gp_Pnt TestTopOpeDraw_DrawableMesure::Pnt() const
291{
292 const Handle(Geom_Curve)& GC = DrawTrSurf_Curve::GetCurve();
293 Standard_Real f = GC->FirstParameter();
294 Standard_Real l = GC->LastParameter();
295 Standard_Real t = 0.;
296 Standard_Real p = t*f + (1-t)*l;
297 gp_Pnt P = GC->Value(p);
298 return P;
299}
300
301//=======================================================================
302//function : Pnts
303//purpose :
304//=======================================================================
305
306const Handle(TColgp_HArray1OfPnt)& TestTopOpeDraw_DrawableMesure::Pnts() const
307{
308 return myP;
309}
310
311//=======================================================================
312//function : SetName
313//purpose :
314//=======================================================================
315
316void TestTopOpeDraw_DrawableMesure::SetName(const TCollection_AsciiString& Name)
317{
318 Standard_CString Str = makename(Name);
319 ChangeText(Str);
320}
321
322//=======================================================================
323//function : Clear
324//purpose :
325//=======================================================================
326
327void TestTopOpeDraw_DrawableMesure::Clear()
328{
329 myScaleX = 1;
330 myScaleY = 1;
331
332}
333
334//=======================================================================
335//function : Whatis
336//purpose :
337//=======================================================================
338
339void TestTopOpeDraw_DrawableMesure::Whatis(Draw_Interpretor& s)const
340{
341 if (!myP.IsNull())
342 s << "DrawableMesure";
343}
344
345//=======================================================================
346//function : DrawOn
347//purpose :
348//=======================================================================
349
350void TestTopOpeDraw_DrawableMesure::DrawOn(Draw_Display& dis) const
351{
352 Standard_Integer i,n;
353
354 // les axes
355 n = myHADP1->Upper();
356 myAXE1->DrawOn(dis);
357 for(i = 1; i <= n; i++) {
358 myHADP1->Value(i)->DrawOn(dis);
359 }
360
361 myAXE2->DrawOn(dis);
362 n = myHADP2->Upper();
363 for(i = 1; i <= n; i++) {
364 myHADP2->Value(i)->DrawOn(dis);
365 }
366
367 // la courbe et ses points
368 TestTopOpeDraw_DrawableC3D::DrawOn(dis);
369 n = myHDP->Upper();
370 for(i = 1; i <= n; i++) {
371 myHDP->Value(i)->DrawOn(dis);
372 myHADP1->Value(i)->DrawOn(dis);
373 myHADP2->Value(i)->DrawOn(dis);
374 }
375}