Test for 0022778: Bug in BRepMesh
[occt.git] / src / TopoDSToStep / TopoDSToStep_Builder.cxx
CommitLineData
b311480e 1// Created on: 1994-11-25
2// Created by: Frederic MAUPAS
3// Copyright (c) 1994-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
23#include <TopoDSToStep_Builder.ixx>
24
25#include <TopoDSToStep_Tool.hxx>
26
27#include <TopoDSToStep_MakeStepFace.hxx>
28
29#include <StepShape_ConnectedFaceSet.hxx>
30#include <StepShape_HArray1OfFace.hxx>
31#include <StepShape_ClosedShell.hxx>
32#include <StepShape_OpenShell.hxx>
33#include <StepShape_FaceSurface.hxx>
34
35#include <TopoDS.hxx>
36#include <TopoDS_Shell.hxx>
37#include <TopoDS_Face.hxx>
38
39#include <TopExp_Explorer.hxx>
40
41#include <TColStd_SequenceOfTransient.hxx>
42#include <TransferBRep_ShapeMapper.hxx>
43#include <TCollection_HAsciiString.hxx>
44
45#include <Message_ProgressIndicator.hxx>
46
47// ============================================================================
48// Method : TopoDSToStep_Builder::TopoDSToStep_Builder
49// Purpose :
50// ============================================================================
51
52TopoDSToStep_Builder::TopoDSToStep_Builder()
53{
54 done = Standard_False;
55}
56
57// ============================================================================
58// Method : TopoDSToStep_Builder::TopoDSToStep_Builder
59// Purpose :
60// ============================================================================
61
62TopoDSToStep_Builder::TopoDSToStep_Builder
63(const TopoDS_Shape& aShape,
64 TopoDSToStep_Tool& aTool, const Handle(Transfer_FinderProcess)& FP)
65{
66 done = Standard_False;
67 Init(aShape, aTool, FP);
68}
69
70// ============================================================================
71// Method : TopoDSToStep_Builder::Init
72// Purpose :
73// ============================================================================
74
75void TopoDSToStep_Builder::Init(const TopoDS_Shape& aShape,
76 TopoDSToStep_Tool& myTool,
77 const Handle(Transfer_FinderProcess)& FP)
78{
79
80 if (myTool.IsBound(aShape)) {
81 myError = TopoDSToStep_BuilderDone;
82 done = Standard_True;
83 myResult = myTool.Find(aShape);
84 return;
85 }
86
87 Handle(Message_ProgressIndicator) progress = FP->GetProgress();
88
89 switch (aShape.ShapeType())
90 {
91 case TopAbs_SHELL:
92 {
93 TopoDS_Shell myShell = TopoDS::Shell(aShape);
94 myTool.SetCurrentShell(myShell);
95
96 Handle(StepShape_FaceSurface) FS;
97 Handle(StepShape_TopologicalRepresentationItem) Fpms;
98 TColStd_SequenceOfTransient mySeq;
99
100// const TopoDS_Shell ForwardShell =
101// TopoDS::Shell(myShell.Oriented(TopAbs_FORWARD));
102
103// TopExp_Explorer myExp(ForwardShell, TopAbs_FACE);
104// CKY 9-DEC-1997 (PRO9824 et consorts)
105// Pour passer les orientations : ELLES SONT DONNEES EN RELATIF
106// Donc, pour SHELL, on doit l ecrire en direct en STEP (pas le choix)
107// -> il faut repercuter en dessous, donc explorer le Shell TEL QUEL
108// Pour FACE WIRE, d une part on ECRIT SON ORIENTATION relative au contenant
109// (puisqu on peut), d autre part on EXPLORE EN FORWARD : ainsi les
110// orientations des sous-shapes sont relatives a leur contenant immediat
111// et la recombinaison en lecture est sans malice
112// Il reste ici et la du code relatif a "en Faceted on combine differemment"
113// -> reste encore du menage a faire
114
115
116
117 TopExp_Explorer myExp(myShell, TopAbs_FACE);
118
119 TopoDSToStep_MakeStepFace MkFace;
120
121 for (;myExp.More();myExp.Next()) {
122
123 const TopoDS_Face Face = TopoDS::Face(myExp.Current());
124
125 MkFace.Init(Face, myTool, FP);
126
127 if (MkFace.IsDone()) {
128 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
129 Fpms = FS;
130 mySeq.Append(Fpms);
131 }
132 else {
133 // MakeFace Error Handling : warning only
134// cout << "Warning : one Face has not been mapped" << endl;
135// Handle(TransferBRep_ShapeMapper) errShape =
136// new TransferBRep_ShapeMapper(Face);
137// FP->AddWarning(errShape, " a Face from a Shell has not been mapped");
138 }
139 if (!progress.IsNull()) progress->Increment();
140 }
141
142 Standard_Integer nbFaces = mySeq.Length();
143 if ( nbFaces >= 1) {
144 Handle(StepShape_HArray1OfFace) aSet =
145 new StepShape_HArray1OfFace(1,nbFaces);
146 for (Standard_Integer i=1; i<=nbFaces; i++ ) {
147 aSet->SetValue(i, Handle(StepShape_Face)::DownCast(mySeq.Value(i)));
148 }
149 Handle(StepShape_ConnectedFaceSet) CFSpms;
150 if (myShell.Closed())
151 CFSpms = new StepShape_ClosedShell();
152 else
153 CFSpms = new StepShape_OpenShell();
154 Handle(TCollection_HAsciiString) aName =
155 new TCollection_HAsciiString("");
156 CFSpms->Init(aName, aSet);
157
158 // --------------------------------------------------------------
159 // To add later : if not facetted context & shell is reversed
160 // then shall create an oriented_shell with
161 // orientation flag to false.
162 // --------------------------------------------------------------
163
164 myTool.Bind(aShape, CFSpms);
165 myResult = CFSpms;
166 done = Standard_True;
167 }
168 else {
169 // Builder Error handling;
170 myError = TopoDSToStep_NoFaceMapped;
171 done = Standard_False;
172 }
173 break;
174 }
175
176 case TopAbs_FACE:
177 {
178 const TopoDS_Face Face = TopoDS::Face(aShape);
179
180 Handle(StepShape_FaceSurface) FS;
181 Handle(StepShape_TopologicalRepresentationItem) Fpms;
182
183 TopoDSToStep_MakeStepFace MkFace(Face, myTool, FP);
184
185 if (MkFace.IsDone()) {
186 FS = Handle(StepShape_FaceSurface)::DownCast(MkFace.Value());
187 Fpms = FS;
188 myResult = Fpms;
189 myError = TopoDSToStep_BuilderDone;
190 done = Standard_True;
191 }
192 else {
193 // MakeFace Error Handling : Face not Mapped
194 myError = TopoDSToStep_BuilderOther;
195// Handle(TransferBRep_ShapeMapper) errShape =
196// new TransferBRep_ShapeMapper(Face);
197// FP->AddWarning(errShape, " the Face has not been mapped");
198 done = Standard_False;
199 }
200 if (!progress.IsNull()) progress->Increment();
201 break;
202 }
203 default: break;
204 }
205}
206
207// ============================================================================
208// Method : TopoDSToStep_Builder::Value
209// Purpose :
210// ============================================================================
211
212const Handle(StepShape_TopologicalRepresentationItem)&
213TopoDSToStep_Builder::Value() const
214{
215 StdFail_NotDone_Raise_if(!done,"");
216 return myResult;
217}
218
219// ============================================================================
220// Method : TopoDSToStep_Builder::Error
221// Purpose :
222// ============================================================================
223
224TopoDSToStep_BuilderError TopoDSToStep_Builder::Error() const
225{
226 return myError;
227}
228