0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / BRepLib / BRepLib_MakeFace.cxx
CommitLineData
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
62BRepLib_MakeFace::BRepLib_MakeFace() :
63 myError(BRepLib_NoFace)
64{
65}
66
67
68//=======================================================================
69//function : BRepLib_MakeFace
70//purpose :
71//=======================================================================
72
73BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Face& F)
74{
75 Init(F);
76}
77
78
79//=======================================================================
80//function : BRepLib_MakeFace
81//purpose :
82//=======================================================================
83
84BRepLib_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
96BRepLib_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
108BRepLib_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
120BRepLib_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
132BRepLib_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
144BRepLib_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
156BRepLib_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
172BRepLib_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
188BRepLib_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
204BRepLib_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
220BRepLib_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
236BRepLib_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
252BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Wire& W,
1c72dff6 253 const Standard_Boolean OnlyPlane)
7fd59977 254
255{
256 // Find a surface through the wire
26347898 257 BRepLib_FindSurface FS(W, -1, OnlyPlane, Standard_True);
7fd59977 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);
26347898 271 //
7fd59977 272 BRepLib::UpdateTolerances(myShape);
26347898 273 //
274 BRepLib::SameParameter(myShape, tol, Standard_True);
275 //
7fd59977 276 CheckInside();
277}
278
279
280//=======================================================================
281//function : BRepLib_MakeFace
282//purpose :
283//=======================================================================
284
285BRepLib_MakeFace::BRepLib_MakeFace(const gp_Pln& P,
1c72dff6
S
286 const TopoDS_Wire& W,
287 const Standard_Boolean Inside)
7fd59977 288{
289 Handle(Geom_Plane) Pl = new Geom_Plane(P);
1c72dff6 290 Init(Pl, Standard_False, Precision::Confusion());
7fd59977 291 Add(W);
292 if (Inside) CheckInside();
293}
294
295
296//=======================================================================
297//function : BRepLib_MakeFace
298//purpose :
299//=======================================================================
300
301BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cylinder& C,
1c72dff6
S
302 const TopoDS_Wire& W,
303 const Standard_Boolean Inside)
7fd59977 304{
305 Handle(Geom_CylindricalSurface) GC = new Geom_CylindricalSurface(C);
1c72dff6 306 Init(GC, Standard_False, Precision::Confusion());
7fd59977 307 Add(W);
308 if (Inside) CheckInside();
309}
310
311
312//=======================================================================
313//function : BRepLib_MakeFace
314//purpose :
315//=======================================================================
316
317BRepLib_MakeFace::BRepLib_MakeFace(const gp_Cone& C,
1c72dff6
S
318 const TopoDS_Wire& W,
319 const Standard_Boolean Inside)
7fd59977 320{
321 Handle(Geom_ConicalSurface) GC = new Geom_ConicalSurface(C);
1c72dff6 322 Init(GC, Standard_False, Precision::Confusion());
7fd59977 323 Add(W);
324 if (Inside) CheckInside();
325}
326
327
328//=======================================================================
329//function : BRepLib_MakeFace
330//purpose :
331//=======================================================================
332
333BRepLib_MakeFace::BRepLib_MakeFace(const gp_Sphere& S,
1c72dff6
S
334 const TopoDS_Wire& W,
335 const Standard_Boolean Inside)
7fd59977 336{
337 Handle(Geom_SphericalSurface) GS = new Geom_SphericalSurface(S);
1c72dff6 338 Init(GS, Standard_False, Precision::Confusion());
7fd59977 339 Add(W);
340 if (Inside) CheckInside();
341}
342
343
344//=======================================================================
345//function : BRepLib_MakeFace
346//purpose :
347//=======================================================================
348
349BRepLib_MakeFace::BRepLib_MakeFace(const gp_Torus& T,
1c72dff6
S
350 const TopoDS_Wire& W,
351 const Standard_Boolean Inside)
7fd59977 352{
353 Handle(Geom_ToroidalSurface) GT = new Geom_ToroidalSurface(T);
1c72dff6 354 Init(GT, Standard_False, Precision::Confusion());
7fd59977 355 Add(W);
356 if (Inside) CheckInside();
357}
358
359
360//=======================================================================
361//function : BRepLib_MakeFace
362//purpose :
363//=======================================================================
364
365BRepLib_MakeFace::BRepLib_MakeFace(const Handle(Geom_Surface)& S,
1c72dff6
S
366 const TopoDS_Wire& W,
367 const Standard_Boolean Inside)
7fd59977 368{
1c72dff6 369 Init(S, Standard_False, Precision::Confusion());
7fd59977 370 Add(W);
371 if (Inside) CheckInside();
372}
373
374
375//=======================================================================
376//function : BRepLib_MakeFace
377//purpose :
378//=======================================================================
379
380BRepLib_MakeFace::BRepLib_MakeFace(const TopoDS_Face& F,
1c72dff6 381 const TopoDS_Wire& W)
7fd59977 382{
383 Init(F);
384 Add(W);
385}
386
387//=======================================================================
388//function : Init
389//purpose :
390//=======================================================================
391
392void BRepLib_MakeFace::Init(const TopoDS_Face& F)
393{
394 // copy the face
395 myShape = F.EmptyCopied();
396 myError = BRepLib_FaceDone;
397
398 BRep_Builder B;
399 TopoDS_Iterator It(F);
400 while (It.More()) {
401 B.Add(myShape,It.Value());
402 It.Next();
403 }
404}
405
406//=======================================================================
407//function : Init
408//purpose :
409//=======================================================================
410
411void BRepLib_MakeFace::Init(const Handle(Geom_Surface)& S,
1c72dff6
S
412 const Standard_Boolean Bound,
413 const Standard_Real TolDegen)
7fd59977 414{
415 myError = BRepLib_FaceDone;
416 if (Bound) {
417 Standard_Real UMin,UMax,VMin,VMax;
418 S->Bounds(UMin,UMax,VMin,VMax);
1c72dff6 419 Init(S,UMin,UMax,VMin,VMax,TolDegen);
7fd59977 420 }
421 else {
422 BRep_Builder B;
423 B.MakeFace(TopoDS::Face(myShape),S,Precision::Confusion());
424 }
425 BRep_Builder B;
426 B.NaturalRestriction(TopoDS::Face(myShape),Standard_True);
427}
428
429
430//=======================================================================
431//function : IsDegenerated
1c72dff6
S
432//purpose : Checks whether the passed curve is degenerated with the
433// passed tolerance value
7fd59977 434//=======================================================================
435
1c72dff6
S
436static Standard_Boolean IsDegenerated(const Handle(Geom_Curve)& theCurve,
437 const Standard_Real theMaxTol,
438 Standard_Real& theActTol)
7fd59977 439{
1c72dff6
S
440 GeomAdaptor_Curve AC(theCurve);
441 Standard_Real aConfusion = Precision::Confusion();
442 theActTol = aConfusion;
7fd59977 443 GeomAbs_CurveType Type = AC.GetType();
1c72dff6 444
7fd59977 445 if (Type == GeomAbs_Circle) {
446 gp_Circ Circ = AC.Circle();
1c72dff6
S
447 if ( Circ.Radius() > theMaxTol )
448 return Standard_False;
449 theActTol = Max(Circ.Radius(), aConfusion);
450 return Standard_True;
7fd59977 451 }
452 else if (Type == GeomAbs_BSplineCurve) {
453 Handle(Geom_BSplineCurve) BS = AC.BSpline();
454 Standard_Integer NbPoles = BS->NbPoles();
1c72dff6 455 Standard_Real aMaxPoleDist2 = 0.0, aMaxTol2 = theMaxTol*theMaxTol;
7fd59977 456 gp_Pnt P1,P2;
457 P1 = BS->Pole(1);
458 for (Standard_Integer i = 2; i <= NbPoles; i++) {
459 P2 = BS->Pole(i);
1c72dff6
S
460 Standard_Real aPoleDist2 = P1.SquareDistance(P2);
461 if (aPoleDist2 > aMaxTol2)
462 return Standard_False;
463 if (aPoleDist2 > aMaxPoleDist2)
464 aMaxPoleDist2 = aPoleDist2;
7fd59977 465 }
1c72dff6 466 theActTol = Max(1.000001*Sqrt(aMaxPoleDist2), aConfusion);
7fd59977 467 return Standard_True;
468 }
469 else if (Type == GeomAbs_BezierCurve) {
470 Handle(Geom_BezierCurve) BZ = AC.Bezier();
471 Standard_Integer NbPoles = BZ->NbPoles();
1c72dff6 472 Standard_Real aMaxPoleDist2 = 0.0, aMaxTol2 = theMaxTol*theMaxTol;;
7fd59977 473 gp_Pnt P1,P2;
474 P1 = BZ->Pole(1);
475 for (Standard_Integer i = 2; i <= NbPoles; i++) {
476 P2 = BZ->Pole(i);
1c72dff6
S
477 Standard_Real aPoleDist2 = P1.SquareDistance(P2);
478 if (aPoleDist2 > aMaxTol2)
479 return Standard_False;
480 if (aPoleDist2 > aMaxPoleDist2)
481 aMaxPoleDist2 = aPoleDist2;
7fd59977 482 }
1c72dff6 483 theActTol = Max(1.000001*Sqrt(aMaxPoleDist2), aConfusion);
7fd59977 484 return Standard_True;
485 }
486
487 return Standard_False;
488}
489
490//=======================================================================
491//function : Init
492//purpose :
493//=======================================================================
494
495void BRepLib_MakeFace::Init(const Handle(Geom_Surface)& SS,
1c72dff6
S
496 const Standard_Real Um,
497 const Standard_Real UM,
498 const Standard_Real Vm,
499 const Standard_Real VM,
500 const Standard_Real TolDegen)
7fd59977 501{
502 myError = BRepLib_FaceDone;
503
504 Standard_Real UMin = Um;
505 Standard_Real UMax = UM;
506 Standard_Real VMin = Vm;
507 Standard_Real VMax = VM;
508
509 Standard_Real umin,umax,vmin,vmax,T;
510
9d109e39 511 Handle(Geom_Surface) S = SS, BS = SS;
7fd59977 512 Handle(Geom_RectangularTrimmedSurface) RS =
513 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
514 if (!RS.IsNull())
9d109e39 515 BS = RS->BasisSurface();
7fd59977 516
517 Standard_Boolean OffsetSurface =
9d109e39 518 (BS->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface));
519
7fd59977 520 // adjust periodical surface or reordonate
521 // check if the values are in the natural range
522 Standard_Real epsilon = Precision::PConfusion();
523
9d109e39 524 BS->Bounds(umin,umax,vmin,vmax);
7fd59977 525
526 if (OffsetSurface) {
9d109e39 527 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(BS);
7fd59977 528 Handle(Geom_Surface) Base = OS->BasisSurface();
529
530 if (Base->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
531 if (Precision::IsInfinite(umin) || Precision::IsInfinite(umax))
532 S = new Geom_RectangularTrimmedSurface(OS, UMin, UMax, VMin, VMax);
533 else
534 S = new Geom_RectangularTrimmedSurface(OS, VMin, VMax, Standard_False);
535 } else if (Base->DynamicType() == STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
536 if (Precision::IsInfinite(vmin) || Precision::IsInfinite(vmax))
537 S = new Geom_RectangularTrimmedSurface(OS, VMin, VMax, Standard_False);
538 }
539 }
540
541 if (S->IsUPeriodic()) {
542 ElCLib::AdjustPeriodic(umin,umax,epsilon,UMin,UMax);
543 }
544 else if (UMin > UMax) {
545 T = UMin;
546 UMin = UMax;
547 UMax = T;
548 if ((umin - UMin > epsilon) || (UMax - umax > epsilon)) {
549 myError = BRepLib_ParametersOutOfRange;
550 return;
551 }
552 }
553
554 if (S->IsVPeriodic()) {
555 ElCLib::AdjustPeriodic(vmin,vmax,epsilon,VMin,VMax);
556 }
557 else if (VMin > VMax) {
558 T = VMin;
559 VMin = VMax;
560 VMax = T;
561 if ((vmin - VMin > epsilon) || (VMax - vmax > epsilon)) {
562 myError = BRepLib_ParametersOutOfRange;
563 return;
564 }
565 }
566
567
568 // compute infinite flags
569 Standard_Boolean umininf = Precision::IsNegativeInfinite(UMin);
570 Standard_Boolean umaxinf = Precision::IsPositiveInfinite(UMax);
571 Standard_Boolean vmininf = Precision::IsNegativeInfinite(VMin);
572 Standard_Boolean vmaxinf = Precision::IsPositiveInfinite(VMax);
573
574 // closed flag
575 Standard_Boolean uclosed =
576 S->IsUClosed() &&
577 Abs(UMin - umin) < epsilon &&
578 Abs(UMax - umax) < epsilon;
579
580 Standard_Boolean vclosed =
581 S->IsVClosed() &&
582 Abs(VMin - vmin) < epsilon &&
583 Abs(VMax - vmax) < epsilon;
584
585
586 // compute 3d curves and degenerate flag
1c72dff6 587 Standard_Real maxTol = TolDegen;
7fd59977 588 Handle(Geom_Curve) Cumin,Cumax,Cvmin,Cvmax;
589 Standard_Boolean Dumin,Dumax,Dvmin,Dvmax;
590 Dumin = Dumax = Dvmin = Dvmax = Standard_False;
1d47d8d0 591 Standard_Real uminTol = Precision::Confusion(),
592 umaxTol = Precision::Confusion(),
593 vminTol = Precision::Confusion(),
594 vmaxTol = Precision::Confusion();
7fd59977 595
596 if (!umininf) {
597 Cumin = S->UIso(UMin);
1c72dff6 598 Dumin = IsDegenerated(Cumin, maxTol, uminTol);
7fd59977 599 }
600 if (!umaxinf) {
601 Cumax = S->UIso(UMax);
1c72dff6 602 Dumax = IsDegenerated(Cumax, maxTol, umaxTol);
7fd59977 603 }
604 if (!vmininf) {
605 Cvmin = S->VIso(VMin);
1c72dff6 606 Dvmin = IsDegenerated(Cvmin, maxTol, vminTol);
7fd59977 607 }
608 if (!vmaxinf) {
609 Cvmax = S->VIso(VMax);
1c72dff6 610 Dvmax = IsDegenerated(Cvmax, maxTol, vmaxTol);
7fd59977 611 }
612
613 // compute vertices
614 BRep_Builder B;
615
616 TopoDS_Vertex V00,V10,V11,V01;
617
618 if (!umininf) {
1c72dff6
S
619 if (!vmininf) B.MakeVertex(V00,S->Value(UMin,VMin), Max(uminTol, vminTol));
620 if (!vmaxinf) B.MakeVertex(V01,S->Value(UMin,VMax), Max(uminTol, vmaxTol));
7fd59977 621 }
622 if (!umaxinf) {
1c72dff6
S
623 if (!vmininf) B.MakeVertex(V10,S->Value(UMax,VMin), Max(umaxTol, vminTol));
624 if (!vmaxinf) B.MakeVertex(V11,S->Value(UMax,VMax), Max(umaxTol, vmaxTol));
7fd59977 625 }
626
627 if (uclosed) {
628 V10 = V00;
629 V11 = V01;
630 }
631
632 if (vclosed) {
633 V01 = V00;
634 V11 = V10;
635 }
636
637 if (Dumin) V00 = V01;
638 if (Dumax) V10 = V11;
639 if (Dvmin) V00 = V10;
640 if (Dvmax) V01 = V11;
641
642 // make the lines
643 Handle(Geom2d_Line) Lumin,Lumax,Lvmin,Lvmax;
644 if (!umininf)
645 Lumin = new Geom2d_Line(gp_Pnt2d(UMin,0),gp_Dir2d(0,1));
646 if (!umaxinf)
647 Lumax = new Geom2d_Line(gp_Pnt2d(UMax,0),gp_Dir2d(0,1));
648 if (!vmininf)
649 Lvmin = new Geom2d_Line(gp_Pnt2d(0,VMin),gp_Dir2d(1,0));
650 if (!vmaxinf)
651 Lvmax = new Geom2d_Line(gp_Pnt2d(0,VMax),gp_Dir2d(1,0));
652
653 // make the face
654 TopoDS_Face& F = TopoDS::Face(myShape);
1c72dff6 655 B.MakeFace(F,S,Precision::Confusion());
7fd59977 656
657 // make the edges
658 TopoDS_Edge eumin,eumax,evmin,evmax;
659
660 if (!umininf) {
661 if (!Dumin)
1c72dff6 662 B.MakeEdge(eumin,Cumin,uminTol);
7fd59977 663 else
664 B.MakeEdge(eumin);
665 if (uclosed)
1c72dff6 666 B.UpdateEdge(eumin,Lumax,Lumin,F,Max(uminTol, umaxTol));
7fd59977 667 else
1c72dff6 668 B.UpdateEdge(eumin,Lumin,F,uminTol);
7fd59977 669 B.Degenerated(eumin,Dumin);
670 if (!vmininf) {
671 V00.Orientation(TopAbs_FORWARD);
672 B.Add(eumin,V00);
673 }
674 if (!vmaxinf) {
675 V01.Orientation(TopAbs_REVERSED);
676 B.Add(eumin,V01);
677 }
678 B.Range(eumin,VMin,VMax);
679 }
680
681 if (!umaxinf) {
682 if (uclosed)
683 eumax = eumin;
684 else {
685 if (!Dumax)
1c72dff6 686 B.MakeEdge(eumax,Cumax,umaxTol);
7fd59977 687 else
688 B.MakeEdge(eumax);
1c72dff6 689 B.UpdateEdge(eumax,Lumax,F,umaxTol);
7fd59977 690 B.Degenerated(eumax,Dumax);
691 if (!vmininf) {
692 V10.Orientation(TopAbs_FORWARD);
693 B.Add(eumax,V10);
694 }
695 if (!vmaxinf) {
696 V11.Orientation(TopAbs_REVERSED);
697 B.Add(eumax,V11);
698 }
699 B.Range(eumax,VMin,VMax);
700 }
701 }
702
703 if (!vmininf) {
704 if (!Dvmin)
1c72dff6 705 B.MakeEdge(evmin,Cvmin,vminTol);
7fd59977 706 else
707 B.MakeEdge(evmin);
708 if (vclosed)
1c72dff6 709 B.UpdateEdge(evmin,Lvmin,Lvmax,F,Max(vminTol, vmaxTol));
7fd59977 710 else
1c72dff6 711 B.UpdateEdge(evmin,Lvmin,F,vminTol);
7fd59977 712 B.Degenerated(evmin,Dvmin);
713 if (!umininf) {
714 V00.Orientation(TopAbs_FORWARD);
715 B.Add(evmin,V00);
716 }
717 if (!umaxinf) {
718 V10.Orientation(TopAbs_REVERSED);
719 B.Add(evmin,V10);
720 }
721 B.Range(evmin,UMin,UMax);
722 }
723
724 if (!vmaxinf) {
725 if (vclosed)
726 evmax = evmin;
727 else {
728 if (!Dvmax)
1c72dff6 729 B.MakeEdge(evmax,Cvmax,vmaxTol);
7fd59977 730 else
731 B.MakeEdge(evmax);
1c72dff6 732 B.UpdateEdge(evmax,Lvmax,F,vmaxTol);
7fd59977 733 B.Degenerated(evmax,Dvmax);
734 if (!umininf) {
735 V01.Orientation(TopAbs_FORWARD);
736 B.Add(evmax,V01);
737 }
738 if (!umaxinf) {
739 V11.Orientation(TopAbs_REVERSED);
740 B.Add(evmax,V11);
741 }
742 B.Range(evmax,UMin,UMax);
743 }
744 }
745
746 // make the wires and add them to the face
747 eumin.Orientation(TopAbs_REVERSED);
748 evmax.Orientation(TopAbs_REVERSED);
749
750 TopoDS_Wire W;
751
752 if (!umininf && !umaxinf && vmininf && vmaxinf) {
753 // two wires in u
754 B.MakeWire(W);
755 B.Add(W,eumin);
756 B.Add(F,W);
757 B.MakeWire(W);
758 B.Add(W,eumax);
759 B.Add(F,W);
760 F.Closed(uclosed);
761 }
762
763 else if (umininf && umaxinf && !vmininf && !vmaxinf) {
764 // two wires in v
765 B.MakeWire(W);
766 B.Add(W,evmin);
767 B.Add(F,W);
768 B.MakeWire(W);
769 B.Add(W,evmax);
770 B.Add(F,W);
771 F.Closed(vclosed);
772 }
773
774 else if (!umininf || !umaxinf || !vmininf || !vmaxinf) {
775 // one wire
776 B.MakeWire(W);
777 if (!umininf) B.Add(W,eumin);
778 if (!vmininf) B.Add(W,evmin);
779 if (!umaxinf) B.Add(W,eumax);
780 if (!vmaxinf) B.Add(W,evmax);
781 B.Add(F,W);
782 W.Closed(!umininf && !umaxinf && !vmininf && !vmaxinf);
783 F.Closed(uclosed && vclosed);
784 }
785
786 if (OffsetSurface) {
787 // Les Isos sont Approximees a Precision::Approximation()
788 // et on code Precision::Confusion() dans l'arete.
789 // ==> Un petit passage dans SamePrameter pour regler les tolerances.
1c72dff6 790 BRepLib::SameParameter(F, Precision::Confusion(), Standard_True);
7fd59977 791 }
792
793 Done();
794}
795
796
797//=======================================================================
798//function : Add
799//purpose :
800//=======================================================================
801
802void BRepLib_MakeFace::Add(const TopoDS_Wire& W)
803{
804 BRep_Builder B;
805 B.Add(myShape,W);
806 B.NaturalRestriction(TopoDS::Face(myShape),Standard_False);
807 Done();
808}
809
810
811//=======================================================================
812//function : Face
813//purpose :
814//=======================================================================
815
816const TopoDS_Face& BRepLib_MakeFace::Face()const
817{
818 return TopoDS::Face(myShape);
819}
820
821
822
823//=======================================================================
824//function : operator
825//purpose :
826//=======================================================================
827
828BRepLib_MakeFace::operator TopoDS_Face() const
829{
830 return Face();
831}
832
833//=======================================================================
834//function : Error
835//purpose :
836//=======================================================================
837
838BRepLib_FaceError BRepLib_MakeFace::Error() const
839{
840 return myError;
841}
842
843
844//=======================================================================
845//function : CheckInside
846//purpose : Reverses the current face if not a bounded area
847//=======================================================================
848
849void BRepLib_MakeFace::CheckInside()
850{
851 // compute the area and return the face if the area is negative
852 TopoDS_Face F = TopoDS::Face(myShape);
853 BRepTopAdaptor_FClass2d FClass(F,0.);
854 if ( FClass.PerformInfinitePoint() == TopAbs_IN) {
855 BRep_Builder B;
856 TopoDS_Shape S = myShape.EmptyCopied();
857 TopoDS_Iterator it(myShape);
858 while (it.More()) {
859 B.Add(S,it.Value().Reversed());
860 it.Next();
861 }
862 myShape = S;
863 }
864}