Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeManifoldSolidBrep.cxx
1 // File:        TopoDSToStep_MakeManifoldSolidBrep.cxx
2 // Created:     Fri Jul 23 15:31:00 1993
3 // Author:      Martine LANGLOIS
4 //              <mla@mastox>
5
6 #include <TopoDSToStep_MakeManifoldSolidBrep.ixx>
7 #include <StdFail_NotDone.hxx>
8 #include <TopoDSToStep.hxx>
9 #include <TopoDSToStep_Builder.hxx>
10 #include <TopoDSToStep_Tool.hxx>
11 #include <BRepTools.hxx>
12 #include <Transfer_FinderProcess.hxx>
13 #include <TransferBRep_ShapeMapper.hxx>
14 #include <TCollection_HAsciiString.hxx>
15
16 #include <StepShape_ClosedShell.hxx>
17 #include <StepShape_OpenShell.hxx>
18 #include <StepShape_HArray1OfFace.hxx>
19
20 static Handle(StepShape_ManifoldSolidBrep) MakeManifoldSolidBrep (const TopoDS_Shell& aShell,
21                                                                   const Handle(Transfer_FinderProcess)& FP)
22 {
23   Handle(StepShape_ManifoldSolidBrep) theManifoldSolidBrep;
24
25   MoniTool_DataMapOfShapeTransient aMap;
26   TopoDSToStep_Tool aTool(aMap, Standard_False);
27   
28   TopoDSToStep_Builder StepB(aShell, aTool, FP);
29
30   TopoDSToStep::AddResult(FP, aTool);
31
32   if (StepB.IsDone()) {
33     Handle(StepShape_ClosedShell) aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
34     // si OPEN on le force a CLOSED mais que c est une honte !
35     if (aCShell.IsNull()) {
36       Handle(StepShape_OpenShell) aOShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value());
37       if (aOShell.IsNull()) return theManifoldSolidBrep;
38       else {
39         aCShell = new StepShape_ClosedShell;
40         aCShell->Init(aOShell->Name(),aOShell->CfsFaces());
41       }
42     }
43     theManifoldSolidBrep = new StepShape_ManifoldSolidBrep();
44     Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
45     theManifoldSolidBrep->Init(aName, aCShell);
46   }
47
48   return theManifoldSolidBrep;
49 }
50
51 //=============================================================================
52 // Create a ManifoldSolidBrep of StepShape from a Shell of TopoDS
53 //=============================================================================
54
55 TopoDSToStep_MakeManifoldSolidBrep::
56   TopoDSToStep_MakeManifoldSolidBrep(const TopoDS_Shell& aShell,
57                                      const Handle(Transfer_FinderProcess)& FP)
58 {
59   theManifoldSolidBrep = MakeManifoldSolidBrep(aShell, FP);
60   done = !theManifoldSolidBrep.IsNull();
61   if (!done) {
62     Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aShell);
63     FP->AddWarning(errShape, " Closed Shell not mapped to ManifoldSolidBrep");
64   }
65 }
66
67 //=============================================================================
68 // Create a ManifoldSolidBrep of StepShape from a Solid of TopoDS containing
69 // only one closed shell
70 //=============================================================================
71
72 TopoDSToStep_MakeManifoldSolidBrep::
73   TopoDSToStep_MakeManifoldSolidBrep(const TopoDS_Solid& aSolid,
74                                      const Handle(Transfer_FinderProcess)& FP)
75 {
76   TopoDS_Shell aOuterShell = BRepTools::OuterShell(aSolid);
77   if (!aOuterShell.IsNull()) {
78
79     theManifoldSolidBrep = MakeManifoldSolidBrep(aOuterShell, FP);
80     done = !theManifoldSolidBrep.IsNull();
81     if (!done) {
82       Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aOuterShell);
83       FP->AddWarning(errShape, " Outer Shell of Solid not mapped to ManifoldSolidBrep");
84     }
85   }
86   else {
87     Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aOuterShell);
88     FP->AddWarning(errShape, " Outer Shell is null; not mapped to ManifoldSolidBrep ");
89     done = Standard_False;
90   }
91 }
92
93 //=============================================================================
94 // renvoi des valeurs
95 //=============================================================================
96
97 const Handle(StepShape_ManifoldSolidBrep) &
98       TopoDSToStep_MakeManifoldSolidBrep::Value() const
99 {
100   StdFail_NotDone_Raise_if(!done,"");
101   return theManifoldSolidBrep;
102 }