1 // Created on: 1995-04-20
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
19 #include <Adaptor3d_Curve.hxx>
20 #include <Adaptor3d_OffsetCurve.hxx>
21 #include <Bisector_Bisec.hxx>
22 #include <BRep_Builder.hxx>
23 #include <BRep_CurveRepresentation.hxx>
24 #include <BRep_GCurve.hxx>
25 #include <BRep_TEdge.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRep_TVertex.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <BRepAdaptor_Surface.hxx>
30 #include <BRepFill_DataMapOfNodeShape.hxx>
31 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
32 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
33 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
34 #include <BRepFill_OffsetWire.hxx>
35 #include <BRepFill_TrimEdgeTool.hxx>
36 #include <BRepLib.hxx>
37 #include <BRepLib_MakeEdge.hxx>
38 #include <BRepLib_MakeFace.hxx>
39 #include <BRepLib_MakeVertex.hxx>
40 #include <BRepLib_MakeWire.hxx>
41 #include <BRepMAT2d_BisectingLocus.hxx>
42 #include <BRepMAT2d_Explorer.hxx>
43 #include <BRepMAT2d_LinkTopoBilo.hxx>
44 #include <BRepTools.hxx>
45 #include <BRepTools_Substitution.hxx>
46 #include <BRepTools_WireExplorer.hxx>
47 #include <Geom2d_BSplineCurve.hxx>
48 #include <Geom2d_Circle.hxx>
49 #include <Geom2d_Curve.hxx>
50 #include <Geom2d_Line.hxx>
51 #include <Geom2d_OffsetCurve.hxx>
52 #include <Geom2d_TrimmedCurve.hxx>
53 #include <Geom2dAdaptor_Curve.hxx>
54 #include <Geom2dAdaptor_HCurve.hxx>
55 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
56 #include <Geom2dLProp_CLProps2d.hxx>
57 #include <Geom_Circle.hxx>
58 #include <Geom_Line.hxx>
59 #include <Geom_OffsetCurve.hxx>
60 #include <Geom_Plane.hxx>
61 #include <Geom_Surface.hxx>
62 #include <Geom_TrimmedCurve.hxx>
63 #include <GeomAPI.hxx>
66 #include <gp_Dir2d.hxx>
69 #include <MAT2d_CutCurve.hxx>
70 #include <MAT_Arc.hxx>
71 #include <MAT_Graph.hxx>
72 #include <MAT_Node.hxx>
73 #include <Precision.hxx>
74 #include <Standard_ConstructionError.hxx>
75 #include <Standard_ErrorHandler.hxx>
76 #include <Standard_NoSuchObject.hxx>
77 #include <Standard_NotImplemented.hxx>
78 #include <TColgp_Array1OfPnt2d.hxx>
79 #include <TColgp_SequenceOfPnt.hxx>
80 #include <TColStd_Array1OfInteger.hxx>
81 #include <TColStd_Array1OfReal.hxx>
82 #include <TColStd_SequenceOfReal.hxx>
85 #include <TopExp_Explorer.hxx>
87 #include <TopoDS_Compound.hxx>
88 #include <TopoDS_Face.hxx>
89 #include <TopoDS_Iterator.hxx>
90 #include <TopoDS_Shape.hxx>
91 #include <TopoDS_Wire.hxx>
92 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
93 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
94 #include <TopTools_DataMapOfShapeListOfShape.hxx>
95 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
96 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
97 #include <TopTools_IndexedMapOfShape.hxx>
98 #include <TopTools_ListIteratorOfListOfShape.hxx>
99 #include <TopTools_ListOfShape.hxx>
100 #include <TopTools_MapIteratorOfMapOfShape.hxx>
101 #include <TopTools_MapOfShape.hxx>
102 #include <TopTools_SequenceOfShape.hxx>
109 #include <DrawTrSurf.hxx>
110 #include <DrawTrSurf_Curve2d.hxx>
112 #include <Geom_Curve.hxx>
113 static Standard_Boolean AffichGeom = Standard_False;
114 static Standard_Boolean Affich2d = Standard_False;
115 static Standard_Boolean AffichEdge = Standard_False;
116 static Standard_Integer NbTRIMEDGES = 0;
117 static Standard_Integer NbOFFSET = 0;
118 static Standard_Integer NbEDGES = 0;
119 static Standard_Integer NbBISSEC = 0;
123 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
125 static void QuasiFleche(const Adaptor3d_Curve& C,
126 const Standard_Real Deflection2,
127 const Standard_Real Udeb,
130 const Standard_Real Ufin,
133 const Standard_Integer Nbmin,
134 const Standard_Real Eps,
135 TColStd_SequenceOfReal& Parameters,
136 TColgp_SequenceOfPnt& Points);
138 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
139 TColgp_SequenceOfPnt& Points,
140 const Adaptor3d_Curve& C,
141 const Standard_Real Deflection,
142 const Standard_Real U1,
143 const Standard_Real U2,
144 const Standard_Real EPSILON,
145 const Standard_Integer Nbmin);
147 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
148 const BRepMAT2d_BisectingLocus& Locus,
149 const BRepMAT2d_LinkTopoBilo& Link,
150 TopTools_ListOfShape& BadEdges);
152 static Standard_Integer CutEdge (const TopoDS_Edge& E,
153 const TopoDS_Face& F,
154 Standard_Integer ForceCut,
155 TopTools_ListOfShape& Cuts);
158 static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
159 const Standard_Integer nbParts,
160 TColGeom2d_SequenceOfCurve& theCurves);
161 // Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
164 static void EdgeVertices (const TopoDS_Edge& E,
168 if (E.Orientation() == TopAbs_REVERSED) {
169 TopExp::Vertices(E,V2,V1);
172 TopExp::Vertices(E,V1,V2);
175 static Standard_Boolean VertexFromNode
176 (const Handle(MAT_Node)& aNode,
177 const Standard_Real Offset,
179 BRepFill_DataMapOfNodeShape& MapNodeVertex,
182 static void StoreInMap (const TopoDS_Shape& V1,
183 const TopoDS_Shape& V2,
184 TopTools_IndexedDataMapOfShapeShape& MapVV);
186 static void TrimEdge (const TopoDS_Edge& CurrentEdge,
187 const TopoDS_Shape& CurrentSpine,
188 const TopoDS_Face& AllSpine,
189 const TopTools_ListOfShape& D,
190 TopTools_SequenceOfShape& Sv,
191 TColStd_SequenceOfReal& MapverPar,
192 TopTools_SequenceOfShape& S,
193 TopTools_IndexedDataMapOfShapeShape& MapVV,
194 const Standard_Integer IndOfE);
196 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
197 const TopoDS_Face& AllSpine,
198 Standard_Real& TrPar1,
199 Standard_Real& TrPar2);
201 static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
202 const TopoDS_Vertex& V);
204 static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
205 const TopoDS_Vertex& aVertex);
207 static void MakeCircle
208 (const TopoDS_Edge& E,
209 const TopoDS_Vertex& V,
210 const TopoDS_Face& F,
211 const Standard_Real Offset,
212 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
213 const Handle(Geom_Plane)& RefPlane);
215 static void MakeOffset
216 (const TopoDS_Edge& E,
217 const TopoDS_Face& F,
218 const Standard_Real Offset,
219 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
220 const Handle(Geom_Plane)& RefPlane,
221 const Standard_Boolean IsOpenResult,
222 const GeomAbs_JoinType theJoinType,
223 const TopoDS_Vertex * Ends);
225 //=======================================================================
226 //function : KPartCircle
228 //=======================================================================
230 static Standard_Boolean KPartCircle
231 (const TopoDS_Face& mySpine,
232 const Standard_Real myOffset,
233 const Standard_Boolean IsOpenResult,
234 const Standard_Real Alt,
235 TopoDS_Shape& myShape,
236 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
237 Standard_Boolean& myIsDone)
239 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
240 Standard_Integer NbEdges = 0;
243 for (; exp.More(); exp.Next()) {
245 E = TopoDS::Edge(exp.Current());
246 if (NbEdges > 1) return Standard_False;
251 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
253 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
254 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
255 C = Ct->BasisCurve();
258 if ((C->IsKind(STANDARD_TYPE(Geom_Circle)) && BRep_Tool::IsClosed(E)) || //closed circle
261 Standard_Real anOffset = myOffset;
263 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(E, mySpine, f, l);
264 Handle(Geom2dAdaptor_HCurve) AHC = new Geom2dAdaptor_HCurve(aPCurve, f, l);
265 Handle(Geom2d_Curve) OC;
266 if (AHC->GetType() == GeomAbs_Line)
268 if (E.Orientation() == TopAbs_REVERSED)
270 Adaptor3d_OffsetCurve Off(AHC,anOffset);
271 OC = new Geom2d_Line(Off.Line());
273 else if (AHC->GetType() == GeomAbs_Circle)
275 if (E.Orientation() == TopAbs_FORWARD)
277 gp_Circ2d theCirc = AHC->Circle();
278 if (anOffset > 0. || Abs(anOffset) < theCirc.Radius())
279 OC = new Geom2d_Circle (theCirc.Position(), theCirc.Radius() + anOffset);
282 myIsDone = Standard_False;
283 return Standard_False;
288 if (E.Orientation() == TopAbs_FORWARD)
290 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(aPCurve, f, l);
291 OC = new Geom2d_OffsetCurve( G2dT, anOffset);
293 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(mySpine);
294 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
295 myShape = BRepLib_MakeEdge(OC, aPlane, f, l);
296 BRepLib::BuildCurve3d(TopoDS::Edge(myShape));
298 myShape.Orientation(E.Orientation());
301 BRepAdaptor_Surface S(mySpine,0);
302 gp_Ax1 Nor = S.Plane().Axis();
304 gp_Vec Trans(Nor.Direction());
306 T.SetTranslation(Trans);
307 myShape.Move(TopLoc_Location(T));
310 TopTools_ListOfShape LL;
314 TopoDS_Edge myEdge = TopoDS::Edge(myShape);
315 myShape = BRepLib_MakeWire(myEdge);
317 myIsDone = Standard_True;
318 return Standard_True;
321 return Standard_False;
324 //=======================================================================
325 //function : BRepFill_OffsetWire
327 //=======================================================================
329 BRepFill_OffsetWire::BRepFill_OffsetWire()
330 : myIsOpenResult(Standard_False),
331 myIsDone(Standard_False)
336 //=======================================================================
337 //function : BRepFill_OffsetWire
339 //=======================================================================
341 BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
342 const GeomAbs_JoinType Join,
343 const Standard_Boolean IsOpenResult)
345 Init(Spine,Join,IsOpenResult);
348 //=======================================================================
351 //=======================================================================
353 void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
354 const GeomAbs_JoinType Join,
355 const Standard_Boolean IsOpenResult)
357 myIsDone = Standard_False;
358 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
359 mySpine = TopoDS::Face(aLocalShape);
360 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
362 myIsOpenResult = IsOpenResult;
366 //------------------------------------------------------------------
367 // cut the spine for bissectors.
368 //------------------------------------------------------------------
369 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
370 static BRepMAT2d_Explorer Exp;
372 Exp.Perform(mySpine);
374 // TopoDS_Face anOldSpine = mySpine;
376 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
379 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
381 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
382 Standard_Boolean Done;
383 if (KPartCircle(myWorkSpine,1.,myIsOpenResult,0.,aShape,aMap,Done)) return;
386 //-----------------------------------------------------
387 // Calculate the map of bissectors to the left.
388 // and Links Topology -> base elements of the map.
389 //-----------------------------------------------------
391 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
392 // static BRepMAT2d_Explorer Exp;
393 // Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
394 Exp.Perform(myWorkSpine);
395 myBilo.Compute(Exp, 1 ,MAT_Left, myJoinType, myIsOpenResult);
396 myLink.Perform(Exp,myBilo);
400 //=======================================================================
403 //=======================================================================
405 Standard_Boolean BRepFill_OffsetWire::IsDone() const
411 //=======================================================================
414 //=======================================================================
416 const TopoDS_Face& BRepFill_OffsetWire::Spine() const
422 //=======================================================================
425 //=======================================================================
427 const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
433 //=======================================================================
434 //function : GeneratedShapes
436 //=======================================================================
438 const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
439 (const TopoDS_Shape& SpineShape)
442 if (!myMapSpine.IsEmpty()) {
443 // myMapSpine can be empty if passed by PerformWithBilo.
444 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
445 for (; it.More(); it.Next()) {
446 if (myMap.Contains(it.Key())) {
447 if (!myMap.Contains(it.Value())) {
448 TopTools_ListOfShape L;
449 myMap.Add(it.Value(),L);
451 if ( !it.Value().IsSame(it.Key())) {
452 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
453 //myMap.UnBind(it.Key());
454 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
455 TopTools_ListOfShape LastList;
456 LastList.Append(myMap(myMap.Extent()));
458 if (myMap.FindIndex(it.Key()) != 0)
459 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
462 if (myMap.Contains(it.Key().Reversed())) {
463 if (!myMap.Contains(it.Value().Reversed())) {
464 TopTools_ListOfShape L;
465 myMap.Add(it.Value().Reversed(),L);
467 if ( !it.Value().IsSame(it.Key())) {
468 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
469 //myMap.UnBind(it.Key().Reversed());
470 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
471 TopTools_ListOfShape LastList;
472 LastList.Append(myMap(myMap.Extent()));
474 if (myMap.FindIndex(it.Key().Reversed()) != 0)
475 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
480 myCallGen = Standard_True;
483 if (myMap.Contains(SpineShape)) {
484 return myMap.FindFromKey(SpineShape);
487 static TopTools_ListOfShape Empty;
493 //=======================================================================
494 //function : JoinType
496 //=======================================================================
498 GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
503 //=======================================================================
506 //=======================================================================
508 void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
509 const Standard_Real Alt)
511 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
515 myCallGen = Standard_False;
516 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone)) return;
518 TopoDS_Face oldWorkSpain = myWorkSpine;
520 TopTools_ListOfShape BadEdges;
521 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
523 if(!BadEdges.IsEmpty())
525 // Modification of myWorkSpine;
526 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
527 BRepTools_Substitution aSubst;
528 TopTools_ListIteratorOfListOfShape it(BadEdges);
529 TopTools_ListOfShape aL;
530 Standard_Real aDefl = .01 * Abs(Offset);
531 TColStd_SequenceOfReal Parameters;
532 TColgp_SequenceOfPnt Points;
534 for(; it.More(); it.Next()) {
538 const TopoDS_Shape& anE = it.Value();
540 TopoDS_Vertex Vf, Vl;
541 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
544 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
545 GeomAdaptor_Curve AC(G3d,f,l);
547 PerformCurve(Parameters, Points, AC, aDefl, f,
548 l, Precision::Confusion(), 2);
550 Standard_Integer NPnts = Points.Length();
553 //cout << NPnts << " points " << endl;
554 TopoDS_Vertex FV = Vf;
558 for(np = 2; np < NPnts; np++) {
559 gp_Pnt LP = Points(np);
560 LV = BRepLib_MakeVertex(LP);
561 newE = BRepLib_MakeEdge(FV, LV);
566 newE = BRepLib_MakeEdge(FV, LV);
571 //cout << " 2 points " << endl;
572 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
576 if (myMapSpine.IsBound( anE ))
578 TopTools_ListIteratorOfListOfShape newit( aL );
579 for (; newit.More(); newit.Next())
581 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
582 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
583 TopoDS_Vertex NewV1, NewV2;
584 EdgeVertices( NewEdge, NewV1, NewV2 );
585 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
586 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
588 myMapSpine.UnBind( anE );
591 aSubst.Substitute(anE, aL);
594 TopTools_DataMapOfShapeListOfShape wwmap;
595 TopoDS_Iterator itws( myWorkSpine );
596 for (; itws.More(); itws.Next())
598 TopoDS_Shape aWire = itws.Value();
599 aSubst.Build( aWire );
600 if (aSubst.IsCopied(aWire))
602 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
603 NewWire.Closed( aWire.Closed() );
604 TopTools_ListOfShape Lw;
605 Lw.Append( NewWire );
606 wwmap.Bind( aWire, Lw );
610 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
611 for (; itmap.More(); itmap.Next())
612 aSubst.Substitute( itmap.Key(), itmap.Value() );
614 aSubst.Build(myWorkSpine);
616 if(aSubst.IsCopied(myWorkSpine)) {
617 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
619 BRepMAT2d_Explorer newExp;
620 newExp.Perform(myWorkSpine);
621 BRepMAT2d_BisectingLocus newBilo;
622 BRepMAT2d_LinkTopoBilo newLink;
623 newBilo.Compute(newExp, 1, MAT_Left, myJoinType, myIsOpenResult);
625 if(!newBilo.IsDone())
628 myIsDone = Standard_False;
632 newLink.Perform(newExp,newBilo);
633 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
634 myWorkSpine = oldWorkSpain;
637 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
642 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
645 catch (Standard_Failure)//Every exception was caught.
648 myIsDone = Standard_False;
650 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
651 Standard_Failure::Caught()->Print(cout);
658 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
659 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
662 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
664 for (; anExp.More(); anExp.Next()) {
665 const TopoDS_Shape &aWire = anExp.Current();
667 if (!aWire.Closed()) {
669 myIsDone = Standard_False;
670 Standard_ConstructionError::Raise("Offset wire is not closed.");
674 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
677 //=======================================================================
680 //=======================================================================
682 void Compute (const TopoDS_Face& Spine,
683 TopoDS_Shape& aShape,
684 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
685 const Standard_Real Alt)
688 B.MakeCompound(TopoDS::Compound(aShape));
689 Standard_Real ALT = Alt;
690 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
692 T.SetTranslation(gp_Vec(0.,0.,ALT));
693 TopLoc_Location L(T);
695 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
696 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
697 TopoDS_Shape aLocalShape = CurW.Moved(L);
698 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
699 // TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
702 TopoDS_Iterator it1( CurW);
703 TopoDS_Iterator it2( NewW);
704 for ( ; it1.More(); it1.Next(), it2.Next()) {
705 TopTools_ListOfShape List;
706 List.Append(it2.Value());
707 Map.Add(it1.Value(), List);
712 //=======================================================================
713 //function : PerformWithBiLo
715 //=======================================================================
717 void BRepFill_OffsetWire::PerformWithBiLo
718 (const TopoDS_Face& Spine,
719 const Standard_Real Offset,
720 const BRepMAT2d_BisectingLocus& Locus,
721 BRepMAT2d_LinkTopoBilo& Link,
722 const GeomAbs_JoinType Join,
723 const Standard_Real Alt)
725 myIsDone = Standard_False;
726 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
727 myWorkSpine = TopoDS::Face(aLocalShape);
728 // myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
734 if (mySpine.IsNull()) {
735 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
736 mySpine = TopoDS::Face(aLocalShape);
737 // mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
741 if ( Abs(myOffset) < Precision::Confusion()) {
742 Compute(mySpine,myShape,myMap,Alt);
743 myIsDone = Standard_True;
747 //********************************
748 // Calculate for a non null offset
749 //********************************
750 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone))
753 BRep_Builder myBuilder;
754 myBuilder.MakeCompound(TopoDS::Compound(myShape));
756 //---------------------------------------------------------------------
757 // MapNodeVertex : associate to each node of the map (key1) and to
758 // each element of the profile (key2) a vertex (item).
759 // MapBis : all edges or vertices (item) generated by
760 // a bisectrice on a face or an edge (key) of revolution tubes.
761 // MapVerPar : Map of parameters of vertices on parallel edges
762 // the list contained in MapVerPar (E) corresponds to
763 // parameters on E of vertices contained in MapBis(E);
764 //---------------------------------------------------------------------
767 BRepFill_DataMapOfNodeShape MapNodeVertex;
768 TopTools_DataMapOfShapeSequenceOfShape MapBis;
769 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
771 TopTools_DataMapOfShapeShape EmptyMap;
772 TopTools_SequenceOfShape EmptySeq;
773 TopTools_ListOfShape EmptyList;
774 TColStd_SequenceOfReal EmptySeqOfReal;
776 Standard_Real ALT = Alt;
777 Handle(Geom_Plane) RefPlane =
778 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
779 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
780 RefPlane = Handle(Geom_Plane)::DownCast
781 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
783 //---------------------------------------------------------------
784 // Construction of Circles and OffsetCurves
785 //---------------------------------------------------------------
787 TopoDS_Vertex Ends [2];
791 TopoDS_Iterator iter(mySpine);
792 theWire = TopoDS::Wire(iter.Value());
793 TopExp::Vertices(theWire, Ends[0], Ends[1]);
796 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
797 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
798 TopoDS_Shape& PE = PEE ;
799 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
800 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
801 if (SE.ShapeType() == TopAbs_VERTEX) {
802 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
803 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
804 myWorkSpine,myOffset,myMap,RefPlane);
807 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
808 myIsOpenResult, myJoinType, Ends);
814 //Remove possible hanging arcs on vertices
815 if (myIsOpenResult && myJoinType == GeomAbs_Arc)
817 if (!myMap.IsEmpty() &&
818 myMap.FindKey(1).ShapeType() == TopAbs_VERTEX)
820 //myMap.RemoveFirst();
821 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
822 TopTools_ListOfShape LastList;
823 LastList.Append(myMap(myMap.Extent()));
825 if (!myMap.IsEmpty())
826 myMap.Substitute(1, LastShape, LastList);
828 if (!myMap.IsEmpty() &&
829 myMap.FindKey(myMap.Extent()).ShapeType() == TopAbs_VERTEX)
836 cout << " End Construction of geometric primitives "<<endl;
842 //---------------------------------------------------
843 // Construction of offset vertices.
844 //---------------------------------------------------
845 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
846 Handle(MAT_Arc) CurrentArc;
847 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
848 Handle(Geom_Curve) CBis;
849 Standard_Boolean Reverse;
850 TopoDS_Edge CurrentEdge;
854 Standard_Integer j, k;
856 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
858 CurrentArc = Locus.Graph()->Arc(i);
859 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
865 sprintf(name,"BISSEC_%d",NbBISSEC++);
866 DrawTrSurf::Set(name,Bisec.Value());
871 //-------------------------------------------------------------------
872 // Return elements of the spine corresponding to separate basicElts.
873 //-------------------------------------------------------------------
874 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
875 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
877 TopTools_SequenceOfShape Vertices;
878 TColgp_SequenceOfPnt Params;
880 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
881 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
883 //-----------------------------------------------------------
884 // Return parallel edges on each face.
885 // If no offset generated => move to the next bissectrice.
886 //--------------------------------------------------------------
887 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
888 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
889 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
893 //-----------------------------------------------------------
894 // Construction of vertices corresponding to the node of the map.
895 // if they are on the offset.
896 //-----------------------------------------------------------
898 Handle(MAT_Node) Node1, Node2;
901 Node1 = CurrentArc->SecondNode();
902 Node2 = CurrentArc->FirstNode();
905 Node1 = CurrentArc->FirstNode();
906 Node2 = CurrentArc->SecondNode();
909 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
911 if (!Node1->Infinite()) {
912 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
913 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
914 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
915 // MapNodeVertex,VS);
917 if (!Node2->Infinite()) {
918 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
919 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
920 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
921 // MapNodeVertex,VE);
924 if (myJoinType == GeomAbs_Intersection)
925 StartOnEdge = EndOnEdge = 0;
927 //---------------------------------------------
928 // Construction of geometries.
929 //---------------------------------------------
930 BRepFill_TrimEdgeTool Trim (Bisec,
931 Locus.GeomElt(CurrentArc->FirstElement()),
932 Locus.GeomElt(CurrentArc->SecondElement()),
935 //-----------------------------------------------------------
936 // Construction of vertices on edges parallel to the spine.
937 //-----------------------------------------------------------
939 Trim.IntersectWith(E [0], E [1], myJoinType, Params);
941 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
943 myBuilder.MakeVertex (VC);
944 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
945 gp_Pnt PVC(P2.X(),P2.Y(),0.);
947 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
951 Standard_Boolean Start = 1;
952 Trim.AddOrConfuse(Start, E[0], E[1], Params);
953 if (Params.Length() == Vertices.Length())
954 Vertices.SetValue(1,VS);
957 // the point was not found by IntersectWith
958 Vertices.Prepend(VS);
961 Standard_Boolean Start = 0;
962 Trim.AddOrConfuse(Start, E[0], E[1], Params);
963 if (Params.Length() == Vertices.Length())
964 Vertices.SetValue(Params.Length(),VE);
967 // the point was not found by IntersectWith
971 //------------------------------------------------------------
973 // Detromp allows to remove vertices on the offset
974 // corresponding to tangency zones
975 // Detromp ranks the vertices that limit
976 // the parts of the bissectrices located between the spine and the
978 //------------------------------------------------------------
979 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
980 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
983 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
984 Bisec, StartOnEdge, EndOnEdge, Trim);
985 //----------------------------------------------
986 // Storage of vertices on parallel edges.
987 // fill MapBis and MapVerPar.
988 //----------------------------------------------
989 if (!Vertices.IsEmpty()) {
990 for (k = 0; k <= 1; k++) {
991 if (!MapBis.IsBound(E[k])) {
992 MapBis .Bind(E[k],EmptySeq);
993 MapVerPar.Bind(E[k],EmptySeqOfReal);
995 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
996 MapBis (E[k]).Append(Vertices.Value(ii));
997 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
998 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
1003 //------------------------------------------------------------
1004 // FOR COMPLETE CIRCLES. the parallel line can be contained
1005 // in the zone without intersection with the border
1007 // if myoffset is < distance of nodes the parallel can be valid.
1008 //-------------------------------------------------------------
1009 for (k = 0; k <= 1; k++) {
1010 if (!MapBis.IsBound(E[k])) {
1011 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
1012 MapBis .Bind(E[k],EmptySeq);
1013 MapVerPar.Bind(E[k],EmptySeqOfReal);
1023 cout << " End Construction of vertices on offsets"<<endl;
1028 //----------------------------------
1029 // Construction of parallel edges.
1030 //----------------------------------
1031 TopTools_IndexedDataMapOfShapeShape MapVV;
1033 TopoDS_Shape CurrentSpine;
1035 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
1037 for (j = 1; j <= myMap.Extent(); j++) {
1038 CurrentSpine = myMap.FindKey(j);
1039 CurrentEdge = TopoDS::Edge(myMap(j).First());
1042 if (MapBis.IsBound(CurrentEdge)) {
1043 TopTools_SequenceOfShape S;
1044 if (!MapBis(CurrentEdge).IsEmpty()) {
1045 Standard_Integer IndOfE = 0;
1050 else if (j == myMap.Extent())
1053 TrimEdge (CurrentEdge,
1056 Detromp (CurrentSpine),
1057 MapBis (CurrentEdge) ,
1058 MapVerPar(CurrentEdge) ,
1060 for ( k = 1; k <= S.Length(); k++) {
1061 myMap(j).Append(S.Value(k));
1068 myMap(j).Append(CurrentEdge);
1073 Standard_Integer ind;
1074 for (ind = 1; ind <= MapVV.Extent(); ind++)
1076 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1077 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1078 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1079 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1080 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1081 TopTools_ListOfShape LV;
1082 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1083 BRepTools_Substitution aSubst;
1084 aSubst.Substitute( OldV, LV );
1085 for (j = 1; j <= myMap.Extent(); j++)
1087 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1088 for (; itl.More(); itl.Next())
1090 aSubst.Build(itl.Value());
1091 if (aSubst.IsCopied(itl.Value()))
1093 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1094 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1095 itl.Value() = listSh.First();
1096 itl.Value().Orientation(SaveOr);
1102 //----------------------------------
1103 // Construction of offset wires.
1104 //----------------------------------
1107 // Update vertices ( Constructed in the plane Z = 0) !!!
1108 TopTools_MapOfShape MapVertex;
1109 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1110 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1111 if ( MapVertex.Add(V)) {
1112 gp_Pnt P = BRep_Tool::Pnt(V);
1113 P = RefPlane->Value(P.X(),P.Y());
1114 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1118 // Construction of curves 3d.
1119 BRepLib::BuildCurves3d(myShape);
1121 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1122 for (; Explo.More(); Explo.Next())
1124 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1125 TopoDS_Vertex V1, V2;
1126 TopExp::Vertices( E, V1, V2 );
1127 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1128 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1130 TopLoc_Location loc;
1132 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1133 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1134 theCurve->Transform( loc.Transformation() );
1135 gp_Pnt f3d = theCurve->Value( f );
1136 gp_Pnt l3d = theCurve->Value( l );
1138 Standard_Real dist1, dist2;
1139 dist1 = f3d.Distance( TV1->Pnt() );
1140 dist2 = l3d.Distance( TV2->Pnt() );
1141 if (! MapVertex.Contains( V1 ))
1145 MapVertex.Add( V1 );
1148 TV1->UpdateTolerance( 1.5*dist1 );
1149 if (! MapVertex.Contains( V2 ))
1152 MapVertex.Add( V2 );
1155 TV2->UpdateTolerance( 1.5*dist2 );
1158 if (!myIsOpenResult)
1161 myIsDone = Standard_True;
1165 //=======================================================================
1166 //function : Generated
1168 //=======================================================================
1170 BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
1171 BRepFill_OffsetWire::Generated()
1177 //=======================================================================
1178 //function : PrepareSpine
1180 //=======================================================================
1182 void BRepFill_OffsetWire::PrepareSpine()
1185 TopTools_ListOfShape Cuts;
1186 TopTools_ListIteratorOfListOfShape IteCuts;
1187 TopoDS_Vertex V1,V2;
1189 myWorkSpine.Nullify();
1193 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1194 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1195 B.MakeFace(myWorkSpine,S,L,TolF);
1197 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1202 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1203 Standard_Integer ForcedCut = 0;
1204 Standard_Integer nbResEdges = -1;
1205 TopTools_IndexedMapOfShape EdgeMap;
1207 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1208 Standard_Integer nbEdges = EdgeMap.Extent();
1210 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
1212 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1214 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1216 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1217 EdgeVertices(E,V1,V2);
1218 myMapSpine.Bind(V1,V1);
1219 myMapSpine.Bind(V2,V2);
1223 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1224 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1225 if (nbEdges == 2 && nbResEdges == 0)
1227 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1228 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1230 if (Cuts.IsEmpty()) {
1232 myMapSpine.Bind(E,E);
1235 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1236 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1237 NE.Orientation(E.Orientation());
1239 myMapSpine.Bind(NE,E);
1240 EdgeVertices(NE,V1,V2);
1241 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1242 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1246 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1250 TopExp::Vertices(NW, aV1, aV2);
1252 NW.Closed(aV1.IsSame(aV2));
1254 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1255 B.Add(myWorkSpine, NW);
1261 DBRep::Set("WS",myWorkSpine);
1262 DBRep::Set("MS",mySpine);
1263 BRepTools::Write(myWorkSpine, "WS");
1264 BRepTools::Write(mySpine, "MS");
1271 //=======================================================================
1272 //function : UpdateDetromp
1273 //purpose : For each interval on bissectrice defined by parameters
1274 // test if the medium point is at a distance > offset
1275 // in this case vertices corresponding to the extremities of the interval
1276 // are ranked in the proofing.
1277 // => If the same vertex appears in the proofing, the
1278 // border of the zone of proximity is tangent to the offset .
1279 //=======================================================================
1281 void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1282 const TopoDS_Shape& Shape1,
1283 const TopoDS_Shape& Shape2,
1284 const TopTools_SequenceOfShape& Vertices,
1285 const TColgp_SequenceOfPnt& Params,
1286 const Bisector_Bisec& Bisec,
1287 const Standard_Boolean SOnE,
1288 const Standard_Boolean EOnE,
1289 const BRepFill_TrimEdgeTool& Trim) const
1291 Standard_Integer ii = 1;
1292 Standard_Real U1,U2;
1293 TopoDS_Vertex V1,V2;
1295 Handle(Geom2d_Curve) Bis (Bisec.Value());
1297 U1 = Bis->FirstParameter();
1300 // the first point of the bissectrice is on the offset
1301 V1 = TopoDS::Vertex(Vertices.Value(ii));
1305 while (ii <= Vertices.Length()) {
1306 U2 = Params.Value(ii).X();
1307 V2 = TopoDS::Vertex(Vertices.Value(ii));
1309 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1310 Standard_Boolean IsP_inside = Standard_True;
1311 if ((myJoinType != GeomAbs_Intersection) || EOnE)
1312 IsP_inside = Trim.IsInside(P);
1315 Detromp(Shape1).Append(V1);
1316 Detromp(Shape2).Append(V1);
1318 Detromp(Shape1).Append(V2);
1319 Detromp(Shape2).Append(V2);
1326 // test medium point between the last parameter and the end of the bissectrice.
1327 U2 = Bis->LastParameter();
1329 if (!Precision::IsInfinite(U2)) {
1330 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1331 Standard_Boolean IsP_inside = Standard_False;
1332 if (myJoinType == GeomAbs_Arc)
1333 IsP_inside = Trim.IsInside(P);
1336 Detromp(Shape1).Append(V1);
1337 Detromp(Shape2).Append(V1);
1343 Detromp(Shape1).Append(V1);
1344 Detromp(Shape2).Append(V1);
1348 //else if(myJoinType != GeomAbs_Arc)
1350 // if (!V1.IsNull()) {
1351 // Detromp(Shape1).Append(V1);
1352 // Detromp(Shape2).Append(V1);
1357 //=======================================================================
1358 //function : MakeWires
1360 //=======================================================================
1362 void BRepFill_OffsetWire::MakeWires()
1364 //--------------------------------------------------------
1365 // creation of a single list of created parallel edges.
1366 //--------------------------------------------------------
1367 TopTools_SequenceOfShape TheEdges;
1368 TopTools_ListOfShape TheWires;
1369 TopTools_ListIteratorOfListOfShape itl;
1370 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1371 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1372 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
1373 TopoDS_Vertex V1,V2,VF,CV;
1376 for (i = 1; i <= myMap.Extent(); i++) {
1377 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
1378 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1379 TopExp::Vertices (E,V1,V2);
1380 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1381 continue; //remove small closed edges
1382 if (!MVE.Contains(V1)) {
1383 TopTools_ListOfShape empty;
1386 MVE.ChangeFromKey(V1).Append(E);
1387 if (!MVE.Contains(V2)) {
1388 TopTools_ListOfShape empty;
1391 MVE.ChangeFromKey(V2).Append(E);
1395 //--------------------------------------
1396 // Creation of parallel wires.
1397 //--------------------------------------
1401 // Standard_Integer NbEdges;
1402 // Standard_Boolean NewWire = Standard_True;
1403 // Standard_Boolean AddEdge = Standard_False;
1406 Standard_Boolean End;
1409 while (!MVE.IsEmpty()) {
1412 //MVEit.Initialize(MVE);
1413 for (i = 1; i <= MVE.Extent(); i++)
1414 if(MVE(i).Extent() == 1)
1417 //if(!MVEit.More()) MVEit.Initialize(MVE);
1418 if (i > MVE.Extent())
1421 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1422 CE = TopoDS::Edge(MVE(i).First());
1423 End = Standard_False;
1424 MVE.ChangeFromKey(CV).RemoveFirst();
1426 if (myIsOpenResult && MVE.FindFromKey(CV).IsEmpty())
1429 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1430 TopTools_ListOfShape LastList;
1431 LastList.Append(MVE(MVE.Extent()));
1433 if (MVE.FindIndex(CV) != 0)
1434 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1438 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1439 Standard_Boolean isClosed = Standard_False;
1441 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1444 //-------------------------------
1445 // Construction of a wire.
1446 //-------------------------------
1447 TopExp::Vertices(CE,V1,V2);
1448 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1452 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
1453 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1454 isClosed = VF.IsSame(CV);
1455 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1456 End = Standard_True;
1458 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1459 TopTools_ListOfShape LastList;
1460 LastList.Append(MVE(MVE.Extent()));
1462 if (MVE.FindIndex(VF) != 0)
1463 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
1467 if (MVE.FindFromKey(CV).Extent() > 2) {
1468 //cout <<"vertex on more that 2 edges in a face."<<endl;
1470 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1471 if (itl.Value().IsSame(CE)) {
1472 MVE.ChangeFromKey(CV).Remove(itl);
1476 if (!MVE.FindFromKey(CV).IsEmpty()) {
1477 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1478 MVE.ChangeFromKey(CV).RemoveFirst();
1480 else if (myIsOpenResult)//CV was a vertex with one edge
1481 End = Standard_True;
1483 if (MVE.FindFromKey(CV).IsEmpty())
1486 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1487 TopTools_ListOfShape LastList;
1488 LastList.Append(MVE(MVE.Extent()));
1490 if (MVE.FindIndex(CV) != 0)
1491 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1495 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1496 // NW.Closed(Standard_True);
1497 NW.Closed(isClosed);
1498 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1499 TheWires.Append(NW);
1503 // -- if only one wire : myShape is a Wire
1504 // -- if several wires : myShape is a Compound.
1505 if ( TheWires.Extent() == 1) {
1506 myShape = TheWires.First();
1511 TopTools_ListIteratorOfListOfShape it(TheWires);
1512 for ( ; it.More(); it.Next()) {
1513 B.Add(R, it.Value());
1520 //=======================================================================
1521 //function : FixHoles
1523 //=======================================================================
1525 void BRepFill_OffsetWire::FixHoles()
1527 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1529 Standard_Real MaxTol = 0.;
1533 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1534 for (; Explo.More(); Explo.Next())
1536 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1537 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1543 Explo.Init( myShape, TopAbs_WIRE );
1544 for (; Explo.More(); Explo.Next())
1546 TopoDS_Shape aWire = Explo.Current();
1547 // Remove duplicated edges
1548 TopTools_DataMapOfShapeListOfShape EEmap;
1549 TopoDS_Iterator it( aWire );
1550 for (; it.More(); it.Next())
1552 const TopoDS_Shape& anEdge = it.Value();
1553 if (! EEmap.IsBound( anEdge ))
1555 TopTools_ListOfShape LE;
1556 EEmap.Bind( anEdge, LE );
1559 EEmap(anEdge).Append( anEdge );
1561 aWire.Free( Standard_True );
1562 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1563 for (; mapit.More(); mapit.Next())
1565 const TopTools_ListOfShape& LE = mapit.Value();
1566 TopTools_ListIteratorOfListOfShape itl( LE );
1567 for (; itl.More(); itl.Next())
1568 BB.Remove( aWire, itl.Value() );
1572 ClosedWires.Append( aWire );
1574 UnclosedWires.Append( aWire );
1577 while (!UnclosedWires.IsEmpty())
1579 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1580 TopoDS_Vertex Vf, Vl;
1581 TopExp::Vertices( Base, Vf, Vl );
1582 if(Vf.IsNull() || Vl.IsNull())
1584 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1586 BRepTools::Write(Base, "Base");
1590 Pf = BRep_Tool::Pnt(Vf);
1591 Pl = BRep_Tool::Pnt(Vl);
1592 Standard_Real DistF = RealLast(), DistL = RealLast();
1593 Standard_Integer IndexF = 1, IndexL = 1;
1594 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1595 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
1597 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1598 TopoDS_Vertex V1, V2;
1599 TopExp::Vertices( aWire, V1, V2 );
1601 if(V1.IsNull() || V2.IsNull())
1603 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1605 BRepTools::Write(Base, "Base");
1607 sprintf(name,"Wire_%d",i);
1608 BRepTools::Write(aWire, name);
1613 P1 = BRep_Tool::Pnt(V1);
1614 P2 = BRep_Tool::Pnt(V2);
1615 Standard_Real dist = Pf.Distance( P1 );
1620 IsFirstF = Standard_True;
1622 dist = Pf.Distance( P2 );
1627 IsFirstF = Standard_False;
1629 dist = Pl.Distance( P1 );
1634 IsFirstL = Standard_True;
1636 dist = Pl.Distance( P2 );
1641 IsFirstL = Standard_False;
1644 TopoDS_Wire theWire;
1645 TopoDS_Edge theEdge;
1646 TopoDS_Vertex theVertex;
1647 Standard_Real CommonTol;
1648 Standard_Boolean TryToClose = Standard_True;
1649 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1661 TryToClose = Standard_False;
1663 if (DistF <= MaxTol)
1665 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1666 TopoDS_Vertex V1, V2;
1667 TopExp::Vertices( theWire, V1, V2 );
1668 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1669 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1670 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1671 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1672 TopoDS_Iterator it( theWire );
1673 for (; it.More(); it.Next())
1675 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1676 if (IsFirstF) anEdge.Reverse();
1677 if (!anEdge.IsSame( theEdge ))
1678 BB.Add( Base, anEdge );
1680 theVertex = (IsFirstF)? V1 : V2;
1681 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1682 if (DistF <= CommonTol)
1684 theEdge.Free( Standard_True );
1685 Vf.Orientation( theVertex.Orientation() );
1686 BB.Remove( theEdge, theVertex );
1687 BB.Add( theEdge, Vf );
1688 BB.UpdateVertex( Vf, CommonTol );
1689 if (IsFirstF) theEdge.Reverse();
1690 BB.Add( Base, theEdge );
1694 if (IsFirstF) theEdge.Reverse();
1695 BB.Add( Base, theEdge );
1696 // Creating new edge from theVertex to Vf
1697 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1698 BB.Add( Base, NewEdge );
1701 if (DistL <= MaxTol && IndexL != IndexF)
1703 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1704 TopoDS_Vertex V1, V2;
1705 TopExp::Vertices( theWire, V1, V2 );
1706 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1707 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1708 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1709 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1710 TopoDS_Iterator it( theWire );
1711 for (; it.More(); it.Next())
1713 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1714 if (!IsFirstL) anEdge.Reverse();
1715 if (!anEdge.IsSame( theEdge ))
1716 BB.Add( Base, anEdge );
1718 theVertex = (IsFirstL)? V1 : V2;
1719 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1720 if (DistL <= CommonTol)
1722 theEdge.Free( Standard_True );
1723 Vl.Orientation( theVertex.Orientation() );
1724 BB.Remove( theEdge, theVertex );
1725 BB.Add( theEdge, Vl );
1726 BB.UpdateVertex( Vl, CommonTol );
1727 if (!IsFirstL) theEdge.Reverse();
1728 BB.Add( Base, theEdge );
1732 if (!IsFirstL) theEdge.Reverse();
1733 BB.Add( Base, theEdge );
1734 // Creating new edge from Vl to theVertex
1735 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1736 BB.Add( Base, NewEdge );
1739 // Check if it is possible to close resulting wire
1742 TopExp::Vertices( Base, Vf, Vl );
1743 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1744 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1745 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1746 TopoDS_Edge Efirst, Elast;
1747 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1748 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
1749 Pf = BRep_Tool::Pnt(Vf);
1750 Pl = BRep_Tool::Pnt(Vl);
1751 Standard_Real Dist = Pf.Distance(Pl);
1752 if (Dist <= CommonTol)
1754 Elast.Free( Standard_True );
1755 Vf.Orientation( Vl.Orientation() );
1756 BB.Remove( Elast, Vl );
1757 BB.Add( Elast, Vf );
1758 BB.UpdateVertex( Vf, CommonTol );
1759 Base.Closed( Standard_True );
1761 else if (Dist <= MaxTol)
1763 // Creating new edge from Vl to Vf
1764 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1765 BB.Add( Base, NewEdge );
1766 Base.Closed( Standard_True );
1769 // Updating sequences ClosedWires and UnclosedWires
1770 if (DistF <= MaxTol)
1771 UnclosedWires.Remove( IndexF );
1772 if (DistL <= MaxTol && IndexL != IndexF)
1774 if (DistF <= MaxTol && IndexL > IndexF)
1776 UnclosedWires.Remove( IndexL );
1780 ClosedWires.Append( Base );
1781 UnclosedWires.Remove( 1 );
1783 else if (DistF > MaxTol && DistL > MaxTol)
1785 IsolatedWires.Append( Base );
1786 UnclosedWires.Remove( 1 );
1791 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1793 if (!ClosedWires.IsEmpty())
1794 myShape = ClosedWires.First();
1796 myShape = IsolatedWires.First();
1801 BB.MakeCompound( R );
1802 for (i = 1; i <= ClosedWires.Length(); i++)
1803 BB.Add( R, ClosedWires(i) );
1804 for (i = 1; i <= IsolatedWires.Length(); i++)
1805 BB.Add( R, IsolatedWires(i) );
1810 //=======================================================================
1811 //function : CutEdge
1812 //purpose : Cut edge at the extrema of curvatures and points of inflexion.
1813 // So, closed circles are cut in two.
1814 // If <Cuts> is empty, the edge is not modified.
1815 // The first and the last vertex of the initial edge
1816 // belong to the first and the last parts respectively.
1817 //=======================================================================
1818 Standard_Integer CutEdge (const TopoDS_Edge& E,
1819 const TopoDS_Face& F,
1820 Standard_Integer ForceCut,
1821 TopTools_ListOfShape& Cuts)
1824 MAT2d_CutCurve Cuter;
1825 TColGeom2d_SequenceOfCurve theCurves;
1827 Handle(Geom2d_Curve) C2d;
1828 Handle(Geom2d_TrimmedCurve) CT2d;
1829 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1830 Standard_Real aTol = BRep_Tool::Tolerance(E);
1831 Handle(Geom_Curve) aC;
1832 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1834 TopoDS_Vertex V1,V2,VF,VL;
1835 TopExp::Vertices (E,V1,V2);
1838 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1839 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1840 aC = BRep_Tool::Curve(E,f,l);
1841 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1842 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1843 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1845 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
1846 ( Abs(f-l) >= M_PI) ) {
1850 //-------------------------
1852 //-------------------------
1853 Cuter.Perform(CT2d);
1855 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1856 if (ForceCut == 0) {
1857 if (Cuter.UnModified()) {
1858 //-----------------------------
1859 // edge not modified => return.
1860 //-----------------------------
1863 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1864 theCurves.Append(Cuter.Value(k));
1866 } else if (ForceCut == 1) {
1867 if (Cuter.UnModified()) {
1868 CutCurve (CT2d, 2, theCurves);
1870 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1872 theCurves.Append(Cuter.Value(k));
1874 } else if (ForceCut == 2) {
1875 if (Cuter.UnModified()) {
1876 CutCurve (CT2d, 3, theCurves);
1878 if (Cuter.NbCurves() == 2) {
1880 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1882 if (CC->LastParameter() > (l+f)/2.) {
1883 CutCurve (CC, 2, theCurves);
1884 theCurves.Append(Cuter.Value(2));
1886 theCurves.Append(CC);
1887 CutCurve (Cuter.Value(2), 2, theCurves);
1890 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1891 theCurves.Append(Cuter.Value(k));
1896 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1898 //--------------------------------------
1899 // Creation of cut edges.
1900 //--------------------------------------
1903 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1905 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1907 if (k == theCurves.Length()) {VL = V2;}
1909 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1910 gp_Pnt P = aC->Value(CC->LastParameter());
1912 VL = BRepLib_MakeVertex(P);
1913 B.UpdateVertex(VL, aTol);
1914 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1916 TopoDS_Shape aLocalShape = E.EmptyCopied();
1917 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1918 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1919 NE.Orientation(TopAbs_FORWARD);
1920 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1921 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1922 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1923 Cuts.Append(NE.Oriented(E.Orientation()));
1927 return theCurves.Length();
1930 // Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1931 //=======================================================================
1932 //function : CutCurve
1934 //=======================================================================
1936 void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1937 const Standard_Integer nbParts,
1938 TColGeom2d_SequenceOfCurve& theCurves)
1940 Handle(Geom2d_TrimmedCurve) TrimC;
1941 Standard_Real UF,UL,UC;
1944 Standard_Real PTol = Precision::PConfusion()*10;
1945 Standard_Real Tol = Precision::Confusion()*10;
1946 Standard_Boolean YaCut = Standard_False;
1948 UF = C->FirstParameter();
1949 UL = C->LastParameter ();
1953 Step = (UL - UF)/nbParts;
1955 for (Standard_Integer i = 1; i < nbParts; i++) {
1960 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1961 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1964 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1965 theCurves.Append(TrimC);
1968 YaCut = Standard_True;
1972 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1973 theCurves.Append(TrimC);
1975 theCurves.Append(C);
1977 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1979 //=======================================================================
1980 //function : MakeCircle
1982 //=======================================================================
1984 void MakeCircle (const TopoDS_Edge& E,
1985 const TopoDS_Vertex& V,
1986 const TopoDS_Face& F,
1987 const Standard_Real Offset,
1988 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
1989 const Handle(Geom_Plane)& RefPlane)
1991 // evaluate the Axis of the Circle.
1993 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1997 if (E.Orientation() == TopAbs_FORWARD) {
2001 else GC->D1(f,P,DX);
2003 gp_Ax2d Axis(P,gp_Dir2d(DX));
2004 Handle(Geom2d_Circle) Circ
2005 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
2007 // Bind the edges in my Map.
2008 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
2009 TopTools_ListOfShape LL;
2016 if ( AffichGeom && !OE.IsNull()) {
2018 sprintf(name,"OFFSET_%d",++NbOFFSET);
2019 DBRep::Set(name,OE);
2025 //=======================================================================
2026 //function : MakeOffset
2028 //=======================================================================
2030 void MakeOffset (const TopoDS_Edge& E,
2031 const TopoDS_Face& F,
2032 const Standard_Real Offset,
2033 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
2034 const Handle(Geom_Plane)& RefPlane,
2035 const Standard_Boolean IsOpenResult,
2036 const GeomAbs_JoinType theJoinType,
2037 const TopoDS_Vertex * Ends)
2040 Standard_Real anOffset = Offset;
2042 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
2044 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2045 Handle(Geom2d_Curve) G2dOC;
2047 Standard_Boolean ToExtendFirstPar = Standard_True;
2048 Standard_Boolean ToExtendLastPar = Standard_True;
2051 TopoDS_Vertex V1, V2;
2052 TopExp::Vertices(E, V1, V2);
2053 if (V1.IsSame(Ends[0]) ||
2055 ToExtendFirstPar = Standard_False;
2056 if (V2.IsSame(Ends[0]) ||
2058 ToExtendLastPar = Standard_False;
2061 Geom2dAdaptor_Curve AC(G2d,f,l);
2062 if ( AC.GetType() == GeomAbs_Circle) {
2063 // if the offset is greater otr equal to the radius and the side of the
2064 // concavity of the circle => edge null.
2065 gp_Circ2d C1(AC.Circle());
2066 gp_Ax22d axes( C1.Axis());
2067 gp_Dir2d Xd = axes.XDirection();
2068 gp_Dir2d Yd = axes.YDirection();
2069 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
2070 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
2072 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
2074 Handle(Geom2dAdaptor_HCurve) AHC =
2075 new Geom2dAdaptor_HCurve(G2d);
2076 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
2077 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
2079 Standard_Real Delta = 2*M_PI - l + f;
2080 if (theJoinType == GeomAbs_Arc)
2082 if (ToExtendFirstPar)
2084 if (ToExtendLastPar)
2087 else //GeomAbs_Intersection
2089 if (ToExtendFirstPar && ToExtendLastPar)
2091 Standard_Real old_l = l;
2092 f = old_l + Delta/2.;
2095 else if (ToExtendFirstPar)
2100 else if (ToExtendLastPar)
2105 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2108 else if (AC.GetType() == GeomAbs_Line) {
2109 Handle(Geom2dAdaptor_HCurve) AHC =
2110 new Geom2dAdaptor_HCurve(G2d);
2111 Adaptor3d_OffsetCurve Off(AHC,anOffset);
2112 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2113 Standard_Real Delta = (l - f);
2114 if (ToExtendFirstPar)
2116 if (theJoinType == GeomAbs_Arc)
2118 else //GeomAbs_Intersection
2119 f = -Precision::Infinite();
2121 if (ToExtendLastPar)
2123 if (theJoinType == GeomAbs_Arc)
2125 else //GeomAbs_Intersection
2126 l = Precision::Infinite();
2128 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2132 anOffset = -anOffset;
2133 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2134 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2138 // Bind the edges in my Map.
2139 if (!G2dOC.IsNull()) {
2140 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2141 OE.Orientation(E.Orientation());
2142 TopTools_ListOfShape LL;
2148 if (AffichGeom && !OE.IsNull()) {
2150 sprintf(name,"OFFSET_%d",++NbOFFSET);
2151 DBRep::Set(name,OE);
2152 //Standard_Real ii = 0;
2161 //=======================================================================
2162 //function : VertexFromNode
2164 //=======================================================================
2166 Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2167 const Standard_Real Offset,
2169 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2172 Standard_Boolean Status;
2173 Standard_Real Tol = Precision::Confusion();
2176 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2177 //------------------------------------------------
2178 // the Node gives a vertex on the offset
2179 //------------------------------------------------
2180 if (MapNodeVertex.IsBound(aNode)) {
2181 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2184 gp_Pnt P(PN.X(),PN.Y(),0.);
2186 B.UpdateVertex(VN,P, Precision::Confusion());
2187 MapNodeVertex.Bind(aNode,VN);
2189 Status = Standard_True;
2191 else Status = Standard_False;
2197 //=======================================================================
2198 //function : StoreInMap
2200 //=======================================================================
2202 void StoreInMap (const TopoDS_Shape& V1,
2203 const TopoDS_Shape& V2,
2204 TopTools_IndexedDataMapOfShapeShape& MapVV)
2206 TopoDS_Shape OldV = V1, NewV = V2;
2209 if (MapVV.Contains(V2))
2210 NewV = MapVV.FindFromKey(V2);
2212 if (MapVV.Contains(V1))
2213 MapVV.ChangeFromKey(V1) = NewV;
2215 for (i = 1; i <= MapVV.Extent(); i++)
2216 if (MapVV(i).IsSame(V1))
2219 MapVV.Add(V1, NewV);
2222 //=======================================================================
2223 //function : TrimEdge
2225 //=======================================================================
2227 void TrimEdge (const TopoDS_Edge& E,
2228 const TopoDS_Shape& ProE,
2229 const TopoDS_Face& AllSpine,
2230 const TopTools_ListOfShape& Detromp,
2231 TopTools_SequenceOfShape& TheVer,
2232 TColStd_SequenceOfReal& ThePar,
2233 TopTools_SequenceOfShape& S,
2234 TopTools_IndexedDataMapOfShapeShape& MapVV,
2235 const Standard_Integer IndOfE)
2237 Standard_Boolean Change = Standard_True;
2238 BRep_Builder TheBuilder;
2241 //-----------------------------------------------------------
2242 // Parse two sequences depending on the parameter on the edge.
2243 //-----------------------------------------------------------
2245 Change = Standard_False;
2246 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2247 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2248 ThePar.Exchange(i,i+1);
2249 TheVer.Exchange(i,i+1);
2250 Change = Standard_True;
2255 //----------------------------------------------------------
2256 // If a vertex is not in the proofing, it is eliminated.
2257 //----------------------------------------------------------
2258 if (!BRep_Tool::Degenerated(E)) {
2259 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2260 if ( DoubleOrNotInside (Detromp,
2261 TopoDS::Vertex(TheVer.Value(k)))) {
2269 //----------------------------------------------------------
2270 // If a vertex_double appears twice in the proofing
2271 // the vertex is removed.
2272 // otherwise preserve only one of its representations.
2273 //----------------------------------------------------------
2274 if (!BRep_Tool::Degenerated(E)) {
2275 Standard_Real aParTol = 2.0 * Precision::PConfusion();
2276 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2277 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2278 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= aParTol) {
2280 if(k+1 == TheVer.Length()) {
2281 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2286 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2291 if ( DoubleOrNotInside (Detromp,
2292 TopoDS::Vertex(TheVer.Value(k)))) {
2302 //-----------------------------------------------------------
2303 // Creation of edges.
2304 // the number of vertices should be even. The created edges
2305 // go from a vertex with uneven index i to vertex i+1;
2306 //-----------------------------------------------------------
2307 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2309 TopoDS_Shape aLocalShape = E.EmptyCopied();
2310 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2311 TopoDS_Vertex V1, V2;
2312 TopExp::Vertices(E, V1, V2);
2313 Standard_Real fpar, lpar;
2314 Handle(Geom_Surface) aPlane;
2315 TopLoc_Location aLoc;
2316 Handle(Geom2d_Curve) PCurve;
2317 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2318 //BRep_Tool::Range(E, fpar, lpar);
2320 Standard_Real TrPar1, TrPar2;
2321 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2323 if (IndOfE == 1) //first edge of open wire
2325 if (NewEdge.Orientation() == TopAbs_FORWARD)
2330 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2331 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2332 V1 = BRepLib_MakeVertex(TrPnt);
2334 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2335 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2336 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2343 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2344 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2345 V2 = BRepLib_MakeVertex(TrPnt);
2347 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2348 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2349 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2352 else //last edge of open wire
2354 if (NewEdge.Orientation() == TopAbs_FORWARD)
2359 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2360 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2361 V2 = BRepLib_MakeVertex(TrPnt);
2363 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2364 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2365 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2372 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2373 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2374 V1 = BRepLib_MakeVertex(TrPnt);
2376 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2377 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2378 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2385 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2386 TopoDS_Shape aLocalShape = E.EmptyCopied();
2387 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2388 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2390 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2391 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2392 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2395 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2396 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2400 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2406 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2407 DBRep::Set(name,NewEdge);
2412 Handle(Geom_Surface) Surf;
2413 Handle(Geom2d_Curve) C;
2414 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2416 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2417 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2418 Handle(DrawTrSurf_Curve2d) dr =
2419 new DrawTrSurf_Curve2d(C2d,Standard_False);
2420 dr->SetColor(Draw_bleu);
2430 //=======================================================================
2431 //function : IsInnerEdge
2433 //=======================================================================
2435 static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2436 const TopoDS_Face& AllSpine,
2437 Standard_Real& TrPar1,
2438 Standard_Real& TrPar2)
2440 if (ProE.ShapeType() != TopAbs_EDGE)
2441 return Standard_False;
2443 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2445 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2446 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2447 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2449 const TopTools_ListOfShape& LE = VEmap(i);
2450 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2451 return Standard_False;
2454 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2455 return Standard_True;
2460 //=======================================================================
2461 //function : DoubleOrNotInside
2462 //purpose : return True if V appears twice in LV or is not inside.
2463 //=======================================================================
2465 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2466 const TopoDS_Vertex& V)
2468 Standard_Boolean Vu = Standard_False;
2469 TopTools_ListIteratorOfListOfShape it(LV);
2471 for ( ; it.More(); it.Next()) {
2472 if (V.IsSame(it.Value())) {
2473 if (Vu) return Standard_True;
2474 else Vu = Standard_True;
2477 if (Vu) return Standard_False;
2478 else return Standard_True;
2481 Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2482 const TopoDS_Vertex& aVertex)
2484 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2485 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2486 PV2d.SetCoord( PV.X(), PV.Y() );
2488 Handle(Geom2d_Curve) PCurve;
2489 Handle( BRep_CurveRepresentation ) CurveRep =
2490 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2491 PCurve = CurveRep->PCurve();
2493 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2494 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2495 Pfirst = PCurve->Value(fpar);
2496 Plast = PCurve->Value(lpar);
2497 Pmid = PCurve->Value((fpar + lpar)*0.5);
2499 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2502 Standard_Real dist1 = Pfirst.Distance(PV2d);
2503 Standard_Real dist2 = Plast.Distance(PV2d);
2504 Standard_Real dist3 = Pmid.Distance(PV2d);
2506 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2507 return Standard_True;
2509 return Standard_False;
2512 static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2513 const BRepMAT2d_BisectingLocus& Locus,
2514 const BRepMAT2d_LinkTopoBilo& Link,
2515 TopTools_ListOfShape& BadEdges)
2518 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2519 Standard_Real eps = Precision::Confusion();
2520 Standard_Real LimCurv = 1./Offset;
2522 TopTools_MapOfShape aMap;
2524 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2525 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2526 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2527 if (SE.ShapeType() == TopAbs_EDGE) {
2530 if (aMap.Contains(SE)) {
2531 //cout << "Edge is treated second time" << endl;
2536 TopoDS_Edge E = TopoDS::Edge(SE);
2542 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2545 Geom2dAdaptor_Curve AC(G2d,f,l);
2546 GeomAbs_CurveType aCType = AC.GetType();
2549 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2552 Standard_Boolean reverse = Standard_False;
2553 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2560 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2563 aCLProps.SetParameter(f);
2564 if(!aCLProps.IsTangentDefined()) {
2565 BadEdges.Append(SE);
2571 P = aCLProps.Value();
2572 Standard_Real Crv = aCLProps.Curvature();
2576 aCLProps.Tangent(N);
2577 Standard_Real x = N.Y(), y = -N.X();
2579 if (reverse) N.Reverse();
2580 aCLProps.CentreOfCurvature(Pc);
2581 gp_Vec2d Dir( P, Pc );
2582 if (N.Dot(Dir) > 0.) {
2583 if (LimCurv <= Crv + eps) {
2584 BadEdges.Append(SE);
2592 aCLProps.SetParameter(l);
2593 if(!aCLProps.IsTangentDefined()) {
2594 BadEdges.Append(SE);
2600 P = aCLProps.Value();
2601 Crv = aCLProps.Curvature();
2605 aCLProps.Tangent(N);
2606 Standard_Real x = N.Y(), y = -N.X();
2608 if (reverse) N.Reverse();
2609 aCLProps.CentreOfCurvature(Pc);
2610 gp_Vec2d Dir( P, Pc );
2611 if (N.Dot(Dir) > 0.) {
2612 if (LimCurv <= Crv + eps) {
2613 BadEdges.Append(SE);
2626 //=======================================================================
2627 //function : PerformCurve
2629 //=======================================================================
2631 static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2633 TColgp_SequenceOfPnt& Points,
2634 const Adaptor3d_Curve& C,
2635 const Standard_Real Deflection,
2636 const Standard_Real U1,
2637 const Standard_Real U2,
2638 const Standard_Real EPSILON,
2639 const Standard_Integer Nbmin)
2641 Standard_Real UU1 = Min(U1, U2);
2642 Standard_Real UU2 = Max(U1, U2);
2646 C.D1(UU1,Pdeb,Ddeb);
2647 Parameters.Append(UU1);
2648 Points.Append(Pdeb);
2650 C.D1(UU2,Pfin,Dfin);
2652 const Standard_Real aDelta = UU2 - UU1;
2653 const Standard_Real aDist = Pdeb.Distance(Pfin);
2655 if((aDelta/aDist) > 5.0e-14)
2657 QuasiFleche(C,Deflection*Deflection,
2668 return Standard_True;
2670 //=======================================================================
2671 //function : QuasiFleche
2673 //=======================================================================
2675 static void QuasiFleche(const Adaptor3d_Curve& C,
2677 const Standard_Real Deflection2,
2678 const Standard_Real Udeb,
2681 const Standard_Real Ufin,
2684 const Standard_Integer Nbmin,
2685 const Standard_Real Eps,
2686 TColStd_SequenceOfReal& Parameters,
2687 TColgp_SequenceOfPnt& Points)
2689 Standard_Integer Ptslength = Points.Length();
2690 Standard_Real Udelta = Ufin-Udeb;
2695 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2703 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2704 Standard_Real theFleche=0;
2705 Standard_Boolean flecheok = Standard_False;
2707 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
2708 Standard_Real N1 = Vdeb.SquareMagnitude();
2709 Standard_Real N2 = Vdelta.SquareMagnitude();
2710 if (N1 > Eps && N2 > Eps) {
2711 Standard_Real Normediff =
2713 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2714 if (Normediff > Eps) {
2716 theFleche = Normediff*Norme/64.;
2717 flecheok = Standard_True;
2722 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2723 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2724 theFleche = Pmid.SquareDistance(Pverif);
2727 if (theFleche < Deflection2) {
2728 Parameters.Append(Udeb+Udelta);
2729 Points.Append(Pdelta);
2732 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2744 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2749 Nbmin-(Points.Length()-Ptslength),