summaryrefslogtreecommitdiff
path: root/src/TestTopOpeDraw/TestTopOpeDraw_TTOT.cxx
blob: 90ce7120a8b3b9e4f028a320943038248e1d4f02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// File:	TestTopOpeDraw_TTOT.hxx
// Created:	Fri Sep 20 11:55:24 1996
// Author:	Jean Yves LEBEY
//		<jyl@bistrox.paris1.matra-dtv.fr>

#ifdef HAVE_CONFIG_H
# include <oce-config.h>
#endif
#include <TestTopOpeDraw_TTOT.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <BRep_Tool.hxx>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

//=======================================================================
//function : ShapeEnumToString
//purpose  : 
//=======================================================================
void TestTopOpeDraw_TTOT::ShapeEnumToString
(const TopAbs_ShapeEnum T, TCollection_AsciiString& N)
{
  if      (T == TopAbs_SHAPE)  N = "s"; 
  else if (T == TopAbs_COMPOUND)  N = "co";
  else if (T == TopAbs_COMPSOLID)  N = "cs";
  else if (T == TopAbs_SOLID)  N = "so";
  else if (T == TopAbs_SHELL)  N = "sh";  
  else if (T == TopAbs_FACE)   N = "f"; 
  else if (T == TopAbs_WIRE)   N = "w"; 
  else if (T == TopAbs_EDGE)   N = "e"; 
  else if (T == TopAbs_VERTEX) N = "v"; 
}

//=======================================================================
//function : OrientationToString
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::OrientationToString
(const TopAbs_Orientation o, TCollection_AsciiString& N)
{
  switch (o) {
  case TopAbs_FORWARD  : N = "FORWARD" ; break;
  case TopAbs_REVERSED : N = "REVERSED"; break;
  case TopAbs_INTERNAL : N = "INTERNAL"; break;
  case TopAbs_EXTERNAL : N = "EXTERNAL"; break;
  }
}

//=======================================================================
//function : StringToKind
//purpose  : 
//=======================================================================

Standard_Boolean TestTopOpeDraw_TTOT::StringToKind
(const TCollection_AsciiString& N, TopOpeBRepDS_Kind& T)
{ 
  char *s = (char*)N.ToCString();
  Standard_Integer ok = 0;
  if      (!strcasecmp(s,"su")) { T = TopOpeBRepDS_SURFACE; ok = 1; }
  else if (!strcasecmp(s,"c"))  { T = TopOpeBRepDS_CURVE; ok = 1; }
  else if (!strcasecmp(s,"p"))  { T = TopOpeBRepDS_POINT; ok = 1; }
  if      (!strcasecmp(s,"co")) { T = TopOpeBRepDS_COMPOUND; ok = 1; }
  if      (!strcasecmp(s,"cs")) { T = TopOpeBRepDS_COMPSOLID; ok = 1; }
  else if (!strcasecmp(s,"so")) { T = TopOpeBRepDS_SOLID; ok = 1; }
  else if (!strcasecmp(s,"sh")) { T = TopOpeBRepDS_SHELL; ok = 1; }
  else if (!strcasecmp(s,"f"))  { T = TopOpeBRepDS_FACE; ok = 1; }
  else if (!strcasecmp(s,"w"))  { T = TopOpeBRepDS_WIRE; ok = 1; }
  else if (!strcasecmp(s,"e"))  { T = TopOpeBRepDS_EDGE; ok = 1; }
  else if (!strcasecmp(s,"v"))  { T = TopOpeBRepDS_VERTEX; ok = 1; }
  return ok != 0;
}

//=======================================================================
//function : KindToString
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::KindToString
(const TopOpeBRepDS_Kind T, TCollection_AsciiString& N)
{
  if      (T == TopOpeBRepDS_SURFACE) N = "su"; 
  else if (T == TopOpeBRepDS_CURVE)   N = "c";
  else if (T == TopOpeBRepDS_POINT)   N = "p";  
  else if (T == TopOpeBRepDS_COMPOUND)   N = "co";
  else if (T == TopOpeBRepDS_COMPSOLID)   N = "cs";
  else if (T == TopOpeBRepDS_SOLID)   N = "so";
  else if (T == TopOpeBRepDS_SHELL)   N = "sh";  
  else if (T == TopOpeBRepDS_FACE)    N = "f"; 
  else if (T == TopOpeBRepDS_WIRE)    N = "w"; 
  else if (T == TopOpeBRepDS_EDGE)    N = "e"; 
  else if (T == TopOpeBRepDS_VERTEX)  N = "v"; 
}


