1 // Created on: 1998-07-22
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_HCompCurve.hxx>
21 #include <BRepBuilderAPI_Copy.hxx>
22 #include <BRepBuilderAPI_Transform.hxx>
23 #include <BRepClass3d_SolidClassifier.hxx>
24 #include <BRepFill.hxx>
25 #include <BRepFill_ACRLaw.hxx>
26 #include <BRepFill_CompatibleWires.hxx>
27 #include <BRepFill_DataMapOfShapeHArray2OfShape.hxx>
28 #include <BRepFill_Edge3DLaw.hxx>
29 #include <BRepFill_EdgeOnSurfLaw.hxx>
30 #include <BRepFill_LocationLaw.hxx>
31 #include <BRepFill_NSections.hxx>
32 #include <BRepFill_PipeShell.hxx>
33 #include <BRepFill_Section.hxx>
34 #include <BRepFill_SectionLaw.hxx>
35 #include <BRepFill_SectionPlacement.hxx>
36 #include <BRepFill_ShapeLaw.hxx>
37 #include <BRepFill_Sweep.hxx>
38 #include <BRepGProp.hxx>
39 #include <BRepLib_MakeEdge.hxx>
40 #include <BRepLib_MakeFace.hxx>
41 #include <GeomAdaptor_HCurve.hxx>
42 #include <GeomAdaptor_HSurface.hxx>
43 #include <GeomFill_ConstantBiNormal.hxx>
44 #include <GeomFill_CorrectedFrenet.hxx>
45 #include <GeomFill_CurveAndTrihedron.hxx>
46 #include <GeomFill_DiscreteTrihedron.hxx>
47 #include <GeomFill_Fixed.hxx>
48 #include <GeomFill_Frenet.hxx>
49 #include <GeomFill_GuideTrihedronAC.hxx>
50 #include <GeomFill_GuideTrihedronPlan.hxx>
51 #include <GeomFill_LocationGuide.hxx>
52 #include <GeomFill_SectionLaw.hxx>
53 #include <GeomFill_TrihedronLaw.hxx>
56 #include <gp_Trsf.hxx>
58 #include <GProp_GProps.hxx>
59 #include <IntCurveSurface_HInter.hxx>
60 #include <IntCurveSurface_IntersectionPoint.hxx>
61 #include <Law_Function.hxx>
62 #include <Law_Interpol.hxx>
63 #include <Precision.hxx>
64 #include <Standard_ConstructionError.hxx>
65 #include <Standard_DomainError.hxx>
66 #include <Standard_NotImplemented.hxx>
67 #include <Standard_Type.hxx>
68 #include <StdFail_NotDone.hxx>
69 #include <TColgp_HArray1OfPnt2d.hxx>
70 #include <TColStd_HArray1OfReal.hxx>
72 #include <TopLoc_Location.hxx>
74 #include <TopoDS_Iterator.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <TopoDS_Shell.hxx>
77 #include <TopoDS_Solid.hxx>
78 #include <TopoDS_Vertex.hxx>
79 #include <TopoDS_Wire.hxx>
80 #include <TopTools_SequenceOfShape.hxx>
83 IMPLEMENT_STANDARD_RTTIEXT(BRepFill_PipeShell,MMgt_TShared)
88 #include <DrawTrSurf.hxx>
90 static Standard_Boolean Affich = 0;
93 #include <TopTools_ListIteratorOfListOfShape.hxx>
94 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
95 #include <TopoDS_Compound.hxx>
97 static Standard_Boolean UpdateMap(const TopoDS_Shape& theKey,
98 const TopoDS_Shape& theValue,
99 TopTools_DataMapOfShapeListOfShape& theMap);
101 static Standard_Boolean BuildBoundaries(const BRepFill_Sweep& theSweep,
102 const Handle(BRepFill_SectionLaw)& theSection,
103 TopoDS_Shape& theBottom,
104 TopoDS_Shape& theTop);
106 //=======================================================================
107 //function : ComputeSection
108 //purpose : Construct an intermediary section
109 //=======================================================================
111 static Standard_Boolean ComputeSection(const TopoDS_Wire& W1,
112 const TopoDS_Wire& W2,
113 const Standard_Real p1,
114 const Standard_Real p2,
117 TColStd_SequenceOfReal SR;
118 TopTools_SequenceOfShape SSh;
125 BRepFill_CompatibleWires CW(SSh);
128 if (!CW.IsDone()) StdFail_NotDone::Raise("Uncompatible wires");
129 GeomFill_SequenceOfTrsf EmptyTrsfs;
130 Handle(BRepFill_NSections) SL = new (BRepFill_NSections) (CW.Shape(),EmptyTrsfs,SR,0.,1.);
131 Standard_Real US = p1/(p1+p2);
133 return Standard_True;
138 //=======================================================================
139 //function : PerformTransition
140 //purpose : Modify a law of location depending on Transition
141 //=======================================================================
143 static void PerformTransition(const BRepFill_TransitionStyle Mode,
144 Handle(BRepFill_LocationLaw)& Loc,
145 const Standard_Real angmin)
148 Loc->DeleteTransform();
149 if (Mode == BRepFill_Modified) Loc->TransformInG0Law();
150 else Loc->TransformInCompatibleLaw(angmin);
153 //=======================================================================
154 //function : PerformPlan
155 //purpose : Construct a plane of filling if exists
156 //=======================================================================
158 static Standard_Boolean PerformPlan(TopoDS_Shape& S)
160 Standard_Boolean isDegen = Standard_True;
161 TopExp_Explorer explo(S, TopAbs_EDGE);
162 for (; explo.More(); explo.Next())
164 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
165 if (!BRep_Tool::Degenerated(anEdge))
166 isDegen = Standard_False;
171 return Standard_True;
174 TopoDS_Wire W = TopoDS::Wire(S);
175 Standard_Boolean Ok = Standard_False;
177 BRepLib_MakeFace mkplan(W, Standard_True);
178 if (mkplan.IsDone()) {
186 //=============================================================================
187 //function : IsSameOriented
188 //purpose : Checks whether aFace is oriented to the same side as aShell or not
189 //=============================================================================
191 static Standard_Boolean IsSameOriented(const TopoDS_Shape& aFace,
192 const TopoDS_Shape& aShell)
194 TopExp_Explorer Explo(aFace, TopAbs_EDGE);
195 TopoDS_Shape anEdge = Explo.Current();
196 TopAbs_Orientation Or1 = anEdge.Orientation();
198 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
199 TopExp::MapShapesAndAncestors( aShell, TopAbs_EDGE, TopAbs_FACE, EFmap );
201 const TopoDS_Shape& AdjacentFace = EFmap.FindFromKey(anEdge).First();
202 TopoDS_Shape theEdge;
203 for (Explo.Init(AdjacentFace, TopAbs_EDGE); Explo.More(); Explo.Next())
205 theEdge = Explo.Current();
206 if (theEdge.IsSame(anEdge))
210 TopAbs_Orientation Or2 = theEdge.Orientation();
212 return Standard_False;
213 return Standard_True;
215 //=======================================================================
216 //function : BRepFill_PipeShell
218 //=======================================================================
219 BRepFill_PipeShell::BRepFill_PipeShell(const TopoDS_Wire& Spine)
221 myForceApproxC1(Standard_False),
222 myIsAutomaticLaw(Standard_False),
223 myTrihedron(GeomFill_IsCorrectedFrenet),
224 myTransition(BRepFill_Modified),
225 myStatus(GeomFill_PipeOk)
227 myLocation.Nullify();
235 // Attention to closed non-declared wire !
236 if (!mySpine.Closed()) {
237 TopoDS_Vertex Vf, Vl;
238 TopExp::Vertices(mySpine, Vf, Vl);
239 if (Vf.IsSame(Vl)) mySpine.Closed(Standard_True);
243 //=======================================================================
245 //purpose : Define a law of Frenet (Correct)
246 //=======================================================================
247 void BRepFill_PipeShell::Set(const Standard_Boolean IsFrenet)
249 Handle(GeomFill_TrihedronLaw) TLaw;
251 myTrihedron = GeomFill_IsFrenet;
252 TLaw = new (GeomFill_Frenet) ();
255 myTrihedron = GeomFill_IsFrenet;
256 TLaw = new (GeomFill_CorrectedFrenet) ();
258 Handle(GeomFill_CurveAndTrihedron) Loc =
259 new (GeomFill_CurveAndTrihedron) (TLaw);
260 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
261 mySection.Nullify(); //It is required to relocalize sections.
264 //=======================================================================
265 //function : SetDiscrete
266 //purpose : Define a law of Discrete Trihedron
267 //=======================================================================
268 void BRepFill_PipeShell::SetDiscrete()
270 Handle(GeomFill_TrihedronLaw) TLaw;
272 myTrihedron = GeomFill_IsDiscreteTrihedron;
273 TLaw = new (GeomFill_DiscreteTrihedron) ();
275 Handle(GeomFill_CurveAndTrihedron) Loc =
276 new (GeomFill_CurveAndTrihedron) (TLaw);
277 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
278 mySection.Nullify(); //It is required to relocalize sections.
281 //=======================================================================
283 //purpose : Define a law Constant
284 //=======================================================================
285 void BRepFill_PipeShell::Set(const gp_Ax2& Axe)
287 myTrihedron = GeomFill_IsFixed;
289 V1.SetXYZ(Axe.Direction().XYZ());
290 V2.SetXYZ(Axe.XDirection().XYZ());
291 Handle(GeomFill_Fixed) TLaw = new (GeomFill_Fixed) (V1, V2);
292 Handle(GeomFill_CurveAndTrihedron) Loc =
293 new (GeomFill_CurveAndTrihedron) (TLaw);
294 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
295 mySection.Nullify(); //It is required to relocalize sections.
298 //=======================================================================
300 //purpose : Construct a law of location of binormal fixed type
301 //=======================================================================
302 void BRepFill_PipeShell::Set(const gp_Dir& BiNormal)
304 myTrihedron = GeomFill_IsConstantNormal;
306 Handle(GeomFill_ConstantBiNormal) TLaw =
307 new (GeomFill_ConstantBiNormal) (BiNormal);
308 Handle(GeomFill_CurveAndTrihedron) Loc =
309 new (GeomFill_CurveAndTrihedron) (TLaw);
310 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
311 mySection.Nullify(); //Il faut relocaliser les sections.
314 //=======================================================================
316 //purpose : Construct a law of location of Darboux type
317 //=======================================================================
318 Standard_Boolean BRepFill_PipeShell::Set(const TopoDS_Shape& SpineSupport)
322 // A special law of location is required
323 Handle(BRepFill_EdgeOnSurfLaw) loc =
324 new (BRepFill_EdgeOnSurfLaw) (mySpine, SpineSupport);
325 B = loc->HasResult();
328 myTrihedron = GeomFill_IsDarboux;
329 mySection.Nullify(); //It is required to relocalize the sections.
334 //=======================================================================
336 //purpose : Defines a lawv with help of a guided contour
337 //=======================================================================
338 void BRepFill_PipeShell::Set(const TopoDS_Wire& AuxiliarySpine,
339 const Standard_Boolean CurvilinearEquivalence,
340 const BRepFill_TypeOfContact KeepContact)
342 // Reorganization of the guide (pb of orientation and origin)
343 TopoDS_Wire TheGuide;
344 TheGuide = AuxiliarySpine;
345 Standard_Boolean SpClose = mySpine.Closed(),
346 GuideClose = AuxiliarySpine.Closed();
348 if (KeepContact == BRepFill_ContactOnBorder)
349 myIsAutomaticLaw = Standard_True;
351 if (!SpClose && !GuideClose) {
352 // Case open reorientation of the guide
353 TopoDS_Wire sp = mySpine;
354 TopTools_SequenceOfShape Seq;
356 Seq.Append(TheGuide);
357 BRepFill_CompatibleWires CW(Seq);
360 if (!CW.IsDone()) StdFail_NotDone::Raise("Uncompatible wires");
361 TheGuide = TopoDS::Wire(CW.Shape().Value(2));
363 else if (GuideClose) {
364 // Case guide closed : Determination of the origin
365 // & reorientation of the guide
369 TopoDS_Vertex Vf, Vl;
371 TopExp::Vertices(mySpine, Vf, Vl);
372 SpOr = BRep_Tool::Pnt(Vf);
373 P = BRep_Tool::Pnt(Vl);
375 SpOr.BaryCenter(0.5, P, 0.5);
379 BRepAdaptor_CompCurve BC(mySpine);
382 BRepFill::SearchOrigin(TheGuide, SpOr, Dir, 100*myTol3d);
387 DBRep::Set("theguide", TheGuide);
389 // transform the guide in a single curve (periodic if posssible)
390 Handle(BRepAdaptor_HCompCurve) Guide =
391 new (BRepAdaptor_HCompCurve) (TheGuide);
392 Guide->ChangeCurve().SetPeriodic(Standard_True);
394 if (CurvilinearEquivalence) { // trihedron by curvilinear reduced abscissa
395 if (KeepContact == BRepFill_Contact ||
396 KeepContact == BRepFill_ContactOnBorder)
397 myTrihedron = GeomFill_IsGuideACWithContact; // with rotation
399 myTrihedron = GeomFill_IsGuideAC; // without rotation
401 Handle(GeomFill_GuideTrihedronAC) TLaw
402 = new (GeomFill_GuideTrihedronAC) (Guide);
403 Handle(GeomFill_LocationGuide) Loc =
404 new (GeomFill_LocationGuide) (TLaw);
405 myLocation = new (BRepFill_ACRLaw) (mySpine, Loc);
407 else {// trihedron by plane
408 if (KeepContact == BRepFill_Contact ||
409 KeepContact == BRepFill_ContactOnBorder)
410 myTrihedron = GeomFill_IsGuidePlanWithContact; // with rotation
412 myTrihedron = GeomFill_IsGuidePlan; // without rotation
414 Handle(GeomFill_GuideTrihedronPlan) TLaw =
415 new (GeomFill_GuideTrihedronPlan) (Guide);
416 Handle(GeomFill_LocationGuide) Loc =
417 new (GeomFill_LocationGuide) (TLaw);
418 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
420 mySection.Nullify(); //It is required to relocalize the sections.
424 //=======================================================================
425 //function : SetMaxDegree
427 //=======================================================================
428 void BRepFill_PipeShell::SetMaxDegree(const Standard_Integer NewMaxDegree)
430 myMaxDegree = NewMaxDegree;
433 //=======================================================================
434 //function : SetMaxSegments
436 //=======================================================================
437 void BRepFill_PipeShell::SetMaxSegments(const Standard_Integer NewMaxSegments)
439 myMaxSegments = NewMaxSegments;
442 //=======================================================================
443 //function : SetForceApproxC1
444 //purpose : Set the flag that indicates attempt to approximate
445 // a C1-continuous surface if a swept surface proved
447 //=======================================================================
448 void BRepFill_PipeShell::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
450 myForceApproxC1 = ForceApproxC1;
453 //=======================================================================
455 //purpose : Add a Section
456 //=======================================================================
457 void BRepFill_PipeShell::Add(const TopoDS_Shape& Profile,
458 const Standard_Boolean WithContact,
459 const Standard_Boolean WithCorrection)
463 Add(Profile, V, WithContact, WithCorrection);
467 //=======================================================================
469 //purpose : Add a Section
470 //=======================================================================
471 void BRepFill_PipeShell::Add(const TopoDS_Shape& Profile,
472 const TopoDS_Vertex& Location,
473 const Standard_Boolean WithContact,
474 const Standard_Boolean WithCorrection)
476 DeleteProfile(Profile); // No duplication
477 if (myIsAutomaticLaw)
480 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
481 S.Set(Standard_True);
486 Handle(GeomFill_LocationGuide) Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(1));
487 Handle(TColgp_HArray1OfPnt2d) ParAndRad;
488 Loc->ComputeAutomaticLaw(ParAndRad);
490 //Compuite initial width of section (this will be 1.)
491 GProp_GProps GlobalProps;
492 BRepGProp::LinearProperties(Profile, GlobalProps);
493 gp_Pnt BaryCenter = GlobalProps.CentreOfMass();
495 TopoDS_Face ProfileFace = BRepLib_MakeFace(TopoDS::Wire(Profile), Standard_True); //only plane
496 Handle(Geom_Surface) thePlane = BRep_Tool::Surface(ProfileFace);
497 Handle(GeomAdaptor_HSurface) GAHplane = new GeomAdaptor_HSurface(thePlane);
498 IntCurveSurface_HInter Intersector;
499 Handle(Adaptor3d_HCurve) aHCurve [2];
500 aHCurve[0] = Loc->GetCurve();
501 aHCurve[1] = Loc->Guide();
502 gp_Pnt PointsOnSpines [2];
503 Standard_Integer i, j;
505 for (i = 0; i < 2; i++)
507 Intersector.Perform(aHCurve[i], GAHplane);
508 Standard_Real MinDist = RealLast();
509 for (j = 1; j <= Intersector.NbPoints(); j++)
511 gp_Pnt aPint = Intersector.Point(j).Pnt();
512 Standard_Real aDist = BaryCenter.Distance(aPint);
516 PointsOnSpines[i] = aPint;
521 //Correct <ParAndRad> according to <InitialWidth>
522 Standard_Real InitialWidth = PointsOnSpines[0].Distance(PointsOnSpines[1]);
523 Standard_Integer NbParRad = ParAndRad->Upper();
524 for (i = 1; i <= NbParRad; i++)
526 gp_Pnt2d aParRad = ParAndRad->Value(i);
527 aParRad.SetY( aParRad.Y() / InitialWidth );
528 ParAndRad->SetValue(i, aParRad);
531 myLaw = new Law_Interpol();
533 Standard_Boolean IsPeriodic =
534 (Abs(ParAndRad->Value(1).Y() - ParAndRad->Value(NbParRad).Y()) < Precision::Confusion());
536 (Handle(Law_Interpol)::DownCast(myLaw))->Set(ParAndRad->Array1(), IsPeriodic);
540 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
547 //=======================================================================
549 //purpose : Section + law of homothety
550 //=======================================================================
551 void BRepFill_PipeShell::SetLaw(const TopoDS_Shape& Profile,
552 const Handle(Law_Function)& L,
553 const Standard_Boolean WithContact,
554 const Standard_Boolean WithCorrection)
558 SetLaw( Profile, L, V, WithContact, WithCorrection);
562 //=======================================================================
564 //purpose : Section + Law of homothety
565 //=======================================================================
566 void BRepFill_PipeShell::SetLaw(const TopoDS_Shape& Profile,
567 const Handle(Law_Function)& L,
568 const TopoDS_Vertex& Location,
569 const Standard_Boolean WithContact,
570 const Standard_Boolean WithCorrection)
573 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
574 S.Set(Standard_True);
581 //=======================================================================
583 //purpose : Delete a section
584 //=======================================================================
585 void BRepFill_PipeShell::DeleteProfile(const TopoDS_Shape& Profile)
587 Standard_Boolean isVertex = (Profile.ShapeType() == TopAbs_VERTEX);
589 Standard_Boolean Trouve=Standard_False;
591 for (ii=1; ii<=mySeq.Length() && !Trouve; ii++) {
592 Standard_Boolean found = Standard_False;
593 const TopoDS_Wire& aWire = mySeq.Value(ii).Wire();
596 TopExp_Explorer Explo(aWire, TopAbs_VERTEX);
597 for (; Explo.More(); Explo.Next())
598 if (Profile.IsSame(Explo.Current()))
599 found = Standard_True;
601 else if (Profile.IsSame(aWire))
602 found = Standard_True;
606 Trouve = Standard_True;
611 if (Trouve) mySection.Nullify();
616 //=======================================================================
619 //=======================================================================
620 Standard_Boolean BRepFill_PipeShell::IsReady() const
622 return (mySeq.Length() != 0);
624 //=======================================================================
625 //function : GetStatus
627 //=======================================================================
628 GeomFill_PipeError BRepFill_PipeShell::GetStatus() const
634 //=======================================================================
635 //function : SetTolerance
637 //=======================================================================
638 void BRepFill_PipeShell::SetTolerance(const Standard_Real Tol3d ,
639 const Standard_Real BoundTol,
640 const Standard_Real TolAngular)
643 myBoundTol = BoundTol;
644 myTolAngular = TolAngular;
647 //=======================================================================
648 //function : SetTransition
649 //purpose : Defines the mode of processing of corners
650 //=======================================================================
651 void BRepFill_PipeShell::SetTransition(const BRepFill_TransitionStyle Mode,
652 const Standard_Real Angmin,
653 const Standard_Real Angmax)
655 if (myTransition != Mode)
656 mySection.Nullify(); //It is required to relocalize the sections.
662 //=======================================================================
663 //function : Simulate
664 //purpose : Calculate N Sections
665 //=======================================================================
666 void BRepFill_PipeShell::Simulate(const Standard_Integer N,
667 TopTools_ListOfShape& List)
673 Standard_Real First, Last, Length, Delta, U,
675 Standard_Integer ii, NbL = myLocation->NbLaw();
676 Standard_Boolean Finis=Standard_False;
679 // Calculate the parameters of digitalization
680 mySection->Law(1)->GetDomain(FirstS, Last);
681 DeltaS = Last - FirstS;
682 myLocation->CurvilinearBounds(NbL,First, Length);
684 if (N>1) Delta /= (N-1);
686 myLocation->CurvilinearBounds(1,First, Last); // Initiation of Last
687 for (U=0.0, ii=1; !Finis ; U+=Delta) {
690 Finis = Standard_True;
693 if (ii < NbL) myLocation->CurvilinearBounds(NbL,First, Last);
694 if (U > Last) U = (Last+First)/2; // The edge is not skipped
697 US = FirstS + (U/Length)*DeltaS;
698 // Calcul d'une section
699 mySection->D0(US, W);
700 myLocation->D0(U, W);
705 //=======================================================================
707 //purpose : Construct the Shell and the history
708 //=======================================================================
709 Standard_Boolean BRepFill_PipeShell::Build()
712 Standard_Real FirstS, LastS;
716 if (myStatus != GeomFill_PipeOk) {
720 myShape = Sh; // Nullify
721 return Standard_False;
724 // 2) Calculate myFirst and myLast
725 mySection->Law(1)->GetDomain(FirstS, LastS);
726 mySection->D0(FirstS, myFirst);
727 myLocation->D0(0, myFirst);
728 if (mySection->IsVClosed() && myLocation->IsClosed()) {
729 if (myLocation->IsG1(0)>=0)
737 Standard_Real Length;
738 myLocation->CurvilinearBounds(myLocation->NbLaw(),
740 mySection->D0(LastS, myLast);
741 myLocation->D0(Length, myLast);
742 // eap 5 Jun 2002 occ332, myLast and myFirst must not share one TShape,
743 // tolerances of shapes built on them may be quite different
744 if (myFirst.IsPartner( myLast )) {
745 BRepBuilderAPI_Copy copy(myLast);
747 myLast = copy.Shape();
749 // eap 5 Jun 2002 occ332, end modif
753 DBRep::Set("PipeFirst", myFirst);
754 DBRep::Set("PipeLast", myLast);
759 BRepFill_Sweep MkSw(mySection, myLocation, Standard_True);
760 MkSw.SetTolerance(myTol3d, myBoundTol, 1.e-5, myTolAngular);
761 MkSw.SetAngularControl(angmin, angmax);
762 MkSw.SetForceApproxC1(myForceApproxC1);
763 MkSw.SetBounds(TopoDS::Wire(myFirst),
764 TopoDS::Wire(myLast));
765 GeomAbs_Shape theContinuity = GeomAbs_C2;
766 if (myTrihedron == GeomFill_IsDiscreteTrihedron)
767 theContinuity = GeomAbs_C0;
768 TopTools_MapOfShape Dummy;
769 BRepFill_DataMapOfShapeHArray2OfShape Dummy2;
770 BRepFill_DataMapOfShapeHArray2OfShape Dummy3;
771 MkSw.Build(Dummy, Dummy2, Dummy3, myTransition, theContinuity,
772 GeomFill_Location, myMaxDegree, myMaxSegments);
774 myStatus = myLocation->GetStatus();
775 Ok = (MkSw.IsDone() && (myStatus == GeomFill_PipeOk));
778 myShape = MkSw.Shape();
779 myErrorOnSurf = MkSw.ErrorOnSurface();
781 TopoDS_Shape aBottomWire = myFirst;
782 TopoDS_Shape aTopWire = myLast;
784 if(BuildBoundaries(MkSw, mySection, aBottomWire, aTopWire)) {
785 myFirst = aBottomWire;
789 if (mySection->IsUClosed())
791 TopExp_Explorer explo;
792 Standard_Boolean DegenFirst = Standard_True, DegenLast = Standard_True;
794 for (explo.Init(myFirst, TopAbs_EDGE); explo.More(); explo.Next())
796 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
797 DegenFirst = DegenFirst && BRep_Tool::Degenerated(anEdge);
800 for (explo.Init(myLast, TopAbs_EDGE); explo.More(); explo.Next())
802 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
803 DegenLast = DegenLast && BRep_Tool::Degenerated(anEdge);
806 if (DegenFirst && DegenLast)
807 myShape.Closed(Standard_True);
816 myShape = Sh; // Nullify
817 if (myStatus == GeomFill_PipeOk) myStatus = GeomFill_PipeNotOk;
822 //=======================================================================
823 //function : MakeSolid
825 //=======================================================================
826 Standard_Boolean BRepFill_PipeShell::MakeSolid()
828 if (myShape.IsNull())
829 StdFail_NotDone::Raise("PipeShell is not built");
830 Standard_Boolean B = myShape.Closed();
835 if(!myFirst.IsNull() && !myLast.IsNull()) {
836 B = (myFirst.Closed() && myLast.Closed());
839 // It is necessary to block the extremities
840 B = PerformPlan(myFirst);
842 B = PerformPlan(myLast);
844 if (!myFirst.IsNull() && !IsSameOriented( myFirst, myShape ))
846 if (!myLast.IsNull() && !IsSameOriented( myLast, myShape ))
849 if (!myFirst.IsNull())
850 BS.Add(myShape, TopoDS::Face(myFirst));
851 if (!myLast.IsNull())
852 BS.Add(myShape, TopoDS::Face(myLast));
854 myShape.Closed(Standard_True);
863 BS.Add(solid,TopoDS::Shell(myShape));
864 BRepClass3d_SolidClassifier SC(solid);
865 SC.PerformInfinitePoint(Precision::Confusion());
866 if ( SC.State() == TopAbs_IN) {
869 BS.Add(solid,TopoDS::Shell(myShape));
872 myShape.Closed(Standard_True);
877 //=======================================================================
879 //purpose : Return the result
880 //=======================================================================
881 const TopoDS_Shape& BRepFill_PipeShell::Shape() const
886 //=======================================================================
887 //function : ErrorOnSurface
889 //=======================================================================
891 Standard_Real BRepFill_PipeShell::ErrorOnSurface() const
893 return myErrorOnSurf;
896 //=======================================================================
897 //function : FirstShape
898 //purpose : Return the start section
899 //=======================================================================
900 const TopoDS_Shape& BRepFill_PipeShell::FirstShape() const
905 //=======================================================================
906 //function : LastShape
907 //purpose : Return the end section
908 //=======================================================================
909 const TopoDS_Shape& BRepFill_PipeShell::LastShape() const
914 //=======================================================================
915 //function : Generated
917 //=======================================================================
918 // void BRepFill_PipeShell::Generated(const TopoDS_Shape& ,
919 // TopTools_ListOfShape& )
920 void BRepFill_PipeShell::Generated(const TopoDS_Shape& theShape,
921 TopTools_ListOfShape& theList)
923 // Standard_NotImplemented::Raise("Generated:Pas Fait");
926 if(myGenMap.IsBound(theShape)) {
927 theList = myGenMap.Find(theShape);
931 //=======================================================================
933 //purpose : - Check that everything is ready
934 // - Construct the law of section
935 // - Construct the law of location if required
936 // - Calculate First & Last
937 //=======================================================================
938 void BRepFill_PipeShell::Prepare()
941 if (!IsReady()) StdFail_NotDone::Raise("PipeShell");
942 if (!myLocation.IsNull() && !mySection.IsNull()) return; // It is ready
944 //Check set of section for right configuration of punctual sections
946 TopoDS_Iterator iter;;
947 for (i = 2; i <= mySeq.Length()-1; i++)
949 Standard_Boolean wdeg = Standard_True;
950 for (iter.Initialize(mySeq(i).Wire()); iter.More(); iter.Next())
952 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
953 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
956 Standard_Failure::Raise("Wrong usage of punctual sections");
958 if (mySeq.Length() <= 2)
960 Standard_Boolean wdeg = Standard_True;
961 for (i = 1; i <= mySeq.Length(); i++)
962 for (iter.Initialize(mySeq(i).Wire()); iter.More(); iter.Next())
964 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
965 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
968 Standard_Failure::Raise("Wrong usage of punctual sections");
971 // Construction of the law of location
972 if(myLocation.IsNull())
976 case GeomFill_IsCorrectedFrenet :
978 Handle(GeomFill_TrihedronLaw) TLaw =
979 new (GeomFill_CorrectedFrenet) ();
980 Handle(GeomFill_CurveAndTrihedron) Loc =
981 new (GeomFill_CurveAndTrihedron) (TLaw);
982 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
987 Standard_ConstructionError::Raise("PipeShell");
992 //Transformation of the law (Transition Management)
993 PerformTransition(myTransition, myLocation, angmin);
996 // Construction of the section law
997 if (mySeq.Length() == 1) {
1000 Place(mySeq(1), theSect, aTrsf, p1);
1001 TopoDS_Wire aLocalShape = theSect;
1002 if (mySeq(1).IsLaw())
1003 mySection = new BRepFill_ShapeLaw(aLocalShape, myLaw);
1004 // mySection = new (BRepFill_ShapeLaw) (TopoDS_Wire(theSect), myLaw);
1006 mySection = new BRepFill_ShapeLaw(aLocalShape);
1007 // mySection = new (BRepFill_ShapeLaw) (TopoDS::Wire(theSect));
1011 TColStd_SequenceOfReal Param;
1012 TopTools_SequenceOfShape WSeq;
1013 GeomFill_SequenceOfTrsf Transformations;
1016 Standard_Integer NbL = myLocation->NbLaw();
1018 Standard_Real V1, V2, param;
1019 myLocation->CurvilinearBounds(NbL, V1, V2);
1021 Standard_Integer ideb = 0, ifin = 0;
1022 // for (Standard_Integer iseq=1;iseq<=mySeq.Length();iseq++) {
1023 Standard_Integer iseq;
1024 for (iseq=1;iseq<=mySeq.Length();iseq++) {
1025 Place(mySeq(iseq), theSect, aTrsf, param);
1026 Param.Append(param);
1027 WSeq.Append(theSect);
1028 // WSeq.Append(TopoDS::Wire(theSect));
1029 Transformations.Append(aTrsf);
1030 if (param==V1) ideb = iseq;
1031 if (param==V2) ifin = iseq;
1035 // looping sections ?
1036 if (myLocation->IsClosed()) {
1038 // place the initial section at the final position
1040 WSeq.Append(WSeq(ideb));
1043 // place the final section at the initial position
1045 WSeq.Append(WSeq(ifin));
1048 // it is necessary to find a medium section to impose by V1 and by V2
1049 Standard_Real pmin = Param.Value(1), pmax = Param.Value(1);
1050 TopoDS_Wire Wmin = TopoDS::Wire(WSeq.Value(1)), Wmax;
1051 for (iseq=2;iseq<=WSeq.Length();iseq++) {
1052 if (Param.Value(iseq)<pmin) {
1053 pmin = Param.Value(iseq);
1054 Wmin = TopoDS::Wire(WSeq.Value(iseq));
1056 if (Param.Value(iseq)>pmax) {
1057 pmax = Param.Value(iseq);
1058 Wmax = TopoDS::Wire(WSeq.Value(iseq));
1061 // medium section between Wmin and Wmax
1063 Standard_Real dmin = Abs(pmin-V1);
1064 Standard_Real dmax = Abs(pmax-V2);
1065 if (ComputeSection(Wmin,Wmax,dmin,dmax,Wres)) {
1066 // impose section Wres at the beginning and the end
1077 // parse sections by increasing parameter
1078 Standard_Boolean play_again = Standard_True;
1079 while (play_again) {
1080 play_again = Standard_False;
1081 for (iseq=1;iseq<=WSeq.Length();iseq++) {
1082 for (Standard_Integer jseq=iseq+1;jseq<=WSeq.Length();jseq++) {
1083 if (Param.Value(iseq)>Param.Value(jseq)) {
1084 Param.Exchange(iseq,jseq);
1085 WSeq.Exchange(iseq,jseq);
1086 play_again = Standard_True;
1094 char* name = new char[100];
1095 Standard_Integer NBSECT = 0;
1096 for (Standard_Integer i=1;i<=WSeq.Length();i++) {
1098 sprintf(name,"WSeq_%d",NBSECT);
1099 DBRep::Set(name,TopoDS::Wire(WSeq.Value(i)));
1106 // Calculate work sections
1107 TopTools_SequenceOfShape WorkingSections;
1108 WorkingSections.Clear();
1109 TopTools_DataMapOfShapeListOfShape WorkingMap;
1111 BRepFill_CompatibleWires Georges(WSeq);
1112 Georges.SetPercent(0.1);
1113 Georges.Perform(Standard_False);
1114 if (Georges.IsDone()) {
1115 WorkingSections = Georges.Shape();
1116 WorkingMap = Georges.Generated();
1119 Standard_ConstructionError::Raise("PipeShell : uncompatible wires");
1121 mySection = new (BRepFill_NSections) (WorkingSections,Transformations,Param,V1,V2);
1125 // modify the law of location if contact
1126 if ( (myTrihedron == GeomFill_IsGuidePlanWithContact)
1127 || (myTrihedron == GeomFill_IsGuideACWithContact) ) {
1128 Standard_Real fs, f, l, Delta, Length;
1129 Handle(GeomFill_LocationGuide) Loc;
1130 Handle(GeomFill_SectionLaw) Sec = mySection->ConcatenedLaw();
1131 myLocation->CurvilinearBounds(myLocation->NbLaw(), f, Length);
1132 Sec->GetDomain(fs,l);
1133 Delta = (l-fs)/Length;
1135 Standard_Real angle, old_angle = 0;
1136 for (Standard_Integer ipath=1; ipath<=myLocation->NbLaw(); ipath++) {
1137 myLocation->CurvilinearBounds(ipath, f, l);
1138 Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(ipath));
1139 Loc->Set(Sec, Standard_True, fs + f*Delta, fs + l*Delta,
1140 old_angle, angle); // force the rotation
1145 myStatus = myLocation->GetStatus();
1148 //=======================================================================
1150 //purpose : Implement a Section in the local refernce frame
1151 // and return its parameter on the trajectory
1152 //=======================================================================
1153 void BRepFill_PipeShell::Place(const BRepFill_Section& Sec,
1156 Standard_Real& param)
1158 BRepFill_SectionPlacement Place(myLocation,
1162 Sec.WithCorrection());
1163 TopoDS_Wire TmpWire = Sec.Wire();
1164 aTrsf = Place.Transformation();
1165 //TopLoc_Location Loc2(Place.Transformation()), Loc1;
1166 //Loc1 = TmpWire.Location();
1167 //W.Location(Loc2.Multiplied(Loc1));
1168 //Transform the copy
1169 W = TopoDS::Wire(BRepBuilderAPI_Transform(TmpWire, aTrsf, Standard_True));
1170 ////////////////////////////////////
1171 param = Place.AbscissaOnPath();
1175 //=======================================================================
1176 //function : ResetLoc
1177 //purpose : Remove references to the sections in the laws of location
1178 //=======================================================================
1179 void BRepFill_PipeShell::ResetLoc()
1181 if ( (myTrihedron == GeomFill_IsGuidePlanWithContact)
1182 || (myTrihedron == GeomFill_IsGuideACWithContact) ) {
1183 Handle(GeomFill_LocationGuide) Loc;
1184 for (Standard_Integer isec=1; isec<=myLocation->NbLaw(); isec++) {
1185 Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(isec));
1186 Loc->EraseRotation();// remove the rotation
1191 //=======================================================================
1192 //function : BuildHistory
1193 //purpose : Builds history for edges of spine,
1194 // for built bottom shape of sweep,
1195 // for boundary vertices of bottom shape of sweep,
1196 // for boundary profiles
1197 //=======================================================================
1198 void BRepFill_PipeShell::BuildHistory(const BRepFill_Sweep& theSweep)
1200 Handle(TopTools_HArray2OfShape) aFaces = theSweep.SubShape();
1201 Handle(TopTools_HArray2OfShape) aVEdges = theSweep.Sections();
1202 Handle(TopTools_HArray2OfShape) aUEdges = theSweep.InterFaces();
1203 Standard_Integer i = 0, j = 0;
1204 Standard_Boolean bPrevModified = Standard_False;
1206 for(i = 1; i <= mySection->NbLaw(); i++) {
1207 if((!aVEdges->Value(i, 1).IsNull()) && (aVEdges->Value(i, 1).ShapeType() == TopAbs_FACE)) {
1208 bPrevModified = Standard_True;
1213 for(j = myLocation->NbLaw(); j >= 1; j--) {
1214 TopTools_ListOfShape aListOfFace;
1217 for(i = 1; i <= mySection->NbLaw(); i++) {
1218 Standard_Integer lessindex = j + 1;
1219 lessindex = (lessindex > myLocation->NbLaw()) ? 1 : lessindex;
1221 if((!aVEdges->Value(i, lessindex).IsNull()) && (aVEdges->Value(i, lessindex).ShapeType() == TopAbs_FACE)) {
1222 aListOfFace.Append(aVEdges->Value(i, lessindex));
1223 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1225 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1226 UpdateMap(aBottomEdge, aVEdges->Value(i, lessindex), myGenMap);
1231 bPrevModified = Standard_False;
1233 for(i = 1; i <= mySection->NbLaw(); i++) {
1234 if((!aVEdges->Value(i, j).IsNull()) && (aVEdges->Value(i, j).ShapeType() == TopAbs_FACE)) {
1235 aListOfFace.Append(aVEdges->Value(i, j));
1236 bPrevModified = Standard_True;
1238 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1240 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1241 UpdateMap(aBottomEdge, aVEdges->Value(i, j), myGenMap);
1245 if(aFaces->Value(i, j).ShapeType() == TopAbs_FACE) {
1246 aListOfFace.Append(aFaces->Value(i, j));
1247 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1249 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1250 UpdateMap(aBottomEdge, aFaces->Value(i, j), myGenMap);
1255 if(!myGenMap.IsBound(myLocation->Edge(j)))
1256 myGenMap.Bind(myLocation->Edge(j), aListOfFace);
1258 myGenMap.ChangeFind(myLocation->Edge(j)).Append(aListOfFace);
1260 // build history for free booundaries.begin
1261 if(!mySection->IsUClosed()) {
1262 TopoDS_Compound aFaceComp;
1264 aB.MakeCompound(aFaceComp);
1265 TopTools_ListIteratorOfListOfShape anIt(aListOfFace);
1267 for(; anIt.More(); anIt.Next()) {
1268 aB.Add(aFaceComp, anIt.Value());
1270 TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
1271 TopExp::MapShapesAndAncestors(aFaceComp, TopAbs_EDGE, TopAbs_FACE, aMapEF);
1272 Standard_Integer eit = 0;
1274 for(eit = aUEdges->LowerRow(); eit <= aUEdges->UpperRow(); eit++) {
1275 const TopoDS_Shape& aShape = aUEdges->Value(eit, j);
1277 if(aMapEF.Contains(aShape)) {
1278 const TopTools_ListOfShape& aList = aMapEF.FindFromKey(aShape);
1280 if(aList.Extent() < 2) {
1281 UpdateMap(myLocation->Edge(j), aShape, myGenMap);
1283 TopoDS_Shape aGenVertex;
1284 TopTools_IndexedDataMapOfShapeListOfShape aMapVE;
1286 for(i = 1; i <= mySection->NbLaw(); i++) {
1287 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, aVEdges->LowerCol());
1289 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1290 TopExp::MapShapesAndAncestors(aBottomEdge, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
1293 const TopoDS_Shape& aFreeEdge = aUEdges->Value(eit, aUEdges->LowerCol());
1294 TopExp::MapShapesAndAncestors(aFreeEdge, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
1295 TopExp_Explorer anExpV(aFreeEdge, TopAbs_VERTEX);
1297 for(; anExpV.More(); anExpV.Next()) {
1298 if(aMapVE.Contains(anExpV.Current())) {
1299 const TopTools_ListOfShape& aListOfV = aMapVE.FindFromKey(anExpV.Current());
1301 if(aListOfV.Extent() >= 2) {
1302 aGenVertex = anExpV.Current();
1307 if(!aGenVertex.IsNull()) {
1308 UpdateMap(aGenVertex, aShape, myGenMap);
1313 // end for(eit = aUEdges->LowerRow...
1315 // build history for free booundaries.end
1318 // build history for boundary section wires. begin
1320 if(!mySeq.IsEmpty()) {
1321 Standard_Integer iseq;
1324 Standard_Real param = 0., aparmin = RealLast(), aparmax = -RealLast();
1325 Standard_Integer ideb = 1, ifin = mySeq.Length();
1327 for (iseq = 1;iseq <= mySeq.Length(); iseq++) {
1328 Place(mySeq(iseq), aSect, aTrsf, param);
1330 if(param < aparmin) {
1335 if(param > aparmax) {
1341 UpdateMap(mySeq(ideb).Wire(), myFirst, myGenMap);
1342 UpdateMap(mySeq(ifin).Wire(), myLast, myGenMap);
1344 // build history for boundary section wires. end
1347 // ---------------------------------------------------------------------------------
1348 // static function: UpdateMap
1350 // ---------------------------------------------------------------------------------
1351 Standard_Boolean UpdateMap(const TopoDS_Shape& theKey,
1352 const TopoDS_Shape& theValue,
1353 TopTools_DataMapOfShapeListOfShape& theMap) {
1355 if(!theMap.IsBound(theKey)) {
1356 TopTools_ListOfShape thelist;
1357 theMap.Bind(theKey, thelist);
1359 TopTools_ListOfShape& aList = theMap.ChangeFind(theKey);
1360 TopTools_ListIteratorOfListOfShape anIt(aList);
1361 Standard_Boolean found = Standard_False;
1363 for(; anIt.More(); anIt.Next()) {
1364 if(theValue.IsSame(anIt.Value())) {
1365 found = Standard_True;
1371 aList.Append(theValue);
1375 // ---------------------------------------------------------------------------------
1376 // static function: BuildBoundaries
1378 // ---------------------------------------------------------------------------------
1379 Standard_Boolean BuildBoundaries(const BRepFill_Sweep& theSweep,
1380 const Handle(BRepFill_SectionLaw)& theSection,
1381 TopoDS_Shape& theBottom,
1382 TopoDS_Shape& theTop) {
1384 TopoDS_Wire aBottomWire;
1385 TopoDS_Wire aTopWire;
1387 aB.MakeWire(aBottomWire);
1388 aB.MakeWire(aTopWire);
1389 Standard_Boolean bfoundbottom = Standard_False;
1390 Standard_Boolean bfoundtop = Standard_False;
1391 Handle(TopTools_HArray2OfShape) aVEdges = theSweep.Sections();
1392 Standard_Integer i = 0;
1393 Standard_Boolean bAllSame = Standard_True;
1395 for(i = 1; i <= theSection->NbLaw(); i++) {
1396 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, aVEdges->LowerCol());
1398 if(!aBottomEdge.IsNull() && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1399 aB.Add(aBottomWire, aBottomEdge);
1400 bfoundbottom = Standard_True;
1402 const TopoDS_Shape& aTopEdge = aVEdges->Value(i, aVEdges->UpperCol());
1404 if(!aTopEdge.IsNull() && (aTopEdge.ShapeType() == TopAbs_EDGE)) {
1405 aB.Add(aTopWire, aTopEdge);
1406 bfoundtop = Standard_True;
1409 if(!aBottomEdge.IsNull() && !aTopEdge.IsNull() && !aBottomEdge.IsSame(aTopEdge))
1410 bAllSame = Standard_False;
1413 if(theSection->IsUClosed()) {
1414 aBottomWire.Closed(Standard_True);
1415 aTopWire.Closed(Standard_True);
1419 theBottom = aBottomWire;
1426 if(bAllSame && bfoundbottom && bfoundtop)
1429 return bfoundbottom || bfoundtop;