summaryrefslogtreecommitdiff
path: root/src/IGESToBRep/IGESToBRep_BRepEntity.cxx
blob: 788e3fa7b3cbf1e692719524b2dba0be180ea659 (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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
//=======================================================================
//file     : IGESToBRep_BRepEntity.cxx
//purpose  : Members to transfert any BRepEntity into TopoDS_Shape
//=======================================================================
// 21.12.98 rln, gka S4054
//#62 rln 10.01.99 PRO17015
//:q5 abv 19.03.99 unnecessary includes removed
//pdn 12.03.99 S4135 Constructing vertex with minimal tolerance
//:r1 abv 25.03.99 CTS21655.igs, CTS18545.igs: apply FixOrientation to whole face
//S4181 pdn 20.04.99 implementing of reading IGES elementary surfaces.
//pdn 20.04.99 CTS22655 avoid of exceptions in case of empty loops

#include <Standard_ErrorHandler.hxx>
#include <IGESToBRep_BRepEntity.ixx>
#include <IGESToBRep.hxx>
#include <IGESToBRep_BasicCurve.hxx>
#include <IGESToBRep_BasicSurface.hxx>
#include <IGESToBRep_CurveAndSurface.hxx>
#include <IGESToBRep_TopoCurve.hxx>
#include <IGESToBRep_TopoSurface.hxx>

#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>

#include <Geom_Curve.hxx>
#include <Geom_TrimmedCurve.hxx>

#include <gp.hxx>
#include <gp_Pnt.hxx>

#include <IGESBasic_SingleParent.hxx>

#include <IGESData_IGESEntity.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <IGESData_ToolLocation.hxx>

#include <IGESGeom_Boundary.hxx>
#include <IGESGeom_BoundedSurface.hxx>
#include <IGESGeom_CurveOnSurface.hxx>
#include <IGESGeom_Plane.hxx>
#include <IGESGeom_TrimmedSurface.hxx>

#include <Interface_Macros.hxx>

#include <Precision.hxx>

#include <TopAbs_ShapeEnum.hxx>

#include <TopExp.hxx>

#include <TopLoc_Location.hxx>
  
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>

#include <Transfer_TransientProcess.hxx>

#include <stdio.h>
#include <gp_Vec2d.hxx>//rln

#include <ShapeExtend_WireData.hxx>
#include <ShapeBuild_Edge.hxx>
#include <IGESToBRep_IGESBoundary.hxx>
#include <Message_Msg.hxx>
#include <TCollection_HAsciiString.hxx>
#include <IGESData_IGESModel.hxx>  
//#include <ShapeFix_Face.hxx>
#include <IGESToBRep_AlgoContainer.hxx>
#include <IGESToBRep_ToolContainer.hxx>
#include <Message_ProgressSentry.hxx>

// mjm le 10/10/96 on force la continuity a 0 en attendant de pouvoir
// travailler sur wire en non plus edge.


//=======================================================================
//function : IGESToBRep_BRepEntity
//purpose  : 
//=======================================================================
IGESToBRep_BRepEntity::IGESToBRep_BRepEntity()
     :IGESToBRep_CurveAndSurface()
{
  SetModeTransfer(Standard_False);
  SetContinuity(0);
}


//=======================================================================
//function : IGESToBRep_BRepEntity
//purpose  : 
//=======================================================================
IGESToBRep_BRepEntity::IGESToBRep_BRepEntity
  (const IGESToBRep_CurveAndSurface& CS)
     :IGESToBRep_CurveAndSurface(CS)
{
  SetContinuity(0);
}


//=======================================================================
//function : IGESToBRep_BRepEntity
//purpose  : 
//=======================================================================
IGESToBRep_BRepEntity::IGESToBRep_BRepEntity
  (const Standard_Real    eps,
   const Standard_Real    epsCoeff,
   const Standard_Real    epsGeom,
   const Standard_Boolean mode,
   const Standard_Boolean modeapprox,
   const Standard_Boolean optimized)
     :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode, modeapprox,
				 optimized)
{  
  SetContinuity(0);
}


