0025748: Parallel version of progress indicator
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRepClass3d.hxx>
19 #include <Message_ProgressScope.hxx>
20 #include <StdFail_NotDone.hxx>
21 #include <StepShape_ClosedShell.hxx>
22 #include <StepShape_FacetedBrep.hxx>
23 #include <StepShape_TopologicalRepresentationItem.hxx>
24 #include <TCollection_HAsciiString.hxx>
25 #include <TopoDS_Shell.hxx>
26 #include <TopoDS_Solid.hxx>
27 #include <TopoDSToStep.hxx>
28 #include <TopoDSToStep_Builder.hxx>
29 #include <TopoDSToStep_MakeFacetedBrep.hxx>
30 #include <TopoDSToStep_Tool.hxx>
31 #include <Transfer_FinderProcess.hxx>
32 #include <TransferBRep_ShapeMapper.hxx>
33
34 //=============================================================================
35 // Create a FacetedBrep of StepShape from a Shell of TopoDS
36 //=============================================================================
37 TopoDSToStep_MakeFacetedBrep::
38   TopoDSToStep_MakeFacetedBrep(const TopoDS_Shell& aShell,
39                                const Handle(Transfer_FinderProcess)& FP,
40                                const Message_ProgressRange& theProgress)
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, theProgress);
49     if (theProgress.UserBreak())
50       return;
51     TopoDSToStep::AddResult ( FP, aTool );
52
53     if (StepB.IsDone()) {
54       aItem = StepB.Value();
55       Handle(StepShape_ClosedShell) aCShell;
56       aCShell = Handle(StepShape_ClosedShell)::DownCast(aItem);
57       theFacetedBrep = new StepShape_FacetedBrep();
58       Handle(TCollection_HAsciiString) aName = 
59         new TCollection_HAsciiString("");
60       theFacetedBrep->Init(aName, aCShell);
61       done = Standard_True;
62     }
63     else {
64       done = Standard_False;
65       Handle(TransferBRep_ShapeMapper) errShape =
66         new TransferBRep_ShapeMapper(aShell);
67       FP->AddWarning(errShape," Closed Shell not mapped to FacetedBrep");
68     }
69   }
70   else {
71     done = Standard_False;
72     Handle(TransferBRep_ShapeMapper) errShape =
73       new TransferBRep_ShapeMapper(aShell);
74     FP->AddWarning(errShape," Shell not closed; not mapped to FacetedBrep");
75   }
76 }
77
78 //=============================================================================
79 // Create a FacetedBrep of StepShape from a Solid of TopoDS containing
80 // only one closed shell
81 //=============================================================================
82
83 TopoDSToStep_MakeFacetedBrep::
84   TopoDSToStep_MakeFacetedBrep(const TopoDS_Solid& aSolid,
85                                const Handle(Transfer_FinderProcess)& FP,
86                                const Message_ProgressRange& theProgress)
87 {
88   done = Standard_False;
89
90   // Looking for the Outer Shell
91   TopoDS_Shell aOuterShell = BRepClass3d::OuterShell(aSolid);
92
93   if (!aOuterShell.IsNull()) {
94     if (aOuterShell.Closed()) {
95       Handle(StepShape_TopologicalRepresentationItem) aItem;
96       MoniTool_DataMapOfShapeTransient aMap;
97       
98       TopoDSToStep_Tool    aTool(aMap, Standard_True);
99       TopoDSToStep_Builder StepB(aOuterShell, aTool, FP, theProgress);
100       if (theProgress.UserBreak())
101         return;
102       TopoDSToStep::AddResult ( FP, aTool );
103       
104       if (StepB.IsDone()) {
105         aItem = StepB.Value();
106         Handle(StepShape_ClosedShell) aCShell;
107         aCShell = Handle(StepShape_ClosedShell)::DownCast(aItem);
108         theFacetedBrep = new StepShape_FacetedBrep();
109         Handle(TCollection_HAsciiString) aName = 
110           new TCollection_HAsciiString("");
111         theFacetedBrep->Init(aName, aCShell);
112         done = Standard_True;
113       }
114       else {
115         done = Standard_False;
116         Handle(TransferBRep_ShapeMapper) errShape =
117           new TransferBRep_ShapeMapper(aOuterShell);
118         FP->AddWarning(errShape," Closed Outer Shell from Solid not mapped to FacetedBrep");
119       }
120     }
121     else {
122       done = Standard_False; 
123       Handle(TransferBRep_ShapeMapper) errShape =
124         new TransferBRep_ShapeMapper(aOuterShell);
125       FP->AddWarning(errShape," Shell not closed; not mapped to FacetedBrep");
126     }
127   }
128   else {
129     done = Standard_False; 
130     Handle(TransferBRep_ShapeMapper) errShape =
131       new TransferBRep_ShapeMapper(aOuterShell);
132     FP->AddWarning(errShape," Solid contains no Outer Shell to be mapped to FacetedBrep");
133   }
134 }
135
136 //=============================================================================
137 // renvoi des valeurs
138 //=============================================================================
139
140 const Handle(StepShape_FacetedBrep) &
141       TopoDSToStep_MakeFacetedBrep::Value() const
142 {
143   StdFail_NotDone_Raise_if (!done, "TopoDSToStep_MakeFacetedBrep::Value() - no result");
144   return theFacetedBrep;
145 }