0033039: Coding - get rid of unused headers [StepData to StlAPI]
[occt.git] / src / StepToTopoDS / StepToTopoDS_Builder.cxx
1 // Created on: 1995-01-03
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GeometricSet
18 //gka 11.01.99 file PRO7755.stp #2018: work-around error in BRepLib_MakeFace
19 //:n4 abv 12.02.99: S4132: treatment of GEOMETRIC_SETs implemented
20 //:o7 abv 18.02.99: bm1_sy_fuel.stp #1427(items 1,2) protection against null entity
21 //abv,gka 05.04.99 S4136: parameter names changed; avoid extra call to FixSameParameter
22
23 #include <BRep_Builder.hxx>
24 #include <BRepBuilderAPI_MakeEdge.hxx>
25 #include <BRepBuilderAPI_MakeFace.hxx>
26 #include <BRepBuilderAPI_MakeVertex.hxx>
27 #include <BRepLib.hxx>
28 #include <Geom_CartesianPoint.hxx>
29 #include <Geom_Curve.hxx>
30 #include <Geom_RectangularTrimmedSurface.hxx>
31 #include <Geom_Surface.hxx>
32 #include <Interface_Static.hxx>
33 #include <Message_Messenger.hxx>
34 #include <Message_ProgressScope.hxx>
35 #include <Precision.hxx>
36 #include <ShapeFix_ShapeTolerance.hxx>
37 #include <Standard_ErrorHandler.hxx>
38 #include <Standard_Failure.hxx>
39 #include <StdFail_NotDone.hxx>
40 #include <STEPControl_ActorRead.hxx>
41 #include <StepGeom_CompositeCurve.hxx>
42 #include <StepGeom_Curve.hxx>
43 #include <StepGeom_CurveBoundedSurface.hxx>
44 #include <StepGeom_GeometricRepresentationItem.hxx>
45 #include <StepGeom_RectangularCompositeSurface.hxx>
46 #include <StepGeom_Surface.hxx>
47 #include <StepGeom_SurfacePatch.hxx>
48 #include <StepShape_BrepWithVoids.hxx>
49 #include <StepShape_ClosedShell.hxx>
50 #include <StepShape_EdgeBasedWireframeModel.hxx>
51 #include <StepShape_FaceBasedSurfaceModel.hxx>
52 #include <StepShape_FaceSurface.hxx>
53 #include <StepShape_FacetedBrep.hxx>
54 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
55 #include <StepShape_GeometricSet.hxx>
56 #include <StepShape_GeometricSetSelect.hxx>
57 #include <StepShape_HArray1OfConnectedEdgeSet.hxx>
58 #include <StepShape_HArray1OfConnectedFaceSet.hxx>
59 #include <StepShape_HArray1OfEdge.hxx>
60 #include <StepShape_HArray1OfFace.hxx>
61 #include <StepShape_ManifoldSolidBrep.hxx>
62 #include <StepShape_OpenShell.hxx>
63 #include <StepShape_OrientedClosedShell.hxx>
64 #include <StepShape_ShellBasedSurfaceModel.hxx>
65 #include <StepVisual_TessellatedFace.hxx>
66 #include <StepVisual_TessellatedShell.hxx>
67 #include <StepVisual_TessellatedSolid.hxx>
68 #include <StepToGeom.hxx>
69 #include <StepToTopoDS_Builder.hxx>
70 #include <StepToTopoDS_NMTool.hxx>
71 #include <StepToTopoDS_Tool.hxx>
72 #include <StepToTopoDS_TranslateCompositeCurve.hxx>
73 #include <StepToTopoDS_TranslateCurveBoundedSurface.hxx>
74 #include <StepToTopoDS_TranslateEdge.hxx>
75 #include <StepToTopoDS_TranslateFace.hxx>
76 #include <StepToTopoDS_TranslateShell.hxx>
77 #include <StepToTopoDS_TranslateSolid.hxx>
78 #include <TopExp_Explorer.hxx>
79 #include <TopoDS.hxx>
80 #include <TopoDS_Compound.hxx>
81 #include <TopoDS_Edge.hxx>
82 #include <TopoDS_Face.hxx>
83 #include <TopoDS_Shape.hxx>
84 #include <TopoDS_Shell.hxx>
85 #include <TopoDS_Solid.hxx>
86 #include <Transfer_ActorOfTransientProcess.hxx>
87 #include <Transfer_TransientProcess.hxx>
88 #include <TransferBRep.hxx>
89
90 #include <stdio.h>
91 static void ResetPreci (const TopoDS_Shape& S, Standard_Real maxtol)
92 {
93   //:S4136
94   Standard_Integer modetol = Interface_Static::IVal("read.maxprecision.mode");
95   if (modetol) {
96     ShapeFix_ShapeTolerance STU;
97     STU.LimitTolerance (S,Precision::Confusion(),maxtol);
98   }
99 }
100
101 // ============================================================================
102 // Method  : StepToTopoDS_Builder::StepToTopoDS_Builder
103 // Purpose : Empty constructor
104 // ============================================================================
105
106 StepToTopoDS_Builder::StepToTopoDS_Builder()
107 : myError(StepToTopoDS_BuilderOther)
108 {
109   done = Standard_False;
110 }
111
112 // ============================================================================
113 // Method  : Init
114 // Purpose : Init with a ManifoldSolidBrep
115 // ============================================================================
116
117 void StepToTopoDS_Builder::Init
118 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
119  const Handle(Transfer_TransientProcess)& TP,
120  const Message_ProgressRange& theProgress)
121 {
122   Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
123   // Initialisation of the Tool
124
125   StepToTopoDS_Tool         myTool;
126   StepToTopoDS_DataMapOfTRI aMap;
127
128   myTool.Init(aMap, TP);
129
130   // Start Mapping
131
132   Handle(StepShape_ConnectedFaceSet) aShell;
133   aShell = aManifoldSolid->Outer();
134
135   StepToTopoDS_TranslateShell myTranShell;
136   myTranShell.SetPrecision(Precision());
137   myTranShell.SetMaxTol(MaxTol());
138   // Non-manifold topology is not referenced by ManifoldSolidBrep (ssv; 14.11.2010)
139   StepToTopoDS_NMTool dummyNMTool;
140   myTranShell.Init(aShell, myTool, dummyNMTool, theProgress);
141
142   if (myTranShell.IsDone()) {
143     TopoDS_Shape Sh = myTranShell.Value();
144     Sh.Closed(Standard_True);
145     //BRepLib::SameParameter(Sh);
146     TopoDS_Solid S;
147     BRep_Builder B;
148     B.MakeSolid(S);
149     B.Add(S,Sh);
150     myResult = S;
151     myError  = StepToTopoDS_BuilderDone;
152     done     = Standard_True;
153
154     // Get Statistics :
155
156     if ( TP->TraceLevel() > 2 )
157     {
158       sout << "Geometric Statistics : " << std::endl;
159       sout << "   Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl;
160       sout << "                        - C1 : " << myTool.C1Surf() << std::endl;
161       sout << "                        - C2 : " << myTool.C2Surf() << std::endl;
162       sout << "   Curve Continuity :   - C0 : " << myTool.C0Cur3() << std::endl;
163       sout << "                        - C1 : " << myTool.C1Cur3() << std::endl;
164       sout << "                        - C2 : " << myTool.C2Cur3() << std::endl;
165       sout << "   PCurve Continuity :  - C0 : " << myTool.C0Cur2() << std::endl;
166       sout << "                        - C1 : " << myTool.C1Cur2() << std::endl;
167       sout << "                        - C2 : " << myTool.C2Cur2() << std::endl;
168     }
169
170 //:S4136    ShapeFix::SameParameter (S,Standard_False);
171     ResetPreci (S, MaxTol());
172   }
173   else {
174     TP->AddWarning(aShell," OuterShell from ManifoldSolidBrep not mapped to TopoDS");
175     myError  = StepToTopoDS_BuilderOther;
176     done     = Standard_False;
177   }
178 }
179
180 // ============================================================================
181 // Method  : Init
182 // Purpose : Init with a BrepWithVoids
183 // ============================================================================
184
185 void StepToTopoDS_Builder::Init
186 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
187  const Handle(Transfer_TransientProcess)& TP,
188  const Message_ProgressRange& theProgress)
189 {
190   Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
191  // Initialisation of the Tool
192   StepToTopoDS_Tool         myTool;
193   StepToTopoDS_DataMapOfTRI aMap;
194
195   myTool.Init(aMap, TP);
196
197   // Start Mapping
198
199   Standard_Integer Nb = aBRepWithVoids->NbVoids();
200   Handle(StepShape_ClosedShell) aCShell;
201   TopoDS_Solid S;
202   TopoDS_Shape Sh;
203   BRep_Builder B;
204   B.MakeSolid(S);
205   
206   Message_ProgressScope PS (theProgress, "Shell", Nb+1);
207
208   StepToTopoDS_TranslateShell myTranShell;
209
210   myTranShell.SetPrecision(Precision());//gka
211   myTranShell.SetMaxTol(MaxTol());
212   // OuterBound
213
214   aCShell = Handle(StepShape_ClosedShell)::DownCast(aBRepWithVoids->Outer());
215   // Non-manifold topology is not referenced by BrepWithVoids (ssv; 14.11.2010)
216   StepToTopoDS_NMTool dummyNMTool;
217   myTranShell.Init(aCShell, myTool, dummyNMTool, PS.Next());
218
219   if (myTranShell.IsDone()) {
220     Sh = myTranShell.Value();
221     Sh.Closed(Standard_True);
222     //BRepLib::SameParameter(Sh);
223     B.MakeSolid(S);
224     B.Add(S,Sh);
225     myResult = S;
226     myError  = StepToTopoDS_BuilderDone;
227     done     = Standard_True;
228   }
229   else {
230     TP->AddWarning(aCShell," OuterShell from BrepWithVoids not mapped to TopoDS");
231     myError  = StepToTopoDS_BuilderOther;
232     done     = Standard_False;
233     return;
234   }
235
236   // Voids
237
238   for (Standard_Integer i=1; i<=Nb && PS.More(); i++) {
239
240     aCShell = aBRepWithVoids->VoidsValue(i);
241     myTranShell.Init(aCShell, myTool, dummyNMTool, PS.Next());
242     if (myTranShell.IsDone()) {
243       Sh = myTranShell.Value();
244       Sh.Closed(Standard_True);
245
246       //:e0 abv 25 Mar 98: void should be an OrientedShell 
247       Handle(StepShape_OrientedClosedShell) aOCShell = aBRepWithVoids->VoidsValue(i);
248       if ( ! aOCShell.IsNull() && ! aOCShell->Orientation() ) Sh.Reverse();
249       
250       //BRepLib::SameParameter(Sh);
251       B.Add(S,Sh);
252     }
253     else {
254       TP->AddWarning
255         (aCShell," A Void from BrepWithVoids not mapped to TopoDS");
256     }
257   }
258   myResult = S;
259
260
261   // Get Statistics :
262   
263   if ( TP->TraceLevel() > 2 )
264   {
265     sout << "Geometric Statistics : " << std::endl;
266     sout << "   Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl;
267     sout << "                        - C1 : " << myTool.C1Surf() << std::endl;
268     sout << "                        - C2 : " << myTool.C2Surf() << std::endl;
269     sout << "   Curve Continuity :   - C0 : " << myTool.C0Cur3() << std::endl;
270     sout << "                        - C1 : " << myTool.C1Cur3() << std::endl;
271     sout << "                        - C2 : " << myTool.C2Cur3() << std::endl;
272     sout << "   PCurve Continuity :  - C0 : " << myTool.C0Cur2() << std::endl;
273     sout << "                        - C1 : " << myTool.C1Cur2() << std::endl;
274     sout << "                        - C2 : " << myTool.C2Cur2() << std::endl;
275   }
276
277 //:S4136  ShapeFix::SameParameter (S,Standard_False);
278   ResetPreci (S, MaxTol());
279 }
280
281 // ============================================================================
282 // Method  : Init
283 // Purpose : Init with a FacetedBrep
284 // ============================================================================
285
286 void StepToTopoDS_Builder::Init(const Handle(StepShape_FacetedBrep)& aFB,
287                                 const Handle(Transfer_TransientProcess)& TP,
288                                 const Message_ProgressRange& theProgress)
289 {
290   // Initialisation of the Tool
291
292   StepToTopoDS_Tool         myTool;
293   StepToTopoDS_DataMapOfTRI aMap;
294
295   myTool.Init(aMap, TP);
296
297   // Start Mapping
298
299   Handle(StepShape_ClosedShell) aCShell;
300   aCShell = Handle(StepShape_ClosedShell)::DownCast(aFB->Outer());
301   TopoDS_Shape Sh;
302
303   StepToTopoDS_TranslateShell myTranShell; 
304   myTranShell.SetPrecision(Precision()); //gka
305   myTranShell.SetMaxTol(MaxTol());  
306   // Non-manifold topology is not referenced by FacetedBrep (ss; 14.11.2010)
307   StepToTopoDS_NMTool dummyNMTool;
308   myTranShell.Init(aCShell, myTool, dummyNMTool, theProgress);
309
310   if (myTranShell.IsDone()) {
311     Sh = myTranShell.Value();
312     Sh.Closed(Standard_True);
313     //BRepLib::SameParameter(Sh);
314     myTool.ClearEdgeMap();
315     myTool.ClearVertexMap();
316     TopoDS_Solid S;
317     BRep_Builder B;
318     B.MakeSolid(S);
319     B.Add(S,Sh);
320     myResult = S;
321     myError  = StepToTopoDS_BuilderDone;
322     done     = Standard_True;
323   }
324   else {
325     TP->AddWarning
326       (aCShell," OuterShell from FacetedBrep not mapped to TopoDS");
327     myError  = StepToTopoDS_BuilderOther;
328     done     = Standard_True;
329   }
330 }
331
332 // ============================================================================
333 // Method  : Init
334 // Purpose : Init with a FacetedBrepAndBrepWithVoids
335 // ============================================================================
336
337 void StepToTopoDS_Builder::Init
338 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
339  const Handle(Transfer_TransientProcess)& TP,
340  const Message_ProgressRange& theProgress)
341 {
342   // Initialisation of the Tool
343
344   StepToTopoDS_Tool         myTool;
345   StepToTopoDS_DataMapOfTRI aMap;
346
347   myTool.Init(aMap, TP);
348
349   // Start Mapping
350
351   Handle(StepShape_ClosedShell) aCShell;
352   aCShell = Handle(StepShape_ClosedShell)::DownCast(aFBABWV->Outer());
353   TopoDS_Shape Sh;
354
355   Message_ProgressScope aPSRoot(theProgress, NULL, 2);
356
357   StepToTopoDS_TranslateShell myTranShell;
358   myTranShell.SetPrecision(Precision()); //gka
359   myTranShell.SetMaxTol(MaxTol());
360   // Non-manifold topology is not referenced by FacetedBrepAndBrepWithVoids (ss; 14.11.2010)
361   StepToTopoDS_NMTool dummyNMTool;
362   myTranShell.Init(aCShell, myTool, dummyNMTool, aPSRoot.Next());
363
364   if (myTranShell.IsDone()) {
365     Sh = myTranShell.Value();
366     Sh.Closed(Standard_True);
367     //BRepLib::SameParameter(Sh);
368     TopoDS_Solid S;
369     BRep_Builder B;
370     B.MakeSolid(S);
371     B.Add(S,Sh);
372     Standard_Integer Nb, i;
373     Nb = aFBABWV->NbVoids();
374     Message_ProgressScope aPS (aPSRoot.Next(), NULL, Nb);
375     for ( i=1; i<=Nb && aPS.More(); i++) {
376       aCShell = aFBABWV->VoidsValue(i);
377       myTranShell.Init(aCShell, myTool, dummyNMTool, aPS.Next());
378       if (myTranShell.IsDone()) {
379         Sh = myTranShell.Value();
380         Sh.Closed(Standard_True);
381         //BRepLib::SameParameter(Sh);
382         B.Add(S, Sh);
383       }
384       else {
385         TP->AddWarning
386           (aCShell," A Void from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
387       }
388     }
389     myResult = S;
390     myError  = StepToTopoDS_BuilderDone;
391     done     = Standard_True;
392   }
393   else {
394     TP->AddWarning
395       (aCShell," OuterShell from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
396     done    = Standard_False;
397     myError = StepToTopoDS_BuilderOther;
398   }
399 }
400
401 // ============================================================================
402 // Method  : Init
403 // Purpose : Init with a ShellBasedSurfaceModel
404 // ============================================================================
405
406 void StepToTopoDS_Builder::Init
407 (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM,
408  const Handle(Transfer_TransientProcess)& TP,
409  StepToTopoDS_NMTool& NMTool,
410  const Message_ProgressRange& theProgress)
411 {
412   Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
413   // Initialisation of the Tool
414
415   StepToTopoDS_Tool         myTool;
416   StepToTopoDS_DataMapOfTRI aMap;
417
418   myTool.Init(aMap, TP);
419
420   // Start Mapping
421
422   Standard_Integer Nb = aSBSM->NbSbsmBoundary();
423   StepShape_Shell aShell;
424   //Handle(StepShape_VertexShell) aVertexShell;
425   Handle(StepShape_OpenShell)   aOpenShell;
426   Handle(StepShape_ClosedShell) aClosedShell;
427   TopoDS_Compound S;
428   //TopoDS_Shape Sh;
429   TopoDS_Shape Shl;
430   BRep_Builder B;
431   B.MakeCompound(S);
432   StepToTopoDS_TranslateShell myTranShell;
433   
434   myTranShell.SetPrecision(Precision());
435   myTranShell.SetMaxTol(MaxTol());
436
437   Message_ProgressScope PS ( theProgress, "Shell", Nb);
438   for (Standard_Integer i = 1; i <= Nb && PS.More(); i++)
439   {
440     Message_ProgressRange aRange = PS.Next();
441     aShell = aSBSM->SbsmBoundaryValue(i);
442     aOpenShell = aShell.OpenShell();
443     aClosedShell = aShell.ClosedShell();
444     if (!aOpenShell.IsNull()) {
445       myTranShell.Init(aOpenShell, myTool, NMTool, aRange);
446       if (myTranShell.IsDone()) {
447         Shl = TopoDS::Shell(myTranShell.Value());
448         Shl.Closed(Standard_False);
449         B.Add(S, Shl);
450       }
451       else {
452         TP->AddWarning
453           (aOpenShell, " OpenShell from ShellBasedSurfaceModel not mapped to TopoDS");
454       }
455     }
456     else if (!aClosedShell.IsNull()) {
457       myTranShell.Init(aClosedShell, myTool, NMTool, aRange);
458       if (myTranShell.IsDone()) {
459         Shl = TopoDS::Shell(myTranShell.Value());
460         Shl.Closed(Standard_True);
461         B.Add(S, Shl);
462       }
463       else {
464         TP->AddWarning
465           (aClosedShell, " ClosedShell from ShellBasedSurfaceModel not mapped to TopoDS");
466       }
467     }
468   }
469   if(Nb>1)
470     myResult = S;
471   else
472     myResult = Shl;
473   myError  = StepToTopoDS_BuilderDone;
474   done     = Standard_True;
475
476   // Get Statistics :
477   
478   if ( TP->TraceLevel() > 2 )
479   {
480     sout << "Geometric Statistics : " << std::endl;
481     sout << "   Surface Continuity : - C0 : " << myTool.C0Surf() << std::endl;
482     sout << "                        - C1 : " << myTool.C1Surf() << std::endl;
483     sout << "                        - C2 : " << myTool.C2Surf() << std::endl;
484     sout << "   Curve Continuity :   - C0 : " << myTool.C0Cur3() << std::endl;
485     sout << "                        - C1 : " << myTool.C1Cur3() << std::endl;
486     sout << "                        - C2 : " << myTool.C2Cur3() << std::endl;
487     sout << "   PCurve Continuity :  - C0 : " << myTool.C0Cur2() << std::endl;
488     sout << "                        - C1 : " << myTool.C1Cur2() << std::endl;
489     sout << "                        - C2 : " << myTool.C2Cur2() << std::endl;
490   }
491
492 //:S4136  ShapeFix::SameParameter (S,Standard_False);
493   ResetPreci (S, MaxTol());
494   ResetPreci (Shl, MaxTol()); //skl
495 }
496
497 // ============================================================================
498 // Method  : Init
499 // Purpose : Init with a EdgeBasedWireframeModel
500 // ============================================================================
501
502 void StepToTopoDS_Builder::Init (const Handle(StepShape_EdgeBasedWireframeModel)& aEBWM,
503                                  const Handle(Transfer_TransientProcess)& TP)
504 {
505   myResult.Nullify();
506   
507   Handle(StepShape_HArray1OfConnectedEdgeSet) boundary = aEBWM->EbwmBoundary();
508   if ( boundary.IsNull() || boundary->Length() <1 ) {
509     TP->AddWarning ( aEBWM, "List of boundaries is empty" );
510     return;
511   }
512
513   StepToTopoDS_Tool myTool;
514   StepToTopoDS_DataMapOfTRI aMap;
515   myTool.Init(aMap, TP);
516
517   StepToTopoDS_TranslateEdge myTranEdge;
518   myTranEdge.SetPrecision(Precision());
519   myTranEdge.SetMaxTol(MaxTol());
520   
521   TopoDS_Compound C;
522   BRep_Builder B;
523   B.MakeCompound ( C );
524
525   StepToTopoDS_NMTool dummyNMTool;
526   
527   for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
528     Handle(StepShape_ConnectedEdgeSet) ces = boundary->Value(i);
529     if ( ces.IsNull() ) continue;
530     Handle(StepShape_HArray1OfEdge) edges = ces->CesEdges();
531     if ( edges.IsNull() || edges->Length() <1 ) {
532       TP->AddWarning ( ces, "No edges in connected_edge_set" );
533       continue;
534     }
535     TopoDS_Wire W;
536     for ( Standard_Integer j=1; j <= edges->Length(); j++ ) {
537       myTranEdge.Init (edges->Value(j), myTool, dummyNMTool);
538       if ( ! myTranEdge.IsDone() ) continue;
539       TopoDS_Edge E = TopoDS::Edge(myTranEdge.Value());
540       if (E.IsNull()) continue;  // NULL, on saute
541       if ( W.IsNull() ) B.MakeWire ( W );
542       B.Add ( W, E );
543     }
544     if ( W.IsNull() ) continue;
545     W.Closed (BRep_Tool::IsClosed (W));
546     B.Add ( C, W );
547     if ( myResult.IsNull() ) myResult = W;
548     else myResult = C;
549   }
550   
551   myError  = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
552   done     = ! myResult.IsNull();
553
554   ResetPreci (myResult, MaxTol());
555 }
556
557 // ============================================================================
558 // Method  : Init
559 // Purpose : Init with a FaceBasedSurfaceModel
560 // ============================================================================
561
562 void StepToTopoDS_Builder::Init (const Handle(StepShape_FaceBasedSurfaceModel)& aFBSM,
563                                  const Handle(Transfer_TransientProcess)& TP)
564 {
565   myResult.Nullify();
566   
567   Handle(StepShape_HArray1OfConnectedFaceSet) boundary = aFBSM->FbsmFaces();
568   if ( boundary.IsNull() || boundary->Length() <1 ) {
569     TP->AddWarning ( aFBSM, "List of faces is empty" );
570     return;
571   }
572
573   StepToTopoDS_Tool myTool;
574   StepToTopoDS_DataMapOfTRI aMap;
575   myTool.Init(aMap, TP);
576
577   StepToTopoDS_TranslateFace myTranFace;
578   myTranFace.SetPrecision(Precision());
579   myTranFace.SetMaxTol(MaxTol());
580   
581   TopoDS_Compound C;
582   BRep_Builder B;
583   B.MakeCompound ( C );
584
585   // Non-manifold topology is not mapped via FaceBasedSurfaceModel (ssv; 14.11.2010)
586   StepToTopoDS_NMTool dummyNMTool;
587   
588   for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
589     Handle(StepShape_ConnectedFaceSet) cfs = boundary->Value(i);
590     if ( cfs.IsNull() ) continue;
591     Handle(StepShape_HArray1OfFace) faces = cfs->CfsFaces();
592     if ( faces.IsNull() || faces->Length() <1 ) {
593       TP->AddWarning ( cfs, "No faces in connected_face_set" );
594       continue;
595     }
596     TopoDS_Shell S;
597     for ( Standard_Integer j=1; j <= faces->Length(); j++ ) {
598       Handle(StepShape_FaceSurface) fs = Handle(StepShape_FaceSurface)::DownCast ( faces->Value(j) );
599       myTranFace.Init(fs, myTool, dummyNMTool);
600       if ( ! myTranFace.IsDone() ) continue;
601       TopoDS_Face F = TopoDS::Face(myTranFace.Value());
602       if (F.IsNull()) continue;  // NULL, on saute
603       if ( S.IsNull() ) B.MakeShell ( S );
604       B.Add ( S, F );
605     }
606     if ( S.IsNull() ) continue;
607     S.Closed (BRep_Tool::IsClosed (S));
608     B.Add ( C, S );
609     if ( myResult.IsNull() ) myResult = S;
610     else myResult = C;
611   }
612   
613   myError  = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
614   done     = ! myResult.IsNull();
615
616   ResetPreci (myResult, MaxTol());
617 }
618
619
620 // ***start DTH Apr/6
621 // ============================================================================
622 // Method  : Init
623 // Purpose : Init with a GeometricCurveSet
624 // ============================================================================
625 //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GS: GeometricCurveSet -> GeometricSet
626
627 static TopoDS_Face TranslateBoundedSurf (const Handle(StepGeom_Surface) &surf,
628                                          const Standard_Real TolDegen)
629 {
630   TopoDS_Face res;
631
632   Handle(Geom_Surface) theSurf = StepToGeom::MakeSurface (surf);
633   if (theSurf.IsNull() || //:i6: protection
634       !theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) return res;
635
636   BRepBuilderAPI_MakeFace myMkFace;
637   Handle(Geom_RectangularTrimmedSurface) RS = 
638                     Handle(Geom_RectangularTrimmedSurface)::DownCast(theSurf);
639
640   if (!RS.IsNull())
641   {
642     Standard_Real umin, umax, vmin, vmax;
643     theSurf->Bounds(umin, umax, vmin, vmax);
644
645     myMkFace.Init(RS->BasisSurface(), umin, umax, vmin, vmax, TolDegen);
646   }
647   else
648   {
649     myMkFace.Init(theSurf, Standard_True, TolDegen);
650   }
651
652   return myMkFace.Face();
653 }
654
655 void StepToTopoDS_Builder::Init
656 (const Handle(StepShape_GeometricSet)& GCS,
657  const Handle(Transfer_TransientProcess)& TP,
658  const Handle(Transfer_ActorOfTransientProcess)& RA,
659  const Standard_Boolean isManifold,
660  const Message_ProgressRange& theProgress)
661 {
662   // Start Mapping
663   TopoDS_Compound S;
664   BRep_Builder B;
665   B.MakeCompound(S);
666   TopoDS_Edge theEdge;
667   Standard_Integer i;
668   Standard_Real preci = Precision();   //gka
669   Standard_Real maxtol = MaxTol();
670   Standard_Integer nbElem = GCS->NbElements();
671   Message_ProgressScope aPS(theProgress, NULL, nbElem);
672   for (i = 1; i <= nbElem && aPS.More(); i++)
673   {
674     Message_ProgressRange aRange = aPS.Next();
675     StepShape_GeometricSetSelect aGSS = GCS->ElementsValue(i);
676     Handle(Standard_Transient) ent = aGSS.Value();
677
678     TopoDS_Shape res = TransferBRep::ShapeResult ( TP, ent );
679     if ( ! res.IsNull() ) { // already translated
680       B.Add ( S, res );
681       continue;
682     }
683     //:o7 abv 18 Feb 99: bm1_sy_fuel.stp #1427(1,2) protection against null entity
684     if ( ent.IsNull() ) {
685       char buff[100];
686       sprintf ( buff, "Entity %d is a Null entity", i );
687       TP->AddWarning (GCS,buff);
688       continue;
689     } 
690     // try curve
691     else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Curve)) ) {
692       Handle(StepGeom_Curve) aCrv = Handle(StepGeom_Curve)::DownCast ( ent );
693
694       // try composite_curve
695       Handle(StepGeom_CompositeCurve) CC = Handle(StepGeom_CompositeCurve)::DownCast(aCrv);
696       if (!CC.IsNull()) {
697         StepToTopoDS_TranslateCompositeCurve TrCC;
698         TrCC.SetPrecision(preci);
699         TrCC.SetMaxTol(maxtol);
700         TrCC.Init(CC, TP);
701         if (TrCC.IsDone())
702         {
703           if (TrCC.IsInfiniteSegment())
704           {
705             BRep_Builder aB;
706             TopoDS_Compound aComp;
707             aB.MakeCompound(aComp);
708             TopExp_Explorer anExp;
709             for (anExp.Init(TrCC.Value(), TopAbs_EDGE); anExp.More(); anExp.Next())
710               aB.Add(aComp, anExp.Current());
711             res = aComp;
712           }
713           else
714             res = TrCC.Value();
715         }
716       }
717       else { // try other curves
718         Handle(Geom_Curve) aGeomCrv;
719         try {
720           OCC_CATCH_SIGNALS
721             aGeomCrv = StepToGeom::MakeCurve(aCrv);
722         }
723         catch (Standard_Failure const& anException) {
724           Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
725           sout << "StepToTopoDS, GeometricSet, elem " << i << " of " << nbElem << ": exception ";
726           sout << anException.GetMessageString() << std::endl;
727         }
728         if (!aGeomCrv.IsNull()) {
729           BRepBuilderAPI_MakeEdge anEdge(aGeomCrv, aGeomCrv->FirstParameter(), aGeomCrv->LastParameter());
730           if (anEdge.IsDone()) res = anEdge.Edge();
731         }
732       }
733     }
734     // try point
735     else if ( ent->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint)) ) {
736       Handle(StepGeom_CartesianPoint) aPnt = Handle(StepGeom_CartesianPoint)::DownCast ( ent );
737       Handle(Geom_CartesianPoint) thePnt = StepToGeom::MakeCartesianPoint (aPnt);
738       if (! thePnt.IsNull()) {
739         BRepBuilderAPI_MakeVertex myMkVtx(thePnt->Pnt());
740         if ( myMkVtx.IsDone() ) res = myMkVtx.Vertex();
741       }
742     }
743     // Element should finally be a Surface
744     else if (ent->IsKind(STANDARD_TYPE(StepGeom_Surface))) {
745       Handle(StepGeom_Surface) aSurf =
746         Handle(StepGeom_Surface)::DownCast(ent);
747
748       // try curve_bounded_surf
749       if (ent->IsKind(STANDARD_TYPE(StepGeom_CurveBoundedSurface))) {
750         Handle(StepGeom_CurveBoundedSurface) CBS =
751           Handle(StepGeom_CurveBoundedSurface)::DownCast(aSurf);
752         StepToTopoDS_TranslateCurveBoundedSurface TrCBS;
753         TrCBS.SetPrecision(preci);
754         TrCBS.SetMaxTol(maxtol);
755
756         TrCBS.Init(CBS, TP);
757         if (TrCBS.IsDone()) res = TrCBS.Value();
758       }
759       // try RectangularCompositeSurface
760       else if (ent->IsKind(STANDARD_TYPE(StepGeom_RectangularCompositeSurface))) {
761         Handle(StepGeom_RectangularCompositeSurface) RCS =
762           Handle(StepGeom_RectangularCompositeSurface)::DownCast(aSurf);
763         Standard_Integer nbi = RCS->NbSegmentsI();
764         Standard_Integer nbj = RCS->NbSegmentsJ();
765         TopoDS_Compound C;
766         B.MakeCompound(C);
767         for (Standard_Integer ii = 1; ii <= nbi; ii++)
768           for (Standard_Integer j = 1; j <= nbj; j++) {
769             Handle(StepGeom_SurfacePatch) patch = RCS->SegmentsValue(ii, j);
770             TopoDS_Face f = TranslateBoundedSurf(patch->ParentSurface(), preci);
771             if (!f.IsNull()) B.Add(C, f);
772           }
773         res = C;
774       }
775       // try other surfs
776       else res = TranslateBoundedSurf(aSurf, preci);
777     }
778     else if ( ent->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) )
779     {
780       Handle(StepGeom_GeometricRepresentationItem) GRI = 
781         Handle(StepGeom_GeometricRepresentationItem)::DownCast(ent);
782       if (!RA.IsNull())
783       {
784         Handle(STEPControl_ActorRead) anActor = Handle(STEPControl_ActorRead)::DownCast(RA);
785         Handle(Transfer_Binder) binder;
786         if( !anActor.IsNull())
787           binder = anActor->TransferShape(GRI, TP, isManifold, Standard_False, aRange);
788         if (!binder.IsNull())
789         {
790           res = TransferBRep::ShapeResult(binder);
791         }
792       }
793     }
794     else TP->AddWarning (ent," Entity is not a Curve, Point, Surface or GeometricRepresentationItem");
795     if ( ! res.IsNull() ) {
796       B.Add(S, res);
797       TransferBRep::SetShapeResult ( TP, ent, res );
798     }
799     else TP->AddWarning (ent," Entity not mapped to TopoDS");
800   }
801   myResult = S;
802   myError  = StepToTopoDS_BuilderDone;
803   done     = Standard_True;
804 }
805 // ***end DTH Apr/6 
806
807 // ============================================================================
808 // Method  : StepToTopoDS_Builder::Init
809 // Purpose : Builds a TopoDS_Solid from StepVisual_TessellatedSolid
810 // ============================================================================
811
812 void StepToTopoDS_Builder::Init(const Handle(StepVisual_TessellatedSolid)& theTSo,
813                                 const Handle(Transfer_TransientProcess)& theTP,
814                                 const Standard_Boolean theReadTessellatedWhenNoBRepOnly,
815                                 Standard_Boolean& theHasGeom,
816                                 const Message_ProgressRange& theProgress)
817 {
818   StepToTopoDS_TranslateSolid aTranSolid;
819   aTranSolid.SetPrecision(Precision());
820   aTranSolid.SetMaxTol(MaxTol());
821
822   StepToTopoDS_Tool aTool;
823   StepToTopoDS_DataMapOfTRI aMap;
824   aTool.Init(aMap, theTP);
825
826   StepToTopoDS_NMTool dummyNMTool;
827   aTranSolid.Init(theTSo, theTP, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly, 
828                   theHasGeom, theProgress);
829
830   if (aTranSolid.IsDone()) 
831   {
832     TopoDS_Shape aS = aTranSolid.Value();
833     TransferBRep::SetShapeResult(theTP, theTSo, aS);
834     myResult = TopoDS::Solid(aS);
835     myError = StepToTopoDS_BuilderDone;
836     done = Standard_True;
837   }
838   else
839   {
840     theTP->AddWarning(theTSo, " TessellatedSolid not mapped to TopoDS");
841     myError = StepToTopoDS_BuilderOther;
842     done = Standard_True;
843   }
844 }
845
846 // ============================================================================
847 // Method  : StepToTopoDS_Builder::Init
848 // Purpose : Builds a TopoDS_Shell from StepVisual_TessellatedShell
849 // ============================================================================
850
851 void StepToTopoDS_Builder::Init(const Handle(StepVisual_TessellatedShell)& theTSh,
852                                 const Handle(Transfer_TransientProcess)& theTP,
853                                 const Standard_Boolean theReadTessellatedWhenNoBRepOnly,
854                                 Standard_Boolean& theHasGeom,
855                                 const Message_ProgressRange& theProgress)
856 {
857   StepToTopoDS_TranslateShell aTranShell;
858   aTranShell.SetPrecision(Precision());
859   aTranShell.SetMaxTol(MaxTol());
860
861   StepToTopoDS_Tool aTool;
862   StepToTopoDS_DataMapOfTRI aMap;
863   aTool.Init(aMap, theTP);
864
865   StepToTopoDS_NMTool dummyNMTool;
866   aTranShell.Init(theTSh, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly, 
867                   theHasGeom, theProgress);
868
869   if (aTranShell.IsDone()) 
870   {
871     TopoDS_Shape aS = aTranShell.Value();
872     TransferBRep::SetShapeResult(theTP, theTSh, aS);
873     myResult = TopoDS::Shell(aS);
874     myError = StepToTopoDS_BuilderDone;
875     done = Standard_True;
876   }
877   else 
878   {
879     theTP->AddWarning(theTSh, " TessellatedShell not mapped to TopoDS");
880     myError = StepToTopoDS_BuilderOther;
881     done = Standard_True;
882   }
883 }
884
885 // ============================================================================
886 // Method  : StepToTopoDS_Builder::Init
887 // Purpose : Builds a TopoDS_Face from StepVisual_TessellatedFace
888 // ============================================================================
889
890 void StepToTopoDS_Builder::Init(const Handle(StepVisual_TessellatedFace)& theTF,
891                                 const Handle(Transfer_TransientProcess)& theTP,
892                                 const Standard_Boolean theReadTessellatedWhenNoBRepOnly,
893                                 Standard_Boolean& theHasGeom)
894 {
895   StepToTopoDS_TranslateFace aTranFace;
896   aTranFace.SetPrecision(Precision());
897   aTranFace.SetMaxTol(MaxTol());
898
899   StepToTopoDS_Tool aTool;
900   StepToTopoDS_DataMapOfTRI aMap;
901   aTool.Init(aMap, theTP);
902
903   StepToTopoDS_NMTool dummyNMTool;
904   aTranFace.Init(theTF, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly, theHasGeom);
905
906   if (aTranFace.IsDone()) 
907   {
908     TopoDS_Shape aS = aTranFace.Value();
909     TransferBRep::SetShapeResult(theTP, theTF, aS);
910     myResult = TopoDS::Face(aS);
911     myError = StepToTopoDS_BuilderDone;
912     done = Standard_True;
913   }
914   else 
915   {
916     theTP->AddWarning(theTF, " TessellatedFace not mapped to TopoDS");
917     myError = StepToTopoDS_BuilderOther;
918     done = Standard_True;
919   }
920 }
921
922 // ============================================================================
923 // Method  : Value
924 // Purpose : Returns the result of the mapping
925 // ============================================================================
926
927 const TopoDS_Shape& StepToTopoDS_Builder::Value() const 
928 {
929   StdFail_NotDone_Raise_if (!done, "StepToTopoDS_Builder::Value() - no result");
930   return myResult;
931 }
932
933 // ============================================================================
934 // Method  : Error
935 // Purpose : Returns the Builder Error code
936 // ============================================================================
937
938 StepToTopoDS_BuilderError StepToTopoDS_Builder::Error() const 
939 {
940   return myError;
941 }
942