//=======================================================================
//function : StringToShapeEnum
//purpose  : 
//=======================================================================

Standard_Boolean TestTopOpeDraw_TTOT::StringToShapeEnum
(const TCollection_AsciiString& N, TopAbs_ShapeEnum& T)
{ 
  char *s = (char*)N.ToCString();
  Standard_Integer ok = 0;
  if      (!strcasecmp(s,"s"))   { T = TopAbs_SHAPE; ok = 1; }
  else if (!strcasecmp(s,"co"))  { T = TopAbs_COMPOUND; ok = 1; }
  else if (!strcasecmp(s,"cs"))  { T = TopAbs_COMPSOLID; ok = 1; }
  else if (!strcasecmp(s,"so"))  { T = TopAbs_SOLID; ok = 1; }
  else if (!strcasecmp(s,"sh"))  { T = TopAbs_SHELL; ok = 1; }
  else if (!strcasecmp(s,"f"))   { T = TopAbs_FACE; ok = 1; }
  else if (!strcasecmp(s,"w"))   { T = TopAbs_WIRE; ok = 1; }
  else if (!strcasecmp(s,"e"))   { T = TopAbs_EDGE; ok = 1; }
  else if (!strcasecmp(s,"v"))   { T = TopAbs_VERTEX; ok = 1; }
  return ok != 0;
}


//=======================================================================
//function : ShapeColor
//purpose  : 
//=======================================================================

Draw_ColorKind TestTopOpeDraw_TTOT::ShapeColor
(const TopoDS_Shape& S)
{
  Draw_ColorKind col = Draw_orange;
  switch ( S.ShapeType() ) {
  case TopAbs_COMPOUND : col = Draw_saumon; break;
  case TopAbs_COMPSOLID : col = Draw_blanc; break;
  case TopAbs_SOLID  : col = Draw_violet; break;
  case TopAbs_SHELL  : col = Draw_corail; break;
  case TopAbs_FACE   : col = Draw_vert; break; // col = Draw_jaune; break;
  case TopAbs_WIRE   : col = Draw_cyan; break;
  case TopAbs_EDGE   : col = Draw_magenta; break;
  case TopAbs_VERTEX : col = Draw_orange; break;
  default            : col = Draw_marron;
  }
  return col;
}

Draw_ColorKind TestTopOpeDraw_TTOT::KindColor
(const TopOpeBRepDS_Kind K)
{
  Draw_ColorKind col = Draw_orange;
  if      (K == TopOpeBRepDS_SURFACE) col = Draw_jaune;
  else if (K == TopOpeBRepDS_CURVE)   col = Draw_vert;
  else if (K == TopOpeBRepDS_POINT)   col = Draw_blanc;
  else if (K == TopOpeBRepDS_FACE)    col = Draw_cyan;
  return col;
}

//=======================================================================
//function : GeometryColor
//purpose  : 
//=======================================================================

Draw_ColorKind TestTopOpeDraw_TTOT::GeometryColor
(const TopOpeBRepDS_Kind K)
{
  Draw_ColorKind col = Draw_orange;
  col = KindColor(K);
  return col;
}

//=======================================================================
//function : CurveToString
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CurveToString
(const GeomAbs_CurveType t, TCollection_AsciiString& N)
{
  switch(t) {
  case GeomAbs_Line                : N = "LINE";              break;
  case GeomAbs_Circle              : N = "CIRCLE";            break;
  case GeomAbs_Ellipse             : N = "ELLIPSE";           break;
  case GeomAbs_Hyperbola           : N = "HYPERBOLA";         break;
  case GeomAbs_Parabola            : N = "PARABOLA";          break;
  case GeomAbs_BezierCurve         : N = "BEZIER";       break;
  case GeomAbs_BSplineCurve        : N = "BSPLINE";      break;
  case GeomAbs_OtherCurve          : N = "OTHER";        break;
  default                          : N = "UNKNOWN";           break;  
  }
}

