Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-07-23 |
2 | // Created by: Remi LEQUETTE | |
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 | ||
23 | #include <BRepLib_MakeFace.ixx> | |
24 | ||
25 | #include <Geom_Plane.hxx> | |
26 | #include <Geom_CylindricalSurface.hxx> | |
27 | #include <Geom_ConicalSurface.hxx> | |
28 | #include <Geom_SphericalSurface.hxx> | |
29 | #include <Geom_ToroidalSurface.hxx> | |
30 | #include <Geom_RectangularTrimmedSurface.hxx> | |
31 | #include <Geom_OffsetSurface.hxx> | |
32 | #include <Geom_BSplineCurve.hxx> | |
33 | #include <Geom_BezierCurve.hxx> | |
34 | #include <GeomAdaptor_Curve.hxx> | |
35 | #include <GeomAbs_CurveType.hxx> | |
36 | ||
37 | #include <Geom2d_Line.hxx> | |
38 | ||
39 | #include <BRep_Builder.hxx> | |
40 | ||
41 | #include <TopoDS.hxx> | |
42 | #include <TopoDS_Vertex.hxx> | |
43 | #include <TopoDS_Edge.hxx> | |
44 | #include <TopoDS_Iterator.hxx> | |
45 | ||
46 | #include <BRepTopAdaptor_FClass2d.hxx> | |
47 | #include <TopAbs_State.hxx> | |
48 | ||
49 | #include <ElCLib.hxx> | |
50 | #include <Precision.hxx> | |
51 | #include <BRepLib.hxx> | |
52 | ||
53 | #include <BRepLib_FindSurface.hxx> | |
54 | #include <Geom_SurfaceOfLinearExtrusion.hxx> | |
55 | #include <Geom_SurfaceOfRevolution.hxx> | |
56 | ||
57 | //======================================================================= | |
58 | //function : BRepLib_MakeFace | |
59 | //purpose : | |
60 | //======================================================================= | |
61 | ||
62 | BRepLib_MakeFace::BRepLib_MakeFace() : | |
63 | myError(BRepLib_NoFace) | |
64 | { | |
65 | } | |
66 | ||
67 | ||
68 | //======================================================================= | |
69 | //function : BRepLib_MakeFace | |
70 | //purpose : | |
71 | //======================================================================= | |
72 | ||
73 | BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Face& F) | |
74 | { | |
75 | Init(F); | |
76 | } | |
77 | ||
78 | ||
79 | //======================================================================= | |
80 | //function : BRepLib_MakeFace | |
81 | //purpose : | |
82 | //======================================================================= | |
83 | ||
84 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Pln& P) | |
85 | { | |
86 | Handle(Geom_Plane) GP = new Geom_Plane(P); | |
1c72dff6 | 87 | Init(GP, Standard_True, Precision::Confusion()); |
7fd59977 | 88 | } |
89 | ||
90 | ||
91 | //======================================================================= | |
92 | //function : BRepLib_MakeFace | |
93 | //purpose : | |
94 | //======================================================================= | |
95 | ||
96 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cylinder& C) | |
97 | { | |
98 | Handle(Geom_CylindricalSurface) GC = new Geom_CylindricalSurface(C); | |
1c72dff6 | 99 | Init(GC, Standard_True, Precision::Confusion()); |
7fd59977 | 100 | } |
101 | ||
102 | ||
103 | //======================================================================= | |
104 | //function : BRepLib_MakeFace | |
105 | //purpose : | |
106 | //======================================================================= | |
107 | ||
108 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cone& C) | |
109 | { | |
110 | Handle(Geom_ConicalSurface) GC = new Geom_ConicalSurface(C); | |
1c72dff6 | 111 | Init(GC, Standard_True, Precision::Confusion()); |
7fd59977 | 112 | } |
113 | ||
114 | ||
115 | //======================================================================= | |
116 | //function : BRepLib_MakeFace | |
117 | //purpose : | |
118 | //======================================================================= | |
119 | ||
120 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Sphere& S) | |
121 | { | |
122 | Handle(Geom_SphericalSurface) GS = new Geom_SphericalSurface(S); | |
1c72dff6 | 123 | Init(GS, Standard_True, Precision::Confusion()); |
7fd59977 | 124 | } |
125 | ||
126 | ||
127 | //======================================================================= | |
128 | //function : BRepLib_MakeFace | |
129 | //purpose : | |
130 | //======================================================================= | |
131 | ||
132 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Torus& T) | |
133 | { | |
134 | Handle(Geom_ToroidalSurface) GT = new Geom_ToroidalSurface(T); | |
1c72dff6 | 135 | Init(GT, Standard_True, Precision::Confusion()); |
7fd59977 | 136 | } |
137 | ||
138 | ||
139 | //======================================================================= | |
140 | //function : BRepLib_MakeFace | |
141 | //purpose : | |
142 | //======================================================================= | |
143 | ||
1c72dff6 S |
144 | BRepLib_MakeFace::BRepLib_MakeFace(const Handle(Geom_Surface)& S, |
145 | const Standard_Real TolDegen) | |
7fd59977 | 146 | { |
1c72dff6 | 147 | Init(S, Standard_True, TolDegen); |
7fd59977 | 148 | } |
149 | ||
150 | ||
151 | //======================================================================= | |
152 | //function : BRepLib_MakeFace | |
153 | //purpose : | |
154 | //======================================================================= | |
155 | ||
156 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Pln& P, | |
1c72dff6 S |
157 | const Standard_Real UMin, |
158 | const Standard_Real UMax, | |
159 | const Standard_Real VMin, | |
160 | const Standard_Real VMax) | |
7fd59977 | 161 | { |
162 | Handle(Geom_Plane) GP = new Geom_Plane(P); | |
1c72dff6 | 163 | Init(GP, UMin, UMax, VMin, VMax, Precision::Confusion()); |
7fd59977 | 164 | } |
165 | ||
166 | ||
167 | //======================================================================= | |
168 | //function : BRepLib_MakeFace | |
169 | //purpose : | |
170 | //======================================================================= | |
171 | ||
172 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cylinder& C, | |
1c72dff6 S |
173 | const Standard_Real UMin, |
174 | const Standard_Real UMax, | |
175 | const Standard_Real VMin, | |
176 | const Standard_Real VMax) | |
7fd59977 | 177 | { |
178 | Handle(Geom_CylindricalSurface) GC = new Geom_CylindricalSurface(C); | |
1c72dff6 | 179 | Init(GC, UMin, UMax, VMin, VMax, Precision::Confusion()); |
7fd59977 | 180 | } |
181 | ||
182 | ||
183 | //======================================================================= | |
184 | //function : BRepLib_MakeFace | |
185 | //purpose : | |
186 | //======================================================================= | |
187 | ||
188 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cone& C, | |
1c72dff6 S |
189 | const Standard_Real UMin, |
190 | const Standard_Real UMax, | |
191 | const Standard_Real VMin, | |
192 | const Standard_Real VMax) | |
7fd59977 | 193 | { |
194 | Handle(Geom_ConicalSurface) GC = new Geom_ConicalSurface(C); | |
1c72dff6 | 195 | Init(GC, UMin, UMax, VMin, VMax, Precision::Confusion()); |
7fd59977 | 196 | } |
197 | ||
198 | ||
199 | //======================================================================= | |
200 | //function : BRepLib_MakeFace | |
201 | //purpose : | |
202 | //======================================================================= | |
203 | ||
204 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Sphere& S, | |
1c72dff6 S |
205 | const Standard_Real UMin, |
206 | const Standard_Real UMax, | |
207 | const Standard_Real VMin, | |
208 | const Standard_Real VMax) | |
7fd59977 | 209 | { |
210 | Handle(Geom_SphericalSurface) GS = new Geom_SphericalSurface(S); | |
1c72dff6 | 211 | Init(GS, UMin, UMax, VMin, VMax, Precision::Confusion()); |
7fd59977 | 212 | } |
213 | ||
214 | ||
215 | //======================================================================= | |
216 | //function : BRepLib_MakeFace | |
217 | //purpose : | |
218 | //======================================================================= | |
219 | ||
220 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Torus& T, | |
1c72dff6 S |
221 | const Standard_Real UMin, |
222 | const Standard_Real UMax, | |
223 | const Standard_Real VMin, | |
224 | const Standard_Real VMax) | |
7fd59977 | 225 | { |
226 | Handle(Geom_ToroidalSurface) GT = new Geom_ToroidalSurface(T); | |
1c72dff6 | 227 | Init(GT, UMin, UMax, VMin, VMax, Precision::Confusion()); |
7fd59977 | 228 | } |
229 | ||
230 | ||
231 | //======================================================================= | |
232 | //function : BRepLib_MakeFace | |
233 | //purpose : | |
234 | //======================================================================= | |
235 | ||
236 | BRepLib_MakeFace::BRepLib_MakeFace(const Handle(Geom_Surface)& S, | |
1c72dff6 S |
237 | const Standard_Real UMin, |
238 | const Standard_Real UMax, | |
239 | const Standard_Real VMin, | |
240 | const Standard_Real VMax, | |
241 | const Standard_Real TolDegen) | |
7fd59977 | 242 | { |
1c72dff6 | 243 | Init(S, UMin, UMax, VMin, VMax, TolDegen); |
7fd59977 | 244 | } |
245 | ||
246 | ||
247 | //======================================================================= | |
248 | //function : BRepLib_MakeFace | |
249 | //purpose : | |
250 | //======================================================================= | |
251 | ||
252 | BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Wire& W, | |
1c72dff6 | 253 | const Standard_Boolean OnlyPlane) |
7fd59977 | 254 | |
255 | { | |
256 | // Find a surface through the wire | |
257 | BRepLib_FindSurface FS(W, -1, OnlyPlane); | |
258 | if (!FS.Found()) { | |
259 | myError = BRepLib_NotPlanar; | |
260 | return; | |
261 | } | |
262 | ||
263 | // build the face and add the wire | |
264 | BRep_Builder B; | |
265 | myError = BRepLib_FaceDone; | |
266 | ||
267 | Standard_Real tol = Max(1.2*FS.ToleranceReached(), FS.Tolerance()); | |
268 | ||
269 | B.MakeFace(TopoDS::Face(myShape),FS.Surface(),FS.Location(),tol); | |
270 | Add(W); | |
271 | ||
272 | BRepLib::UpdateTolerances(myShape); | |
273 | ||
274 | CheckInside(); | |
275 | } | |
276 | ||
277 | ||
278 | //======================================================================= | |
279 | //function : BRepLib_MakeFace | |
280 | //purpose : | |
281 | //======================================================================= | |
282 | ||
283 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Pln& P, | |
1c72dff6 S |
284 | const TopoDS_Wire& W, |
285 | const Standard_Boolean Inside) | |
7fd59977 | 286 | { |
287 | Handle(Geom_Plane) Pl = new Geom_Plane(P); | |
1c72dff6 | 288 | Init(Pl, Standard_False, Precision::Confusion()); |
7fd59977 | 289 | Add(W); |
290 | if (Inside) CheckInside(); | |
291 | } | |
292 | ||
293 | ||
294 | //======================================================================= | |
295 | //function : BRepLib_MakeFace | |
296 | //purpose : | |
297 | //======================================================================= | |
298 | ||
299 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cylinder& C, | |
1c72dff6 S |
300 | const TopoDS_Wire& W, |
301 | const Standard_Boolean Inside) | |
7fd59977 | 302 | { |
303 | Handle(Geom_CylindricalSurface) GC = new Geom_CylindricalSurface(C); | |
1c72dff6 | 304 | Init(GC, Standard_False, Precision::Confusion()); |
7fd59977 | 305 | Add(W); |
306 | if (Inside) CheckInside(); | |
307 | } | |
308 | ||
309 | ||
310 | //======================================================================= | |
311 | //function : BRepLib_MakeFace | |
312 | //purpose : | |
313 | //======================================================================= | |
314 | ||
315 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cone& C, | |
1c72dff6 S |
316 | const TopoDS_Wire& W, |
317 | const Standard_Boolean Inside) | |
7fd59977 | 318 | { |
319 | Handle(Geom_ConicalSurface) GC = new Geom_ConicalSurface(C); | |
1c72dff6 | 320 | Init(GC, Standard_False, Precision::Confusion()); |
7fd59977 | 321 | Add(W); |
322 | if (Inside) CheckInside(); | |
323 | } | |
324 | ||
325 | ||
326 | //======================================================================= | |
327 | //function : BRepLib_MakeFace | |
328 | //purpose : | |
329 | //======================================================================= | |
330 | ||
331 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Sphere& S, | |
1c72dff6 S |
332 | const TopoDS_Wire& W, |
333 | const Standard_Boolean Inside) | |
7fd59977 | 334 | { |
335 | Handle(Geom_SphericalSurface) GS = new Geom_SphericalSurface(S); | |
1c72dff6 | 336 | Init(GS, Standard_False, Precision::Confusion()); |
7fd59977 | 337 | Add(W); |
338 | if (Inside) CheckInside(); | |
339 | } | |
340 | ||
341 | ||
342 | //======================================================================= | |
343 | //function : BRepLib_MakeFace | |
344 | //purpose : | |
345 | //======================================================================= | |
346 | ||
347 | BRepLib_MakeFace::BRepLib_MakeFace(const gp_Torus& T, | |
1c72dff6 S |
348 | const TopoDS_Wire& W, |
349 | const Standard_Boolean Inside) | |
7fd59977 | 350 | { |
351 | Handle(Geom_ToroidalSurface) GT = new Geom_ToroidalSurface(T); | |
1c72dff6 | 352 | Init(GT, Standard_False, Precision::Confusion()); |
7fd59977 | 353 | Add(W); |
354 | if (Inside) CheckInside(); | |
355 | } | |
356 | ||
357 | ||
358 | //======================================================================= | |
359 | //function : BRepLib_MakeFace | |
360 | //purpose : | |
361 | //======================================================================= | |
362 | ||
363 | BRepLib_MakeFace::BRepLib_MakeFace(const Handle(Geom_Surface)& S, | |
1c72dff6 S |
364 | const TopoDS_Wire& W, |
365 | const Standard_Boolean Inside) | |
7fd59977 | 366 | { |
1c72dff6 | 367 | Init(S, Standard_False, Precision::Confusion()); |
7fd59977 | 368 | Add(W); |
369 | if (Inside) CheckInside(); | |
370 | } | |
371 | ||
372 | ||
373 | //======================================================================= | |
374 | //function : BRepLib_MakeFace | |
375 | //purpose : | |
376 | //======================================================================= | |
377 | ||
378 | BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Face& F, | |
1c72dff6 | 379 | const TopoDS_Wire& W) |
7fd59977 | 380 | { |
381 | Init(F); | |
382 | Add(W); | |
383 | } | |
384 | ||
385 | //======================================================================= | |
386 | //function : Init | |
387 | //purpose : | |
388 | //======================================================================= | |
389 | ||
390 | void BRepLib_MakeFace::Init(const TopoDS_Face& F) | |
391 | { | |
392 | // copy the face | |
393 | myShape = F.EmptyCopied(); | |
394 | myError = BRepLib_FaceDone; | |
395 | ||
396 | BRep_Builder B; | |
397 | TopoDS_Iterator It(F); | |
398 | while (It.More()) { | |
399 | B.Add(myShape,It.Value()); | |
400 | It.Next(); | |
401 | } | |
402 | } | |
403 | ||
404 | //======================================================================= | |
405 | //function : Init | |
406 | //purpose : | |
407 | //======================================================================= | |
408 | ||
409 | void BRepLib_MakeFace::Init(const Handle(Geom_Surface)& S, | |
1c72dff6 S |
410 | const Standard_Boolean Bound, |
411 | const Standard_Real TolDegen) | |
7fd59977 | 412 | { |
413 | myError = BRepLib_FaceDone; | |
414 | if (Bound) { | |
415 | Standard_Real UMin,UMax,VMin,VMax; | |
416 | S->Bounds(UMin,UMax,VMin,VMax); | |
1c72dff6 | 417 | Init(S,UMin,UMax,VMin,VMax,TolDegen); |
7fd59977 | 418 | } |
419 | else { | |
420 | BRep_Builder B; | |
421 | B.MakeFace(TopoDS::Face(myShape),S,Precision::Confusion()); | |
422 | } | |
423 | BRep_Builder B; | |
424 | B.NaturalRestriction(TopoDS::Face(myShape),Standard_True); | |
425 | } | |
426 | ||
427 | ||
428 | //======================================================================= | |
429 | //function : IsDegenerated | |
1c72dff6 S |
430 | //purpose : Checks whether the passed curve is degenerated with the |
431 | // passed tolerance value | |
7fd59977 | 432 | //======================================================================= |
433 | ||
1c72dff6 S |
434 | static Standard_Boolean IsDegenerated(const Handle(Geom_Curve)& theCurve, |
435 | const Standard_Real theMaxTol, | |
436 | Standard_Real& theActTol) | |
7fd59977 | 437 | { |
1c72dff6 S |
438 | GeomAdaptor_Curve AC(theCurve); |
439 | Standard_Real aConfusion = Precision::Confusion(); | |
440 | theActTol = aConfusion; | |
7fd59977 | 441 | GeomAbs_CurveType Type = AC.GetType(); |
1c72dff6 | 442 | |
7fd59977 | 443 | if (Type == GeomAbs_Circle) { |
444 | gp_Circ Circ = AC.Circle(); | |
1c72dff6 S |
445 | if ( Circ.Radius() > theMaxTol ) |
446 | return Standard_False; | |
447 | theActTol = Max(Circ.Radius(), aConfusion); | |
448 | return Standard_True; | |
7fd59977 | 449 | } |
450 | else if (Type == GeomAbs_BSplineCurve) { | |
451 | Handle(Geom_BSplineCurve) BS = AC.BSpline(); | |
452 | Standard_Integer NbPoles = BS->NbPoles(); | |
1c72dff6 | 453 | Standard_Real aMaxPoleDist2 = 0.0, aMaxTol2 = theMaxTol*theMaxTol; |
7fd59977 | 454 | gp_Pnt P1,P2; |
455 | P1 = BS->Pole(1); | |
456 | for (Standard_Integer i = 2; i <= NbPoles; i++) { | |
457 | P2 = BS->Pole(i); | |
1c72dff6 S |
458 | Standard_Real aPoleDist2 = P1.SquareDistance(P2); |
459 | if (aPoleDist2 > aMaxTol2) | |
460 | return Standard_False; | |
461 | if (aPoleDist2 > aMaxPoleDist2) | |
462 | aMaxPoleDist2 = aPoleDist2; | |
7fd59977 | 463 | } |
1c72dff6 | 464 | theActTol = Max(1.000001*Sqrt(aMaxPoleDist2), aConfusion); |
7fd59977 | 465 | return Standard_True; |
466 | } | |
467 | else if (Type == GeomAbs_BezierCurve) { | |
468 | Handle(Geom_BezierCurve) BZ = AC.Bezier(); | |
469 | Standard_Integer NbPoles = BZ->NbPoles(); | |
1c72dff6 | 470 | Standard_Real aMaxPoleDist2 = 0.0, aMaxTol2 = theMaxTol*theMaxTol;; |
7fd59977 | 471 | gp_Pnt P1,P2; |
472 | P1 = BZ->Pole(1); | |
473 | for (Standard_Integer i = 2; i <= NbPoles; i++) { | |
474 | P2 = BZ->Pole(i); | |
1c72dff6 S |
475 | Standard_Real aPoleDist2 = P1.SquareDistance(P2); |
476 | if (aPoleDist2 > aMaxTol2) | |
477 | return Standard_False; | |
478 | if (aPoleDist2 > aMaxPoleDist2) | |
479 | aMaxPoleDist2 = aPoleDist2; | |
7fd59977 | 480 | } |
1c72dff6 | 481 | theActTol = Max(1.000001*Sqrt(aMaxPoleDist2), aConfusion); |
7fd59977 | 482 | return Standard_True; |
483 | } | |
484 | ||
485 | return Standard_False; | |
486 | } | |
487 | ||
488 | //======================================================================= | |
489 | //function : Init | |
490 | //purpose : | |
491 | //======================================================================= | |
492 | ||
493 | void BRepLib_MakeFace::Init(const Handle(Geom_Surface)& SS, | |
1c72dff6 S |
494 | const Standard_Real Um, |
495 | const Standard_Real UM, | |
496 | const Standard_Real Vm, | |
497 | const Standard_Real VM, | |
498 | const Standard_Real TolDegen) | |
7fd59977 | 499 | { |
500 | myError = BRepLib_FaceDone; | |
501 | ||
502 | Standard_Real UMin = Um; | |
503 | Standard_Real UMax = UM; | |
504 | Standard_Real VMin = Vm; | |
505 | Standard_Real VMax = VM; | |
506 | ||
507 | Standard_Real umin,umax,vmin,vmax,T; | |
508 | ||
509 | Handle(Geom_Surface) S = SS; | |
510 | Handle(Geom_RectangularTrimmedSurface) RS = | |
511 | Handle(Geom_RectangularTrimmedSurface)::DownCast(S); | |
512 | if (!RS.IsNull()) | |
513 | S = RS->BasisSurface(); | |
514 | ||
515 | ||
516 | Standard_Boolean OffsetSurface = | |
517 | (S->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)); | |
518 | ||
519 | // adjust periodical surface or reordonate | |
520 | // check if the values are in the natural range | |
521 | Standard_Real epsilon = Precision::PConfusion(); | |
522 | ||
523 | S->Bounds(umin,umax,vmin,vmax); | |
524 | ||
525 | if (OffsetSurface) { | |
526 | Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(S); | |
527 | Handle(Geom_Surface) Base = OS->BasisSurface(); | |
528 | ||
529 | if (Base->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) { | |
530 | if (Precision::IsInfinite(umin) || Precision::IsInfinite(umax)) | |
531 | S = new Geom_RectangularTrimmedSurface(OS, UMin, UMax, VMin, VMax); | |
532 | else | |
533 | S = new Geom_RectangularTrimmedSurface(OS, VMin, VMax, Standard_False); | |
534 | } else if (Base->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) { | |
535 | if (Precision::IsInfinite(vmin) || Precision::IsInfinite(vmax)) | |
536 | S = new Geom_RectangularTrimmedSurface(OS, VMin, VMax, Standard_False); | |
537 | } | |
538 | } | |
539 | ||
540 | if (S->IsUPeriodic()) { | |
541 | ElCLib::AdjustPeriodic(umin,umax,epsilon,UMin,UMax); | |
542 | } | |
543 | else if (UMin > UMax) { | |
544 | T = UMin; | |
545 | UMin = UMax; | |
546 | UMax = T; | |
547 | if ((umin - UMin > epsilon) || (UMax - umax > epsilon)) { | |
548 | myError = BRepLib_ParametersOutOfRange; | |
549 | return; | |
550 | } | |
551 | } | |
552 | ||
553 | if (S->IsVPeriodic()) { | |
554 | ElCLib::AdjustPeriodic(vmin,vmax,epsilon,VMin,VMax); | |
555 | } | |
556 | else if (VMin > VMax) { | |
557 | T = VMin; | |
558 | VMin = VMax; | |
559 | VMax = T; | |
560 | if ((vmin - VMin > epsilon) || (VMax - vmax > epsilon)) { | |
561 | myError = BRepLib_ParametersOutOfRange; | |
562 | return; | |
563 | } | |
564 | } | |
565 | ||
566 | ||
567 | // compute infinite flags | |
568 | Standard_Boolean umininf = Precision::IsNegativeInfinite(UMin); | |
569 | Standard_Boolean umaxinf = Precision::IsPositiveInfinite(UMax); | |
570 | Standard_Boolean vmininf = Precision::IsNegativeInfinite(VMin); | |
571 | Standard_Boolean vmaxinf = Precision::IsPositiveInfinite(VMax); | |
572 | ||
573 | // closed flag | |
574 | Standard_Boolean uclosed = | |
575 | S->IsUClosed() && | |
576 | Abs(UMin - umin) < epsilon && | |
577 | Abs(UMax - umax) < epsilon; | |
578 | ||
579 | Standard_Boolean vclosed = | |
580 | S->IsVClosed() && | |
581 | Abs(VMin - vmin) < epsilon && | |
582 | Abs(VMax - vmax) < epsilon; | |
583 | ||
584 | ||
585 | // compute 3d curves and degenerate flag | |
1c72dff6 | 586 | Standard_Real maxTol = TolDegen; |
7fd59977 | 587 | Handle(Geom_Curve) Cumin,Cumax,Cvmin,Cvmax; |
588 | Standard_Boolean Dumin,Dumax,Dvmin,Dvmax; | |
589 | Dumin = Dumax = Dvmin = Dvmax = Standard_False; | |
1c72dff6 | 590 | Standard_Real uminTol, umaxTol, vminTol, vmaxTol; |
7fd59977 | 591 | |
592 | if (!umininf) { | |
593 | Cumin = S->UIso(UMin); | |
1c72dff6 | 594 | Dumin = IsDegenerated(Cumin, maxTol, uminTol); |
7fd59977 | 595 | } |
596 | if (!umaxinf) { | |
597 | Cumax = S->UIso(UMax); | |
1c72dff6 | 598 | Dumax = IsDegenerated(Cumax, maxTol, umaxTol); |
7fd59977 | 599 | } |
600 | if (!vmininf) { | |
601 | Cvmin = S->VIso(VMin); | |
1c72dff6 | 602 | Dvmin = IsDegenerated(Cvmin, maxTol, vminTol); |
7fd59977 | 603 | } |
604 | if (!vmaxinf) { | |
605 | Cvmax = S->VIso(VMax); | |
1c72dff6 | 606 | Dvmax = IsDegenerated(Cvmax, maxTol, vmaxTol); |
7fd59977 | 607 | } |
608 | ||
609 | // compute vertices | |
610 | BRep_Builder B; | |
611 | ||
612 | TopoDS_Vertex V00,V10,V11,V01; | |
613 | ||
614 | if (!umininf) { | |
1c72dff6 S |
615 | if (!vmininf) B.MakeVertex(V00,S->Value(UMin,VMin), Max(uminTol, vminTol)); |
616 | if (!vmaxinf) B.MakeVertex(V01,S->Value(UMin,VMax), Max(uminTol, vmaxTol)); | |
7fd59977 | 617 | } |
618 | if (!umaxinf) { | |
1c72dff6 S |
619 | if (!vmininf) B.MakeVertex(V10,S->Value(UMax,VMin), Max(umaxTol, vminTol)); |
620 | if (!vmaxinf) B.MakeVertex(V11,S->Value(UMax,VMax), Max(umaxTol, vmaxTol)); | |
7fd59977 | 621 | } |
622 | ||
623 | if (uclosed) { | |
624 | V10 = V00; | |
625 | V11 = V01; | |
626 | } | |
627 | ||
628 | if (vclosed) { | |
629 | V01 = V00; | |
630 | V11 = V10; | |
631 | } | |
632 | ||
633 | if (Dumin) V00 = V01; | |
634 | if (Dumax) V10 = V11; | |
635 | if (Dvmin) V00 = V10; | |
636 | if (Dvmax) V01 = V11; | |
637 | ||
638 | // make the lines | |
639 | Handle(Geom2d_Line) Lumin,Lumax,Lvmin,Lvmax; | |
640 | if (!umininf) | |
641 | Lumin = new Geom2d_Line(gp_Pnt2d(UMin,0),gp_Dir2d(0,1)); | |
642 | if (!umaxinf) | |
643 | Lumax = new Geom2d_Line(gp_Pnt2d(UMax,0),gp_Dir2d(0,1)); | |
644 | if (!vmininf) | |
645 | Lvmin = new Geom2d_Line(gp_Pnt2d(0,VMin),gp_Dir2d(1,0)); | |
646 | if (!vmaxinf) | |
647 | Lvmax = new Geom2d_Line(gp_Pnt2d(0,VMax),gp_Dir2d(1,0)); | |
648 | ||
649 | // make the face | |
650 | TopoDS_Face& F = TopoDS::Face(myShape); | |
1c72dff6 | 651 | B.MakeFace(F,S,Precision::Confusion()); |
7fd59977 | 652 | |
653 | // make the edges | |
654 | TopoDS_Edge eumin,eumax,evmin,evmax; | |
655 | ||
656 | if (!umininf) { | |
657 | if (!Dumin) | |
1c72dff6 | 658 | B.MakeEdge(eumin,Cumin,uminTol); |
7fd59977 | 659 | else |
660 | B.MakeEdge(eumin); | |
661 | if (uclosed) | |
1c72dff6 | 662 | B.UpdateEdge(eumin,Lumax,Lumin,F,Max(uminTol, umaxTol)); |
7fd59977 | 663 | else |
1c72dff6 | 664 | B.UpdateEdge(eumin,Lumin,F,uminTol); |
7fd59977 | 665 | B.Degenerated(eumin,Dumin); |
666 | if (!vmininf) { | |
667 | V00.Orientation(TopAbs_FORWARD); | |
668 | B.Add(eumin,V00); | |
669 | } | |
670 | if (!vmaxinf) { | |
671 | V01.Orientation(TopAbs_REVERSED); | |
672 | B.Add(eumin,V01); | |
673 | } | |
674 | B.Range(eumin,VMin,VMax); | |
675 | } | |
676 | ||
677 | if (!umaxinf) { | |
678 | if (uclosed) | |
679 | eumax = eumin; | |
680 | else { | |
681 | if (!Dumax) | |
1c72dff6 | 682 | B.MakeEdge(eumax,Cumax,umaxTol); |
7fd59977 | 683 | else |
684 | B.MakeEdge(eumax); | |
1c72dff6 | 685 | B.UpdateEdge(eumax,Lumax,F,umaxTol); |
7fd59977 | 686 | B.Degenerated(eumax,Dumax); |
687 | if (!vmininf) { | |
688 | V10.Orientation(TopAbs_FORWARD); | |
689 | B.Add(eumax,V10); | |
690 | } | |
691 | if (!vmaxinf) { | |
692 | V11.Orientation(TopAbs_REVERSED); | |
693 | B.Add(eumax,V11); | |
694 | } | |
695 | B.Range(eumax,VMin,VMax); | |
696 | } | |
697 | } | |
698 | ||
699 | if (!vmininf) { | |
700 | if (!Dvmin) | |
1c72dff6 | 701 | B.MakeEdge(evmin,Cvmin,vminTol); |
7fd59977 | 702 | else |
703 | B.MakeEdge(evmin); | |
704 | if (vclosed) | |
1c72dff6 | 705 | B.UpdateEdge(evmin,Lvmin,Lvmax,F,Max(vminTol, vmaxTol)); |
7fd59977 | 706 | else |
1c72dff6 | 707 | B.UpdateEdge(evmin,Lvmin,F,vminTol); |
7fd59977 | 708 | B.Degenerated(evmin,Dvmin); |
709 | if (!umininf) { | |
710 | V00.Orientation(TopAbs_FORWARD); | |
711 | B.Add(evmin,V00); | |
712 | } | |
713 | if (!umaxinf) { | |
714 | V10.Orientation(TopAbs_REVERSED); | |
715 | B.Add(evmin,V10); | |
716 | } | |
717 | B.Range(evmin,UMin,UMax); | |
718 | } | |
719 | ||
720 | if (!vmaxinf) { | |
721 | if (vclosed) | |
722 | evmax = evmin; | |
723 | else { | |
724 | if (!Dvmax) | |
1c72dff6 | 725 | B.MakeEdge(evmax,Cvmax,vmaxTol); |
7fd59977 | 726 | else |
727 | B.MakeEdge(evmax); | |
1c72dff6 | 728 | B.UpdateEdge(evmax,Lvmax,F,vmaxTol); |
7fd59977 | 729 | B.Degenerated(evmax,Dvmax); |
730 | if (!umininf) { | |
731 | V01.Orientation(TopAbs_FORWARD); | |
732 | B.Add(evmax,V01); | |
733 | } | |
734 | if (!umaxinf) { | |
735 | V11.Orientation(TopAbs_REVERSED); | |
736 | B.Add(evmax,V11); | |
737 | } | |
738 | B.Range(evmax,UMin,UMax); | |
739 | } | |
740 | } | |
741 | ||
742 | // make the wires and add them to the face | |
743 | eumin.Orientation(TopAbs_REVERSED); | |
744 | evmax.Orientation(TopAbs_REVERSED); | |
745 | ||
746 | TopoDS_Wire W; | |
747 | ||
748 | if (!umininf && !umaxinf && vmininf && vmaxinf) { | |
749 | // two wires in u | |
750 | B.MakeWire(W); | |
751 | B.Add(W,eumin); | |
752 | B.Add(F,W); | |
753 | B.MakeWire(W); | |
754 | B.Add(W,eumax); | |
755 | B.Add(F,W); | |
756 | F.Closed(uclosed); | |
757 | } | |
758 | ||
759 | else if (umininf && umaxinf && !vmininf && !vmaxinf) { | |
760 | // two wires in v | |
761 | B.MakeWire(W); | |
762 | B.Add(W,evmin); | |
763 | B.Add(F,W); | |
764 | B.MakeWire(W); | |
765 | B.Add(W,evmax); | |
766 | B.Add(F,W); | |
767 | F.Closed(vclosed); | |
768 | } | |
769 | ||
770 | else if (!umininf || !umaxinf || !vmininf || !vmaxinf) { | |
771 | // one wire | |
772 | B.MakeWire(W); | |
773 | if (!umininf) B.Add(W,eumin); | |
774 | if (!vmininf) B.Add(W,evmin); | |
775 | if (!umaxinf) B.Add(W,eumax); | |
776 | if (!vmaxinf) B.Add(W,evmax); | |
777 | B.Add(F,W); | |
778 | W.Closed(!umininf && !umaxinf && !vmininf && !vmaxinf); | |
779 | F.Closed(uclosed && vclosed); | |
780 | } | |
781 | ||
782 | if (OffsetSurface) { | |
783 | // Les Isos sont Approximees a Precision::Approximation() | |
784 | // et on code Precision::Confusion() dans l'arete. | |
785 | // ==> Un petit passage dans SamePrameter pour regler les tolerances. | |
1c72dff6 | 786 | BRepLib::SameParameter(F, Precision::Confusion(), Standard_True); |
7fd59977 | 787 | } |
788 | ||
789 | Done(); | |
790 | } | |
791 | ||
792 | ||
793 | //======================================================================= | |
794 | //function : Add | |
795 | //purpose : | |
796 | //======================================================================= | |
797 | ||
798 | void BRepLib_MakeFace::Add(const TopoDS_Wire& W) | |
799 | { | |
800 | BRep_Builder B; | |
801 | B.Add(myShape,W); | |
802 | B.NaturalRestriction(TopoDS::Face(myShape),Standard_False); | |
803 | Done(); | |
804 | } | |
805 | ||
806 | ||
807 | //======================================================================= | |
808 | //function : Face | |
809 | //purpose : | |
810 | //======================================================================= | |
811 | ||
812 | const TopoDS_Face& BRepLib_MakeFace::Face()const | |
813 | { | |
814 | return TopoDS::Face(myShape); | |
815 | } | |
816 | ||
817 | ||
818 | ||
819 | //======================================================================= | |
820 | //function : operator | |
821 | //purpose : | |
822 | //======================================================================= | |
823 | ||
824 | BRepLib_MakeFace::operator TopoDS_Face() const | |
825 | { | |
826 | return Face(); | |
827 | } | |
828 | ||
829 | //======================================================================= | |
830 | //function : Error | |
831 | //purpose : | |
832 | //======================================================================= | |
833 | ||
834 | BRepLib_FaceError BRepLib_MakeFace::Error() const | |
835 | { | |
836 | return myError; | |
837 | } | |
838 | ||
839 | ||
840 | //======================================================================= | |
841 | //function : CheckInside | |
842 | //purpose : Reverses the current face if not a bounded area | |
843 | //======================================================================= | |
844 | ||
845 | void BRepLib_MakeFace::CheckInside() | |
846 | { | |
847 | // compute the area and return the face if the area is negative | |
848 | TopoDS_Face F = TopoDS::Face(myShape); | |
849 | BRepTopAdaptor_FClass2d FClass(F,0.); | |
850 | if ( FClass.PerformInfinitePoint() == TopAbs_IN) { | |
851 | BRep_Builder B; | |
852 | TopoDS_Shape S = myShape.EmptyCopied(); | |
853 | TopoDS_Iterator it(myShape); | |
854 | while (it.More()) { | |
855 | B.Add(S,it.Value().Reversed()); | |
856 | it.Next(); | |
857 | } | |
858 | myShape = S; | |
859 | } | |
860 | } |