0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / BRepFill / BRepFill_Draft.cxx
CommitLineData
7fd59977 1// File: BRepFill_Draft.cxx
2// Created: Mon Jun 8 15:13:03 1998
3// Author: Stephanie HUMEAU
4// <shu@sun17>
5
6
7#include <BRepFill_Draft.ixx>
8
9#include <BRepFill_DraftLaw.hxx>
10#include <BRepFill_ShapeLaw.hxx>
11#include <BRepFill_Sweep.hxx>
12
13#include <BndLib_Add3dCurve.hxx>
14#include <BndLib_AddSurface.hxx>
15#include <Bnd_Box.hxx>
16#include <gp_Dir.hxx>
17#include <gp_Pnt.hxx>
18#include <gp_Trsf.hxx>
19#include <gp_Ax3.hxx>
20#include <gp_Lin.hxx>
21#include <gp_Mat.hxx>
22#include <TColgp_Array1OfPnt.hxx>
23
24#include <GeomAdaptor_Surface.hxx>
25#include <BRepAdaptor_Surface.hxx>
26#include <Adaptor3d_HCurve.hxx>
27
28#include <GeomLProp_SLProps.hxx>
29#include <Geom_Surface.hxx>
30#include <Geom_Line.hxx>
31#include <Geom_TrimmedCurve.hxx>
32#include <Geom_Geometry.hxx>
33#include <Geom_Plane.hxx>
34#include <Geom_RectangularTrimmedSurface.hxx>
35
36#include <GeomAdaptor_HSurface.hxx>
37#include <Adaptor3d_Surface.hxx>
38#include <BRepAdaptor_Curve.hxx>
39
40#include <GeomFill_LocationDraft.hxx>
41
42#include <TopoDS.hxx>
43#include <TopoDS_Edge.hxx>
44#include <TopoDS_Wire.hxx>
45#include <TopoDS_Shell.hxx>
46#include <TopoDS_Solid.hxx>
47#include <TopoDS_Iterator.hxx>
48#include <TopExp_Explorer.hxx>
49#include <TopExp.hxx>
50#include <TopAbs.hxx>
51#include <BRepLib_MakeWire.hxx>
52#include <BRepLib_MakeEdge.hxx>
53#include <BRepLib_MakeFace.hxx>
54#include <BRepLib_FindSurface.hxx>
55#include <BRep_Builder.hxx>
56
57#include <BRep_Tool.hxx>
58#include <BRepTools.hxx>
59#include <BRepAlgo_DSAccess.hxx>
60#include <BRepBuilderAPI_Sewing.hxx>
61#include <BRepClass3d_SolidClassifier.hxx>
62
63#include <TopTools_ListIteratorOfListOfShape.hxx>
64#include <TopTools_ListOfShape.hxx>
65#include <BRepExtrema_DistShapeShape.hxx>
66
67#include <Precision.hxx>
68#include <TColStd_Array1OfReal.hxx>
69
70#include <Standard_NoSuchObject.hxx>
71#include <StdFail_NotDone.hxx>
72
73#ifdef DRAW
74#include <Geom_Circle.hxx>
75#include <gp.hxx>
76#include <DBRep.hxx>
77#include <DrawTrSurf.hxx>
78static Standard_Boolean Affich = 0;
79#endif
80
81//=======================================================================
82//function : Trsf
83//purpose :
84//======================================================================
85static void ComputeTrsf(const TopoDS_Wire& W,
86 const gp_Dir& D,
87 Bnd_Box& Box,
88 gp_Trsf& Tf)
89{
0d969553 90 // Calculate approximate barycenter
7fd59977 91 BRepTools_WireExplorer Exp(W);
92// Class BRep_Tool without fields and without Constructor :
93// BRep_Tool BT;
94 gp_XYZ Bary(0.,0.,0.);
95 Standard_Integer nb;
96
97 for (nb=0; Exp.More(); Exp.Next()) {
98// Bary += BT.Pnt(Exp.CurrentVertex()).XYZ();
99 Bary += BRep_Tool::Pnt(Exp.CurrentVertex()).XYZ();
100 nb++;
101 }
102 Bary /= nb;
103
0d969553 104 // Calculate the Transformation
7fd59977 105 gp_Ax3 N(Bary, D);
106 Tf.SetTransformation(N);
107 BRepAdaptor_Curve AC;
108// BndLib_Add3dCurve BC;
109
0d969553 110 // transformation to the wire
7fd59977 111 TopoDS_Wire TheW = W;
112 TopLoc_Location Loc(Tf);
113 TheW.Location(Loc);
114
115
0d969553 116 // Calculate the box
7fd59977 117 Box.SetVoid();
118 for (Exp.Init(TheW); Exp.More(); Exp.Next()) {
119 AC.Initialize(Exp.Current());
120// BC.Add(AC, 0.1, Box);
121 BndLib_Add3dCurve::Add(AC, 0.1, Box);
122 }
123}
124
125//=======================================================================
0d969553 126//function : Length
7fd59977 127//purpose :
128//======================================================================
129static Standard_Real Longueur(const Bnd_Box& WBox,
130 const Bnd_Box& SBox,
131 gp_Dir& D,
132 gp_Pnt& P)
133{
0d969553
Y
134 // face of the box most remoted from the face input in
135 // the direction of skin
7fd59977 136 Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,WZmin,WZmax,L;
137
0d969553 138 //"coord" of the box
7fd59977 139 WBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
140 WZmin = Zmin;
141 WZmax = Zmax;
142
143 SBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
144 P.SetCoord( (Xmin+Xmax)/2, (Ymin+Ymax)/2, Zmax);
145
146 if (Zmax < WZmin) {
0d969553 147 // Skin in the wrong direction. Invert...
7fd59977 148 D.Reverse();
149 L = WZmax - Zmin;
150 P.SetZ(Zmin);
151 }
152 else {
153 L = Zmax - WZmin;
154 }
155 return L;
156}
157
158//=======================================================================
159//function : GoodOrientation
0d969553 160//purpose : Check if the law is oriented to have an exterior skin
7fd59977 161//======================================================================
162static Standard_Boolean GoodOrientation(const Bnd_Box& B,
163 const Handle(BRepFill_LocationLaw)& Law,
164 const gp_Dir& D)
165{
166 Standard_Real f, l, r, t;
167 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
168
169 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
170 gp_Pnt P1(aXmin, aYmin, aZmin), P2(aXmax, aYmax, aZmax);
171 gp_Vec V(P1, P2);
172
173 Law->CurvilinearBounds(Law->NbLaw(), f, l);
174 r = V.Magnitude()/l;
175
176 Standard_Integer ii, Ind;
177//#ifndef DEB
178 Standard_Integer Nb = (Standard_Integer) (4+(10*r));
179//#else
180// Standard_Integer Nb = 4+(10*r);
181//#endif
182 r = l/Nb;
183
0d969553 184 Nb++; // Number of points
7fd59977 185
186 TColgp_Array1OfPnt Pnts(1, Nb);
187 Handle(Adaptor3d_HCurve) AC;
188 gp_XYZ Bary(0.,0.,0.);
189
190 for (ii=1; ii<=Nb; ii++) {
191 Law->Parameter((ii-1)*r, Ind, t);
192 AC = Law->Law(Ind)->GetCurve();
193 AC->D0(t, Pnts(ii));
194 Bary+= Pnts(ii).XYZ();
195 }
196
197 Bary /= Nb;
198 gp_Pnt Centre(Bary);
199 gp_Vec Normal(D.XYZ());
200 Standard_Real Angle = 0;
201 gp_Vec Ref(Centre, Pnts(1));
202
203 for (ii=2; ii<=Nb; ii++) {
204 gp_Vec R(Centre, Pnts(ii));
205 Angle += Ref.AngleWithRef(R, Normal);
206 Ref = R;
207 }
208
209 return (Angle >= 0);
210}
211
212//=======================================================================
213//function : Constructeur
214//purpose :
215//======================================================================
216 BRepFill_Draft::BRepFill_Draft(const TopoDS_Shape& S,
217 const gp_Dir& Dir,
218 const Standard_Real Angle)
219{
220 myLoc.Nullify();
221 mySec.Nullify();
222 myFaces.Nullify();
223 mySections.Nullify();
224
225 switch (S.ShapeType()) {
226 case TopAbs_WIRE :
227 {
228 myWire = TopoDS::Wire(S);
229 break;
230 }
231 case TopAbs_FACE :
232 {
233 TopoDS_Iterator Exp (S);
234 myWire = TopoDS::Wire(Exp.Value());
235 break;
236 }
237 case TopAbs_SHELL :
238 {
239 TopTools_ListOfShape List;
240 TopTools_IndexedDataMapOfShapeListOfShape edgemap;
241 TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,edgemap);
242 Standard_Integer iedge, nbf;
243 for (iedge = 1; iedge <= edgemap.Extent(); iedge++) {
244 const TopoDS_Edge& theEdge = TopoDS::Edge(edgemap.FindKey(iedge));
245 // skip degenerated edges
246 if (!BRep_Tool::Degenerated(theEdge)) {
247 nbf = edgemap(iedge).Extent();
248 if (nbf==1) List.Append(theEdge);
249 }
250 }
251
252 if( List.Extent()>0) {
253 BRepLib_MakeWire MW;
254 MW.Add(List);
255 BRepLib_WireError Err = MW.Error();
256 if (Err == BRepLib_WireDone) {
257 myWire = MW.Wire();
258 }
259 else {
260#if DEB
261 cout << "Error in MakeWire" << endl;
262#endif
263 Standard_ConstructionError::Raise("BRepFill_Draft");
264 }
265 }
266 else {
267#if DEB
0d969553 268 cout << "No Free Borders !" << endl;
7fd59977 269#endif
270 Standard_ConstructionError::Raise("BRepFill_Draft");
271 }
272 break;
273 }
274 default :
275 Standard_ConstructionError::Raise("BRepFill_Draft");
276 }
277
0d969553 278 // Attention to closed non declared wires !
7fd59977 279 if (!myWire.Closed()) {
280 TopoDS_Vertex Vf, Vl;
281 TopExp::Vertices(myWire, Vf, Vl);
282 if (Vf.IsSame(Vl)) myWire.Closed(Standard_True);
283 }
284#if DRAW
285 if (Affich) {
286 DBRep::Set("TheWire", myWire);
287 }
288#endif
289
290 myAngle = Abs(Angle);
291 myDir = Dir;
292 myTop = S;
293 myDone = Standard_False;
294 myTol = 1.e-4;
295 myCont = GeomAbs_C1;
296 SetOptions();
297 SetDraft();
298}
299
300//=======================================================================
301//function :SetOptions
0d969553 302//purpose : Defines the style
7fd59977 303//======================================================================
304 void BRepFill_Draft::SetOptions(const BRepFill_TransitionStyle Style,
305 const Standard_Real Min,
306 const Standard_Real Max)
307{
308 myStyle = Style;
309 angmin = Min;
310 angmax = Max;
311}
312
313//=======================================================================
314//function :SetDraft
315//purpose :
316//======================================================================
317 void BRepFill_Draft::SetDraft(const Standard_Boolean Internal)
318{
319 IsInternal = Internal;
320}
321
322
323//=======================================================================
324//function :Perform
0d969553 325//purpose : calculate a surface of skinning
7fd59977 326//======================================================================
327 void BRepFill_Draft::Perform(const Standard_Real LengthMax)
328{
329 Handle(Geom_Surface) S;
330 S.Nullify();
331 Bnd_Box WBox;//, SBox;
332 gp_Trsf Trsf;
333
334
335 ComputeTrsf(myWire, myDir, WBox, Trsf);
336 Init(S, LengthMax, WBox);
337 BuildShell(S);
338 Sewing();
339}
340
341//=======================================================================
342//function :Perform
0d969553 343//purpose : calculate a surface of skinning
7fd59977 344//======================================================================
345 void BRepFill_Draft::Perform(const Handle(Geom_Surface)& Surface,
346 const Standard_Boolean KeepInsideSurface)
347{
348 Bnd_Box WBox, SBox;
349 gp_Trsf Trsf;
350 gp_Pnt Pt;
351 Standard_Real L;
352
353 ComputeTrsf(myWire, myDir, WBox, Trsf);
354
0d969553 355 // box with bounds of the stop surface
7fd59977 356 Handle(Geom_Surface) Surf;
357 Surf = Handle(Geom_Surface)::DownCast(Surface->Transformed(Trsf));
358 GeomAdaptor_Surface S1 (Surf);
359// BndLib_AddSurface AS;
360// AS.Add(S1, 0.1, SBox);
361 BndLib_AddSurface::Add(S1, 0.1, SBox);
362
0d969553 363 // calculate the maximum length of the rule.
7fd59977 364 L = Longueur(WBox, SBox, myDir, Pt);
365 L /= Abs(Cos(myAngle));
366
0d969553 367 // Construction
7fd59977 368 Init(Surface, L, WBox);
369 BuildShell(Surface, !KeepInsideSurface);
370 Sewing();
371}
372
0d969553 373//================================================================
7fd59977 374//function :Perform
0d969553
Y
375//purpose : calculate the surface of skinning, stopped by a shape
376//================================================================
7fd59977 377 void BRepFill_Draft::Perform(const TopoDS_Shape& StopShape,
378 const Standard_Boolean KeepOutSide)
379{
380 Bnd_Box WBox, SBox;
381 gp_Trsf Trsf;
382 gp_Pnt Pt;
383 Standard_Real L;
384
385 ComputeTrsf(myWire, myDir, WBox, Trsf);
386
0d969553 387// bounding box of the stop shape
7fd59977 388 Bnd_Box BSurf;//, TheBox;
389 Standard_Real Umin, Umax, Vmin, Vmax;
7fd59977 390// BRepTools B;
391// BRep_Tool BT;
392 Handle(Geom_Surface) Surf;
393
394// BndLib_AddSurface AS;
395
396 TopExp_Explorer Ex (StopShape, TopAbs_FACE);
397
398 SBox.SetVoid();
0d969553 399 while (Ex.More()) { // parse faces of the stop shape
7fd59977 400// B.UVBounds(TopoDS::Face(Ex.Current()), Umin,Umax,Vmin,Vmax);
401 BRepTools::UVBounds(TopoDS::Face(Ex.Current()), Umin,Umax,Vmin,Vmax);
402 Surf = Handle(Geom_Surface)::DownCast(
403// BT.Surface(TopoDS::Face(Ex.Current()))->Transformed(Trsf) );
404 BRep_Tool::Surface(TopoDS::Face(Ex.Current()))->Transformed(Trsf) );
405 GeomAdaptor_Surface S1 (Surf);
0d969553 406// bounding box of the current face
7fd59977 407// AS.Add(S1, Umin, Umax, Vmin, Vmax, 0.1, BSurf);
408 BndLib_AddSurface::Add(S1, Umin, Umax, Vmin, Vmax, 0.1, BSurf);
0d969553 409 SBox.Add(BSurf); // group boxes
7fd59977 410 Ex.Next();
411 }// while_Ex
412
0d969553 413 // calculate the maximum length of the rule.
7fd59977 414 L = Longueur(WBox, SBox, myDir, Pt);
415 L /= Abs(Cos(myAngle));
416
0d969553 417// surface of stop
7fd59977 418 gp_Trsf Inv;
0d969553
Y
419 Inv = Trsf.Inverted(); // inverted transformation
420 Pt.Transform(Inv); // coordinate in the absolute reference
7fd59977 421 Handle(Geom_Plane) Plan = new (Geom_Plane)(Pt, myDir);
422 Surf = new (Geom_RectangularTrimmedSurface) (Plan,-L, L, -L, L);
423
424#if DRAW
425 if (Affich) {
426 char* Temp = "ThePlan" ;
427 DrawTrSurf::Set(Temp, Surf);
428// DrawTrSurf::Set("ThePlan", Surf);
429 }
430#endif
431
0d969553 432// Sweeping and restriction
7fd59977 433 Init(Plan, L*1.01, WBox);
434 BuildShell(Surf, Standard_False);
435 Fuse(StopShape, KeepOutSide);
436 Sewing();
437}
438
439//=======================================================================
440//function : Init
0d969553 441//purpose : Construction of laws.
7fd59977 442//======================================================================
443 void BRepFill_Draft::Init(const Handle(Geom_Surface)& ,
444 const Standard_Real Length,
445 const Bnd_Box& Box)
446{
447 Standard_Boolean B;
448
0d969553 449// law of positioning
7fd59977 450 Handle(GeomFill_LocationDraft) Loc
451 = new (GeomFill_LocationDraft) (myDir, myAngle);
452 myLoc = new (BRepFill_DraftLaw) (myWire, Loc);
453
454 B = GoodOrientation(Box, myLoc, myDir);
455
456 if (IsInternal ^ (!B) ) {
457 myAngle = - myAngle;
458 Loc->SetAngle(myAngle);
459 myLoc = new (BRepFill_DraftLaw) (myWire, Loc);
460 }
461
0d969553 462 myLoc->CleanLaw(angmin); // Clean small discontinuities.
7fd59977 463
0d969553
Y
464// law of section
465// generating line is straight and parallel to binormal.
7fd59977 466 gp_Pnt P(0, 0, 0);
467 gp_Vec D (0., 1., 0.);
468
0d969553 469// Control of the orientation
7fd59977 470 Standard_Real f,l;
471 myLoc->Law(1)->GetDomain(f,l);
472 gp_Mat M;
473
474 gp_Vec Bid;
475 myLoc->Law(1)->D0( (f+l)/2, M, Bid);
476 gp_Dir BN(M.Column(2));
477
478 Standard_Real ang = myDir.Angle(BN);
c6541a0c 479 if (ang > M_PI/2) D.Reverse();
7fd59977 480 Handle(Geom_Line) L = new (Geom_Line) (P, D);
481
482 Handle(Geom_Curve) TC = new (Geom_TrimmedCurve) (L, 0, Length);
483
484
485#if DRAW
486 if (Affich > 2) {
487 TC = new (Geom_Circle) (gp::XOY(), Length);
488 }
489#endif
490
491 BRepLib_MakeEdge ME(TC);
492 TopoDS_Edge EG = ME.Edge();
493
494 BRepLib_MakeWire MW(EG);
495 TopoDS_Wire G = MW.Wire();
496
497 mySec = new (BRepFill_ShapeLaw) (G, Standard_True);
498}
499
500
501//=======================================================================
502//function : BuildShell
0d969553 503//purpose : Construction of the skinning surface
7fd59977 504//======================================================================
505 void BRepFill_Draft::BuildShell(const Handle(Geom_Surface)& Surf,
506 const Standard_Boolean KeepOutSide)
507{
0d969553 508// construction of the surface
7fd59977 509 BRepFill_Sweep Sweep(mySec, myLoc, Standard_True);
510 Sweep.SetTolerance(myTol);
511 Sweep.SetAngularControl(angmin, angmax);
512 Sweep.Build(myStyle, GeomFill_Location, myCont);
513 if (Sweep.IsDone()) {
514 myShape = Sweep.Shape();
515 myShell = TopoDS::Shell(myShape);
516 myFaces = Sweep.SubShape();
517 mySections = Sweep.Sections();
518 myDone = Standard_True;
0d969553 519 // Control of the orientation
7fd59977 520 Standard_Boolean out=Standard_True;
521 TopExp_Explorer ex(myShell,TopAbs_FACE);
522 TopoDS_Face F;
523 F = TopoDS::Face(ex.Current());
524 BRepAdaptor_Surface SF(F);
525 Standard_Real u, v;
526 gp_Pnt P;
527 gp_Vec V1, V2, V;
528 u = SF.FirstUParameter();
529 v = SF.FirstVParameter();
530 SF.D1(u,v,P,V1,V2);
531 V = V1.Crossed(V2);
532 if (F.Orientation() == TopAbs_REVERSED) V.Reverse();
533 if (V.Magnitude() > 1.e-10) {
c6541a0c 534 out = myDir.Angle(V) > M_PI/2;
7fd59977 535 }
536 if (out == IsInternal) {
537 myShell.Reverse();
538 myShape.Reverse();
539 }
540 }
541 else {
542 myDone = Standard_False;
543 return;
544 }
545
0d969553 546 if (!Surf.IsNull()) { // Add the face at end
7fd59977 547
0d969553
Y
548 // Waiting the use of traces & retriction in BRepFill_Sweep
549 // Make Fuse.
7fd59977 550 BRepLib_MakeFace MkF;
1c72dff6 551 MkF.Init(Surf, Standard_True, Precision::Confusion());
7fd59977 552 Fuse(MkF.Face(), KeepOutSide);
553 }
554}
555
556
557//=======================================================================
558//function : Fuse
0d969553
Y
559//purpose : Boolean operation between the skin and the
560// stop shape
7fd59977 561//======================================================================
562 Standard_Boolean BRepFill_Draft::Fuse(const TopoDS_Shape& StopShape,
563 const Standard_Boolean KeepOutSide)
564{
565 BRep_Builder B;
566 Standard_Boolean issolid = Standard_False;
567 TopoDS_Solid Sol1, Sol2;
568 TopAbs_State State1 = TopAbs_OUT, State2 = TopAbs_OUT;
569
570
571 if (myShape.ShapeType()==TopAbs_SOLID) {
572 Sol1 = TopoDS::Solid(myShape);
573 issolid = Standard_True;
574 }
575 else {
576 B.MakeSolid(Sol1);
0d969553 577 B.Add(Sol1, myShape); // shell => solid (for fusion)
7fd59977 578 }
579
580
581 switch (StopShape.ShapeType()) {
582 case TopAbs_COMPOUND :
583 {
584 TopoDS_Iterator It(StopShape);
585 return Fuse(It.Value(), KeepOutSide);
586 }
587 case TopAbs_SOLID :
588 {
589 Sol2 = TopoDS::Solid(StopShape);
590 break;
591 }
592 case TopAbs_SHELL :
593 {
594 B.MakeSolid(Sol2);
0d969553 595 B.Add(Sol2, StopShape); // shell => solid (for fusion)
7fd59977 596 break;
597 }
598
599 case TopAbs_FACE :
600 {
601 TopoDS_Shell S;
602 B.MakeShell(S);
603 B.Add(S, StopShape);
604 B.MakeSolid(Sol2);
0d969553 605 B.Add(Sol2, S); // shell => solid (for fusion)
7fd59977 606 break;
607 }
608
609 default :
610 {
0d969553 611 return Standard_False; // Impossible to do
7fd59977 612 }
613 }
614
615 BRepAlgo_DSAccess DSA;
616 DSA.Load(Sol1, Sol2);
0d969553 617 DSA.Intersect(Sol1, Sol2); // intersection of 2 solids
7fd59977 618
0d969553 619// removal of edges corresponding to "unused" intersections
7fd59977 620 Standard_Integer NbPaquet;
621// gp_Pnt P1,P2;
622 TopoDS_Vertex V,V1;
623 TopTools_ListOfShape List;
0d969553 624 List = DSA.GetSectionEdgeSet();// list of edges
7fd59977 625
626 NbPaquet = List.Extent();
627
628 if (NbPaquet == 0) {
629#if DRAW
0d969553 630 cout << "No fusion" << endl;
7fd59977 631 DBRep::Set("DepPart", Sol1);
632 DBRep::Set("StopPart", Sol2);
633#endif
634 return Standard_False;
635 }
636
637 if (NbPaquet > 1) {
0d969553 638 // It is required to select packs.
7fd59977 639 TColStd_Array1OfReal Dist(1, NbPaquet);
640 TopTools_ListIteratorOfListOfShape it(List);
641 Standard_Real D, Dmin = 1.e10;
642 Standard_Integer ii;
643
0d969553 644 //Classify the packs by distance.
7fd59977 645 BRepExtrema_DistShapeShape Dist2;
646 Dist2.LoadS1( myWire );
647 for (ii=1; it.More();it.Next(),ii++){
648 Dist2.LoadS2( it.Value() );
649 Dist2.Perform();
650 if (Dist2.IsDone()) {
651 D = Dist2.Value();
652 Dist(ii) = D;
653 if (D < Dmin) Dmin = D;
654 }
655 else
656 Dist(ii) = 1.e10;
657 }
658
0d969553 659 // remove edges "farther" than Dmin
7fd59977 660 for (ii=1, it.Initialize(List); it.More();it.Next(), ii++){
661 if (Dist(ii) > Dmin) {
662 DSA.SuppressEdgeSet(it.Value());
663 }
664#if DRAW
665 else if (Affich) {
666 DBRep::Set("KeepEdges", it.Value());
667 }
668#endif
669 }
670 }
671
672 if (StopShape.ShapeType() != TopAbs_SOLID) {
0d969553 673 // It is required to choose the state by the geometry
7fd59977 674
0d969553
Y
675 //(1) Return an edge of section
676 List = DSA.GetSectionEdgeSet();// list of edges
7fd59977 677 TopTools_ListIteratorOfListOfShape it(List);
678 TopoDS_Iterator iter(it.Value());
679 TopoDS_Edge E = TopoDS::Edge(iter.Value());
680
0d969553 681 //(2) Return geometry on StopShape
7fd59977 682// Class BRep_Tool without fields and without Constructor :
683// BRep_Tool BT;
684 Handle(Geom_Surface) S;
685 Handle(Geom2d_Curve) C2d;
686 gp_Pnt2d P2d;
687 Standard_Real f,l;
688 TopLoc_Location L;
689// BT.CurveOnSurface(E, C2d, S, L, f, l, 2);
690 BRep_Tool::CurveOnSurface(E, C2d, S, L, f, l, 2);
691
0d969553 692 // Find a normal.
7fd59977 693 C2d->D0((f+l)/2,P2d);
694 GeomLProp_SLProps SP(S, P2d.X(), P2d.Y(), 1, 1.e-12);
695 if (! SP.IsNormalDefined()) {
696 C2d->D0((3*f+l)/4,P2d);
697 SP.SetParameters(P2d.X(), P2d.Y());
698 if ( !SP.IsNormalDefined()) {
699 C2d->D0((f+3*l)/4,P2d);
700 SP.SetParameters(P2d.X(), P2d.Y());
701 }
702 }
703
0d969553 704 // Subtract State1
c6541a0c 705 if (myDir.Angle(SP.Normal()) < M_PI/2) State1 = TopAbs_IN;
7fd59977 706 else State1 = TopAbs_OUT;
707 }
708
0d969553 709 if (! KeepOutSide) { // Invert State2;
7fd59977 710 if (State2 == TopAbs_IN) State2 = TopAbs_OUT;
711 else State2 = TopAbs_IN;
712 }
713
0d969553 714//recalculate the final shape
7fd59977 715 TopoDS_Shape result = DSA.Merge(State1, State2);
716
717 if (issolid) myShape = result;
718 else {
719 TopExp_Explorer Exp;
720 Exp.Init(result, TopAbs_SHELL);
721 if (Exp.More()) myShape = Exp.Current();
722 }
723
0d969553 724// Update the History
7fd59977 725 Standard_Integer ii;
726 for (ii=1; ii<=myLoc->NbLaw(); ii++) {
727 const TopTools_ListOfShape& L = DSA.Modified(myFaces->Value(1,ii));
728 if (L.Extent()>0)
729 myFaces->SetValue(1, ii, L.First());
730 }
731 for (ii=1; ii<=myLoc->NbLaw()+1; ii++) {
732 const TopTools_ListOfShape& L = DSA.Modified(mySections->Value(1,ii));
733 if (L.Extent()>0)
734 mySections->SetValue(1, ii, L.First());
735 }
736
737 return Standard_True;
738}
739
740//=======================================================================
741//function : Sewing
0d969553 742//purpose : Assemble the skin with the above face
7fd59977 743//======================================================================
744 Standard_Boolean BRepFill_Draft::Sewing()
745{
746 Standard_Boolean ToAss;
747 Standard_Boolean Ok = Standard_False;
748 ToAss = (myTop.ShapeType() != TopAbs_WIRE);
749
750 if ((!ToAss) || (!myDone)) return Standard_False;
751
0d969553 752 // Assembly make a shell from the faces of the shape + the input shape
7fd59977 753 Handle(BRepBuilderAPI_Sewing) Ass = new BRepBuilderAPI_Sewing(5*myTol, Standard_True,
754 Standard_True, Standard_False);
755 Ass->Add(myShape);
756 Ass->Add(myTop);
757 ToAss = Standard_True;
758
759
760 Standard_Integer NbCE;
761
762 Ass->Perform();
0d969553 763 // Check if the assembly is real.
7fd59977 764 NbCE = Ass->NbContigousEdges();
765
766 if (NbCE > 0) {
767 TopoDS_Shape res;
768 res = Ass->SewedShape();
769 if ((res.ShapeType() == TopAbs_SHELL)||
770 (res.ShapeType() == TopAbs_SOLID)) {
771 myShape = res;
772 Ok = Standard_True;
773 }
774 else if (res.ShapeType() == TopAbs_COMPOUND) {
775 TopoDS_Iterator It(res);
776 res = It.Value();
777 It.Next();
0d969553 778 if (!It.More()) {//Only one part => this is correct
7fd59977 779 myShape = res;
780 Ok = Standard_True;
781 }
782 }
783 }
784
785 if (Ok) {
0d969553 786 // Update the History
7fd59977 787 Standard_Integer ii;
788 for (ii=1; ii<=myLoc->NbLaw(); ii++) {
789 if (Ass->IsModified(myFaces->Value(1,ii)))
790 myFaces->SetValue(1, ii,
791 Ass->Modified(myFaces->Value(1,ii)));
792 }
793 for (ii=1; ii<=myLoc->NbLaw()+1; ii++) {
794 if (Ass->IsModified(mySections->Value(1,ii)))
795 mySections->SetValue(1, ii,
796 Ass->Modified(mySections->Value(1,ii)));
797 }
798
0d969553 799 if (myShape.Closed()) { // Make a Solid
7fd59977 800 TopoDS_Solid solid;
801 BRep_Builder BS;
802 BS.MakeSolid(solid);
803 BS.Add(solid,TopoDS::Shell(myShape));
804
805 BRepClass3d_SolidClassifier SC(solid);
806 SC.PerformInfinitePoint(Precision::Confusion());
807 if ( SC.State() == TopAbs_IN) {
808 BS.MakeSolid(solid);
809 myShape.Reverse();
810 BS.Add(solid,TopoDS::Shell(myShape));
811 }
812 myShape = solid;
813 }
814 }
815#if DEB
0d969553 816 else cout << "Draft : No assembly !" << endl;
7fd59977 817#endif
818 return Ok;
819}
820
821//=======================================================================
822//function : Generated
0d969553 823//purpose : return a sub-part generated by sweeping
7fd59977 824//======================================================================
825 const TopTools_ListOfShape&
826 BRepFill_Draft::Generated(const TopoDS_Shape& S)
827{
828 myGenerated.Clear();
829 TopoDS_Edge E;
830 Standard_Integer ii;
831 E = TopoDS::Edge(S);
832 if (E.IsNull()) {
833 for (ii=0; ii<=myLoc->NbLaw(); ii++)
834 if (E.IsSame(myLoc->Vertex(ii))) {
835 myGenerated.Append(mySections->Value(1, ii+1));
836 break;
837 }
838 }
839 else {
840 for (ii=1; ii<=myLoc->NbLaw(); ii++)
841 if (E.IsSame(myLoc->Edge(ii))) {
842 myGenerated.Append(myFaces->Value(1, ii));
843 break;
844 }
845 }
846
847 return myGenerated;
848}
849
850//=======================================================================
851//function : Shape
0d969553 852//purpose : return the complete shape
7fd59977 853//======================================================================
854 TopoDS_Shape BRepFill_Draft::Shape()const
855{
856 return myShape;
857}
858
0d969553 859//=====================================================================
7fd59977 860//function : Shell
0d969553
Y
861//purpose : surface of skinning with the input face (=>shell)
862//=====================================================================
7fd59977 863 TopoDS_Shell BRepFill_Draft::Shell()const
864{
865 return myShell;
866}
867
868//=======================================================================
869//function : IsDone
870//purpose :
871//======================================================================
872 Standard_Boolean BRepFill_Draft::IsDone()const
873{
874 return myDone;
875}