0024428: Implementation of LGPL license
[occt.git] / src / BRepFill / BRepFill_Generator.cxx
CommitLineData
b311480e 1// Created on: 1994-03-07
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1994-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
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.
7fd59977 16
17#include <BRepFill_Generator.ixx>
18
19#include <TopoDS_Face.hxx>
20#include <TopoDS_Wire.hxx>
21#include <TopoDS_Edge.hxx>
22#include <TopoDS_Vertex.hxx>
23#include <BRep_Builder.hxx>
24#include <TopLoc_Location.hxx>
25#include <TopExp_Explorer.hxx>
26#include <gp_Pnt2d.hxx>
27#include <gp_Dir2d.hxx>
28#include <gp_Ax1.hxx>
29#include <gp_Ax3.hxx>
30#include <gp_Circ.hxx>
31#include <gp_Lin.hxx>
32#include <GeomAbs_Shape.hxx>
33#include <GeomAdaptor_Curve.hxx>
34#include <Geom_Circle.hxx>
35#include <Geom_Line.hxx>
36#include <Geom_Curve.hxx>
37#include <Geom_BezierCurve.hxx>
38#include <Geom_TrimmedCurve.hxx>
39#include <Geom_Surface.hxx>
40#include <Geom_Plane.hxx>
41#include <Geom_CylindricalSurface.hxx>
42#include <Geom_ConicalSurface.hxx>
43#include <Geom_RectangularTrimmedSurface.hxx>
44#include <Geom2d_Line.hxx>
45#include <Geom2d_BezierCurve.hxx>
46#include <GeomFill_Generator.hxx>
47
48#include <TopTools_DataMapOfShapeShape.hxx>
49#include <GeomFill.hxx>
50#include <BRep_Tool.hxx>
51#include <TopoDS.hxx>
52#include <TopExp.hxx>
53#include <Precision.hxx>
54#include <BRepLib.hxx>
55
56#include <TColgp_Array1OfPnt.hxx>
57#include <TColgp_Array1OfPnt2d.hxx>
58#include <Geom_BSplineCurve.hxx>
59#include <gp_Vec.hxx>
60#include <GeomConvert.hxx>
61
62#include <BRepTools_WireExplorer.hxx>
63#include <BRepTools.hxx>
64
65
66
67//=======================================================================
68//function : DetectKPart
69//purpose :
70//=======================================================================
71
72Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
73 const TopoDS_Edge& Edge2)
74{
0d969553 75 // initializations
7fd59977 76 Standard_Integer IType = 0;
77
0d969553 78 // characteristics of the first edge
1d47d8d0 79 Standard_Real first1 = 0., last1 = 0., first2, last2, ff, ll;
7fd59977 80 TopLoc_Location loc;
81 TopoDS_Vertex V1, V2;
82 Handle(Geom_Curve) curv1, curv;
83 GeomAdaptor_Curve AdC1;
84 Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1);
85
0d969553 86 // find the particular case
7fd59977 87 gp_Pnt pos1, pos;
88 Standard_Real dist;
7fd59977 89 Standard_Real dist1 =0.;
7fd59977 90 gp_Ax1 axe1, axe;
91
92 if (degen1) {
93 IType = -2;
94 TopExp::Vertices(Edge1,V1,V2);
95 pos1 = BRep_Tool::Pnt(V1);
96 }
97 else {
98 curv1 = BRep_Tool::Curve(Edge1, loc, first1, last1);
99 curv1 =
100 Handle(Geom_Curve)::DownCast(curv1->Transformed(loc.Transformation()));
101 ff = first1;
102 ll = last1;
103 if (Edge1.Orientation() == TopAbs_REVERSED) {
104 curv1->Reverse();
105 first1 = curv1->ReversedParameter(ll);
106 last1 = curv1->ReversedParameter(ff);
107 }
108 AdC1.Load(curv1);
109 if (AdC1.GetType() == GeomAbs_Circle) {
0d969553 110 // first circular section
7fd59977 111 IType = 1;
112 pos1 = AdC1.Circle().Location();
113 dist1 = AdC1.Circle().Radius();
114 axe1 = AdC1.Circle().Axis();
115 }
116 else if (AdC1.GetType() == GeomAbs_Line) {
0d969553 117 // first straight line section
7fd59977 118 IType = 4;
119 pos1 = AdC1.Line().Location();
120 dist1 = AdC1.Value(first1).Distance(AdC1.Value(last1));
121 gp_Vec vec(AdC1.Value(first1),AdC1.Value(last1));
122 gp_Dir dir(vec);
123 axe1 = gp_Ax1(AdC1.Value(first1),dir);
124 }
125 else {
0d969553 126 // first section of any type
7fd59977 127 IType = 0;
128 }
129 }
130
131 if (IType!=0) {
132
133 Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2);
134 if (degen2) {
135 TopExp::Vertices(Edge2,V1,V2);
136 pos = BRep_Tool::Pnt(V1);
137 if (IType==1) {
0d969553 138 // the only particular case with degenerated edge at end : the cone
7fd59977 139 if (pos.IsEqual(pos1,Precision::Confusion())) {
0d969553 140 // the top is mixed with the center of the circle
7fd59977 141 IType = 0;
142 }
143 else {
144 gp_Vec vec(pos1,pos);
145 gp_Dir dir(vec);
146 axe = gp_Ax1(pos1,dir);
147 if (axe.IsParallel(axe1,Precision::Angular())) {
0d969553 148 // the top is on the axis of the circle
7fd59977 149 IType = 2;
150 }
151 else {
0d969553 152 // incorrect top --> no particular case
7fd59977 153 IType = 0;
154 }
155 }
156 }
0d969553
Y
157 else if (IType != 4) { //not a plane
158 // no particular case
7fd59977 159 IType = 0;
160 }
161 }
162 else {
163 curv = BRep_Tool::Curve(Edge2, loc, first2, last2);
164 curv =
165 Handle(Geom_Curve)::DownCast(curv->Transformed(loc.Transformation()));
166 ff = first2;
167 ll = last2;
168 if (Edge2.Orientation() == TopAbs_REVERSED) {
169 curv->Reverse();
170 first2 = curv->ReversedParameter(ll);
171 last2 = curv->ReversedParameter(ff);
172 }
173 GeomAdaptor_Curve AdC(curv);
174
175 if (IType>0 && IType<4) {
176 if (AdC.GetType() != GeomAbs_Circle) {
0d969553 177 // section not circular --> no particular case
7fd59977 178 IType = 0;
179 }
180 else {
181 if (AdC.Circle().Axis()
182 .IsCoaxial(axe1,Precision::Angular(),Precision::Confusion())) {
0d969553 183 // same axis
7fd59977 184 if (Abs(AdC.Circle().Radius()-dist1)< Precision::Confusion()) {
0d969553 185 // possibility of cylinder or a piece of cylinder
7fd59977 186 Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2);
187 Standard_Boolean Same,
188 SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() );
189 Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.;
190 gp_Pnt P1,P2;
191 gp_Vec DU;
192 AdC1.D1(m1,P1,DU);
193 AdC.D0(m2,P2);
194 Same = SameParametricLength
195 && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ;
196 if (Same) {
0d969553 197 // cylinder or piece of cylinder
7fd59977 198 IType = 1;
199 }
200 else {
0d969553 201 // the interval of definition is not correct
7fd59977 202 IType = 0;
203 }
204 }
205 else {
0d969553 206 // possibility of cone truncation
7fd59977 207 Standard_Real h1 = Abs(last1-first1), h2 = Abs(last2-first2);
208 Standard_Boolean Same,
209 SameParametricLength = ( Abs(h1-h2) < Precision::PConfusion() );
210 Standard_Real m1=(first1+last1)/2., m2=(first2+last2)/2.;
211 gp_Pnt P1,P2;
212 gp_Vec DU;
213 AdC1.D1(m1,P1,DU);
214 AdC.D0(m2,P2);
215 Same = SameParametricLength
216 && ( gp_Vec(P1,P2).IsNormal(DU,Precision::Angular()) ) ;
217 if (Same) {
0d969553 218 // truncation of cone
7fd59977 219 IType = 2;
220 }
221 else {
0d969553 222 // the interval of definition is not correct
7fd59977 223 IType = 0;
224 }
225 }
226 if (AdC.Circle().Location().IsEqual(pos1,Precision::Confusion())) {
0d969553 227 // the centers are mixed
7fd59977 228 IType = 0;
229 }
230 }
231 else {
0d969553 232 // different axis
7fd59977 233 if (AdC.Circle().Radius()==dist1) {
0d969553 234 // torus ?
7fd59977 235 IType = 3;
236 }
237 else {
0d969553 238 // different radius --> no particular case
7fd59977 239 IType = 0;
240 }
241 }
242 }
243 }
244 else if (IType>=4) {
245 if (AdC.GetType() != GeomAbs_Line) {
0d969553 246 // not a straight line section --> no particular case
7fd59977 247 IType = 0;
248 }
249 else {
250 pos = AdC.Line().Location();
251 dist = AdC.Value(first2).Distance(AdC.Value(last2));
252 gp_Vec vec(AdC.Value(first2),AdC.Value(last2));
253 gp_Dir dir(vec);
254 axe = gp_Ax1(AdC.Value(first2),dir);
255 if (axe.IsParallel(axe1,Precision::Angular())) {
0d969553 256 // parallel straight line
7fd59977 257 if (Abs(dist-dist1)<Precision::Confusion()) {
258 gp_Dir dir(gp_Vec(AdC1.Value(first1),AdC.Value(first2)));
259 if (dir.IsNormal(gp_Dir(vec),Precision::Angular())) {
0d969553 260 // plane
7fd59977 261 IType = 4;
262 }
263 else {
264 // extrusion ?
265 IType = 5;
266 }
267 }
268 else {
0d969553 269 // different length --> no particular case
7fd59977 270 IType = 0;
271 }
272 }
273 else {
0d969553 274 // not parallel straight line --> no particular case
7fd59977 275 IType = 0;
276 }
277 }
278 }
279 else if (IType==-2) {
280 if (AdC.GetType() == GeomAbs_Line)
281 IType = 4; //plane
282 else if (AdC.GetType() == GeomAbs_Circle)
283 {
0d969553 284 // the only particular case with degenerated edge at the beginning the cone
7fd59977 285 pos = AdC.Circle().Location();
286 axe = AdC.Circle().Axis();
287 if (pos1.IsEqual(pos,Precision::Confusion())) {
0d969553 288 // the top is mixed with the center of the circle
7fd59977 289 IType = 0;
290 }
291 else {
292 gp_Vec vec(pos1,pos);
293 gp_Dir dir(vec);
294 axe1 = gp_Ax1(pos1,dir);
295 if (axe.IsParallel(axe1,Precision::Angular())) {
0d969553 296 // the top is on the axis of the circle
7fd59977 297 IType = -2;
298 }
299 else {
0d969553 300 // incorrect top --> no particular case
7fd59977 301 IType = 0;
302 }
303 }
304 }
305 else
306 IType = 0;
307 }
308 }
309
310 }
0d969553 311 // torus and extrusion are not particular cases.
7fd59977 312 if (IType == 3 || IType == 5) IType = 0;
313 return IType;
314}
315
316
317//=======================================================================
318//function : CreateKPart
319//purpose :
320//=======================================================================
321
322void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
323 const Standard_Integer IType,
324 Handle(Geom_Surface)& Surf)
325{
326 // find the dimension
327 TopoDS_Vertex V1, V2;
328
329 TopLoc_Location loc;
330 Standard_Real a1, b1, aa =0., bb =0.;
331 TopoDS_Vertex v1f,v1l,v2f,v2l;
332
333 // find characteristics of the first edge
334 Handle(Geom_Curve) C1;
335 Standard_Boolean degen1 = BRep_Tool::Degenerated(Edge1);
336 if(degen1) {
0d969553 337 // cone with degenerated edge at the top
7fd59977 338 TopExp::Vertices(Edge1,v1f,v1l);
339 }
340 else {
341 C1 = BRep_Tool::Curve(Edge1, loc, a1, b1);
342 C1 = Handle(Geom_Curve)::DownCast(C1->Transformed(loc.Transformation()));
343 aa = a1;
344 bb = b1;
345 if (Edge1.Orientation() == TopAbs_REVERSED) {
346 C1->Reverse();
347 aa = C1->ReversedParameter(b1);
348 bb = C1->ReversedParameter(a1);
349 TopExp::Vertices(Edge1,v1l,v1f);
350 }
351 else {
352 TopExp::Vertices(Edge1,v1f,v1l);
353 }
354 }
355
356 // find characteristics of the second edge
357 Handle(Geom_Curve) C2;
358 Standard_Boolean degen2 = BRep_Tool::Degenerated(Edge2);
359 if(degen2) {
0d969553 360 // cone with degenerated edge at the top
7fd59977 361 TopExp::Vertices(Edge2,v2f,v2l);
362 }
363 else {
364 C2 = BRep_Tool::Curve(Edge2, loc, a1, b1);
365 C2 = Handle(Geom_Curve)::DownCast(C2->Transformed(loc.Transformation()));
366 if (Edge2.Orientation() == TopAbs_REVERSED) {
367 C2->Reverse();
368 if (degen1) {
369 aa = a1;
370 bb = b1;
371 }
372 TopExp::Vertices(Edge2,v2l,v2f);
373 }
374 else {
375 if (degen1) {
376 aa = a1; //C2->ReversedParameter(b1);
377 bb = b1; //C2->ReversedParameter(a1);
378 }
379 TopExp::Vertices(Edge2,v2f,v2l);
380 }
381 }
382
383 // create the new surface
384 TopoDS_Shell shell;
385 TopoDS_Face face;
386 TopoDS_Wire W;
387 TopoDS_Edge edge1, edge2, edge3, edge4, couture;
388
389 BRep_Builder B;
390 B.MakeShell(shell);
391
392 TopoDS_Wire newW1, newW2;
393 BRep_Builder BW1, BW2;
394 BW1.MakeWire(newW1);
395 BW2.MakeWire(newW2);
396
397
398 // calculate the surface
399 Handle(Geom_Surface) surface;
400 Standard_Real V, Rad;
401 if (IType==1) {
0d969553 402 // cylindrical surface
7fd59977 403 gp_Circ c1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
404 gp_Circ c2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
405 gp_Ax3 Ac1 = c1.Position();
406 V = gp_Vec( c1.Location(),c2.Location()).Dot(gp_Vec(Ac1.Direction()));
407 if ( V < 0.) {
408 Ac1.ZReverse();
409 V = -V;
410 }
411 Handle(Geom_CylindricalSurface) Cyl =
412 new Geom_CylindricalSurface( Ac1, c1.Radius());
413 surface = new Geom_RectangularTrimmedSurface
414 ( Cyl, aa, bb, Min(0.,V), Max(0.,V) );
415 }
416 else if (IType==2) {
0d969553 417 // conical surface
7fd59977 418 gp_Circ k1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
419 gp_Ax3 Ak1 = k1.Position();
420 if (degen2) {
421 V = gp_Vec( k1.Location(),BRep_Tool::Pnt(v2f))
422 .Dot(gp_Vec(Ak1.Direction()));
423 Rad = - k1.Radius();
424 }
425 else {
426 gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
427 V = gp_Vec( k1.Location(),k2.Location()).Dot(gp_Vec(Ak1.Direction()));
428 Rad = k2.Radius() - k1.Radius();
429 }
430
431 if ( V < 0.) {
432 Ak1.ZReverse();
433 V = -V;
434 }
435 Standard_Real Ang = ATan( Rad / V);
436 Handle(Geom_ConicalSurface) Cone =
437 new Geom_ConicalSurface( Ak1, Ang, k1.Radius());
438 V /= Cos(Ang);
439 surface = new Geom_RectangularTrimmedSurface
440 ( Cone, aa, bb, Min(0.,V), Max(0.,V) );
441 }
442 else if (IType==-2) {
0d969553 443 // conical surface with the top at the beginning (degen1 is true)
7fd59977 444 gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
445 gp_Ax3 Ak2 = k2.Position();
446 Ak2.SetLocation(BRep_Tool::Pnt(v1f));
447 V = gp_Vec(BRep_Tool::Pnt(v1f),k2.Location())
448 .Dot(gp_Vec(Ak2.Direction()));
449 Rad = k2.Radius(); // - k2.Radius();
450 if ( V < 0.) {
451 Ak2.ZReverse();
452 V = -V;
453 }
454 Standard_Real Ang = ATan( Rad / V);
455 Handle(Geom_ConicalSurface) Cone =
456 new Geom_ConicalSurface( Ak2, Ang, 0.);
457 V /= Cos(Ang);
458 surface = new Geom_RectangularTrimmedSurface
459 ( Cone, aa, bb, Min(0.,V), Max(0.,V) );
460 }
461 else if (IType==3) {
0d969553 462 // torus surface ?
7fd59977 463 }
464 else if (IType==4) {
465 // surface plane
466 gp_Lin L1, L2, aLine;
467 if (!degen1)
468 {
469 L1 = (Handle(Geom_Line)::DownCast(C1))->Lin();
470 aLine = L1;
471 }
472 if (!degen2)
473 {
474 L2 = (Handle(Geom_Line)::DownCast(C2))->Lin();
475 aLine = L2;
476 }
477
478 gp_Pnt P1 = (degen1)? BRep_Tool::Pnt(v1f) : L1.Location();
479 gp_Pnt P2 = (degen2)? BRep_Tool::Pnt(v2f) : L2.Location();
480
481 gp_Vec P1P2( P1, P2 );
482 gp_Dir D1 = aLine.Direction();
483 gp_Ax3 Ax( aLine.Location(), gp_Dir(D1.Crossed(P1P2)), D1 );
484 Handle(Geom_Plane) Plan = new Geom_Plane(Ax);
485 V = P1P2.Dot( Ax.YDirection());
486 surface = Plan;
487 //surface = new Geom_RectangularTrimmedSurface
488 //( Plan, aa, bb, Min(0.,V), Max(0.,V) );
489 }
490 else if (IType==5) {
0d969553 491 // surface of extrusion ?
7fd59977 492 }
493 else {
494 // IType incorrect
495 }
496 Surf = surface;
497}
498
499
500//=======================================================================
501//function : BRepFill_Generator
502//purpose :
503//=======================================================================
504
505BRepFill_Generator::BRepFill_Generator()
506{
507}
508
509
510//=======================================================================
511//function : AddWire
512//purpose :
513//=======================================================================
514
515void BRepFill_Generator::AddWire(const TopoDS_Wire& Wire)
516{
517 myWires.Append( Wire);
518}
519
520
521//=======================================================================
522//function : Perform
523//purpose :
524//=======================================================================
525
526void BRepFill_Generator::Perform()
527{
528 TopoDS_Shell Shell;
529 TopoDS_Face Face;
530 TopoDS_Shape S1, S2;
531 TopoDS_Edge Edge1, Edge2, Edge3, Edge4, Couture;
532
533 BRep_Builder B;
534 B.MakeShell(myShell);
535
536 Standard_Integer Nb = myWires.Length();
537
538 BRepTools_WireExplorer ex1,ex2;
539
1d47d8d0 540 Standard_Boolean wPoint1, wPoint2, uClosed = Standard_False, DegenFirst = Standard_False, DegenLast = Standard_False;
7fd59977 541
542 for ( Standard_Integer i = 1; i <= Nb-1; i++) {
543
544 TopoDS_Wire Wire1 = TopoDS::Wire(myWires( i ));
545 TopoDS_Wire Wire2 = TopoDS::Wire(myWires(i+1));
546
547 wPoint1 = Standard_False;
548 if (i==1) {
549 wPoint1 = Standard_True;
550 for(ex1.Init(Wire1); ex1.More(); ex1.Next()) {
551 wPoint1 = wPoint1 && (BRep_Tool::Degenerated(ex1.Current()));
552 }
553 DegenFirst = wPoint1;
554
555 TopoDS_Vertex V1, V2;
556 TopExp::Vertices(Wire1, V1, V2);
557 uClosed = V1.IsSame(V2);
558 }
559
560 wPoint2 = Standard_False;
561 if (i==Nb-1) {
562 wPoint2 = Standard_True;
563 for(ex2.Init(Wire2); ex2.More(); ex2.Next()) {
564 wPoint2 = wPoint2 && (BRep_Tool::Degenerated(ex2.Current()));
565 }
566 DegenLast = wPoint2;
567 }
568
569 ex1.Init(Wire1);
570 ex2.Init(Wire2);
571
572 TopTools_DataMapOfShapeShape Map;
573
574 Standard_Boolean tantque = ex1.More() && ex2.More();
575
576 while ( tantque ) {
577
578 TopoDS_Vertex V1f,V1l,V2f,V2l, Vf_toMap, Vl_toMap;
579
580 Standard_Boolean degen1
581 = BRep_Tool::Degenerated(TopoDS::Edge(ex1.Current()));
582 Standard_Boolean degen2
583 = BRep_Tool::Degenerated(TopoDS::Edge(ex2.Current()));
584
585 if ( degen1 ) {
586 TopoDS_Shape aLocalShape = ex1.Current().EmptyCopied();
587 Edge1 = TopoDS::Edge(aLocalShape);
588// Edge1 = TopoDS::Edge(ex1.Current().EmptyCopied());
589// aLocalShape = ex1.Current();
590// TopExp::Vertices(TopoDS::Edge(aLocalShape),V1f,V1l);
591 TopExp::Vertices(TopoDS::Edge(ex1.Current()),V1f,V1l);
592 V1f.Orientation(TopAbs_FORWARD);
593 B.Add(Edge1,V1f);
594 V1l.Orientation(TopAbs_REVERSED);
595 B.Add(Edge1,V1l);
596 B.Range(Edge1,0,1);
597 }
598 else {
599 TopoDS_Shape aLocalShape = ex1.Current();
600 Edge1 = TopoDS::Edge(aLocalShape);
601// Edge1 = TopoDS::Edge(ex1.Current());
602 }
603
604 if ( degen2 ) {
605 TopoDS_Shape aLocalShape = ex2.Current().EmptyCopied();
606 Edge2 = TopoDS::Edge(aLocalShape);
607// Edge2 = TopoDS::Edge(ex2.Current().EmptyCopied());
608 TopExp::Vertices(TopoDS::Edge(ex2.Current()),V2f,V2l);
609 V2f.Orientation(TopAbs_FORWARD);
610 B.Add(Edge2,V2f);
611 V2l.Orientation(TopAbs_REVERSED);
612 B.Add(Edge2,V2l);
613 B.Range(Edge2,0,1);
614 }
615 else {
616 Edge2 = TopoDS::Edge(ex2.Current());
617 }
618
619 Standard_Boolean Periodic
620 = (Edge1.Closed() || degen1) && (Edge2.Closed() || degen2);
0d969553
Y
621 // ATTENTION : a non-punctual wire should not
622 // contain a punctual edge
7fd59977 623 if (!wPoint1) ex1.Next();
624 if (!wPoint2) ex2.Next();
625
0d969553 626 // initialization of vertices
7fd59977 627 Handle(Geom_Surface) Surf;
628 Standard_Real f1=0, l1=1, f2=0, l2=1;
629 if (Edge1.Orientation() == TopAbs_REVERSED)
630 TopExp::Vertices(Edge1,V1l,V1f);
631 else
632 TopExp::Vertices(Edge1,V1f,V1l);
633 if (Edge2.Orientation() == TopAbs_REVERSED)
634 TopExp::Vertices(Edge2,V2l,V2f);
635 else
636 TopExp::Vertices(Edge2,V2f,V2l);
637 if (degen1)
638 {
639 Vf_toMap = V2f;
640 Vl_toMap = V2l;
641 }
642 else
643 {
644 Vf_toMap = V1f;
645 Vl_toMap = V1l;
646 }
647
648 if(Periodic) {
649 Standard_Boolean E1IsReallyClosed = BRepTools::Compare(V1f,V1l);
650 Standard_Boolean E2IsReallyClosed = BRepTools::Compare(V2f,V2l);
651 Periodic
652 = (E1IsReallyClosed || degen1) && (E2IsReallyClosed || degen2);
653 }
0d969553 654 // processing of KPart
7fd59977 655 Standard_Integer IType = DetectKPart(Edge1,Edge2);
656 if (IType==0) {
0d969553 657 // no part cases
7fd59977 658 TopLoc_Location L,L1,L2;
659
660 Handle(Geom_Curve) C1, C2;
661 TColgp_Array1OfPnt Extremities(1,2);
662
663 if (degen1) {
664 Extremities(1) = BRep_Tool::Pnt(V1f);
665 Extremities(2) = BRep_Tool::Pnt(V1l);
666 C1 = new Geom_BezierCurve(Extremities);
667 }
668 else {
669 C1 = BRep_Tool::Curve(Edge1,L1,f1,l1);
670 }
671 if (degen2) {
672 Extremities(1) = BRep_Tool::Pnt(V2l);
673 Extremities(2) = BRep_Tool::Pnt(V2f);
674 C2 = new Geom_BezierCurve(Extremities);
675 }
676 else {
677 C2 = BRep_Tool::Curve(Edge2,L2,f2,l2);
678 }
679
680 // compute the location
681 Standard_Boolean SameLoc = Standard_False;
682
683 // transform and trim the curves
684
685 if (Abs(f1 - C1->FirstParameter()) > Precision::PConfusion() ||
686 Abs(l1 - C1->LastParameter()) > Precision::PConfusion() ) {
687 C1 = new Geom_TrimmedCurve(C1,f1,l1);
688 }
689 else {
690 C1 = Handle(Geom_Curve)::DownCast(C1->Copy());
691 }
692 if (!SameLoc) C1->Transform(L1.Transformation());
693 if (Edge1.Orientation() == TopAbs_REVERSED) {
694 C1->Reverse();
695 }
696
697 if (Abs(f2 - C2->FirstParameter()) > Precision::PConfusion() ||
698 Abs(l2 - C2->LastParameter()) > Precision::PConfusion() ) {
699 C2 = new Geom_TrimmedCurve(C2,f2,l2);
700 }
701 else {
702 C2 = Handle(Geom_Curve)::DownCast(C2->Copy());
703 }
704 if (!SameLoc) C2->Transform(L2.Transformation());
705 if (Edge2.Orientation() == TopAbs_REVERSED) {
706 C2->Reverse();
707 }
708
709 GeomFill_Generator Generator;
710 Generator.AddCurve( C1);
711 Generator.AddCurve( C2);
712 Generator.Perform( Precision::PConfusion());
713
714 Surf = Generator.Surface();
715 B.MakeFace(Face,Surf,Precision::Confusion());
716 }
717 else {
0d969553 718 // particular case
7fd59977 719 CreateKPart(Edge1,Edge2,IType,Surf);
720 B.MakeFace(Face,Surf,Precision::Confusion());
721 }
722
723 // make the missing edges
724 Standard_Real first,last;
725 Surf->Bounds(f1,l1,f2,l2);
726
727 if ( Map.IsBound(Vf_toMap)) {
728 TopoDS_Shape aLocalShape = Map(Vf_toMap).Reversed();
729 Edge3 = TopoDS::Edge(aLocalShape);
730// Edge3 = TopoDS::Edge(Map(V1f).Reversed());
731 }
732 else {
733 Handle(Geom_Curve) CC;
734 TColgp_Array1OfPnt Extremities(1,2);
735 if (IType==0) {
0d969553 736 // general case : Edge3 corresponds to iso U=f1
7fd59977 737 CC = Surf->UIso(f1);
738 first=f2;
739 last=l2;
740 }
741 else {
0d969553 742 // particular case : it is required to calculate the curve 3d
7fd59977 743 Extremities(1) = BRep_Tool::Pnt(V1f);
744 Extremities(2) = BRep_Tool::Pnt(V2f);
745 CC = new Geom_BezierCurve(Extremities);
746 first=0.;
747 last=1.;
748 }
749 B.MakeEdge(Edge3,CC,Precision::Confusion());
750 V1f.Orientation(TopAbs_FORWARD);
751 B.Add(Edge3,V1f);
752 V2f.Orientation(TopAbs_REVERSED);
753 B.Add(Edge3,V2f);
754 B.Range(Edge3,first,last);
755 Edge3.Reverse();
756 Map.Bind(Vf_toMap, Edge3);
757 }
758
759 Standard_Boolean CommonEdge = Standard_False;
760 if ( Map.IsBound(Vl_toMap) ) {
761 TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed();
762 const TopoDS_Edge CommonE = TopoDS::Edge(aLocalShape);
763// const TopoDS_Edge CommonE = TopoDS::Edge(Map(V1l).Reversed());
764 TopoDS_Vertex V1, V2;
765 TopExp::Vertices(CommonE,V1,V2);
766 CommonEdge = V1.IsSame(V1l) && V2.IsSame(V2l);
767 }
768 if ( CommonEdge ) {
769 TopoDS_Shape aLocalShape = Map(Vl_toMap).Reversed();
770 Edge4 = TopoDS::Edge(aLocalShape);
771// Edge4 = TopoDS::Edge(Map(V1l).Reversed());
772 }
773 else {
774 Handle(Geom_Curve) CC;
775 TColgp_Array1OfPnt Extremities(1,2);
776 if (IType==0) {
0d969553 777 // general case : Edge4 corresponds to iso U=l1
7fd59977 778 CC = Surf->UIso(l1);
779 first=f2;
780 last=l2;
781 }
782 else {
0d969553 783 // particular case : it is required to calculate the curve 3d
7fd59977 784 Extremities(1) = BRep_Tool::Pnt(V1l);
785 Extremities(2) = BRep_Tool::Pnt(V2l);
786 CC = new Geom_BezierCurve(Extremities);
787 first=0.;
788 last=1.;
789 }
790 B.MakeEdge(Edge4,CC,Precision::Confusion());
791 V1l.Orientation(TopAbs_FORWARD);
792 B.Add(Edge4,V1l);
793 V2l.Orientation(TopAbs_REVERSED);
794 B.Add(Edge4,V2l);
795 B.Range(Edge4,first,last);
796 Map.Bind(Vl_toMap, Edge4);
797 }
798
799 // make the wire
800
801 TopoDS_Wire W;
802 B.MakeWire(W);
803
804 if (! (degen1 && IType == 4))
805 B.Add(W,Edge1);
806 B.Add(W,Edge4);
807 if (! (degen2 && IType == 4))
808 B.Add(W,Edge2.Reversed());
809 B.Add(W,Edge3);
810
811 B.Add(Face,W);
812
813 B.Add(myShell,Face);
814
815 // complete myMap for edge1
816 if (! (degen1 && IType == 4))
817 {
818 TopTools_ListOfShape Empty;
819 if (!myMap.IsBound(Edge1)) myMap.Bind(Edge1,Empty);
820 myMap(Edge1).Append(Face);
821 }
822
823 // set the pcurves
824
825 Standard_Real T = Precision::Confusion();
826
827 if (IType != 4) //not plane
828 {
829 if ( Edge1.Orientation() == TopAbs_REVERSED ) {
830 B.UpdateEdge(Edge1,
831 new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(-1,0)),
832 Face,T);
833 B.Range(Edge1,Face,-l1,-f1);
834 }
835 else {
836 B.UpdateEdge(Edge1,
837 new Geom2d_Line(gp_Pnt2d(0,f2),gp_Dir2d(1,0)),
838 Face,T);
839 B.Range(Edge1,Face,f1,l1);
840 }
841
842 if ( Edge2.Orientation() == TopAbs_REVERSED ) {
843 B.UpdateEdge(Edge2,
844 new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(-1,0)),
845 Face,T);
846 B.Range(Edge2,Face,-l1,-f1);
847 }
848 else {
849 B.UpdateEdge(Edge2,
850 new Geom2d_Line(gp_Pnt2d(0,l2),gp_Dir2d(1,0)),
851 Face,T);
852 B.Range(Edge2,Face,f1,l1);
853 }
854 }
855
856 if (IType==0) {
857 if ( Periodic) {
858 B.UpdateEdge(Edge3,
859 new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
860 new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),
861 Face,T);
862 }
863 else {
864 B.UpdateEdge(Edge3,
865 new Geom2d_Line(gp_Pnt2d(f1,0),gp_Dir2d(0,1)),
866 Face,T);
867 B.UpdateEdge(Edge4,
868 new Geom2d_Line(gp_Pnt2d(l1,0),gp_Dir2d(0,1)),
869 Face,T);
870 }
871 }
872 else {
873 // KPart
874 if ( Periodic) {
875 TColgp_Array1OfPnt2d Extrem1(1,2);
876 Extrem1(1).SetCoord(l1,f2);
877 Extrem1(2).SetCoord(l1,l2);
878 TColgp_Array1OfPnt2d Extrem2(1,2);
879 Extrem2(1).SetCoord(f1,f2);
880 Extrem2(2).SetCoord(f1,l2);
881 B.UpdateEdge(Edge3,
882 new Geom2d_BezierCurve(Extrem1),
883 new Geom2d_BezierCurve(Extrem2),
884 Face,T);
885 }
886 else if (IType != 4) { //not plane
887 TColgp_Array1OfPnt2d Extrem2(1,2);
888 Extrem2(1).SetCoord(f1,f2);
889 Extrem2(2).SetCoord(f1,l2);
890 B.UpdateEdge(Edge3,
891 new Geom2d_BezierCurve(Extrem2),
892 Face,T);
893 TColgp_Array1OfPnt2d Extrem1(1,2);
894 Extrem1(1).SetCoord(l1,f2);
895 Extrem1(2).SetCoord(l1,l2);
896 B.UpdateEdge(Edge4,
897 new Geom2d_BezierCurve(Extrem1),
898 Face,T);
899 }
900 }
901 // Set the non parameter flag;
902 B.SameParameter(Edge1,Standard_False);
903 B.SameParameter(Edge2,Standard_False);
904 B.SameParameter(Edge3,Standard_False);
905 B.SameParameter(Edge4,Standard_False);
906 B.SameRange(Edge1,Standard_False);
907 B.SameRange(Edge2,Standard_False);
908 B.SameRange(Edge3,Standard_False);
909 B.SameRange(Edge4,Standard_False);
910
911 tantque = ex1.More() && ex2.More();
912 if (wPoint1) tantque = ex2.More();
913 if (wPoint2) tantque = ex1.More();
914 }
915 }
916 BRepLib::SameParameter(myShell);
917
918 if (uClosed && DegenFirst && DegenLast)
919 myShell.Closed(Standard_True);
920}
921
922
923//=======================================================================
924//function : GeneratedShapes
925//purpose :
926//=======================================================================
927
928const TopTools_ListOfShape&
929 BRepFill_Generator::GeneratedShapes (const TopoDS_Shape& SSection) const
930{
931 if (myMap.IsBound(SSection)) {
932 return myMap(SSection);
933 }
934 else {
935 static TopTools_ListOfShape Empty;
936 return Empty;
937 }
938}
939
940//=======================================================================
941//function : Generated
942//purpose :
943//=================================================================== ====
944
945const TopTools_DataMapOfShapeListOfShape& BRepFill_Generator::Generated() const
946{
947 return myMap;
948}
949
950