//=======================================================================
//function : TransferBRepEntity
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferBRepEntity
  (const Handle(IGESData_IGESEntity)& start)
{
  TopoDS_Shape res;

  if (start->IsKind(STANDARD_TYPE(IGESSolid_Face))) {
    DeclareAndCast(IGESSolid_Face, st510, start);
    res = TransferFace(st510);
  }
  else if (start->IsKind(STANDARD_TYPE(IGESSolid_Shell))) {
    DeclareAndCast(IGESSolid_Shell, st514, start);
    res = TransferShell(st514);
  }
  else if (start->IsKind(STANDARD_TYPE(IGESSolid_ManifoldSolid))) {
    DeclareAndCast(IGESSolid_ManifoldSolid, st186, start);
    res = TransferManifoldSolid(st186);
  }
  else {
    Message_Msg Msg1005("IGES_1005");
    SendFail(start,Msg1005);
  }
  return res;
}


//=======================================================================
//function : TransferVertex
//purpose  : 
//=======================================================================
TopoDS_Vertex IGESToBRep_BRepEntity::TransferVertex
  (const Handle(IGESSolid_VertexList)& start,
   const Standard_Integer index)
{
  TopoDS_Vertex res;

  Standard_Integer nbshapes = NbShapeResult(start);
  if (nbshapes == 0 ) {
    BRep_Builder B;
    for (Standard_Integer inum = 1; inum <= start->NbVertices(); inum++) {
      gp_Pnt point = start-> Vertex(inum);
      point.Scale(gp_Pnt(0,0,0),GetUnitFactor());
      TopoDS_Vertex V;
      //pdn 12.03.99 S4135 Constructing vertex with minimal tolerance
      B.MakeVertex(V, point, Precision::Confusion());
      AddShapeResult(start,V);
    }
  }
  
  TopoDS_Shape Sh = GetShapeResult(start,index);
  if ( Sh.IsNull()) { 
    Message_Msg Msg1156("IGES_1156"); //"the Vertex number %d is a null object." FAIL!!!
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("vertex %d");
    Msg1156.Arg(index);
    Msg1156.Arg(label);
    SendWarning(start,Msg1156);
  }
  res = TopoDS::Vertex(Sh);
  return res;
}


