1 // Created on: 1995-04-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
26 #include <BRepFill_OffsetWire.ixx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepFill_DataMapOfNodeShape.hxx>
32 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
33 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
34 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
35 #include <BRepFill_TrimEdgeTool.hxx>
36 #include <BRepLib.hxx>
37 #include <BRepLib_MakeVertex.hxx>
38 #include <BRepLib_MakeFace.hxx>
39 #include <BRepLib_MakeWire.hxx>
40 #include <BRepLib_MakeEdge.hxx>
41 #include <BRepTools.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRep_Tool.hxx>
44 #include <BRep_TEdge.hxx>
45 #include <BRep_CurveRepresentation.hxx>
46 #include <BRep_GCurve.hxx>
47 #include <BRepTools_WireExplorer.hxx>
48 #include <BRepMAT2d_Explorer.hxx>
49 #include <Geom2dAdaptor_Curve.hxx>
50 #include <Geom2dAdaptor_HCurve.hxx>
51 #include <Adaptor3d_OffsetCurve.hxx>
52 #include <Adaptor3d_Curve.hxx>
53 #include <Geom_Surface.hxx>
54 #include <Geom_Plane.hxx>
55 #include <Geom2d_Curve.hxx>
56 #include <Geom2d_Circle.hxx>
57 #include <Geom2d_Line.hxx>
58 #include <Geom2d_TrimmedCurve.hxx>
59 #include <Geom2d_OffsetCurve.hxx>
60 #include <GeomAPI.hxx>
61 #include <Geom_TrimmedCurve.hxx>
62 #include <Geom_Circle.hxx>
63 #include <Geom_OffsetCurve.hxx>
64 #include <MAT_Arc.hxx>
65 #include <MAT_Node.hxx>
66 #include <MAT_Graph.hxx>
67 #include <MAT2d_CutCurve.hxx>
68 #include <Precision.hxx>
69 #include <Standard_NotImplemented.hxx>
70 #include <TColgp_SequenceOfPnt.hxx>
71 #include <TColStd_SequenceOfReal.hxx>
74 #include <TopExp_Explorer.hxx>
76 #include <TopoDS_Wire.hxx>
77 #include <TopoDS_Compound.hxx>
78 #include <TopoDS_Iterator.hxx>
79 #include <TopTools_MapOfShape.hxx>
80 #include <TopTools_MapIteratorOfMapOfShape.hxx>
81 #include <TopTools_ListIteratorOfListOfShape.hxx>
82 #include <TopTools_DataMapOfShapeListOfShape.hxx>
83 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
84 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
85 #include <TopTools_SequenceOfShape.hxx>
86 #include <TopTools_ListOfShape.hxx>
87 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
88 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
94 #include <gp_Dir2d.hxx>
96 #include <BRep_TVertex.hxx>
97 #include <TopTools_IndexedMapOfShape.hxx>
98 #include <Geom2d_BSplineCurve.hxx>
99 #include <TColgp_Array1OfPnt2d.hxx>
100 #include <TColStd_Array1OfReal.hxx>
101 #include <TColStd_Array1OfInteger.hxx>
102 #include <BRepTools_Substitution.hxx>
103 #include <BRepLib_MakeVertex.hxx>
104 #include <Geom2dLProp_CLProps2d.hxx>
105 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
106 #include <Standard_ErrorHandler.hxx>
110 #include <DrawTrSurf.hxx>
111 #include <DrawTrSurf_Curve2d.hxx>
116 static Standard_Boolean AffichGeom = Standard_False;
117 static Standard_Boolean Affich2d = Standard_False;
118 static Standard_Boolean AffichEdge = Standard_False;
119 static Standard_Integer NbTRIMEDGES = 0;
120 static Standard_Integer NbOFFSET = 0;
121 static Standard_Integer NbEDGES = 0;
122 static Standard_Integer NbBISSEC = 0;
124 static char tname[100];
125 static Standard_CString name = tname ;
129 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
131 static void QuasiFleche(const Adaptor3d_Curve& C,
132 const Standard_Real Deflection2,
133 const Standard_Real Udeb,
136 const Standard_Real Ufin,
139 const Standard_Integer Nbmin,
140 const Standard_Real Eps,
141 TColStd_SequenceOfReal& Parameters,
142 TColgp_SequenceOfPnt& Points);
144 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
145 TColgp_SequenceOfPnt& Points,
146 const Adaptor3d_Curve& C,
147 const Standard_Real Deflection,
148 const Standard_Real U1,
149 const Standard_Real U2,
150 const Standard_Real EPSILON,
151 const Standard_Integer Nbmin);
153 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
154 const BRepMAT2d_BisectingLocus& Locus,
155 const BRepMAT2d_LinkTopoBilo& Link,
156 TopTools_ListOfShape& BadEdges);
158 static Standard_Integer CutEdge (const TopoDS_Edge& E,
159 const TopoDS_Face& F,
160 Standard_Integer ForceCut,
161 TopTools_ListOfShape& Cuts);
164 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
165 const Standard_Integer nbParts,
166 TColGeom2d_SequenceOfCurve& theCurves);
167 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
170 static void EdgeVertices (const TopoDS_Edge& E,
174 if (E.Orientation() == TopAbs_REVERSED) {
175 TopExp::Vertices(E,V2,V1);
178 TopExp::Vertices(E,V1,V2);
182 static void UpdateDetromp (TopTools_ListOfShape& Detromp1,
183 TopTools_ListOfShape& Detromp2,
184 const TopTools_SequenceOfShape& Vertices,
185 const TColgp_SequenceOfPnt& Params,
186 const Bisector_Bisec& Bisec,
187 const Standard_Boolean SOnE,
188 const Standard_Boolean EOnE,
189 const BRepFill_TrimEdgeTool& Trim);
191 static Standard_Boolean VertexFromNode
192 (const Handle(MAT_Node)& aNode,
193 const Standard_Real Offset,
195 BRepFill_DataMapOfNodeShape& MapNodeVertex,
198 static void StoreInMap (const TopoDS_Shape& V1,
199 const TopoDS_Shape& V2,
200 TopTools_IndexedDataMapOfShapeShape& MapVV);
202 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
203 const TopTools_ListOfShape& D,
204 TopTools_SequenceOfShape& Sv,
205 TColStd_SequenceOfReal& MapverPar,
206 TopTools_SequenceOfShape& S,
207 TopTools_IndexedDataMapOfShapeShape& MapVV);
209 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
210 const TopoDS_Vertex& V);
212 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
213 const TopoDS_Vertex& aVertex);
215 static void MakeCircle
216 (const TopoDS_Edge& E,
217 const TopoDS_Vertex& V,
218 const TopoDS_Face& F,
219 const Standard_Real Offset,
220 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
221 const Handle(Geom_Plane)& RefPlane);
223 static void MakeOffset
224 (const TopoDS_Edge& E,
225 const TopoDS_Face& F,
226 const Standard_Real Offset,
227 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
228 const Handle(Geom_Plane)& RefPlane);
232 //=======================================================================
233 //function : CheckFace
234 //purpose : Check if face contains an edge with C0 continuity
235 //=======================================================================
237 static void CheckFace(const TopoDS_Face& theFace)
239 TopExp_Explorer ex(theFace,TopAbs_EDGE);
240 for(; ex.More(); ex.Next())
242 TopoDS_Edge anEdge=TopoDS::Edge(ex.Current());
244 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(anEdge,theFace,f,l);
245 if (C->Continuity() == GeomAbs_C0)
246 Standard_ConstructionError::Raise("Initial shape contains an edge with C0 continuity");
250 //=======================================================================
251 //function : KPartCircle
253 //=======================================================================
255 static Standard_Boolean KPartCircle
256 (const TopoDS_Face& mySpine,
257 const Standard_Real myOffset,
258 const Standard_Real Alt,
259 TopoDS_Shape& myShape,
260 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
261 Standard_Boolean& myIsDone)
263 // The only contour which is a closed circle
264 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
265 Standard_Integer NbEdges = 0;
268 for (; exp.More(); exp.Next()) {
270 E = TopoDS::Edge(exp.Current());
271 if (NbEdges > 1) return Standard_False;
274 TopExp::Vertices(E,V1,V2);
275 if (!V1.IsSame(V2)) return Standard_False;
279 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
281 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
282 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
283 C = Ct->BasisCurve();
286 if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False;
287 Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C);
288 Standard_Real anOffset = myOffset;
289 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
291 if (anOffset < 0. || Abs(anOffset) < CE->Radius()) {
292 Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset);
293 myShape = BRepLib_MakeEdge(OC,f,l);
295 myShape.Orientation(E.Orientation());
298 BRepAdaptor_Surface S(mySpine,0);
299 gp_Ax1 Nor = S.Plane().Axis();
301 gp_Vec Trans(Nor.Direction());
303 T.SetTranslation(Trans);
304 myShape.Move(TopLoc_Location(T));
307 TopTools_ListOfShape LL;
311 myIsDone = Standard_True;
312 return Standard_True;
315 //=======================================================================
316 //function : BRepFill_OffsetWire
318 //=======================================================================
320 BRepFill_OffsetWire::BRepFill_OffsetWire()
321 :myIsDone(Standard_False)
326 //=======================================================================
327 //function : BRepFill_OffsetWire
329 //=======================================================================
331 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
332 const GeomAbs_JoinType Join )
337 //=======================================================================
340 //=======================================================================
342 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
343 const GeomAbs_JoinType Join )
345 Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc,
346 "Only GeomAbs_Arc is implemented");
348 myIsDone = Standard_False;
349 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
350 mySpine = TopoDS::Face(aLocalShape);
351 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
358 //------------------------------------------------------------------
359 // cut the spine for bissectors.
360 //------------------------------------------------------------------
361 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
362 static BRepMAT2d_Explorer Exp;
364 Exp.Perform(mySpine);
366 // TopoDS_Face anOldSpine = mySpine;
368 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
371 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
373 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
374 Standard_Boolean Done;
375 if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
378 //-----------------------------------------------------
379 // Calculate the map of bissectors to the left.
380 // and Links Topology -> base elements of the map.
381 //-----------------------------------------------------
383 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
384 // static BRepMAT2d_Explorer Exp;
385 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
386 Exp.Perform(myWorkSpine);
387 myBilo.Compute(Exp,1,MAT_Left);
388 myLink.Perform(Exp,myBilo);
392 //=======================================================================
395 //=======================================================================
397 Standard_Boolean BRepFill_OffsetWire::IsDone() const
403 //=======================================================================
406 //=======================================================================
408 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
414 //=======================================================================
417 //=======================================================================
419 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
425 //=======================================================================
426 //function : GeneratedShapes
428 //=======================================================================
430 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
431 (const TopoDS_Shape& SpineShape)
434 if (!myMapSpine.IsEmpty()) {
435 // myMapSpine can be empty if passed by PerformWithBilo.
436 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
437 for (; it.More(); it.Next()) {
438 if (myMap.Contains(it.Key())) {
439 if (!myMap.Contains(it.Value())) {
440 TopTools_ListOfShape L;
441 myMap.Add(it.Value(),L);
443 if ( !it.Value().IsSame(it.Key())) {
444 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
445 //myMap.UnBind(it.Key());
446 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
447 TopTools_ListOfShape LastList;
448 LastList.Append(myMap(myMap.Extent()));
450 if (myMap.FindIndex(it.Key()) != 0)
451 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
454 if (myMap.Contains(it.Key().Reversed())) {
455 if (!myMap.Contains(it.Value().Reversed())) {
456 TopTools_ListOfShape L;
457 myMap.Add(it.Value().Reversed(),L);
459 if ( !it.Value().IsSame(it.Key())) {
460 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
461 //myMap.UnBind(it.Key().Reversed());
462 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
463 TopTools_ListOfShape LastList;
464 LastList.Append(myMap(myMap.Extent()));
466 if (myMap.FindIndex(it.Key().Reversed()) != 0)
467 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
472 myCallGen = Standard_True;
475 if (myMap.Contains(SpineShape)) {
476 return myMap.FindFromKey(SpineShape);
479 static TopTools_ListOfShape Empty;
485 //=======================================================================
486 //function : JoinType
488 //=======================================================================
490 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
495 //=======================================================================
498 //=======================================================================
500 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
501 const Standard_Real Alt)
503 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
506 myCallGen = Standard_False;
507 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
509 TopoDS_Face oldWorkSpain = myWorkSpine;
511 TopTools_ListOfShape BadEdges;
512 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
514 if(!BadEdges.IsEmpty()) {
515 // Modification of myWorkSpine;
516 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
517 BRepTools_Substitution aSubst;
518 TopTools_ListIteratorOfListOfShape it(BadEdges);
519 TopTools_ListOfShape aL;
520 Standard_Real aDefl = .01 * Abs(Offset);
521 TColStd_SequenceOfReal Parameters;
522 TColgp_SequenceOfPnt Points;
524 for(; it.More(); it.Next()) {
528 const TopoDS_Shape& anE = it.Value();
529 TopoDS_Vertex Vf, Vl;
530 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
533 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
534 GeomAdaptor_Curve AC(G3d,f,l);
536 PerformCurve(Parameters, Points, AC, aDefl, f,
537 l, Precision::Confusion(), 2);
539 Standard_Integer NPnts = Points.Length();
541 //cout << NPnts << " points " << endl;
542 TopoDS_Vertex FV = Vf;
546 for(np = 2; np < NPnts; np++) {
547 gp_Pnt LP = Points(np);
548 LV = BRepLib_MakeVertex(LP);
549 newE = BRepLib_MakeEdge(FV, LV);
554 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() );
600 aSubst.Build(myWorkSpine);
601 if(aSubst.IsCopied(myWorkSpine)) {
602 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
603 //sprintf(name,"WS1");
604 //DBRep::Set(name,myWorkSpine);
606 BRepMAT2d_Explorer newExp;
607 newExp.Perform(myWorkSpine);
608 BRepMAT2d_BisectingLocus newBilo;
609 BRepMAT2d_LinkTopoBilo newLink;
610 newBilo.Compute(newExp,1,MAT_Left);
612 if(!newBilo.IsDone())
615 myIsDone = Standard_False;
619 newLink.Perform(newExp,newBilo);
620 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
622 myWorkSpine = oldWorkSpain;
625 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
630 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)) return;
739 BRep_Builder myBuilder;
740 myBuilder.MakeCompound(TopoDS::Compound(myShape));
742 //---------------------------------------------------------------------
743 // MapNodeVertex : associate to each node of the map (key1) and to
744 // each element of the profile (key2) a vertex (item).
745 // MapBis : all edges or vertices (item) generated by
746 // a bisectrice on a face or an edge (key) of revolution tubes.
747 // MapVerPar : Map of parameters of vertices on parallel edges
748 // the list contained in MapVerPar (E) corresponds to
749 // parameters on E of vertices contained in MapBis(E);
750 //---------------------------------------------------------------------
753 BRepFill_DataMapOfNodeShape MapNodeVertex;
754 TopTools_DataMapOfShapeSequenceOfShape MapBis;
755 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
757 TopTools_DataMapOfShapeShape EmptyMap;
758 TopTools_SequenceOfShape EmptySeq;
759 TopTools_ListOfShape EmptyList;
760 TColStd_SequenceOfReal EmptySeqOfReal;
762 Standard_Real ALT = Alt;
763 Handle(Geom_Plane) RefPlane =
764 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
765 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
766 RefPlane = Handle(Geom_Plane)::DownCast
767 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
769 //---------------------------------------------------------------
770 // Construction of Circles and OffsetCurves
771 //---------------------------------------------------------------
773 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
774 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
775 TopoDS_Shape& PE = PEE ;
776 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
777 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
778 if (SE.ShapeType() == TopAbs_VERTEX) {
779 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
780 myWorkSpine,myOffset,myMap,RefPlane);
783 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane);
792 cout << " End Construction of geometric primitives "<<endl;
797 //---------------------------------------------------
798 // Construction of offset vertices.
799 //---------------------------------------------------
800 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
801 Handle(MAT_Arc) CurrentArc;
802 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
803 Handle(Geom_Curve) CBis;
804 Standard_Boolean Reverse;
805 TopoDS_Edge CurrentEdge;
809 Standard_Integer j, k;
811 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
813 CurrentArc = Locus.Graph()->Arc(i);
814 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
818 sprintf(name,"BISSEC_%d",NbBISSEC++);
819 DrawTrSurf::Set(name,Bisec.Value());
823 //-------------------------------------------------------------------
824 // Return elements of the spine corresponding to separate basicElts.
825 //-------------------------------------------------------------------
826 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
827 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
829 TopTools_SequenceOfShape Vertices;
830 TColgp_SequenceOfPnt Params;
832 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
833 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
835 //-----------------------------------------------------------
836 // Return parallel edges on each face.
837 // If no offset generated => move to the next bissectrice.
838 //--------------------------------------------------------------
839 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
840 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
841 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
845 //-----------------------------------------------------------
846 // Construction of vertices corresponding to the node of the map.
847 // if they are on the offset.
848 //-----------------------------------------------------------
850 Handle(MAT_Node) Node1, Node2;
853 Node1 = CurrentArc->SecondNode();
854 Node2 = CurrentArc->FirstNode();
857 Node1 = CurrentArc->FirstNode();
858 Node2 = CurrentArc->SecondNode();
861 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
863 if (!Node1->Infinite()) {
864 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
865 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
866 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
867 // MapNodeVertex,VS);
869 if (!Node2->Infinite()) {
870 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
871 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
872 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
873 // MapNodeVertex,VE);
876 //---------------------------------------------
877 // Construction of geometries.
878 //---------------------------------------------
879 BRepFill_TrimEdgeTool Trim (Bisec,
880 Locus.GeomElt(CurrentArc->FirstElement()),
881 Locus.GeomElt(CurrentArc->SecondElement()),
884 //-----------------------------------------------------------
885 // Construction of vertices on edges parallel to the spine.
886 //-----------------------------------------------------------
888 Trim.IntersectWith(E [0], E [1], Params);
890 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
892 myBuilder.MakeVertex (VC);
893 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
894 gp_Pnt PVC(P2.X(),P2.Y(),0.);
896 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
900 Standard_Boolean Start = 1;
901 Trim.AddOrConfuse(Start, E[0], E[1], Params);
902 if (Params.Length() == Vertices.Length())
903 Vertices.SetValue(1,VS);
906 // the point was not found by IntersectWith
907 Vertices.Prepend(VS);
910 Standard_Boolean Start = 0;
911 Trim.AddOrConfuse(Start, E[0], E[1], Params);
912 if (Params.Length() == Vertices.Length())
913 Vertices.SetValue(Params.Length(),VE);
916 // the point was not found by IntersectWith
920 //------------------------------------------------------------
922 // Detromp allows to remove vertices on the offset
923 // corresponding to tangency zones
924 // Detromp ranks the vertices that limit
925 // the parts of the bissectrices located between the spine and the
927 //------------------------------------------------------------
928 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
929 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
932 UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params,
933 Bisec, StartOnEdge, EndOnEdge, Trim);
934 //----------------------------------------------
935 // Storage of vertices on parallel edges.
936 // fill MapBis and MapVerPar.
937 //----------------------------------------------
938 if (!Vertices.IsEmpty()) {
939 for (k = 0; k <= 1; k++) {
940 if (!MapBis.IsBound(E[k])) {
941 MapBis .Bind(E[k],EmptySeq);
942 MapVerPar.Bind(E[k],EmptySeqOfReal);
944 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
945 MapBis (E[k]).Append(Vertices.Value(ii));
946 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
947 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
952 //------------------------------------------------------------
953 // FOR COMPLETE CIRCLES. the parallel line can be contained
954 // in the zone without intersection with the border
956 // if myoffset is < distance of nodes the parallel can be valid.
957 //-------------------------------------------------------------
958 for (k = 0; k <= 1; k++) {
959 if (!MapBis.IsBound(E[k])) {
960 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
961 MapBis .Bind(E[k],EmptySeq);
962 MapVerPar.Bind(E[k],EmptySeqOfReal);
971 cout << " End Construction of vertices on offsets"<<endl;
975 //----------------------------------
976 // Construction of parallel edges.
977 //----------------------------------
978 TopTools_IndexedDataMapOfShapeShape MapVV;
980 TopoDS_Shape CurrentSpine;
982 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
984 for (j = 1; j <= myMap.Extent(); j++) {
985 CurrentSpine = myMap.FindKey(j);
986 CurrentEdge = TopoDS::Edge(myMap(j).First());
989 if (MapBis.IsBound(CurrentEdge)) {
990 TopTools_SequenceOfShape S;
991 if (!MapBis(CurrentEdge).IsEmpty()) {
992 TrimEdge (CurrentEdge,
993 Detromp (CurrentSpine),
994 MapBis (CurrentEdge) ,
995 MapVerPar(CurrentEdge) ,
997 for ( k = 1; k <= S.Length(); k++) {
998 myMap(j).Append(S.Value(k));
1005 myMap(j).Append(CurrentEdge);
1010 Standard_Integer ind;
1011 for (ind = 1; ind <= MapVV.Extent(); ind++)
1013 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1014 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1015 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1016 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1017 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1018 TopTools_ListOfShape LV;
1019 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1020 BRepTools_Substitution aSubst;
1021 aSubst.Substitute( OldV, LV );
1022 for (j = 1; j <= myMap.Extent(); j++)
1024 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1025 for (; itl.More(); itl.Next())
1027 aSubst.Build(itl.Value());
1028 if (aSubst.IsCopied(itl.Value()))
1030 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1031 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1032 itl.Value() = listSh.First();
1033 itl.Value().Orientation(SaveOr);
1039 //----------------------------------
1040 // Construction of offset wires.
1041 //----------------------------------
1044 // Update vertices ( Constructed in the plane Z = 0) !!!
1045 TopTools_MapOfShape MapVertex;
1046 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1047 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1048 if ( MapVertex.Add(V)) {
1049 gp_Pnt P = BRep_Tool::Pnt(V);
1050 P = RefPlane->Value(P.X(),P.Y());
1051 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1055 // Construction of curves 3d.
1056 BRepLib::BuildCurves3d(myShape);
1058 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1059 for (; Explo.More(); Explo.Next())
1061 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1062 TopoDS_Vertex V1, V2;
1063 TopExp::Vertices( E, V1, V2 );
1064 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1065 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1067 TopLoc_Location loc;
1069 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1070 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1071 theCurve->Transform( loc.Transformation() );
1072 gp_Pnt f3d = theCurve->Value( f );
1073 gp_Pnt l3d = theCurve->Value( l );
1075 Standard_Real dist1, dist2;
1076 dist1 = f3d.Distance( TV1->Pnt() );
1077 dist2 = l3d.Distance( TV2->Pnt() );
1078 if (! MapVertex.Contains( V1 ))
1081 MapVertex.Add( V1 );
1084 TV1->UpdateTolerance( 1.5*dist1 );
1085 if (! MapVertex.Contains( V2 ))
1088 MapVertex.Add( V2 );
1091 TV2->UpdateTolerance( 1.5*dist2 );
1096 myIsDone = Standard_True;
1100 //=======================================================================
1101 //function : Generated
1103 //=======================================================================
1105 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1106 BRepFill_OffsetWire::Generated()
1112 //=======================================================================
1113 //function : PrepareSpine
1115 //=======================================================================
1117 void BRepFill_OffsetWire::PrepareSpine()
1120 TopTools_ListOfShape Cuts;
1121 TopTools_ListIteratorOfListOfShape IteCuts;
1122 TopoDS_Vertex V1,V2;
1124 myWorkSpine.Nullify();
1128 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1129 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1130 B.MakeFace(myWorkSpine,S,L,TolF);
1132 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1137 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1138 Standard_Integer ForcedCut = 0;
1139 Standard_Integer nbResEdges = -1;
1140 TopTools_IndexedMapOfShape EdgeMap;
1142 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1143 Standard_Integer nbEdges = EdgeMap.Extent();
1147 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1149 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1151 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1152 EdgeVertices(E,V1,V2);
1153 myMapSpine.Bind(V1,V1);
1154 myMapSpine.Bind(V2,V2);
1158 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1159 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1160 if (nbEdges == 2 && nbResEdges == 0)
1162 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1163 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1165 if (Cuts.IsEmpty()) {
1167 myMapSpine.Bind(E,E);
1170 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1171 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1172 NE.Orientation(E.Orientation());
1174 myMapSpine.Bind(NE,E);
1175 EdgeVertices(NE,V1,V2);
1176 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1177 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1181 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1185 TopExp::Vertices(NW, aV1, aV2);
1187 NW.Closed(aV1.IsSame(aV2));
1188 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1189 B.Add(myWorkSpine, NW);
1195 DBRep::Set(name,myWorkSpine);
1201 //=======================================================================
1202 //function : MakeWires
1204 //=======================================================================
1206 void BRepFill_OffsetWire::MakeWires()
1208 //--------------------------------------------------------
1209 // creation of a single list of created parallel edges.
1210 //--------------------------------------------------------
1211 TopTools_SequenceOfShape TheEdges;
1212 TopTools_ListOfShape TheWires;
1213 TopTools_ListIteratorOfListOfShape itl;
1214 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1215 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1216 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1217 TopoDS_Vertex V1,V2,VF,CV;
1220 for (i = 1; i <= myMap.Extent(); i++) {
1221 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1222 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1223 TopExp::Vertices (E,V1,V2);
1224 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1225 continue; //remove small closed edges
1226 if (!MVE.Contains(V1)) {
1227 TopTools_ListOfShape empty;
1230 MVE.ChangeFromKey(V1).Append(E);
1231 if (!MVE.Contains(V2)) {
1232 TopTools_ListOfShape empty;
1235 MVE.ChangeFromKey(V2).Append(E);
1239 //--------------------------------------
1240 // Creation of parallel wires.
1241 //--------------------------------------
1244 // Standard_Integer NbEdges;
1245 // Standard_Boolean NewWire = Standard_True;
1246 // Standard_Boolean AddEdge = Standard_False;
1249 Standard_Boolean End;
1252 while (!MVE.IsEmpty()) {
1255 //MVEit.Initialize(MVE);
1256 for (i = 1; i <= MVE.Extent(); i++)
1257 if(MVE(i).Extent() == 1)
1260 //if(!MVEit.More()) MVEit.Initialize(MVE);
1261 if (i > MVE.Extent())
1264 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1265 CE = TopoDS::Edge(MVE(i).First());
1266 End = Standard_False;
1267 MVE.ChangeFromKey(CV).RemoveFirst();
1269 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1270 Standard_Boolean isClosed = Standard_False;
1271 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1274 //-------------------------------
1275 // Construction of a wire.
1276 //-------------------------------
1277 TopExp::Vertices(CE,V1,V2);
1278 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1282 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1283 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1284 isClosed = VF.IsSame(CV);
1285 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1286 End = Standard_True;
1288 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1289 TopTools_ListOfShape LastList;
1290 LastList.Append(MVE(MVE.Extent()));
1292 if (MVE.FindIndex(VF) != 0)
1293 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1297 if (MVE.FindFromKey(CV).Extent() > 2) {
1298 //cout <<"vertex on more that 2 edges in a face."<<endl;
1300 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1301 if (itl.Value().IsSame(CE)) {
1302 MVE.ChangeFromKey(CV).Remove(itl);
1306 if (!MVE.FindFromKey(CV).IsEmpty()) {
1307 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1308 MVE.ChangeFromKey(CV).RemoveFirst();
1310 if (MVE.FindFromKey(CV).IsEmpty())
1313 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1314 TopTools_ListOfShape LastList;
1315 LastList.Append(MVE(MVE.Extent()));
1317 if (MVE.FindIndex(CV) != 0)
1318 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1322 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1323 // NW.Closed(Standard_True);
1324 NW.Closed(isClosed);
1325 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1326 TheWires.Append(NW);
1330 // -- if only one wire : myShape is a Wire
1331 // -- if several wires : myShape is a Compound.
1332 if ( TheWires.Extent() == 1) {
1333 myShape = TheWires.First();
1338 TopTools_ListIteratorOfListOfShape it(TheWires);
1339 for ( ; it.More(); it.Next()) {
1340 B.Add(R, it.Value());
1347 //=======================================================================
1348 //function : FixHoles
1350 //=======================================================================
1352 void BRepFill_OffsetWire::FixHoles()
1354 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1356 Standard_Real MaxTol = 0.;
1360 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1361 for (; Explo.More(); Explo.Next())
1363 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1364 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1370 Explo.Init( myShape, TopAbs_WIRE );
1371 for (; Explo.More(); Explo.Next())
1373 TopoDS_Shape aWire = Explo.Current();
1374 // Remove duplicated edges
1375 TopTools_DataMapOfShapeListOfShape EEmap;
1376 TopoDS_Iterator it( aWire );
1377 for (; it.More(); it.Next())
1379 const TopoDS_Shape& anEdge = it.Value();
1380 if (! EEmap.IsBound( anEdge ))
1382 TopTools_ListOfShape LE;
1383 EEmap.Bind( anEdge, LE );
1386 EEmap(anEdge).Append( anEdge );
1388 aWire.Free( Standard_True );
1389 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1390 for (; mapit.More(); mapit.Next())
1392 const TopTools_ListOfShape& LE = mapit.Value();
1393 TopTools_ListIteratorOfListOfShape itl( LE );
1394 for (; itl.More(); itl.Next())
1395 BB.Remove( aWire, itl.Value() );
1399 ClosedWires.Append( aWire );
1401 UnclosedWires.Append( aWire );
1404 while (!UnclosedWires.IsEmpty())
1406 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1407 TopoDS_Vertex Vf, Vl;
1408 TopExp::Vertices( Base, Vf, Vl );
1409 if(Vf.IsNull() || Vl.IsNull())
1410 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1412 Pf = BRep_Tool::Pnt(Vf);
1413 Pl = BRep_Tool::Pnt(Vl);
1414 Standard_Real DistF = RealLast(), DistL = RealLast();
1415 Standard_Integer IndexF, IndexL;
1416 Standard_Boolean IsFirstF, IsFirstL;
1417 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1419 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1420 TopoDS_Vertex V1, V2;
1421 TopExp::Vertices( aWire, V1, V2 );
1423 P1 = BRep_Tool::Pnt(V1);
1424 P2 = BRep_Tool::Pnt(V2);
1425 Standard_Real dist = Pf.Distance( P1 );
1430 IsFirstF = Standard_True;
1432 dist = Pf.Distance( P2 );
1437 IsFirstF = Standard_False;
1439 dist = Pl.Distance( P1 );
1444 IsFirstL = Standard_True;
1446 dist = Pl.Distance( P2 );
1451 IsFirstL = Standard_False;
1454 TopoDS_Wire theWire;
1455 TopoDS_Edge theEdge;
1456 TopoDS_Vertex theVertex;
1457 Standard_Real CommonTol;
1458 Standard_Boolean TryToClose = Standard_True;
1459 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1471 TryToClose = Standard_False;
1473 if (DistF <= MaxTol)
1475 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1476 TopoDS_Vertex V1, V2;
1477 TopExp::Vertices( theWire, V1, V2 );
1478 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1479 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1480 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1481 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1482 TopoDS_Iterator it( theWire );
1483 for (; it.More(); it.Next())
1485 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1486 if (IsFirstF) anEdge.Reverse();
1487 if (!anEdge.IsSame( theEdge ))
1488 BB.Add( Base, anEdge );
1490 theVertex = (IsFirstF)? V1 : V2;
1491 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1492 if (DistF <= CommonTol)
1494 theEdge.Free( Standard_True );
1495 Vf.Orientation( theVertex.Orientation() );
1496 BB.Remove( theEdge, theVertex );
1497 BB.Add( theEdge, Vf );
1498 BB.UpdateVertex( Vf, CommonTol );
1499 if (IsFirstF) theEdge.Reverse();
1500 BB.Add( Base, theEdge );
1504 if (IsFirstF) theEdge.Reverse();
1505 BB.Add( Base, theEdge );
1506 // Creating new edge from theVertex to Vf
1507 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1508 BB.Add( Base, NewEdge );
1511 if (DistL <= MaxTol && IndexL != IndexF)
1513 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1514 TopoDS_Vertex V1, V2;
1515 TopExp::Vertices( theWire, V1, V2 );
1516 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1517 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1518 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1519 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1520 TopoDS_Iterator it( theWire );
1521 for (; it.More(); it.Next())
1523 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1524 if (!IsFirstL) anEdge.Reverse();
1525 if (!anEdge.IsSame( theEdge ))
1526 BB.Add( Base, anEdge );
1528 theVertex = (IsFirstL)? V1 : V2;
1529 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1530 if (DistL <= CommonTol)
1532 theEdge.Free( Standard_True );
1533 Vl.Orientation( theVertex.Orientation() );
1534 BB.Remove( theEdge, theVertex );
1535 BB.Add( theEdge, Vl );
1536 BB.UpdateVertex( Vl, CommonTol );
1537 if (!IsFirstL) theEdge.Reverse();
1538 BB.Add( Base, theEdge );
1542 if (!IsFirstL) theEdge.Reverse();
1543 BB.Add( Base, theEdge );
1544 // Creating new edge from Vl to theVertex
1545 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1546 BB.Add( Base, NewEdge );
1549 // Check if it is possible to close resulting wire
1552 TopExp::Vertices( Base, Vf, Vl );
1553 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1554 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1555 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1556 TopoDS_Edge Efirst, Elast;
1557 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1558 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1559 Pf = BRep_Tool::Pnt(Vf);
1560 Pl = BRep_Tool::Pnt(Vl);
1561 Standard_Real Dist = Pf.Distance(Pl);
1562 if (Dist <= CommonTol)
1564 Elast.Free( Standard_True );
1565 Vf.Orientation( Vl.Orientation() );
1566 BB.Remove( Elast, Vl );
1567 BB.Add( Elast, Vf );
1568 BB.UpdateVertex( Vf, CommonTol );
1569 Base.Closed( Standard_True );
1571 else if (Dist <= MaxTol)
1573 // Creating new edge from Vl to Vf
1574 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1575 BB.Add( Base, NewEdge );
1576 Base.Closed( Standard_True );
1579 // Updating sequences ClosedWires and UnclosedWires
1580 if (DistF <= MaxTol)
1581 UnclosedWires.Remove( IndexF );
1582 if (DistL <= MaxTol && IndexL != IndexF)
1584 if (DistF <= MaxTol && IndexL > IndexF)
1586 UnclosedWires.Remove( IndexL );
1590 ClosedWires.Append( Base );
1591 UnclosedWires.Remove( 1 );
1593 else if (DistF > MaxTol && DistL > MaxTol)
1595 IsolatedWires.Append( Base );
1596 UnclosedWires.Remove( 1 );
1601 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1603 if (!ClosedWires.IsEmpty())
1604 myShape = ClosedWires.First();
1606 myShape = IsolatedWires.First();
1611 BB.MakeCompound( R );
1612 for (i = 1; i <= ClosedWires.Length(); i++)
1613 BB.Add( R, ClosedWires(i) );
1614 for (i = 1; i <= IsolatedWires.Length(); i++)
1615 BB.Add( R, IsolatedWires(i) );
1620 //=======================================================================
1621 //function : CutEdge
1622 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1623 // So, closed circles are cut in two.
1624 // If <Cuts> is empty, the edge is not modified.
1625 // The first and the last vertex of the initial edge
1626 // belong to the first and the last parts respectively.
1627 //=======================================================================
1628 Standard_Integer CutEdge (const TopoDS_Edge& E,
1629 const TopoDS_Face& F,
1630 Standard_Integer ForceCut,
1631 TopTools_ListOfShape& Cuts)
1634 MAT2d_CutCurve Cuter;
1635 TColGeom2d_SequenceOfCurve theCurves;
1637 Handle(Geom2d_Curve) C2d;
1638 Handle(Geom2d_TrimmedCurve) CT2d;
1639 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1640 Standard_Real aTol = BRep_Tool::Tolerance(E);
1641 Handle(Geom_Curve) aC;
1642 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1644 TopoDS_Vertex V1,V2,VF,VL;
1645 TopExp::Vertices (E,V1,V2);
1648 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1649 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1650 aC = BRep_Tool::Curve(E,f,l);
1651 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1652 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1653 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1655 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1656 ( Abs(f-l) >= M_PI) ) {
1660 //-------------------------
1662 //-------------------------
1663 Cuter.Perform(CT2d);
1665 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1666 if (ForceCut == 0) {
1667 if (Cuter.UnModified()) {
1668 //-----------------------------
1669 // edge not modified => return.
1670 //-----------------------------
1673 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1674 theCurves.Append(Cuter.Value(k));
1676 } else if (ForceCut == 1) {
1677 if (Cuter.UnModified()) {
1678 CutCurve (CT2d, 2, theCurves);
1680 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1681 theCurves.Append(Cuter.Value(k));
1683 } else if (ForceCut == 2) {
1684 if (Cuter.UnModified()) {
1685 CutCurve (CT2d, 3, theCurves);
1687 if (Cuter.NbCurves() == 2) {
1688 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1690 if (CC->LastParameter() > (l+f)/2.) {
1691 CutCurve (CC, 2, theCurves);
1692 theCurves.Append(Cuter.Value(2));
1694 theCurves.Append(CC);
1695 CutCurve (Cuter.Value(2), 2, theCurves);
1698 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1699 theCurves.Append(Cuter.Value(k));
1703 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1705 //--------------------------------------
1706 // Creation of cut edges.
1707 //--------------------------------------
1710 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1712 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1714 if (k == theCurves.Length()) {VL = V2;}
1716 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1717 gp_Pnt P = aC->Value(CC->LastParameter());
1719 VL = BRepLib_MakeVertex(P);
1720 B.UpdateVertex(VL, aTol);
1721 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1723 TopoDS_Shape aLocalShape = E.EmptyCopied();
1724 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1725 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1726 NE.Orientation(TopAbs_FORWARD);
1727 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1728 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1729 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1730 Cuts.Append(NE.Oriented(E.Orientation()));
1734 return theCurves.Length();
1737 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1738 //=======================================================================
1739 //function : CutCurve
1741 //=======================================================================
1743 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1744 const Standard_Integer nbParts,
1745 TColGeom2d_SequenceOfCurve& theCurves)
1747 Handle(Geom2d_TrimmedCurve) TrimC;
1748 Standard_Real UF,UL,UC;
1751 Standard_Real PTol = Precision::PConfusion()*10;
1752 Standard_Real Tol = Precision::Confusion()*10;
1753 Standard_Boolean YaCut = Standard_False;
1755 UF = C->FirstParameter();
1756 UL = C->LastParameter ();
1760 Step = (UL - UF)/nbParts;
1762 for (Standard_Integer i = 1; i < nbParts; i++) {
1767 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1768 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1771 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1772 theCurves.Append(TrimC);
1775 YaCut = Standard_True;
1779 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1780 theCurves.Append(TrimC);
1782 theCurves.Append(C);
1784 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1786 //=======================================================================
1787 //function : MakeCircle
1789 //=======================================================================
1791 void MakeCircle (const TopoDS_Edge& E,
1792 const TopoDS_Vertex& V,
1793 const TopoDS_Face& F,
1794 const Standard_Real Offset,
1795 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1796 const Handle(Geom_Plane)& RefPlane)
1798 // evaluate the Axis of the Circle.
1800 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1804 if (E.Orientation() == TopAbs_FORWARD) {
1808 else GC->D1(f,P,DX);
1810 gp_Ax2d Axis(P,gp_Dir2d(DX));
1811 Handle(Geom2d_Circle) Circ
1812 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1814 // Bind the edges in my Map.
1815 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1816 TopTools_ListOfShape LL;
1822 if ( AffichGeom && !OE.IsNull()) {
1823 sprintf(name,"OFFSET_%d",++NbOFFSET);
1824 DBRep::Set(name,OE);
1829 //=======================================================================
1830 //function : MakeOffset
1832 //=======================================================================
1834 void MakeOffset (const TopoDS_Edge& E,
1835 const TopoDS_Face& F,
1836 const Standard_Real Offset,
1837 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1838 const Handle(Geom_Plane)& RefPlane)
1841 Standard_Real anOffset = Offset;
1843 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1845 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1846 Handle(Geom2d_Curve) G2dOC;
1848 Geom2dAdaptor_Curve AC(G2d,f,l);
1849 if ( AC.GetType() == GeomAbs_Circle) {
1850 // if the offset is greater otr equal to the radius and the side of the
1851 // concavity of the circle => edge null.
1852 gp_Circ2d C1(AC.Circle());
1853 gp_Ax22d axes( C1.Axis());
1854 gp_Dir2d Xd = axes.XDirection();
1855 gp_Dir2d Yd = axes.YDirection();
1856 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1857 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1859 if (anOffset*Signe < AC.Circle().Radius()) {
1861 Handle(Geom2dAdaptor_HCurve) AHC =
1862 new Geom2dAdaptor_HCurve(G2d);
1863 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1864 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1866 Standard_Real Delta = 2*M_PI - l + f;
1867 f -= 0.2*Delta; l += 0.2*Delta;
1869 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1872 else if (AC.GetType() == GeomAbs_Line) {
1873 Handle(Geom2dAdaptor_HCurve) AHC =
1874 new Geom2dAdaptor_HCurve(G2d);
1875 Adaptor3d_OffsetCurve Off(AHC,anOffset);
1876 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
1877 Standard_Real Delta = (l - f);
1878 f -= Delta; l += Delta;
1879 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1883 anOffset = -anOffset;
1884 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
1885 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
1889 // Bind the edges in my Map.
1890 if (!G2dOC.IsNull()) {
1891 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
1892 OE.Orientation(E.Orientation());
1893 TopTools_ListOfShape LL;
1898 if (AffichGeom && !OE.IsNull()) {
1899 sprintf(name,"OFFSET_%d",++NbOFFSET);
1900 DBRep::Set(name,OE);
1901 Standard_Real ii = 0;
1908 //=======================================================================
1909 //function : UpdateDetromp
1910 //purpose : For each interval on bissectrice defined by parameters
1911 // test if the medium point is at a distance > offset
1912 // in this case vertices corresponding to the extremities of the interval
1913 // are ranked in the proofing.
1914 // => If the same vertex appears in the proofing, the
1915 // border of the zone of proximity is tangent to the offset .
1916 //=======================================================================
1918 void UpdateDetromp (TopTools_ListOfShape& Detromp1,
1919 TopTools_ListOfShape& Detromp2,
1920 const TopTools_SequenceOfShape& Vertices,
1921 const TColgp_SequenceOfPnt& Params,
1922 const Bisector_Bisec& Bisec,
1923 const Standard_Boolean SOnE,
1924 const Standard_Boolean EOnE,
1925 const BRepFill_TrimEdgeTool& Trim)
1927 Standard_Integer ii = 1;
1928 Standard_Real U1,U2;
1929 TopoDS_Vertex V1,V2;
1931 Handle(Geom2d_Curve) Bis = Bisec.Value();
1933 U1 = Bis->FirstParameter();
1936 // the first point of the bissectrice is on the offset
1937 V1 = TopoDS::Vertex(Vertices.Value(ii));
1941 while (ii <= Vertices.Length()) {
1942 U2 = Params.Value(ii).X();
1943 V2 = TopoDS::Vertex(Vertices.Value(ii));
1945 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1946 if (!Trim.IsInside(P)) {
1948 Detromp1.Append(V1);
1949 Detromp2.Append(V1);
1951 Detromp1.Append(V2);
1952 Detromp2.Append(V2);
1959 // test medium point between the last parameter and the end of the bissectrice.
1960 U2 = Bis->LastParameter();
1962 if (!Precision::IsInfinite(U2)) {
1963 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1964 if (!Trim.IsInside(P)) {
1966 Detromp1.Append(V1);
1967 Detromp2.Append(V1);
1973 Detromp1.Append(V1);
1974 Detromp2.Append(V1);
1980 //=======================================================================
1981 //function : VertexFromNode
1983 //=======================================================================
1985 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
1986 const Standard_Real Offset,
1988 BRepFill_DataMapOfNodeShape& MapNodeVertex,
1991 Standard_Boolean Status;
1992 Standard_Real Tol = Precision::Confusion();
1995 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
1996 //------------------------------------------------
1997 // the Node gives a vertex on the offset
1998 //------------------------------------------------
1999 if (MapNodeVertex.IsBound(aNode)) {
2000 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2003 gp_Pnt P(PN.X(),PN.Y(),0.);
2005 B.UpdateVertex(VN,P, Precision::Confusion());
2006 MapNodeVertex.Bind(aNode,VN);
2008 Status = Standard_True;
2010 else Status = Standard_False;
2016 //=======================================================================
2017 //function : StoreInMap
2019 //=======================================================================
2021 void StoreInMap (const TopoDS_Shape& V1,
2022 const TopoDS_Shape& V2,
2023 TopTools_IndexedDataMapOfShapeShape& MapVV)
2025 TopoDS_Shape OldV = V1, NewV = V2;
2028 if (MapVV.Contains(V2))
2029 NewV = MapVV.FindFromKey(V2);
2031 if (MapVV.Contains(V1))
2032 MapVV.ChangeFromKey(V1) = NewV;
2034 for (i = 1; i <= MapVV.Extent(); i++)
2035 if (MapVV(i).IsSame(V1))
2038 MapVV.Add(V1, NewV);
2041 //=======================================================================
2042 //function : TrimEdge
2044 //=======================================================================
2046 void TrimEdge (const TopoDS_Edge& E,
2047 const TopTools_ListOfShape& Detromp,
2048 TopTools_SequenceOfShape& TheVer,
2049 TColStd_SequenceOfReal& ThePar,
2050 TopTools_SequenceOfShape& S,
2051 TopTools_IndexedDataMapOfShapeShape& MapVV)
2053 Standard_Boolean Change = Standard_True;
2054 BRep_Builder TheBuilder;
2057 //-----------------------------------------------------------
2058 // Parse two sequences depending on the parameter on the edge.
2059 //-----------------------------------------------------------
2061 Change = Standard_False;
2062 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2063 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2064 ThePar.Exchange(i,i+1);
2065 TheVer.Exchange(i,i+1);
2066 Change = Standard_True;
2071 //----------------------------------------------------------
2072 // If a vertex is not in the proofing, it is eliminated.
2073 //----------------------------------------------------------
2074 if (!BRep_Tool::Degenerated(E)) {
2075 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2076 if ( DoubleOrNotInside (Detromp,
2077 TopoDS::Vertex(TheVer.Value(k)))) {
2085 //----------------------------------------------------------
2086 // If a vertex_double appears twice in the proofing
2087 // the vertex is removed.
2088 // otherwise preserve only one of its representations.
2089 //----------------------------------------------------------
2090 if (!BRep_Tool::Degenerated(E)) {
2091 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2092 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2093 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2095 if(k+1 == TheVer.Length()) {
2096 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2101 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2106 if ( DoubleOrNotInside (Detromp,
2107 TopoDS::Vertex(TheVer.Value(k)))) {
2117 //-----------------------------------------------------------
2118 // Creation of edges.
2119 // the number of vertices should be even. The created edges
2120 // go from a vertex with uneven index i to vertex i+1;
2121 //-----------------------------------------------------------
2122 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2123 TopoDS_Shape aLocalShape = E.EmptyCopied();
2124 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2125 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2127 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2128 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2129 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2132 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2133 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2137 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2141 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2142 DBRep::Set(name,NewEdge);
2147 Handle(Geom_Surface) Surf;
2148 Handle(Geom2d_Curve) C;
2149 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2150 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2151 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2152 Handle(DrawTrSurf_Curve2d) dr =
2153 new DrawTrSurf_Curve2d(C2d,Standard_False);
2154 dr->SetColor(Draw_bleu);
2163 //=======================================================================
2164 //function : DoubleOrNotInside
2165 //purpose : return True if V appears twice in LV or is not inside.
2166 //=======================================================================
2168 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2169 const TopoDS_Vertex& V)
2171 Standard_Boolean Vu = Standard_False;
2172 TopTools_ListIteratorOfListOfShape it(LV);
2174 for ( ; it.More(); it.Next()) {
2175 if (V.IsSame(it.Value())) {
2176 if (Vu) return Standard_True;
2177 else Vu = Standard_True;
2180 if (Vu) return Standard_False;
2181 else return Standard_True;
2184 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2185 const TopoDS_Vertex& aVertex)
2187 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2188 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2189 PV2d.SetCoord( PV.X(), PV.Y() );
2191 Handle(Geom2d_Curve) PCurve;
2192 Handle( BRep_CurveRepresentation ) CurveRep =
2193 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2194 PCurve = CurveRep->PCurve();
2196 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2197 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2198 Pfirst = PCurve->Value(fpar);
2199 Plast = PCurve->Value(lpar);
2200 Pmid = PCurve->Value((fpar + lpar)*0.5);
2202 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2205 Standard_Real dist1 = Pfirst.Distance(PV2d);
2206 Standard_Real dist2 = Plast.Distance(PV2d);
2207 Standard_Real dist3 = Pmid.Distance(PV2d);
2209 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2210 return Standard_True;
2212 return Standard_False;
2215 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2216 const BRepMAT2d_BisectingLocus& Locus,
2217 const BRepMAT2d_LinkTopoBilo& Link,
2218 TopTools_ListOfShape& BadEdges)
2221 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2222 Standard_Real eps = Precision::Confusion();
2223 Standard_Real LimCurv = 1./Offset;
2225 TopTools_MapOfShape aMap;
2227 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2228 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2229 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2230 if (SE.ShapeType() == TopAbs_EDGE) {
2232 if (aMap.Contains(SE)) {
2233 //cout << "Edge is treated second time" << endl;
2237 TopoDS_Edge E = TopoDS::Edge(SE);
2241 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2243 Geom2dAdaptor_Curve AC(G2d,f,l);
2244 GeomAbs_CurveType aCType = AC.GetType();
2246 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2248 Standard_Boolean reverse = Standard_False;
2249 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2254 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2256 aCLProps.SetParameter(f);
2257 if(!aCLProps.IsTangentDefined()) {
2258 BadEdges.Append(SE);
2263 P = aCLProps.Value();
2264 Standard_Real Crv = aCLProps.Curvature();
2267 aCLProps.Tangent(N);
2268 Standard_Real x = N.Y(), y = -N.X();
2270 if (reverse) N.Reverse();
2271 aCLProps.CentreOfCurvature(Pc);
2272 gp_Vec2d Dir( P, Pc );
2273 if (N.Dot(Dir) > 0.) {
2274 if (LimCurv <= Crv + eps) {
2275 BadEdges.Append(SE);
2282 aCLProps.SetParameter(l);
2283 if(!aCLProps.IsTangentDefined()) {
2284 BadEdges.Append(SE);
2289 P = aCLProps.Value();
2290 Crv = aCLProps.Curvature();
2293 aCLProps.Tangent(N);
2294 Standard_Real x = N.Y(), y = -N.X();
2296 if (reverse) N.Reverse();
2297 aCLProps.CentreOfCurvature(Pc);
2298 gp_Vec2d Dir( P, Pc );
2299 if (N.Dot(Dir) > 0.) {
2300 if (LimCurv <= Crv + eps) {
2301 BadEdges.Append(SE);
2314 //=======================================================================
2315 //function : PerformCurve
2317 //=======================================================================
2319 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2320 TColgp_SequenceOfPnt& Points,
2321 const Adaptor3d_Curve& C,
2322 const Standard_Real Deflection,
2323 const Standard_Real U1,
2324 const Standard_Real U2,
2325 const Standard_Real EPSILON,
2326 const Standard_Integer Nbmin)
2328 Standard_Real UU1 = Min(U1, U2);
2329 Standard_Real UU2 = Max(U1, U2);
2333 C.D1(UU1,Pdeb,Ddeb);
2334 Parameters.Append(UU1);
2335 Points.Append(Pdeb);
2337 C.D1(UU2,Pfin,Dfin);
2338 QuasiFleche(C,Deflection*Deflection,
2346 return Standard_True;
2348 //=======================================================================
2349 //function : QuasiFleche
2351 //=======================================================================
2353 static void QuasiFleche(const Adaptor3d_Curve& C,
2354 const Standard_Real Deflection2,
2355 const Standard_Real Udeb,
2358 const Standard_Real Ufin,
2361 const Standard_Integer Nbmin,
2362 const Standard_Real Eps,
2363 TColStd_SequenceOfReal& Parameters,
2364 TColgp_SequenceOfPnt& Points)
2366 Standard_Integer Ptslength = Points.Length();
2367 Standard_Real Udelta = Ufin-Udeb;
2372 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2380 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2381 Standard_Real theFleche=0;
2382 Standard_Boolean flecheok = Standard_False;
2384 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2385 Standard_Real N1 = Vdeb.SquareMagnitude();
2386 Standard_Real N2 = Vdelta.SquareMagnitude();
2387 if (N1 > Eps && N2 > Eps) {
2388 Standard_Real Normediff =
2389 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2390 if (Normediff > Eps) {
2391 theFleche = Normediff*Norme/64.;
2392 flecheok = Standard_True;
2397 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2398 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2399 theFleche = Pmid.SquareDistance(Pverif);
2402 if (theFleche < Deflection2) {
2403 Parameters.Append(Udeb+Udelta);
2404 Points.Append(Pdelta);
2407 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2418 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2422 Nbmin-(Points.Length()-Ptslength),