0022627: Change OCCT memory management defaults
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.cxx
1 // File:        TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.cxx
2 // Created:     Fri Jul 23 17:48:46 1993
3 // Author:      Martine LANGLOIS
4 //              <mla@mastox>
5
6
7 #include <TopoDSToStep_MakeFacetedBrepAndBrepWithVoids.ixx>
8 #include <TopoDSToStep.hxx>
9 #include <TopoDSToStep_Builder.hxx>
10 #include <TopoDSToStep_Tool.hxx>
11 #include <MoniTool_DataMapOfShapeTransient.hxx>
12 #include <StepShape_TopologicalRepresentationItem.hxx>
13 #include <StepShape_ClosedShell.hxx>
14 #include <StepShape_OrientedClosedShell.hxx>
15 #include <StepShape_HArray1OfOrientedClosedShell.hxx>
16 #include <TopoDS_Iterator.hxx>
17 #include <TopoDS_Shell.hxx>
18 #include <TopoDS.hxx>
19 #include <TColStd_SequenceOfTransient.hxx>
20 #include <BRepTools.hxx>
21 #include <StdFail_NotDone.hxx>
22 #include <Transfer_FinderProcess.hxx>
23 #include <TransferBRep_ShapeMapper.hxx>
24 #include <TCollection_HAsciiString.hxx>
25
26 //=============================================================================
27 // Create a FacetedBrepAndBrepWithVoids of StepShape from a Solid of TopoDS
28 // containing more than one closed shell 
29 //=============================================================================
30
31 TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::
32   TopoDSToStep_MakeFacetedBrepAndBrepWithVoids(const TopoDS_Solid& aSolid,
33                                     const Handle(Transfer_FinderProcess)& FP)
34 {
35   done = Standard_False;
36   TopoDS_Iterator              It;
37   MoniTool_DataMapOfShapeTransient   aMap;
38   TColStd_SequenceOfTransient  S;
39   TopoDS_Shell                 aOutShell;
40
41   Handle(StepShape_TopologicalRepresentationItem) aItem;
42   Handle(StepShape_ClosedShell)                   aOuter, aCShell;
43   Handle(StepShape_OrientedClosedShell)           aOCShell;
44   Handle(StepShape_HArray1OfOrientedClosedShell)  aVoids;
45
46   aOutShell = BRepTools::OuterShell(aSolid);
47
48   TopoDSToStep_Builder StepB;
49   TopoDSToStep_Tool    aTool;
50
51   if (!aOutShell.IsNull()) {
52     It.Initialize(aSolid);
53     for ( ; It.More(); It.Next() ) {
54       if (It.Value().ShapeType() == TopAbs_SHELL) {
55         TopoDS_Shell CurrentShell = TopoDS::Shell(It.Value());
56         if (It.Value().Closed()) {
57
58           aTool.Init(aMap, Standard_False);
59           StepB.Init(CurrentShell, aTool, FP);
60           TopoDSToStep::AddResult ( FP, aTool );
61
62           if (StepB.IsDone()) {
63             aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
64             if ( aOutShell.IsEqual(It.Value()) ) 
65               aOuter = aCShell;
66             else 
67               S.Append(aCShell);
68           }
69           else {
70             Handle(TransferBRep_ShapeMapper) errShape =
71               new TransferBRep_ShapeMapper(CurrentShell);
72             FP->AddWarning(errShape," Shell from Solid not mapped to FacetedBrepAndBrepWithVoids");
73           }
74         }
75         else {
76           done = Standard_False;
77           Handle(TransferBRep_ShapeMapper) errShape =
78             new TransferBRep_ShapeMapper(CurrentShell);
79           FP->AddWarning(errShape," Shell from Solid not closed; not mapped to FacetedBrepAndBrepWithVoids");
80         }
81       }
82     }
83   }
84   Standard_Integer N = S.Length();
85   if ( N>=1 ) {
86     aVoids = new StepShape_HArray1OfOrientedClosedShell(1,N);
87     Handle(TCollection_HAsciiString) aName = 
88       new TCollection_HAsciiString("");
89     for ( Standard_Integer i=1; i<=N; i++ ) {
90       aOCShell = new StepShape_OrientedClosedShell();
91       aOCShell->Init(aName, Handle(StepShape_ClosedShell)::DownCast(S.Value(i)),
92                      Standard_True);
93       aVoids->SetValue(i, aOCShell);
94     }
95     theFacetedBrepAndBrepWithVoids = 
96       new StepShape_FacetedBrepAndBrepWithVoids();
97     theFacetedBrepAndBrepWithVoids->Init(aName, aOuter, aVoids);
98     done = Standard_True;
99   }
100   else {
101     done = Standard_False;
102     Handle(TransferBRep_ShapeMapper) errShape =
103       new TransferBRep_ShapeMapper(aSolid);
104     FP->AddWarning(errShape," Solid contains no Shell to be mapped to FacetedBrepAndBrepWithVoids");
105   }
106 }
107
108 //=============================================================================
109 // renvoi des valeurs
110 //=============================================================================
111
112 const Handle(StepShape_FacetedBrepAndBrepWithVoids) &
113       TopoDSToStep_MakeFacetedBrepAndBrepWithVoids::Value() const
114 {
115   StdFail_NotDone_Raise_if(!done,"");
116   return theFacetedBrepAndBrepWithVoids;
117 }