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_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>
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>
91 static void ResetPreci (const TopoDS_Shape& S, Standard_Real maxtol)
94 Standard_Integer modetol = Interface_Static::IVal("read.maxprecision.mode");
96 ShapeFix_ShapeTolerance STU;
97 STU.LimitTolerance (S,Precision::Confusion(),maxtol);
101 // ============================================================================
102 // Method : StepToTopoDS_Builder::StepToTopoDS_Builder
103 // Purpose : Empty constructor
104 // ============================================================================
106 StepToTopoDS_Builder::StepToTopoDS_Builder()
107 : myError(StepToTopoDS_BuilderOther)
109 done = Standard_False;
112 // ============================================================================
114 // Purpose : Init with a ManifoldSolidBrep
115 // ============================================================================
117 void StepToTopoDS_Builder::Init
118 (const Handle(StepShape_ManifoldSolidBrep)& aManifoldSolid,
119 const Handle(Transfer_TransientProcess)& TP,
120 const Message_ProgressRange& theProgress)
122 Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
123 // Initialisation of the Tool
125 StepToTopoDS_Tool myTool;
126 StepToTopoDS_DataMapOfTRI aMap;
128 myTool.Init(aMap, TP);
132 Handle(StepShape_ConnectedFaceSet) aShell;
133 aShell = aManifoldSolid->Outer();
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);
142 if (myTranShell.IsDone()) {
143 TopoDS_Shape Sh = myTranShell.Value();
144 Sh.Closed(Standard_True);
145 //BRepLib::SameParameter(Sh);
151 myError = StepToTopoDS_BuilderDone;
152 done = Standard_True;
156 if ( TP->TraceLevel() > 2 )
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;
170 //:S4136 ShapeFix::SameParameter (S,Standard_False);
171 ResetPreci (S, MaxTol());
174 TP->AddWarning(aShell," OuterShell from ManifoldSolidBrep not mapped to TopoDS");
175 myError = StepToTopoDS_BuilderOther;
176 done = Standard_False;
180 // ============================================================================
182 // Purpose : Init with a BrepWithVoids
183 // ============================================================================
185 void StepToTopoDS_Builder::Init
186 (const Handle(StepShape_BrepWithVoids)& aBRepWithVoids,
187 const Handle(Transfer_TransientProcess)& TP,
188 const Message_ProgressRange& theProgress)
190 Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
191 // Initialisation of the Tool
192 StepToTopoDS_Tool myTool;
193 StepToTopoDS_DataMapOfTRI aMap;
195 myTool.Init(aMap, TP);
199 Standard_Integer Nb = aBRepWithVoids->NbVoids();
200 Handle(StepShape_ClosedShell) aCShell;
206 Message_ProgressScope PS (theProgress, "Shell", Nb+1);
208 StepToTopoDS_TranslateShell myTranShell;
210 myTranShell.SetPrecision(Precision());//gka
211 myTranShell.SetMaxTol(MaxTol());
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());
219 if (myTranShell.IsDone()) {
220 Sh = myTranShell.Value();
221 Sh.Closed(Standard_True);
222 //BRepLib::SameParameter(Sh);
226 myError = StepToTopoDS_BuilderDone;
227 done = Standard_True;
230 TP->AddWarning(aCShell," OuterShell from BrepWithVoids not mapped to TopoDS");
231 myError = StepToTopoDS_BuilderOther;
232 done = Standard_False;
238 for (Standard_Integer i=1; i<=Nb && PS.More(); i++) {
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);
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();
250 //BRepLib::SameParameter(Sh);
255 (aCShell," A Void from BrepWithVoids not mapped to TopoDS");
263 if ( TP->TraceLevel() > 2 )
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;
277 //:S4136 ShapeFix::SameParameter (S,Standard_False);
278 ResetPreci (S, MaxTol());
281 // ============================================================================
283 // Purpose : Init with a FacetedBrep
284 // ============================================================================
286 void StepToTopoDS_Builder::Init(const Handle(StepShape_FacetedBrep)& aFB,
287 const Handle(Transfer_TransientProcess)& TP,
288 const Message_ProgressRange& theProgress)
290 // Initialisation of the Tool
292 StepToTopoDS_Tool myTool;
293 StepToTopoDS_DataMapOfTRI aMap;
295 myTool.Init(aMap, TP);
299 Handle(StepShape_ClosedShell) aCShell;
300 aCShell = Handle(StepShape_ClosedShell)::DownCast(aFB->Outer());
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);
310 if (myTranShell.IsDone()) {
311 Sh = myTranShell.Value();
312 Sh.Closed(Standard_True);
313 //BRepLib::SameParameter(Sh);
314 myTool.ClearEdgeMap();
315 myTool.ClearVertexMap();
321 myError = StepToTopoDS_BuilderDone;
322 done = Standard_True;
326 (aCShell," OuterShell from FacetedBrep not mapped to TopoDS");
327 myError = StepToTopoDS_BuilderOther;
328 done = Standard_True;
332 // ============================================================================
334 // Purpose : Init with a FacetedBrepAndBrepWithVoids
335 // ============================================================================
337 void StepToTopoDS_Builder::Init
338 (const Handle(StepShape_FacetedBrepAndBrepWithVoids)& aFBABWV,
339 const Handle(Transfer_TransientProcess)& TP,
340 const Message_ProgressRange& theProgress)
342 // Initialisation of the Tool
344 StepToTopoDS_Tool myTool;
345 StepToTopoDS_DataMapOfTRI aMap;
347 myTool.Init(aMap, TP);
351 Handle(StepShape_ClosedShell) aCShell;
352 aCShell = Handle(StepShape_ClosedShell)::DownCast(aFBABWV->Outer());
355 Message_ProgressScope aPSRoot(theProgress, NULL, 2);
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());
364 if (myTranShell.IsDone()) {
365 Sh = myTranShell.Value();
366 Sh.Closed(Standard_True);
367 //BRepLib::SameParameter(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);
386 (aCShell," A Void from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
390 myError = StepToTopoDS_BuilderDone;
391 done = Standard_True;
395 (aCShell," OuterShell from FacetedBrepAndBrepWithVoids not mapped to TopoDS");
396 done = Standard_False;
397 myError = StepToTopoDS_BuilderOther;
401 // ============================================================================
403 // Purpose : Init with a ShellBasedSurfaceModel
404 // ============================================================================
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)
412 Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
413 // Initialisation of the Tool
415 StepToTopoDS_Tool myTool;
416 StepToTopoDS_DataMapOfTRI aMap;
418 myTool.Init(aMap, TP);
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;
432 StepToTopoDS_TranslateShell myTranShell;
434 myTranShell.SetPrecision(Precision());
435 myTranShell.SetMaxTol(MaxTol());
437 Message_ProgressScope PS ( theProgress, "Shell", Nb);
438 for (Standard_Integer i = 1; i <= Nb && PS.More(); i++)
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);
453 (aOpenShell, " OpenShell from ShellBasedSurfaceModel not mapped to TopoDS");
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);
465 (aClosedShell, " ClosedShell from ShellBasedSurfaceModel not mapped to TopoDS");
473 myError = StepToTopoDS_BuilderDone;
474 done = Standard_True;
478 if ( TP->TraceLevel() > 2 )
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;
492 //:S4136 ShapeFix::SameParameter (S,Standard_False);
493 ResetPreci (S, MaxTol());
494 ResetPreci (Shl, MaxTol()); //skl
497 // ============================================================================
499 // Purpose : Init with a EdgeBasedWireframeModel
500 // ============================================================================
502 void StepToTopoDS_Builder::Init (const Handle(StepShape_EdgeBasedWireframeModel)& aEBWM,
503 const Handle(Transfer_TransientProcess)& TP)
507 Handle(StepShape_HArray1OfConnectedEdgeSet) boundary = aEBWM->EbwmBoundary();
508 if ( boundary.IsNull() || boundary->Length() <1 ) {
509 TP->AddWarning ( aEBWM, "List of boundaries is empty" );
513 StepToTopoDS_Tool myTool;
514 StepToTopoDS_DataMapOfTRI aMap;
515 myTool.Init(aMap, TP);
517 StepToTopoDS_TranslateEdge myTranEdge;
518 myTranEdge.SetPrecision(Precision());
519 myTranEdge.SetMaxTol(MaxTol());
523 B.MakeCompound ( C );
525 StepToTopoDS_NMTool dummyNMTool;
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" );
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 );
544 if ( W.IsNull() ) continue;
545 W.Closed (BRep_Tool::IsClosed (W));
547 if ( myResult.IsNull() ) myResult = W;
551 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
552 done = ! myResult.IsNull();
554 ResetPreci (myResult, MaxTol());
557 // ============================================================================
559 // Purpose : Init with a FaceBasedSurfaceModel
560 // ============================================================================
562 void StepToTopoDS_Builder::Init (const Handle(StepShape_FaceBasedSurfaceModel)& aFBSM,
563 const Handle(Transfer_TransientProcess)& TP)
567 Handle(StepShape_HArray1OfConnectedFaceSet) boundary = aFBSM->FbsmFaces();
568 if ( boundary.IsNull() || boundary->Length() <1 ) {
569 TP->AddWarning ( aFBSM, "List of faces is empty" );
573 StepToTopoDS_Tool myTool;
574 StepToTopoDS_DataMapOfTRI aMap;
575 myTool.Init(aMap, TP);
577 StepToTopoDS_TranslateFace myTranFace;
578 myTranFace.SetPrecision(Precision());
579 myTranFace.SetMaxTol(MaxTol());
583 B.MakeCompound ( C );
585 // Non-manifold topology is not mapped via FaceBasedSurfaceModel (ssv; 14.11.2010)
586 StepToTopoDS_NMTool dummyNMTool;
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" );
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 );
606 if ( S.IsNull() ) continue;
607 S.Closed (BRep_Tool::IsClosed (S));
609 if ( myResult.IsNull() ) myResult = S;
613 myError = ( myResult.IsNull() ? StepToTopoDS_BuilderDone : StepToTopoDS_BuilderOther );
614 done = ! myResult.IsNull();
616 ResetPreci (myResult, MaxTol());
620 // ***start DTH Apr/6
621 // ============================================================================
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
627 static TopoDS_Face TranslateBoundedSurf (const Handle(StepGeom_Surface) &surf,
628 const Standard_Real TolDegen)
632 Handle(Geom_Surface) theSurf = StepToGeom::MakeSurface (surf);
633 if (theSurf.IsNull() || //:i6: protection
634 !theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) return res;
636 BRepBuilderAPI_MakeFace myMkFace;
637 Handle(Geom_RectangularTrimmedSurface) RS =
638 Handle(Geom_RectangularTrimmedSurface)::DownCast(theSurf);
642 Standard_Real umin, umax, vmin, vmax;
643 theSurf->Bounds(umin, umax, vmin, vmax);
645 myMkFace.Init(RS->BasisSurface(), umin, umax, vmin, vmax, TolDegen);
649 myMkFace.Init(theSurf, Standard_True, TolDegen);
652 return myMkFace.Face();
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)
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++)
674 Message_ProgressRange aRange = aPS.Next();
675 StepShape_GeometricSetSelect aGSS = GCS->ElementsValue(i);
676 Handle(Standard_Transient) ent = aGSS.Value();
678 TopoDS_Shape res = TransferBRep::ShapeResult ( TP, ent );
679 if ( ! res.IsNull() ) { // already translated
683 //:o7 abv 18 Feb 99: bm1_sy_fuel.stp #1427(1,2) protection against null entity
684 if ( ent.IsNull() ) {
686 sprintf ( buff, "Entity %d is a Null entity", i );
687 TP->AddWarning (GCS,buff);
691 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_Curve)) ) {
692 Handle(StepGeom_Curve) aCrv = Handle(StepGeom_Curve)::DownCast ( ent );
694 // try composite_curve
695 Handle(StepGeom_CompositeCurve) CC = Handle(StepGeom_CompositeCurve)::DownCast(aCrv);
697 StepToTopoDS_TranslateCompositeCurve TrCC;
698 TrCC.SetPrecision(preci);
699 TrCC.SetMaxTol(maxtol);
703 if (TrCC.IsInfiniteSegment())
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());
717 else { // try other curves
718 Handle(Geom_Curve) aGeomCrv;
721 aGeomCrv = StepToGeom::MakeCurve(aCrv);
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;
728 if (!aGeomCrv.IsNull()) {
729 BRepBuilderAPI_MakeEdge anEdge(aGeomCrv, aGeomCrv->FirstParameter(), aGeomCrv->LastParameter());
730 if (anEdge.IsDone()) res = anEdge.Edge();
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();
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);
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);
757 if (TrCBS.IsDone()) res = TrCBS.Value();
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();
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);
776 else res = TranslateBoundedSurf(aSurf, preci);
778 else if ( ent->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem)) )
780 Handle(StepGeom_GeometricRepresentationItem) GRI =
781 Handle(StepGeom_GeometricRepresentationItem)::DownCast(ent);
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())
790 res = TransferBRep::ShapeResult(binder);
794 else TP->AddWarning (ent," Entity is not a Curve, Point, Surface or GeometricRepresentationItem");
795 if ( ! res.IsNull() ) {
797 TransferBRep::SetShapeResult ( TP, ent, res );
799 else TP->AddWarning (ent," Entity not mapped to TopoDS");
802 myError = StepToTopoDS_BuilderDone;
803 done = Standard_True;
807 // ============================================================================
808 // Method : StepToTopoDS_Builder::Init
809 // Purpose : Builds a TopoDS_Solid from StepVisual_TessellatedSolid
810 // ============================================================================
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)
818 StepToTopoDS_TranslateSolid aTranSolid;
819 aTranSolid.SetPrecision(Precision());
820 aTranSolid.SetMaxTol(MaxTol());
822 StepToTopoDS_Tool aTool;
823 StepToTopoDS_DataMapOfTRI aMap;
824 aTool.Init(aMap, theTP);
826 StepToTopoDS_NMTool dummyNMTool;
827 aTranSolid.Init(theTSo, theTP, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly,
828 theHasGeom, theProgress);
830 if (aTranSolid.IsDone())
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;
840 theTP->AddWarning(theTSo, " TessellatedSolid not mapped to TopoDS");
841 myError = StepToTopoDS_BuilderOther;
842 done = Standard_True;
846 // ============================================================================
847 // Method : StepToTopoDS_Builder::Init
848 // Purpose : Builds a TopoDS_Shell from StepVisual_TessellatedShell
849 // ============================================================================
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)
857 StepToTopoDS_TranslateShell aTranShell;
858 aTranShell.SetPrecision(Precision());
859 aTranShell.SetMaxTol(MaxTol());
861 StepToTopoDS_Tool aTool;
862 StepToTopoDS_DataMapOfTRI aMap;
863 aTool.Init(aMap, theTP);
865 StepToTopoDS_NMTool dummyNMTool;
866 aTranShell.Init(theTSh, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly,
867 theHasGeom, theProgress);
869 if (aTranShell.IsDone())
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;
879 theTP->AddWarning(theTSh, " TessellatedShell not mapped to TopoDS");
880 myError = StepToTopoDS_BuilderOther;
881 done = Standard_True;
885 // ============================================================================
886 // Method : StepToTopoDS_Builder::Init
887 // Purpose : Builds a TopoDS_Face from StepVisual_TessellatedFace
888 // ============================================================================
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)
895 StepToTopoDS_TranslateFace aTranFace;
896 aTranFace.SetPrecision(Precision());
897 aTranFace.SetMaxTol(MaxTol());
899 StepToTopoDS_Tool aTool;
900 StepToTopoDS_DataMapOfTRI aMap;
901 aTool.Init(aMap, theTP);
903 StepToTopoDS_NMTool dummyNMTool;
904 aTranFace.Init(theTF, aTool, dummyNMTool, theReadTessellatedWhenNoBRepOnly, theHasGeom);
906 if (aTranFace.IsDone())
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;
916 theTP->AddWarning(theTF, " TessellatedFace not mapped to TopoDS");
917 myError = StepToTopoDS_BuilderOther;
918 done = Standard_True;
922 // ============================================================================
924 // Purpose : Returns the result of the mapping
925 // ============================================================================
927 const TopoDS_Shape& StepToTopoDS_Builder::Value() const
929 StdFail_NotDone_Raise_if (!done, "StepToTopoDS_Builder::Value() - no result");
933 // ============================================================================
935 // Purpose : Returns the Builder Error code
936 // ============================================================================
938 StepToTopoDS_BuilderError StepToTopoDS_Builder::Error() const