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 | |
2157cfd0 |
20 | #include <BRep_Builder.hxx> |
7fd59977 |
21 | #include <BRep_Tool.hxx> |
42cf5bc1 |
22 | #include <BRepToIGES_BREntity.hxx> |
23 | #include <BRepToIGES_BRShell.hxx> |
24 | #include <BRepToIGES_BRWire.hxx> |
7fd59977 |
25 | #include <BRepTools.hxx> |
42cf5bc1 |
26 | #include <Geom2d_Curve.hxx> |
7fd59977 |
27 | #include <Geom_ConicalSurface.hxx> |
28 | #include <Geom_CylindricalSurface.hxx> |
29 | #include <Geom_RectangularTrimmedSurface.hxx> |
30 | #include <Geom_SphericalSurface.hxx> |
31 | #include <Geom_Surface.hxx> |
32 | #include <Geom_SurfaceOfRevolution.hxx> |
33 | #include <Geom_ToroidalSurface.hxx> |
7fd59977 |
34 | #include <GeomToIGES_GeomSurface.hxx> |
42cf5bc1 |
35 | #include <gp.hxx> |
36 | #include <gp_Trsf.hxx> |
7fd59977 |
37 | #include <IGESBasic_Group.hxx> |
38 | #include <IGESData_HArray1OfIGESEntity.hxx> |
39 | #include <IGESData_IGESEntity.hxx> |
7fd59977 |
40 | #include <IGESGeom_CurveOnSurface.hxx> |
41 | #include <IGESGeom_HArray1OfCurveOnSurface.hxx> |
7fd59977 |
42 | #include <IGESGeom_SurfaceOfRevolution.hxx> |
42cf5bc1 |
43 | #include <IGESGeom_TrimmedSurface.hxx> |
7fd59977 |
44 | #include <Interface_Macros.hxx> |
42cf5bc1 |
45 | #include <Message_ProgressIndicator.hxx> |
2157cfd0 |
46 | #include <NCollection_IncAllocator.hxx> |
42cf5bc1 |
47 | #include <NCollection_Map.hxx> |
48 | #include <ShapeAlgo.hxx> |
49 | #include <ShapeAlgo_AlgoContainer.hxx> |
7fd59977 |
50 | #include <TColStd_HSequenceOfTransient.hxx> |
42cf5bc1 |
51 | #include <TopAbs_ShapeEnum.hxx> |
52 | #include <TopExp.hxx> |
53 | #include <TopExp_Explorer.hxx> |
7fd59977 |
54 | #include <TopLoc_Location.hxx> |
7fd59977 |
55 | #include <TopoDS.hxx> |
7fd59977 |
56 | #include <TopoDS_Edge.hxx> |
57 | #include <TopoDS_Face.hxx> |
42cf5bc1 |
58 | #include <TopoDS_Shape.hxx> |
7fd59977 |
59 | #include <TopoDS_Shell.hxx> |
42cf5bc1 |
60 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
61 | #include <TopoDS_Wire.hxx> |
42cf5bc1 |
62 | #include <TopTools_ShapeMapHasher.hxx> |
7fd59977 |
63 | #include <Transfer_FinderProcess.hxx> |
64 | |
65 | //============================================================================= |
66 | // BRepToIGES_BRShell |
67 | //============================================================================= |
7fd59977 |
68 | BRepToIGES_BRShell::BRepToIGES_BRShell() |
69 | { |
70 | } |
71 | |
72 | |
73 | //============================================================================= |
74 | // BRepToIGES_BRShell |
75 | //============================================================================= |
76 | |
77 | BRepToIGES_BRShell::BRepToIGES_BRShell |
78 | (const BRepToIGES_BREntity& BR) |
79 | : BRepToIGES_BREntity(BR) |
80 | { |
81 | } |
82 | |
83 | |
84 | //============================================================================= |
85 | // TransferShell |
86 | //============================================================================= |
87 | |
88 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferShell(const TopoDS_Shape& start) |
89 | { |
90 | Handle(IGESData_IGESEntity) res; |
91 | |
92 | if (start.IsNull()) return res; |
93 | |
94 | if (start.ShapeType() == TopAbs_FACE) { |
95 | TopoDS_Face F = TopoDS::Face(start); |
96 | res = TransferFace(F); |
97 | } |
98 | else if (start.ShapeType() == TopAbs_SHELL) { |
99 | TopoDS_Shell S = TopoDS::Shell(start); |
100 | res = TransferShell(S); |
101 | } |
102 | else { |
103 | // message d`erreur |
104 | } |
105 | return res; |
106 | } |
107 | |
108 | |
109 | //============================================================================= |
110 | // TransferFace |
111 | // |
112 | //============================================================================= |
113 | |
114 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell ::TransferFace(const TopoDS_Face& start) |
115 | { |
116 | Handle(IGESData_IGESEntity) res; |
117 | |
118 | Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress(); |
119 | if ( ! progress.IsNull() ) { |
120 | if ( progress->UserBreak() ) return res; |
121 | progress->Increment(); |
122 | } |
123 | |
124 | if ( start.IsNull()) { |
125 | return res; |
126 | } |
2157cfd0 |
127 | |
128 | // pour explorer la face , il faut la mettre fORWARD. |
129 | TopoDS_Face myface; |
130 | if (start.Orientation() == TopAbs_REVERSED) { |
131 | //create face with redirected surface |
132 | BRep_Builder B; |
133 | TopLoc_Location aLoc; |
134 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(start, aLoc); |
135 | aSurf = aSurf->UReversed(); |
136 | Standard_Real U1, U2, V1, V2; |
137 | aSurf->Bounds(U1, U2, V1, V2); |
138 | Standard_Real aTol = BRep_Tool::Tolerance(start); |
139 | B.MakeFace(myface, aSurf, aLoc ,aTol); |
140 | // set specifics flags of a Face |
141 | B.NaturalRestriction(myface, BRep_Tool::NaturalRestriction(start)); |
142 | //add wires |
143 | TopoDS_Wire anOuter = TopoDS::Wire(ShapeAlgo::AlgoContainer()->OuterWire(start)); |
144 | TopExp_Explorer ex; |
145 | for (ex.Init(start,TopAbs_WIRE); ex.More(); ex.Next()) { |
146 | TopoDS_Wire W = TopoDS::Wire(ex.Current()); |
147 | if (!W.IsNull() && W.IsSame(anOuter)) { |
148 | B.Add(myface, W); |
149 | break; |
150 | } |
151 | } |
152 | for (ex.Init(start,TopAbs_WIRE); ex.More(); ex.Next()) { |
153 | TopoDS_Wire W = TopoDS::Wire(ex.Current()); |
154 | if (!W.IsNull() && !W.IsSame(anOuter)) { |
155 | B.Add(myface, W); |
156 | } |
157 | } |
158 | // mirror pcurves |
159 | NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> aMap (101, new NCollection_IncAllocator); |
160 | for (ex.Init(myface,TopAbs_EDGE);ex.More(); ex.Next()) { |
161 | TopoDS_Edge anEdge = TopoDS::Edge(ex.Current()); |
162 | if (!aMap.Add(anEdge)) |
163 | // seam edge has been already updated |
164 | continue; |
165 | Standard_Real f, l; |
166 | Handle(Geom2d_Curve) aCurve1, aCurve2; |
167 | aCurve1 = BRep_Tool::CurveOnSurface(anEdge, start, f, l); |
168 | aTol = BRep_Tool::Tolerance(anEdge); |
169 | gp_Trsf2d T; |
170 | gp_Ax2d axis(gp_Pnt2d(0.5 * (U1 + U2), V1), gp_Dir2d(0.,1.)); |
171 | T.SetMirror(axis); |
172 | if (!aCurve1.IsNull()) { |
173 | aCurve1 = Handle(Geom2d_Curve)::DownCast(aCurve1->Transformed(T)); |
174 | if (BRepTools::IsReallyClosed(anEdge, start)) { |
175 | TopoDS_Edge revEdge = TopoDS::Edge(anEdge.Reversed()); |
176 | aCurve2 = BRep_Tool::CurveOnSurface(revEdge, start, f, l); |
177 | if (!aCurve2.IsNull()) { |
178 | aCurve2 = Handle(Geom2d_Curve)::DownCast(aCurve2->Transformed(T)); |
179 | B.UpdateEdge(anEdge, aCurve1, aCurve2, myface, aTol); |
180 | } |
181 | else { |
182 | B.UpdateEdge(anEdge, aCurve1, myface, aTol); |
183 | } |
184 | } |
185 | else { |
186 | B.UpdateEdge(anEdge, aCurve1, myface, aTol); |
187 | } |
188 | } |
189 | } |
190 | } |
191 | else { |
192 | myface = start; |
193 | } |
194 | |
7fd59977 |
195 | //Standard_Integer Nb = 0; //szv#4:S4163:12Mar99 unused |
196 | Standard_Real Length = 1.; |
197 | Handle(IGESData_IGESEntity) ISurf; |
198 | |
199 | // returns the face surface |
200 | // ------------------------ |
201 | |
2157cfd0 |
202 | Handle(Geom_Surface) Surf = BRep_Tool::Surface(myface); |
7fd59977 |
203 | Handle(Geom_Surface) Surf1; |
204 | |
205 | if (!Surf.IsNull()) { |
206 | Standard_Real U1, U2, V1, V2; |
207 | // pour limiter les surfaces de base |
2157cfd0 |
208 | BRepTools::UVBounds(myface, U1, U2, V1, V2); |
7fd59977 |
209 | GeomToIGES_GeomSurface GS; |
210 | GS.SetModel(GetModel()); |
211 | ISurf = GS.TransferSurface(Surf, U1, U2, V1, V2); |
212 | if (ISurf.IsNull()) { |
213 | AddWarning (start, "the basic surface is a null entity"); |
214 | return res; |
215 | } |
216 | Length = GS.Length(); |
217 | |
218 | // modif mjm du 17/07/97 |
219 | if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
220 | DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf); |
221 | Surf1 = rectang->BasisSurface(); |
222 | } |
223 | else |
224 | Surf1 = Surf; |
225 | } |
226 | |
227 | |
228 | // returns the wires of the face |
229 | // ----------------------------- |
230 | |
231 | BRepToIGES_BRWire BW(*this); |
232 | Standard_Integer Imode = 0; |
233 | Standard_Integer Iprefer = 0; |
234 | Handle(IGESData_IGESEntity) ICurve2d; |
7fd59977 |
235 | |
236 | // outer wire |
2157cfd0 |
237 | //:n3 TopoDS_Wire Outer = BRepTools::OuterWire(myface); |
7fd59977 |
238 | TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3 |
239 | Handle(IGESGeom_CurveOnSurface) IOuter = new IGESGeom_CurveOnSurface; |
240 | if (!Outer.IsNull()) { |
241 | Handle(IGESData_IGESEntity) ICurve3d = |
242 | BW.TransferWire(Outer, myface, ICurve2d, Length); |
243 | if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; |
244 | if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; |
245 | if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; |
246 | IOuter -> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer); |
247 | } |
248 | |
249 | // inners wires |
250 | TopExp_Explorer Ex; |
251 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
252 | |
253 | for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) { |
254 | TopoDS_Wire W = TopoDS::Wire(Ex.Current()); |
255 | Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; |
256 | if (W.IsNull()) { |
257 | AddWarning(start," an Wire is a null entity"); |
258 | } |
259 | else if (!W.IsSame(Outer)) { |
260 | Handle(IGESData_IGESEntity) ICurve3d = |
2157cfd0 |
261 | BW.TransferWire(W, myface, ICurve2d, Length); |
7fd59977 |
262 | if ((!ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 3; |
263 | if ((!ICurve3d.IsNull()) && (ICurve2d.IsNull())) Iprefer = 2; |
264 | if ((ICurve3d.IsNull()) && (!ICurve2d.IsNull())) Iprefer = 1; |
265 | Curve-> Init (Imode, ISurf, ICurve2d, ICurve3d, Iprefer); |
266 | if (!Curve.IsNull()) Seq->Append(Curve); |
267 | } |
268 | } |
269 | |
270 | // all inners edges not in a wire |
271 | for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) { |
272 | TopoDS_Edge E = TopoDS::Edge(Ex.Current()); |
273 | Handle(IGESGeom_CurveOnSurface) Curve = new IGESGeom_CurveOnSurface; |
274 | if (E.IsNull()) { |
275 | AddWarning(start," an Edge is a null entity"); |
276 | } |
277 | else { |
278 | Handle(IGESData_IGESEntity) ICurve3d = BW.TransferEdge(E, Standard_False); |
279 | Handle(IGESData_IGESEntity) newICurve2d = BW.TransferEdge(E, myface, Length, Standard_False); |
280 | if ((!ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 3; |
281 | if ((!ICurve3d.IsNull()) && (newICurve2d.IsNull())) Iprefer = 2; |
282 | if ((ICurve3d.IsNull()) && (!newICurve2d.IsNull())) Iprefer = 1; |
283 | Curve-> Init (Imode, ISurf, newICurve2d, ICurve3d, Iprefer); |
284 | if (!Curve.IsNull()) Seq->Append(Curve); |
285 | } |
286 | } |
287 | |
288 | |
289 | Standard_Integer nbent = Seq->Length(); |
290 | Handle(IGESGeom_HArray1OfCurveOnSurface) Tab; |
291 | if (nbent >=1) { |
292 | Tab = new IGESGeom_HArray1OfCurveOnSurface(1,nbent); |
293 | for (Standard_Integer itab = 1; itab <= nbent; itab++) { |
294 | Handle(IGESGeom_CurveOnSurface) item = GetCasted(IGESGeom_CurveOnSurface, Seq->Value(itab)); |
295 | Tab->SetValue(itab,item); |
296 | } |
297 | } |
298 | |
299 | // returns the TrimmedSurface |
300 | // -------------------------- |
fdabc211 |
301 | Standard_Boolean Flag = Standard_True; |
7fd59977 |
302 | Handle(IGESGeom_TrimmedSurface) TrimmedSurf = new IGESGeom_TrimmedSurface; |
fdabc211 |
303 | if (BRep_Tool::NaturalRestriction(start)) { |
304 | //if face bounds and surface bounds are same, outer wire is unnecessary |
305 | Standard_Boolean Flag = Standard_False; |
306 | TrimmedSurf-> Init (ISurf, Flag, NULL, Tab); |
307 | } |
308 | else |
309 | TrimmedSurf-> Init (ISurf, Flag, IOuter, Tab); |
7fd59977 |
310 | |
311 | res = TrimmedSurf; |
7fd59977 |
312 | SetShapeResult ( start, res ); |
7fd59977 |
313 | return res; |
314 | } |
315 | |
316 | |
317 | //============================================================================= |
318 | // TransferShell |
319 | //============================================================================= |
320 | |
321 | Handle(IGESData_IGESEntity) BRepToIGES_BRShell::TransferShell(const TopoDS_Shell& start) |
322 | { |
323 | Handle(IGESData_IGESEntity) res; |
324 | if ( start.IsNull()) return res; |
325 | |
326 | TopExp_Explorer Ex; |
327 | Handle(IGESBasic_Group) IGroup = new IGESBasic_Group; |
328 | Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient(); |
329 | Handle(IGESData_IGESEntity) IFace; |
330 | |
331 | for (Ex.Init(start,TopAbs_FACE); Ex.More(); Ex.Next()) { |
332 | TopoDS_Face F = TopoDS::Face(Ex.Current()); |
333 | if (F.IsNull()) { |
334 | AddWarning(start," a Face is a null entity"); |
335 | } |
336 | else { |
337 | IFace = TransferFace(F); |
338 | if (!IFace.IsNull()) Seq->Append(IFace); |
339 | } |
340 | } |
341 | |
342 | |
343 | Standard_Integer nbfaces = Seq->Length(); |
344 | Handle(IGESData_HArray1OfIGESEntity) Tab; |
345 | if ( nbfaces >= 1) { |
346 | Tab = new IGESData_HArray1OfIGESEntity(1,nbfaces); |
347 | for (Standard_Integer itab = 1; itab <= nbfaces; itab++) { |
348 | Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab)); |
349 | Tab->SetValue(itab,item); |
350 | } |
351 | } |
352 | |
353 | if (nbfaces == 1) { |
354 | res = IFace; |
355 | } |
356 | else { |
357 | IGroup->Init(Tab); |
358 | res = IGroup; |
359 | } |
360 | |
361 | SetShapeResult ( start, res ); |
362 | |
363 | return res; |
364 | } |
365 | |
366 | |
367 | |
368 | |