0025717: Non reentrant (and hence non-thread-safe) math_RealRandom / _IntegerRandom
[occt.git] / src / BRepToIGES / BRepToIGES_BRShell.cxx
CommitLineData
b311480e 1// Created on: 1995-01-30
2// Created by: Marie Jose MARTZ
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17//:n3 abv 8 Feb 99: PRO17820: BRepTools::OuterWire() -> ShapeAnalysis::OuterWire
18//szv#4 S4163
19
20#include <BRepToIGES_BRShell.ixx>
21#include <BRepToIGES_BRWire.hxx>
22
23#include <BRep_Tool.hxx>
24#include <BRepTools.hxx>
25
26#include <gp.hxx>
27#include <gp_Trsf.hxx>
28
29#include <Geom_ConicalSurface.hxx>
30#include <Geom_CylindricalSurface.hxx>
31#include <Geom_RectangularTrimmedSurface.hxx>
32#include <Geom_SphericalSurface.hxx>
33#include <Geom_Surface.hxx>
34#include <Geom_SurfaceOfRevolution.hxx>
35#include <Geom_ToroidalSurface.hxx>
36
37#include <GeomToIGES_GeomSurface.hxx>
38
39#include <IGESBasic_Group.hxx>
40#include <IGESData_HArray1OfIGESEntity.hxx>
41#include <IGESData_IGESEntity.hxx>
42
43#include <IGESGeom_CurveOnSurface.hxx>
44#include <IGESGeom_HArray1OfCurveOnSurface.hxx>
45#include <IGESGeom_TrimmedSurface.hxx>
46#include <IGESGeom_SurfaceOfRevolution.hxx>
47
48#include <Interface_Macros.hxx>
49
50#include <TColStd_HSequenceOfTransient.hxx>
51
52#include <TopLoc_Location.hxx>
53
54#include <TopoDS.hxx>
55#include <TopoDS_Vertex.hxx>
56#include <TopoDS_Edge.hxx>
57#include <TopoDS_Face.hxx>
58#include <TopoDS_Shell.hxx>
59#include <TopoDS_Wire.hxx>
60#include <TopoDS_Shape.hxx>
61
62#include <TopAbs_ShapeEnum.hxx>
63#include <TopExp.hxx>
64#include <TopExp_Explorer.hxx>
65
66#include <ShapeAlgo.hxx>
67#include <ShapeAlgo_AlgoContainer.hxx>
68
69#include <Message_ProgressIndicator.hxx>
70#include <Transfer_FinderProcess.hxx>
71
72//=============================================================================
73// BRepToIGES_BRShell
74//=============================================================================
75
76BRepToIGES_BRShell::BRepToIGES_BRShell()
77{
78}
79
80
81//=============================================================================
82// BRepToIGES_BRShell
83//=============================================================================
84
85BRepToIGES_BRShell::BRepToIGES_BRShell
86(const BRepToIGES_BREntity& BR)
87: BRepToIGES_BREntity(BR)
88{
89}
90
91
92//=============================================================================
93// TransferShell
94//=============================================================================
95
96Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferShell(const TopoDS_Shape& start)
97{
98 Handle(IGESData_IGESEntity) res;
99
100 if (start.IsNull()) return res;
101
102 if (start.ShapeType() == TopAbs_FACE) {
103 TopoDS_Face F = TopoDS::Face(start);
104 res = TransferFace(F);
105 }
106 else if (start.ShapeType() == TopAbs_SHELL) {
107 TopoDS_Shell S = TopoDS::Shell(start);
108 res = TransferShell(S);
109 }
110 else {
111 // message d`erreur
112 }
113 return res;
114}
115
116
117//=============================================================================
118// TransferFace
119//
120//=============================================================================
121
122Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& start)
123{
124 Handle(IGESData_IGESEntity) res;
125
126 Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress();
127 if ( ! progress.IsNull() ) {
128 if ( progress->UserBreak() ) return res;
129 progress->Increment();
130 }
131
132 if ( start.IsNull()) {
133 return res;
134 }
135 //Standard_Integer Nb = 0; //szv#4:S4163:12Mar99 unused
136 Standard_Real Length = 1.;
137 Handle(IGESData_IGESEntity) ISurf;
138
139 // returns the face surface
140 // ------------------------
141
142 Handle(Geom_Surface) Surf = BRep_Tool::Surface(start);
143 Handle(Geom_Surface) Surf1;
144
145 if (!Surf.IsNull()) {
146 Standard_Real U1, U2, V1, V2;
147 // pour limiter les surfaces de base
148 BRepTools::UVBounds(start, U1, U2, V1, V2);
149 GeomToIGES_GeomSurface GS;
150 GS.SetModel(GetModel());
151 ISurf = GS.TransferSurface(Surf, U1, U2, V1, V2);
152 if (ISurf.IsNull()) {
153 AddWarning (start, "the basic surface is a null entity");
154 return res;
155 }
156 Length = GS.Length();
157
158 // modif mjm du 17/07/97
159 if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
160 DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf);
161 Surf1 = rectang->BasisSurface();
162 }
163 else
164 Surf1 = Surf;
165 }
166
167
168 // returns the wires of the face
169 // -----------------------------
170
171 BRepToIGES_BRWire BW(*this);
172 Standard_Integer Imode = 0;
173 Standard_Integer Iprefer = 0;
174 Handle(IGESData_IGESEntity) ICurve2d;
175 // pour explorer la face , il faut la mettre fORWARD.
176 TopoDS_Face myface = start;
177 Standard_Boolean IsReversed = Standard_False;
178 if (start.Orientation() == TopAbs_REVERSED) {
179 myface.Reverse();
180 IsReversed = Standard_True;
181 }
182
183 // outer wire
184//:n3 TopoDS_Wire Outer = BRepTools::OuterWire(myface);
185 TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3
186 Handle(IGESGeom_CurveOnSurface) IOuter = new IGESGeom_CurveOnSurface;
187 if (!Outer.IsNull()) {
188 Handle(IGESData_IGESEntity) ICurve3d =
189 BW.TransferWire(Outer, myface, ICurve2d, Length);
190 if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3;
191 if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2;
192 if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1;
193 IOuter -> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer);
194 }
195
196 // inners wires
197 TopExp_Explorer Ex;
198 Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
199
200 for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) {
201 TopoDS_Wire W = TopoDS::Wire(Ex.Current());
202 Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface;
203 if (W.IsNull()) {
204 AddWarning(start," an Wire is a null entity");
205 }
206 else if (!W.IsSame(Outer)) {
207 Handle(IGESData_IGESEntity) ICurve3d =
208 BW.TransferWire(W, myface, ICurve2d, Length);
209 if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3;
210 if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2;
211 if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1;
212 Curve-> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer);
213 if (!Curve.IsNull()) Seq->Append(Curve);
214 }
215 }
216
217 // all inners edges not in a wire
218 for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) {
219 TopoDS_Edge E = TopoDS::Edge(Ex.Current());
220 Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface;
221 if (E.IsNull()) {
222 AddWarning(start," an Edge is a null entity");
223 }
224 else {
225 Handle(IGESData_IGESEntity) ICurve3d = BW.TransferEdge(E, Standard_False);
226 Handle(IGESData_IGESEntity) newICurve2d = BW.TransferEdge(E, myface, Length, Standard_False);
227 if ((!ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 3;
228 if ((!ICurve3d.IsNull()) && (newICurve2d.IsNull())) Iprefer = 2;
229 if ((ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 1;
230 Curve-> Init (Imode, ISurf, newICurve2d, ICurve3d, Iprefer);
231 if (!Curve.IsNull()) Seq->Append(Curve);
232 }
233 }
234
235
236 Standard_Integer nbent = Seq->Length();
237 Handle(IGESGeom_HArray1OfCurveOnSurface) Tab;
238 if (nbent >=1) {
239 Tab = new IGESGeom_HArray1OfCurveOnSurface(1,nbent);
240 for (Standard_Integer itab = 1; itab <= nbent; itab++) {
241 Handle(IGESGeom_CurveOnSurface) item = GetCasted(IGESGeom_CurveOnSurface, Seq->Value(itab));
242 Tab->SetValue(itab,item);
243 }
244 }
245
246 // returns the TrimmedSurface
247 // --------------------------
fdabc211 248 Standard_Boolean Flag = Standard_True;
7fd59977 249 Handle(IGESGeom_TrimmedSurface) TrimmedSurf = new IGESGeom_TrimmedSurface;
fdabc211 250 if (BRep_Tool::NaturalRestriction(start)) {
251 //if face bounds and surface bounds are same, outer wire is unnecessary
252 Standard_Boolean Flag = Standard_False;
253 TrimmedSurf-> Init (ISurf, Flag, NULL, Tab);
254 }
255 else
256 TrimmedSurf-> Init (ISurf, Flag, IOuter, Tab);
7fd59977 257
258 res = TrimmedSurf;
259 if (IsReversed) myface.Reverse();
260
261 SetShapeResult ( start, res );
262
263 return res;
264}
265
266
267//=============================================================================
268// TransferShell
269//=============================================================================
270
271Handle(IGESData_IGESEntity) BRepToIGES_BRShell::TransferShell(const TopoDS_Shell& start)
272{
273 Handle(IGESData_IGESEntity) res;
274 if ( start.IsNull()) return res;
275
276 TopExp_Explorer Ex;
277 Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
278 Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
279 Handle(IGESData_IGESEntity) IFace;
280
281 for (Ex.Init(start,TopAbs_FACE); Ex.More(); Ex.Next()) {
282 TopoDS_Face F = TopoDS::Face(Ex.Current());
283 if (F.IsNull()) {
284 AddWarning(start," a Face is a null entity");
285 }
286 else {
287 IFace = TransferFace(F);
288 if (!IFace.IsNull()) Seq->Append(IFace);
289 }
290 }
291
292
293 Standard_Integer nbfaces = Seq->Length();
294 Handle(IGESData_HArray1OfIGESEntity) Tab;
295 if ( nbfaces >= 1) {
296 Tab = new IGESData_HArray1OfIGESEntity(1,nbfaces);
297 for (Standard_Integer itab = 1; itab <= nbfaces; itab++) {
298 Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
299 Tab->SetValue(itab,item);
300 }
301 }
302
303 if (nbfaces == 1) {
304 res = IFace;
305 }
306 else {
307 IGroup->Init(Tab);
308 res = IGroup;
309 }
310
311 SetShapeResult ( start, res );
312
313 return res;
314}
315
316
317
318