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