2256bab83644c44b9d67532aeb32b97621ca4ea3
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeFacetedBrep.cxx
1 // Created on: 1993-07-23
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopoDSToStep_MakeFacetedBrep.ixx>
23 #include <StdFail_NotDone.hxx>
24 #include <StepShape_TopologicalRepresentationItem.hxx>
25 #include <TopoDSToStep.hxx>
26 #include <TopoDSToStep_Builder.hxx>
27 #include <TopoDSToStep_Tool.hxx>
28 #include <TopoDS_Iterator.hxx>
29 #include <BRepTools.hxx>
30 #include <Transfer_FinderProcess.hxx>
31 #include <TransferBRep_ShapeMapper.hxx>
32 #include <TCollection_HAsciiString.hxx>
33
34 //=============================================================================
35 // Create a FacetedBrep of StepShape from a Shell of TopoDS
36 //=============================================================================
37
38 TopoDSToStep_MakeFacetedBrep::
39   TopoDSToStep_MakeFacetedBrep(const TopoDS_Shell& aShell,
40                                     const Handle(Transfer_FinderProcess)& FP)
41 {
42   done = Standard_False;
43   if (aShell.Closed()) {
44     Handle(StepShape_TopologicalRepresentationItem) aItem;
45     MoniTool_DataMapOfShapeTransient aMap;
46     
47     TopoDSToStep_Tool    aTool(aMap, Standard_True);
48     TopoDSToStep_Builder StepB(aShell, aTool, FP);
49     TopoDSToStep::AddResult ( FP, aTool );
50
51     if (StepB.IsDone()) {
52       aItem = StepB.Value();
53       Handle(StepShape_ClosedShell) aCShell;
54       aCShell = Handle(StepShape_ClosedShell)::DownCast(aItem);
55       theFacetedBrep = new StepShape_FacetedBrep();
56       Handle(TCollection_HAsciiString) aName = 
57         new TCollection_HAsciiString("");
58       theFacetedBrep->Init(aName, aCShell);
59       done = Standard_True;
60     }
61     else {
62       done = Standard_False;
63       Handle(TransferBRep_ShapeMapper) errShape =
64         new TransferBRep_ShapeMapper(aShell);
65       FP->AddWarning(errShape," Closed Shell not mapped to FacetedBrep");
66     }
67   }
68   else {
69     done = Standard_False;
70     Handle(TransferBRep_ShapeMapper) errShape =
71       new TransferBRep_ShapeMapper(aShell);
72     FP->AddWarning(errShape," Shell not closed; not mapped to FacetedBrep");
73   }
74 }
75
76 //=============================================================================
77 // Create a FacetedBrep of StepShape from a Solid of TopoDS containing
78 // only one closed shell
79 //=============================================================================
80
81 TopoDSToStep_MakeFacetedBrep::
82   TopoDSToStep_MakeFacetedBrep(const TopoDS_Solid& aSolid,
83                                     const Handle(Transfer_FinderProcess)& FP)
84 {
85   done = Standard_False;
86
87   // Looking for the Outer Shell
88   TopoDS_Shell aOuterShell = BRepTools::OuterShell(aSolid);
89
90   if (!aOuterShell.IsNull()) {
91     if (aOuterShell.Closed()) {
92       Handle(StepShape_TopologicalRepresentationItem) aItem;
93       MoniTool_DataMapOfShapeTransient aMap;
94       
95       TopoDSToStep_Tool    aTool(aMap, Standard_True);
96       TopoDSToStep_Builder StepB(aOuterShell, aTool, FP);
97       TopoDSToStep::AddResult ( FP, aTool );
98       
99       if (StepB.IsDone()) {
100         aItem = StepB.Value();
101         Handle(StepShape_ClosedShell) aCShell;
102         aCShell = Handle(StepShape_ClosedShell)::DownCast(aItem);
103         theFacetedBrep = new StepShape_FacetedBrep();
104         Handle(TCollection_HAsciiString) aName = 
105           new TCollection_HAsciiString("");
106         theFacetedBrep->Init(aName, aCShell);
107         done = Standard_True;
108       }
109       else {
110         done = Standard_False;
111         Handle(TransferBRep_ShapeMapper) errShape =
112           new TransferBRep_ShapeMapper(aOuterShell);
113         FP->AddWarning(errShape," Closed Outer Shell from Solid not mapped to FacetedBrep");
114       }
115     }
116     else {
117       done = Standard_False; 
118       Handle(TransferBRep_ShapeMapper) errShape =
119         new TransferBRep_ShapeMapper(aOuterShell);
120       FP->AddWarning(errShape," Shell not closed; not mapped to FacetedBrep");
121     }
122   }
123   else {
124     done = Standard_False; 
125     Handle(TransferBRep_ShapeMapper) errShape =
126       new TransferBRep_ShapeMapper(aOuterShell);
127     FP->AddWarning(errShape," Solid contains no Outer Shell to be mapped to FacetedBrep");
128   }
129 }
130
131 //=============================================================================
132 // renvoi des valeurs
133 //=============================================================================
134
135 const Handle(StepShape_FacetedBrep) &
136       TopoDSToStep_MakeFacetedBrep::Value() const
137 {
138   StdFail_NotDone_Raise_if(!done,"");
139   return theFacetedBrep;
140 }