//=======================================================================
//function : TransferEdge
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferEdge
  (const Handle(IGESSolid_EdgeList)& start,
   const Standard_Integer index)
{
  TopoDS_Shape res;
  BRep_Builder B;
  
  Standard_Integer nbshapes = NbShapeResult(start);
  if (nbshapes == 0) {
    IGESToBRep_TopoCurve  TC(*this);
    for (Standard_Integer inum = 1; inum <= start->NbEdges(); inum++) {
      
      // Vertices
      // --------
      Handle(IGESSolid_VertexList) thestartlist = start->StartVertexList(inum);
      Standard_Integer thestartindex = start->StartVertexIndex(inum);
      TopoDS_Vertex V1 = TransferVertex(thestartlist,thestartindex);
      
      Handle(IGESSolid_VertexList) theendlist = start->EndVertexList(inum);
      Standard_Integer theendindex = start->EndVertexIndex(inum);
      TopoDS_Vertex V2 = TransferVertex(theendlist,theendindex);
      
      // Curve
      // -----
      
      Handle(IGESData_IGESEntity)  thecurve = start->Curve(inum);
      if (thecurve.IsNull() ||
	  !IGESToBRep::IsTopoCurve(thecurve)  || 
          thecurve->IsKind(STANDARD_TYPE(IGESGeom_CurveOnSurface)) ||
	  thecurve->IsKind(STANDARD_TYPE(IGESGeom_Boundary))           ) {
	Message_Msg Msg1306("IGES_1306");//one underlying curve is a Null object.
        Msg1306.Arg(inum);
	SendWarning(start,Msg1306);
	TopoDS_Edge Sh;
	AddShapeResult(start,Sh);
      }
      else {
	TopoDS_Shape Sh = TC.TransferTopoCurve(thecurve);
	if (!Sh.IsNull()) {
	  if (Sh.ShapeType() == TopAbs_EDGE) {
	    TopoDS_Edge edge = TopoDS::Edge(Sh);
	    TopoDS_Vertex Vf,Vl;
	    TopExp::Vertices (edge, Vf, Vl);
	    TopoDS_Edge E;
	    B.MakeEdge(E);
	    TopLoc_Location    loc;
	    Standard_Real      first, last;
	    Handle(Geom_Curve) Crv  = BRep_Tool::Curve(edge, loc, first, last);
	    Handle(Geom_Curve) newC3d;
	    // dams le cas d`une conique, il faut reverser
	    // sens de parcours IGES inverse sens de parcours CASCADE.
	    if (Crv->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
	      DeclareAndCast(Geom_TrimmedCurve, acurve, Crv);
	      newC3d = acurve->BasisCurve();
	    }
	    else {
	      newC3d = Crv;
	    }
	    B.UpdateEdge(E,newC3d,loc,0.);//S4054:GetEpsGeom()*GetUnitFactor()
	    gp_Pnt p1 = BRep_Tool::Pnt ( V1 ); 
	    gp_Pnt p2 = BRep_Tool::Pnt ( V2 ); 
	    gp_Pnt pf = BRep_Tool::Pnt ( Vf ); 
	    gp_Pnt pl = BRep_Tool::Pnt ( Vl ); 
	    Standard_Real dist1f = p1.Distance ( pf );
	    Standard_Real dist2f = p2.Distance ( pf );
	    Standard_Real dist1l = p1.Distance ( pl );
	    Standard_Real dist2l = p2.Distance ( pl );
	    if ( E.Closed() || dist1f + dist2l <= dist1l + dist2f ) {
	      //:77 if (BRepTools::Compare(V1, Vf)) //the part 'else' only if, in fact, edge should be reversed
	      V1.Orientation(TopAbs_FORWARD);
	      B.Add(E,V1);
	      V2.Orientation(TopAbs_REVERSED);
	      B.Add(E,V2);
	      B.UpdateVertex(V1, first, E, 0.);//S4054 1.001 * dist1f //:77 GetEpsGeom()*GetUnitFactor();
	      B.UpdateVertex(V2, last,  E, 0.);//S4054 1.001 * dist2l //:77 GetEpsGeom()*GetUnitFactor();
	      B.Range (E, first, last);
	    }
	    // modif mjm du 13/10/97 : Reverse de l`edge ?
	    else {
	      E.Reverse();
	      V1.Orientation(TopAbs_FORWARD);
	      B.Add(E,V1);
	      V2.Orientation(TopAbs_REVERSED);
	      B.Add(E,V2);
	      B.UpdateVertex(V1, last,  E, 0.);//S4054 1.001 * dist1l //:77 GetEpsGeom()*GetUnitFactor();
	      B.UpdateVertex(V2, first, E, 0.);//S4054 1.001 * dist2f //:77 GetEpsGeom()*GetUnitFactor();
	      B.Range (E, first, last);
	    }
	    AddShapeResult(start,E);
	  }
	  else if (Sh.ShapeType() == TopAbs_WIRE) {
	    // pas traite 
	    Message_Msg Msg1325("IGES_1325"); //"Edge : result of TransferTopoCurve is WIRE"
	    Msg1325.Arg(inum);
	    SendWarning(start,Msg1325);
	    //AddWarning(start,"Edge : result of TransferTopoCurve is WIRE");
	  }
	}
	else {
	  Message_Msg Msg1156("IGES_1156");
	  Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(thecurve);
	  Msg1156.Arg("underlying curve");
	  Msg1156.Arg(label);
	  SendWarning(start,Msg1156);	    
	}
      }
    }
  }
  
  TopoDS_Shape Sh = GetShapeResult(start,index);
  if ( Sh.IsNull()) {
    Message_Msg Msg1156("IGES_1156"); 
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("edge %d");
    Msg1156.Arg(index);
    Msg1156.Arg(label);
    SendWarning(start,Msg1156);
  }
  return Sh;
}


