1 // File: StepToTopoDS_Builder.cxx
2 // Created: Tue Jan 3 11:26:22 1995
3 // Author: Frederic MAUPAS
5 //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GeometricSet
6 //gka 11.01.99 file PRO7755.stp #2018: work-around error in BRepLib_MakeFace
7 //:n4 abv 12.02.99: S4132: treatment of GEOMETRIC_SETs implemented
8 //:o7 abv 18.02.99: bm1_sy_fuel.stp #1427(items 1,2) protection against null entity
9 //abv,gka 05.04.99 S4136: parameter names changed; avoid extra call to FixSameParameter
12 #include <StepToTopoDS_Builder.ixx>
13 #include <Standard_ErrorHandler.hxx>
14 #include <Standard_Failure.hxx>
15 #include <Interface_Static.hxx>
16 #include <TransferBRep.hxx>
18 #include <StepToTopoDS_Tool.hxx>
19 #include <StepToTopoDS_DataMapOfTRI.hxx>
20 #include <StepToTopoDS_TranslateShell.hxx>
21 #include <StepToTopoDS_TranslateCompositeCurve.hxx>
22 #include <StepToTopoDS_TranslateCurveBoundedSurface.hxx>
24 //#include <StepShape_VertexShell.hxx>
25 #include <StepShape_Shell.hxx>
26 #include <StepShape_OpenShell.hxx>
27 #include <StepShape_OrientedClosedShell.hxx> //:e0
28 #include <StepGeom_Surface.hxx>
29 #include <StepGeom_Curve.hxx>
30 #include <StepGeom_CartesianPoint.hxx>
31 #include <StepGeom_CompositeCurve.hxx>
32 #include <StepGeom_RectangularCompositeSurface.hxx>
33 #include <StepGeom_SurfacePatch.hxx>
34 #include <StepShape_GeometricSetSelect.hxx>
35 #include <StepToGeom_MakeCurve.hxx>
36 #include <StepToGeom_MakeCartesianPoint.hxx>
37 #include <StepToGeom_MakeSurface.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom_BoundedSurface.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_CartesianPoint.hxx>
44 #include <BRepBuilderAPI_MakeFace.hxx>
45 #include <BRepBuilderAPI_MakeEdge.hxx>
46 #include <BRepBuilderAPI_MakeVertex.hxx>
47 #include <BRepLib.hxx>
48 #include <BRep_Builder.hxx>
49 #include <Precision.hxx>
50 #include <TopoDS_Shell.hxx>
51 #include <TopoDS_Face.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Solid.hxx>
54 #include <TopoDS_Compound.hxx>
56 #include <ShapeFix_ShapeTolerance.hxx>
57 #include <StepShape_ConnectedEdgeSet.hxx>
58 #include <StepShape_EdgeBasedWireframeModel.hxx>
59 #include <StepShape_HArray1OfConnectedEdgeSet.hxx>
60 #include <StepToTopoDS_TranslateEdge.hxx>
61 #include <StepShape_HArray1OfEdge.hxx>
63 #include <StepShape_HArray1OfConnectedFaceSet.hxx>
64 #include <StepToTopoDS_TranslateFace.hxx>
65 #include <StepShape_HArray1OfFace.hxx>
67 #include <Message_ProgressSentry.hxx>
68 #include <Message_Messenger.hxx>
70 static void ResetPreci (const TopoDS_Shape& S, Standard_Real maxtol)
73 Standard_Integer modetol = Interface_Static::IVal("read.maxprecision.mode");
75 ShapeFix_ShapeTolerance STU;
76 STU.LimitTolerance (S,Precision::Confusion(),maxtol);
78 // Standard_Real ratio = Interface_Static::RVal("XSTEP.readprecision.ratio");
80 // Standard_Real lastpre = Interface_Static::RVal("lastpreci");
81 // ShapeFix_ShapeTolerance STU;
82 // STU.LimitTolerance (S,lastpre/ratio,lastpre*ratio);
86 // ============================================================================
87 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
88 // Purpose : Empty constructor
89 // ============================================================================
91 StepToTopoDS_Builder::StepToTopoDS_Builder()
93 done = Standard_False;
96 // ============================================================================
97 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
98 // Purpose : Constructor with a ManifoldSolidBrep
99 // ============================================================================
101 StepToTopoDS_Builder::StepToTopoDS_Builder
102 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
103 const Handle(Transfer_TransientProcess)& TP)
105 Init(aManifoldSolid, TP);
108 // ============================================================================
109 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
110 // Purpose : Constructor woth a BrepWithVoids
111 // ============================================================================
113 StepToTopoDS_Builder::StepToTopoDS_Builder
114 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
115 const Handle(Transfer_TransientProcess)& TP)
117 Init(aBRepWithVoids, TP);
120 // ============================================================================
121 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
122 // Purpose : Constructor with a FacetedBrep
123 // ============================================================================
125 StepToTopoDS_Builder::StepToTopoDS_Builder
126 (const Handle(StepShape_FacetedBrep)& aFB,
127 const Handle(Transfer_TransientProcess)& TP)
132 // ============================================================================
133 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
134 // Purpose : Constructor with a FacetedBrepAndBrepWithVoids
135 // ============================================================================
137 StepToTopoDS_Builder::StepToTopoDS_Builder
138 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
139 const Handle(Transfer_TransientProcess)& TP)
144 // ============================================================================
145 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
146 // Purpose : Constructor with a ShellBasedSurfaceModel
147 // ============================================================================
149 StepToTopoDS_Builder::StepToTopoDS_Builder
150 (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM,
151 const Handle(Transfer_TransientProcess)& TP,
152 StepToTopoDS_NMTool& NMTool)
154 Init(aSBSM, TP, NMTool);
157 // ============================================================================
159 // Purpose : Init with a ManifoldSolidBrep
160 // ============================================================================
162 void StepToTopoDS_Builder::Init
163 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
164 const Handle(Transfer_TransientProcess)& TP)
166 Handle(Message_Messenger) sout = TP->Messenger();
167 // Initialisation of the Tool
169 StepToTopoDS_Tool myTool;
170 StepToTopoDS_DataMapOfTRI aMap;
172 myTool.Init(aMap, TP);
176 Handle(StepShape_ClosedShell) aCShell;
177 aCShell = aManifoldSolid->Outer();
179 StepToTopoDS_TranslateShell myTranShell;
180 myTranShell.SetPrecision(Precision());
181 myTranShell.SetMaxTol(MaxTol());
182 // Non-manifold topology is not referenced by ManifoldSolidBrep (ssv; 14.11.2010)
183 StepToTopoDS_NMTool dummyNMTool;
184 myTranShell.Init(aCShell, myTool, dummyNMTool);
186 if (myTranShell.IsDone()) {
187 TopoDS_Shape Sh = myTranShell.Value();
188 Sh.Closed(Standard_True);
189 //BRepLib::SameParameter(Sh);
195 myError = StepToTopoDS_BuilderDone;
196 done = Standard_True;
200 if ( TP->TraceLevel() > 2 )
202 sout << "Geometric Statitics : " << endl;
203 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
204 sout << " - C1 : " << myTool.C1Surf() << endl;
205 sout << " - C2 : " << myTool.C2Surf() << endl;
206 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
207 sout << " - C1 : " << myTool.C1Cur3() << endl;
208 sout << " - C2 : " << myTool.C2Cur3() << endl;
209 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
210 sout << " - C1 : " << myTool.C1Cur2() << endl;
211 sout << " - C2 : " << myTool.C2Cur2() << endl;
214 //:S4136 ShapeFix::SameParameter (S,Standard_False);
215 ResetPreci (S, MaxTol());
218 TP->AddWarning(aCShell," OuterShell from ManifoldSolidBrep not mapped to TopoDS");
219 myError = StepToTopoDS_BuilderOther;
220 done = Standard_False;
224 // ============================================================================
226 // Purpose : Init with a BrepWithVoids
227 // ============================================================================
229 void StepToTopoDS_Builder::Init
230 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
231 const Handle(Transfer_TransientProcess)& TP)
233 Handle(Message_Messenger) sout = TP->Messenger();
234 // Initialisation of the Tool
235 StepToTopoDS_Tool myTool;
236 StepToTopoDS_DataMapOfTRI aMap;
238 myTool.Init(aMap, TP);
242 Standard_Integer Nb = aBRepWithVoids->NbVoids();
243 Handle(StepShape_ClosedShell) aCShell;
249 Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb+1, 1 );
251 StepToTopoDS_TranslateShell myTranShell;
253 myTranShell.SetPrecision(Precision());//gka
254 myTranShell.SetMaxTol(MaxTol());
257 aCShell = aBRepWithVoids->Outer();
258 // Non-manifold topology is not referenced by BrepWithVoids (ssv; 14.11.2010)
259 StepToTopoDS_NMTool dummyNMTool;
260 myTranShell.Init(aCShell, myTool, dummyNMTool);
264 if (myTranShell.IsDone()) {
265 Sh = myTranShell.Value();
266 Sh.Closed(Standard_True);
267 //BRepLib::SameParameter(Sh);
271 myError = StepToTopoDS_BuilderDone;
272 done = Standard_True;
275 TP->AddWarning(aCShell," OuterShell from BrepWithVoids not mapped to TopoDS");
276 myError = StepToTopoDS_BuilderOther;
277 done = Standard_False;
283 for (Standard_Integer i=1; i<=Nb && PS.More(); i++, PS.Next()) {
285 aCShell = aBRepWithVoids->VoidsValue(i);
286 myTranShell.Init(aCShell, myTool, dummyNMTool);
287 if (myTranShell.IsDone()) {
288 Sh = myTranShell.Value();
289 Sh.Closed(Standard_True);
291 //:e0 abv 25 Mar 98: void should be an OrientedShell
292 Handle(StepShape_OrientedClosedShell) aOCShell = aBRepWithVoids->VoidsValue(i);
293 if ( ! aOCShell.IsNull() && ! aOCShell->Orientation() ) Sh.Reverse();
295 //BRepLib::SameParameter(Sh);
300 (aCShell," A Void from BrepWithVoids not mapped to TopoDS");
308 if ( TP->TraceLevel() > 2 )
310 sout << "Geometric Statitics : " << endl;
311 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
312 sout << " - C1 : " << myTool.C1Surf() << endl;
313 sout << " - C2 : " << myTool.C2Surf() << endl;
314 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
315 sout << " - C1 : " << myTool.C1Cur3() << endl;
316 sout << " - C2 : " << myTool.C2Cur3() << endl;
317 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
318 sout << " - C1 : " << myTool.C1Cur2() << endl;
319 sout << " - C2 : " << myTool.C2Cur2() << endl;
322 //:S4136 ShapeFix::SameParameter (S,Standard_False);
323 ResetPreci (S, MaxTol());
326 // ============================================================================
328 // Purpose : Init with a FacetedBrep
329 // ============================================================================
331 void StepToTopoDS_Builder::Init(const Handle(StepShape_FacetedBrep)& aFB,
332 const Handle(Transfer_TransientProcess)& TP)
334 // Initialisation of the Tool
336 StepToTopoDS_Tool myTool;
337 StepToTopoDS_DataMapOfTRI aMap;
339 myTool.Init(aMap, TP);
343 Handle(StepShape_ClosedShell) aCShell;
344 aCShell = aFB->Outer();
347 StepToTopoDS_TranslateShell myTranShell;
348 myTranShell.SetPrecision(Precision()); //gka
349 myTranShell.SetMaxTol(MaxTol());
350 // Non-manifold topology is not referenced by FacetedBrep (ss; 14.11.2010)
351 StepToTopoDS_NMTool dummyNMTool;
352 myTranShell.Init(aCShell, myTool, dummyNMTool);
354 if (myTranShell.IsDone()) {
355 Sh = myTranShell.Value();
356 Sh.Closed(Standard_True);
357 //BRepLib::SameParameter(Sh);
358 myTool.ClearEdgeMap();
359 myTool.ClearVertexMap();
365 myError = StepToTopoDS_BuilderDone;
366 done = Standard_True;
370 (aCShell," OuterShell from FacetedBrep not mapped to TopoDS");
371 myError = StepToTopoDS_BuilderOther;
372 done = Standard_True;
376 // ============================================================================
378 // Purpose : Init with a FacetedBrepAndBrepWithVoids
379 // ============================================================================
381 void StepToTopoDS_Builder::Init
382 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
383 const Handle(Transfer_TransientProcess)& TP)
385 // Initialisation of the Tool
387 StepToTopoDS_Tool myTool;
388 StepToTopoDS_DataMapOfTRI aMap;
390 myTool.Init(aMap, TP);
394 Handle(StepShape_ClosedShell) aCShell;
395 aCShell = aFBABWV->Outer();
398 StepToTopoDS_TranslateShell myTranShell;
399 myTranShell.SetPrecision(Precision()); //gka
400 myTranShell.SetMaxTol(MaxTol());
401 // Non-manifold topology is not referenced by FacetedBrepAndBrepWithVoids (ss; 14.11.2010)
402 StepToTopoDS_NMTool dummyNMTool;
403 myTranShell.Init(aCShell, myTool, dummyNMTool);
405 if (myTranShell.IsDone()) {
406 Sh = myTranShell.Value();
407 Sh.Closed(Standard_True);
408 //BRepLib::SameParameter(Sh);
413 Standard_Integer Nb, i;
414 Nb = aFBABWV->NbVoids();
415 for ( i=1; i<=Nb; i++ ) {
416 aCShell = aFBABWV->VoidsValue(i);
417 myTranShell.Init(aCShell, myTool, dummyNMTool);
418 if (myTranShell.IsDone()) {
419 Sh = myTranShell.Value();
420 Sh.Closed(Standard_True);
421 //BRepLib::SameParameter(Sh);
426 (aCShell," A Void from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
430 myError = StepToTopoDS_BuilderDone;
431 done = Standard_True;
435 (aCShell," OuterShell from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
436 done = Standard_False;
437 myError = StepToTopoDS_BuilderOther;
441 // ============================================================================
443 // Purpose : Init with a ShellBasedSurfaceModel
444 // ============================================================================
446 void StepToTopoDS_Builder::Init
447 (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM,
448 const Handle(Transfer_TransientProcess)& TP,
449 StepToTopoDS_NMTool& NMTool)
451 Handle(Message_Messenger) sout = TP->Messenger();
452 // Initialisation of the Tool
454 StepToTopoDS_Tool myTool;
455 StepToTopoDS_DataMapOfTRI aMap;
457 myTool.Init(aMap, TP);
461 Standard_Integer Nb = aSBSM->NbSbsmBoundary();
462 StepShape_Shell aShell;
463 //Handle(StepShape_VertexShell) aVertexShell;
464 Handle(StepShape_OpenShell) aOpenShell;
465 Handle(StepShape_ClosedShell) aClosedShell;
471 StepToTopoDS_TranslateShell myTranShell;
473 myTranShell.SetPrecision(Precision());
474 myTranShell.SetMaxTol(MaxTol());
476 Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb, 1 );
477 for (Standard_Integer i=1; i<=Nb && PS.More(); i++, PS.Next()) {
478 //for (Standard_Integer i=1; i<=Nb; i++) {
479 aShell = aSBSM->SbsmBoundaryValue(i);
480 //aVertexShell = aShell.VertexShell();
481 aOpenShell = aShell.OpenShell();
482 aClosedShell = aShell.ClosedShell();
483 //if (!aVertexShell.IsNull()) {
486 //" VertexShell from ShellBasedSurfaceModel not mapped to TopoDS");
489 if (!aOpenShell.IsNull()) {
490 myTranShell.Init(aOpenShell, myTool, NMTool);
491 if (myTranShell.IsDone()) {
492 //Sh = myTranShell.Value();
493 //Sh.Closed(Standard_False);
494 //BRepLib::SameParameter(Sh);
496 Shl = TopoDS::Shell(myTranShell.Value());
497 Shl.Closed(Standard_False);
502 (aOpenShell," OpenShell from ShellBasedSurfaceModel not mapped to TopoDS");
505 else if (!aClosedShell.IsNull()) {
506 myTranShell.Init(aClosedShell, myTool, NMTool);
507 if (myTranShell.IsDone()) {
508 //Sh = myTranShell.Value();
509 //Sh.Closed(Standard_True);
510 //BRepLib::SameParameter(Sh);
512 Shl = TopoDS::Shell(myTranShell.Value());
513 Shl.Closed(Standard_True);
518 (aClosedShell," ClosedShell from ShellBasedSurfaceModel not mapped to TopoDS");
526 myError = StepToTopoDS_BuilderDone;
527 done = Standard_True;
531 if ( TP->TraceLevel() > 2 )
533 sout << "Geometric Statitics : " << endl;
534 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
535 sout << " - C1 : " << myTool.C1Surf() << endl;
536 sout << " - C2 : " << myTool.C2Surf() << endl;
537 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
538 sout << " - C1 : " << myTool.C1Cur3() << endl;
539 sout << " - C2 : " << myTool.C2Cur3() << endl;
540 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
541 sout << " - C1 : " << myTool.C1Cur2() << endl;
542 sout << " - C2 : " << myTool.C2Cur2() << endl;
545 //:S4136 ShapeFix::SameParameter (S,Standard_False);
546 ResetPreci (S, MaxTol());
547 ResetPreci (Shl, MaxTol()); //skl
550 // ============================================================================
552 // Purpose : Init with a EdgeBasedWireframeModel
553 // ============================================================================
555 void StepToTopoDS_Builder::Init (const Handle(StepShape_EdgeBasedWireframeModel)& aEBWM,
556 const Handle(Transfer_TransientProcess)& TP)
560 Handle(StepShape_HArray1OfConnectedEdgeSet) boundary = aEBWM->EbwmBoundary();
561 if ( boundary.IsNull() || boundary->Length() <1 ) {
562 TP->AddWarning ( aEBWM, "List of boundaries is empty" );
566 StepToTopoDS_Tool myTool;
567 StepToTopoDS_DataMapOfTRI aMap;
568 myTool.Init(aMap, TP);
570 StepToTopoDS_TranslateEdge myTranEdge;
571 myTranEdge.SetPrecision(Precision());
572 myTranEdge.SetMaxTol(MaxTol());
576 B.MakeCompound ( C );
578 StepToTopoDS_NMTool dummyNMTool;
580 for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
581 Handle(StepShape_ConnectedEdgeSet) ces = boundary->Value(i);
582 if ( ces.IsNull() ) continue;
583 Handle(StepShape_HArray1OfEdge) edges = ces->CesEdges();
584 if ( edges.IsNull() || edges->Length() <1 ) {
585 TP->AddWarning ( ces, "No edges in connected_edge_set" );
589 for ( Standard_Integer j=1; j <= edges->Length(); j++ ) {
590 myTranEdge.Init (edges->Value(j), myTool, dummyNMTool);
591 if ( ! myTranEdge.IsDone() ) continue;
592 TopoDS_Edge E = TopoDS::Edge(myTranEdge.Value());
593 if (E.IsNull()) continue; // NULL, on saute
594 if ( W.IsNull() ) B.MakeWire ( W );
597 if ( W.IsNull() ) continue;
599 if ( myResult.IsNull() ) myResult = W;
603 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
604 done = ! myResult.IsNull();
606 ResetPreci (myResult, MaxTol());
609 // ============================================================================
611 // Purpose : Init with a FaceBasedSurfaceModel
612 // ============================================================================
614 void StepToTopoDS_Builder::Init (const Handle(StepShape_FaceBasedSurfaceModel)& aFBSM,
615 const Handle(Transfer_TransientProcess)& TP)
619 Handle(StepShape_HArray1OfConnectedFaceSet) boundary = aFBSM->FbsmFaces();
620 if ( boundary.IsNull() || boundary->Length() <1 ) {
621 TP->AddWarning ( aFBSM, "List of faces is empty" );
625 StepToTopoDS_Tool myTool;
626 StepToTopoDS_DataMapOfTRI aMap;
627 myTool.Init(aMap, TP);
629 StepToTopoDS_TranslateFace myTranFace;
630 myTranFace.SetPrecision(Precision());
631 myTranFace.SetMaxTol(MaxTol());
635 B.MakeCompound ( C );
637 // Non-manifold topology is not mapped via FaceBasedSurfaceModel (ssv; 14.11.2010)
638 StepToTopoDS_NMTool dummyNMTool;
640 for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
641 Handle(StepShape_ConnectedFaceSet) cfs = boundary->Value(i);
642 if ( cfs.IsNull() ) continue;
643 Handle(StepShape_HArray1OfFace) faces = cfs->CfsFaces();
644 if ( faces.IsNull() || faces->Length() <1 ) {
645 TP->AddWarning ( cfs, "No faces in connected_face_set" );
649 for ( Standard_Integer j=1; j <= faces->Length(); j++ ) {
650 Handle(StepShape_FaceSurface) fs = Handle(StepShape_FaceSurface)::DownCast ( faces->Value(j) );
651 myTranFace.Init(fs, myTool, dummyNMTool);
652 if ( ! myTranFace.IsDone() ) continue;
653 TopoDS_Face F = TopoDS::Face(myTranFace.Value());
654 if (F.IsNull()) continue; // NULL, on saute
655 if ( S.IsNull() ) B.MakeShell ( S );
658 if ( S.IsNull() ) continue;
660 if ( myResult.IsNull() ) myResult = S;
664 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
665 done = ! myResult.IsNull();
667 ResetPreci (myResult, MaxTol());
671 // ***start DTH Apr/6
672 // ============================================================================
674 // Purpose : Init with a GeometricCurveSet
675 // ============================================================================
676 //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GS: GeometricCurveSet -> GeometricSet
678 static TopoDS_Face TranslateBoundedSurf (const Handle(StepGeom_Surface) &surf)
682 Handle(Geom_Surface) theSurf;
683 if (!StepToGeom_MakeSurface::Convert(surf,theSurf) || //:i6: protection
684 !theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) return res;
686 //gka 11.01.99 file PRO7755.stp entity #2018 surface #1895: error BRepLib_MakeFace func IsDegenerated
687 BRepBuilderAPI_MakeFace myMkFace(theSurf);
688 return myMkFace.Face();
691 void StepToTopoDS_Builder::Init
692 (const Handle(StepShape_GeometricSet)& GCS,
693 const Handle(Transfer_TransientProcess)& TP)
695 // Initialisation of the Tool
697 // StepToTopoDS_Tool myTool;
698 // StepToTopoDS_DataMapOfTRI aMap;
700 // myTool.Init(aMap, TP);
708 Standard_Real preci = Precision(); //gka
709 Standard_Real maxtol = MaxTol();
710 Standard_Integer nbElem = GCS->NbElements();
711 for (i = 1; i <= nbElem ; i++) {
712 StepShape_GeometricSetSelect aGSS = GCS->ElementsValue(i);
713 Handle(Standard_Transient) ent = aGSS.Value();
715 TopoDS_Shape res = TransferBRep::ShapeResult ( TP, ent );
716 if ( ! res.IsNull() ) { // already translated
720 //:o7 abv 18 Feb 99: bm1_sy_fuel.stp #1427(1,2) protection against null entity
721 if ( ent.IsNull() ) {
723 sprintf ( buff, "Entity %d is a Null entity", i );
724 TP->AddWarning (GCS,buff);
728 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Curve)) ) {
729 Handle(StepGeom_Curve) aCrv = Handle(StepGeom_Curve)::DownCast ( ent );
731 // try composite_curve
732 Handle(StepGeom_CompositeCurve) CC = Handle(StepGeom_CompositeCurve)::DownCast(aCrv);
733 if ( ! CC.IsNull() ) {
734 StepToTopoDS_TranslateCompositeCurve TrCC;
735 TrCC.SetPrecision(preci);
736 TrCC.SetMaxTol(maxtol);
738 if ( TrCC.IsDone() ) res = TrCC.Value();
740 else { // try other curves
741 Handle(Geom_Curve) aGeomCrv;
744 StepToGeom_MakeCurve::Convert(aCrv,aGeomCrv);
746 catch(Standard_Failure) {
747 Handle(Message_Messenger) sout = TP->Messenger();
748 sout<<"StepToTopoDS, GeometricSet, elem "<<i<<" of "<<nbElem<<": exception ";
749 sout<<Standard_Failure::Caught()->GetMessageString() << endl;
751 if ( ! aGeomCrv.IsNull() ) {
752 BRepBuilderAPI_MakeEdge anEdge(aGeomCrv, aGeomCrv->FirstParameter(), aGeomCrv->LastParameter());
753 if ( anEdge.IsDone() ) res = anEdge.Edge();
758 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint)) ) {
759 Handle(StepGeom_CartesianPoint) aPnt = Handle(StepGeom_CartesianPoint)::DownCast ( ent );
760 Handle(Geom_CartesianPoint) thePnt;
761 if (StepToGeom_MakeCartesianPoint::Convert(aPnt,thePnt)) {
762 BRepBuilderAPI_MakeVertex myMkVtx(thePnt->Pnt());
763 if ( myMkVtx.IsDone() ) res = myMkVtx.Vertex();
766 // Element should finally be a Surface
767 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Surface)) ) {
768 Handle(StepGeom_Surface) aSurf =
769 Handle(StepGeom_Surface)::DownCast(ent);
771 // try curve_bounded_surf
772 if ( ent->IsKind(STANDARD_TYPE(StepGeom_CurveBoundedSurface)) ) {
773 Handle(StepGeom_CurveBoundedSurface) CBS =
774 Handle(StepGeom_CurveBoundedSurface)::DownCast(aSurf);
775 StepToTopoDS_TranslateCurveBoundedSurface TrCBS;
776 TrCBS.SetPrecision(preci);
777 TrCBS.SetMaxTol(maxtol);
779 TrCBS.Init( CBS, TP );
780 if ( TrCBS.IsDone() ) res = TrCBS.Value();
782 // try RectangularCompositeSurface
783 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_RectangularCompositeSurface)) ) {
784 Handle(StepGeom_RectangularCompositeSurface) RCS =
785 Handle(StepGeom_RectangularCompositeSurface)::DownCast(aSurf);
786 Standard_Integer nbi = RCS->NbSegmentsI();
787 Standard_Integer nbj = RCS->NbSegmentsJ();
789 B.MakeCompound ( C );
790 for ( Standard_Integer ii=1; ii <= nbi; ii++ )
791 for ( Standard_Integer j=1; j <= nbj; j++ ) {
792 Handle(StepGeom_SurfacePatch) patch = RCS->SegmentsValue ( ii, j );
793 TopoDS_Face f = TranslateBoundedSurf ( patch->ParentSurface() );
794 if ( ! f.IsNull() ) B.Add ( C, f );
799 else res = TranslateBoundedSurf ( aSurf );
801 else TP->AddWarning (ent," Entity is not a Curve, Point or Surface");
802 if ( ! res.IsNull() ) {
804 TransferBRep::SetShapeResult ( TP, ent, res );
806 else TP->AddWarning (ent," Entity not mapped to TopoDS");
809 myError = StepToTopoDS_BuilderDone;
810 done = Standard_True;
815 // ============================================================================
817 // Purpose : Returns the result of the mapping
818 // ============================================================================
820 const TopoDS_Shape& StepToTopoDS_Builder::Value() const
822 StdFail_NotDone_Raise_if(!done,"");
826 // ============================================================================
828 // Purpose : Returns the Builder Error code
829 // ============================================================================
831 StepToTopoDS_BuilderError StepToTopoDS_Builder::Error() const