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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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
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_BoundedSurface.hxx>
29 #include <Geom_CartesianPoint.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom_RectangularTrimmedSurface.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Interface_Static.hxx>
34 #include <Message_Messenger.hxx>
35 #include <Message_ProgressSentry.hxx>
36 #include <Precision.hxx>
37 #include <ShapeFix_ShapeTolerance.hxx>
38 #include <Standard_ErrorHandler.hxx>
39 #include <Standard_Failure.hxx>
40 #include <StdFail_NotDone.hxx>
41 #include <STEPControl_ActorRead.hxx>
42 #include <StepGeom_CartesianPoint.hxx>
43 #include <StepGeom_CompositeCurve.hxx>
44 #include <StepGeom_Curve.hxx>
45 #include <StepGeom_CurveBoundedSurface.hxx>
46 #include <StepGeom_GeometricRepresentationItem.hxx>
47 #include <StepGeom_RectangularCompositeSurface.hxx>
48 #include <StepGeom_Surface.hxx>
49 #include <StepGeom_SurfacePatch.hxx>
50 #include <StepShape_BrepWithVoids.hxx>
51 #include <StepShape_ClosedShell.hxx>
52 #include <StepShape_ConnectedEdgeSet.hxx>
53 #include <StepShape_EdgeBasedWireframeModel.hxx>
54 #include <StepShape_FaceBasedSurfaceModel.hxx>
55 #include <StepShape_FaceSurface.hxx>
56 #include <StepShape_FacetedBrep.hxx>
57 #include <StepShape_FacetedBrepAndBrepWithVoids.hxx>
58 #include <StepShape_GeometricSet.hxx>
59 #include <StepShape_GeometricSetSelect.hxx>
60 #include <StepShape_HArray1OfConnectedEdgeSet.hxx>
61 #include <StepShape_HArray1OfConnectedFaceSet.hxx>
62 #include <StepShape_HArray1OfEdge.hxx>
63 #include <StepShape_HArray1OfFace.hxx>
64 #include <StepShape_ManifoldSolidBrep.hxx>
65 #include <StepShape_OpenShell.hxx>
66 #include <StepShape_OrientedClosedShell.hxx>
67 #include <StepShape_Shell.hxx>
68 #include <StepShape_ShellBasedSurfaceModel.hxx>
69 #include <StepToGeom.hxx>
70 #include <StepToTopoDS_Builder.hxx>
71 #include <StepToTopoDS_DataMapOfTRI.hxx>
72 #include <StepToTopoDS_NMTool.hxx>
73 #include <StepToTopoDS_Tool.hxx>
74 #include <StepToTopoDS_TranslateCompositeCurve.hxx>
75 #include <StepToTopoDS_TranslateCurveBoundedSurface.hxx>
76 #include <StepToTopoDS_TranslateEdge.hxx>
77 #include <StepToTopoDS_TranslateFace.hxx>
78 #include <StepToTopoDS_TranslateShell.hxx>
79 #include <TopExp_Explorer.hxx>
81 #include <TopoDS_Compound.hxx>
82 #include <TopoDS_Edge.hxx>
83 #include <TopoDS_Face.hxx>
84 #include <TopoDS_Shape.hxx>
85 #include <TopoDS_Shell.hxx>
86 #include <TopoDS_Solid.hxx>
87 #include <Transfer_ActorOfTransientProcess.hxx>
88 #include <Transfer_TransientProcess.hxx>
89 #include <TransferBRep.hxx>
92 //#include <StepShape_VertexShell.hxx>
94 static void ResetPreci (const TopoDS_Shape& S, Standard_Real maxtol)
97 Standard_Integer modetol = Interface_Static::IVal("read.maxprecision.mode");
99 ShapeFix_ShapeTolerance STU;
100 STU.LimitTolerance (S,Precision::Confusion(),maxtol);
102 // Standard_Real ratio = Interface_Static::RVal("XSTEP.readprecision.ratio");
104 // Standard_Real lastpre = Interface_Static::RVal("lastpreci");
105 // ShapeFix_ShapeTolerance STU;
106 // STU.LimitTolerance (S,lastpre/ratio,lastpre*ratio);
110 // ============================================================================
111 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
112 // Purpose : Empty constructor
113 // ============================================================================
115 StepToTopoDS_Builder::StepToTopoDS_Builder()
117 done = Standard_False;
120 // ============================================================================
121 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
122 // Purpose : Constructor with a ManifoldSolidBrep
123 // ============================================================================
125 StepToTopoDS_Builder::StepToTopoDS_Builder
126 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
127 const Handle(Transfer_TransientProcess)& TP)
129 Init(aManifoldSolid, TP);
132 // ============================================================================
133 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
134 // Purpose : Constructor woth a BrepWithVoids
135 // ============================================================================
137 StepToTopoDS_Builder::StepToTopoDS_Builder
138 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
139 const Handle(Transfer_TransientProcess)& TP)
141 Init(aBRepWithVoids, TP);
144 // ============================================================================
145 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
146 // Purpose : Constructor with a FacetedBrep
147 // ============================================================================
149 StepToTopoDS_Builder::StepToTopoDS_Builder
150 (const Handle(StepShape_FacetedBrep)& aFB,
151 const Handle(Transfer_TransientProcess)& TP)
156 // ============================================================================
157 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
158 // Purpose : Constructor with a FacetedBrepAndBrepWithVoids
159 // ============================================================================
161 StepToTopoDS_Builder::StepToTopoDS_Builder
162 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
163 const Handle(Transfer_TransientProcess)& TP)
168 // ============================================================================
169 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
170 // Purpose : Constructor with a ShellBasedSurfaceModel
171 // ============================================================================
173 StepToTopoDS_Builder::StepToTopoDS_Builder
174 (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM,
175 const Handle(Transfer_TransientProcess)& TP,
176 StepToTopoDS_NMTool& NMTool)
178 Init(aSBSM, TP, NMTool);
181 // ============================================================================
183 // Purpose : Init with a ManifoldSolidBrep
184 // ============================================================================
186 void StepToTopoDS_Builder::Init
187 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
188 const Handle(Transfer_TransientProcess)& TP)
190 Handle(Message_Messenger) sout = TP->Messenger();
191 // Initialisation of the Tool
193 StepToTopoDS_Tool myTool;
194 StepToTopoDS_DataMapOfTRI aMap;
196 myTool.Init(aMap, TP);
200 Handle(StepShape_ConnectedFaceSet) aShell;
201 aShell = aManifoldSolid->Outer();
203 StepToTopoDS_TranslateShell myTranShell;
204 myTranShell.SetPrecision(Precision());
205 myTranShell.SetMaxTol(MaxTol());
206 // Non-manifold topology is not referenced by ManifoldSolidBrep (ssv; 14.11.2010)
207 StepToTopoDS_NMTool dummyNMTool;
208 myTranShell.Init(aShell, myTool, dummyNMTool);
210 if (myTranShell.IsDone()) {
211 TopoDS_Shape Sh = myTranShell.Value();
212 Sh.Closed(Standard_True);
213 //BRepLib::SameParameter(Sh);
219 myError = StepToTopoDS_BuilderDone;
220 done = Standard_True;
224 if ( TP->TraceLevel() > 2 )
226 sout << "Geometric Statitics : " << endl;
227 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
228 sout << " - C1 : " << myTool.C1Surf() << endl;
229 sout << " - C2 : " << myTool.C2Surf() << endl;
230 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
231 sout << " - C1 : " << myTool.C1Cur3() << endl;
232 sout << " - C2 : " << myTool.C2Cur3() << endl;
233 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
234 sout << " - C1 : " << myTool.C1Cur2() << endl;
235 sout << " - C2 : " << myTool.C2Cur2() << endl;
238 //:S4136 ShapeFix::SameParameter (S,Standard_False);
239 ResetPreci (S, MaxTol());
242 TP->AddWarning(aShell," OuterShell from ManifoldSolidBrep not mapped to TopoDS");
243 myError = StepToTopoDS_BuilderOther;
244 done = Standard_False;
248 // ============================================================================
250 // Purpose : Init with a BrepWithVoids
251 // ============================================================================
253 void StepToTopoDS_Builder::Init
254 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
255 const Handle(Transfer_TransientProcess)& TP)
257 Handle(Message_Messenger) sout = TP->Messenger();
258 // Initialisation of the Tool
259 StepToTopoDS_Tool myTool;
260 StepToTopoDS_DataMapOfTRI aMap;
262 myTool.Init(aMap, TP);
266 Standard_Integer Nb = aBRepWithVoids->NbVoids();
267 Handle(StepShape_ClosedShell) aCShell;
273 Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb+1, 1 );
275 StepToTopoDS_TranslateShell myTranShell;
277 myTranShell.SetPrecision(Precision());//gka
278 myTranShell.SetMaxTol(MaxTol());
281 aCShell = Handle(StepShape_ClosedShell)::DownCast(aBRepWithVoids->Outer());
282 // Non-manifold topology is not referenced by BrepWithVoids (ssv; 14.11.2010)
283 StepToTopoDS_NMTool dummyNMTool;
284 myTranShell.Init(aCShell, myTool, dummyNMTool);
288 if (myTranShell.IsDone()) {
289 Sh = myTranShell.Value();
290 Sh.Closed(Standard_True);
291 //BRepLib::SameParameter(Sh);
295 myError = StepToTopoDS_BuilderDone;
296 done = Standard_True;
299 TP->AddWarning(aCShell," OuterShell from BrepWithVoids not mapped to TopoDS");
300 myError = StepToTopoDS_BuilderOther;
301 done = Standard_False;
307 for (Standard_Integer i=1; i<=Nb && PS.More(); i++, PS.Next()) {
309 aCShell = aBRepWithVoids->VoidsValue(i);
310 myTranShell.Init(aCShell, myTool, dummyNMTool);
311 if (myTranShell.IsDone()) {
312 Sh = myTranShell.Value();
313 Sh.Closed(Standard_True);
315 //:e0 abv 25 Mar 98: void should be an OrientedShell
316 Handle(StepShape_OrientedClosedShell) aOCShell = aBRepWithVoids->VoidsValue(i);
317 if ( ! aOCShell.IsNull() && ! aOCShell->Orientation() ) Sh.Reverse();
319 //BRepLib::SameParameter(Sh);
324 (aCShell," A Void from BrepWithVoids not mapped to TopoDS");
332 if ( TP->TraceLevel() > 2 )
334 sout << "Geometric Statitics : " << endl;
335 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
336 sout << " - C1 : " << myTool.C1Surf() << endl;
337 sout << " - C2 : " << myTool.C2Surf() << endl;
338 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
339 sout << " - C1 : " << myTool.C1Cur3() << endl;
340 sout << " - C2 : " << myTool.C2Cur3() << endl;
341 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
342 sout << " - C1 : " << myTool.C1Cur2() << endl;
343 sout << " - C2 : " << myTool.C2Cur2() << endl;
346 //:S4136 ShapeFix::SameParameter (S,Standard_False);
347 ResetPreci (S, MaxTol());
350 // ============================================================================
352 // Purpose : Init with a FacetedBrep
353 // ============================================================================
355 void StepToTopoDS_Builder::Init(const Handle(StepShape_FacetedBrep)& aFB,
356 const Handle(Transfer_TransientProcess)& TP)
358 // Initialisation of the Tool
360 StepToTopoDS_Tool myTool;
361 StepToTopoDS_DataMapOfTRI aMap;
363 myTool.Init(aMap, TP);
367 Handle(StepShape_ClosedShell) aCShell;
368 aCShell = Handle(StepShape_ClosedShell)::DownCast(aFB->Outer());
371 StepToTopoDS_TranslateShell myTranShell;
372 myTranShell.SetPrecision(Precision()); //gka
373 myTranShell.SetMaxTol(MaxTol());
374 // Non-manifold topology is not referenced by FacetedBrep (ss; 14.11.2010)
375 StepToTopoDS_NMTool dummyNMTool;
376 myTranShell.Init(aCShell, myTool, dummyNMTool);
378 if (myTranShell.IsDone()) {
379 Sh = myTranShell.Value();
380 Sh.Closed(Standard_True);
381 //BRepLib::SameParameter(Sh);
382 myTool.ClearEdgeMap();
383 myTool.ClearVertexMap();
389 myError = StepToTopoDS_BuilderDone;
390 done = Standard_True;
394 (aCShell," OuterShell from FacetedBrep not mapped to TopoDS");
395 myError = StepToTopoDS_BuilderOther;
396 done = Standard_True;
400 // ============================================================================
402 // Purpose : Init with a FacetedBrepAndBrepWithVoids
403 // ============================================================================
405 void StepToTopoDS_Builder::Init
406 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
407 const Handle(Transfer_TransientProcess)& TP)
409 // Initialisation of the Tool
411 StepToTopoDS_Tool myTool;
412 StepToTopoDS_DataMapOfTRI aMap;
414 myTool.Init(aMap, TP);
418 Handle(StepShape_ClosedShell) aCShell;
419 aCShell = Handle(StepShape_ClosedShell)::DownCast(aFBABWV->Outer());
422 StepToTopoDS_TranslateShell myTranShell;
423 myTranShell.SetPrecision(Precision()); //gka
424 myTranShell.SetMaxTol(MaxTol());
425 // Non-manifold topology is not referenced by FacetedBrepAndBrepWithVoids (ss; 14.11.2010)
426 StepToTopoDS_NMTool dummyNMTool;
427 myTranShell.Init(aCShell, myTool, dummyNMTool);
429 if (myTranShell.IsDone()) {
430 Sh = myTranShell.Value();
431 Sh.Closed(Standard_True);
432 //BRepLib::SameParameter(Sh);
437 Standard_Integer Nb, i;
438 Nb = aFBABWV->NbVoids();
439 for ( i=1; i<=Nb; i++ ) {
440 aCShell = aFBABWV->VoidsValue(i);
441 myTranShell.Init(aCShell, myTool, dummyNMTool);
442 if (myTranShell.IsDone()) {
443 Sh = myTranShell.Value();
444 Sh.Closed(Standard_True);
445 //BRepLib::SameParameter(Sh);
450 (aCShell," A Void from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
454 myError = StepToTopoDS_BuilderDone;
455 done = Standard_True;
459 (aCShell," OuterShell from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
460 done = Standard_False;
461 myError = StepToTopoDS_BuilderOther;
465 // ============================================================================
467 // Purpose : Init with a ShellBasedSurfaceModel
468 // ============================================================================
470 void StepToTopoDS_Builder::Init
471 (const Handle(StepShape_ShellBasedSurfaceModel)& aSBSM,
472 const Handle(Transfer_TransientProcess)& TP,
473 StepToTopoDS_NMTool& NMTool)
475 Handle(Message_Messenger) sout = TP->Messenger();
476 // Initialisation of the Tool
478 StepToTopoDS_Tool myTool;
479 StepToTopoDS_DataMapOfTRI aMap;
481 myTool.Init(aMap, TP);
485 Standard_Integer Nb = aSBSM->NbSbsmBoundary();
486 StepShape_Shell aShell;
487 //Handle(StepShape_VertexShell) aVertexShell;
488 Handle(StepShape_OpenShell) aOpenShell;
489 Handle(StepShape_ClosedShell) aClosedShell;
495 StepToTopoDS_TranslateShell myTranShell;
497 myTranShell.SetPrecision(Precision());
498 myTranShell.SetMaxTol(MaxTol());
500 Message_ProgressSentry PS ( TP->GetProgress(), "Shell", 0, Nb, 1 );
501 for (Standard_Integer i=1; i<=Nb && PS.More(); i++, PS.Next()) {
502 //for (Standard_Integer i=1; i<=Nb; i++) {
503 aShell = aSBSM->SbsmBoundaryValue(i);
504 //aVertexShell = aShell.VertexShell();
505 aOpenShell = aShell.OpenShell();
506 aClosedShell = aShell.ClosedShell();
507 //if (!aVertexShell.IsNull()) {
510 //" VertexShell from ShellBasedSurfaceModel not mapped to TopoDS");
513 if (!aOpenShell.IsNull()) {
514 myTranShell.Init(aOpenShell, myTool, NMTool);
515 if (myTranShell.IsDone()) {
516 //Sh = myTranShell.Value();
517 //Sh.Closed(Standard_False);
518 //BRepLib::SameParameter(Sh);
520 Shl = TopoDS::Shell(myTranShell.Value());
521 Shl.Closed(Standard_False);
526 (aOpenShell," OpenShell from ShellBasedSurfaceModel not mapped to TopoDS");
529 else if (!aClosedShell.IsNull()) {
530 myTranShell.Init(aClosedShell, myTool, NMTool);
531 if (myTranShell.IsDone()) {
532 //Sh = myTranShell.Value();
533 //Sh.Closed(Standard_True);
534 //BRepLib::SameParameter(Sh);
536 Shl = TopoDS::Shell(myTranShell.Value());
537 Shl.Closed(Standard_True);
542 (aClosedShell," ClosedShell from ShellBasedSurfaceModel not mapped to TopoDS");
550 myError = StepToTopoDS_BuilderDone;
551 done = Standard_True;
555 if ( TP->TraceLevel() > 2 )
557 sout << "Geometric Statitics : " << endl;
558 sout << " Surface Continuity : - C0 : " << myTool.C0Surf() << endl;
559 sout << " - C1 : " << myTool.C1Surf() << endl;
560 sout << " - C2 : " << myTool.C2Surf() << endl;
561 sout << " Curve Continuity : - C0 : " << myTool.C0Cur3() << endl;
562 sout << " - C1 : " << myTool.C1Cur3() << endl;
563 sout << " - C2 : " << myTool.C2Cur3() << endl;
564 sout << " PCurve Continuity : - C0 : " << myTool.C0Cur2() << endl;
565 sout << " - C1 : " << myTool.C1Cur2() << endl;
566 sout << " - C2 : " << myTool.C2Cur2() << endl;
569 //:S4136 ShapeFix::SameParameter (S,Standard_False);
570 ResetPreci (S, MaxTol());
571 ResetPreci (Shl, MaxTol()); //skl
574 // ============================================================================
576 // Purpose : Init with a EdgeBasedWireframeModel
577 // ============================================================================
579 void StepToTopoDS_Builder::Init (const Handle(StepShape_EdgeBasedWireframeModel)& aEBWM,
580 const Handle(Transfer_TransientProcess)& TP)
584 Handle(StepShape_HArray1OfConnectedEdgeSet) boundary = aEBWM->EbwmBoundary();
585 if ( boundary.IsNull() || boundary->Length() <1 ) {
586 TP->AddWarning ( aEBWM, "List of boundaries is empty" );
590 StepToTopoDS_Tool myTool;
591 StepToTopoDS_DataMapOfTRI aMap;
592 myTool.Init(aMap, TP);
594 StepToTopoDS_TranslateEdge myTranEdge;
595 myTranEdge.SetPrecision(Precision());
596 myTranEdge.SetMaxTol(MaxTol());
600 B.MakeCompound ( C );
602 StepToTopoDS_NMTool dummyNMTool;
604 for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
605 Handle(StepShape_ConnectedEdgeSet) ces = boundary->Value(i);
606 if ( ces.IsNull() ) continue;
607 Handle(StepShape_HArray1OfEdge) edges = ces->CesEdges();
608 if ( edges.IsNull() || edges->Length() <1 ) {
609 TP->AddWarning ( ces, "No edges in connected_edge_set" );
613 for ( Standard_Integer j=1; j <= edges->Length(); j++ ) {
614 myTranEdge.Init (edges->Value(j), myTool, dummyNMTool);
615 if ( ! myTranEdge.IsDone() ) continue;
616 TopoDS_Edge E = TopoDS::Edge(myTranEdge.Value());
617 if (E.IsNull()) continue; // NULL, on saute
618 if ( W.IsNull() ) B.MakeWire ( W );
621 if ( W.IsNull() ) continue;
622 W.Closed (BRep_Tool::IsClosed (W));
624 if ( myResult.IsNull() ) myResult = W;
628 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
629 done = ! myResult.IsNull();
631 ResetPreci (myResult, MaxTol());
634 // ============================================================================
636 // Purpose : Init with a FaceBasedSurfaceModel
637 // ============================================================================
639 void StepToTopoDS_Builder::Init (const Handle(StepShape_FaceBasedSurfaceModel)& aFBSM,
640 const Handle(Transfer_TransientProcess)& TP)
644 Handle(StepShape_HArray1OfConnectedFaceSet) boundary = aFBSM->FbsmFaces();
645 if ( boundary.IsNull() || boundary->Length() <1 ) {
646 TP->AddWarning ( aFBSM, "List of faces is empty" );
650 StepToTopoDS_Tool myTool;
651 StepToTopoDS_DataMapOfTRI aMap;
652 myTool.Init(aMap, TP);
654 StepToTopoDS_TranslateFace myTranFace;
655 myTranFace.SetPrecision(Precision());
656 myTranFace.SetMaxTol(MaxTol());
660 B.MakeCompound ( C );
662 // Non-manifold topology is not mapped via FaceBasedSurfaceModel (ssv; 14.11.2010)
663 StepToTopoDS_NMTool dummyNMTool;
665 for ( Standard_Integer i=1; i <= boundary->Length(); i++ ) {
666 Handle(StepShape_ConnectedFaceSet) cfs = boundary->Value(i);
667 if ( cfs.IsNull() ) continue;
668 Handle(StepShape_HArray1OfFace) faces = cfs->CfsFaces();
669 if ( faces.IsNull() || faces->Length() <1 ) {
670 TP->AddWarning ( cfs, "No faces in connected_face_set" );
674 for ( Standard_Integer j=1; j <= faces->Length(); j++ ) {
675 Handle(StepShape_FaceSurface) fs = Handle(StepShape_FaceSurface)::DownCast ( faces->Value(j) );
676 myTranFace.Init(fs, myTool, dummyNMTool);
677 if ( ! myTranFace.IsDone() ) continue;
678 TopoDS_Face F = TopoDS::Face(myTranFace.Value());
679 if (F.IsNull()) continue; // NULL, on saute
680 if ( S.IsNull() ) B.MakeShell ( S );
683 if ( S.IsNull() ) continue;
684 S.Closed (BRep_Tool::IsClosed (S));
686 if ( myResult.IsNull() ) myResult = S;
690 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
691 done = ! myResult.IsNull();
693 ResetPreci (myResult, MaxTol());
697 // ***start DTH Apr/6
698 // ============================================================================
700 // Purpose : Init with a GeometricCurveSet
701 // ============================================================================
702 //:i6 abv 17 Sep 98: ProSTEP TR9 r0601-ct.stp: to be able read GS: GeometricCurveSet -> GeometricSet
704 static TopoDS_Face TranslateBoundedSurf (const Handle(StepGeom_Surface) &surf,
705 const Standard_Real TolDegen)
709 Handle(Geom_Surface) theSurf = StepToGeom::MakeSurface (surf);
710 if (theSurf.IsNull() || //:i6: protection
711 !theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) return res;
713 BRepBuilderAPI_MakeFace myMkFace;
714 Handle(Geom_RectangularTrimmedSurface) RS =
715 Handle(Geom_RectangularTrimmedSurface)::DownCast(theSurf);
719 Standard_Real umin, umax, vmin, vmax;
720 theSurf->Bounds(umin, umax, vmin, vmax);
722 myMkFace.Init(RS->BasisSurface(), umin, umax, vmin, vmax, TolDegen);
726 myMkFace.Init(theSurf, Standard_True, TolDegen);
729 return myMkFace.Face();
732 void StepToTopoDS_Builder::Init
733 (const Handle(StepShape_GeometricSet)& GCS,
734 const Handle(Transfer_TransientProcess)& TP,
735 const Handle(Transfer_ActorOfTransientProcess)& RA,
736 const Standard_Boolean isManifold)
738 // Initialisation of the Tool
740 // StepToTopoDS_Tool myTool;
741 // StepToTopoDS_DataMapOfTRI aMap;
743 // myTool.Init(aMap, TP);
751 Standard_Real preci = Precision(); //gka
752 Standard_Real maxtol = MaxTol();
753 Standard_Integer nbElem = GCS->NbElements();
754 for (i = 1; i <= nbElem ; i++) {
755 StepShape_GeometricSetSelect aGSS = GCS->ElementsValue(i);
756 Handle(Standard_Transient) ent = aGSS.Value();
758 TopoDS_Shape res = TransferBRep::ShapeResult ( TP, ent );
759 if ( ! res.IsNull() ) { // already translated
763 //:o7 abv 18 Feb 99: bm1_sy_fuel.stp #1427(1,2) protection against null entity
764 if ( ent.IsNull() ) {
766 sprintf ( buff, "Entity %d is a Null entity", i );
767 TP->AddWarning (GCS,buff);
771 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Curve)) ) {
772 Handle(StepGeom_Curve) aCrv = Handle(StepGeom_Curve)::DownCast ( ent );
774 // try composite_curve
775 Handle(StepGeom_CompositeCurve) CC = Handle(StepGeom_CompositeCurve)::DownCast(aCrv);
776 if ( ! CC.IsNull() ) {
777 StepToTopoDS_TranslateCompositeCurve TrCC;
778 TrCC.SetPrecision(preci);
779 TrCC.SetMaxTol(maxtol);
783 if (TrCC.IsInfiniteSegment())
786 TopoDS_Compound aComp;
787 aB.MakeCompound(aComp);
788 TopExp_Explorer anExp;
789 for (anExp.Init (TrCC.Value(), TopAbs_EDGE); anExp.More(); anExp.Next())
790 aB.Add (aComp, anExp.Current());
797 else { // try other curves
798 Handle(Geom_Curve) aGeomCrv;
801 aGeomCrv = StepToGeom::MakeCurve (aCrv);
803 catch(Standard_Failure const& anException) {
804 Handle(Message_Messenger) sout = TP->Messenger();
805 sout<<"StepToTopoDS, GeometricSet, elem "<<i<<" of "<<nbElem<<": exception ";
806 sout<<anException.GetMessageString() << endl;
808 if ( ! aGeomCrv.IsNull() ) {
809 BRepBuilderAPI_MakeEdge anEdge(aGeomCrv, aGeomCrv->FirstParameter(), aGeomCrv->LastParameter());
810 if ( anEdge.IsDone() ) res = anEdge.Edge();
815 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_CartesianPoint)) ) {
816 Handle(StepGeom_CartesianPoint) aPnt = Handle(StepGeom_CartesianPoint)::DownCast ( ent );
817 Handle(Geom_CartesianPoint) thePnt = StepToGeom::MakeCartesianPoint (aPnt);
818 if (! thePnt.IsNull()) {
819 BRepBuilderAPI_MakeVertex myMkVtx(thePnt->Pnt());
820 if ( myMkVtx.IsDone() ) res = myMkVtx.Vertex();
823 // Element should finally be a Surface
824 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Surface)) ) {
825 Handle(StepGeom_Surface) aSurf =
826 Handle(StepGeom_Surface)::DownCast(ent);
828 // try curve_bounded_surf
829 if ( ent->IsKind(STANDARD_TYPE(StepGeom_CurveBoundedSurface)) ) {
830 Handle(StepGeom_CurveBoundedSurface) CBS =
831 Handle(StepGeom_CurveBoundedSurface)::DownCast(aSurf);
832 StepToTopoDS_TranslateCurveBoundedSurface TrCBS;
833 TrCBS.SetPrecision(preci);
834 TrCBS.SetMaxTol(maxtol);
836 TrCBS.Init( CBS, TP );
837 if ( TrCBS.IsDone() ) res = TrCBS.Value();
839 // try RectangularCompositeSurface
840 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_RectangularCompositeSurface)) ) {
841 Handle(StepGeom_RectangularCompositeSurface) RCS =
842 Handle(StepGeom_RectangularCompositeSurface)::DownCast(aSurf);
843 Standard_Integer nbi = RCS->NbSegmentsI();
844 Standard_Integer nbj = RCS->NbSegmentsJ();
846 B.MakeCompound ( C );
847 for ( Standard_Integer ii=1; ii <= nbi; ii++ )
848 for ( Standard_Integer j=1; j <= nbj; j++ ) {
849 Handle(StepGeom_SurfacePatch) patch = RCS->SegmentsValue ( ii, j );
850 TopoDS_Face f = TranslateBoundedSurf (patch->ParentSurface(), preci);
851 if ( ! f.IsNull() ) B.Add ( C, f );
856 else res = TranslateBoundedSurf (aSurf, preci);
858 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) )
860 Handle(StepGeom_GeometricRepresentationItem) GRI =
861 Handle(StepGeom_GeometricRepresentationItem)::DownCast(ent);
864 Handle(STEPControl_ActorRead) anActor = Handle(STEPControl_ActorRead)::DownCast(RA);
865 Handle(Transfer_Binder) binder;
866 if( !anActor.IsNull())
867 binder = anActor->TransferShape(GRI, TP, isManifold);
868 if (!binder.IsNull())
870 res = TransferBRep::ShapeResult(binder);
874 else TP->AddWarning (ent," Entity is not a Curve, Point, Surface or GeometricRepresentationItem");
875 if ( ! res.IsNull() ) {
877 TransferBRep::SetShapeResult ( TP, ent, res );
879 else TP->AddWarning (ent," Entity not mapped to TopoDS");
882 myError = StepToTopoDS_BuilderDone;
883 done = Standard_True;
888 // ============================================================================
890 // Purpose : Returns the result of the mapping
891 // ============================================================================
893 const TopoDS_Shape& StepToTopoDS_Builder::Value() const
895 StdFail_NotDone_Raise_if(!done,"");
899 // ============================================================================
901 // Purpose : Returns the Builder Error code
902 // ============================================================================
904 StepToTopoDS_BuilderError StepToTopoDS_Builder::Error() const