//=======================================================================
//function : TransferLoop
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferLoop(const Handle(IGESSolid_Loop)& start,
						 const TopoDS_Face& face,
						 const gp_Trsf2d& trans,
						 const Standard_Real uFact) 
{
  TopoDS_Shape res;
  
  if (!HasShapeResult(start)) {
    TopoDS_Wire mywire;
    Standard_Boolean okCurve = Standard_True, okCurve3d = Standard_True, okCurve2d = Standard_True;
    Handle(ShapeExtend_WireData) sewd;
    Standard_Integer filepreference = 3;//3D is preferred by default
    Standard_Boolean Result = Standard_True;

    Handle(IGESToBRep_IGESBoundary) IB = IGESToBRep::AlgoContainer()->ToolContainer()->IGESBoundary();
    IB->Init (*this, start, face, trans, uFact, filepreference);
    BRep_Builder B;
    ShapeBuild_Edge sbe;
    
    for ( Standard_Integer iedge = 1; iedge <= start->NbEdges(); iedge++ ) {
      Standard_Integer itype = start->EdgeType(iedge);
      Handle(IGESData_IGESEntity)  theedge = start->Edge(iedge);
      Standard_Integer indexlist = start->ListIndex(iedge);
      Standard_Boolean orientation = start->Orientation(iedge);
      Standard_Integer nbparam = start->NbParameterCurves(iedge);
      if (theedge.IsNull()) {
	 Message_Msg Msg1365("IGES_1365"); //"Loop : one edge is null" 
	 Msg1365.Arg(iedge);
	 SendWarning(start,Msg1365);
	//	AddWarning (start,"Loop : one edge is null");
      }
      else {
	//  edge
	//  ----
	Handle(ShapeExtend_WireData) curve3d = new ShapeExtend_WireData;

	if (( itype == 1) && (theedge ->IsKind(STANDARD_TYPE(IGESSolid_VertexList)))) {
	  DeclareAndCast(IGESSolid_VertexList,thelist,theedge);
	  TopoDS_Vertex V1 = TransferVertex(thelist,indexlist);
	  TopoDS_Edge  E;
	  B.MakeEdge(E);
	  //szv#4:S4163:12Mar99 SGI warns
	  TopoDS_Shape sh = V1.Oriented(TopAbs_FORWARD);
	  B.Add(E, TopoDS::Vertex(sh));
	  sh = V1.Oriented(TopAbs_REVERSED);
	  B.Add(E, TopoDS::Vertex(sh));
	  B.Degenerated(E, Standard_True);
	  curve3d->Add (E);
	}
        else if (( itype == 0) && (theedge ->IsKind(STANDARD_TYPE(IGESSolid_EdgeList)))) {
	  DeclareAndCast(IGESSolid_EdgeList,thelist,theedge);
	  TopoDS_Shape Sh = TransferEdge(thelist,indexlist);
	  curve3d->Add (Sh);
	}
	else { 
	  Message_Msg Msg1365("IGES_1365"); //"Improper type for the edge"
	  Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
	  Msg1365.Arg(iedge);
	  SendWarning(start,Msg1365);
	  //AddWarning (start, "Improper type for the edge");   
	  continue;
	}
	if (!orientation) curve3d->Reverse();
	
	//  traitement des courbes 2d.
	//  -------------------------
	Handle(IGESData_HArray1OfIGESEntity) Curves2d;
	
	//Current limitation:
	//2D representation is not translated if:
	//- 3D curve was translated into wire (i.e. if it is 102)
	//- more than 1 2D curve,
	//- 2D curve is 102
	Handle(TColStd_HSequenceOfTransient) seq2d;
       	if (curve3d->NbEdges() == 1 && nbparam == 1 &&
	    IGESToBRep::IGESCurveToSequenceOfIGESCurve (start->ParametricCurve(iedge, 1), seq2d) == 1) {
	  Curves2d = new IGESData_HArray1OfIGESEntity (1, nbparam);
	  for (Standard_Integer i = 1; i <= nbparam; i++)
	    Curves2d->SetValue (i, start->ParametricCurve(iedge,i));
	}
	Handle(ShapeExtend_WireData) lsewd;//result of translation of current edge
	Result = Result & IB->Transfer (okCurve, okCurve3d, okCurve2d,
					curve3d, Curves2d, !orientation,
					iedge, lsewd);
	if (iedge == 1) sewd = IB->WireData();//initialization
	if (curve3d->NbEdges() == 1 && lsewd->NbEdges() == 1) {//the condition corresponds to limitation above
	  //to keep sharing of edges all geometric representations should be put
	  //into the edge from EdgeList
	  TopoDS_Edge fromedge = lsewd->Edge(1), toedge = curve3d->Edge(1);
	  if (!fromedge.IsSame (toedge)) {
	    sbe.RemoveCurve3d (toedge);
	    IGESToBRep::TransferPCurve (fromedge, toedge, face);
	    sewd->Set (toedge, sewd->Index (fromedge));
	  }
	}
      }
    }
    //IB->Check(Result, Standard_True);
    //pdn 20.04.99 CTS22655 avoid of exceptions in case of empty loops
    if(!sewd.IsNull()) {
      //IB.Fix (sewd, Standard_False, Standard_True, Standard_True, Standard_True, Standard_True);
      mywire = sewd->Wire();
    }
    SetShapeResult(start, mywire);
  }
  
  TopoDS_Shape Sh = GetShapeResult(start);
  if ( Sh.IsNull()) {
    Message_Msg Msg1156("IGES_1156"); //The Loop is null
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("loop");
    Msg1156.Arg(label);
    SendWarning(start,Msg1156);
  }
  return Sh;
}