//=======================================================================
//function : SurfaceToString
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::SurfaceToString
(const GeomAbs_SurfaceType t, TCollection_AsciiString& N)
{
  switch(t) {
  case GeomAbs_Plane               : N = "PLANE";              break;
  case GeomAbs_Cylinder            : N = "CYLINDER";            break;
  case GeomAbs_Cone                : N = "CONE";           break;
  case GeomAbs_Sphere              : N = "SPHERE";         break;
  case GeomAbs_Torus               : N = "TORUS";          break;
  case GeomAbs_BezierSurface       : N = "BEZIER";       break;
  case GeomAbs_BSplineSurface      : N = "BSPLINE";      break;
  case GeomAbs_SurfaceOfRevolution : N = "REVOLUTION";        break;
  case GeomAbs_SurfaceOfExtrusion  : N = "EXTRUSION";        break;
  case GeomAbs_OffsetSurface       : N = "OFFSET";        break;
  case GeomAbs_OtherSurface        : N = "OTHER";        break;
  default                          : N = "UNKNOWN";           break;  
  }
}

//=======================================================================
//function : GeometryName
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::GeometryName
(const Standard_Integer  I, const TopOpeBRepDS_Kind K, TCollection_AsciiString& N)
{ 
  TCollection_AsciiString name; KindToString(K,name); 
  name = name + "_" + TCollection_AsciiString(I);
  N = name;
}

//=======================================================================
//function : CatCurveName
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatCurveName
(const Standard_Integer I, TCollection_AsciiString& N)
{ 
  TCollection_AsciiString n; GeometryName(I,TopOpeBRepDS_CURVE,n); 
  N = N + n;
}

//=======================================================================
//function : CatOrientation
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatOrientation
(const TopAbs_Orientation o,TCollection_AsciiString& N)
{ 
  TCollection_AsciiString s; OrientationToString(o,s);
  s.Trunc(1);
  N = N + "["; N = N + s; N = N + "]";
}

//=======================================================================
//function : CatOrientation
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatOrientation
(const TopoDS_Shape& S,TCollection_AsciiString& N)
{ 
  CatOrientation(S.Orientation(),N);
}

//=======================================================================
//function : CatCurve
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatCurve
(const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
{
  if ( GC.IsNull() ) return;
  GeomAdaptor_Curve GAC(GC); GeomAbs_CurveType t = GAC.GetType();
  TCollection_AsciiString s; CurveToString(t,s); 
  s.Trunc(2);
  N = N + "("; N = N + s; N = N + ")";
}

//=======================================================================
//function : CatSurface
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatSurface
(const Handle(Geom_Surface) GS, TCollection_AsciiString& N)
{
  if ( GS.IsNull() ) return;
  GeomAdaptor_Surface GAS(GS); GeomAbs_SurfaceType t = GAS.GetType();
  TCollection_AsciiString s; SurfaceToString(t,s);
  s.Trunc(2);
  N = N + "("; N = N + s; N = N + ")";
}

//=======================================================================
//function : CatGeometry
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatGeometry
(const TopoDS_Shape& S, TCollection_AsciiString& N)
{
  if ( S.IsNull() ) return;
  const TopAbs_ShapeEnum t = S.ShapeType();
  if      (t == TopAbs_FACE) {
    const TopoDS_Face& F = TopoDS::Face(S);
    TopLoc_Location loc; 
    Handle(Geom_Surface) GS = BRep_Tool::Surface(F,loc);
    CatSurface(GS,N);
  }
  else if (t == TopAbs_EDGE) {
    const TopoDS_Edge& E = TopoDS::Edge(S);
    TopLoc_Location loc; Standard_Real f,l;
    Handle(Geom_Curve) GC = BRep_Tool::Curve(E,loc,f,l);
    CatCurve(GC,N);
  }
}

//=======================================================================
//function : CatCurveDisplayName
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CatCurveDisplayName
(const Standard_Integer I, const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
{
  if ( GC.IsNull() ) return;
  CatCurveName(I,N);
  CatCurve(GC,N);
}

//=======================================================================
//function : CurveDisplayName
//purpose  : 
//=======================================================================

void TestTopOpeDraw_TTOT::CurveDisplayName
(const Standard_Integer   I, const Handle(Geom_Curve) GC, TCollection_AsciiString& N)
{
  N = " "; 
  CatCurveDisplayName(I,GC,N);
}

//=======================================================================
//function : ShapeKind
//purpose  : 
//=======================================================================

Standard_Boolean TestTopOpeDraw_TTOT::ShapeKind(const TopoDS_Shape& S,const TopAbs_ShapeEnum TS)
{
  if ( TS == TopAbs_SHAPE ) return Standard_True;
  else return ( S.ShapeType() == TS );
}