0022627: Change OCCT memory management defaults
[occt.git] / src / TestTopOpeDraw / TestTopOpeDraw_TTOT.cxx
CommitLineData
7fd59977 1// File: TestTopOpeDraw_TTOT.hxx
2// Created: Fri Sep 20 11:55:24 1996
3// Author: Jean Yves LEBEY
4// <jyl@bistrox.paris1.matra-dtv.fr>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9#include <TestTopOpeDraw_TTOT.hxx>
10#include <GeomAdaptor_Curve.hxx>
11#include <GeomAdaptor_Surface.hxx>
12#include <BRep_Tool.hxx>
13#ifdef HAVE_STRINGS_H
14# include <strings.h>
15#endif
16
17//=======================================================================
18//function : ShapeEnumToString
19//purpose :
20//=======================================================================
21void TestTopOpeDraw_TTOT::ShapeEnumToString
22(const TopAbs_ShapeEnum T, TCollection_AsciiString& N)
23{
24 if (T == TopAbs_SHAPE) N = "s";
25 else if (T == TopAbs_COMPOUND) N = "co";
26 else if (T == TopAbs_COMPSOLID) N = "cs";
27 else if (T == TopAbs_SOLID) N = "so";
28 else if (T == TopAbs_SHELL) N = "sh";
29 else if (T == TopAbs_FACE) N = "f";
30 else if (T == TopAbs_WIRE) N = "w";
31 else if (T == TopAbs_EDGE) N = "e";
32 else if (T == TopAbs_VERTEX) N = "v";
33}
34
35//=======================================================================
36//function : OrientationToString
37//purpose :
38//=======================================================================
39
40void TestTopOpeDraw_TTOT::OrientationToString
41(const TopAbs_Orientation o, TCollection_AsciiString& N)
42{
43 switch (o) {
44 case TopAbs_FORWARD : N = "FORWARD" ; break;
45 case TopAbs_REVERSED : N = "REVERSED"; break;
46 case TopAbs_INTERNAL : N = "INTERNAL"; break;
47 case TopAbs_EXTERNAL : N = "EXTERNAL"; break;
48 }
49}
50
51//=======================================================================
52//function : StringToKind
53//purpose :
54//=======================================================================
55
56Standard_Boolean TestTopOpeDraw_TTOT::StringToKind
57(const TCollection_AsciiString& N, TopOpeBRepDS_Kind& T)
58{
59 char *s = (char*)N.ToCString();
60 Standard_Integer ok = 0;
61 if (!strcasecmp(s,"su")) { T = TopOpeBRepDS_SURFACE; ok = 1; }
62 else if (!strcasecmp(s,"c")) { T = TopOpeBRepDS_CURVE; ok = 1; }
63 else if (!strcasecmp(s,"p")) { T = TopOpeBRepDS_POINT; ok = 1; }
64 if (!strcasecmp(s,"co")) { T = TopOpeBRepDS_COMPOUND; ok = 1; }
65 if (!strcasecmp(s,"cs")) { T = TopOpeBRepDS_COMPSOLID; ok = 1; }
66 else if (!strcasecmp(s,"so")) { T = TopOpeBRepDS_SOLID; ok = 1; }
67 else if (!strcasecmp(s,"sh")) { T = TopOpeBRepDS_SHELL; ok = 1; }
68 else if (!strcasecmp(s,"f")) { T = TopOpeBRepDS_FACE; ok = 1; }
69 else if (!strcasecmp(s,"w")) { T = TopOpeBRepDS_WIRE; ok = 1; }
70 else if (!strcasecmp(s,"e")) { T = TopOpeBRepDS_EDGE; ok = 1; }
71 else if (!strcasecmp(s,"v")) { T = TopOpeBRepDS_VERTEX; ok = 1; }
72 return ok != 0;
73}
74
75//=======================================================================
76//function : KindToString
77//purpose :
78//=======================================================================
79
80void TestTopOpeDraw_TTOT::KindToString
81(const TopOpeBRepDS_Kind T, TCollection_AsciiString& N)
82{
83 if (T == TopOpeBRepDS_SURFACE) N = "su";
84 else if (T == TopOpeBRepDS_CURVE) N = "c";
85 else if (T == TopOpeBRepDS_POINT) N = "p";
86 else if (T == TopOpeBRepDS_COMPOUND) N = "co";
87 else if (T == TopOpeBRepDS_COMPSOLID) N = "cs";
88 else if (T == TopOpeBRepDS_SOLID) N = "so";
89 else if (T == TopOpeBRepDS_SHELL) N = "sh";
90 else if (T == TopOpeBRepDS_FACE) N = "f";
91 else if (T == TopOpeBRepDS_WIRE) N = "w";
92 else if (T == TopOpeBRepDS_EDGE) N = "e";
93 else if (T == TopOpeBRepDS_VERTEX) N = "v";
94}
95
96
97//=======================================================================
98//function : StringToShapeEnum
99//purpose :
100//=======================================================================
101
102Standard_Boolean TestTopOpeDraw_TTOT::StringToShapeEnum
103(const TCollection_AsciiString& N, TopAbs_ShapeEnum& T)
104{
105 char *s = (char*)N.ToCString();
106 Standard_Integer ok = 0;
107 if (!strcasecmp(s,"s")) { T = TopAbs_SHAPE; ok = 1; }
108 else if (!strcasecmp(s,"co")) { T = TopAbs_COMPOUND; ok = 1; }
109 else if (!strcasecmp(s,"cs")) { T = TopAbs_COMPSOLID; ok = 1; }
110 else if (!strcasecmp(s,"so")) { T = TopAbs_SOLID; ok = 1; }
111 else if (!strcasecmp(s,"sh")) { T = TopAbs_SHELL; ok = 1; }
112 else if (!strcasecmp(s,"f")) { T = TopAbs_FACE; ok = 1; }
113 else if (!strcasecmp(s,"w")) { T = TopAbs_WIRE; ok = 1; }
114 else if (!strcasecmp(s,"e")) { T = TopAbs_EDGE; ok = 1; }
115 else if (!strcasecmp(s,"v")) { T = TopAbs_VERTEX; ok = 1; }
116 return ok != 0;
117}
118
119
120//=======================================================================
121//function : ShapeColor
122//purpose :
123//=======================================================================
124
125Draw_ColorKind TestTopOpeDraw_TTOT::ShapeColor
126(const TopoDS_Shape& S)
127{
128 Draw_ColorKind col = Draw_orange;
129 switch ( S.ShapeType() ) {
130 case TopAbs_COMPOUND : col = Draw_saumon; break;
131 case TopAbs_COMPSOLID : col = Draw_blanc; break;
132 case TopAbs_SOLID : col = Draw_violet; break;
133 case TopAbs_SHELL : col = Draw_corail; break;
134 case TopAbs_FACE : col = Draw_vert; break; // col = Draw_jaune; break;
135 case TopAbs_WIRE : col = Draw_cyan; break;
136 case TopAbs_EDGE : col = Draw_magenta; break;
137 case TopAbs_VERTEX : col = Draw_orange; break;
138 default : col = Draw_marron;
139 }
140 return col;
141}
142
143Draw_ColorKind TestTopOpeDraw_TTOT::KindColor
144(const TopOpeBRepDS_Kind K)
145{
146 Draw_ColorKind col = Draw_orange;
147 if (K == TopOpeBRepDS_SURFACE) col = Draw_jaune;
148 else if (K == TopOpeBRepDS_CURVE) col = Draw_vert;
149 else if (K == TopOpeBRepDS_POINT) col = Draw_blanc;
150 else if (K == TopOpeBRepDS_FACE) col = Draw_cyan;
151 return col;
152}
153
154//=======================================================================
155//function : GeometryColor
156//purpose :
157//=======================================================================
158
159Draw_ColorKind TestTopOpeDraw_TTOT::GeometryColor
160(const TopOpeBRepDS_Kind K)
161{
162 Draw_ColorKind col = Draw_orange;
163 col = KindColor(K);
164 return col;
165}
166
167//=======================================================================
168//function : CurveToString
169//purpose :
170//=======================================================================
171
172void TestTopOpeDraw_TTOT::CurveToString
173(const GeomAbs_CurveType t, TCollection_AsciiString& N)
174{
175 switch(t) {
176 case GeomAbs_Line : N = "LINE"; break;
177 case GeomAbs_Circle : N = "CIRCLE"; break;
178 case GeomAbs_Ellipse : N = "ELLIPSE"; break;
179 case GeomAbs_Hyperbola : N = "HYPERBOLA"; break;
180 case GeomAbs_Parabola : N = "PARABOLA"; break;
181 case GeomAbs_BezierCurve : N = "BEZIER"; break;
182 case GeomAbs_BSplineCurve : N = "BSPLINE"; break;
183 case GeomAbs_OtherCurve : N = "OTHER"; break;
184 default : N = "UNKNOWN"; break;
185 }
186}
187
188//=======================================================================
189//function : SurfaceToString
190//purpose :
191//=======================================================================
192
193void TestTopOpeDraw_TTOT::SurfaceToString
194(const GeomAbs_SurfaceType t, TCollection_AsciiString& N)
195{
196 switch(t) {
197 case GeomAbs_Plane : N = "PLANE"; break;
198 case GeomAbs_Cylinder : N = "CYLINDER"; break;
199 case GeomAbs_Cone : N = "CONE"; break;
200 case GeomAbs_Sphere : N = "SPHERE"; break;
201 case GeomAbs_Torus : N = "TORUS"; break;
202 case GeomAbs_BezierSurface : N = "BEZIER"; break;
203 case GeomAbs_BSplineSurface : N = "BSPLINE"; break;
204 case GeomAbs_SurfaceOfRevolution : N = "REVOLUTION"; break;
205 case GeomAbs_SurfaceOfExtrusion : N = "EXTRUSION"; break;
206 case GeomAbs_OffsetSurface : N = "OFFSET"; break;
207 case GeomAbs_OtherSurface : N = "OTHER"; break;
208 default : N = "UNKNOWN"; break;
209 }
210}
211
212//=======================================================================
213//function : GeometryName
214//purpose :
215//=======================================================================
216
217void TestTopOpeDraw_TTOT::GeometryName
218(const Standard_Integer I, const TopOpeBRepDS_Kind K, TCollection_AsciiString& N)
219{
220 TCollection_AsciiString name; KindToString(K,name);
221 name = name + "_" + TCollection_AsciiString(I);
222 N = name;
223}
224
225//=======================================================================
226//function : CatCurveName
227//purpose :
228//=======================================================================
229
230void TestTopOpeDraw_TTOT::CatCurveName
231(const Standard_Integer I, TCollection_AsciiString& N)
232{
233 TCollection_AsciiString n; GeometryName(I,TopOpeBRepDS_CURVE,n);
234 N = N + n;
235}
236
237//=======================================================================
238//function : CatOrientation
239//purpose :
240//=======================================================================
241
242void TestTopOpeDraw_TTOT::CatOrientation
243(const TopAbs_Orientation o,TCollection_AsciiString& N)
244{
245 TCollection_AsciiString s; OrientationToString(o,s);
246 s.Trunc(1);
247 N = N + "["; N = N + s; N = N + "]";
248}
249
250//=======================================================================
251//function : CatOrientation
252//purpose :
253//=======================================================================
254
255void TestTopOpeDraw_TTOT::CatOrientation
256(const TopoDS_Shape& S,TCollection_AsciiString& N)
257{
258 CatOrientation(S.Orientation(),N);
259}
260
261//=======================================================================
262//function : CatCurve
263//purpose :
264//=======================================================================
265
266void TestTopOpeDraw_TTOT::CatCurve
267(const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
268{
269 if ( GC.IsNull() ) return;
270 GeomAdaptor_Curve GAC(GC); GeomAbs_CurveType t = GAC.GetType();
271 TCollection_AsciiString s; CurveToString(t,s);
272 s.Trunc(2);
273 N = N + "("; N = N + s; N = N + ")";
274}
275
276//=======================================================================
277//function : CatSurface
278//purpose :
279//=======================================================================
280
281void TestTopOpeDraw_TTOT::CatSurface
282(const Handle(Geom_Surface) GS, TCollection_AsciiString& N)
283{
284 if ( GS.IsNull() ) return;
285 GeomAdaptor_Surface GAS(GS); GeomAbs_SurfaceType t = GAS.GetType();
286 TCollection_AsciiString s; SurfaceToString(t,s);
287 s.Trunc(2);
288 N = N + "("; N = N + s; N = N + ")";
289}
290
291//=======================================================================
292//function : CatGeometry
293//purpose :
294//=======================================================================
295
296void TestTopOpeDraw_TTOT::CatGeometry
297(const TopoDS_Shape& S, TCollection_AsciiString& N)
298{
299 if ( S.IsNull() ) return;
300 const TopAbs_ShapeEnum t = S.ShapeType();
301 if (t == TopAbs_FACE) {
302 const TopoDS_Face& F = TopoDS::Face(S);
303 TopLoc_Location loc;
304 Handle(Geom_Surface) GS = BRep_Tool::Surface(F,loc);
305 CatSurface(GS,N);
306 }
307 else if (t == TopAbs_EDGE) {
308 const TopoDS_Edge& E = TopoDS::Edge(S);
309 TopLoc_Location loc; Standard_Real f,l;
310 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,loc,f,l);
311 CatCurve(GC,N);
312 }
313}
314
315//=======================================================================
316//function : CatCurveDisplayName
317//purpose :
318//=======================================================================
319
320void TestTopOpeDraw_TTOT::CatCurveDisplayName
321(const Standard_Integer I, const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
322{
323 if ( GC.IsNull() ) return;
324 CatCurveName(I,N);
325 CatCurve(GC,N);
326}
327
328//=======================================================================
329//function : CurveDisplayName
330//purpose :
331//=======================================================================
332
333void TestTopOpeDraw_TTOT::CurveDisplayName
334(const Standard_Integer I, const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
335{
336 N = " ";
337 CatCurveDisplayName(I,GC,N);
338}
339
340//=======================================================================
341//function : ShapeKind
342//purpose :
343//=======================================================================
344
345Standard_Boolean TestTopOpeDraw_TTOT::ShapeKind(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS)
346{
347 if ( TS == TopAbs_SHAPE ) return Standard_True;
348 else return ( S.ShapeType() == TS );
349}