//=======================================================================
//function : TransferFace
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferFace
  (const Handle(IGESSolid_Face)& start)
{
  TopoDS_Shape res;

  if (!HasShapeResult(start)) {
    BRep_Builder B;
    TopoDS_Face F;
    Handle(IGESData_IGESEntity) surf         = start->Surface();
    Standard_Integer            nbloops      = start->NbLoops();
    Standard_Boolean            hasouterloop = start->HasOuterLoop();
    IGESToBRep_TopoSurface TS(*this);

    // surface
    // -------
    if (surf.IsNull() || 
	!IGESToBRep::IsTopoSurface(surf) ||
	surf->IsKind(STANDARD_TYPE(IGESGeom_Plane)) ||
	surf->IsKind(STANDARD_TYPE(IGESGeom_BoundedSurface)) ||
	surf->IsKind(STANDARD_TYPE(IGESGeom_TrimmedSurface)) ||
	surf->IsKind(STANDARD_TYPE(IGESBasic_SingleParent)) ){
      Message_Msg Msg196("XSTEP_196"); //"pas de surface de base pour creer la face"
      SendWarning(start,Msg196);
      // AddWarning(start, "pas de surface de base pour creer la face");
      TopoDS_Shape Sh;
      SetShapeResult(start,Sh);
    }
    else {
      // si la surface IGES est une surface de revolution , il faudra
      // inverser les courbes 2d (u,v) pour etre en accord avec le parametrage
      // BRep.
      gp_Trsf2d trans;
      Standard_Real uFact;
      TopoDS_Shape myshape = TS.ParamSurface(surf, trans, uFact);
      
      if (!myshape.IsNull()) {
	if (myshape.ShapeType() == TopAbs_FACE) {
	  //#62 rln 10.01.99 PRO17015 (reading back IGES written in 'BRep' mode) face #65
	  F = TopoDS::Face (myshape);
	  F.EmptyCopy();
	  if (!hasouterloop) B.NaturalRestriction (F,Standard_True);
	  
	  // Loops
	  // -----
	  for (Standard_Integer iloop = 1; iloop <= nbloops; iloop++){
	    Handle(IGESSolid_Loop) loop = start->Loop(iloop);
	    TopoDS_Shape Shape = TransferLoop (loop, F, trans, uFact);
	    //pdn 20.04.99 CTS22655 avoid of exceptions in case of empty loops
	    if(!Shape.IsNull())
	      B.Add(F,Shape);
	  }

	  // update the face
	  BRepTools::Update (F);
	  F.Orientable(Standard_True);
	  SetShapeResult(start,F);
	}
      }
      else {
	Message_Msg Msg1156("IGES_1156"); //Face : result of TransferTopoSurface is Null
	Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(surf);
	Msg1156.Arg("surface");
	Msg1156.Arg(label);
	SendFail(start,Msg1156);
	//  AddWarning(start,"Face : result of TransferTopoSurface is Null");
	TopoDS_Shape Sh;
	SetShapeResult(start,Sh);
      }
    }
  }
  
  
  TopoDS_Shape Sh = GetShapeResult(start);
  if ( Sh.IsNull()) {
    Message_Msg Msg1156("IGES_1156"); //the Face is a Null object.
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("face");
    Msg1156.Arg(label);
    SendFail(start,Msg1156);     
    //    AddWarning (start, "the Face is a Null object.");
  }
  return Sh;
}


