summaryrefslogtreecommitdiff
path: root/src/IGESSolid/IGESSolid_TopoBuilder.cxx
blob: bdad0b0922543a889f4c9981b3eb719403605b66 (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
#include <IGESSolid_TopoBuilder.ixx>
#include <Standard_DomainError.hxx>
#include <TColgp_HArray1OfXYZ.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <IGESSolid_HArray1OfVertexList.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <IGESBasic_HArray1OfHArray1OfInteger.hxx>
#include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
#include <IGESSolid_HArray1OfLoop.hxx>
#include <IGESSolid_HArray1OfFace.hxx>
#include <IGESSolid_HArray1OfShell.hxx>
#include <Interface_Macros.hxx>




    IGESSolid_TopoBuilder::IGESSolid_TopoBuilder ()    {  Clear();  }

    void  IGESSolid_TopoBuilder::Clear ()
{
  thesolid = new IGESSolid_ManifoldSolid;
  thevoids = new TColStd_HSequenceOfTransient();
  thevflag = new TColStd_HSequenceOfInteger();
  theshell = new IGESSolid_Shell;
  thefaces = new TColStd_HSequenceOfTransient();
  thefflag = new TColStd_HSequenceOfInteger();
  theface.Nullify();
  theinner = new TColStd_HSequenceOfTransient();
  theloop.Nullify();
  theetype = new TColStd_HSequenceOfInteger();
  thee3d   = new TColStd_HSequenceOfInteger();
  theeflag = new TColStd_HSequenceOfInteger();
  theeuv   = new TColStd_HSequenceOfTransient();
  theisol  = new TColStd_HSequenceOfInteger();
  thecuruv = new TColStd_HSequenceOfTransient();
  theiso   = new TColStd_HSequenceOfTransient();
  theedgel = new IGESSolid_EdgeList;
  thecur3d = new TColStd_HSequenceOfTransient();
  thevstar = new TColStd_HSequenceOfInteger();
  thevend  = new TColStd_HSequenceOfInteger();
  thevertl = new IGESSolid_VertexList;
  thepoint = new TColgp_HSequenceOfXYZ();
}

    void  IGESSolid_TopoBuilder::AddVertex (const gp_XYZ& val)
      {  thepoint->Append(val);  }

    Standard_Integer  IGESSolid_TopoBuilder::NbVertices () const
      {  return thepoint->Length();  }

    const gp_XYZ&  IGESSolid_TopoBuilder::Vertex
  (const Standard_Integer num) const
      {  return thepoint->Value(num);  }

    Handle(IGESSolid_VertexList)  IGESSolid_TopoBuilder::VertexList () const
      {  return thevertl;  }


    void  IGESSolid_TopoBuilder::AddEdge
  (const Handle(IGESData_IGESEntity)& curve,
   const Standard_Integer vstart,  const Standard_Integer vend)
{
  if (curve.IsNull() || vstart <= 0 || vend <= 0 ||
      vstart > thepoint->Length() || vend > thepoint->Length())
    Standard_DomainError::Raise ("IGESSolid_TopoBuilder : AddEdge");
  thecur3d->Append (curve);
  thevstar->Append (vstart);
  thevend->Append  (vend);
}

    Standard_Integer  IGESSolid_TopoBuilder::NbEdges () const
      {  return thecur3d->Length();  }

    void  IGESSolid_TopoBuilder::Edge
  (const Standard_Integer num,
   Handle(IGESData_IGESEntity)& curve,
   Standard_Integer& vstart, Standard_Integer& vend) const
{
  if (num <= 0 || num > thecur3d->Length()) return;
  curve  = GetCasted(IGESData_IGESEntity,thecur3d->Value(num));
  vstart = thevstar->Value(num);
  vend   = thevend->Value(num);
}

    Handle(IGESSolid_EdgeList)  IGESSolid_TopoBuilder::EdgeList () const
      {  return theedgel;  }

    void  IGESSolid_TopoBuilder::EndLists ()
{
  Standard_Integer i,nb;
  Handle(TColgp_HArray1OfXYZ) vert;
  Handle(IGESData_HArray1OfIGESEntity)  curves;
  Handle(IGESSolid_HArray1OfVertexList) estart, eend;
  Handle(TColStd_HArray1OfInteger)      nstart, nend;

  nb = thepoint->Length();
  if (nb > 0) {
    vert   = new TColgp_HArray1OfXYZ (1,nb);
    for (i = 1; i <= nb; i ++) vert->SetValue (i, thepoint->Value(i));
  }
  thevertl->Init (vert);

  nb = thecur3d->Length();
  if (nb > 0) {
    curves = new IGESData_HArray1OfIGESEntity (1,nb);
    nstart = new TColStd_HArray1OfInteger     (1,nb); nstart->Init(0);
    nend   = new TColStd_HArray1OfInteger     (1,nb); nend->Init(0);
    estart = new IGESSolid_HArray1OfVertexList (1,nb);
    eend   = new IGESSolid_HArray1OfVertexList (1,nb);
    for (i = 1; i <= nb; i ++) {
      curves->SetValue
	(i,GetCasted(IGESData_IGESEntity,thecur3d->Value(i)));
      nstart->SetValue (i,thevstar->Value(i));
      nend->SetValue   (i,thevend->Value(i));
      estart->SetValue (i,thevertl);
      estart->SetValue (i,thevertl);
    }
  }
  theedgel->Init (curves,estart,nstart,eend,nend);
}

    void  IGESSolid_TopoBuilder::MakeLoop ()
{
  theloop = new IGESSolid_Loop;
  theetype->Clear();  thee3d->Clear();   theeflag->Clear();
  theeuv->Clear();    theisol->Clear();
}

    void  IGESSolid_TopoBuilder::MakeEdge
  (const Standard_Integer edgetype, const Standard_Integer edge3d,
   const Standard_Integer orientation)
{
  if (edge3d <= 0 || edge3d > thecur3d->Length())
    Standard_DomainError::Raise ("IGESSolid_TopoBuilder : MakeEdge");
  theetype->Append (edgetype);
  thee3d->Append   (edge3d);
  theeflag->Append (orientation);
  thecuruv->Clear();  theisol->Clear();
}

    void  IGESSolid_TopoBuilder::AddCurveUV
  (const Handle(IGESData_IGESEntity)& curve, const Standard_Integer iso)
{
  if (curve.IsNull() || thee3d->IsEmpty())
    Standard_DomainError::Raise ("IGESSolid_TopoBuilder : AddCurveUV");
  thecuruv->Append(curve);
  theisol->Append(iso);
}

    void  IGESSolid_TopoBuilder::EndEdge ()
{
//  transformer  thecuruv,theiso en array et le mettre dans theeuv
  Handle(IGESData_HArray1OfIGESEntity) curuv;
  Handle(TColStd_HArray1OfInteger) iso;
  if (!thecuruv->IsEmpty()) {
    Standard_Integer i, nb = thecuruv->Length();
    curuv = new IGESData_HArray1OfIGESEntity (1,nb);
    iso   = new TColStd_HArray1OfInteger     (1,nb); iso->Init(0);
    for (i = 1; i <= nb; i ++) {
      curuv->SetValue (i, GetCasted(IGESData_IGESEntity,thecuruv->Value(i)));
      iso->SetValue   (i, theisol->Value(i));
    }
  }
  theeuv->Append(curuv);
}

    void  IGESSolid_TopoBuilder::EndLoop ()
{
  Handle(TColStd_HArray1OfInteger) etypes, e3d, eflags, enbuv, eiso;
  Handle(IGESData_HArray1OfIGESEntity) edges, curves;
  Handle(IGESBasic_HArray1OfHArray1OfInteger) isol;
  Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) curvl;
  Standard_Integer i, nb; //szv#4:S4163:12Mar99 nbuv not needed
  nb = thee3d->Length();
  if (nb > 0) {
    etypes = new TColStd_HArray1OfInteger (1,nb);
    e3d    = new TColStd_HArray1OfInteger (1,nb);
    eflags = new TColStd_HArray1OfInteger (1,nb);
    enbuv  = new TColStd_HArray1OfInteger (1,nb);
    edges  = new IGESData_HArray1OfIGESEntity (1,nb);
    curvl  = new IGESBasic_HArray1OfHArray1OfIGESEntity (1,nb);
    isol   = new IGESBasic_HArray1OfHArray1OfInteger    (1,nb);

    for (i = 1; i <= nb; i ++) {
      etypes->SetValue (i, theetype->Value(i));
      e3d->SetValue    (i, thee3d->Value(i));
      eflags->SetValue (i, theeflag->Value(i));
      enbuv->SetValue  (i,0);
      edges->SetValue  (i,theedgel);
      curves = GetCasted(IGESData_HArray1OfIGESEntity,thecuruv->Value(i));
      if (!curves.IsNull()) {
	//nbuv = curves->Length(); //szv#4:S4163:12Mar99 not needed
	enbuv->SetValue (i,nb);
	curvl->SetValue (i,curves);
	isol->SetValue  (i,GetCasted(TColStd_HArray1OfInteger,theiso->Value(i)));
      }
    }
  }
  theloop->Init (etypes,edges,e3d,eflags,enbuv, isol,curvl);
}


    void  IGESSolid_TopoBuilder::MakeFace
  (const Handle(IGESData_IGESEntity)& surface)
{
  if (surface.IsNull())
    Standard_DomainError::Raise ("IGESSolid_TopoBuilder : MakeFace");
  thesurf  = surface;
  theouter = 0;
  theinner->Clear();
  theface  = new IGESSolid_Face;
}

    void  IGESSolid_TopoBuilder::SetOuter ()
{
  EndLoop();
  theouter = 1;
  theinner->Append (theloop);
  theloop.Nullify();
}

    void  IGESSolid_TopoBuilder::AddInner ()
{
  EndLoop();
  theinner->Append (theloop);
  theloop.Nullify();
}

    void  IGESSolid_TopoBuilder::EndFace (const Standard_Integer orientation)
{
  Handle(IGESSolid_HArray1OfLoop) loops;
  Standard_Integer i, nb = theinner->Length();
  if (nb > 0) {
    loops = new IGESSolid_HArray1OfLoop (1,nb);
    for (i = 1; i <= nb; i ++) loops->SetValue
      (i, GetCasted(IGESSolid_Loop,theinner->Value(i)));
  }
  theface->Init (thesurf,theouter,loops);
  thefaces->Append(theface);
  thefflag->Append(orientation);
}


    void  IGESSolid_TopoBuilder::MakeShell ()
{
  theshell = new IGESSolid_Shell;
  thefaces->Clear();
  thefflag->Clear();
}

    void  IGESSolid_TopoBuilder::EndShell ()
{
  Handle(IGESSolid_HArray1OfFace)  faces;
  Handle(TColStd_HArray1OfInteger) flags;
  Standard_Integer i, nb = thefaces->Length();
  if (nb > 0) {
    faces = new IGESSolid_HArray1OfFace ( 1,nb);
    flags = new TColStd_HArray1OfInteger (1,nb); flags->Init(0);
    for (i = 1; i <= nb; i ++) {
      faces->SetValue (i,GetCasted(IGESSolid_Face,thefaces->Value(i)));
      flags->SetValue (i, thefflag->Value(i));
    }
  }
  theshell->Init (faces,flags);
}

    void  IGESSolid_TopoBuilder::EndSimpleShell ()
      {  EndShell();  EndLists();  }

    void  IGESSolid_TopoBuilder::SetMainShell
  (const Standard_Integer orientation)
{
  EndShell();
  themains = theshell;
  themflag = orientation;
  theshell.Nullify();
}

    void  IGESSolid_TopoBuilder::AddVoidShell
  (const Standard_Integer orientation)
{
  EndShell();
  thevoids->Append (theshell);
  thevflag->Append (orientation);
  theshell.Nullify();
}


    void  IGESSolid_TopoBuilder::EndSolid ()
{
  EndLists();
  Handle(IGESSolid_HArray1OfShell) shells;
  Handle(TColStd_HArray1OfInteger) flags;
  Standard_Integer i, nb = thevoids->Length();
  if (nb > 0) {
    shells = new IGESSolid_HArray1OfShell (1,nb);
    flags  = new TColStd_HArray1OfInteger (1,nb); flags->Init(0);
    for (i = 1; i <= nb; i ++) {
      shells->SetValue (i,GetCasted(IGESSolid_Shell,thevoids->Value(i)));
      flags->SetValue  (i,thevflag->Value(i));
    }
  }
  thesolid->Init (themains,themflag, shells,flags);
}

    Handle(IGESSolid_Shell)  IGESSolid_TopoBuilder::Shell () const
      {  return theshell;  }

    Handle(IGESSolid_ManifoldSolid)  IGESSolid_TopoBuilder::Solid () const
      {  return thesolid;  }