1 // Created on: 1994-06-07
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-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 <Adaptor3d_CurveOnSurface.hxx>
19 #include <BRep_Builder.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepBuilderAPI_Copy.hxx>
22 #include <BRepBuilderAPI_Transform.hxx>
23 #include <BRepClass3d_SolidClassifier.hxx>
24 #include <BRepFill_Edge3DLaw.hxx>
25 #include <BRepFill_LocationLaw.hxx>
26 #include <BRepFill_Pipe.hxx>
27 #include <BRepFill_SectionPlacement.hxx>
28 #include <BRepFill_ShapeLaw.hxx>
29 #include <BRepFill_Sweep.hxx>
30 #include <BRepLib.hxx>
31 #include <BRepLib_MakeVertex.hxx>
32 #include <BRepTools_Substitution.hxx>
33 #include <Geom2dAdaptor_HCurve.hxx>
34 #include <Geom_BSplineCurve.hxx>
35 #include <Geom_OffsetCurve.hxx>
36 #include <Geom_TrimmedCurve.hxx>
37 #include <GeomAbs_Shape.hxx>
38 #include <GeomAdaptor_HSurface.hxx>
39 #include <GeomFill_CorrectedFrenet.hxx>
40 #include <GeomFill_CurveAndTrihedron.hxx>
41 #include <GeomFill_DiscreteTrihedron.hxx>
42 #include <GeomFill_Frenet.hxx>
44 #include <Precision.hxx>
45 #include <ShapeUpgrade_RemoveLocations.hxx>
46 #include <Standard_DomainError.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_NotImplemented.hxx>
49 #include <StdFail_NotDone.hxx>
50 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
51 #include <TColStd_DataMapOfIntegerInteger.hxx>
52 #include <TopAbs_ShapeEnum.hxx>
55 #include <TopoDS_Compound.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Iterator.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Shell.hxx>
61 #include <TopoDS_Solid.hxx>
62 #include <TopoDS_Vertex.hxx>
63 #include <TopoDS_Wire.hxx>
64 #include <TopTools_DataMapOfShapeInteger.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <TopTools_SequenceOfShape.hxx>
70 static Standard_Boolean Affich = 0;
73 static void ReverseModifiedEdges(TopoDS_Shape& aShape,
74 TopTools_MapOfShape& Emap)
76 TopExp_Explorer Explo(aShape, TopAbs_FACE);
79 for (; Explo.More(); Explo.Next())
81 TopoDS_Shape aFace = Explo.Current();
82 TopoDS_Iterator itf(aFace);
83 for (; itf.More(); itf.Next())
85 TopoDS_Shape aWire = itf.Value();
86 TopTools_ListOfShape Ledges;
87 TopoDS_Iterator itw(aWire);
88 for (; itw.More(); itw.Next())
89 Ledges.Append(itw.Value());
91 aWire.Free(Standard_True);
92 TopTools_ListIteratorOfListOfShape itl(Ledges);
93 for (; itl.More(); itl.Next())
94 BB.Remove(aWire, itl.Value());
96 for (itl.Initialize(Ledges); itl.More(); itl.Next())
98 TopoDS_Shape anEdge = itl.Value();
99 if (Emap.Contains(anEdge))
101 BB.Add(aWire, anEdge);
107 static void UpdateTolFromTopOrBottomPCurve(const TopoDS_Face& aFace,
110 Standard_Real fpar, lpar;
111 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(anEdge, aFace, fpar, lpar);
112 if (aPCurve.IsNull())
115 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
119 Handle(Geom2dAdaptor_HCurve) GAHC2d = new Geom2dAdaptor_HCurve(aPCurve, fpar, lpar);
120 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
121 Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(aSurf);
122 Adaptor3d_CurveOnSurface ConS(GAHC2d, GAHS);
124 Standard_Real Tol = BRep_Tool::Tolerance(anEdge);
125 Standard_Real InitTol = Tol;
126 Standard_Real TolTol = Tol*Tol;
127 const Standard_Integer NCONTROL = 22;
128 Standard_Real delta = (lpar - fpar)/NCONTROL;
129 for (Standard_Integer i = 0; i <= NCONTROL; i++)
131 Standard_Real par = fpar + i*delta;
132 gp_Pnt pnt = aCurve->Value(par);
133 gp_Pnt prj = ConS.Value(par);
134 Standard_Real sqdist = pnt.SquareDistance(prj);
138 Tol = 1.00005 * Sqrt(TolTol);
142 BB.UpdateEdge(anEdge, Tol);
143 TopoDS_Iterator itv(anEdge);
144 for (; itv.More(); itv.Next())
146 TopoDS_Vertex aVertex = TopoDS::Vertex(itv.Value());
147 BB.UpdateVertex(aVertex, Tol);
152 //=======================================================================
153 //function : BRepFill_Pipe
155 //=======================================================================
157 BRepFill_Pipe::BRepFill_Pipe()
161 myContinuity = GeomAbs_C2;
162 myMode = GeomFill_IsCorrectedFrenet;
163 myForceApproxC1 = Standard_False;
165 myCurIndexOfSectionEdge = 1;
169 //=======================================================================
170 //function : BRepFill_Pipe
172 //=======================================================================
174 BRepFill_Pipe::BRepFill_Pipe(const TopoDS_Wire& Spine,
175 const TopoDS_Shape& Profile,
176 const GeomFill_Trihedron aMode,
177 const Standard_Boolean ForceApproxC1,
178 const Standard_Boolean KPart)
184 myMode = GeomFill_IsCorrectedFrenet;
185 if (aMode == GeomFill_IsFrenet ||
186 aMode == GeomFill_IsCorrectedFrenet ||
187 aMode == GeomFill_IsDiscreteTrihedron)
190 myContinuity = GeomAbs_C2;
191 if (myMode == GeomFill_IsDiscreteTrihedron)
192 myContinuity = GeomAbs_C0;
194 myForceApproxC1 = ForceApproxC1;
196 myCurIndexOfSectionEdge = 1;
198 Perform(Spine, Profile, KPart);
202 //=======================================================================
205 //=======================================================================
207 void BRepFill_Pipe::Perform(const TopoDS_Wire& Spine,
208 const TopoDS_Shape& Profile,
209 const Standard_Boolean /*KPart*/)
212 mySections.Nullify();
221 BRepTools_WireExplorer wexp;
222 TopoDS_Shape TheProf;
224 Handle(GeomFill_TrihedronLaw) TLaw;
227 case GeomFill_IsFrenet:
228 TLaw = new GeomFill_Frenet();
230 case GeomFill_IsCorrectedFrenet:
231 TLaw = new GeomFill_CorrectedFrenet();
233 case GeomFill_IsDiscreteTrihedron:
234 TLaw = new GeomFill_DiscreteTrihedron();
239 Handle(GeomFill_CurveAndTrihedron) Loc =
240 new (GeomFill_CurveAndTrihedron) (TLaw);
241 myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc);
242 if (myLoc->NbLaw() == 0) {
243 return; // Degenerated case
245 myLoc->TransformInG0Law(); // Set into continuity
247 BRepFill_SectionPlacement Place(myLoc, Profile);
248 myTrsf = Place.Transformation();
250 TopLoc_Location Loc2(myTrsf), Loc1;
251 Loc1 = Profile.Location();
254 TheProf.Location(Loc2.Multiplied(Loc1));
256 // Construct First && Last Shape
257 Handle(GeomFill_LocationLaw) law;
262 Standard_Real first, last;
263 myLoc->Law(1)->GetDomain(first, last);
264 myLoc->Law(1)->D0(first, M, V);
265 fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
266 M(2,1), M(2,2), M(2,3), V.Y(),
267 M(3,1), M(3,2), M(3,3), V.Z());
269 fila.Multiply(myTrsf);
270 TopLoc_Location LocFirst(fila);
272 if ( ! LocFirst.IsIdentity()) {
273 //myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
274 myFirst = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
277 ShapeUpgrade_RemoveLocations RemLoc;
278 RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
279 RemLoc.Remove(myFirst);
280 myFirst = RemLoc.GetResult();
282 myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
283 myLoc->Law(myLoc->NbLaw())->D0(last,M, V);
284 // try { // Not good, but there are no other means to test SetValues
285 fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
286 M(2,1), M(2,2), M(2,3), V.Y(),
287 M(3,1), M(3,2), M(3,3), V.Z());
288 fila.Multiply(myTrsf);
289 TopLoc_Location LocLast(fila);
290 if (! myLoc->IsClosed() || LocFirst != LocLast) {
292 if ( ! LocLast.IsIdentity()) {
293 //myLast.Location(LocLast.Multiplied(myProfile.Location()) );
294 myLast = BRepBuilderAPI_Transform(myProfile, fila, Standard_True); //copy
301 RemLoc.Remove(myLast);
302 myLast = RemLoc.GetResult();
306 DBRep::Set("theprof", TheProf);
307 DBRep::Set("thefirst", myFirst);
308 DBRep::Set("thelast" , myLast);
312 myShape = MakeShape(TheProf, myFirst, myLast);
316 //=======================================================================
319 //=======================================================================
321 const TopoDS_Shape& BRepFill_Pipe::Spine() const
326 //=======================================================================
329 //=======================================================================
331 const TopoDS_Shape& BRepFill_Pipe::Profile() const
336 //=======================================================================
339 //=======================================================================
341 const TopoDS_Shape& BRepFill_Pipe::Shape() const
346 //=======================================================================
347 //function : ErrorOnSurface
349 //=======================================================================
351 Standard_Real BRepFill_Pipe::ErrorOnSurface() const
353 return myErrorOnSurf;
357 //=======================================================================
358 //function : FirstShape
360 //=======================================================================
362 const TopoDS_Shape& BRepFill_Pipe::FirstShape() const
368 //=======================================================================
369 //function : LastShape
371 //=======================================================================
373 const TopoDS_Shape& BRepFill_Pipe::LastShape() const
379 //=======================================================================
382 //=======================================================================
384 TopoDS_Face BRepFill_Pipe::Face(const TopoDS_Edge& ESpine,
385 const TopoDS_Edge& EProfile)
389 if ( BRep_Tool::Degenerated(EProfile))
392 Standard_Integer ii, ispin = 0, iprof = 0, count = 0;
394 // *************************************************
395 // Search if EProfile is an edge of myProfile
396 // *************************************************
397 iprof = FindEdge(myProfile, EProfile, count);
399 if (!iprof) Standard_DomainError::Raise(
400 "BRepFill_Pipe::Face : Edge not in the Profile");
403 // *************************************************
404 // Search if ESpine is an edge of mySpine and find
405 // the index of the corresponding Filler
406 // *************************************************
407 for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++)
408 if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;
410 if (!ispin) Standard_DomainError::Raise(
411 "BRepFill_Pipe::Edge : Edge not in the Spine");
413 theFace = TopoDS::Face(myFaces->Value(iprof, ispin));
418 //=======================================================================
421 //=======================================================================
422 TopoDS_Edge BRepFill_Pipe::Edge(const TopoDS_Edge& ESpine,
423 const TopoDS_Vertex& VProfile)
425 Standard_Integer ii, ispin = 0, iprof = 0, count = 0;;
427 // *************************************************
428 // Search if VProfile is a Vertex of myProfile
429 // *************************************************
430 iprof = FindVertex(myProfile, VProfile, count);
431 if (!iprof) Standard_DomainError::Raise(
432 "BRepFill_Pipe::Edge : Vertex not in the Profile");
435 // *************************************************
436 // Search if ESpine is an edge of mySpine and find
437 // the index of the corresponding Filler
438 // *************************************************
440 for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++)
441 if (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;
443 if (!ispin) Standard_DomainError::Raise(
444 "BRepFill_Pipe::Edge : Edge not in the Spine");
447 // *************************************************
448 // Generate the corresponding Shape
449 // *************************************************
451 theEdge = TopoDS::Edge(myEdges->Value(iprof, ispin));
458 //=======================================================================
461 //=======================================================================
463 TopoDS_Shape BRepFill_Pipe::Section(const TopoDS_Vertex& VSpine) const
465 TopoDS_Iterator it, itv;
467 Standard_Integer ii, ispin = 0;
469 TopoDS_Shape curSect = myProfile;
471 // *************************************************
472 // Search if ESpine is an edge of mySpine and find
473 // the index of the corresponding Filler
474 // *************************************************
476 // iterate on all the edges of mySpine
477 for (ii=1; ii<=myLoc->NbLaw()+1 && (!ispin); ii++)
478 if (VSpine.IsSame(myLoc->Vertex(ii))) ispin = ii;
480 if (!ispin) Standard_DomainError::Raise(
481 "BRepFill_Pipe::Section : Vertex not in the Spine");
484 TopoDS_Compound Comp;
485 B.MakeCompound(Comp);
486 for (ii=1; ii<=mySections->ColLength(); ii++)
487 B.Add(Comp, mySections->Value(ii, ispin));
492 //=======================================================================
493 //function : PipeLine
494 //purpose : Construct a wire by sweeping of a point
495 //=======================================================================
497 TopoDS_Wire BRepFill_Pipe::PipeLine(const gp_Pnt& Point)
504 BRepLib_MakeVertex MkV(P);
505 Handle(BRepFill_ShapeLaw) Section =
506 new (BRepFill_ShapeLaw) (MkV.Vertex());
509 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
510 MkSw.SetForceApproxC1(myForceApproxC1);
511 MkSw.Build( myReversedEdges, myTapes, myRails,
512 BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
513 TopoDS_Shape aLocalShape = MkSw.Shape();
514 myErrorOnSurf = MkSw.ErrorOnSurface();
515 return TopoDS::Wire(aLocalShape);
516 // return TopoDS::Wire(MkSw.Shape());
519 //=======================================================================
520 //function : MakeShape
522 //=======================================================================
524 TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
525 const TopoDS_Shape& FirstShape,
526 const TopoDS_Shape& LastShape)
530 Standard_Boolean explode = Standard_False;
531 TopoDS_Shape TheS, TheFirst, TheLast;
532 Standard_Integer InitialLength = 0;
534 TheFirst = FirstShape;
536 if (! myFaces.IsNull()) InitialLength = myFaces->ColLength();
538 // there are two kinds of generation
539 // 1. generate with S from each Filler (Vertex, Edge)
540 // 2. call MakeShape recursively on the subshapes of S
542 // explode is True in the second case
544 // create the result empty
546 switch (S.ShapeType()) {
550 B.MakeWire(TopoDS::Wire(result));
557 B.MakeShell(TopoDS::Shell(result));
560 W.Closed(BRep_Tool::IsClosed(S));
562 if (!FirstShape.IsNull()) {
564 B.Add(W, FirstShape);
565 W.Closed(BRep_Tool::IsClosed(FirstShape));
568 if (!LastShape.IsNull()) {
571 W.Closed(BRep_Tool::IsClosed(LastShape));
574 result.Closed (BRep_Tool::IsClosed (result));
579 B.MakeShell(TopoDS::Shell(result));
584 B.MakeShell(TopoDS::Shell(result));
585 explode = Standard_True;
586 if ( !mySpine.Closed() && !TheFirst.IsNull()) {
587 B.Add(result, TheFirst.Reversed());
589 result.Closed (BRep_Tool::IsClosed (result));
595 B.MakeCompSolid(TopoDS::CompSolid(result));
596 explode = Standard_True;
601 case TopAbs_COMPSOLID :
602 Standard_DomainError::Raise("BRepFill_Pipe::profile contains solids");
605 case TopAbs_COMPOUND :
607 B.MakeCompound(TopoDS::Compound(result));
608 explode = Standard_True;
617 TopoDS_Iterator itFirst, itLast;
618 TopoDS_Shape first, last;
619 if (!TheFirst.IsNull()) itFirst.Initialize(TheFirst);
620 if (!TheLast.IsNull()) itLast.Initialize(TheLast);
622 for (TopoDS_Iterator it(S); it.More(); it.Next()) {
623 if (!TheFirst.IsNull()) first = itFirst.Value();
624 if (!TheLast.IsNull()) last = itLast.Value();
625 if (TheS.ShapeType() == TopAbs_FACE )
626 MakeShape(it.Value(), first, last);
628 B.Add(result,MakeShape(it.Value(), first, last));
630 if (!TheFirst.IsNull()) itFirst.Next();
631 if (!TheLast.IsNull()) itLast.Next();
636 if (TheS.ShapeType() == TopAbs_VERTEX ) {
637 Handle(BRepFill_ShapeLaw) Section =
638 new (BRepFill_ShapeLaw) (TopoDS::Vertex(TheS));
639 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
640 MkSw.SetForceApproxC1(myForceApproxC1);
641 MkSw.Build( myReversedEdges, myTapes, myRails,
642 BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
643 result = MkSw.Shape();
644 myErrorOnSurf = MkSw.ErrorOnSurface();
646 Handle(TopTools_HArray2OfShape) aSections = MkSw.Sections();
648 if (aSections.IsNull() == Standard_False) {
649 const Standard_Integer aVLast = aSections->UpperCol();
651 myFirst = aSections->Value(1, 1);
652 myLast = aSections->Value(1, aVLast);
656 if (TheS.ShapeType() == TopAbs_WIRE ) {
657 Handle(BRepFill_ShapeLaw) Section =
658 new (BRepFill_ShapeLaw) (TopoDS::Wire(TheS));
659 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
660 MkSw.SetBounds(TopoDS::Wire(TheFirst),
661 TopoDS::Wire(TheLast));
662 MkSw.SetForceApproxC1(myForceApproxC1);
663 MkSw.Build( myReversedEdges, myTapes, myRails,
664 BRepFill_Modified, myContinuity, GeomFill_Location, myDegmax, mySegmax );
665 result = MkSw.Shape();
666 myErrorOnSurf = MkSw.ErrorOnSurface();
667 //Correct <myFirst> and <myLast>
668 ReverseModifiedEdges(myFirst, myReversedEdges);
669 ReverseModifiedEdges(myLast, myReversedEdges);
671 // Labeling of elements
672 if (mySections.IsNull()) {
673 myFaces = MkSw.SubShape();
674 mySections = MkSw.Sections();
675 myEdges = MkSw.InterFaces();
678 Handle(TopTools_HArray2OfShape) Aux, Somme;
679 Standard_Integer length;
680 Standard_Integer ii, jj, kk;
682 Aux = MkSw.SubShape();
683 length = Aux->ColLength() + myFaces->ColLength();
684 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
686 for (jj=1; jj<=myFaces->RowLength(); jj++) {
687 for (ii=1; ii<=myFaces->ColLength(); ii++)
688 Somme->SetValue(ii, jj, myFaces->Value(ii, jj));
690 for (kk=1, ii=myFaces->ColLength()+1;
691 kk <=Aux->ColLength(); kk++, ii++)
692 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
696 Aux = MkSw.Sections();
697 length = Aux->ColLength() + mySections->ColLength();
698 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
700 for (jj=1; jj<=mySections->RowLength(); jj++) {
701 for (ii=1; ii<=mySections->ColLength(); ii++)
702 Somme->SetValue(ii, jj, mySections->Value(ii, jj));
704 myCurIndexOfSectionEdge = mySections->ColLength()+1;
706 for (kk=1, ii=mySections->ColLength()+1;
707 kk <=Aux->ColLength(); kk++, ii++)
708 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
712 Aux = MkSw.InterFaces();
713 length = Aux->ColLength() + myEdges->ColLength();
714 Somme = new (TopTools_HArray2OfShape) (1, length, 1,
716 for (jj=1; jj<=myEdges->RowLength(); jj++) {
717 for (ii=1; ii<=myEdges->ColLength(); ii++)
718 Somme->SetValue(ii, jj, myEdges->Value(ii, jj));
720 for (kk=1, ii=myEdges->ColLength()+1;
721 kk <=Aux->ColLength(); kk++, ii++)
722 Somme->SetValue(ii, jj, Aux->Value(kk, jj));
730 if ( TheS.ShapeType() == TopAbs_FACE ) {
731 Standard_Integer ii, jj;
733 TopExp_Explorer Explo(result, TopAbs_FACE);
734 for (; Explo.More(); Explo.Next())
736 TopoDS_Shape aFace = Explo.Current();
737 RebuildTopOrBottomFace(aFace.Reversed(), Standard_True); //top face was reversed
741 for (ii=InitialLength+1; ii<=myFaces->ColLength(); ii++) {
742 for (jj=1; jj<=myFaces->RowLength(); jj++) {
743 F = TopoDS::Face(myFaces->Value(ii, jj));
744 if (!F.IsNull()) B.Add(result, F);
748 if ( !mySpine.Closed()) {
749 // if Spine is not closed
750 // add the last face of the solid
753 RebuildTopOrBottomFace(TheLast, Standard_False); //bottom face
755 B.Add(result, TopoDS::Face(TheLast));
762 result.Closed(Standard_True);
763 BS.Add(solid,TopoDS::Shell(result));
765 BRepClass3d_SolidClassifier SC(solid);
766 SC.PerformInfinitePoint(Precision::Confusion());
767 if ( SC.State() == TopAbs_IN) {
769 TopoDS_Shape aLocalShape = result.Reversed();
770 BS.Add(solid,TopoDS::Shell(aLocalShape));
771 // BS.Add(solid,TopoDS::Shell(result.Reversed()));
780 //============================================================================
781 //function : FindEdge
782 //purpose : Find the number of edge corresponding to the edge of the profile.
783 //============================================================================
785 Standard_Integer BRepFill_Pipe::FindEdge(const TopoDS_Shape& S,
786 const TopoDS_Edge& E,
787 Standard_Integer& InitialLength) const
789 Standard_Integer result = 0;
791 switch (S.ShapeType()) {
796 if (S.IsSame(E)) result = InitialLength;
802 Handle(BRepFill_ShapeLaw) Section =
803 new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
804 Standard_Integer NbLaw = Section->NbLaw();
806 for (Standard_Integer ii = 1; (ii<=NbLaw) && (!result); ii++) {
807 if (E.IsSame(Section->Edge(ii)) ) result = InitialLength + ii;
809 InitialLength += NbLaw;
815 case TopAbs_COMPOUND :
817 for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
818 result = FindEdge(it.Value(), E, InitialLength );
823 case TopAbs_COMPSOLID :
824 Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
833 //=======================================================================
834 //function : FindVertex
835 //purpose : Find the number of edge corresponding to an edge of the profile.
836 //=======================================================================
838 Standard_Integer BRepFill_Pipe::FindVertex(const TopoDS_Shape& S,
839 const TopoDS_Vertex& V,
840 Standard_Integer& InitialLength) const
842 Standard_Integer result = 0;
844 switch (S.ShapeType()) {
848 if (S.IsSame(V)) result = InitialLength;
854 TopoDS_Vertex VF, VL;
855 TopExp::Vertices(TopoDS::Edge(S), VF, VL);
856 if (S.Orientation() == TopAbs_REVERSED) {
858 aux = VF; VF = VL; VL = aux;
860 if (VF.IsSame(V)) result = InitialLength+1;
861 else if (VL.IsSame(V)) result = InitialLength+2;
868 Standard_Integer ii = InitialLength+1;
869 Handle(BRepFill_ShapeLaw) Section =
870 new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
871 InitialLength += Section->NbLaw()+1;
873 for (; (ii<=InitialLength) && (!result); ii++) {
874 if (V.IsSame(Section->Vertex(ii, 0.)) ) result = ii;
881 case TopAbs_COMPOUND :
883 for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
884 result = FindVertex(it.Value(), V, InitialLength);
889 case TopAbs_COMPSOLID :
890 Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
899 //=======================================================================
900 //function : DefineRealSegmax
901 //purpose : Defines the real number of segments
902 // required in the case of bspline spine
903 //=======================================================================
905 void BRepFill_Pipe::DefineRealSegmax()
907 Standard_Integer RealSegmax = 0;
909 TopoDS_Iterator iter(mySpine);
910 for (; iter.More(); iter.Next())
912 TopoDS_Edge E = TopoDS::Edge(iter.Value());
913 Standard_Real first, last;
914 Handle(Geom_Curve) C = BRep_Tool::Curve( E, first, last );
917 while (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve) ||
918 C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
920 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
921 C = Handle(Geom_TrimmedCurve)::DownCast (C)->BasisCurve();
922 if (C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
923 C = Handle(Geom_OffsetCurve)::DownCast (C)->BasisCurve();
925 if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve))
927 Handle(Geom_BSplineCurve) BC (Handle(Geom_BSplineCurve)::DownCast (C));
928 Standard_Integer NbKnots = BC->NbKnots();
929 Standard_Integer RealNbKnots = NbKnots;
930 if (first > BC->FirstParameter())
932 Standard_Integer I1, I2;
933 BC->LocateU( first, Precision::PConfusion(), I1, I2 );
936 if (last < BC->LastParameter())
938 Standard_Integer I1, I2;
939 BC->LocateU( last, Precision::PConfusion(), I1, I2 );
940 RealNbKnots -= NbKnots-I2;
942 RealSegmax += RealNbKnots-1;
946 if (mySegmax < RealSegmax)
947 mySegmax = RealSegmax;
950 //=======================================================================
951 //function : RebuildTopOrBottomFace
952 //purpose : Correct orientation of v-iso edges
953 // according to new 3d and 2d curves taken from swept surfaces
954 //=======================================================================
956 void BRepFill_Pipe::RebuildTopOrBottomFace(const TopoDS_Shape& aFace,
957 const Standard_Boolean IsTop) const
959 Standard_Integer IndexOfSection =
960 (IsTop)? 1 : mySections->RowLength();
964 TopoDS_Iterator itf(aFace);
965 for (; itf.More(); itf.Next())
967 TopoDS_Shape aWire = itf.Value();
968 TopTools_SequenceOfShape InitEdges;
969 TopTools_SequenceOfShape ResEdges;
970 TopoDS_Iterator itw(aWire);
971 for (; itw.More(); itw.Next())
973 TopoDS_Shape anEdge = itw.Value();
974 for (ii = myCurIndexOfSectionEdge; ii <= mySections->ColLength(); ii++)
976 TopoDS_Shape aVisoEdge = mySections->Value(ii, IndexOfSection);
977 if (anEdge.IsSame(aVisoEdge))
979 InitEdges.Append(anEdge);
980 ResEdges.Append(aVisoEdge);
985 aWire.Free(Standard_True);
986 for (ii = 1; ii <= InitEdges.Length(); ii++)
988 BB.Remove(aWire, InitEdges(ii));
989 UpdateTolFromTopOrBottomPCurve(TopoDS::Face(aFace), TopoDS::Edge(ResEdges(ii)));
990 BB.Add(aWire, ResEdges(ii));