1 // File: BRepFill_OffsetWire.cxx
2 // Created: Thu Apr 20 10:33:55 1995
3 // Author: Bruno DUMORTIER
6 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
10 #include <BRepFill_OffsetWire.ixx>
12 #include <BRepAdaptor_Curve.hxx>
13 #include <BRepAdaptor_Surface.hxx>
15 #include <BRepFill_DataMapOfNodeShape.hxx>
16 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
17 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
18 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
19 #include <BRepFill_TrimEdgeTool.hxx>
20 #include <BRepLib.hxx>
21 #include <BRepLib_MakeVertex.hxx>
22 #include <BRepLib_MakeFace.hxx>
23 #include <BRepLib_MakeWire.hxx>
24 #include <BRepLib_MakeEdge.hxx>
25 #include <BRepTools.hxx>
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRep_TEdge.hxx>
29 #include <BRep_CurveRepresentation.hxx>
30 #include <BRep_GCurve.hxx>
31 #include <BRepTools_WireExplorer.hxx>
32 #include <BRepMAT2d_Explorer.hxx>
33 #include <Geom2dAdaptor_Curve.hxx>
34 #include <Geom2dAdaptor_HCurve.hxx>
35 #include <Adaptor3d_OffsetCurve.hxx>
36 #include <Adaptor3d_Curve.hxx>
37 #include <Geom_Surface.hxx>
38 #include <Geom_Plane.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <Geom2d_Circle.hxx>
41 #include <Geom2d_Line.hxx>
42 #include <Geom2d_TrimmedCurve.hxx>
43 #include <Geom2d_OffsetCurve.hxx>
44 #include <GeomAPI.hxx>
45 #include <Geom_TrimmedCurve.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_OffsetCurve.hxx>
48 #include <MAT_Arc.hxx>
49 #include <MAT_Node.hxx>
50 #include <MAT_Graph.hxx>
51 #include <MAT2d_CutCurve.hxx>
52 #include <Precision.hxx>
53 #include <Standard_NotImplemented.hxx>
54 #include <TColgp_SequenceOfPnt.hxx>
55 #include <TColStd_SequenceOfReal.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <TopoDS_Wire.hxx>
61 #include <TopoDS_Compound.hxx>
62 #include <TopoDS_Iterator.hxx>
63 #include <TopTools_MapOfShape.hxx>
64 #include <TopTools_MapIteratorOfMapOfShape.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <TopTools_DataMapOfShapeListOfShape.hxx>
67 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
68 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
69 #include <TopTools_SequenceOfShape.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
72 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
78 #include <gp_Dir2d.hxx>
80 #include <BRep_TVertex.hxx>
81 #include <TopTools_IndexedMapOfShape.hxx>
82 #include <Geom2d_BSplineCurve.hxx>
83 #include <TColgp_Array1OfPnt2d.hxx>
84 #include <TColStd_Array1OfReal.hxx>
85 #include <TColStd_Array1OfInteger.hxx>
86 #include <BRepTools_Substitution.hxx>
87 #include <BRepLib_MakeVertex.hxx>
88 #include <Geom2dLProp_CLProps2d.hxx>
89 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
90 #include <Standard_ErrorHandler.hxx>
94 #include <DrawTrSurf.hxx>
95 #include <DrawTrSurf_Curve2d.hxx>
100 static Standard_Boolean AffichGeom = Standard_False;
101 static Standard_Boolean Affich2d = Standard_False;
102 static Standard_Boolean AffichEdge = Standard_False;
103 static Standard_Integer NbTRIMEDGES = 0;
104 static Standard_Integer NbOFFSET = 0;
105 static Standard_Integer NbEDGES = 0;
106 static Standard_Integer NbBISSEC = 0;
108 static char tname[100];
109 static Standard_CString name = tname ;
113 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
115 static void QuasiFleche(const Adaptor3d_Curve& C,
116 const Standard_Real Deflection2,
117 const Standard_Real Udeb,
120 const Standard_Real Ufin,
123 const Standard_Integer Nbmin,
124 const Standard_Real Eps,
125 TColStd_SequenceOfReal& Parameters,
126 TColgp_SequenceOfPnt& Points);
128 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
129 TColgp_SequenceOfPnt& Points,
130 const Adaptor3d_Curve& C,
131 const Standard_Real Deflection,
132 const Standard_Real U1,
133 const Standard_Real U2,
134 const Standard_Real EPSILON,
135 const Standard_Integer Nbmin);
137 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
138 const BRepMAT2d_BisectingLocus& Locus,
139 const BRepMAT2d_LinkTopoBilo& Link,
140 TopTools_ListOfShape& BadEdges);
142 static Standard_Integer CutEdge (const TopoDS_Edge& E,
143 const TopoDS_Face& F,
144 Standard_Integer ForceCut,
145 TopTools_ListOfShape& Cuts);
148 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
149 const Standard_Integer nbParts,
150 TColGeom2d_SequenceOfCurve& theCurves);
151 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
154 static void EdgeVertices (const TopoDS_Edge& E,
158 if (E.Orientation() == TopAbs_REVERSED) {
159 TopExp::Vertices(E,V2,V1);
162 TopExp::Vertices(E,V1,V2);
166 static void UpdateDetromp (TopTools_ListOfShape& Detromp1,
167 TopTools_ListOfShape& Detromp2,
168 const TopTools_SequenceOfShape& Vertices,
169 const TColgp_SequenceOfPnt& Params,
170 const Bisector_Bisec& Bisec,
171 const Standard_Boolean SOnE,
172 const Standard_Boolean EOnE,
173 const BRepFill_TrimEdgeTool& Trim);
175 static Standard_Boolean VertexFromNode
176 (const Handle(MAT_Node)& aNode,
177 const Standard_Real Offset,
179 BRepFill_DataMapOfNodeShape& MapNodeVertex,
182 static void StoreInMap (const TopoDS_Shape& V1,
183 const TopoDS_Shape& V2,
184 TopTools_IndexedDataMapOfShapeShape& MapVV);
186 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
187 const TopTools_ListOfShape& D,
188 TopTools_SequenceOfShape& Sv,
189 TColStd_SequenceOfReal& MapverPar,
190 TopTools_SequenceOfShape& S,
191 TopTools_IndexedDataMapOfShapeShape& MapVV);
193 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
194 const TopoDS_Vertex& V);
196 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
197 const TopoDS_Vertex& aVertex);
199 static void MakeCircle
200 (const TopoDS_Edge& E,
201 const TopoDS_Vertex& V,
202 const TopoDS_Face& F,
203 const Standard_Real Offset,
204 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
205 const Handle(Geom_Plane)& RefPlane);
207 static void MakeOffset
208 (const TopoDS_Edge& E,
209 const TopoDS_Face& F,
210 const Standard_Real Offset,
211 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
212 const Handle(Geom_Plane)& RefPlane);
214 //=======================================================================
215 //function : KPartCircle
217 //=======================================================================
219 static Standard_Boolean KPartCircle
220 (const TopoDS_Face& mySpine,
221 const Standard_Real myOffset,
222 const Standard_Real Alt,
223 TopoDS_Shape& myShape,
224 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
225 Standard_Boolean& myIsDone)
227 // Un seul contour qui est un cercle ferme
228 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
229 Standard_Integer NbEdges = 0;
232 for (; exp.More(); exp.Next()) {
234 E = TopoDS::Edge(exp.Current());
235 if (NbEdges > 1) return Standard_False;
238 TopExp::Vertices(E,V1,V2);
239 if (!V1.IsSame(V2)) return Standard_False;
243 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
245 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
246 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
247 C = Ct->BasisCurve();
250 if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False;
251 Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C);
252 Standard_Real anOffset = myOffset;
253 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
255 if (anOffset < 0. || Abs(anOffset) < CE->Radius()) {
256 Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset);
257 myShape = BRepLib_MakeEdge(OC,f,l);
259 myShape.Orientation(E.Orientation());
262 BRepAdaptor_Surface S(mySpine,0);
263 gp_Ax1 Nor = S.Plane().Axis();
265 gp_Vec Trans(Nor.Direction());
267 T.SetTranslation(Trans);
268 myShape.Move(TopLoc_Location(T));
271 TopTools_ListOfShape LL;
275 myIsDone = Standard_True;
276 return Standard_True;
279 //=======================================================================
280 //function : BRepFill_OffsetWire
282 //=======================================================================
284 BRepFill_OffsetWire::BRepFill_OffsetWire()
285 :myIsDone(Standard_False)
290 //=======================================================================
291 //function : BRepFill_OffsetWire
293 //=======================================================================
295 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
296 const GeomAbs_JoinType Join )
302 //=======================================================================
305 //=======================================================================
307 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
308 const GeomAbs_JoinType Join )
310 Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc,
311 "Only GeomAbs_Arc is implemented");
313 myIsDone = Standard_False;
314 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
315 mySpine = TopoDS::Face(aLocalShape);
316 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
321 //------------------------------------------------------------------
322 // decoupe du spine pour les lieux bissecteurs.
323 //------------------------------------------------------------------
324 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
325 static BRepMAT2d_Explorer Exp;
327 Exp.Perform(mySpine);
329 // TopoDS_Face anOldSpine = mySpine;
331 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
334 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
336 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
337 Standard_Boolean Done;
338 if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
341 //-----------------------------------------------------
342 // Calcul de la carte des lieux bissecteurs a gauche.
343 // et des Liens Topologie -> elements de base de la carte.
344 //-----------------------------------------------------
346 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
347 // static BRepMAT2d_Explorer Exp;
348 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
349 Exp.Perform(myWorkSpine);
350 myBilo.Compute(Exp,1,MAT_Left);
351 myLink.Perform(Exp,myBilo);
355 //=======================================================================
358 //=======================================================================
360 Standard_Boolean BRepFill_OffsetWire::IsDone() const
366 //=======================================================================
369 //=======================================================================
371 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
377 //=======================================================================
380 //=======================================================================
382 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
388 //=======================================================================
389 //function : GeneratedShapes
391 //=======================================================================
393 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
394 (const TopoDS_Shape& SpineShape)
397 if (!myMapSpine.IsEmpty()) {
398 // myMapSpine peut etre vide si on est passe par PerformWithBilo.
399 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
400 for (; it.More(); it.Next()) {
401 if (myMap.Contains(it.Key())) {
402 if (!myMap.Contains(it.Value())) {
403 TopTools_ListOfShape L;
404 myMap.Add(it.Value(),L);
406 if ( !it.Value().IsSame(it.Key())) {
407 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
408 //myMap.UnBind(it.Key());
409 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
410 TopTools_ListOfShape LastList;
411 LastList.Append(myMap(myMap.Extent()));
413 if (myMap.FindIndex(it.Key()) != 0)
414 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
417 if (myMap.Contains(it.Key().Reversed())) {
418 if (!myMap.Contains(it.Value().Reversed())) {
419 TopTools_ListOfShape L;
420 myMap.Add(it.Value().Reversed(),L);
422 if ( !it.Value().IsSame(it.Key())) {
423 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
424 //myMap.UnBind(it.Key().Reversed());
425 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
426 TopTools_ListOfShape LastList;
427 LastList.Append(myMap(myMap.Extent()));
429 if (myMap.FindIndex(it.Key().Reversed()) != 0)
430 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
435 myCallGen = Standard_True;
438 if (myMap.Contains(SpineShape)) {
439 return myMap.FindFromKey(SpineShape);
442 static TopTools_ListOfShape Empty;
448 //=======================================================================
449 //function : JoinType
451 //=======================================================================
453 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
458 //=======================================================================
461 //=======================================================================
463 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
464 const Standard_Real Alt)
466 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
469 myCallGen = Standard_False;
470 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
472 TopoDS_Face oldWorkSpain = myWorkSpine;
474 TopTools_ListOfShape BadEdges;
475 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
477 if(!BadEdges.IsEmpty()) {
478 // Modification of myWorkSpine;
479 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
480 BRepTools_Substitution aSubst;
481 TopTools_ListIteratorOfListOfShape it(BadEdges);
482 TopTools_ListOfShape aL;
483 Standard_Real aDefl = .01 * Abs(Offset);
484 TColStd_SequenceOfReal Parameters;
485 TColgp_SequenceOfPnt Points;
487 for(; it.More(); it.Next()) {
491 const TopoDS_Shape& anE = it.Value();
492 TopoDS_Vertex Vf, Vl;
493 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
496 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
497 GeomAdaptor_Curve AC(G3d,f,l);
499 Standard_Boolean dummy = PerformCurve(Parameters, Points,
500 AC, aDefl, f, l, Precision::Confusion(),
503 Standard_Integer NPnts = Points.Length();
505 //cout << NPnts << " points " << endl;
506 TopoDS_Vertex FV = Vf;
510 for(np = 2; np < NPnts; np++) {
511 gp_Pnt LP = Points(np);
512 LV = BRepLib_MakeVertex(LP);
513 newE = BRepLib_MakeEdge(FV, LV);
518 newE = BRepLib_MakeEdge(FV, LV);
522 //cout << " 2 points " << endl;
523 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
527 if (myMapSpine.IsBound( anE ))
529 TopTools_ListIteratorOfListOfShape newit( aL );
530 for (; newit.More(); newit.Next())
532 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
533 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
534 TopoDS_Vertex NewV1, NewV2;
535 EdgeVertices( NewEdge, NewV1, NewV2 );
536 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
537 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
539 myMapSpine.UnBind( anE );
542 aSubst.Substitute(anE, aL);
545 TopTools_DataMapOfShapeListOfShape wwmap;
546 TopoDS_Iterator itws( myWorkSpine );
547 for (; itws.More(); itws.Next())
549 TopoDS_Shape aWire = itws.Value();
550 aSubst.Build( aWire );
551 if (aSubst.IsCopied(aWire))
553 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
554 NewWire.Closed( aWire.Closed() );
555 TopTools_ListOfShape Lw;
556 Lw.Append( NewWire );
557 wwmap.Bind( aWire, Lw );
561 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
562 for (; itmap.More(); itmap.Next())
563 aSubst.Substitute( itmap.Key(), itmap.Value() );
564 aSubst.Build(myWorkSpine);
565 if(aSubst.IsCopied(myWorkSpine)) {
566 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
567 //sprintf(name,"WS1");
568 //DBRep::Set(name,myWorkSpine);
570 BRepMAT2d_Explorer newExp;
571 newExp.Perform(myWorkSpine);
572 BRepMAT2d_BisectingLocus newBilo;
573 BRepMAT2d_LinkTopoBilo newLink;
574 newBilo.Compute(newExp,1,MAT_Left);
575 newLink.Perform(newExp,newBilo);
576 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
578 myWorkSpine = oldWorkSpain;
581 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
586 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
589 } catch (Standard_Failure) {
591 myIsDone = Standard_False;
595 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
596 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
597 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
599 for (; anExp.More(); anExp.Next()) {
600 const TopoDS_Shape &aWire = anExp.Current();
602 if (!aWire.Closed()) {
604 myIsDone = Standard_False;
605 Standard_ConstructionError::Raise("Offset wire is not closed.");
608 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
611 //=======================================================================
614 //=======================================================================
616 void Compute (const TopoDS_Face& Spine,
617 TopoDS_Shape& aShape,
618 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
619 const Standard_Real Alt)
622 B.MakeCompound(TopoDS::Compound(aShape));
623 Standard_Real ALT = Alt;
624 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
626 T.SetTranslation(gp_Vec(0.,0.,ALT));
627 TopLoc_Location L(T);
629 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
630 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
631 TopoDS_Shape aLocalShape = CurW.Moved(L);
632 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
633 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
635 // mise a jour de la Map.
636 TopoDS_Iterator it1( CurW);
637 TopoDS_Iterator it2( NewW);
638 for ( ; it1.More(); it1.Next(), it2.Next()) {
639 TopTools_ListOfShape List;
640 List.Append(it2.Value());
641 Map.Add(it1.Value(), List);
646 //=======================================================================
647 //function : PerformWithBiLo
649 //=======================================================================
651 void BRepFill_OffsetWire::PerformWithBiLo
652 (const TopoDS_Face& Spine,
653 const Standard_Real Offset,
654 const BRepMAT2d_BisectingLocus& Locus,
655 BRepMAT2d_LinkTopoBilo& Link,
656 const GeomAbs_JoinType Join,
657 const Standard_Real Alt)
659 Standard_NotImplemented_Raise_if (Join > GeomAbs_Arc,
660 "Only GeomAbs_Arc is implemented");
662 myIsDone = Standard_False;
663 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
664 myWorkSpine = TopoDS::Face(aLocalShape);
665 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
671 if (mySpine.IsNull()) {
672 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
673 mySpine = TopoDS::Face(aLocalShape);
674 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
678 //*****************************************
679 // si myOffset = 0, on ne s'emmerde pas !!
680 //*****************************************
681 if ( Abs(myOffset) < Precision::Confusion()) {
682 Compute(mySpine,myShape,myMap,Alt);
683 myIsDone = Standard_True;
687 //******************************
688 // Calcul pour un offset non nul
689 //******************************
690 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
692 BRep_Builder myBuilder;
693 myBuilder.MakeCompound(TopoDS::Compound(myShape));
695 //---------------------------------------------------------------------
696 // MapNodeVertex : associe a chaque noeud de la carte (key1) et
697 // a chaque element du profil (key2) un vertex (item).
698 // MapBis : ensemble des edges ou vertex (item) generes par
699 // une bisectrice sur une face ou un edge (key)des
701 // MapVerPar : Map des parametres des vertex sur les edges paralleles
702 // la liste contenue dans MapVerPar (E) correspond aux
703 // parametres sur E des vertex contenu dans MapBis(E);
704 //---------------------------------------------------------------------
707 BRepFill_DataMapOfNodeShape MapNodeVertex;
708 TopTools_DataMapOfShapeSequenceOfShape MapBis;
709 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
711 TopTools_DataMapOfShapeShape EmptyMap;
712 TopTools_SequenceOfShape EmptySeq;
713 TopTools_ListOfShape EmptyList;
714 TColStd_SequenceOfReal EmptySeqOfReal;
716 Standard_Real ALT = Alt;
717 Handle(Geom_Plane) RefPlane =
718 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
719 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
720 RefPlane = Handle(Geom_Plane)::DownCast
721 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
723 //---------------------------------------------------------------
724 // Construction des Cercles et des OffsetCurves
725 //---------------------------------------------------------------
727 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
728 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
729 TopoDS_Shape& PE = PEE ;
730 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
731 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
732 if (SE.ShapeType() == TopAbs_VERTEX) {
733 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
734 myWorkSpine,myOffset,myMap,RefPlane);
737 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane);
746 cout << " Fin Construction des primitives geometriques"<<endl;
751 //---------------------------------------------------
752 // Constructions des vertex de l offset.
753 //---------------------------------------------------
754 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
755 Handle(MAT_Arc) CurrentArc;
756 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
757 Handle(Geom_Curve) CBis;
758 Standard_Boolean Reverse;
759 TopoDS_Edge CurrentEdge;
763 Standard_Integer j, k;
765 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
767 CurrentArc = Locus.Graph()->Arc(i);
768 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
772 sprintf(name,"BISSEC_%d",NbBISSEC++);
773 DrawTrSurf::Set(name,Bisec.Value());
777 //-----------------------------------------------------------------------
778 // Recuperation des elements du spine correspondant aux basicElts separes.
779 //-----------------------------------------------------------------------
780 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
781 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
783 TopTools_SequenceOfShape Vertices;
784 TColgp_SequenceOfPnt Params;
786 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
787 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
789 //-----------------------------------------------------------
790 // Recuperation des edges paralleles sur chaque face.
791 // Si pas d offset generees => saut a la bissectrice suivante.
792 //--------------------------------------------------------------
793 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
794 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
795 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
799 //-----------------------------------------------------------
800 // Construction des vertex correspondant au noeud de la carte.
801 // si ils sont sur l offset.
802 //-----------------------------------------------------------
804 Handle(MAT_Node) Node1, Node2;
807 Node1 = CurrentArc->SecondNode();
808 Node2 = CurrentArc->FirstNode();
811 Node1 = CurrentArc->FirstNode();
812 Node2 = CurrentArc->SecondNode();
815 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
817 if (!Node1->Infinite()) {
818 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
819 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
820 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
821 // MapNodeVertex,VS);
823 if (!Node2->Infinite()) {
824 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
825 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
826 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
827 // MapNodeVertex,VE);
830 //---------------------------------------------
831 // Construction des geometries.
832 //---------------------------------------------
833 BRepFill_TrimEdgeTool Trim (Bisec,
834 Locus.GeomElt(CurrentArc->FirstElement()),
835 Locus.GeomElt(CurrentArc->SecondElement()),
838 //-----------------------------------------------------------
839 // Construction des vertex sur les edges paralleles au spine.
840 //-----------------------------------------------------------
842 Trim.IntersectWith(E [0], E [1], Params);
844 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
846 myBuilder.MakeVertex (VC);
847 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
848 gp_Pnt PVC(P2.X(),P2.Y(),0.);
850 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
854 Standard_Boolean Start = 1;
855 Trim.AddOrConfuse(Start, E[0], E[1], Params);
856 if (Params.Length() == Vertices.Length())
857 Vertices.SetValue(1,VS);
860 // le point n avait pas ete trouve par IntersectWith
861 Vertices.Prepend(VS);
864 Standard_Boolean Start = 0;
865 Trim.AddOrConfuse(Start, E[0], E[1], Params);
866 if (Params.Length() == Vertices.Length())
867 Vertices.SetValue(Params.Length(),VE);
870 // le point n avait pas ete trouve par IntersectWith
874 //------------------------------------------------------------
875 // Mise a jour Detromp.
876 // Detromp permetra de supprimer les vertex sur l offset
877 // correspondant a des zones de tangences
878 // dans Detromp sont ranges les vertex qui limitent
879 // les portions de la bissectrices situes entre le spine et
881 //------------------------------------------------------------
882 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
883 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
886 UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params,
887 Bisec, StartOnEdge, EndOnEdge, Trim);
888 //----------------------------------------------
889 // Stockage des vertex sur les edges paralleles.
890 // on remplit MapBis et MapVerPar.
891 //----------------------------------------------
892 if (!Vertices.IsEmpty()) {
893 for (k = 0; k <= 1; k++) {
894 if (!MapBis.IsBound(E[k])) {
895 MapBis .Bind(E[k],EmptySeq);
896 MapVerPar.Bind(E[k],EmptySeqOfReal);
898 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
899 MapBis (E[k]).Append(Vertices.Value(ii));
900 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
901 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
906 //------------------------------------------------------------
907 //POUR LES CERCLES COMPLETS . la parallele peut etre contenue
908 // dans la zone sans intersection avec la frontiere
909 // pas d intersection
910 // si myoffset est < distance des noeuds la parallele peut etre
912 //-------------------------------------------------------------
913 for (k = 0; k <= 1; k++) {
914 if (!MapBis.IsBound(E[k])) {
915 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
916 MapBis .Bind(E[k],EmptySeq);
917 MapVerPar.Bind(E[k],EmptySeqOfReal);
926 cout << " Fin Construction des vertex sur les offsets"<<endl;
930 //----------------------------------
931 // Construction des edges paralleles.
932 //----------------------------------
933 TopTools_IndexedDataMapOfShapeShape MapVV;
935 TopoDS_Shape CurrentSpine;
937 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
939 for (j = 1; j <= myMap.Extent(); j++) {
940 CurrentSpine = myMap.FindKey(j);
941 CurrentEdge = TopoDS::Edge(myMap(j).First());
944 if (MapBis.IsBound(CurrentEdge)) {
945 TopTools_SequenceOfShape S;
946 if (!MapBis(CurrentEdge).IsEmpty()) {
947 TrimEdge (CurrentEdge,
948 Detromp (CurrentSpine),
949 MapBis (CurrentEdge) ,
950 MapVerPar(CurrentEdge) ,
952 for ( k = 1; k <= S.Length(); k++) {
953 myMap(j).Append(S.Value(k));
960 myMap(j).Append(CurrentEdge);
965 Standard_Integer ind;
966 for (ind = 1; ind <= MapVV.Extent(); ind++)
968 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
969 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
970 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
971 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
972 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
973 TopTools_ListOfShape LV;
974 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
975 BRepTools_Substitution aSubst;
976 aSubst.Substitute( OldV, LV );
977 for (j = 1; j <= myMap.Extent(); j++)
979 TopTools_ListIteratorOfListOfShape itl(myMap(j));
980 for (; itl.More(); itl.Next())
982 aSubst.Build(itl.Value());
983 if (aSubst.IsCopied(itl.Value()))
985 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
986 TopAbs_Orientation SaveOr = itl.Value().Orientation();
987 itl.Value() = listSh.First();
988 itl.Value().Orientation(SaveOr);
994 //----------------------------------
995 // Constructions des wires offset.
996 //----------------------------------
999 // Mise a jour des vertex ( Construits dans le plan Z = 0) !!!
1000 TopTools_MapOfShape MapVertex;
1001 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1002 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1003 if ( MapVertex.Add(V)) {
1004 gp_Pnt P = BRep_Tool::Pnt(V);
1005 P = RefPlane->Value(P.X(),P.Y());
1006 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1010 // Constructions des courbes 3d.
1011 BRepLib::BuildCurves3d(myShape);
1013 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1014 for (; Explo.More(); Explo.Next())
1016 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1017 TopoDS_Vertex V1, V2;
1018 TopExp::Vertices( E, V1, V2 );
1019 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1020 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1022 TopLoc_Location loc;
1024 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1025 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1026 theCurve->Transform( loc.Transformation() );
1027 gp_Pnt f3d = theCurve->Value( f );
1028 gp_Pnt l3d = theCurve->Value( l );
1030 Standard_Real dist1, dist2;
1031 dist1 = f3d.Distance( TV1->Pnt() );
1032 dist2 = l3d.Distance( TV2->Pnt() );
1033 if (! MapVertex.Contains( V1 ))
1036 MapVertex.Add( V1 );
1039 TV1->UpdateTolerance( 1.5*dist1 );
1040 if (! MapVertex.Contains( V2 ))
1043 MapVertex.Add( V2 );
1046 TV2->UpdateTolerance( 1.5*dist2 );
1051 myIsDone = Standard_True;
1055 //=======================================================================
1056 //function : Generated
1058 //=======================================================================
1060 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1061 BRepFill_OffsetWire::Generated()
1067 //=======================================================================
1068 //function : PrepareSpine
1070 //=======================================================================
1072 void BRepFill_OffsetWire::PrepareSpine()
1075 TopTools_ListOfShape Cuts;
1076 TopTools_ListIteratorOfListOfShape IteCuts;
1077 TopoDS_Vertex V1,V2;
1079 myWorkSpine.Nullify();
1083 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1084 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1085 B.MakeFace(myWorkSpine,S,L,TolF);
1087 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1092 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1093 Standard_Integer ForcedCut = 0;
1094 Standard_Integer nbResEdges = -1;
1095 TopTools_IndexedMapOfShape EdgeMap;
1097 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1098 Standard_Integer nbEdges = EdgeMap.Extent();
1102 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1104 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1106 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1107 EdgeVertices(E,V1,V2);
1108 myMapSpine.Bind(V1,V1);
1109 myMapSpine.Bind(V2,V2);
1113 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1114 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1115 if (nbEdges == 2 && nbResEdges == 0)
1117 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1118 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1120 if (Cuts.IsEmpty()) {
1122 myMapSpine.Bind(E,E);
1125 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1126 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1127 NE.Orientation(E.Orientation());
1129 myMapSpine.Bind(NE,E);
1130 EdgeVertices(NE,V1,V2);
1131 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1132 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1136 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1140 TopExp::Vertices(NW, aV1, aV2);
1142 NW.Closed(aV1.IsSame(aV2));
1143 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1144 B.Add(myWorkSpine, NW);
1150 DBRep::Set(name,myWorkSpine);
1156 //=======================================================================
1157 //function : MakeWires
1159 //=======================================================================
1161 void BRepFill_OffsetWire::MakeWires()
1163 //--------------------------------------------------------
1164 // creation d une liste unique des edges paralelles crees.
1165 //--------------------------------------------------------
1166 TopTools_SequenceOfShape TheEdges;
1167 TopTools_ListOfShape TheWires;
1168 TopTools_ListIteratorOfListOfShape itl;
1169 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1170 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1171 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1172 TopoDS_Vertex V1,V2,VF,CV;
1175 for (i = 1; i <= myMap.Extent(); i++) {
1176 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1177 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1178 TopExp::Vertices (E,V1,V2);
1179 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1180 continue; //remove small closed edges
1181 if (!MVE.Contains(V1)) {
1182 TopTools_ListOfShape empty;
1185 MVE.ChangeFromKey(V1).Append(E);
1186 if (!MVE.Contains(V2)) {
1187 TopTools_ListOfShape empty;
1190 MVE.ChangeFromKey(V2).Append(E);
1194 //--------------------------------------
1195 // Creation des wires paralleles.
1196 //--------------------------------------
1199 // Standard_Integer NbEdges;
1200 // Standard_Boolean NewWire = Standard_True;
1201 // Standard_Boolean AddEdge = Standard_False;
1204 Standard_Boolean End;
1207 while (!MVE.IsEmpty()) {
1210 //MVEit.Initialize(MVE);
1211 for (i = 1; i <= MVE.Extent(); i++)
1212 if(MVE(i).Extent() == 1)
1215 //if(!MVEit.More()) MVEit.Initialize(MVE);
1216 if (i > MVE.Extent())
1219 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1220 CE = TopoDS::Edge(MVE(i).First());
1221 End = Standard_False;
1222 MVE.ChangeFromKey(CV).RemoveFirst();
1224 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1225 Standard_Boolean isClosed = Standard_False;
1226 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1229 //-------------------------------
1230 // Construction d un wire.
1231 //-------------------------------
1232 TopExp::Vertices(CE,V1,V2);
1233 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1237 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1238 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1239 isClosed = VF.IsSame(CV);
1240 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1241 End = Standard_True;
1243 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1244 TopTools_ListOfShape LastList;
1245 LastList.Append(MVE(MVE.Extent()));
1247 if (MVE.FindIndex(VF) != 0)
1248 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1252 if (MVE.FindFromKey(CV).Extent() > 2) {
1253 //cout <<"vertex sur plus de 2 edges dans une face."<<endl;
1255 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1256 if (itl.Value().IsSame(CE)) {
1257 MVE.ChangeFromKey(CV).Remove(itl);
1261 if (!MVE.FindFromKey(CV).IsEmpty()) {
1262 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1263 MVE.ChangeFromKey(CV).RemoveFirst();
1265 if (MVE.FindFromKey(CV).IsEmpty())
1268 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1269 TopTools_ListOfShape LastList;
1270 LastList.Append(MVE(MVE.Extent()));
1272 if (MVE.FindIndex(CV) != 0)
1273 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1277 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1278 // NW.Closed(Standard_True);
1279 NW.Closed(isClosed);
1280 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1281 TheWires.Append(NW);
1284 // mise a jour de myShape :
1285 // -- si un seul wire : myShape est un Wire
1286 // -- si plusieurs wires : myShape est un Compound.
1287 if ( TheWires.Extent() == 1) {
1288 myShape = TheWires.First();
1293 TopTools_ListIteratorOfListOfShape it(TheWires);
1294 for ( ; it.More(); it.Next()) {
1295 B.Add(R, it.Value());
1302 //=======================================================================
1303 //function : FixHoles
1305 //=======================================================================
1307 void BRepFill_OffsetWire::FixHoles()
1309 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1311 Standard_Real MaxTol = 0.;
1315 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1316 for (; Explo.More(); Explo.Next())
1318 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1319 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1325 Explo.Init( myShape, TopAbs_WIRE );
1326 for (; Explo.More(); Explo.Next())
1328 TopoDS_Shape aWire = Explo.Current();
1329 // Remove duplicated edges
1330 TopTools_DataMapOfShapeListOfShape EEmap;
1331 TopoDS_Iterator it( aWire );
1332 for (; it.More(); it.Next())
1334 const TopoDS_Shape& anEdge = it.Value();
1335 if (! EEmap.IsBound( anEdge ))
1337 TopTools_ListOfShape LE;
1338 EEmap.Bind( anEdge, LE );
1341 EEmap(anEdge).Append( anEdge );
1343 aWire.Free( Standard_True );
1344 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1345 for (; mapit.More(); mapit.Next())
1347 const TopTools_ListOfShape& LE = mapit.Value();
1348 TopTools_ListIteratorOfListOfShape itl( LE );
1349 for (; itl.More(); itl.Next())
1350 BB.Remove( aWire, itl.Value() );
1354 ClosedWires.Append( aWire );
1356 UnclosedWires.Append( aWire );
1359 while (!UnclosedWires.IsEmpty())
1361 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1362 TopoDS_Vertex Vf, Vl;
1363 TopExp::Vertices( Base, Vf, Vl );
1365 Pf = BRep_Tool::Pnt(Vf);
1366 Pl = BRep_Tool::Pnt(Vl);
1367 Standard_Real DistF = RealLast(), DistL = RealLast();
1368 Standard_Integer IndexF, IndexL;
1369 Standard_Boolean IsFirstF, IsFirstL;
1370 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1372 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1373 TopoDS_Vertex V1, V2;
1374 TopExp::Vertices( aWire, V1, V2 );
1376 P1 = BRep_Tool::Pnt(V1);
1377 P2 = BRep_Tool::Pnt(V2);
1378 Standard_Real dist = Pf.Distance( P1 );
1383 IsFirstF = Standard_True;
1385 dist = Pf.Distance( P2 );
1390 IsFirstF = Standard_False;
1392 dist = Pl.Distance( P1 );
1397 IsFirstL = Standard_True;
1399 dist = Pl.Distance( P2 );
1404 IsFirstL = Standard_False;
1407 TopoDS_Wire theWire;
1408 TopoDS_Edge theEdge;
1409 TopoDS_Vertex theVertex;
1410 Standard_Real CommonTol;
1411 Standard_Boolean TryToClose = Standard_True;
1412 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1424 TryToClose = Standard_False;
1426 if (DistF <= MaxTol)
1428 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1429 TopoDS_Vertex V1, V2;
1430 TopExp::Vertices( theWire, V1, V2 );
1431 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1432 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1433 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1434 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1435 TopoDS_Iterator it( theWire );
1436 for (; it.More(); it.Next())
1438 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1439 if (IsFirstF) anEdge.Reverse();
1440 if (!anEdge.IsSame( theEdge ))
1441 BB.Add( Base, anEdge );
1443 theVertex = (IsFirstF)? V1 : V2;
1444 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1445 if (DistF <= CommonTol)
1447 theEdge.Free( Standard_True );
1448 Vf.Orientation( theVertex.Orientation() );
1449 BB.Remove( theEdge, theVertex );
1450 BB.Add( theEdge, Vf );
1451 BB.UpdateVertex( Vf, CommonTol );
1452 if (IsFirstF) theEdge.Reverse();
1453 BB.Add( Base, theEdge );
1457 if (IsFirstF) theEdge.Reverse();
1458 BB.Add( Base, theEdge );
1459 // Creating new edge from theVertex to Vf
1460 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1461 BB.Add( Base, NewEdge );
1464 if (DistL <= MaxTol && IndexL != IndexF)
1466 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1467 TopoDS_Vertex V1, V2;
1468 TopExp::Vertices( theWire, V1, V2 );
1469 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1470 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1471 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1472 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1473 TopoDS_Iterator it( theWire );
1474 for (; it.More(); it.Next())
1476 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1477 if (!IsFirstL) anEdge.Reverse();
1478 if (!anEdge.IsSame( theEdge ))
1479 BB.Add( Base, anEdge );
1481 theVertex = (IsFirstL)? V1 : V2;
1482 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1483 if (DistL <= CommonTol)
1485 theEdge.Free( Standard_True );
1486 Vl.Orientation( theVertex.Orientation() );
1487 BB.Remove( theEdge, theVertex );
1488 BB.Add( theEdge, Vl );
1489 BB.UpdateVertex( Vl, CommonTol );
1490 if (!IsFirstL) theEdge.Reverse();
1491 BB.Add( Base, theEdge );
1495 if (!IsFirstL) theEdge.Reverse();
1496 BB.Add( Base, theEdge );
1497 // Creating new edge from Vl to theVertex
1498 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1499 BB.Add( Base, NewEdge );
1502 // Check if it is possible to close resulting wire
1505 TopExp::Vertices( Base, Vf, Vl );
1506 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1507 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1508 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1509 TopoDS_Edge Efirst, Elast;
1510 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1511 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1512 Pf = BRep_Tool::Pnt(Vf);
1513 Pl = BRep_Tool::Pnt(Vl);
1514 Standard_Real Dist = Pf.Distance(Pl);
1515 if (Dist <= CommonTol)
1517 Elast.Free( Standard_True );
1518 Vf.Orientation( Vl.Orientation() );
1519 BB.Remove( Elast, Vl );
1520 BB.Add( Elast, Vf );
1521 BB.UpdateVertex( Vf, CommonTol );
1522 Base.Closed( Standard_True );
1524 else if (Dist <= MaxTol)
1526 // Creating new edge from Vl to Vf
1527 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1528 BB.Add( Base, NewEdge );
1529 Base.Closed( Standard_True );
1532 // Updating sequences ClosedWires and UnclosedWires
1533 if (DistF <= MaxTol)
1534 UnclosedWires.Remove( IndexF );
1535 if (DistL <= MaxTol && IndexL != IndexF)
1537 if (DistF <= MaxTol && IndexL > IndexF)
1539 UnclosedWires.Remove( IndexL );
1543 ClosedWires.Append( Base );
1544 UnclosedWires.Remove( 1 );
1546 else if (DistF > MaxTol && DistL > MaxTol)
1548 IsolatedWires.Append( Base );
1549 UnclosedWires.Remove( 1 );
1554 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1556 if (!ClosedWires.IsEmpty())
1557 myShape = ClosedWires.First();
1559 myShape = IsolatedWires.First();
1564 BB.MakeCompound( R );
1565 for (i = 1; i <= ClosedWires.Length(); i++)
1566 BB.Add( R, ClosedWires(i) );
1567 for (i = 1; i <= IsolatedWires.Length(); i++)
1568 BB.Add( R, IsolatedWires(i) );
1573 //=======================================================================
1574 //function : CutEdge
1575 //purpose : Decoupe d une edge aux extrema de courbures et aux points
1577 // Les cercles fermes sont aussi decoupes en deux.
1578 // Si <Cuts> est vide l edge n est pas modifie.
1579 // Le premier et le dernier vertex de l edge originale
1580 // appartiennent respectivement a la premiere et derniere
1582 //=======================================================================
1583 Standard_Integer CutEdge (const TopoDS_Edge& E,
1584 const TopoDS_Face& F,
1585 Standard_Integer ForceCut,
1586 TopTools_ListOfShape& Cuts)
1589 MAT2d_CutCurve Cuter;
1590 TColGeom2d_SequenceOfCurve theCurves;
1592 Handle(Geom2d_Curve) C2d;
1593 Handle(Geom2d_TrimmedCurve) CT2d;
1594 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1595 Standard_Real aTol = BRep_Tool::Tolerance(E);
1596 Handle(Geom_Curve) aC;
1597 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1599 TopoDS_Vertex V1,V2,VF,VL;
1600 TopExp::Vertices (E,V1,V2);
1603 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1604 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1605 aC = BRep_Tool::Curve(E,f,l);
1606 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1607 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1608 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1610 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1611 ( Abs(f-l) >= PI) ) {
1613 //---------------------------
1614 // Decoupe cercle ferme.
1615 //---------------------------
1616 Standard_Real m = (f + l)*0.5;
1617 // Modified by Sergey KHROMOV - Wed Mar 6 17:37:28 2002 Begin
1618 gp_Pnt P = aC->Value(m);
1620 VL = BRepLib_MakeVertex(P);
1621 B.UpdateVertex(VL, aTol);
1622 // Modified by Sergey KHROMOV - Wed Mar 6 17:37:30 2002 End
1623 TopoDS_Shape aLocalShape = E.EmptyCopied();
1624 TopoDS_Edge FE = TopoDS::Edge(aLocalShape);
1625 TopoDS_Edge LE = TopoDS::Edge(aLocalShape);
1626 // TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied());
1627 // TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied());
1628 FE.Orientation(TopAbs_FORWARD);
1629 LE.Orientation(TopAbs_FORWARD);
1631 B.Add (FE,VL.Oriented(TopAbs_REVERSED));
1634 B.Add (LE,VL.Oriented(TopAbs_FORWARD));
1636 Cuts.Append(FE.Oriented(E.Orientation()));
1637 Cuts.Append(LE.Oriented(E.Orientation()));
1644 //-------------------------
1645 // Decoupe de la courbe.
1646 //-------------------------
1647 Cuter.Perform(CT2d);
1649 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1650 if (ForceCut == 0) {
1651 if (Cuter.UnModified()) {
1652 //-----------------------------
1653 // edge non modifiee => retour.
1654 //-----------------------------
1657 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1658 theCurves.Append(Cuter.Value(k));
1660 } else if (ForceCut == 1) {
1661 if (Cuter.UnModified()) {
1662 CutCurve (CT2d, 2, theCurves);
1664 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1665 theCurves.Append(Cuter.Value(k));
1667 } else if (ForceCut == 2) {
1668 if (Cuter.UnModified()) {
1669 CutCurve (CT2d, 3, theCurves);
1671 if (Cuter.NbCurves() == 2) {
1672 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1674 if (CC->LastParameter() > (l+f)/2.) {
1675 CutCurve (CC, 2, theCurves);
1676 theCurves.Append(Cuter.Value(2));
1678 theCurves.Append(CC);
1679 CutCurve (Cuter.Value(2), 2, theCurves);
1682 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1683 theCurves.Append(Cuter.Value(k));
1687 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1689 //--------------------------------------
1690 // Creation des edges decoupees.
1691 //--------------------------------------
1694 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1696 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1698 if (k == theCurves.Length()) {VL = V2;}
1700 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1701 gp_Pnt P = aC->Value(CC->LastParameter());
1703 VL = BRepLib_MakeVertex(P);
1704 B.UpdateVertex(VL, aTol);
1705 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1707 TopoDS_Shape aLocalShape = E.EmptyCopied();
1708 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1709 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1710 NE.Orientation(TopAbs_FORWARD);
1711 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1712 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1713 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1714 Cuts.Append(NE.Oriented(E.Orientation()));
1718 return theCurves.Length();
1721 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1722 //=======================================================================
1723 //function : CutCurve
1725 //=======================================================================
1727 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1728 const Standard_Integer nbParts,
1729 TColGeom2d_SequenceOfCurve& theCurves)
1731 Handle(Geom2d_TrimmedCurve) TrimC;
1732 Standard_Real UF,UL,UC;
1735 Standard_Real PTol = Precision::PConfusion()*10;
1736 Standard_Real Tol = Precision::Confusion()*10;
1737 Standard_Boolean YaCut = Standard_False;
1739 UF = C->FirstParameter();
1740 UL = C->LastParameter ();
1744 Step = (UL - UF)/nbParts;
1746 for (Standard_Integer i = 1; i < nbParts; i++) {
1751 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1752 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1755 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1756 theCurves.Append(TrimC);
1759 YaCut = Standard_True;
1763 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1764 theCurves.Append(TrimC);
1766 theCurves.Append(C);
1768 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1770 //=======================================================================
1771 //function : MakeCircle
1773 //=======================================================================
1775 void MakeCircle (const TopoDS_Edge& E,
1776 const TopoDS_Vertex& V,
1777 const TopoDS_Face& F,
1778 const Standard_Real Offset,
1779 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1780 const Handle(Geom_Plane)& RefPlane)
1782 // eval the Axis of the Circle.
1784 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1788 if (E.Orientation() == TopAbs_FORWARD) {
1792 else GC->D1(f,P,DX);
1794 gp_Ax2d Axis(P,gp_Dir2d(DX));
1795 Handle(Geom2d_Circle) Circ
1796 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1798 // Bind the edges in my Map.
1799 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1800 TopTools_ListOfShape LL;
1806 if ( AffichGeom && !OE.IsNull()) {
1807 sprintf(name,"OFFSET_%d",++NbOFFSET);
1808 DBRep::Set(name,OE);
1813 //=======================================================================
1814 //function : MakeOffset
1816 //=======================================================================
1818 void MakeOffset (const TopoDS_Edge& E,
1819 const TopoDS_Face& F,
1820 const Standard_Real Offset,
1821 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1822 const Handle(Geom_Plane)& RefPlane)
1825 Standard_Real anOffset = Offset;
1827 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1829 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1830 Handle(Geom2d_Curve) G2dOC;
1832 Geom2dAdaptor_Curve AC(G2d,f,l);
1833 if ( AC.GetType() == GeomAbs_Circle) {
1834 // si l offset est superieur ou egal au rayon et du cote de la
1835 // concavite du cercle => edge null.
1836 gp_Circ2d C1(AC.Circle());
1838 Standard_Real radius =
1841 gp_Ax22d axes( C1.Axis());
1842 gp_Dir2d Xd = axes.XDirection();
1843 gp_Dir2d Yd = axes.YDirection();
1844 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1845 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1847 if (anOffset*Signe < AC.Circle().Radius()) {
1848 // -anOffset vient d une Etrangete adaptoresque!
1849 Handle(Geom2dAdaptor_HCurve) AHC =
1850 new Geom2dAdaptor_HCurve(G2d);
1851 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1852 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1854 Standard_Real Delta = 2*PI - l + f;
1855 f -= 0.2*Delta; l += 0.2*Delta;
1857 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1860 else if (AC.GetType() == GeomAbs_Line) {
1861 Handle(Geom2dAdaptor_HCurve) AHC =
1862 new Geom2dAdaptor_HCurve(G2d);
1863 Adaptor3d_OffsetCurve Off(AHC,anOffset);
1864 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
1865 Standard_Real Delta = (l - f);
1866 f -= Delta; l += Delta;
1867 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1871 anOffset = -anOffset;
1872 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
1873 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
1877 // Bind the edges in my Map.
1878 if (!G2dOC.IsNull()) {
1879 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
1880 OE.Orientation(E.Orientation());
1881 TopTools_ListOfShape LL;
1886 if (AffichGeom && !OE.IsNull()) {
1887 sprintf(name,"OFFSET_%d",++NbOFFSET);
1888 DBRep::Set(name,OE);
1889 Standard_Real ii = 0;
1896 //=======================================================================
1897 //function : UpdateDetromp
1898 //purpose : Pour chaque interval sur la bissectrice defini par params
1899 // test si le point milieu est a une distance > offset
1900 // dans ce cas les vertex correspondants aux extremites de l interval
1901 // sont ranges dans le detrompeur.
1902 // => Si un meme vertex apparait deux fois dans le detrompeur la
1903 // frontiere de la zone de proximitee est tangente a l offset .
1904 //=======================================================================
1906 void UpdateDetromp (TopTools_ListOfShape& Detromp1,
1907 TopTools_ListOfShape& Detromp2,
1908 const TopTools_SequenceOfShape& Vertices,
1909 const TColgp_SequenceOfPnt& Params,
1910 const Bisector_Bisec& Bisec,
1911 const Standard_Boolean SOnE,
1912 const Standard_Boolean EOnE,
1913 const BRepFill_TrimEdgeTool& Trim)
1915 Standard_Integer ii = 1;
1916 Standard_Real U1,U2;
1917 TopoDS_Vertex V1,V2;
1919 Handle(Geom2d_Curve) Bis = Bisec.Value();
1921 U1 = Bis->FirstParameter();
1924 // le premier point de la bissectrice est sur l offset
1925 V1 = TopoDS::Vertex(Vertices.Value(ii));
1929 while (ii <= Vertices.Length()) {
1930 U2 = Params.Value(ii).X();
1931 V2 = TopoDS::Vertex(Vertices.Value(ii));
1933 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1934 if (!Trim.IsInside(P)) {
1936 Detromp1.Append(V1);
1937 Detromp2.Append(V1);
1939 Detromp1.Append(V2);
1940 Detromp2.Append(V2);
1947 // test point milieu entre le dernier params et la fin de la bissectrice.
1948 U2 = Bis->LastParameter();
1950 if (!Precision::IsInfinite(U2)) {
1951 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1952 if (!Trim.IsInside(P)) {
1954 Detromp1.Append(V1);
1955 Detromp2.Append(V1);
1961 Detromp1.Append(V1);
1962 Detromp2.Append(V1);
1968 //=======================================================================
1969 //function : VertexFromNode
1971 //=======================================================================
1973 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
1974 const Standard_Real Offset,
1976 BRepFill_DataMapOfNodeShape& MapNodeVertex,
1979 Standard_Boolean Status;
1980 Standard_Real Tol = Precision::Confusion();
1983 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
1984 //------------------------------------------------
1985 // le Noeud donne un vertex sur l offset
1986 //------------------------------------------------
1987 if (MapNodeVertex.IsBound(aNode)) {
1988 VN = TopoDS::Vertex(MapNodeVertex(aNode));
1991 gp_Pnt P(PN.X(),PN.Y(),0.);
1993 B.UpdateVertex(VN,P, Precision::Confusion());
1994 MapNodeVertex.Bind(aNode,VN);
1996 Status = Standard_True;
1998 else Status = Standard_False;
2004 //=======================================================================
2005 //function : StoreInMap
2007 //=======================================================================
2009 void StoreInMap (const TopoDS_Shape& V1,
2010 const TopoDS_Shape& V2,
2011 TopTools_IndexedDataMapOfShapeShape& MapVV)
2013 TopoDS_Shape OldV = V1, NewV = V2;
2016 if (MapVV.Contains(V2))
2017 NewV = MapVV.FindFromKey(V2);
2019 if (MapVV.Contains(V1))
2020 MapVV.ChangeFromKey(V1) = NewV;
2022 for (i = 1; i <= MapVV.Extent(); i++)
2023 if (MapVV(i).IsSame(V1))
2026 MapVV.Add(V1, NewV);
2029 //=======================================================================
2030 //function : TrimEdge
2032 //=======================================================================
2034 void TrimEdge (const TopoDS_Edge& E,
2035 const TopTools_ListOfShape& Detromp,
2036 TopTools_SequenceOfShape& TheVer,
2037 TColStd_SequenceOfReal& ThePar,
2038 TopTools_SequenceOfShape& S,
2039 TopTools_IndexedDataMapOfShapeShape& MapVV)
2041 Standard_Boolean Change = Standard_True;
2042 BRep_Builder TheBuilder;
2045 //-----------------------------------------------------------
2046 // Tri des deux sequences en fonction du parametre sur l edge.
2047 //-----------------------------------------------------------
2049 Change = Standard_False;
2050 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2051 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2052 ThePar.Exchange(i,i+1);
2053 TheVer.Exchange(i,i+1);
2054 Change = Standard_True;
2059 //----------------------------------------------------------
2060 // Si un vertex n est pas dans le detrompeur il est elimine.
2061 //----------------------------------------------------------
2062 if (!BRep_Tool::Degenerated(E)) {
2063 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2064 if ( DoubleOrNotInside (Detromp,
2065 TopoDS::Vertex(TheVer.Value(k)))) {
2073 //----------------------------------------------------------
2074 // Si un vertex_double apparait deux fois dans le detrompeur
2075 // le vertex est elimine .
2076 // sinon on garde une seule de ces representations.
2077 //----------------------------------------------------------
2078 if (!BRep_Tool::Degenerated(E)) {
2079 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2080 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2081 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2083 if(k+1 == TheVer.Length()) {
2084 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2089 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2094 if ( DoubleOrNotInside (Detromp,
2095 TopoDS::Vertex(TheVer.Value(k)))) {
2105 //-----------------------------------------------------------
2106 // Creation des edges.
2107 // le nombre de vertex doit etre pair les edges a creer vont
2108 // d un vertex d indice impair i au vertex i+1;
2109 //-----------------------------------------------------------
2110 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2111 TopoDS_Shape aLocalShape = E.EmptyCopied();
2112 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2113 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2115 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2116 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2117 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2120 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2121 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2125 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2129 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2130 DBRep::Set(name,NewEdge);
2135 Handle(Geom_Surface) Surf;
2136 Handle(Geom2d_Curve) C;
2137 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2138 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2139 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2140 Handle(DrawTrSurf_Curve2d) dr =
2141 new DrawTrSurf_Curve2d(C2d,Standard_False);
2142 dr->SetColor(Draw_bleu);
2151 //=======================================================================
2152 //function : DoubleOrNotInside
2153 //purpose : return True si V apparait 2 fois dans LV ou n est pas dedans.
2154 //=======================================================================
2156 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2157 const TopoDS_Vertex& V)
2159 Standard_Boolean Vu = Standard_False;
2160 TopTools_ListIteratorOfListOfShape it(LV);
2162 for ( ; it.More(); it.Next()) {
2163 if (V.IsSame(it.Value())) {
2164 if (Vu) return Standard_True;
2165 else Vu = Standard_True;
2168 if (Vu) return Standard_False;
2169 else return Standard_True;
2172 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2173 const TopoDS_Vertex& aVertex)
2175 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2176 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2177 PV2d.SetCoord( PV.X(), PV.Y() );
2179 Handle(Geom2d_Curve) PCurve;
2180 Handle( BRep_CurveRepresentation ) CurveRep =
2181 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2182 PCurve = CurveRep->PCurve();
2184 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2185 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2186 Pfirst = PCurve->Value(fpar);
2187 Plast = PCurve->Value(lpar);
2188 Pmid = PCurve->Value((fpar + lpar)*0.5);
2190 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2193 Standard_Real dist1 = Pfirst.Distance(PV2d);
2194 Standard_Real dist2 = Plast.Distance(PV2d);
2195 Standard_Real dist3 = Pmid.Distance(PV2d);
2197 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2198 return Standard_True;
2200 return Standard_False;
2203 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2204 const BRepMAT2d_BisectingLocus& Locus,
2205 const BRepMAT2d_LinkTopoBilo& Link,
2206 TopTools_ListOfShape& BadEdges)
2209 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2210 Standard_Real eps = Precision::Confusion();
2211 Standard_Real LimCurv = 1./Offset;
2213 TopTools_MapOfShape aMap;
2215 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2216 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2217 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2218 if (SE.ShapeType() == TopAbs_EDGE) {
2220 if (aMap.Contains(SE)) {
2221 //cout << "Edge is treated second time" << endl;
2225 TopoDS_Edge E = TopoDS::Edge(SE);
2229 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2231 Geom2dAdaptor_Curve AC(G2d,f,l);
2232 GeomAbs_CurveType aCType = AC.GetType();
2234 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2236 Standard_Boolean reverse = Standard_False;
2237 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2242 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2244 aCLProps.SetParameter(f);
2245 if(!aCLProps.IsTangentDefined()) {
2246 BadEdges.Append(SE);
2251 P = aCLProps.Value();
2252 Standard_Real Crv = aCLProps.Curvature();
2255 aCLProps.Tangent(N);
2256 Standard_Real x = N.Y(), y = -N.X();
2258 if (reverse) N.Reverse();
2259 aCLProps.CentreOfCurvature(Pc);
2260 gp_Vec2d Dir( P, Pc );
2261 if (N.Dot(Dir) > 0.) {
2262 if (LimCurv <= Crv + eps) {
2263 BadEdges.Append(SE);
2270 aCLProps.SetParameter(l);
2271 if(!aCLProps.IsTangentDefined()) {
2272 BadEdges.Append(SE);
2277 P = aCLProps.Value();
2278 Crv = aCLProps.Curvature();
2281 aCLProps.Tangent(N);
2282 Standard_Real x = N.Y(), y = -N.X();
2284 if (reverse) N.Reverse();
2285 aCLProps.CentreOfCurvature(Pc);
2286 gp_Vec2d Dir( P, Pc );
2287 if (N.Dot(Dir) > 0.) {
2288 if (LimCurv <= Crv + eps) {
2289 BadEdges.Append(SE);
2302 //=======================================================================
2303 //function : PerformCurve
2305 //=======================================================================
2307 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2308 TColgp_SequenceOfPnt& Points,
2309 const Adaptor3d_Curve& C,
2310 const Standard_Real Deflection,
2311 const Standard_Real U1,
2312 const Standard_Real U2,
2313 const Standard_Real EPSILON,
2314 const Standard_Integer Nbmin)
2316 Standard_Real UU1 = Min(U1, U2);
2317 Standard_Real UU2 = Max(U1, U2);
2321 C.D1(UU1,Pdeb,Ddeb);
2322 Parameters.Append(UU1);
2323 Points.Append(Pdeb);
2325 C.D1(UU2,Pfin,Dfin);
2326 QuasiFleche(C,Deflection*Deflection,
2334 return Standard_True;
2336 //=======================================================================
2337 //function : QuasiFleche
2339 //=======================================================================
2341 static void QuasiFleche(const Adaptor3d_Curve& C,
2342 const Standard_Real Deflection2,
2343 const Standard_Real Udeb,
2346 const Standard_Real Ufin,
2349 const Standard_Integer Nbmin,
2350 const Standard_Real Eps,
2351 TColStd_SequenceOfReal& Parameters,
2352 TColgp_SequenceOfPnt& Points)
2354 Standard_Integer Ptslength = Points.Length();
2355 Standard_Real Udelta = Ufin-Udeb;
2360 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2368 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2369 Standard_Real theFleche=0;
2370 Standard_Boolean flecheok = Standard_False;
2372 // Evaluation de la fleche par interpolation . Voir IntWalk_IWalking_5.gxx
2373 Standard_Real N1 = Vdeb.SquareMagnitude();
2374 Standard_Real N2 = Vdelta.SquareMagnitude();
2375 if (N1 > Eps && N2 > Eps) {
2376 Standard_Real Normediff =
2377 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2378 if (Normediff > Eps) {
2379 theFleche = Normediff*Norme/64.;
2380 flecheok = Standard_True;
2385 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2386 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2387 theFleche = Pmid.SquareDistance(Pverif);
2390 if (theFleche < Deflection2) {
2391 Parameters.Append(Udeb+Udelta);
2392 Points.Append(Pdelta);
2395 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2406 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2410 Nbmin-(Points.Length()-Ptslength),