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);
230 //=======================================================================
231 //function : KPartCircle
233 //=======================================================================
235 static Standard_Boolean KPartCircle
236 (const TopoDS_Face& mySpine,
237 const Standard_Real myOffset,
238 const Standard_Real Alt,
239 TopoDS_Shape& myShape,
240 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
241 Standard_Boolean& myIsDone)
243 // The only contour which is a closed circle
244 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
245 Standard_Integer NbEdges = 0;
248 for (; exp.More(); exp.Next()) {
250 E = TopoDS::Edge(exp.Current());
251 if (NbEdges > 1) return Standard_False;
254 TopExp::Vertices(E,V1,V2);
255 if (!V1.IsSame(V2)) return Standard_False;
259 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
261 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
262 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
263 C = Ct->BasisCurve();
266 if (!C->IsKind(STANDARD_TYPE(Geom_Circle))) return Standard_False;
267 Handle(Geom_Circle) CE = Handle(Geom_Circle)::DownCast(C);
268 Standard_Real anOffset = myOffset;
269 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
271 if (anOffset < 0. || Abs(anOffset) < CE->Radius()) {
272 Handle(Geom_Circle) OC = new Geom_Circle (CE->Position(),CE->Radius() - anOffset);
273 myShape = BRepLib_MakeEdge(OC,f,l);
275 myShape.Orientation(E.Orientation());
278 BRepAdaptor_Surface S(mySpine,0);
279 gp_Ax1 Nor = S.Plane().Axis();
281 gp_Vec Trans(Nor.Direction());
283 T.SetTranslation(Trans);
284 myShape.Move(TopLoc_Location(T));
287 TopTools_ListOfShape LL;
291 myIsDone = Standard_True;
292 return Standard_True;
295 //=======================================================================
296 //function : BRepFill_OffsetWire
298 //=======================================================================
300 BRepFill_OffsetWire::BRepFill_OffsetWire()
301 :myIsDone(Standard_False)
306 //=======================================================================
307 //function : BRepFill_OffsetWire
309 //=======================================================================
311 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
312 const GeomAbs_JoinType Join )
318 //=======================================================================
321 //=======================================================================
323 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
324 const GeomAbs_JoinType Join )
326 Standard_NotImplemented_Raise_if(Join > GeomAbs_Arc,
327 "Only GeomAbs_Arc is implemented");
329 myIsDone = Standard_False;
330 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
331 mySpine = TopoDS::Face(aLocalShape);
332 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
337 //------------------------------------------------------------------
338 // cut the spine for bissectors.
339 //------------------------------------------------------------------
340 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
341 static BRepMAT2d_Explorer Exp;
343 Exp.Perform(mySpine);
345 // TopoDS_Face anOldSpine = mySpine;
347 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
350 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
352 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
353 Standard_Boolean Done;
354 if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
357 //-----------------------------------------------------
358 // Calculate the map of bissectors to the left.
359 // and Links Topology -> base elements of the map.
360 //-----------------------------------------------------
362 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
363 // static BRepMAT2d_Explorer Exp;
364 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
365 Exp.Perform(myWorkSpine);
366 myBilo.Compute(Exp,1,MAT_Left);
367 myLink.Perform(Exp,myBilo);
371 //=======================================================================
374 //=======================================================================
376 Standard_Boolean BRepFill_OffsetWire::IsDone() const
382 //=======================================================================
385 //=======================================================================
387 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
393 //=======================================================================
396 //=======================================================================
398 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
404 //=======================================================================
405 //function : GeneratedShapes
407 //=======================================================================
409 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
410 (const TopoDS_Shape& SpineShape)
413 if (!myMapSpine.IsEmpty()) {
414 // myMapSpine can be empty if passed by PerformWithBilo.
415 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
416 for (; it.More(); it.Next()) {
417 if (myMap.Contains(it.Key())) {
418 if (!myMap.Contains(it.Value())) {
419 TopTools_ListOfShape L;
420 myMap.Add(it.Value(),L);
422 if ( !it.Value().IsSame(it.Key())) {
423 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
424 //myMap.UnBind(it.Key());
425 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
426 TopTools_ListOfShape LastList;
427 LastList.Append(myMap(myMap.Extent()));
429 if (myMap.FindIndex(it.Key()) != 0)
430 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
433 if (myMap.Contains(it.Key().Reversed())) {
434 if (!myMap.Contains(it.Value().Reversed())) {
435 TopTools_ListOfShape L;
436 myMap.Add(it.Value().Reversed(),L);
438 if ( !it.Value().IsSame(it.Key())) {
439 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
440 //myMap.UnBind(it.Key().Reversed());
441 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
442 TopTools_ListOfShape LastList;
443 LastList.Append(myMap(myMap.Extent()));
445 if (myMap.FindIndex(it.Key().Reversed()) != 0)
446 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
451 myCallGen = Standard_True;
454 if (myMap.Contains(SpineShape)) {
455 return myMap.FindFromKey(SpineShape);
458 static TopTools_ListOfShape Empty;
464 //=======================================================================
465 //function : JoinType
467 //=======================================================================
469 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
474 //=======================================================================
477 //=======================================================================
479 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
480 const Standard_Real Alt)
482 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
485 myCallGen = Standard_False;
486 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
488 TopoDS_Face oldWorkSpain = myWorkSpine;
490 TopTools_ListOfShape BadEdges;
491 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
493 if(!BadEdges.IsEmpty()) {
494 // Modification of myWorkSpine;
495 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
496 BRepTools_Substitution aSubst;
497 TopTools_ListIteratorOfListOfShape it(BadEdges);
498 TopTools_ListOfShape aL;
499 Standard_Real aDefl = .01 * Abs(Offset);
500 TColStd_SequenceOfReal Parameters;
501 TColgp_SequenceOfPnt Points;
503 for(; it.More(); it.Next()) {
507 const TopoDS_Shape& anE = it.Value();
508 TopoDS_Vertex Vf, Vl;
509 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
512 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
513 GeomAdaptor_Curve AC(G3d,f,l);
515 Standard_Boolean dummy = PerformCurve(Parameters, Points,
516 AC, aDefl, f, l, Precision::Confusion(),
519 Standard_Integer NPnts = Points.Length();
521 //cout << NPnts << " points " << endl;
522 TopoDS_Vertex FV = Vf;
526 for(np = 2; np < NPnts; np++) {
527 gp_Pnt LP = Points(np);
528 LV = BRepLib_MakeVertex(LP);
529 newE = BRepLib_MakeEdge(FV, LV);
534 newE = BRepLib_MakeEdge(FV, LV);
538 //cout << " 2 points " << endl;
539 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
543 if (myMapSpine.IsBound( anE ))
545 TopTools_ListIteratorOfListOfShape newit( aL );
546 for (; newit.More(); newit.Next())
548 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
549 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
550 TopoDS_Vertex NewV1, NewV2;
551 EdgeVertices( NewEdge, NewV1, NewV2 );
552 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
553 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
555 myMapSpine.UnBind( anE );
558 aSubst.Substitute(anE, aL);
561 TopTools_DataMapOfShapeListOfShape wwmap;
562 TopoDS_Iterator itws( myWorkSpine );
563 for (; itws.More(); itws.Next())
565 TopoDS_Shape aWire = itws.Value();
566 aSubst.Build( aWire );
567 if (aSubst.IsCopied(aWire))
569 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
570 NewWire.Closed( aWire.Closed() );
571 TopTools_ListOfShape Lw;
572 Lw.Append( NewWire );
573 wwmap.Bind( aWire, Lw );
577 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
578 for (; itmap.More(); itmap.Next())
579 aSubst.Substitute( itmap.Key(), itmap.Value() );
580 aSubst.Build(myWorkSpine);
581 if(aSubst.IsCopied(myWorkSpine)) {
582 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
583 //sprintf(name,"WS1");
584 //DBRep::Set(name,myWorkSpine);
586 BRepMAT2d_Explorer newExp;
587 newExp.Perform(myWorkSpine);
588 BRepMAT2d_BisectingLocus newBilo;
589 BRepMAT2d_LinkTopoBilo newLink;
590 newBilo.Compute(newExp,1,MAT_Left);
591 newLink.Perform(newExp,newBilo);
592 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
594 myWorkSpine = oldWorkSpain;
597 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
602 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
605 } catch (Standard_Failure) {
607 myIsDone = Standard_False;
611 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
612 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
613 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
615 for (; anExp.More(); anExp.Next()) {
616 const TopoDS_Shape &aWire = anExp.Current();
618 if (!aWire.Closed()) {
620 myIsDone = Standard_False;
621 Standard_ConstructionError::Raise("Offset wire is not closed.");
624 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
627 //=======================================================================
630 //=======================================================================
632 void Compute (const TopoDS_Face& Spine,
633 TopoDS_Shape& aShape,
634 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
635 const Standard_Real Alt)
638 B.MakeCompound(TopoDS::Compound(aShape));
639 Standard_Real ALT = Alt;
640 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
642 T.SetTranslation(gp_Vec(0.,0.,ALT));
643 TopLoc_Location L(T);
645 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
646 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
647 TopoDS_Shape aLocalShape = CurW.Moved(L);
648 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
649 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
652 TopoDS_Iterator it1( CurW);
653 TopoDS_Iterator it2( NewW);
654 for ( ; it1.More(); it1.Next(), it2.Next()) {
655 TopTools_ListOfShape List;
656 List.Append(it2.Value());
657 Map.Add(it1.Value(), List);
662 //=======================================================================
663 //function : PerformWithBiLo
665 //=======================================================================
667 void BRepFill_OffsetWire::PerformWithBiLo
668 (const TopoDS_Face& Spine,
669 const Standard_Real Offset,
670 const BRepMAT2d_BisectingLocus& Locus,
671 BRepMAT2d_LinkTopoBilo& Link,
672 const GeomAbs_JoinType Join,
673 const Standard_Real Alt)
675 Standard_NotImplemented_Raise_if (Join > GeomAbs_Arc,
676 "Only GeomAbs_Arc is implemented");
678 myIsDone = Standard_False;
679 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
680 myWorkSpine = TopoDS::Face(aLocalShape);
681 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
687 if (mySpine.IsNull()) {
688 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
689 mySpine = TopoDS::Face(aLocalShape);
690 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
694 if ( Abs(myOffset) < Precision::Confusion()) {
695 Compute(mySpine,myShape,myMap,Alt);
696 myIsDone = Standard_True;
700 //********************************
701 // Calculate for a non null offset
702 //********************************
703 if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
705 BRep_Builder myBuilder;
706 myBuilder.MakeCompound(TopoDS::Compound(myShape));
708 //---------------------------------------------------------------------
709 // MapNodeVertex : associate to each node of the map (key1) and to
710 // each element of the profile (key2) a vertex (item).
711 // MapBis : all edges or vertices (item) generated by
712 // a bisectrice on a face or an edge (key) of revolution tubes.
713 // MapVerPar : Map of parameters of vertices on parallel edges
714 // the list contained in MapVerPar (E) corresponds to
715 // parameters on E of vertices contained in MapBis(E);
716 //---------------------------------------------------------------------
719 BRepFill_DataMapOfNodeShape MapNodeVertex;
720 TopTools_DataMapOfShapeSequenceOfShape MapBis;
721 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
723 TopTools_DataMapOfShapeShape EmptyMap;
724 TopTools_SequenceOfShape EmptySeq;
725 TopTools_ListOfShape EmptyList;
726 TColStd_SequenceOfReal EmptySeqOfReal;
728 Standard_Real ALT = Alt;
729 Handle(Geom_Plane) RefPlane =
730 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
731 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
732 RefPlane = Handle(Geom_Plane)::DownCast
733 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
735 //---------------------------------------------------------------
736 // Construction of Circles and OffsetCurves
737 //---------------------------------------------------------------
739 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
740 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
741 TopoDS_Shape& PE = PEE ;
742 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
743 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
744 if (SE.ShapeType() == TopAbs_VERTEX) {
745 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
746 myWorkSpine,myOffset,myMap,RefPlane);
749 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane);
758 cout << " End Construction of geometric primitives "<<endl;
763 //---------------------------------------------------
764 // Construction of offset vertices.
765 //---------------------------------------------------
766 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
767 Handle(MAT_Arc) CurrentArc;
768 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
769 Handle(Geom_Curve) CBis;
770 Standard_Boolean Reverse;
771 TopoDS_Edge CurrentEdge;
775 Standard_Integer j, k;
777 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
779 CurrentArc = Locus.Graph()->Arc(i);
780 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
784 sprintf(name,"BISSEC_%d",NbBISSEC++);
785 DrawTrSurf::Set(name,Bisec.Value());
789 //-------------------------------------------------------------------
790 // Return elements of the spine corresponding to separate basicElts.
791 //-------------------------------------------------------------------
792 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
793 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
795 TopTools_SequenceOfShape Vertices;
796 TColgp_SequenceOfPnt Params;
798 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
799 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
801 //-----------------------------------------------------------
802 // Return parallel edges on each face.
803 // If no offset generated => move to the next bissectrice.
804 //--------------------------------------------------------------
805 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
806 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
807 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
811 //-----------------------------------------------------------
812 // Construction of vertices corresponding to the node of the map.
813 // if they are on the offset.
814 //-----------------------------------------------------------
816 Handle(MAT_Node) Node1, Node2;
819 Node1 = CurrentArc->SecondNode();
820 Node2 = CurrentArc->FirstNode();
823 Node1 = CurrentArc->FirstNode();
824 Node2 = CurrentArc->SecondNode();
827 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
829 if (!Node1->Infinite()) {
830 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
831 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
832 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
833 // MapNodeVertex,VS);
835 if (!Node2->Infinite()) {
836 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
837 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
838 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
839 // MapNodeVertex,VE);
842 //---------------------------------------------
843 // Construction of geometries.
844 //---------------------------------------------
845 BRepFill_TrimEdgeTool Trim (Bisec,
846 Locus.GeomElt(CurrentArc->FirstElement()),
847 Locus.GeomElt(CurrentArc->SecondElement()),
850 //-----------------------------------------------------------
851 // Construction of vertices on edges parallel to the spine.
852 //-----------------------------------------------------------
854 Trim.IntersectWith(E [0], E [1], Params);
856 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
858 myBuilder.MakeVertex (VC);
859 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
860 gp_Pnt PVC(P2.X(),P2.Y(),0.);
862 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
866 Standard_Boolean Start = 1;
867 Trim.AddOrConfuse(Start, E[0], E[1], Params);
868 if (Params.Length() == Vertices.Length())
869 Vertices.SetValue(1,VS);
872 // the point was not found by IntersectWith
873 Vertices.Prepend(VS);
876 Standard_Boolean Start = 0;
877 Trim.AddOrConfuse(Start, E[0], E[1], Params);
878 if (Params.Length() == Vertices.Length())
879 Vertices.SetValue(Params.Length(),VE);
882 // the point was not found by IntersectWith
886 //------------------------------------------------------------
888 // Detromp allows to remove vertices on the offset
889 // corresponding to tangency zones
890 // Detromp ranks the vertices that limit
891 // the parts of the bissectrices located between the spine and the
893 //------------------------------------------------------------
894 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
895 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
898 UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params,
899 Bisec, StartOnEdge, EndOnEdge, Trim);
900 //----------------------------------------------
901 // Storage of vertices on parallel edges.
902 // fill MapBis and MapVerPar.
903 //----------------------------------------------
904 if (!Vertices.IsEmpty()) {
905 for (k = 0; k <= 1; k++) {
906 if (!MapBis.IsBound(E[k])) {
907 MapBis .Bind(E[k],EmptySeq);
908 MapVerPar.Bind(E[k],EmptySeqOfReal);
910 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
911 MapBis (E[k]).Append(Vertices.Value(ii));
912 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
913 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
918 //------------------------------------------------------------
919 // FOR COMPLETE CIRCLES. the parallel line can be contained
920 // in the zone without intersection with the border
922 // if myoffset is < distance of nodes the parallel can be valid.
923 //-------------------------------------------------------------
924 for (k = 0; k <= 1; k++) {
925 if (!MapBis.IsBound(E[k])) {
926 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
927 MapBis .Bind(E[k],EmptySeq);
928 MapVerPar.Bind(E[k],EmptySeqOfReal);
937 cout << " End Construction of vertices on offsets"<<endl;
941 //----------------------------------
942 // Construction of parallel edges.
943 //----------------------------------
944 TopTools_IndexedDataMapOfShapeShape MapVV;
946 TopoDS_Shape CurrentSpine;
948 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
950 for (j = 1; j <= myMap.Extent(); j++) {
951 CurrentSpine = myMap.FindKey(j);
952 CurrentEdge = TopoDS::Edge(myMap(j).First());
955 if (MapBis.IsBound(CurrentEdge)) {
956 TopTools_SequenceOfShape S;
957 if (!MapBis(CurrentEdge).IsEmpty()) {
958 TrimEdge (CurrentEdge,
959 Detromp (CurrentSpine),
960 MapBis (CurrentEdge) ,
961 MapVerPar(CurrentEdge) ,
963 for ( k = 1; k <= S.Length(); k++) {
964 myMap(j).Append(S.Value(k));
971 myMap(j).Append(CurrentEdge);
976 Standard_Integer ind;
977 for (ind = 1; ind <= MapVV.Extent(); ind++)
979 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
980 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
981 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
982 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
983 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
984 TopTools_ListOfShape LV;
985 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
986 BRepTools_Substitution aSubst;
987 aSubst.Substitute( OldV, LV );
988 for (j = 1; j <= myMap.Extent(); j++)
990 TopTools_ListIteratorOfListOfShape itl(myMap(j));
991 for (; itl.More(); itl.Next())
993 aSubst.Build(itl.Value());
994 if (aSubst.IsCopied(itl.Value()))
996 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
997 TopAbs_Orientation SaveOr = itl.Value().Orientation();
998 itl.Value() = listSh.First();
999 itl.Value().Orientation(SaveOr);
1005 //----------------------------------
1006 // Construction of offset wires.
1007 //----------------------------------
1010 // Update vertices ( Constructed in the plane Z = 0) !!!
1011 TopTools_MapOfShape MapVertex;
1012 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1013 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1014 if ( MapVertex.Add(V)) {
1015 gp_Pnt P = BRep_Tool::Pnt(V);
1016 P = RefPlane->Value(P.X(),P.Y());
1017 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1021 // Construction of curves 3d.
1022 BRepLib::BuildCurves3d(myShape);
1024 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1025 for (; Explo.More(); Explo.Next())
1027 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1028 TopoDS_Vertex V1, V2;
1029 TopExp::Vertices( E, V1, V2 );
1030 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1031 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1033 TopLoc_Location loc;
1035 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1036 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1037 theCurve->Transform( loc.Transformation() );
1038 gp_Pnt f3d = theCurve->Value( f );
1039 gp_Pnt l3d = theCurve->Value( l );
1041 Standard_Real dist1, dist2;
1042 dist1 = f3d.Distance( TV1->Pnt() );
1043 dist2 = l3d.Distance( TV2->Pnt() );
1044 if (! MapVertex.Contains( V1 ))
1047 MapVertex.Add( V1 );
1050 TV1->UpdateTolerance( 1.5*dist1 );
1051 if (! MapVertex.Contains( V2 ))
1054 MapVertex.Add( V2 );
1057 TV2->UpdateTolerance( 1.5*dist2 );
1062 myIsDone = Standard_True;
1066 //=======================================================================
1067 //function : Generated
1069 //=======================================================================
1071 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1072 BRepFill_OffsetWire::Generated()
1078 //=======================================================================
1079 //function : PrepareSpine
1081 //=======================================================================
1083 void BRepFill_OffsetWire::PrepareSpine()
1086 TopTools_ListOfShape Cuts;
1087 TopTools_ListIteratorOfListOfShape IteCuts;
1088 TopoDS_Vertex V1,V2;
1090 myWorkSpine.Nullify();
1094 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1095 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1096 B.MakeFace(myWorkSpine,S,L,TolF);
1098 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1103 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1104 Standard_Integer ForcedCut = 0;
1105 Standard_Integer nbResEdges = -1;
1106 TopTools_IndexedMapOfShape EdgeMap;
1108 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1109 Standard_Integer nbEdges = EdgeMap.Extent();
1113 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1115 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1117 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1118 EdgeVertices(E,V1,V2);
1119 myMapSpine.Bind(V1,V1);
1120 myMapSpine.Bind(V2,V2);
1124 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1125 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1126 if (nbEdges == 2 && nbResEdges == 0)
1128 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1129 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1131 if (Cuts.IsEmpty()) {
1133 myMapSpine.Bind(E,E);
1136 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1137 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1138 NE.Orientation(E.Orientation());
1140 myMapSpine.Bind(NE,E);
1141 EdgeVertices(NE,V1,V2);
1142 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1143 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1147 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1151 TopExp::Vertices(NW, aV1, aV2);
1153 NW.Closed(aV1.IsSame(aV2));
1154 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1155 B.Add(myWorkSpine, NW);
1161 DBRep::Set(name,myWorkSpine);
1167 //=======================================================================
1168 //function : MakeWires
1170 //=======================================================================
1172 void BRepFill_OffsetWire::MakeWires()
1174 //--------------------------------------------------------
1175 // creation of a single list of created parallel edges.
1176 //--------------------------------------------------------
1177 TopTools_SequenceOfShape TheEdges;
1178 TopTools_ListOfShape TheWires;
1179 TopTools_ListIteratorOfListOfShape itl;
1180 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1181 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1182 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1183 TopoDS_Vertex V1,V2,VF,CV;
1186 for (i = 1; i <= myMap.Extent(); i++) {
1187 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1188 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1189 TopExp::Vertices (E,V1,V2);
1190 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1191 continue; //remove small closed edges
1192 if (!MVE.Contains(V1)) {
1193 TopTools_ListOfShape empty;
1196 MVE.ChangeFromKey(V1).Append(E);
1197 if (!MVE.Contains(V2)) {
1198 TopTools_ListOfShape empty;
1201 MVE.ChangeFromKey(V2).Append(E);
1205 //--------------------------------------
1206 // Creation of parallel wires.
1207 //--------------------------------------
1210 // Standard_Integer NbEdges;
1211 // Standard_Boolean NewWire = Standard_True;
1212 // Standard_Boolean AddEdge = Standard_False;
1215 Standard_Boolean End;
1218 while (!MVE.IsEmpty()) {
1221 //MVEit.Initialize(MVE);
1222 for (i = 1; i <= MVE.Extent(); i++)
1223 if(MVE(i).Extent() == 1)
1226 //if(!MVEit.More()) MVEit.Initialize(MVE);
1227 if (i > MVE.Extent())
1230 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1231 CE = TopoDS::Edge(MVE(i).First());
1232 End = Standard_False;
1233 MVE.ChangeFromKey(CV).RemoveFirst();
1235 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1236 Standard_Boolean isClosed = Standard_False;
1237 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1240 //-------------------------------
1241 // Construction of a wire.
1242 //-------------------------------
1243 TopExp::Vertices(CE,V1,V2);
1244 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1248 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1249 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1250 isClosed = VF.IsSame(CV);
1251 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1252 End = Standard_True;
1254 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1255 TopTools_ListOfShape LastList;
1256 LastList.Append(MVE(MVE.Extent()));
1258 if (MVE.FindIndex(VF) != 0)
1259 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1263 if (MVE.FindFromKey(CV).Extent() > 2) {
1264 //cout <<"vertex on more that 2 edges in a face."<<endl;
1266 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1267 if (itl.Value().IsSame(CE)) {
1268 MVE.ChangeFromKey(CV).Remove(itl);
1272 if (!MVE.FindFromKey(CV).IsEmpty()) {
1273 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1274 MVE.ChangeFromKey(CV).RemoveFirst();
1276 if (MVE.FindFromKey(CV).IsEmpty())
1279 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1280 TopTools_ListOfShape LastList;
1281 LastList.Append(MVE(MVE.Extent()));
1283 if (MVE.FindIndex(CV) != 0)
1284 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1288 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1289 // NW.Closed(Standard_True);
1290 NW.Closed(isClosed);
1291 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1292 TheWires.Append(NW);
1296 // -- if only one wire : myShape is a Wire
1297 // -- if several wires : myShape is a Compound.
1298 if ( TheWires.Extent() == 1) {
1299 myShape = TheWires.First();
1304 TopTools_ListIteratorOfListOfShape it(TheWires);
1305 for ( ; it.More(); it.Next()) {
1306 B.Add(R, it.Value());
1313 //=======================================================================
1314 //function : FixHoles
1316 //=======================================================================
1318 void BRepFill_OffsetWire::FixHoles()
1320 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1322 Standard_Real MaxTol = 0.;
1326 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1327 for (; Explo.More(); Explo.Next())
1329 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1330 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1336 Explo.Init( myShape, TopAbs_WIRE );
1337 for (; Explo.More(); Explo.Next())
1339 TopoDS_Shape aWire = Explo.Current();
1340 // Remove duplicated edges
1341 TopTools_DataMapOfShapeListOfShape EEmap;
1342 TopoDS_Iterator it( aWire );
1343 for (; it.More(); it.Next())
1345 const TopoDS_Shape& anEdge = it.Value();
1346 if (! EEmap.IsBound( anEdge ))
1348 TopTools_ListOfShape LE;
1349 EEmap.Bind( anEdge, LE );
1352 EEmap(anEdge).Append( anEdge );
1354 aWire.Free( Standard_True );
1355 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1356 for (; mapit.More(); mapit.Next())
1358 const TopTools_ListOfShape& LE = mapit.Value();
1359 TopTools_ListIteratorOfListOfShape itl( LE );
1360 for (; itl.More(); itl.Next())
1361 BB.Remove( aWire, itl.Value() );
1365 ClosedWires.Append( aWire );
1367 UnclosedWires.Append( aWire );
1370 while (!UnclosedWires.IsEmpty())
1372 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1373 TopoDS_Vertex Vf, Vl;
1374 TopExp::Vertices( Base, Vf, Vl );
1376 Pf = BRep_Tool::Pnt(Vf);
1377 Pl = BRep_Tool::Pnt(Vl);
1378 Standard_Real DistF = RealLast(), DistL = RealLast();
1379 Standard_Integer IndexF, IndexL;
1380 Standard_Boolean IsFirstF, IsFirstL;
1381 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1383 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1384 TopoDS_Vertex V1, V2;
1385 TopExp::Vertices( aWire, V1, V2 );
1387 P1 = BRep_Tool::Pnt(V1);
1388 P2 = BRep_Tool::Pnt(V2);
1389 Standard_Real dist = Pf.Distance( P1 );
1394 IsFirstF = Standard_True;
1396 dist = Pf.Distance( P2 );
1401 IsFirstF = Standard_False;
1403 dist = Pl.Distance( P1 );
1408 IsFirstL = Standard_True;
1410 dist = Pl.Distance( P2 );
1415 IsFirstL = Standard_False;
1418 TopoDS_Wire theWire;
1419 TopoDS_Edge theEdge;
1420 TopoDS_Vertex theVertex;
1421 Standard_Real CommonTol;
1422 Standard_Boolean TryToClose = Standard_True;
1423 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1435 TryToClose = Standard_False;
1437 if (DistF <= MaxTol)
1439 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1440 TopoDS_Vertex V1, V2;
1441 TopExp::Vertices( theWire, V1, V2 );
1442 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1443 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1444 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1445 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1446 TopoDS_Iterator it( theWire );
1447 for (; it.More(); it.Next())
1449 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1450 if (IsFirstF) anEdge.Reverse();
1451 if (!anEdge.IsSame( theEdge ))
1452 BB.Add( Base, anEdge );
1454 theVertex = (IsFirstF)? V1 : V2;
1455 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1456 if (DistF <= CommonTol)
1458 theEdge.Free( Standard_True );
1459 Vf.Orientation( theVertex.Orientation() );
1460 BB.Remove( theEdge, theVertex );
1461 BB.Add( theEdge, Vf );
1462 BB.UpdateVertex( Vf, CommonTol );
1463 if (IsFirstF) theEdge.Reverse();
1464 BB.Add( Base, theEdge );
1468 if (IsFirstF) theEdge.Reverse();
1469 BB.Add( Base, theEdge );
1470 // Creating new edge from theVertex to Vf
1471 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1472 BB.Add( Base, NewEdge );
1475 if (DistL <= MaxTol && IndexL != IndexF)
1477 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1478 TopoDS_Vertex V1, V2;
1479 TopExp::Vertices( theWire, V1, V2 );
1480 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1481 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1482 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1483 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1484 TopoDS_Iterator it( theWire );
1485 for (; it.More(); it.Next())
1487 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1488 if (!IsFirstL) anEdge.Reverse();
1489 if (!anEdge.IsSame( theEdge ))
1490 BB.Add( Base, anEdge );
1492 theVertex = (IsFirstL)? V1 : V2;
1493 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1494 if (DistL <= CommonTol)
1496 theEdge.Free( Standard_True );
1497 Vl.Orientation( theVertex.Orientation() );
1498 BB.Remove( theEdge, theVertex );
1499 BB.Add( theEdge, Vl );
1500 BB.UpdateVertex( Vl, CommonTol );
1501 if (!IsFirstL) theEdge.Reverse();
1502 BB.Add( Base, theEdge );
1506 if (!IsFirstL) theEdge.Reverse();
1507 BB.Add( Base, theEdge );
1508 // Creating new edge from Vl to theVertex
1509 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1510 BB.Add( Base, NewEdge );
1513 // Check if it is possible to close resulting wire
1516 TopExp::Vertices( Base, Vf, Vl );
1517 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1518 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1519 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1520 TopoDS_Edge Efirst, Elast;
1521 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1522 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1523 Pf = BRep_Tool::Pnt(Vf);
1524 Pl = BRep_Tool::Pnt(Vl);
1525 Standard_Real Dist = Pf.Distance(Pl);
1526 if (Dist <= CommonTol)
1528 Elast.Free( Standard_True );
1529 Vf.Orientation( Vl.Orientation() );
1530 BB.Remove( Elast, Vl );
1531 BB.Add( Elast, Vf );
1532 BB.UpdateVertex( Vf, CommonTol );
1533 Base.Closed( Standard_True );
1535 else if (Dist <= MaxTol)
1537 // Creating new edge from Vl to Vf
1538 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1539 BB.Add( Base, NewEdge );
1540 Base.Closed( Standard_True );
1543 // Updating sequences ClosedWires and UnclosedWires
1544 if (DistF <= MaxTol)
1545 UnclosedWires.Remove( IndexF );
1546 if (DistL <= MaxTol && IndexL != IndexF)
1548 if (DistF <= MaxTol && IndexL > IndexF)
1550 UnclosedWires.Remove( IndexL );
1554 ClosedWires.Append( Base );
1555 UnclosedWires.Remove( 1 );
1557 else if (DistF > MaxTol && DistL > MaxTol)
1559 IsolatedWires.Append( Base );
1560 UnclosedWires.Remove( 1 );
1565 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1567 if (!ClosedWires.IsEmpty())
1568 myShape = ClosedWires.First();
1570 myShape = IsolatedWires.First();
1575 BB.MakeCompound( R );
1576 for (i = 1; i <= ClosedWires.Length(); i++)
1577 BB.Add( R, ClosedWires(i) );
1578 for (i = 1; i <= IsolatedWires.Length(); i++)
1579 BB.Add( R, IsolatedWires(i) );
1584 //=======================================================================
1585 //function : CutEdge
1586 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1587 // So, closed circles are cut in two.
1588 // If <Cuts> is empty, the edge is not modified.
1589 // The first and the last vertex of the initial edge
1590 // belong to the first and the last parts respectively.
1591 //=======================================================================
1592 Standard_Integer CutEdge (const TopoDS_Edge& E,
1593 const TopoDS_Face& F,
1594 Standard_Integer ForceCut,
1595 TopTools_ListOfShape& Cuts)
1598 MAT2d_CutCurve Cuter;
1599 TColGeom2d_SequenceOfCurve theCurves;
1601 Handle(Geom2d_Curve) C2d;
1602 Handle(Geom2d_TrimmedCurve) CT2d;
1603 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1604 Standard_Real aTol = BRep_Tool::Tolerance(E);
1605 Handle(Geom_Curve) aC;
1606 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1608 TopoDS_Vertex V1,V2,VF,VL;
1609 TopExp::Vertices (E,V1,V2);
1612 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1613 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1614 aC = BRep_Tool::Curve(E,f,l);
1615 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1616 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1617 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1619 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1620 ( Abs(f-l) >= M_PI) ) {
1622 //---------------------------
1623 // Cut closed circle.
1624 //---------------------------
1625 Standard_Real m = (f + l)*0.5;
1626 // Modified by Sergey KHROMOV - Wed Mar 6 17:37:28 2002 Begin
1627 gp_Pnt P = aC->Value(m);
1629 VL = BRepLib_MakeVertex(P);
1630 B.UpdateVertex(VL, aTol);
1631 // Modified by Sergey KHROMOV - Wed Mar 6 17:37:30 2002 End
1632 TopoDS_Shape aLocalShape = E.EmptyCopied();
1633 TopoDS_Edge FE = TopoDS::Edge(aLocalShape);
1634 TopoDS_Edge LE = TopoDS::Edge(aLocalShape);
1635 // TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied());
1636 // TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied());
1637 FE.Orientation(TopAbs_FORWARD);
1638 LE.Orientation(TopAbs_FORWARD);
1640 B.Add (FE,VL.Oriented(TopAbs_REVERSED));
1643 B.Add (LE,VL.Oriented(TopAbs_FORWARD));
1645 Cuts.Append(FE.Oriented(E.Orientation()));
1646 Cuts.Append(LE.Oriented(E.Orientation()));
1653 //-------------------------
1655 //-------------------------
1656 Cuter.Perform(CT2d);
1658 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1659 if (ForceCut == 0) {
1660 if (Cuter.UnModified()) {
1661 //-----------------------------
1662 // edge not modified => return.
1663 //-----------------------------
1666 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1667 theCurves.Append(Cuter.Value(k));
1669 } else if (ForceCut == 1) {
1670 if (Cuter.UnModified()) {
1671 CutCurve (CT2d, 2, theCurves);
1673 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1674 theCurves.Append(Cuter.Value(k));
1676 } else if (ForceCut == 2) {
1677 if (Cuter.UnModified()) {
1678 CutCurve (CT2d, 3, theCurves);
1680 if (Cuter.NbCurves() == 2) {
1681 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1683 if (CC->LastParameter() > (l+f)/2.) {
1684 CutCurve (CC, 2, theCurves);
1685 theCurves.Append(Cuter.Value(2));
1687 theCurves.Append(CC);
1688 CutCurve (Cuter.Value(2), 2, theCurves);
1691 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1692 theCurves.Append(Cuter.Value(k));
1696 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1698 //--------------------------------------
1699 // Creation of cut edges.
1700 //--------------------------------------
1703 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1705 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1707 if (k == theCurves.Length()) {VL = V2;}
1709 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1710 gp_Pnt P = aC->Value(CC->LastParameter());
1712 VL = BRepLib_MakeVertex(P);
1713 B.UpdateVertex(VL, aTol);
1714 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1716 TopoDS_Shape aLocalShape = E.EmptyCopied();
1717 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1718 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1719 NE.Orientation(TopAbs_FORWARD);
1720 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1721 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1722 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1723 Cuts.Append(NE.Oriented(E.Orientation()));
1727 return theCurves.Length();
1730 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1731 //=======================================================================
1732 //function : CutCurve
1734 //=======================================================================
1736 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1737 const Standard_Integer nbParts,
1738 TColGeom2d_SequenceOfCurve& theCurves)
1740 Handle(Geom2d_TrimmedCurve) TrimC;
1741 Standard_Real UF,UL,UC;
1744 Standard_Real PTol = Precision::PConfusion()*10;
1745 Standard_Real Tol = Precision::Confusion()*10;
1746 Standard_Boolean YaCut = Standard_False;
1748 UF = C->FirstParameter();
1749 UL = C->LastParameter ();
1753 Step = (UL - UF)/nbParts;
1755 for (Standard_Integer i = 1; i < nbParts; i++) {
1760 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1761 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1764 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1765 theCurves.Append(TrimC);
1768 YaCut = Standard_True;
1772 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1773 theCurves.Append(TrimC);
1775 theCurves.Append(C);
1777 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1779 //=======================================================================
1780 //function : MakeCircle
1782 //=======================================================================
1784 void MakeCircle (const TopoDS_Edge& E,
1785 const TopoDS_Vertex& V,
1786 const TopoDS_Face& F,
1787 const Standard_Real Offset,
1788 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1789 const Handle(Geom_Plane)& RefPlane)
1791 // evaluate the Axis of the Circle.
1793 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1797 if (E.Orientation() == TopAbs_FORWARD) {
1801 else GC->D1(f,P,DX);
1803 gp_Ax2d Axis(P,gp_Dir2d(DX));
1804 Handle(Geom2d_Circle) Circ
1805 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1807 // Bind the edges in my Map.
1808 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1809 TopTools_ListOfShape LL;
1815 if ( AffichGeom && !OE.IsNull()) {
1816 sprintf(name,"OFFSET_%d",++NbOFFSET);
1817 DBRep::Set(name,OE);
1822 //=======================================================================
1823 //function : MakeOffset
1825 //=======================================================================
1827 void MakeOffset (const TopoDS_Edge& E,
1828 const TopoDS_Face& F,
1829 const Standard_Real Offset,
1830 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1831 const Handle(Geom_Plane)& RefPlane)
1834 Standard_Real anOffset = Offset;
1836 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1838 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1839 Handle(Geom2d_Curve) G2dOC;
1841 Geom2dAdaptor_Curve AC(G2d,f,l);
1842 if ( AC.GetType() == GeomAbs_Circle) {
1843 // if the offset is greater otr equal to the radius and the side of the
1844 // concavity of the circle => edge null.
1845 gp_Circ2d C1(AC.Circle());
1846 gp_Ax22d axes( C1.Axis());
1847 gp_Dir2d Xd = axes.XDirection();
1848 gp_Dir2d Yd = axes.YDirection();
1849 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1850 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1852 if (anOffset*Signe < AC.Circle().Radius()) {
1854 Handle(Geom2dAdaptor_HCurve) AHC =
1855 new Geom2dAdaptor_HCurve(G2d);
1856 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1857 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1859 Standard_Real Delta = 2*M_PI - l + f;
1860 f -= 0.2*Delta; l += 0.2*Delta;
1862 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1865 else if (AC.GetType() == GeomAbs_Line) {
1866 Handle(Geom2dAdaptor_HCurve) AHC =
1867 new Geom2dAdaptor_HCurve(G2d);
1868 Adaptor3d_OffsetCurve Off(AHC,anOffset);
1869 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
1870 Standard_Real Delta = (l - f);
1871 f -= Delta; l += Delta;
1872 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
1876 anOffset = -anOffset;
1877 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
1878 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
1882 // Bind the edges in my Map.
1883 if (!G2dOC.IsNull()) {
1884 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
1885 OE.Orientation(E.Orientation());
1886 TopTools_ListOfShape LL;
1891 if (AffichGeom && !OE.IsNull()) {
1892 sprintf(name,"OFFSET_%d",++NbOFFSET);
1893 DBRep::Set(name,OE);
1894 Standard_Real ii = 0;
1901 //=======================================================================
1902 //function : UpdateDetromp
1903 //purpose : For each interval on bissectrice defined by parameters
1904 // test if the medium point is at a distance > offset
1905 // in this case vertices corresponding to the extremities of the interval
1906 // are ranked in the proofing.
1907 // => If the same vertex appears in the proofing, the
1908 // border of the zone of proximity is tangent to the offset .
1909 //=======================================================================
1911 void UpdateDetromp (TopTools_ListOfShape& Detromp1,
1912 TopTools_ListOfShape& Detromp2,
1913 const TopTools_SequenceOfShape& Vertices,
1914 const TColgp_SequenceOfPnt& Params,
1915 const Bisector_Bisec& Bisec,
1916 const Standard_Boolean SOnE,
1917 const Standard_Boolean EOnE,
1918 const BRepFill_TrimEdgeTool& Trim)
1920 Standard_Integer ii = 1;
1921 Standard_Real U1,U2;
1922 TopoDS_Vertex V1,V2;
1924 Handle(Geom2d_Curve) Bis = Bisec.Value();
1926 U1 = Bis->FirstParameter();
1929 // the first point of the bissectrice is on the offset
1930 V1 = TopoDS::Vertex(Vertices.Value(ii));
1934 while (ii <= Vertices.Length()) {
1935 U2 = Params.Value(ii).X();
1936 V2 = TopoDS::Vertex(Vertices.Value(ii));
1938 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1939 if (!Trim.IsInside(P)) {
1941 Detromp1.Append(V1);
1942 Detromp2.Append(V1);
1944 Detromp1.Append(V2);
1945 Detromp2.Append(V2);
1952 // test medium point between the last parameter and the end of the bissectrice.
1953 U2 = Bis->LastParameter();
1955 if (!Precision::IsInfinite(U2)) {
1956 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1957 if (!Trim.IsInside(P)) {
1959 Detromp1.Append(V1);
1960 Detromp2.Append(V1);
1966 Detromp1.Append(V1);
1967 Detromp2.Append(V1);
1973 //=======================================================================
1974 //function : VertexFromNode
1976 //=======================================================================
1978 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
1979 const Standard_Real Offset,
1981 BRepFill_DataMapOfNodeShape& MapNodeVertex,
1984 Standard_Boolean Status;
1985 Standard_Real Tol = Precision::Confusion();
1988 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
1989 //------------------------------------------------
1990 // the Node gives a vertex on the offset
1991 //------------------------------------------------
1992 if (MapNodeVertex.IsBound(aNode)) {
1993 VN = TopoDS::Vertex(MapNodeVertex(aNode));
1996 gp_Pnt P(PN.X(),PN.Y(),0.);
1998 B.UpdateVertex(VN,P, Precision::Confusion());
1999 MapNodeVertex.Bind(aNode,VN);
2001 Status = Standard_True;
2003 else Status = Standard_False;
2009 //=======================================================================
2010 //function : StoreInMap
2012 //=======================================================================
2014 void StoreInMap (const TopoDS_Shape& V1,
2015 const TopoDS_Shape& V2,
2016 TopTools_IndexedDataMapOfShapeShape& MapVV)
2018 TopoDS_Shape OldV = V1, NewV = V2;
2021 if (MapVV.Contains(V2))
2022 NewV = MapVV.FindFromKey(V2);
2024 if (MapVV.Contains(V1))
2025 MapVV.ChangeFromKey(V1) = NewV;
2027 for (i = 1; i <= MapVV.Extent(); i++)
2028 if (MapVV(i).IsSame(V1))
2031 MapVV.Add(V1, NewV);
2034 //=======================================================================
2035 //function : TrimEdge
2037 //=======================================================================
2039 void TrimEdge (const TopoDS_Edge& E,
2040 const TopTools_ListOfShape& Detromp,
2041 TopTools_SequenceOfShape& TheVer,
2042 TColStd_SequenceOfReal& ThePar,
2043 TopTools_SequenceOfShape& S,
2044 TopTools_IndexedDataMapOfShapeShape& MapVV)
2046 Standard_Boolean Change = Standard_True;
2047 BRep_Builder TheBuilder;
2050 //-----------------------------------------------------------
2051 // Parse two sequences depending on the parameter on the edge.
2052 //-----------------------------------------------------------
2054 Change = Standard_False;
2055 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2056 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2057 ThePar.Exchange(i,i+1);
2058 TheVer.Exchange(i,i+1);
2059 Change = Standard_True;
2064 //----------------------------------------------------------
2065 // If a vertex is not in the proofing, it is eliminated.
2066 //----------------------------------------------------------
2067 if (!BRep_Tool::Degenerated(E)) {
2068 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2069 if ( DoubleOrNotInside (Detromp,
2070 TopoDS::Vertex(TheVer.Value(k)))) {
2078 //----------------------------------------------------------
2079 // If a vertex_double appears twice in the proofing
2080 // the vertex is removed.
2081 // otherwise preserve only one of its representations.
2082 //----------------------------------------------------------
2083 if (!BRep_Tool::Degenerated(E)) {
2084 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2085 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2086 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2088 if(k+1 == TheVer.Length()) {
2089 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2094 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2099 if ( DoubleOrNotInside (Detromp,
2100 TopoDS::Vertex(TheVer.Value(k)))) {
2110 //-----------------------------------------------------------
2111 // Creation of edges.
2112 // the number of vertices should be even. The created edges
2113 // go from a vertex with uneven index i to vertex i+1;
2114 //-----------------------------------------------------------
2115 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2116 TopoDS_Shape aLocalShape = E.EmptyCopied();
2117 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2118 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2120 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2121 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2122 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2125 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2126 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2130 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2134 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2135 DBRep::Set(name,NewEdge);
2140 Handle(Geom_Surface) Surf;
2141 Handle(Geom2d_Curve) C;
2142 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2143 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2144 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2145 Handle(DrawTrSurf_Curve2d) dr =
2146 new DrawTrSurf_Curve2d(C2d,Standard_False);
2147 dr->SetColor(Draw_bleu);
2156 //=======================================================================
2157 //function : DoubleOrNotInside
2158 //purpose : return True if V appears twice in LV or is not inside.
2159 //=======================================================================
2161 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2162 const TopoDS_Vertex& V)
2164 Standard_Boolean Vu = Standard_False;
2165 TopTools_ListIteratorOfListOfShape it(LV);
2167 for ( ; it.More(); it.Next()) {
2168 if (V.IsSame(it.Value())) {
2169 if (Vu) return Standard_True;
2170 else Vu = Standard_True;
2173 if (Vu) return Standard_False;
2174 else return Standard_True;
2177 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2178 const TopoDS_Vertex& aVertex)
2180 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2181 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2182 PV2d.SetCoord( PV.X(), PV.Y() );
2184 Handle(Geom2d_Curve) PCurve;
2185 Handle( BRep_CurveRepresentation ) CurveRep =
2186 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2187 PCurve = CurveRep->PCurve();
2189 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2190 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2191 Pfirst = PCurve->Value(fpar);
2192 Plast = PCurve->Value(lpar);
2193 Pmid = PCurve->Value((fpar + lpar)*0.5);
2195 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2198 Standard_Real dist1 = Pfirst.Distance(PV2d);
2199 Standard_Real dist2 = Plast.Distance(PV2d);
2200 Standard_Real dist3 = Pmid.Distance(PV2d);
2202 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2203 return Standard_True;
2205 return Standard_False;
2208 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2209 const BRepMAT2d_BisectingLocus& Locus,
2210 const BRepMAT2d_LinkTopoBilo& Link,
2211 TopTools_ListOfShape& BadEdges)
2214 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2215 Standard_Real eps = Precision::Confusion();
2216 Standard_Real LimCurv = 1./Offset;
2218 TopTools_MapOfShape aMap;
2220 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2221 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2222 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2223 if (SE.ShapeType() == TopAbs_EDGE) {
2225 if (aMap.Contains(SE)) {
2226 //cout << "Edge is treated second time" << endl;
2230 TopoDS_Edge E = TopoDS::Edge(SE);
2234 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2236 Geom2dAdaptor_Curve AC(G2d,f,l);
2237 GeomAbs_CurveType aCType = AC.GetType();
2239 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2241 Standard_Boolean reverse = Standard_False;
2242 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2247 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2249 aCLProps.SetParameter(f);
2250 if(!aCLProps.IsTangentDefined()) {
2251 BadEdges.Append(SE);
2256 P = aCLProps.Value();
2257 Standard_Real Crv = aCLProps.Curvature();
2260 aCLProps.Tangent(N);
2261 Standard_Real x = N.Y(), y = -N.X();
2263 if (reverse) N.Reverse();
2264 aCLProps.CentreOfCurvature(Pc);
2265 gp_Vec2d Dir( P, Pc );
2266 if (N.Dot(Dir) > 0.) {
2267 if (LimCurv <= Crv + eps) {
2268 BadEdges.Append(SE);
2275 aCLProps.SetParameter(l);
2276 if(!aCLProps.IsTangentDefined()) {
2277 BadEdges.Append(SE);
2282 P = aCLProps.Value();
2283 Crv = aCLProps.Curvature();
2286 aCLProps.Tangent(N);
2287 Standard_Real x = N.Y(), y = -N.X();
2289 if (reverse) N.Reverse();
2290 aCLProps.CentreOfCurvature(Pc);
2291 gp_Vec2d Dir( P, Pc );
2292 if (N.Dot(Dir) > 0.) {
2293 if (LimCurv <= Crv + eps) {
2294 BadEdges.Append(SE);
2307 //=======================================================================
2308 //function : PerformCurve
2310 //=======================================================================
2312 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2313 TColgp_SequenceOfPnt& Points,
2314 const Adaptor3d_Curve& C,
2315 const Standard_Real Deflection,
2316 const Standard_Real U1,
2317 const Standard_Real U2,
2318 const Standard_Real EPSILON,
2319 const Standard_Integer Nbmin)
2321 Standard_Real UU1 = Min(U1, U2);
2322 Standard_Real UU2 = Max(U1, U2);
2326 C.D1(UU1,Pdeb,Ddeb);
2327 Parameters.Append(UU1);
2328 Points.Append(Pdeb);
2330 C.D1(UU2,Pfin,Dfin);
2331 QuasiFleche(C,Deflection*Deflection,
2339 return Standard_True;
2341 //=======================================================================
2342 //function : QuasiFleche
2344 //=======================================================================
2346 static void QuasiFleche(const Adaptor3d_Curve& C,
2347 const Standard_Real Deflection2,
2348 const Standard_Real Udeb,
2351 const Standard_Real Ufin,
2354 const Standard_Integer Nbmin,
2355 const Standard_Real Eps,
2356 TColStd_SequenceOfReal& Parameters,
2357 TColgp_SequenceOfPnt& Points)
2359 Standard_Integer Ptslength = Points.Length();
2360 Standard_Real Udelta = Ufin-Udeb;
2365 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2373 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2374 Standard_Real theFleche=0;
2375 Standard_Boolean flecheok = Standard_False;
2377 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2378 Standard_Real N1 = Vdeb.SquareMagnitude();
2379 Standard_Real N2 = Vdelta.SquareMagnitude();
2380 if (N1 > Eps && N2 > Eps) {
2381 Standard_Real Normediff =
2382 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2383 if (Normediff > Eps) {
2384 theFleche = Normediff*Norme/64.;
2385 flecheok = Standard_True;
2390 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2391 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2392 theFleche = Pmid.SquareDistance(Pverif);
2395 if (theFleche < Deflection2) {
2396 Parameters.Append(Udeb+Udelta);
2397 Points.Append(Pdelta);
2400 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2411 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2415 Nbmin-(Points.Length()-Ptslength),