Test for 0022778: Bug in BRepMesh
[occt.git] / src / TopoDSToStep / TopoDSToStep_MakeBrepWithVoids.cxx
CommitLineData
b311480e 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
7fd59977 21
22#include <TopoDSToStep_MakeBrepWithVoids.ixx>
23#include <TopoDSToStep.hxx>
24#include <TopoDSToStep_Builder.hxx>
25#include <TopoDSToStep_Tool.hxx>
26#include <MoniTool_DataMapOfShapeTransient.hxx>
27#include <StepShape_TopologicalRepresentationItem.hxx>
28#include <StepShape_OpenShell.hxx> //:d7
29#include <StepShape_ClosedShell.hxx>
30#include <StepShape_OrientedClosedShell.hxx>
31#include <StepShape_HArray1OfOrientedClosedShell.hxx>
32#include <TopoDS_Iterator.hxx>
33#include <TopoDS_Shell.hxx>
34#include <TopoDS.hxx>
35#include <TColStd_SequenceOfTransient.hxx>
2f0109b7 36#include <BRepClass3d.hxx>
7fd59977 37#include <StdFail_NotDone.hxx>
38#include <Transfer_FinderProcess.hxx>
39#include <TransferBRep_ShapeMapper.hxx>
40#include <TCollection_HAsciiString.hxx>
41
42#ifdef DEB
43#define DEBUG
44#endif
45
46//=============================================================================
47// Create a BrepWithVoids of StepShape from a Solid of TopoDS containing
48// more than one closed shell
49//=============================================================================
50
51TopoDSToStep_MakeBrepWithVoids::
52 TopoDSToStep_MakeBrepWithVoids(const TopoDS_Solid& aSolid,
53 const Handle(Transfer_FinderProcess)& FP)
54{
55 done = Standard_False ;
56 TopoDS_Iterator It;
57 MoniTool_DataMapOfShapeTransient aMap;
58 TColStd_SequenceOfTransient S;
59 TopoDS_Shell aOutShell;
60
61 Handle(StepShape_TopologicalRepresentationItem) aItem;
62 Handle(StepShape_ClosedShell) aOuter, aCShell;
63 Handle(StepShape_OrientedClosedShell) aOCShell;
64 Handle(StepShape_HArray1OfOrientedClosedShell) aVoids;
65
2f0109b7 66 aOutShell = BRepClass3d::OuterShell(aSolid);
7fd59977 67
68 TopoDSToStep_Builder StepB;
69 TopoDSToStep_Tool aTool;
70
71 if (!aOutShell.IsNull()) {
72 It.Initialize(aSolid);
73 for ( ; It.More(); It.Next() ) {
74 if (It.Value().ShapeType() == TopAbs_SHELL) {
75 TopoDS_Shell CurrentShell = TopoDS::Shell(It.Value());
76 if ( ! aOutShell.IsEqual(CurrentShell) ) //:e0 abv 25 Mar 98: voids should be reversed according to EXPRESS for ABSR
77 CurrentShell.Reverse();
78 //:d7 abv 16 Mar 98: try to treat 'open' shells as closed since flag
79 // IsClosed() is often incorrect (taken from MakeManifoldSolid(Solid))
80 aTool.Init(aMap, Standard_False);
81 StepB.Init(CurrentShell, aTool, FP);
82 TopoDSToStep::AddResult ( FP, aTool );
83 if (StepB.IsDone()) {
84 aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
85 // si OPEN on le force a CLOSED mais que c est une honte !
86 if (aCShell.IsNull()) {
87 Handle(StepShape_OpenShell) aOShell = Handle(StepShape_OpenShell)::DownCast(StepB.Value());
88 if (!aOShell.IsNull()) {
89 aCShell = new StepShape_ClosedShell;
90 aCShell->Init (aOShell->Name(),aOShell->CfsFaces());
91#ifdef DEBUG
92 cout<<"Warning: MakeBRepWithVoids: Open shell in the solid; treated as closed"<<endl;
93#endif
94 }
95 }
96 if ( ! aCShell.IsNull() ) {
97 if ( aOutShell.IsEqual(It.Value()) )
98 aOuter = aCShell;
99 else
100 S.Append(aCShell);
101 }
102#ifdef DEBUG
103 else cout<<"*** MakeBRepWithVoids : Shell not mapped"<<endl;
104#endif
105 }
106#ifdef DEBUG
107 else cout << "Shell not mapped" << endl;
108#endif
109/* //:d7
110 if (It.Value().Closed()) {
111 aTool.Init(aMap, Standard_False);
112 StepB.Init(CurrentShell, aTool, FP);
113 TopoDSToStep::AddResult ( FP, aTool );
114 if (StepB.IsDone()) {
115 aCShell = Handle(StepShape_ClosedShell)::DownCast(StepB.Value());
116 if ( aOutShell.IsEqual(It.Value()) )
117 aOuter = aCShell;
118 else
119 S.Append(aCShell);
120 }
121 else {
122#ifdef DEBUG
123 cout << "Shell not mapped" << endl;
124#endif
125 done = Standard_False;
126 }
127 }
128 else {
129 // Error Handling : the Shape is not closed
130 done = Standard_False;
131 }
132*/
133 }
134 }
135 Standard_Integer N = S.Length();
136 if ( N>=1 ) {
137 Handle(TCollection_HAsciiString) aName =
138 new TCollection_HAsciiString("");
139 aVoids = new StepShape_HArray1OfOrientedClosedShell(1,N);
140 for ( Standard_Integer i=1; i<=N; i++ ) {
141 aOCShell = new StepShape_OrientedClosedShell;
142 // Warning : the Oriented Shell Orientation is not always
143 // TRUE.
144 // Shall check the TopoDS_Shell orientation.
145 // => if the Shell is reversed, shall create an OrientedShell.
146 aOCShell -> Init(aName,Handle(StepShape_ClosedShell)::DownCast(S.Value(i)),
147 Standard_False); //:e0
148//:e0 Standard_True);
149 aVoids->SetValue(i, aOCShell);
150 }
151 theBrepWithVoids = new StepShape_BrepWithVoids();
152 theBrepWithVoids->Init(aName, aOuter, aVoids);
153 done = Standard_True;
154 }
155 else done = Standard_False;
156 }
157}
158
159//=============================================================================
160// renvoi des valeurs
161//=============================================================================
162
163const Handle(StepShape_BrepWithVoids) &
164 TopoDSToStep_MakeBrepWithVoids::Value() const
165{
166 StdFail_NotDone_Raise_if(!done,"");
167 return theBrepWithVoids;
168}