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.
19 #include <BRepFill_PipeShell.ixx>
21 #include <BRep_Builder.hxx>
22 #include <BRep_Tool.hxx>
24 #include <TopTools_SequenceOfShape.hxx>
26 #include <TopoDS_Shell.hxx>
27 #include <TopoDS_Solid.hxx>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopLoc_Location.hxx>
31 #include <BRepLib_MakeEdge.hxx>
32 #include <BRepLib_MakeFace.hxx>
33 #include <BRepAdaptor_HCompCurve.hxx>
34 #include <BRepClass3d_SolidClassifier.hxx>
36 #include <BRepFill.hxx>
37 #include <BRepFill_Sweep.hxx>
38 #include <BRepFill_SectionPlacement.hxx>
39 #include <BRepFill_Edge3DLaw.hxx>
40 #include <BRepFill_ACRLaw.hxx>
41 #include <BRepFill_EdgeOnSurfLaw.hxx>
42 #include <BRepFill_ShapeLaw.hxx>
43 #include <BRepFill_CompatibleWires.hxx>
44 #include <BRepFill_NSections.hxx>
45 #include <BRepFill_DataMapOfShapeHArray2OfShape.hxx>
46 #include <TColStd_HArray1OfReal.hxx>
48 #include <GeomFill_TrihedronLaw.hxx>
49 #include <GeomFill_CorrectedFrenet.hxx>
50 #include <GeomFill_Frenet.hxx>
51 #include <GeomFill_DiscreteTrihedron.hxx>
52 #include <GeomFill_Fixed.hxx>
53 #include <GeomFill_ConstantBiNormal.hxx>
54 #include <GeomFill_SectionLaw.hxx>
55 #include <GeomFill_CurveAndTrihedron.hxx>
56 #include <GeomFill_GuideTrihedronAC.hxx>
57 #include <GeomFill_GuideTrihedronPlan.hxx>
58 #include <GeomFill_LocationGuide.hxx>
61 #include <GeomAdaptor_HCurve.hxx>
63 #include <gp_Trsf.hxx>
66 #include <Precision.hxx>
68 #include <Standard_NotImplemented.hxx>
69 #include <Standard_ConstructionError.hxx>
70 #include <StdFail_NotDone.hxx>
72 #include <BRepBuilderAPI_Copy.hxx>
73 #include <BRepBuilderAPI_Transform.hxx>
75 #include <GProp_GProps.hxx>
76 #include <BRepGProp.hxx>
77 #include <GeomAdaptor_HSurface.hxx>
78 #include <IntCurveSurface_HInter.hxx>
79 #include <IntCurveSurface_IntersectionPoint.hxx>
80 #include <TColgp_HArray1OfPnt2d.hxx>
81 #include <Law_Interpol.hxx>
85 #include <DrawTrSurf.hxx>
87 static Standard_Boolean Affich = 0;
90 #include <TopTools_ListIteratorOfListOfShape.hxx>
91 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
92 #include <TopoDS_Compound.hxx>
94 static Standard_Boolean UpdateMap(const TopoDS_Shape& theKey,
95 const TopoDS_Shape& theValue,
96 TopTools_DataMapOfShapeListOfShape& theMap);
98 static Standard_Boolean BuildBoundaries(const BRepFill_Sweep& theSweep,
99 const Handle(BRepFill_SectionLaw)& theSection,
100 TopoDS_Shape& theBottom,
101 TopoDS_Shape& theTop);
103 //=======================================================================
104 //function : ComputeSection
105 //purpose : Construct an intermediary section
106 //=======================================================================
108 static Standard_Boolean ComputeSection(const TopoDS_Wire& W1,
109 const TopoDS_Wire& W2,
110 const Standard_Real p1,
111 const Standard_Real p2,
114 TColStd_SequenceOfReal SR;
115 TopTools_SequenceOfShape SSh;
122 BRepFill_CompatibleWires CW(SSh);
125 if (!CW.IsDone()) StdFail_NotDone::Raise("Uncompatible wires");
126 GeomFill_SequenceOfTrsf EmptyTrsfs;
127 Handle(BRepFill_NSections) SL = new (BRepFill_NSections) (CW.Shape(),EmptyTrsfs,SR,0.,1.);
128 Standard_Real US = p1/(p1+p2);
130 return Standard_True;
135 //=======================================================================
136 //function : PerformTransition
137 //purpose : Modify a law of location depending on Transition
138 //=======================================================================
140 static void PerformTransition(const BRepFill_TransitionStyle Mode,
141 Handle(BRepFill_LocationLaw)& Loc,
142 const Standard_Real angmin)
145 Loc->DeleteTransform();
146 if (Mode == BRepFill_Modified) Loc->TransformInG0Law();
147 else Loc->TransformInCompatibleLaw(angmin);
150 //=======================================================================
151 //function : PerformPlan
152 //purpose : Construct a plane of filling if exists
153 //=======================================================================
155 static Standard_Boolean PerformPlan(TopoDS_Shape& S)
157 Standard_Boolean isDegen = Standard_True;
158 TopExp_Explorer explo(S, TopAbs_EDGE);
159 for (; explo.More(); explo.Next())
161 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
162 if (!BRep_Tool::Degenerated(anEdge))
163 isDegen = Standard_False;
168 return Standard_True;
171 TopoDS_Wire W = TopoDS::Wire(S);
172 Standard_Boolean Ok = Standard_False;
174 BRepLib_MakeFace mkplan(W, Standard_True);
175 if (mkplan.IsDone()) {
183 //=============================================================================
184 //function : IsSameOriented
185 //purpose : Checks whether aFace is oriented to the same side as aShell or not
186 //=============================================================================
188 static Standard_Boolean IsSameOriented(const TopoDS_Shape& aFace,
189 const TopoDS_Shape& aShell)
191 TopExp_Explorer Explo(aFace, TopAbs_EDGE);
192 TopoDS_Shape anEdge = Explo.Current();
193 TopAbs_Orientation Or1 = anEdge.Orientation();
195 TopTools_IndexedDataMapOfShapeListOfShape EFmap;
196 TopExp::MapShapesAndAncestors( aShell, TopAbs_EDGE, TopAbs_FACE, EFmap );
198 const TopoDS_Shape& AdjacentFace = EFmap.FindFromKey(anEdge).First();
199 TopoDS_Shape theEdge;
200 for (Explo.Init(AdjacentFace, TopAbs_EDGE); Explo.More(); Explo.Next())
202 theEdge = Explo.Current();
203 if (theEdge.IsSame(anEdge))
207 TopAbs_Orientation Or2 = theEdge.Orientation();
209 return Standard_False;
210 return Standard_True;
212 //=======================================================================
213 //function : BRepFill_PipeShell
215 //=======================================================================
216 BRepFill_PipeShell::BRepFill_PipeShell(const TopoDS_Wire& Spine)
218 myForceApproxC1(Standard_False),
219 myIsAutomaticLaw(Standard_False),
220 myTrihedron(GeomFill_IsCorrectedFrenet),
221 myTransition(BRepFill_Modified),
222 myStatus(GeomFill_PipeOk)
224 myLocation.Nullify();
232 // Attention to closed non-declared wire !
233 if (!mySpine.Closed()) {
234 TopoDS_Vertex Vf, Vl;
235 TopExp::Vertices(mySpine, Vf, Vl);
236 if (Vf.IsSame(Vl)) mySpine.Closed(Standard_True);
240 //=======================================================================
242 //purpose : Define a law of Frenet (Correct)
243 //=======================================================================
244 void BRepFill_PipeShell::Set(const Standard_Boolean IsFrenet)
246 Handle(GeomFill_TrihedronLaw) TLaw;
248 myTrihedron = GeomFill_IsFrenet;
249 TLaw = new (GeomFill_Frenet) ();
252 myTrihedron = GeomFill_IsFrenet;
253 TLaw = new (GeomFill_CorrectedFrenet) ();
255 Handle(GeomFill_CurveAndTrihedron) Loc =
256 new (GeomFill_CurveAndTrihedron) (TLaw);
257 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
258 mySection.Nullify(); //It is required to relocalize sections.
261 //=======================================================================
262 //function : SetDiscrete
263 //purpose : Define a law of Discrete Trihedron
264 //=======================================================================
265 void BRepFill_PipeShell::SetDiscrete()
267 Handle(GeomFill_TrihedronLaw) TLaw;
269 myTrihedron = GeomFill_IsDiscreteTrihedron;
270 TLaw = new (GeomFill_DiscreteTrihedron) ();
272 Handle(GeomFill_CurveAndTrihedron) Loc =
273 new (GeomFill_CurveAndTrihedron) (TLaw);
274 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
275 mySection.Nullify(); //It is required to relocalize sections.
278 //=======================================================================
280 //purpose : Define a law Constant
281 //=======================================================================
282 void BRepFill_PipeShell::Set(const gp_Ax2& Axe)
284 myTrihedron = GeomFill_IsFixed;
286 V1.SetXYZ(Axe.Direction().XYZ());
287 V2.SetXYZ(Axe.XDirection().XYZ());
288 Handle(GeomFill_Fixed) TLaw = new (GeomFill_Fixed) (V1, V2);
289 Handle(GeomFill_CurveAndTrihedron) Loc =
290 new (GeomFill_CurveAndTrihedron) (TLaw);
291 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
292 mySection.Nullify(); //It is required to relocalize sections.
295 //=======================================================================
297 //purpose : Construct a law of location of binormal fixed type
298 //=======================================================================
299 void BRepFill_PipeShell::Set(const gp_Dir& BiNormal)
301 myTrihedron = GeomFill_IsConstantNormal;
303 Handle(GeomFill_ConstantBiNormal) TLaw =
304 new (GeomFill_ConstantBiNormal) (BiNormal);
305 Handle(GeomFill_CurveAndTrihedron) Loc =
306 new (GeomFill_CurveAndTrihedron) (TLaw);
307 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
308 mySection.Nullify(); //Il faut relocaliser les sections.
311 //=======================================================================
313 //purpose : Construct a law of location of Darboux type
314 //=======================================================================
315 Standard_Boolean BRepFill_PipeShell::Set(const TopoDS_Shape& SpineSupport)
319 // A special law of location is required
320 Handle(BRepFill_EdgeOnSurfLaw) loc =
321 new (BRepFill_EdgeOnSurfLaw) (mySpine, SpineSupport);
322 B = loc->HasResult();
325 myTrihedron = GeomFill_IsDarboux;
326 mySection.Nullify(); //It is required to relocalize the sections.
331 //=======================================================================
333 //purpose : Defines a lawv with help of a guided contour
334 //=======================================================================
335 void BRepFill_PipeShell::Set(const TopoDS_Wire& AuxiliarySpine,
336 const Standard_Boolean CurvilinearEquivalence,
337 const BRepFill_TypeOfContact KeepContact)
339 // Reorganization of the guide (pb of orientation and origin)
340 TopoDS_Wire TheGuide;
341 TheGuide = AuxiliarySpine;
342 Standard_Boolean SpClose = mySpine.Closed(),
343 GuideClose = AuxiliarySpine.Closed();
345 if (KeepContact == BRepFill_ContactOnBorder)
346 myIsAutomaticLaw = Standard_True;
348 if (!SpClose && !GuideClose) {
349 // Case open reorientation of the guide
350 TopoDS_Wire sp = mySpine;
351 TopTools_SequenceOfShape Seq;
353 Seq.Append(TheGuide);
354 BRepFill_CompatibleWires CW(Seq);
357 if (!CW.IsDone()) StdFail_NotDone::Raise("Uncompatible wires");
358 TheGuide = TopoDS::Wire(CW.Shape().Value(2));
360 else if (GuideClose) {
361 // Case guide closed : Determination of the origin
362 // & reorientation of the guide
366 TopoDS_Vertex Vf, Vl;
368 TopExp::Vertices(mySpine, Vf, Vl);
369 SpOr = BRep_Tool::Pnt(Vf);
370 P = BRep_Tool::Pnt(Vl);
372 SpOr.BaryCenter(0.5, P, 0.5);
376 BRepAdaptor_CompCurve BC(mySpine);
379 BRepFill::SearchOrigin(TheGuide, SpOr, Dir, 100*myTol3d);
384 DBRep::Set("theguide", TheGuide);
386 // transform the guide in a single curve (periodic if posssible)
387 Handle(BRepAdaptor_HCompCurve) Guide =
388 new (BRepAdaptor_HCompCurve) (TheGuide);
389 Guide->ChangeCurve().SetPeriodic(Standard_True);
391 if (CurvilinearEquivalence) { // trihedron by curvilinear reduced abscissa
392 if (KeepContact == BRepFill_Contact ||
393 KeepContact == BRepFill_ContactOnBorder)
394 myTrihedron = GeomFill_IsGuideACWithContact; // with rotation
396 myTrihedron = GeomFill_IsGuideAC; // without rotation
398 Handle(GeomFill_GuideTrihedronAC) TLaw
399 = new (GeomFill_GuideTrihedronAC) (Guide);
400 Handle(GeomFill_LocationGuide) Loc =
401 new (GeomFill_LocationGuide) (TLaw);
402 myLocation = new (BRepFill_ACRLaw) (mySpine, Loc);
404 else {// trihedron by plane
405 if (KeepContact == BRepFill_Contact ||
406 KeepContact == BRepFill_ContactOnBorder)
407 myTrihedron = GeomFill_IsGuidePlanWithContact; // with rotation
409 myTrihedron = GeomFill_IsGuidePlan; // without rotation
411 Handle(GeomFill_GuideTrihedronPlan) TLaw =
412 new (GeomFill_GuideTrihedronPlan) (Guide);
413 Handle(GeomFill_LocationGuide) Loc =
414 new (GeomFill_LocationGuide) (TLaw);
415 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
417 mySection.Nullify(); //It is required to relocalize the sections.
421 //=======================================================================
422 //function : SetMaxDegree
424 //=======================================================================
425 void BRepFill_PipeShell::SetMaxDegree(const Standard_Integer NewMaxDegree)
427 myMaxDegree = NewMaxDegree;
430 //=======================================================================
431 //function : SetMaxSegments
433 //=======================================================================
434 void BRepFill_PipeShell::SetMaxSegments(const Standard_Integer NewMaxSegments)
436 myMaxSegments = NewMaxSegments;
439 //=======================================================================
440 //function : SetForceApproxC1
441 //purpose : Set the flag that indicates attempt to approximate
442 // a C1-continuous surface if a swept surface proved
444 //=======================================================================
445 void BRepFill_PipeShell::SetForceApproxC1(const Standard_Boolean ForceApproxC1)
447 myForceApproxC1 = ForceApproxC1;
450 //=======================================================================
452 //purpose : Add a Section
453 //=======================================================================
454 void BRepFill_PipeShell::Add(const TopoDS_Shape& Profile,
455 const Standard_Boolean WithContact,
456 const Standard_Boolean WithCorrection)
460 Add(Profile, V, WithContact, WithCorrection);
464 //=======================================================================
466 //purpose : Add a Section
467 //=======================================================================
468 void BRepFill_PipeShell::Add(const TopoDS_Shape& Profile,
469 const TopoDS_Vertex& Location,
470 const Standard_Boolean WithContact,
471 const Standard_Boolean WithCorrection)
473 Delete(Profile); // No duplication
474 if (myIsAutomaticLaw)
477 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
478 S.Set(Standard_True);
483 Handle(GeomFill_LocationGuide) Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(1));
484 Handle(TColgp_HArray1OfPnt2d) ParAndRad;
485 Loc->ComputeAutomaticLaw(ParAndRad);
487 //Compuite initial width of section (this will be 1.)
488 GProp_GProps GlobalProps;
489 BRepGProp::LinearProperties(Profile, GlobalProps);
490 gp_Pnt BaryCenter = GlobalProps.CentreOfMass();
492 TopoDS_Face ProfileFace = BRepLib_MakeFace(TopoDS::Wire(Profile), Standard_True); //only plane
493 Handle(Geom_Surface) thePlane = BRep_Tool::Surface(ProfileFace);
494 Handle(GeomAdaptor_HSurface) GAHplane = new GeomAdaptor_HSurface(thePlane);
495 IntCurveSurface_HInter Intersector;
496 Handle(Adaptor3d_HCurve) aHCurve [2];
497 aHCurve[0] = Loc->GetCurve();
498 aHCurve[1] = Loc->Guide();
499 gp_Pnt PointsOnSpines [2];
500 Standard_Integer i, j;
502 for (i = 0; i < 2; i++)
504 Intersector.Perform(aHCurve[i], GAHplane);
505 Standard_Real MinDist = RealLast();
506 for (j = 1; j <= Intersector.NbPoints(); j++)
508 gp_Pnt aPint = Intersector.Point(j).Pnt();
509 Standard_Real aDist = BaryCenter.Distance(aPint);
513 PointsOnSpines[i] = aPint;
518 //Correct <ParAndRad> according to <InitialWidth>
519 Standard_Real InitialWidth = PointsOnSpines[0].Distance(PointsOnSpines[1]);
520 Standard_Integer NbParRad = ParAndRad->Upper();
521 for (i = 1; i <= NbParRad; i++)
523 gp_Pnt2d aParRad = ParAndRad->Value(i);
524 aParRad.SetY( aParRad.Y() / InitialWidth );
525 ParAndRad->SetValue(i, aParRad);
528 myLaw = new Law_Interpol();
530 Standard_Boolean IsPeriodic =
531 (Abs(ParAndRad->Value(1).Y() - ParAndRad->Value(NbParRad).Y()) < Precision::Confusion());
533 (Handle(Law_Interpol)::DownCast(myLaw))->Set(ParAndRad->Array1(), IsPeriodic);
537 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
544 //=======================================================================
546 //purpose : Section + law of homothety
547 //=======================================================================
548 void BRepFill_PipeShell::SetLaw(const TopoDS_Shape& Profile,
549 const Handle(Law_Function)& L,
550 const Standard_Boolean WithContact,
551 const Standard_Boolean WithCorrection)
555 SetLaw( Profile, L, V, WithContact, WithCorrection);
559 //=======================================================================
561 //purpose : Section + Law of homothety
562 //=======================================================================
563 void BRepFill_PipeShell::SetLaw(const TopoDS_Shape& Profile,
564 const Handle(Law_Function)& L,
565 const TopoDS_Vertex& Location,
566 const Standard_Boolean WithContact,
567 const Standard_Boolean WithCorrection)
570 BRepFill_Section S (Profile, Location, WithContact, WithCorrection);
571 S.Set(Standard_True);
578 //=======================================================================
580 //purpose : Delete a section
581 //=======================================================================
582 void BRepFill_PipeShell::Delete(const TopoDS_Shape& Profile)
584 Standard_Boolean isVertex = (Profile.ShapeType() == TopAbs_VERTEX);
586 Standard_Boolean Trouve=Standard_False;
588 for (ii=1; ii<=mySeq.Length() && !Trouve; ii++) {
589 Standard_Boolean found = Standard_False;
590 const TopoDS_Wire& aWire = mySeq.Value(ii).Wire();
593 TopExp_Explorer Explo(aWire, TopAbs_VERTEX);
594 for (; Explo.More(); Explo.Next())
595 if (Profile.IsSame(Explo.Current()))
596 found = Standard_True;
598 else if (Profile.IsSame(aWire))
599 found = Standard_True;
603 Trouve = Standard_True;
608 if (Trouve) mySection.Nullify();
613 //=======================================================================
616 //=======================================================================
617 Standard_Boolean BRepFill_PipeShell::IsReady() const
619 return (mySeq.Length() != 0);
621 //=======================================================================
622 //function : GetStatus
624 //=======================================================================
625 GeomFill_PipeError BRepFill_PipeShell::GetStatus() const
631 //=======================================================================
632 //function : SetTolerance
634 //=======================================================================
635 void BRepFill_PipeShell::SetTolerance(const Standard_Real Tol3d ,
636 const Standard_Real BoundTol,
637 const Standard_Real TolAngular)
640 myBoundTol = BoundTol;
641 myTolAngular = TolAngular;
644 //=======================================================================
645 //function : SetTransition
646 //purpose : Defines the mode of processing of corners
647 //=======================================================================
648 void BRepFill_PipeShell::SetTransition(const BRepFill_TransitionStyle Mode,
649 const Standard_Real Angmin,
650 const Standard_Real Angmax)
652 if (myTransition != Mode)
653 mySection.Nullify(); //It is required to relocalize the sections.
659 //=======================================================================
660 //function : Simulate
661 //purpose : Calculate N Sections
662 //=======================================================================
663 void BRepFill_PipeShell::Simulate(const Standard_Integer N,
664 TopTools_ListOfShape& List)
670 Standard_Real First, Last, Length, Delta, U,
672 Standard_Integer ii, NbL = myLocation->NbLaw();
673 Standard_Boolean Finis=Standard_False;
676 // Calculate the parameters of digitalization
677 mySection->Law(1)->GetDomain(FirstS, Last);
678 DeltaS = Last - FirstS;
679 myLocation->CurvilinearBounds(NbL,First, Length);
681 if (N>1) Delta /= (N-1);
683 myLocation->CurvilinearBounds(1,First, Last); // Initiation of Last
684 for (U=0.0, ii=1; !Finis ; U+=Delta) {
687 Finis = Standard_True;
690 if (ii < NbL) myLocation->CurvilinearBounds(NbL,First, Last);
691 if (U > Last) U = (Last+First)/2; // The edge is not skipped
694 US = FirstS + (U/Length)*DeltaS;
695 // Calcul d'une section
696 mySection->D0(US, W);
697 myLocation->D0(U, W);
702 //=======================================================================
704 //purpose : Construct the Shell and the history
705 //=======================================================================
706 Standard_Boolean BRepFill_PipeShell::Build()
709 Standard_Real FirstS, LastS;
713 if (myStatus != GeomFill_PipeOk) {
717 myShape = Sh; // Nullify
718 return Standard_False;
721 // 2) Calculate myFirst and myLast
722 mySection->Law(1)->GetDomain(FirstS, LastS);
723 mySection->D0(FirstS, myFirst);
724 myLocation->D0(0, myFirst);
725 if (mySection->IsVClosed() && myLocation->IsClosed()) {
726 if (myLocation->IsG1(0)>=0)
734 Standard_Real Length;
735 myLocation->CurvilinearBounds(myLocation->NbLaw(),
737 mySection->D0(LastS, myLast);
738 myLocation->D0(Length, myLast);
739 // eap 5 Jun 2002 occ332, myLast and myFirst must not share one TShape,
740 // tolerances of shapes built on them may be quite different
741 if (myFirst.IsPartner( myLast )) {
742 BRepBuilderAPI_Copy copy(myLast);
744 myLast = copy.Shape();
746 // eap 5 Jun 2002 occ332, end modif
750 DBRep::Set("PipeFirst", myFirst);
751 DBRep::Set("PipeLast", myLast);
756 BRepFill_Sweep MkSw(mySection, myLocation, Standard_True);
757 MkSw.SetTolerance(myTol3d, myBoundTol, 1.e-5, myTolAngular);
758 MkSw.SetAngularControl(angmin, angmax);
759 MkSw.SetForceApproxC1(myForceApproxC1);
760 MkSw.SetBounds(TopoDS::Wire(myFirst),
761 TopoDS::Wire(myLast));
762 GeomAbs_Shape theContinuity = GeomAbs_C2;
763 if (myTrihedron == GeomFill_IsDiscreteTrihedron)
764 theContinuity = GeomAbs_C0;
765 TopTools_MapOfShape Dummy;
766 BRepFill_DataMapOfShapeHArray2OfShape Dummy2;
767 BRepFill_DataMapOfShapeHArray2OfShape Dummy3;
768 MkSw.Build(Dummy, Dummy2, Dummy3, myTransition, theContinuity);
770 myStatus = myLocation->GetStatus();
771 Ok = (MkSw.IsDone() && (myStatus == GeomFill_PipeOk));
774 myShape = MkSw.Shape();
776 TopoDS_Shape aBottomWire = myFirst;
777 TopoDS_Shape aTopWire = myLast;
779 if(BuildBoundaries(MkSw, mySection, aBottomWire, aTopWire)) {
780 myFirst = aBottomWire;
784 if (mySection->IsUClosed())
786 TopExp_Explorer explo;
787 Standard_Boolean DegenFirst = Standard_True, DegenLast = Standard_True;
789 for (explo.Init(myFirst, TopAbs_EDGE); explo.More(); explo.Next())
791 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
792 DegenFirst = DegenFirst && BRep_Tool::Degenerated(anEdge);
795 for (explo.Init(myLast, TopAbs_EDGE); explo.More(); explo.Next())
797 const TopoDS_Edge& anEdge = TopoDS::Edge(explo.Current());
798 DegenLast = DegenLast && BRep_Tool::Degenerated(anEdge);
801 if (DegenFirst && DegenLast)
802 myShape.Closed(Standard_True);
811 myShape = Sh; // Nullify
812 if (myStatus == GeomFill_PipeOk) myStatus = GeomFill_PipeNotOk;
817 //=======================================================================
818 //function : MakeSolid
820 //=======================================================================
821 Standard_Boolean BRepFill_PipeShell::MakeSolid()
823 if (myShape.IsNull())
824 StdFail_NotDone::Raise("PipeShell is not built");
825 Standard_Boolean B = myShape.Closed();
830 if(!myFirst.IsNull() && !myLast.IsNull()) {
831 B = (myFirst.Closed() && myLast.Closed());
834 // It is necessary to block the extremities
835 B = PerformPlan(myFirst);
837 B = PerformPlan(myLast);
839 if (!myFirst.IsNull() && !IsSameOriented( myFirst, myShape ))
841 if (!myLast.IsNull() && !IsSameOriented( myLast, myShape ))
844 if (!myFirst.IsNull())
845 BS.Add(myShape, TopoDS::Face(myFirst));
846 if (!myLast.IsNull())
847 BS.Add(myShape, TopoDS::Face(myLast));
849 myShape.Closed(Standard_True);
858 BS.Add(solid,TopoDS::Shell(myShape));
859 BRepClass3d_SolidClassifier SC(solid);
860 SC.PerformInfinitePoint(Precision::Confusion());
861 if ( SC.State() == TopAbs_IN) {
864 BS.Add(solid,TopoDS::Shell(myShape));
867 myShape.Closed(Standard_True);
872 //=======================================================================
874 //purpose : Return the result
875 //=======================================================================
876 const TopoDS_Shape& BRepFill_PipeShell::Shape() const
881 //=======================================================================
882 //function : FirstShape
883 //purpose : Return the start section
884 //=======================================================================
885 const TopoDS_Shape& BRepFill_PipeShell::FirstShape() const
890 //=======================================================================
891 //function : LastShape
892 //purpose : Return the end section
893 //=======================================================================
894 const TopoDS_Shape& BRepFill_PipeShell::LastShape() const
899 //=======================================================================
900 //function : Generated
902 //=======================================================================
903 // void BRepFill_PipeShell::Generated(const TopoDS_Shape& ,
904 // TopTools_ListOfShape& )
905 void BRepFill_PipeShell::Generated(const TopoDS_Shape& theShape,
906 TopTools_ListOfShape& theList)
908 // Standard_NotImplemented::Raise("Generated:Pas Fait");
911 if(myGenMap.IsBound(theShape)) {
912 theList = myGenMap.Find(theShape);
916 //=======================================================================
918 //purpose : - Check that everything is ready
919 // - Construct the law of section
920 // - Construct the law of location if required
921 // - Calculate First & Last
922 //=======================================================================
923 void BRepFill_PipeShell::Prepare()
926 if (!IsReady()) StdFail_NotDone::Raise("PipeShell");
927 if (!myLocation.IsNull() && !mySection.IsNull()) return; // It is ready
929 //Check set of section for right configuration of punctual sections
931 TopoDS_Iterator iter;;
932 for (i = 2; i <= mySeq.Length()-1; i++)
934 Standard_Boolean wdeg = Standard_True;
935 for (iter.Initialize(mySeq(i).Wire()); iter.More(); iter.Next())
937 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
938 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
941 Standard_Failure::Raise("Wrong usage of punctual sections");
943 if (mySeq.Length() <= 2)
945 Standard_Boolean wdeg = Standard_True;
946 for (i = 1; i <= mySeq.Length(); i++)
947 for (iter.Initialize(mySeq(i).Wire()); iter.More(); iter.Next())
949 const TopoDS_Edge& anEdge = TopoDS::Edge(iter.Value());
950 wdeg = wdeg && (BRep_Tool::Degenerated(anEdge));
953 Standard_Failure::Raise("Wrong usage of punctual sections");
956 // Construction of the law of location
957 if(myLocation.IsNull())
961 case GeomFill_IsCorrectedFrenet :
963 Handle(GeomFill_TrihedronLaw) TLaw =
964 new (GeomFill_CorrectedFrenet) ();
965 Handle(GeomFill_CurveAndTrihedron) Loc =
966 new (GeomFill_CurveAndTrihedron) (TLaw);
967 myLocation = new (BRepFill_Edge3DLaw) (mySpine, Loc);
972 Standard_ConstructionError::Raise("PipeShell");
977 //Transformation of the law (Transition Management)
978 PerformTransition(myTransition, myLocation, angmin);
981 // Construction of the section law
982 if (mySeq.Length() == 1) {
985 Place(mySeq(1), theSect, aTrsf, p1);
986 TopoDS_Wire aLocalShape = theSect;
987 if (mySeq(1).IsLaw())
988 mySection = new BRepFill_ShapeLaw(aLocalShape, myLaw);
989 // mySection = new (BRepFill_ShapeLaw) (TopoDS_Wire(theSect), myLaw);
991 mySection = new BRepFill_ShapeLaw(aLocalShape);
992 // mySection = new (BRepFill_ShapeLaw) (TopoDS::Wire(theSect));
996 TColStd_SequenceOfReal Param;
997 TopTools_SequenceOfShape WSeq;
998 GeomFill_SequenceOfTrsf Transformations;
1001 Standard_Integer NbL = myLocation->NbLaw();
1003 Standard_Real V1, V2, param;
1004 myLocation->CurvilinearBounds(NbL, V1, V2);
1006 Standard_Integer ideb = 0, ifin = 0;
1007 // for (Standard_Integer iseq=1;iseq<=mySeq.Length();iseq++) {
1008 Standard_Integer iseq;
1009 for (iseq=1;iseq<=mySeq.Length();iseq++) {
1010 Place(mySeq(iseq), theSect, aTrsf, param);
1011 Param.Append(param);
1012 WSeq.Append(theSect);
1013 // WSeq.Append(TopoDS::Wire(theSect));
1014 Transformations.Append(aTrsf);
1015 if (param==V1) ideb = iseq;
1016 if (param==V2) ifin = iseq;
1020 // looping sections ?
1021 if (myLocation->IsClosed()) {
1023 // place the initial section at the final position
1025 WSeq.Append(WSeq(ideb));
1028 // place the final section at the initial position
1030 WSeq.Append(WSeq(ifin));
1033 // it is necessary to find a medium section to impose by V1 and by V2
1034 Standard_Real pmin = Param.Value(1), pmax = Param.Value(1);
1035 TopoDS_Wire Wmin = TopoDS::Wire(WSeq.Value(1)), Wmax;
1036 for (iseq=2;iseq<=WSeq.Length();iseq++) {
1037 if (Param.Value(iseq)<pmin) {
1038 pmin = Param.Value(iseq);
1039 Wmin = TopoDS::Wire(WSeq.Value(iseq));
1041 if (Param.Value(iseq)>pmax) {
1042 pmax = Param.Value(iseq);
1043 Wmax = TopoDS::Wire(WSeq.Value(iseq));
1046 // medium section between Wmin and Wmax
1048 Standard_Real dmin = Abs(pmin-V1);
1049 Standard_Real dmax = Abs(pmax-V2);
1050 if (ComputeSection(Wmin,Wmax,dmin,dmax,Wres)) {
1051 // impose section Wres at the beginning and the end
1062 // parse sections by increasing parameter
1063 Standard_Boolean play_again = Standard_True;
1064 while (play_again) {
1065 play_again = Standard_False;
1066 for (iseq=1;iseq<=WSeq.Length();iseq++) {
1067 for (Standard_Integer jseq=iseq+1;jseq<=WSeq.Length();jseq++) {
1068 if (Param.Value(iseq)>Param.Value(jseq)) {
1069 Param.Exchange(iseq,jseq);
1070 WSeq.Exchange(iseq,jseq);
1071 play_again = Standard_True;
1079 char* name = new char[100];
1080 Standard_Integer NBSECT = 0;
1081 for (Standard_Integer i=1;i<=WSeq.Length();i++) {
1083 sprintf(name,"WSeq_%d",NBSECT);
1084 DBRep::Set(name,TopoDS::Wire(WSeq.Value(i)));
1091 // Calculate work sections
1092 TopTools_SequenceOfShape WorkingSections;
1093 WorkingSections.Clear();
1094 TopTools_DataMapOfShapeListOfShape WorkingMap;
1096 BRepFill_CompatibleWires Georges(WSeq);
1097 Georges.SetPercent(0.1);
1098 Georges.Perform(Standard_False);
1099 if (Georges.IsDone()) {
1100 WorkingSections = Georges.Shape();
1101 WorkingMap = Georges.Generated();
1104 Standard_ConstructionError::Raise("PipeShell : uncompatible wires");
1106 mySection = new (BRepFill_NSections) (WorkingSections,Transformations,Param,V1,V2);
1110 // modify the law of location if contact
1111 if ( (myTrihedron == GeomFill_IsGuidePlanWithContact)
1112 || (myTrihedron == GeomFill_IsGuideACWithContact) ) {
1113 Standard_Real fs, f, l, Delta, Length;
1114 Handle(GeomFill_LocationGuide) Loc;
1115 Handle(GeomFill_SectionLaw) Sec = mySection->ConcatenedLaw();
1116 myLocation->CurvilinearBounds(myLocation->NbLaw(), f, Length);
1117 Sec->GetDomain(fs,l);
1118 Delta = (l-fs)/Length;
1120 Standard_Real angle, old_angle = 0;
1121 for (Standard_Integer ipath=1; ipath<=myLocation->NbLaw(); ipath++) {
1122 myLocation->CurvilinearBounds(ipath, f, l);
1123 Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(ipath));
1124 Loc->Set(Sec, Standard_True, fs + f*Delta, fs + l*Delta,
1125 old_angle, angle); // force the rotation
1130 myStatus = myLocation->GetStatus();
1133 //=======================================================================
1135 //purpose : Implement a Section in the local refernce frame
1136 // and return its parameter on the trajectory
1137 //=======================================================================
1138 void BRepFill_PipeShell::Place(const BRepFill_Section& Sec,
1141 Standard_Real& param)
1143 BRepFill_SectionPlacement Place(myLocation,
1147 Sec.WithCorrection());
1148 TopoDS_Wire TmpWire = Sec.Wire();
1149 aTrsf = Place.Transformation();
1150 //TopLoc_Location Loc2(Place.Transformation()), Loc1;
1151 //Loc1 = TmpWire.Location();
1152 //W.Location(Loc2.Multiplied(Loc1));
1153 //Transform the copy
1154 W = TopoDS::Wire(BRepBuilderAPI_Transform(TmpWire, aTrsf, Standard_True));
1155 ////////////////////////////////////
1156 param = Place.AbscissaOnPath();
1160 //=======================================================================
1161 //function : ResetLoc
1162 //purpose : Remove references to the sections in the laws of location
1163 //=======================================================================
1164 void BRepFill_PipeShell::ResetLoc()
1166 if ( (myTrihedron == GeomFill_IsGuidePlanWithContact)
1167 || (myTrihedron == GeomFill_IsGuideACWithContact) ) {
1168 Handle(GeomFill_LocationGuide) Loc;
1169 for (Standard_Integer isec=1; isec<=myLocation->NbLaw(); isec++) {
1170 Loc = Handle(GeomFill_LocationGuide)::DownCast(myLocation->Law(isec));
1171 Loc->EraseRotation();// remove the rotation
1176 //=======================================================================
1177 //function : BuildHistory
1178 //purpose : Builds history for edges of spine,
1179 // for built bottom shape of sweep,
1180 // for boundary vertices of bottom shape of sweep,
1181 // for boundary profiles
1182 //=======================================================================
1183 void BRepFill_PipeShell::BuildHistory(const BRepFill_Sweep& theSweep)
1185 Handle(TopTools_HArray2OfShape) aFaces = theSweep.SubShape();
1186 Handle(TopTools_HArray2OfShape) aVEdges = theSweep.Sections();
1187 Handle(TopTools_HArray2OfShape) aUEdges = theSweep.InterFaces();
1188 Standard_Integer i = 0, j = 0;
1189 Standard_Boolean bPrevModified = Standard_False;
1191 for(i = 1; i <= mySection->NbLaw(); i++) {
1192 if((!aVEdges->Value(i, 1).IsNull()) && (aVEdges->Value(i, 1).ShapeType() == TopAbs_FACE)) {
1193 bPrevModified = Standard_True;
1198 for(j = myLocation->NbLaw(); j >= 1; j--) {
1199 TopTools_ListOfShape aListOfFace;
1202 for(i = 1; i <= mySection->NbLaw(); i++) {
1203 Standard_Integer lessindex = j + 1;
1204 lessindex = (lessindex > myLocation->NbLaw()) ? 1 : lessindex;
1206 if((!aVEdges->Value(i, lessindex).IsNull()) && (aVEdges->Value(i, lessindex).ShapeType() == TopAbs_FACE)) {
1207 aListOfFace.Append(aVEdges->Value(i, lessindex));
1208 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1210 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1211 UpdateMap(aBottomEdge, aVEdges->Value(i, lessindex), myGenMap);
1216 bPrevModified = Standard_False;
1218 for(i = 1; i <= mySection->NbLaw(); i++) {
1219 if((!aVEdges->Value(i, j).IsNull()) && (aVEdges->Value(i, j).ShapeType() == TopAbs_FACE)) {
1220 aListOfFace.Append(aVEdges->Value(i, j));
1221 bPrevModified = Standard_True;
1223 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1225 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1226 UpdateMap(aBottomEdge, aVEdges->Value(i, j), myGenMap);
1230 if(aFaces->Value(i, j).ShapeType() == TopAbs_FACE) {
1231 aListOfFace.Append(aFaces->Value(i, j));
1232 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, 1);
1234 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1235 UpdateMap(aBottomEdge, aFaces->Value(i, j), myGenMap);
1240 if(!myGenMap.IsBound(myLocation->Edge(j)))
1241 myGenMap.Bind(myLocation->Edge(j), aListOfFace);
1243 myGenMap.ChangeFind(myLocation->Edge(j)).Append(aListOfFace);
1245 // build history for free booundaries.begin
1246 if(!mySection->IsUClosed()) {
1247 TopoDS_Compound aFaceComp;
1249 aB.MakeCompound(aFaceComp);
1250 TopTools_ListIteratorOfListOfShape anIt(aListOfFace);
1252 for(; anIt.More(); anIt.Next()) {
1253 aB.Add(aFaceComp, anIt.Value());
1255 TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
1256 TopExp::MapShapesAndAncestors(aFaceComp, TopAbs_EDGE, TopAbs_FACE, aMapEF);
1257 Standard_Integer eit = 0;
1259 for(eit = aUEdges->LowerRow(); eit <= aUEdges->UpperRow(); eit++) {
1260 const TopoDS_Shape& aShape = aUEdges->Value(eit, j);
1262 if(aMapEF.Contains(aShape)) {
1263 const TopTools_ListOfShape& aList = aMapEF.FindFromKey(aShape);
1265 if(aList.Extent() < 2) {
1266 UpdateMap(myLocation->Edge(j), aShape, myGenMap);
1268 TopoDS_Shape aGenVertex;
1269 TopTools_IndexedDataMapOfShapeListOfShape aMapVE;
1271 for(i = 1; i <= mySection->NbLaw(); i++) {
1272 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, aVEdges->LowerCol());
1274 if((!aBottomEdge.IsNull()) && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1275 TopExp::MapShapesAndAncestors(aBottomEdge, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
1278 const TopoDS_Shape& aFreeEdge = aUEdges->Value(eit, aUEdges->LowerCol());
1279 TopExp::MapShapesAndAncestors(aFreeEdge, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
1280 TopExp_Explorer anExpV(aFreeEdge, TopAbs_VERTEX);
1282 for(; anExpV.More(); anExpV.Next()) {
1283 if(aMapVE.Contains(anExpV.Current())) {
1284 const TopTools_ListOfShape& aListOfV = aMapVE.FindFromKey(anExpV.Current());
1286 if(aListOfV.Extent() >= 2) {
1287 aGenVertex = anExpV.Current();
1292 if(!aGenVertex.IsNull()) {
1293 UpdateMap(aGenVertex, aShape, myGenMap);
1298 // end for(eit = aUEdges->LowerRow...
1300 // build history for free booundaries.end
1303 // build history for boundary section wires. begin
1305 if(!mySeq.IsEmpty()) {
1306 Standard_Integer iseq;
1309 Standard_Real param = 0., aparmin = RealLast(), aparmax = -RealLast();
1310 Standard_Integer ideb = 1, ifin = mySeq.Length();
1312 for (iseq = 1;iseq <= mySeq.Length(); iseq++) {
1313 Place(mySeq(iseq), aSect, aTrsf, param);
1315 if(param < aparmin) {
1320 if(param > aparmax) {
1326 UpdateMap(mySeq(ideb).Wire(), myFirst, myGenMap);
1327 UpdateMap(mySeq(ifin).Wire(), myLast, myGenMap);
1329 // build history for boundary section wires. end
1332 // ---------------------------------------------------------------------------------
1333 // static function: UpdateMap
1335 // ---------------------------------------------------------------------------------
1336 Standard_Boolean UpdateMap(const TopoDS_Shape& theKey,
1337 const TopoDS_Shape& theValue,
1338 TopTools_DataMapOfShapeListOfShape& theMap) {
1340 if(!theMap.IsBound(theKey)) {
1341 TopTools_ListOfShape thelist;
1342 theMap.Bind(theKey, thelist);
1344 TopTools_ListOfShape& aList = theMap.ChangeFind(theKey);
1345 TopTools_ListIteratorOfListOfShape anIt(aList);
1346 Standard_Boolean found = Standard_False;
1348 for(; anIt.More(); anIt.Next()) {
1349 if(theValue.IsSame(anIt.Value())) {
1350 found = Standard_True;
1356 aList.Append(theValue);
1360 // ---------------------------------------------------------------------------------
1361 // static function: BuildBoundaries
1363 // ---------------------------------------------------------------------------------
1364 Standard_Boolean BuildBoundaries(const BRepFill_Sweep& theSweep,
1365 const Handle(BRepFill_SectionLaw)& theSection,
1366 TopoDS_Shape& theBottom,
1367 TopoDS_Shape& theTop) {
1369 TopoDS_Wire aBottomWire;
1370 TopoDS_Wire aTopWire;
1372 aB.MakeWire(aBottomWire);
1373 aB.MakeWire(aTopWire);
1374 Standard_Boolean bfoundbottom = Standard_False;
1375 Standard_Boolean bfoundtop = Standard_False;
1376 Handle(TopTools_HArray2OfShape) aVEdges = theSweep.Sections();
1377 Standard_Integer i = 0;
1378 Standard_Boolean bAllSame = Standard_True;
1380 for(i = 1; i <= theSection->NbLaw(); i++) {
1381 const TopoDS_Shape& aBottomEdge = aVEdges->Value(i, aVEdges->LowerCol());
1383 if(!aBottomEdge.IsNull() && (aBottomEdge.ShapeType() == TopAbs_EDGE)) {
1384 aB.Add(aBottomWire, aBottomEdge);
1385 bfoundbottom = Standard_True;
1387 const TopoDS_Shape& aTopEdge = aVEdges->Value(i, aVEdges->UpperCol());
1389 if(!aTopEdge.IsNull() && (aTopEdge.ShapeType() == TopAbs_EDGE)) {
1390 aB.Add(aTopWire, aTopEdge);
1391 bfoundtop = Standard_True;
1394 if(!aBottomEdge.IsNull() && !aTopEdge.IsNull() && !aBottomEdge.IsSame(aTopEdge))
1395 bAllSame = Standard_False;
1398 if(theSection->IsUClosed()) {
1399 aBottomWire.Closed(Standard_True);
1400 aTopWire.Closed(Standard_True);
1404 theBottom = aBottomWire;
1411 if(bAllSame && bfoundbottom && bfoundtop)
1414 return bfoundbottom || bfoundtop;