//=======================================================================
//function : TransferShell
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferShell
  (const Handle(IGESSolid_Shell)& start)
{
  TopoDS_Shape res;

  if (!HasShapeResult(start)) {
    TopoDS_Shell S;
    BRep_Builder B;
    B.MakeShell(S);
    Standard_Integer nbfaces = start->NbFaces();
    if (nbfaces != 0) {
      Standard_Boolean closed = Standard_True; //:39
      Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress();
      if ( ! progress.IsNull() ) progress->SetScale ( "Face", 0, nbfaces, 1 );
      for (Standard_Integer iface = 1; iface <= nbfaces; iface++) {
        if ( ! progress.IsNull() ) { 
          progress->Increment(); 
          if ( progress->UserBreak() ) break; 
        }
	Handle(IGESSolid_Face) face = start->Face(iface);
	Standard_Boolean orientation = start->Orientation(iface);
 	TopoDS_Shape Sh = TransferFace(face);
	if ( Sh.IsNull() ) { //:39 by abv 15.12.97
	  
	  closed = Standard_False;
	  continue;
	}
	if (!orientation) Sh.Reverse();
	B.Add(S,Sh);
      }
      if ( ! closed ) {
	Message_Msg Msg1360("IGES_1360");
	SendFail(start,Msg1360);
	
      }
	//AddWarning ( start, "Shell is not closed" ); //:39
      S.Closed ( closed ); //:39
      S.Orientable(Standard_True);
      SetShapeResult(start,S);
    }
    else {
      Message_Msg Msg200("XSTEP_200"); //Number of Faces = 0
      SendFail(start,Msg200);
    }
  }
  
  TopoDS_Shape Sh = GetShapeResult(start);
  if ( Sh.IsNull()) {
    Message_Msg Msg1156("IGES_1156"); //the Shell is a null object
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("shell");
    Msg1156.Arg(label);
    SendFail(start,Msg1156); 
  }
    //AddWarning (start, "the Shell is a null object.");
  res = Sh;
  return res;
}


//=======================================================================
//function : TransferManifoldSolid
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_BRepEntity::TransferManifoldSolid
  (const Handle(IGESSolid_ManifoldSolid)& start)
{
  TopoDS_Shape res;

  if (!HasShapeResult(start)) {
    TopoDS_Solid S;
    BRep_Builder B;
    B.MakeSolid(S);
    Handle(IGESSolid_Shell) shell = start->Shell();
    Standard_Boolean isoriented   = start->OrientationFlag();
    Standard_Integer nbshell      = start->NbVoidShells();
    TopoDS_Shape Sh = TransferShell(shell);
    if (!Sh.IsNull()) {
      if (Sh.ShapeType() == TopAbs_SHELL) {
	TopoDS_Shell Shell = TopoDS::Shell(Sh);
	if (!isoriented) Shell.Reverse();
	B.Add(S,Shell);
      }

      if (nbshell != 0) {
        // progress scope without name, since usually we have single shell in solid
        Message_ProgressSentry PS ( GetTransferProcess()->GetProgress(), 0, 0, nbshell, 1 );
	for (Standard_Integer ishell=1; ishell<= nbshell && PS.More(); ishell++, PS.Next()) {
	  Handle(IGESSolid_Shell) voidshell= start->VoidShell(ishell);
//	  Standard_Boolean orientation = start->VoidOrientationFlag(ishell);
	  TopoDS_Shape aSh = TransferShell(voidshell);
	  if (!aSh.IsNull()) {
	    if (aSh.ShapeType() == TopAbs_SHELL) {
	      TopoDS_Shell Shell = TopoDS::Shell(aSh);
	      if (!isoriented) Shell.Reverse();
	      B.Add(S,Shell);
	    }
	  }
	  else {
	  //  AddWarning(start,"ManifoldSolid : one VoidShell is Null");
	    TopoDS_Shell Shell;
	    B.Add(S,Shell);
	  }
	}    
      }
    }
    SetShapeResult(start,S);
  }

  TopoDS_Shape Sh = GetShapeResult(start);
  if ( Sh.IsNull()) {
    Message_Msg Msg1156("IGES_1156"); //the ManifoldSolid is a null object.
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
    Msg1156.Arg("solid");
    Msg1156.Arg(label);
    SendFail(start,Msg1156);  
  }
 //   AddWarning (start, "the ManifoldSolid is a null object.");
  res = Sh;
  return res;
}