1 // Created on: 1995-04-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-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.
17 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
21 #include <BRepFill_OffsetWire.ixx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepAdaptor_Surface.hxx>
26 #include <BRepFill_DataMapOfNodeShape.hxx>
27 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
28 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
29 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
30 #include <BRepFill_TrimEdgeTool.hxx>
31 #include <BRepLib.hxx>
32 #include <BRepLib_MakeVertex.hxx>
33 #include <BRepLib_MakeFace.hxx>
34 #include <BRepLib_MakeWire.hxx>
35 #include <BRepLib_MakeEdge.hxx>
36 #include <BRepTools.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRep_TEdge.hxx>
40 #include <BRep_CurveRepresentation.hxx>
41 #include <BRep_GCurve.hxx>
42 #include <BRepTools_WireExplorer.hxx>
43 #include <BRepMAT2d_Explorer.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
45 #include <Geom2dAdaptor_HCurve.hxx>
46 #include <Adaptor3d_OffsetCurve.hxx>
47 #include <Adaptor3d_Curve.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom2d_Curve.hxx>
51 #include <Geom2d_Circle.hxx>
52 #include <Geom2d_Line.hxx>
53 #include <Geom2d_TrimmedCurve.hxx>
54 #include <Geom2d_OffsetCurve.hxx>
55 #include <GeomAPI.hxx>
56 #include <Geom_TrimmedCurve.hxx>
57 #include <Geom_Circle.hxx>
58 #include <Geom_OffsetCurve.hxx>
59 #include <MAT_Arc.hxx>
60 #include <MAT_Node.hxx>
61 #include <MAT_Graph.hxx>
62 #include <MAT2d_CutCurve.hxx>
63 #include <Precision.hxx>
64 #include <Standard_NotImplemented.hxx>
65 #include <TColgp_SequenceOfPnt.hxx>
66 #include <TColStd_SequenceOfReal.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Wire.hxx>
72 #include <TopoDS_Compound.hxx>
73 #include <TopoDS_Iterator.hxx>
74 #include <TopTools_MapOfShape.hxx>
75 #include <TopTools_MapIteratorOfMapOfShape.hxx>
76 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_DataMapOfShapeListOfShape.hxx>
78 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
79 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
80 #include <TopTools_SequenceOfShape.hxx>
81 #include <TopTools_ListOfShape.hxx>
82 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
83 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
89 #include <gp_Dir2d.hxx>
91 #include <BRep_TVertex.hxx>
92 #include <TopTools_IndexedMapOfShape.hxx>
93 #include <Geom2d_BSplineCurve.hxx>
94 #include <TColgp_Array1OfPnt2d.hxx>
95 #include <TColStd_Array1OfReal.hxx>
96 #include <TColStd_Array1OfInteger.hxx>
97 #include <BRepTools_Substitution.hxx>
98 #include <BRepLib_MakeVertex.hxx>
99 #include <Geom2dLProp_CLProps2d.hxx>
100 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
101 #include <Standard_ErrorHandler.hxx>
105 #include <DrawTrSurf.hxx>
106 #include <DrawTrSurf_Curve2d.hxx>
111 static Standard_Boolean AffichGeom = Standard_False;
112 static Standard_Boolean Affich2d = Standard_False;
113 static Standard_Boolean AffichEdge = Standard_False;
114 static Standard_Integer NbTRIMEDGES = 0;
115 static Standard_Integer NbOFFSET = 0;
116 static Standard_Integer NbEDGES = 0;
117 static Standard_Integer NbBISSEC = 0;
119 static char tname[100];
120 static Standard_CString name = tname ;
124 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
126 static void QuasiFleche(const Adaptor3d_Curve& C,
127 const Standard_Real Deflection2,
128 const Standard_Real Udeb,
131 const Standard_Real Ufin,
134 const Standard_Integer Nbmin,
135 const Standard_Real Eps,
136 TColStd_SequenceOfReal& Parameters,
137 TColgp_SequenceOfPnt& Points);
139 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
140 TColgp_SequenceOfPnt& Points,
141 const Adaptor3d_Curve& C,
142 const Standard_Real Deflection,
143 const Standard_Real U1,
144 const Standard_Real U2,
145 const Standard_Real EPSILON,
146 const Standard_Integer Nbmin);
148 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
149 const BRepMAT2d_BisectingLocus& Locus,
150 const BRepMAT2d_LinkTopoBilo& Link,
151 TopTools_ListOfShape& BadEdges);
153 static Standard_Integer CutEdge (const TopoDS_Edge& E,
154 const TopoDS_Face& F,
155 Standard_Integer ForceCut,
156 TopTools_ListOfShape& Cuts);
159 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
160 const Standard_Integer nbParts,
161 TColGeom2d_SequenceOfCurve& theCurves);
162 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
165 static void EdgeVertices (const TopoDS_Edge& E,
169 if (E.Orientation() == TopAbs_REVERSED) {
170 TopExp::Vertices(E,V2,V1);
173 TopExp::Vertices(E,V1,V2);
177 static void UpdateDetromp (TopTools_ListOfShape& Detromp1,
178 TopTools_ListOfShape& Detromp2,
179 const TopTools_SequenceOfShape& Vertices,
180 const TColgp_SequenceOfPnt& Params,
181 const Bisector_Bisec& Bisec,
182 const Standard_Boolean SOnE,
183 const Standard_Boolean EOnE,
184 const BRepFill_TrimEdgeTool& Trim);
186 static Standard_Boolean VertexFromNode
187 (const Handle(MAT_Node)& aNode,
188 const Standard_Real Offset,
190 BRepFill_DataMapOfNodeShape& MapNodeVertex,
193 static void StoreInMap (const TopoDS_Shape& V1,
194 const TopoDS_Shape& V2,
195 TopTools_IndexedDataMapOfShapeShape& MapVV);
197 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
198 const TopTools_ListOfShape& D,
199 TopTools_SequenceOfShape& Sv,
200 TColStd_SequenceOfReal& MapverPar,
201 TopTools_SequenceOfShape& S,
202 TopTools_IndexedDataMapOfShapeShape& MapVV);
204 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
205 const TopoDS_Vertex& V);
207 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
208 const TopoDS_Vertex& aVertex);
210 static void MakeCircle
211 (const TopoDS_Edge& E,
212 const TopoDS_Vertex& V,
213 const TopoDS_Face& F,
214 const Standard_Real Offset,
215 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
216 const Handle(Geom_Plane)& RefPlane);
218 static void MakeOffset
219 (const TopoDS_Edge& E,
220 const TopoDS_Face& F,
221 const Standard_Real Offset,
222 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
223 const Handle(Geom_Plane)& RefPlane);
227 //=======================================================================
228 //function : CheckFace
229 //purpose : Check if face contains an edge with C0 continuity
230 //=======================================================================
232 static void CheckFace(const TopoDS_Face& theFace)
234 TopExp_Explorer ex(theFace,TopAbs_EDGE);
235 for(; ex.More(); ex.Next())
237 TopoDS_Edge anEdge=TopoDS::Edge(ex.Current());
239 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(anEdge,theFace,f,l);
240 if (C->Continuity() == GeomAbs_C0)
241 Standard_ConstructionError::Raise("Initial shape contains an edge with C0 continuity");
245 //=======================================================================
246 //function : KPartCircle
248 //=======================================================================
250 static Standard_Boolean KPartCircle
251 (const TopoDS_Face& mySpine,
252 const Standard_Real myOffset,
253 const Standard_Real Alt,
254 TopoDS_Shape& myShape,
255 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
256 Standard_Boolean& myIsDone)
258 // The only contour which is a closed circle
259 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
260 Standard_Integer NbEdges = 0;
263 for (; exp.More(); exp.Next()) {
265 E = TopoDS::Edge(exp.Current());
266 if (NbEdges > 1) return Standard_False;
269 TopExp::Vertices(E,V1,V2);
270 if (!V1.IsSame(V2)) return Standard_False;
274 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
276 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
277 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
278 C = Ct->BasisCurve();
281 if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False;
282 Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C);
283 Standard_Real anOffset = myOffset;
284 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
286 if (anOffset < 0. || Abs(anOffset) < CE->Radius()) {
287 Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset);
288 myShape = BRepLib_MakeEdge(OC,f,l);
290 myShape.Orientation(E.Orientation());
293 BRepAdaptor_Surface S(mySpine,0);
294 gp_Ax1 Nor = S.Plane().Axis();
296 gp_Vec Trans(Nor.Direction());
298 T.SetTranslation(Trans);
299 myShape.Move(TopLoc_Location(T));
302 TopTools_ListOfShape LL;
306 myIsDone = Standard_True;
307 return Standard_True;
310 //=======================================================================
311 //function : BRepFill_OffsetWire
313 //=======================================================================
315 BRepFill_OffsetWire::BRepFill_OffsetWire()
316 :myIsDone(Standard_False)
321 //=======================================================================
322 //function : BRepFill_OffsetWire
324 //=======================================================================
326 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
327 const GeomAbs_JoinType Join )
332 //=======================================================================
335 //=======================================================================
337 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
338 const GeomAbs_JoinType Join )
340 Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc,
341 "Only GeomAbs_Arc is implemented");
343 myIsDone = Standard_False;
344 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
345 mySpine = TopoDS::Face(aLocalShape);
346 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
353 //------------------------------------------------------------------
354 // cut the spine for bissectors.
355 //------------------------------------------------------------------
356 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
357 static BRepMAT2d_Explorer Exp;
359 Exp.Perform(mySpine);
361 // TopoDS_Face anOldSpine = mySpine;
363 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
366 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
368 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
369 Standard_Boolean Done;
370 if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
373 //-----------------------------------------------------
374 // Calculate the map of bissectors to the left.
375 // and Links Topology -> base elements of the map.
376 //-----------------------------------------------------
378 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
379 // static BRepMAT2d_Explorer Exp;
380 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
381 Exp.Perform(myWorkSpine);
382 myBilo.Compute(Exp,1,MAT_Left);
383 myLink.Perform(Exp,myBilo);
387 //=======================================================================
390 //=======================================================================
392 Standard_Boolean BRepFill_OffsetWire::IsDone() const
398 //=======================================================================
401 //=======================================================================
403 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
409 //=======================================================================
412 //=======================================================================
414 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
420 //=======================================================================
421 //function : GeneratedShapes
423 //=======================================================================
425 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
426 (const TopoDS_Shape& SpineShape)
429 if (!myMapSpine.IsEmpty()) {
430 // myMapSpine can be empty if passed by PerformWithBilo.
431 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
432 for (; it.More(); it.Next()) {
433 if (myMap.Contains(it.Key())) {
434 if (!myMap.Contains(it.Value())) {
435 TopTools_ListOfShape L;
436 myMap.Add(it.Value(),L);
438 if ( !it.Value().IsSame(it.Key())) {
439 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
440 //myMap.UnBind(it.Key());
441 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
442 TopTools_ListOfShape LastList;
443 LastList.Append(myMap(myMap.Extent()));
445 if (myMap.FindIndex(it.Key()) != 0)
446 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
449 if (myMap.Contains(it.Key().Reversed())) {
450 if (!myMap.Contains(it.Value().Reversed())) {
451 TopTools_ListOfShape L;
452 myMap.Add(it.Value().Reversed(),L);
454 if ( !it.Value().IsSame(it.Key())) {
455 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
456 //myMap.UnBind(it.Key().Reversed());
457 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
458 TopTools_ListOfShape LastList;
459 LastList.Append(myMap(myMap.Extent()));
461 if (myMap.FindIndex(it.Key().Reversed()) != 0)
462 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
467 myCallGen = Standard_True;
470 if (myMap.Contains(SpineShape)) {
471 return myMap.FindFromKey(SpineShape);
474 static TopTools_ListOfShape Empty;
480 //=======================================================================
481 //function : JoinType
483 //=======================================================================
485 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
490 //=======================================================================
493 //=======================================================================
495 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
496 const Standard_Real Alt)
498 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
502 myCallGen = Standard_False;
503 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
505 TopoDS_Face oldWorkSpain = myWorkSpine;
507 TopTools_ListOfShape BadEdges;
508 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
510 if(!BadEdges.IsEmpty())
512 // Modification of myWorkSpine;
513 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
514 BRepTools_Substitution aSubst;
515 TopTools_ListIteratorOfListOfShape it(BadEdges);
516 TopTools_ListOfShape aL;
517 Standard_Real aDefl = .01 * Abs(Offset);
518 TColStd_SequenceOfReal Parameters;
519 TColgp_SequenceOfPnt Points;
521 for(; it.More(); it.Next()) {
525 const TopoDS_Shape& anE = it.Value();
527 TopoDS_Vertex Vf, Vl;
528 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
531 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
532 GeomAdaptor_Curve AC(G3d,f,l);
534 PerformCurve(Parameters, Points, AC, aDefl, f,
535 l, Precision::Confusion(), 2);
537 Standard_Integer NPnts = Points.Length();
540 //cout << NPnts << " points " << endl;
541 TopoDS_Vertex FV = Vf;
545 for(np = 2; np < NPnts; np++) {
546 gp_Pnt LP = Points(np);
547 LV = BRepLib_MakeVertex(LP);
548 newE = BRepLib_MakeEdge(FV, LV);
553 newE = BRepLib_MakeEdge(FV, LV);
558 //cout << " 2 points " << endl;
559 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
563 if (myMapSpine.IsBound( anE ))
565 TopTools_ListIteratorOfListOfShape newit( aL );
566 for (; newit.More(); newit.Next())
568 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
569 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
570 TopoDS_Vertex NewV1, NewV2;
571 EdgeVertices( NewEdge, NewV1, NewV2 );
572 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
573 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
575 myMapSpine.UnBind( anE );
578 aSubst.Substitute(anE, aL);
581 TopTools_DataMapOfShapeListOfShape wwmap;
582 TopoDS_Iterator itws( myWorkSpine );
583 for (; itws.More(); itws.Next())
585 TopoDS_Shape aWire = itws.Value();
586 aSubst.Build( aWire );
587 if (aSubst.IsCopied(aWire))
589 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
590 NewWire.Closed( aWire.Closed() );
591 TopTools_ListOfShape Lw;
592 Lw.Append( NewWire );
593 wwmap.Bind( aWire, Lw );
597 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
598 for (; itmap.More(); itmap.Next())
599 aSubst.Substitute( itmap.Key(), itmap.Value() );
601 aSubst.Build(myWorkSpine);
603 if(aSubst.IsCopied(myWorkSpine)) {
604 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
605 //sprintf(name,"WS1");
606 //DBRep::Set(name,myWorkSpine);
608 BRepMAT2d_Explorer newExp;
609 newExp.Perform(myWorkSpine);
610 BRepMAT2d_BisectingLocus newBilo;
611 BRepMAT2d_LinkTopoBilo newLink;
612 newBilo.Compute(newExp,1,MAT_Left);
614 if(!newBilo.IsDone())
617 myIsDone = Standard_False;
621 newLink.Perform(newExp,newBilo);
622 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
623 myWorkSpine = oldWorkSpain;
626 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
631 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
634 catch (...)//Every exception was caught.
637 myIsDone = Standard_False;
638 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
639 Standard_Failure::Caught()->Print(cout);
645 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
646 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
647 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
649 for (; anExp.More(); anExp.Next()) {
650 const TopoDS_Shape &aWire = anExp.Current();
652 if (!aWire.Closed()) {
654 myIsDone = Standard_False;
655 Standard_ConstructionError::Raise("Offset wire is not closed.");
658 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
661 //=======================================================================
664 //=======================================================================
666 void Compute (const TopoDS_Face& Spine,
667 TopoDS_Shape& aShape,
668 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
669 const Standard_Real Alt)
672 B.MakeCompound(TopoDS::Compound(aShape));
673 Standard_Real ALT = Alt;
674 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
676 T.SetTranslation(gp_Vec(0.,0.,ALT));
677 TopLoc_Location L(T);
679 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
680 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
681 TopoDS_Shape aLocalShape = CurW.Moved(L);
682 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
683 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
686 TopoDS_Iterator it1( CurW);
687 TopoDS_Iterator it2( NewW);
688 for ( ; it1.More(); it1.Next(), it2.Next()) {
689 TopTools_ListOfShape List;
690 List.Append(it2.Value());
691 Map.Add(it1.Value(), List);
696 //=======================================================================
697 //function : PerformWithBiLo
699 //=======================================================================
701 void BRepFill_OffsetWire::PerformWithBiLo
702 (const TopoDS_Face& Spine,
703 const Standard_Real Offset,
704 const BRepMAT2d_BisectingLocus& Locus,
705 BRepMAT2d_LinkTopoBilo& Link,
706 const GeomAbs_JoinType Join,
707 const Standard_Real Alt)
709 Standard_NotImplemented_Raise_if (Join > GeomAbs_Arc,
710 "Only GeomAbs_Arc is implemented");
712 myIsDone = Standard_False;
713 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
714 myWorkSpine = TopoDS::Face(aLocalShape);
715 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
721 if (mySpine.IsNull()) {
722 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
723 mySpine = TopoDS::Face(aLocalShape);
724 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
728 if ( Abs(myOffset) < Precision::Confusion()) {
729 Compute(mySpine,myShape,myMap,Alt);
730 myIsDone = Standard_True;
734 //********************************
735 // Calculate for a non null offset
736 //********************************
737 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone))
740 BRep_Builder myBuilder;
741 myBuilder.MakeCompound(TopoDS::Compound(myShape));
743 //---------------------------------------------------------------------
744 // MapNodeVertex : associate to each node of the map (key1) and to
745 // each element of the profile (key2) a vertex (item).
746 // MapBis : all edges or vertices (item) generated by
747 // a bisectrice on a face or an edge (key) of revolution tubes.
748 // MapVerPar : Map of parameters of vertices on parallel edges
749 // the list contained in MapVerPar (E) corresponds to
750 // parameters on E of vertices contained in MapBis(E);
751 //---------------------------------------------------------------------
754 BRepFill_DataMapOfNodeShape MapNodeVertex;
755 TopTools_DataMapOfShapeSequenceOfShape MapBis;
756 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
758 TopTools_DataMapOfShapeShape EmptyMap;
759 TopTools_SequenceOfShape EmptySeq;
760 TopTools_ListOfShape EmptyList;
761 TColStd_SequenceOfReal EmptySeqOfReal;
763 Standard_Real ALT = Alt;
764 Handle(Geom_Plane) RefPlane =
765 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
766 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
767 RefPlane = Handle(Geom_Plane)::DownCast
768 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
770 //---------------------------------------------------------------
771 // Construction of Circles and OffsetCurves
772 //---------------------------------------------------------------
774 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
775 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
776 TopoDS_Shape& PE = PEE ;
777 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
778 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
779 if (SE.ShapeType() == TopAbs_VERTEX) {
780 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
781 myWorkSpine,myOffset,myMap,RefPlane);
784 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane);
793 cout << " End Construction of geometric primitives "<<endl;
798 //---------------------------------------------------
799 // Construction of offset vertices.
800 //---------------------------------------------------
801 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
802 Handle(MAT_Arc) CurrentArc;
803 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
804 Handle(Geom_Curve) CBis;
805 Standard_Boolean Reverse;
806 TopoDS_Edge CurrentEdge;
810 Standard_Integer j, k;
812 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
814 CurrentArc = Locus.Graph()->Arc(i);
815 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
819 sprintf(name,"BISSEC_%d",NbBISSEC++);
820 DrawTrSurf::Set(name,Bisec.Value());
824 //-------------------------------------------------------------------
825 // Return elements of the spine corresponding to separate basicElts.
826 //-------------------------------------------------------------------
827 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
828 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
830 TopTools_SequenceOfShape Vertices;
831 TColgp_SequenceOfPnt Params;
833 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
834 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
836 //-----------------------------------------------------------
837 // Return parallel edges on each face.
838 // If no offset generated => move to the next bissectrice.
839 //--------------------------------------------------------------
840 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
841 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
842 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
846 //-----------------------------------------------------------
847 // Construction of vertices corresponding to the node of the map.
848 // if they are on the offset.
849 //-----------------------------------------------------------
851 Handle(MAT_Node) Node1, Node2;
854 Node1 = CurrentArc->SecondNode();
855 Node2 = CurrentArc->FirstNode();
858 Node1 = CurrentArc->FirstNode();
859 Node2 = CurrentArc->SecondNode();
862 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
864 if (!Node1->Infinite()) {
865 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
866 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
867 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
868 // MapNodeVertex,VS);
870 if (!Node2->Infinite()) {
871 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
872 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
873 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
874 // MapNodeVertex,VE);
877 //---------------------------------------------
878 // Construction of geometries.
879 //---------------------------------------------
880 BRepFill_TrimEdgeTool Trim (Bisec,
881 Locus.GeomElt(CurrentArc->FirstElement()),
882 Locus.GeomElt(CurrentArc->SecondElement()),
885 //-----------------------------------------------------------
886 // Construction of vertices on edges parallel to the spine.
887 //-----------------------------------------------------------
889 Trim.IntersectWith(E [0], E [1], Params);
891 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
893 myBuilder.MakeVertex (VC);
894 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
895 gp_Pnt PVC(P2.X(),P2.Y(),0.);
897 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
901 Standard_Boolean Start = 1;
902 Trim.AddOrConfuse(Start, E[0], E[1], Params);
903 if (Params.Length() == Vertices.Length())
904 Vertices.SetValue(1,VS);
907 // the point was not found by IntersectWith
908 Vertices.Prepend(VS);
911 Standard_Boolean Start = 0;
912 Trim.AddOrConfuse(Start, E[0], E[1], Params);
913 if (Params.Length() == Vertices.Length())
914 Vertices.SetValue(Params.Length(),VE);
917 // the point was not found by IntersectWith
921 //------------------------------------------------------------
923 // Detromp allows to remove vertices on the offset
924 // corresponding to tangency zones
925 // Detromp ranks the vertices that limit
926 // the parts of the bissectrices located between the spine and the
928 //------------------------------------------------------------
929 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
930 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
933 UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params,
934 Bisec, StartOnEdge, EndOnEdge, Trim);
935 //----------------------------------------------
936 // Storage of vertices on parallel edges.
937 // fill MapBis and MapVerPar.
938 //----------------------------------------------
939 if (!Vertices.IsEmpty()) {
940 for (k = 0; k <= 1; k++) {
941 if (!MapBis.IsBound(E[k])) {
942 MapBis .Bind(E[k],EmptySeq);
943 MapVerPar.Bind(E[k],EmptySeqOfReal);
945 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
946 MapBis (E[k]).Append(Vertices.Value(ii));
947 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
948 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
953 //------------------------------------------------------------
954 // FOR COMPLETE CIRCLES. the parallel line can be contained
955 // in the zone without intersection with the border
957 // if myoffset is < distance of nodes the parallel can be valid.
958 //-------------------------------------------------------------
959 for (k = 0; k <= 1; k++) {
960 if (!MapBis.IsBound(E[k])) {
961 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
962 MapBis .Bind(E[k],EmptySeq);
963 MapVerPar.Bind(E[k],EmptySeqOfReal);
972 cout << " End Construction of vertices on offsets"<<endl;
976 //----------------------------------
977 // Construction of parallel edges.
978 //----------------------------------
979 TopTools_IndexedDataMapOfShapeShape MapVV;
981 TopoDS_Shape CurrentSpine;
983 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
985 for (j = 1; j <= myMap.Extent(); j++) {
986 CurrentSpine = myMap.FindKey(j);
987 CurrentEdge = TopoDS::Edge(myMap(j).First());
990 if (MapBis.IsBound(CurrentEdge)) {
991 TopTools_SequenceOfShape S;
992 if (!MapBis(CurrentEdge).IsEmpty()) {
993 TrimEdge (CurrentEdge,
994 Detromp (CurrentSpine),
995 MapBis (CurrentEdge) ,
996 MapVerPar(CurrentEdge) ,
998 for ( k = 1; k <= S.Length(); k++) {
999 myMap(j).Append(S.Value(k));
1006 myMap(j).Append(CurrentEdge);
1011 Standard_Integer ind;
1012 for (ind = 1; ind <= MapVV.Extent(); ind++)
1014 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1015 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1016 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1017 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1018 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1019 TopTools_ListOfShape LV;
1020 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1021 BRepTools_Substitution aSubst;
1022 aSubst.Substitute( OldV, LV );
1023 for (j = 1; j <= myMap.Extent(); j++)
1025 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1026 for (; itl.More(); itl.Next())
1028 aSubst.Build(itl.Value());
1029 if (aSubst.IsCopied(itl.Value()))
1031 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1032 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1033 itl.Value() = listSh.First();
1034 itl.Value().Orientation(SaveOr);
1040 //----------------------------------
1041 // Construction of offset wires.
1042 //----------------------------------
1045 // Update vertices ( Constructed in the plane Z = 0) !!!
1046 TopTools_MapOfShape MapVertex;
1047 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1048 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1049 if ( MapVertex.Add(V)) {
1050 gp_Pnt P = BRep_Tool::Pnt(V);
1051 P = RefPlane->Value(P.X(),P.Y());
1052 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1056 // Construction of curves 3d.
1057 BRepLib::BuildCurves3d(myShape);
1059 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1060 for (; Explo.More(); Explo.Next())
1062 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1063 TopoDS_Vertex V1, V2;
1064 TopExp::Vertices( E, V1, V2 );
1065 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1066 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1068 TopLoc_Location loc;
1070 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1071 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1072 theCurve->Transform( loc.Transformation() );
1073 gp_Pnt f3d = theCurve->Value( f );
1074 gp_Pnt l3d = theCurve->Value( l );
1076 Standard_Real dist1, dist2;
1077 dist1 = f3d.Distance( TV1->Pnt() );
1078 dist2 = l3d.Distance( TV2->Pnt() );
1079 if (! MapVertex.Contains( V1 ))
1082 MapVertex.Add( V1 );
1085 TV1->UpdateTolerance( 1.5*dist1 );
1086 if (! MapVertex.Contains( V2 ))
1089 MapVertex.Add( V2 );
1092 TV2->UpdateTolerance( 1.5*dist2 );
1097 myIsDone = Standard_True;
1101 //=======================================================================
1102 //function : Generated
1104 //=======================================================================
1106 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1107 BRepFill_OffsetWire::Generated()
1113 //=======================================================================
1114 //function : PrepareSpine
1116 //=======================================================================
1118 void BRepFill_OffsetWire::PrepareSpine()
1121 TopTools_ListOfShape Cuts;
1122 TopTools_ListIteratorOfListOfShape IteCuts;
1123 TopoDS_Vertex V1,V2;
1125 myWorkSpine.Nullify();
1129 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1130 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1131 B.MakeFace(myWorkSpine,S,L,TolF);
1133 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1138 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1139 Standard_Integer ForcedCut = 0;
1140 Standard_Integer nbResEdges = -1;
1141 TopTools_IndexedMapOfShape EdgeMap;
1143 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1144 Standard_Integer nbEdges = EdgeMap.Extent();
1148 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1150 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1152 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1153 EdgeVertices(E,V1,V2);
1154 myMapSpine.Bind(V1,V1);
1155 myMapSpine.Bind(V2,V2);
1159 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1160 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1161 if (nbEdges == 2 && nbResEdges == 0)
1163 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1164 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1166 if (Cuts.IsEmpty()) {
1168 myMapSpine.Bind(E,E);
1171 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1172 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1173 NE.Orientation(E.Orientation());
1175 myMapSpine.Bind(NE,E);
1176 EdgeVertices(NE,V1,V2);
1177 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1178 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1182 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1186 TopExp::Vertices(NW, aV1, aV2);
1188 NW.Closed(aV1.IsSame(aV2));
1189 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1190 B.Add(myWorkSpine, NW);
1196 DBRep::Set(name,myWorkSpine);
1202 //=======================================================================
1203 //function : MakeWires
1205 //=======================================================================
1207 void BRepFill_OffsetWire::MakeWires()
1209 //--------------------------------------------------------
1210 // creation of a single list of created parallel edges.
1211 //--------------------------------------------------------
1212 TopTools_SequenceOfShape TheEdges;
1213 TopTools_ListOfShape TheWires;
1214 TopTools_ListIteratorOfListOfShape itl;
1215 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1216 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1217 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1218 TopoDS_Vertex V1,V2,VF,CV;
1221 for (i = 1; i <= myMap.Extent(); i++) {
1222 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1223 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1224 TopExp::Vertices (E,V1,V2);
1225 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1226 continue; //remove small closed edges
1227 if (!MVE.Contains(V1)) {
1228 TopTools_ListOfShape empty;
1231 MVE.ChangeFromKey(V1).Append(E);
1232 if (!MVE.Contains(V2)) {
1233 TopTools_ListOfShape empty;
1236 MVE.ChangeFromKey(V2).Append(E);
1240 //--------------------------------------
1241 // Creation of parallel wires.
1242 //--------------------------------------
1245 // Standard_Integer NbEdges;
1246 // Standard_Boolean NewWire = Standard_True;
1247 // Standard_Boolean AddEdge = Standard_False;
1250 Standard_Boolean End;
1253 while (!MVE.IsEmpty()) {
1256 //MVEit.Initialize(MVE);
1257 for (i = 1; i <= MVE.Extent(); i++)
1258 if(MVE(i).Extent() == 1)
1261 //if(!MVEit.More()) MVEit.Initialize(MVE);
1262 if (i > MVE.Extent())
1265 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1266 CE = TopoDS::Edge(MVE(i).First());
1267 End = Standard_False;
1268 MVE.ChangeFromKey(CV).RemoveFirst();
1270 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1271 Standard_Boolean isClosed = Standard_False;
1272 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1275 //-------------------------------
1276 // Construction of a wire.
1277 //-------------------------------
1278 TopExp::Vertices(CE,V1,V2);
1279 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1283 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1284 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1285 isClosed = VF.IsSame(CV);
1286 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1287 End = Standard_True;
1289 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1290 TopTools_ListOfShape LastList;
1291 LastList.Append(MVE(MVE.Extent()));
1293 if (MVE.FindIndex(VF) != 0)
1294 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1298 if (MVE.FindFromKey(CV).Extent() > 2) {
1299 //cout <<"vertex on more that 2 edges in a face."<<endl;
1301 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1302 if (itl.Value().IsSame(CE)) {
1303 MVE.ChangeFromKey(CV).Remove(itl);
1307 if (!MVE.FindFromKey(CV).IsEmpty()) {
1308 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1309 MVE.ChangeFromKey(CV).RemoveFirst();
1311 if (MVE.FindFromKey(CV).IsEmpty())
1314 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1315 TopTools_ListOfShape LastList;
1316 LastList.Append(MVE(MVE.Extent()));
1318 if (MVE.FindIndex(CV) != 0)
1319 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1323 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1324 // NW.Closed(Standard_True);
1325 NW.Closed(isClosed);
1326 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1327 TheWires.Append(NW);
1331 // -- if only one wire : myShape is a Wire
1332 // -- if several wires : myShape is a Compound.
1333 if ( TheWires.Extent() == 1) {
1334 myShape = TheWires.First();
1339 TopTools_ListIteratorOfListOfShape it(TheWires);
1340 for ( ; it.More(); it.Next()) {
1341 B.Add(R, it.Value());
1348 //=======================================================================
1349 //function : FixHoles
1351 //=======================================================================
1353 void BRepFill_OffsetWire::FixHoles()
1355 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1357 Standard_Real MaxTol = 0.;
1361 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1362 for (; Explo.More(); Explo.Next())
1364 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1365 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1371 Explo.Init( myShape, TopAbs_WIRE );
1372 for (; Explo.More(); Explo.Next())
1374 TopoDS_Shape aWire = Explo.Current();
1375 // Remove duplicated edges
1376 TopTools_DataMapOfShapeListOfShape EEmap;
1377 TopoDS_Iterator it( aWire );
1378 for (; it.More(); it.Next())
1380 const TopoDS_Shape& anEdge = it.Value();
1381 if (! EEmap.IsBound( anEdge ))
1383 TopTools_ListOfShape LE;
1384 EEmap.Bind( anEdge, LE );
1387 EEmap(anEdge).Append( anEdge );
1389 aWire.Free( Standard_True );
1390 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1391 for (; mapit.More(); mapit.Next())
1393 const TopTools_ListOfShape& LE = mapit.Value();
1394 TopTools_ListIteratorOfListOfShape itl( LE );
1395 for (; itl.More(); itl.Next())
1396 BB.Remove( aWire, itl.Value() );
1400 ClosedWires.Append( aWire );
1402 UnclosedWires.Append( aWire );
1405 while (!UnclosedWires.IsEmpty())
1407 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1408 TopoDS_Vertex Vf, Vl;
1409 TopExp::Vertices( Base, Vf, Vl );
1410 if(Vf.IsNull() || Vl.IsNull())
1411 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1413 Pf = BRep_Tool::Pnt(Vf);
1414 Pl = BRep_Tool::Pnt(Vl);
1415 Standard_Real DistF = RealLast(), DistL = RealLast();
1416 Standard_Integer IndexF = 1, IndexL = 1;
1417 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1418 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1420 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1421 TopoDS_Vertex V1, V2;
1422 TopExp::Vertices( aWire, V1, V2 );
1424 if(V1.IsNull() || V2.IsNull())
1425 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1428 P1 = BRep_Tool::Pnt(V1);
1429 P2 = BRep_Tool::Pnt(V2);
1430 Standard_Real dist = Pf.Distance( P1 );
1435 IsFirstF = Standard_True;
1437 dist = Pf.Distance( P2 );
1442 IsFirstF = Standard_False;
1444 dist = Pl.Distance( P1 );
1449 IsFirstL = Standard_True;
1451 dist = Pl.Distance( P2 );
1456 IsFirstL = Standard_False;
1459 TopoDS_Wire theWire;
1460 TopoDS_Edge theEdge;
1461 TopoDS_Vertex theVertex;
1462 Standard_Real CommonTol;
1463 Standard_Boolean TryToClose = Standard_True;
1464 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1476 TryToClose = Standard_False;
1478 if (DistF <= MaxTol)
1480 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1481 TopoDS_Vertex V1, V2;
1482 TopExp::Vertices( theWire, V1, V2 );
1483 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1484 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1485 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1486 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1487 TopoDS_Iterator it( theWire );
1488 for (; it.More(); it.Next())
1490 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1491 if (IsFirstF) anEdge.Reverse();
1492 if (!anEdge.IsSame( theEdge ))
1493 BB.Add( Base, anEdge );
1495 theVertex = (IsFirstF)? V1 : V2;
1496 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1497 if (DistF <= CommonTol)
1499 theEdge.Free( Standard_True );
1500 Vf.Orientation( theVertex.Orientation() );
1501 BB.Remove( theEdge, theVertex );
1502 BB.Add( theEdge, Vf );
1503 BB.UpdateVertex( Vf, CommonTol );
1504 if (IsFirstF) theEdge.Reverse();
1505 BB.Add( Base, theEdge );
1509 if (IsFirstF) theEdge.Reverse();
1510 BB.Add( Base, theEdge );
1511 // Creating new edge from theVertex to Vf
1512 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1513 BB.Add( Base, NewEdge );
1516 if (DistL <= MaxTol && IndexL != IndexF)
1518 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1519 TopoDS_Vertex V1, V2;
1520 TopExp::Vertices( theWire, V1, V2 );
1521 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1522 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1523 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1524 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1525 TopoDS_Iterator it( theWire );
1526 for (; it.More(); it.Next())
1528 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1529 if (!IsFirstL) anEdge.Reverse();
1530 if (!anEdge.IsSame( theEdge ))
1531 BB.Add( Base, anEdge );
1533 theVertex = (IsFirstL)? V1 : V2;
1534 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1535 if (DistL <= CommonTol)
1537 theEdge.Free( Standard_True );
1538 Vl.Orientation( theVertex.Orientation() );
1539 BB.Remove( theEdge, theVertex );
1540 BB.Add( theEdge, Vl );
1541 BB.UpdateVertex( Vl, CommonTol );
1542 if (!IsFirstL) theEdge.Reverse();
1543 BB.Add( Base, theEdge );
1547 if (!IsFirstL) theEdge.Reverse();
1548 BB.Add( Base, theEdge );
1549 // Creating new edge from Vl to theVertex
1550 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1551 BB.Add( Base, NewEdge );
1554 // Check if it is possible to close resulting wire
1557 TopExp::Vertices( Base, Vf, Vl );
1558 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1559 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1560 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1561 TopoDS_Edge Efirst, Elast;
1562 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1563 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1564 Pf = BRep_Tool::Pnt(Vf);
1565 Pl = BRep_Tool::Pnt(Vl);
1566 Standard_Real Dist = Pf.Distance(Pl);
1567 if (Dist <= CommonTol)
1569 Elast.Free( Standard_True );
1570 Vf.Orientation( Vl.Orientation() );
1571 BB.Remove( Elast, Vl );
1572 BB.Add( Elast, Vf );
1573 BB.UpdateVertex( Vf, CommonTol );
1574 Base.Closed( Standard_True );
1576 else if (Dist <= MaxTol)
1578 // Creating new edge from Vl to Vf
1579 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1580 BB.Add( Base, NewEdge );
1581 Base.Closed( Standard_True );
1584 // Updating sequences ClosedWires and UnclosedWires
1585 if (DistF <= MaxTol)
1586 UnclosedWires.Remove( IndexF );
1587 if (DistL <= MaxTol && IndexL != IndexF)
1589 if (DistF <= MaxTol && IndexL > IndexF)
1591 UnclosedWires.Remove( IndexL );
1595 ClosedWires.Append( Base );
1596 UnclosedWires.Remove( 1 );
1598 else if (DistF > MaxTol && DistL > MaxTol)
1600 IsolatedWires.Append( Base );
1601 UnclosedWires.Remove( 1 );
1606 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1608 if (!ClosedWires.IsEmpty())
1609 myShape = ClosedWires.First();
1611 myShape = IsolatedWires.First();
1616 BB.MakeCompound( R );
1617 for (i = 1; i <= ClosedWires.Length(); i++)
1618 BB.Add( R, ClosedWires(i) );
1619 for (i = 1; i <= IsolatedWires.Length(); i++)
1620 BB.Add( R, IsolatedWires(i) );
1625 //=======================================================================
1626 //function : CutEdge
1627 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1628 // So, closed circles are cut in two.
1629 // If <Cuts> is empty, the edge is not modified.
1630 // The first and the last vertex of the initial edge
1631 // belong to the first and the last parts respectively.
1632 //=======================================================================
1633 Standard_Integer CutEdge (const TopoDS_Edge& E,
1634 const TopoDS_Face& F,
1635 Standard_Integer ForceCut,
1636 TopTools_ListOfShape& Cuts)
1639 MAT2d_CutCurve Cuter;
1640 TColGeom2d_SequenceOfCurve theCurves;
1642 Handle(Geom2d_Curve) C2d;
1643 Handle(Geom2d_TrimmedCurve) CT2d;
1644 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1645 Standard_Real aTol = BRep_Tool::Tolerance(E);
1646 Handle(Geom_Curve) aC;
1647 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1649 TopoDS_Vertex V1,V2,VF,VL;
1650 TopExp::Vertices (E,V1,V2);
1653 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1654 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1655 aC = BRep_Tool::Curve(E,f,l);
1656 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1657 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1658 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1660 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1661 ( Abs(f-l) >= M_PI) ) {
1665 //-------------------------
1667 //-------------------------
1668 Cuter.Perform(CT2d);
1670 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1671 if (ForceCut == 0) {
1672 if (Cuter.UnModified()) {
1673 //-----------------------------
1674 // edge not modified => return.
1675 //-----------------------------
1678 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1679 theCurves.Append(Cuter.Value(k));
1681 } else if (ForceCut == 1) {
1682 if (Cuter.UnModified()) {
1683 CutCurve (CT2d, 2, theCurves);
1685 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1686 theCurves.Append(Cuter.Value(k));
1688 } else if (ForceCut == 2) {
1689 if (Cuter.UnModified()) {
1690 CutCurve (CT2d, 3, theCurves);
1692 if (Cuter.NbCurves() == 2) {
1693 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1695 if (CC->LastParameter() > (l+f)/2.) {
1696 CutCurve (CC, 2, theCurves);
1697 theCurves.Append(Cuter.Value(2));
1699 theCurves.Append(CC);
1700 CutCurve (Cuter.Value(2), 2, theCurves);
1703 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1704 theCurves.Append(Cuter.Value(k));
1708 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1710 //--------------------------------------
1711 // Creation of cut edges.
1712 //--------------------------------------
1715 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1717 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1719 if (k == theCurves.Length()) {VL = V2;}
1721 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1722 gp_Pnt P = aC->Value(CC->LastParameter());
1724 VL = BRepLib_MakeVertex(P);
1725 B.UpdateVertex(VL, aTol);
1726 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1728 TopoDS_Shape aLocalShape = E.EmptyCopied();
1729 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1730 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1731 NE.Orientation(TopAbs_FORWARD);
1732 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1733 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1734 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1735 Cuts.Append(NE.Oriented(E.Orientation()));
1739 return theCurves.Length();
1742 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1743 //=======================================================================
1744 //function : CutCurve
1746 //=======================================================================
1748 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1749 const Standard_Integer nbParts,
1750 TColGeom2d_SequenceOfCurve& theCurves)
1752 Handle(Geom2d_TrimmedCurve) TrimC;
1753 Standard_Real UF,UL,UC;
1756 Standard_Real PTol = Precision::PConfusion()*10;
1757 Standard_Real Tol = Precision::Confusion()*10;
1758 Standard_Boolean YaCut = Standard_False;
1760 UF = C->FirstParameter();
1761 UL = C->LastParameter ();
1765 Step = (UL - UF)/nbParts;
1767 for (Standard_Integer i = 1; i < nbParts; i++) {
1772 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1773 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1776 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1777 theCurves.Append(TrimC);
1780 YaCut = Standard_True;
1784 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1785 theCurves.Append(TrimC);
1787 theCurves.Append(C);
1789 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1791 //=======================================================================
1792 //function : MakeCircle
1794 //=======================================================================
1796 void MakeCircle (const TopoDS_Edge& E,
1797 const TopoDS_Vertex& V,
1798 const TopoDS_Face& F,
1799 const Standard_Real Offset,
1800 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1801 const Handle(Geom_Plane)& RefPlane)
1803 // evaluate the Axis of the Circle.
1805 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1809 if (E.Orientation() == TopAbs_FORWARD) {
1813 else GC->D1(f,P,DX);
1815 gp_Ax2d Axis(P,gp_Dir2d(DX));
1816 Handle(Geom2d_Circle) Circ
1817 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1819 // Bind the edges in my Map.
1820 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1821 TopTools_ListOfShape LL;
1827 if ( AffichGeom && !OE.IsNull()) {
1828 sprintf(name,"OFFSET_%d",++NbOFFSET);
1829 DBRep::Set(name,OE);
1834 //=======================================================================
1835 //function : MakeOffset
1837 //=======================================================================
1839 void MakeOffset (const TopoDS_Edge& E,
1840 const TopoDS_Face& F,
1841 const Standard_Real Offset,
1842 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1843 const Handle(Geom_Plane)& RefPlane)
1846 Standard_Real anOffset = Offset;
1848 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1850 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1851 Handle(Geom2d_Curve) G2dOC;
1853 Geom2dAdaptor_Curve AC(G2d,f,l);
1854 if ( AC.GetType() == GeomAbs_Circle) {
1855 // if the offset is greater otr equal to the radius and the side of the
1856 // concavity of the circle => edge null.
1857 gp_Circ2d C1(AC.Circle());
1858 gp_Ax22d axes( C1.Axis());
1859 gp_Dir2d Xd = axes.XDirection();
1860 gp_Dir2d Yd = axes.YDirection();
1861 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1862 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1864 if (anOffset*Signe < AC.Circle().Radius()) {
1866 Handle(Geom2dAdaptor_HCurve) AHC =
1867 new Geom2dAdaptor_HCurve(G2d);
1868 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1869 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1871 Standard_Real Delta = 2*M_PI - l + f;
1872 f -= 0.2*Delta; l += 0.2*Delta;
1874 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1877 else if (AC.GetType() == GeomAbs_Line) {
1878 Handle(Geom2dAdaptor_HCurve) AHC =
1879 new Geom2dAdaptor_HCurve(G2d);
1880 Adaptor3d_OffsetCurve Off(AHC,anOffset);
1881 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
1882 Standard_Real Delta = (l - f);
1883 f -= Delta; l += Delta;
1884 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1888 anOffset = -anOffset;
1889 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
1890 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
1894 // Bind the edges in my Map.
1895 if (!G2dOC.IsNull()) {
1896 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
1897 OE.Orientation(E.Orientation());
1898 TopTools_ListOfShape LL;
1903 if (AffichGeom && !OE.IsNull()) {
1904 sprintf(name,"OFFSET_%d",++NbOFFSET);
1905 DBRep::Set(name,OE);
1906 Standard_Real ii = 0;
1913 //=======================================================================
1914 //function : UpdateDetromp
1915 //purpose : For each interval on bissectrice defined by parameters
1916 // test if the medium point is at a distance > offset
1917 // in this case vertices corresponding to the extremities of the interval
1918 // are ranked in the proofing.
1919 // => If the same vertex appears in the proofing, the
1920 // border of the zone of proximity is tangent to the offset .
1921 //=======================================================================
1923 void UpdateDetromp (TopTools_ListOfShape& Detromp1,
1924 TopTools_ListOfShape& Detromp2,
1925 const TopTools_SequenceOfShape& Vertices,
1926 const TColgp_SequenceOfPnt& Params,
1927 const Bisector_Bisec& Bisec,
1928 const Standard_Boolean SOnE,
1929 const Standard_Boolean EOnE,
1930 const BRepFill_TrimEdgeTool& Trim)
1932 Standard_Integer ii = 1;
1933 Standard_Real U1,U2;
1934 TopoDS_Vertex V1,V2;
1936 Handle(Geom2d_Curve) Bis = Bisec.Value();
1938 U1 = Bis->FirstParameter();
1941 // the first point of the bissectrice is on the offset
1942 V1 = TopoDS::Vertex(Vertices.Value(ii));
1946 while (ii <= Vertices.Length()) {
1947 U2 = Params.Value(ii).X();
1948 V2 = TopoDS::Vertex(Vertices.Value(ii));
1950 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1951 if (!Trim.IsInside(P)) {
1953 Detromp1.Append(V1);
1954 Detromp2.Append(V1);
1956 Detromp1.Append(V2);
1957 Detromp2.Append(V2);
1964 // test medium point between the last parameter and the end of the bissectrice.
1965 U2 = Bis->LastParameter();
1967 if (!Precision::IsInfinite(U2)) {
1968 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1969 if (!Trim.IsInside(P)) {
1971 Detromp1.Append(V1);
1972 Detromp2.Append(V1);
1978 Detromp1.Append(V1);
1979 Detromp2.Append(V1);
1985 //=======================================================================
1986 //function : VertexFromNode
1988 //=======================================================================
1990 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
1991 const Standard_Real Offset,
1993 BRepFill_DataMapOfNodeShape& MapNodeVertex,
1996 Standard_Boolean Status;
1997 Standard_Real Tol = Precision::Confusion();
2000 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2001 //------------------------------------------------
2002 // the Node gives a vertex on the offset
2003 //------------------------------------------------
2004 if (MapNodeVertex.IsBound(aNode)) {
2005 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2008 gp_Pnt P(PN.X(),PN.Y(),0.);
2010 B.UpdateVertex(VN,P, Precision::Confusion());
2011 MapNodeVertex.Bind(aNode,VN);
2013 Status = Standard_True;
2015 else Status = Standard_False;
2021 //=======================================================================
2022 //function : StoreInMap
2024 //=======================================================================
2026 void StoreInMap (const TopoDS_Shape& V1,
2027 const TopoDS_Shape& V2,
2028 TopTools_IndexedDataMapOfShapeShape& MapVV)
2030 TopoDS_Shape OldV = V1, NewV = V2;
2033 if (MapVV.Contains(V2))
2034 NewV = MapVV.FindFromKey(V2);
2036 if (MapVV.Contains(V1))
2037 MapVV.ChangeFromKey(V1) = NewV;
2039 for (i = 1; i <= MapVV.Extent(); i++)
2040 if (MapVV(i).IsSame(V1))
2043 MapVV.Add(V1, NewV);
2046 //=======================================================================
2047 //function : TrimEdge
2049 //=======================================================================
2051 void TrimEdge (const TopoDS_Edge& E,
2052 const TopTools_ListOfShape& Detromp,
2053 TopTools_SequenceOfShape& TheVer,
2054 TColStd_SequenceOfReal& ThePar,
2055 TopTools_SequenceOfShape& S,
2056 TopTools_IndexedDataMapOfShapeShape& MapVV)
2058 Standard_Boolean Change = Standard_True;
2059 BRep_Builder TheBuilder;
2062 //-----------------------------------------------------------
2063 // Parse two sequences depending on the parameter on the edge.
2064 //-----------------------------------------------------------
2066 Change = Standard_False;
2067 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2068 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2069 ThePar.Exchange(i,i+1);
2070 TheVer.Exchange(i,i+1);
2071 Change = Standard_True;
2076 //----------------------------------------------------------
2077 // If a vertex is not in the proofing, it is eliminated.
2078 //----------------------------------------------------------
2079 if (!BRep_Tool::Degenerated(E)) {
2080 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2081 if ( DoubleOrNotInside (Detromp,
2082 TopoDS::Vertex(TheVer.Value(k)))) {
2090 //----------------------------------------------------------
2091 // If a vertex_double appears twice in the proofing
2092 // the vertex is removed.
2093 // otherwise preserve only one of its representations.
2094 //----------------------------------------------------------
2095 if (!BRep_Tool::Degenerated(E)) {
2096 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2097 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2098 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2100 if(k+1 == TheVer.Length()) {
2101 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2106 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2111 if ( DoubleOrNotInside (Detromp,
2112 TopoDS::Vertex(TheVer.Value(k)))) {
2122 //-----------------------------------------------------------
2123 // Creation of edges.
2124 // the number of vertices should be even. The created edges
2125 // go from a vertex with uneven index i to vertex i+1;
2126 //-----------------------------------------------------------
2127 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2128 TopoDS_Shape aLocalShape = E.EmptyCopied();
2129 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2130 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2132 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2133 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2134 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2137 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2138 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2142 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2146 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2147 DBRep::Set(name,NewEdge);
2152 Handle(Geom_Surface) Surf;
2153 Handle(Geom2d_Curve) C;
2154 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2155 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2156 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2157 Handle(DrawTrSurf_Curve2d) dr =
2158 new DrawTrSurf_Curve2d(C2d,Standard_False);
2159 dr->SetColor(Draw_bleu);
2168 //=======================================================================
2169 //function : DoubleOrNotInside
2170 //purpose : return True if V appears twice in LV or is not inside.
2171 //=======================================================================
2173 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2174 const TopoDS_Vertex& V)
2176 Standard_Boolean Vu = Standard_False;
2177 TopTools_ListIteratorOfListOfShape it(LV);
2179 for ( ; it.More(); it.Next()) {
2180 if (V.IsSame(it.Value())) {
2181 if (Vu) return Standard_True;
2182 else Vu = Standard_True;
2185 if (Vu) return Standard_False;
2186 else return Standard_True;
2189 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2190 const TopoDS_Vertex& aVertex)
2192 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2193 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2194 PV2d.SetCoord( PV.X(), PV.Y() );
2196 Handle(Geom2d_Curve) PCurve;
2197 Handle( BRep_CurveRepresentation ) CurveRep =
2198 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2199 PCurve = CurveRep->PCurve();
2201 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2202 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2203 Pfirst = PCurve->Value(fpar);
2204 Plast = PCurve->Value(lpar);
2205 Pmid = PCurve->Value((fpar + lpar)*0.5);
2207 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2210 Standard_Real dist1 = Pfirst.Distance(PV2d);
2211 Standard_Real dist2 = Plast.Distance(PV2d);
2212 Standard_Real dist3 = Pmid.Distance(PV2d);
2214 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2215 return Standard_True;
2217 return Standard_False;
2220 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2221 const BRepMAT2d_BisectingLocus& Locus,
2222 const BRepMAT2d_LinkTopoBilo& Link,
2223 TopTools_ListOfShape& BadEdges)
2226 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2227 Standard_Real eps = Precision::Confusion();
2228 Standard_Real LimCurv = 1./Offset;
2230 TopTools_MapOfShape aMap;
2232 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2233 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2234 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2235 if (SE.ShapeType() == TopAbs_EDGE) {
2237 if (aMap.Contains(SE)) {
2238 //cout << "Edge is treated second time" << endl;
2242 TopoDS_Edge E = TopoDS::Edge(SE);
2246 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2248 Geom2dAdaptor_Curve AC(G2d,f,l);
2249 GeomAbs_CurveType aCType = AC.GetType();
2251 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2253 Standard_Boolean reverse = Standard_False;
2254 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2259 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2261 aCLProps.SetParameter(f);
2262 if(!aCLProps.IsTangentDefined()) {
2263 BadEdges.Append(SE);
2268 P = aCLProps.Value();
2269 Standard_Real Crv = aCLProps.Curvature();
2272 aCLProps.Tangent(N);
2273 Standard_Real x = N.Y(), y = -N.X();
2275 if (reverse) N.Reverse();
2276 aCLProps.CentreOfCurvature(Pc);
2277 gp_Vec2d Dir( P, Pc );
2278 if (N.Dot(Dir) > 0.) {
2279 if (LimCurv <= Crv + eps) {
2280 BadEdges.Append(SE);
2287 aCLProps.SetParameter(l);
2288 if(!aCLProps.IsTangentDefined()) {
2289 BadEdges.Append(SE);
2294 P = aCLProps.Value();
2295 Crv = aCLProps.Curvature();
2298 aCLProps.Tangent(N);
2299 Standard_Real x = N.Y(), y = -N.X();
2301 if (reverse) N.Reverse();
2302 aCLProps.CentreOfCurvature(Pc);
2303 gp_Vec2d Dir( P, Pc );
2304 if (N.Dot(Dir) > 0.) {
2305 if (LimCurv <= Crv + eps) {
2306 BadEdges.Append(SE);
2319 //=======================================================================
2320 //function : PerformCurve
2322 //=======================================================================
2324 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2325 TColgp_SequenceOfPnt& Points,
2326 const Adaptor3d_Curve& C,
2327 const Standard_Real Deflection,
2328 const Standard_Real U1,
2329 const Standard_Real U2,
2330 const Standard_Real EPSILON,
2331 const Standard_Integer Nbmin)
2333 Standard_Real UU1 = Min(U1, U2);
2334 Standard_Real UU2 = Max(U1, U2);
2338 C.D1(UU1,Pdeb,Ddeb);
2339 Parameters.Append(UU1);
2340 Points.Append(Pdeb);
2342 C.D1(UU2,Pfin,Dfin);
2344 const Standard_Real aDelta = UU2 - UU1;
2345 const Standard_Real aDist = Pdeb.Distance(Pfin);
2347 if((aDelta/aDist) > 5.0e-14)
2349 QuasiFleche(C,Deflection*Deflection,
2359 return Standard_True;
2361 //=======================================================================
2362 //function : QuasiFleche
2364 //=======================================================================
2366 static void QuasiFleche(const Adaptor3d_Curve& C,
2367 const Standard_Real Deflection2,
2368 const Standard_Real Udeb,
2371 const Standard_Real Ufin,
2374 const Standard_Integer Nbmin,
2375 const Standard_Real Eps,
2376 TColStd_SequenceOfReal& Parameters,
2377 TColgp_SequenceOfPnt& Points)
2379 Standard_Integer Ptslength = Points.Length();
2380 Standard_Real Udelta = Ufin-Udeb;
2385 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2393 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2394 Standard_Real theFleche=0;
2395 Standard_Boolean flecheok = Standard_False;
2397 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2398 Standard_Real N1 = Vdeb.SquareMagnitude();
2399 Standard_Real N2 = Vdelta.SquareMagnitude();
2400 if (N1 > Eps && N2 > Eps) {
2401 Standard_Real Normediff =
2402 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2403 if (Normediff > Eps) {
2404 theFleche = Normediff*Norme/64.;
2405 flecheok = Standard_True;
2410 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2411 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2412 theFleche = Pmid.SquareDistance(Pverif);
2415 if (theFleche < Deflection2) {
2416 Parameters.Append(Udeb+Udelta);
2417 Points.Append(Pdelta);
2420 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2431 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2435 Nbmin-(Points.Length()-Ptslength),