0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeManifoldSolidBrep.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 #include <TopoDSToStep_MakeManifoldSolidBrep.ixx>
18 #include <StdFail_NotDone.hxx>
19 #include <TopoDSToStep.hxx>
20 #include <TopoDSToStep_Builder.hxx>
21 #include <TopoDSToStep_Tool.hxx>
22 #include <BRepClass3d.hxx>
23 #include <Transfer_FinderProcess.hxx>
24 #include <TransferBRep_ShapeMapper.hxx>
25 #include <TCollection_HAsciiString.hxx>
26
27 #include <StepShape_ClosedShell.hxx>
28 #include <StepShape_OpenShell.hxx>
29 #include <StepShape_HArray1OfFace.hxx>
30
31 static Handle(StepShape_ManifoldSolidBrep) MakeManifoldSolidBrep (const TopoDS_Shell& aShell,
32                                                                   const Handle(Transfer_FinderProcess)& FP)
33 {
34   Handle(StepShape_ManifoldSolidBrep) theManifoldSolidBrep;
35
36   MoniTool_DataMapOfShapeTransient aMap;
37   TopoDSToStep_Tool aTool(aMap, Standard_False);
38   
39   TopoDSToStep_Builder StepB(aShell, aTool, FP);
40
41   TopoDSToStep::AddResult(FP, aTool);
42
43   if (StepB.IsDone()) {
44     Handle(StepShape_ClosedShell) aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
45     // si OPEN on le force a CLOSED mais que c est une honte !
46     if (aCShell.IsNull()) {
47       Handle(StepShape_OpenShell) aOShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value());
48       if (aOShell.IsNull()) return theManifoldSolidBrep;
49       else {
50         aCShell = new StepShape_ClosedShell;
51         aCShell->Init(aOShell->Name(),aOShell->CfsFaces());
52       }
53     }
54     theManifoldSolidBrep = new StepShape_ManifoldSolidBrep();
55     Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("");
56     theManifoldSolidBrep->Init(aName, aCShell);
57   }
58
59   return theManifoldSolidBrep;
60 }
61
62 //=============================================================================
63 // Create a ManifoldSolidBrep of StepShape from a Shell of TopoDS
64 //=============================================================================
65
66 TopoDSToStep_MakeManifoldSolidBrep::
67   TopoDSToStep_MakeManifoldSolidBrep(const TopoDS_Shell& aShell,
68                                      const Handle(Transfer_FinderProcess)& FP)
69 {
70   theManifoldSolidBrep = MakeManifoldSolidBrep(aShell, FP);
71   done = !theManifoldSolidBrep.IsNull();
72   if (!done) {
73     Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aShell);
74     FP->AddWarning(errShape, " Closed Shell not mapped to ManifoldSolidBrep");
75   }
76 }
77
78 //=============================================================================
79 // Create a ManifoldSolidBrep of StepShape from a Solid of TopoDS containing
80 // only one closed shell
81 //=============================================================================
82
83 TopoDSToStep_MakeManifoldSolidBrep::
84   TopoDSToStep_MakeManifoldSolidBrep(const TopoDS_Solid& aSolid,
85                                      const Handle(Transfer_FinderProcess)& FP)
86 {
87   TopoDS_Shell aOuterShell = BRepClass3d::OuterShell(aSolid);
88   if (!aOuterShell.IsNull()) {
89
90     theManifoldSolidBrep = MakeManifoldSolidBrep(aOuterShell, FP);
91     done = !theManifoldSolidBrep.IsNull();
92     if (!done) {
93       Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aOuterShell);
94       FP->AddWarning(errShape, " Outer Shell of Solid not mapped to ManifoldSolidBrep");
95     }
96   }
97   else {
98     Handle(TransferBRep_ShapeMapper) errShape = new TransferBRep_ShapeMapper(aOuterShell);
99     FP->AddWarning(errShape, " Outer Shell is null; not mapped to ManifoldSolidBrep ");
100     done = Standard_False;
101   }
102 }
103
104 //=============================================================================
105 // renvoi des valeurs
106 //=============================================================================
107
108 const Handle(StepShape_ManifoldSolidBrep) &
109       TopoDSToStep_MakeManifoldSolidBrep::Value() const
110 {
111   StdFail_NotDone_Raise_if(!done,"");
112   return theManifoldSolidBrep;
113 }