0025772: Boolean operation produces invalid result after patch for 0025416
[occt.git] / src / BRepFill / BRepFill_OffsetWire.cxx
CommitLineData
b311480e 1// Created on: 1995-04-20
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145
18
19#include <stdio.h>
20
21#include <BRepFill_OffsetWire.ixx>
22
23#include <BRepAdaptor_Curve.hxx>
24#include <BRepAdaptor_Surface.hxx>
25
26#include <BRepFill_DataMapOfNodeShape.hxx>
27#include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
28#include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
29#include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx>
7fd59977 30#include <BRepFill_TrimEdgeTool.hxx>
31#include <BRepLib.hxx>
32#include <BRepLib_MakeVertex.hxx>
33#include <BRepLib_MakeFace.hxx>
34#include <BRepLib_MakeWire.hxx>
35#include <BRepLib_MakeEdge.hxx>
36#include <BRepTools.hxx>
37#include <BRep_Builder.hxx>
38#include <BRep_Tool.hxx>
39#include <BRep_TEdge.hxx>
40#include <BRep_CurveRepresentation.hxx>
41#include <BRep_GCurve.hxx>
42#include <BRepTools_WireExplorer.hxx>
43#include <BRepMAT2d_Explorer.hxx>
44#include <Geom2dAdaptor_Curve.hxx>
45#include <Geom2dAdaptor_HCurve.hxx>
46#include <Adaptor3d_OffsetCurve.hxx>
47#include <Adaptor3d_Curve.hxx>
48#include <Geom_Surface.hxx>
49#include <Geom_Plane.hxx>
50#include <Geom2d_Curve.hxx>
51#include <Geom2d_Circle.hxx>
52#include <Geom2d_Line.hxx>
53#include <Geom2d_TrimmedCurve.hxx>
54#include <Geom2d_OffsetCurve.hxx>
55#include <GeomAPI.hxx>
56#include <Geom_TrimmedCurve.hxx>
57#include <Geom_Circle.hxx>
6a442250 58#include <Geom_Line.hxx>
7fd59977 59#include <Geom_OffsetCurve.hxx>
60#include <MAT_Arc.hxx>
61#include <MAT_Node.hxx>
62#include <MAT_Graph.hxx>
63#include <MAT2d_CutCurve.hxx>
64#include <Precision.hxx>
65#include <Standard_NotImplemented.hxx>
66#include <TColgp_SequenceOfPnt.hxx>
67#include <TColStd_SequenceOfReal.hxx>
68#include <TopAbs.hxx>
69#include <TopExp.hxx>
70#include <TopExp_Explorer.hxx>
71#include <TopoDS.hxx>
72#include <TopoDS_Wire.hxx>
73#include <TopoDS_Compound.hxx>
74#include <TopoDS_Iterator.hxx>
75#include <TopTools_MapOfShape.hxx>
76#include <TopTools_MapIteratorOfMapOfShape.hxx>
77#include <TopTools_ListIteratorOfListOfShape.hxx>
78#include <TopTools_DataMapOfShapeListOfShape.hxx>
79#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
80#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
81#include <TopTools_SequenceOfShape.hxx>
82#include <TopTools_ListOfShape.hxx>
83#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
84#include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
85
86#include <gp.hxx>
87#include <gp_Vec.hxx>
88#include <gp_Ax2.hxx>
89#include <gp_Pln.hxx>
90#include <gp_Dir2d.hxx>
91
92#include <BRep_TVertex.hxx>
93#include <TopTools_IndexedMapOfShape.hxx>
94#include <Geom2d_BSplineCurve.hxx>
95#include <TColgp_Array1OfPnt2d.hxx>
96#include <TColStd_Array1OfReal.hxx>
97#include <TColStd_Array1OfInteger.hxx>
98#include <BRepTools_Substitution.hxx>
99#include <BRepLib_MakeVertex.hxx>
100#include <Geom2dLProp_CLProps2d.hxx>
101#include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
102#include <Standard_ErrorHandler.hxx>
103
104#ifdef DRAW
105#include <Draw.hxx>
106#include <DrawTrSurf.hxx>
107#include <DrawTrSurf_Curve2d.hxx>
108#include <DBRep.hxx>
7fd59977 109static Standard_Boolean AffichGeom = Standard_False;
110static Standard_Boolean Affich2d = Standard_False;
111static Standard_Boolean AffichEdge = Standard_False;
112static Standard_Integer NbTRIMEDGES = 0;
113static Standard_Integer NbOFFSET = 0;
114static Standard_Integer NbEDGES = 0;
115static Standard_Integer NbBISSEC = 0;
7fd59977 116#endif
117
118// Modified by Sergey KHROMOV - Thu Nov 16 17:24:39 2000 Begin
119
120static void QuasiFleche(const Adaptor3d_Curve& C,
121 const Standard_Real Deflection2,
122 const Standard_Real Udeb,
123 const gp_Pnt& Pdeb,
124 const gp_Vec& Vdeb,
125 const Standard_Real Ufin,
126 const gp_Pnt& Pfin,
127 const gp_Vec& Vfin,
128 const Standard_Integer Nbmin,
129 const Standard_Real Eps,
130 TColStd_SequenceOfReal& Parameters,
131 TColgp_SequenceOfPnt& Points);
132
133static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
134 TColgp_SequenceOfPnt& Points,
135 const Adaptor3d_Curve& C,
136 const Standard_Real Deflection,
137 const Standard_Real U1,
138 const Standard_Real U2,
139 const Standard_Real EPSILON,
140 const Standard_Integer Nbmin);
141
142static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
143 const BRepMAT2d_BisectingLocus& Locus,
144 const BRepMAT2d_LinkTopoBilo& Link,
145 TopTools_ListOfShape& BadEdges);
146
147static Standard_Integer CutEdge (const TopoDS_Edge& E,
148 const TopoDS_Face& F,
149 Standard_Integer ForceCut,
150 TopTools_ListOfShape& Cuts);
151
152
153static void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
154 const Standard_Integer nbParts,
155 TColGeom2d_SequenceOfCurve& theCurves);
156// Modified by Sergey KHROMOV - Thu Nov 16 17:24:47 2000 End
157
158
159static void EdgeVertices (const TopoDS_Edge& E,
160 TopoDS_Vertex& V1,
161 TopoDS_Vertex& V2)
162{
163 if (E.Orientation() == TopAbs_REVERSED) {
164 TopExp::Vertices(E,V2,V1);
165 }
166 else {
167 TopExp::Vertices(E,V1,V2);
168 }
169}
170
7fd59977 171static Standard_Boolean VertexFromNode
172(const Handle(MAT_Node)& aNode,
173 const Standard_Real Offset,
174 gp_Pnt2d& PN,
175 BRepFill_DataMapOfNodeShape& MapNodeVertex,
176 TopoDS_Vertex& VN);
177
178static void StoreInMap (const TopoDS_Shape& V1,
179 const TopoDS_Shape& V2,
180 TopTools_IndexedDataMapOfShapeShape& MapVV);
181
182static void TrimEdge (const TopoDS_Edge& CurrentEdge,
e11c1bc4 183 const TopoDS_Shape& CurrentSpine,
184 const TopoDS_Face& AllSpine,
7fd59977 185 const TopTools_ListOfShape& D,
6a442250 186 TopTools_SequenceOfShape& Sv,
187 TColStd_SequenceOfReal& MapverPar,
188 TopTools_SequenceOfShape& S,
189 TopTools_IndexedDataMapOfShapeShape& MapVV,
190 const Standard_Integer IndOfE);
7fd59977 191
e11c1bc4 192static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
193 const TopoDS_Face& AllSpine,
194 Standard_Real& TrPar1,
195 Standard_Real& TrPar2);
196
7fd59977 197static Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& EC,
198 const TopoDS_Vertex& V);
199
200static Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
201 const TopoDS_Vertex& aVertex);
202
203static void MakeCircle
204(const TopoDS_Edge& E,
205 const TopoDS_Vertex& V,
206 const TopoDS_Face& F,
207 const Standard_Real Offset,
86b3805f 208 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
7fd59977 209 const Handle(Geom_Plane)& RefPlane);
210
211static void MakeOffset
212(const TopoDS_Edge& E,
213 const TopoDS_Face& F,
214 const Standard_Real Offset,
86b3805f 215 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
6a442250 216 const Handle(Geom_Plane)& RefPlane,
217 const Standard_Boolean IsOpenResult,
c7806cb6 218 const GeomAbs_JoinType theJoinType,
6a442250 219 const TopoDS_Vertex * Ends);
7fd59977 220
221//=======================================================================
222//function : KPartCircle
223//purpose :
224//=======================================================================
225
226static Standard_Boolean KPartCircle
227(const TopoDS_Face& mySpine,
228 const Standard_Real myOffset,
e11c1bc4 229 const Standard_Boolean IsOpenResult,
7fd59977 230 const Standard_Real Alt,
231 TopoDS_Shape& myShape,
86b3805f 232 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
7fd59977 233 Standard_Boolean& myIsDone)
234{
0d969553 235 // The only contour which is a closed circle
7fd59977 236 TopExp_Explorer exp(mySpine,TopAbs_EDGE);
237 Standard_Integer NbEdges = 0;
238 TopoDS_Edge E;
239
240 for (; exp.More(); exp.Next()) {
241 NbEdges++;
242 E = TopoDS::Edge(exp.Current());
243 if (NbEdges > 1) return Standard_False;
244 }
7fd59977 245
246 Standard_Real f,l;
247 TopLoc_Location L;
248 Handle(Geom_Curve) C = BRep_Tool::Curve(E,L,f,l);
249
250 if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
251 Handle(Geom_TrimmedCurve) Ct = Handle(Geom_TrimmedCurve)::DownCast(C);
252 C = Ct->BasisCurve();
253 }
254
da72a17c 255 if ((C->IsKind(STANDARD_TYPE(Geom_Circle)) && BRep_Tool::IsClosed(E)) || //closed circle
e11c1bc4 256 IsOpenResult)
6a442250 257 {
6a442250 258 Standard_Real anOffset = myOffset;
6a442250 259
0e0f7a7c 260 Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(E, mySpine, f, l);
6a442250 261 Handle(Geom2dAdaptor_HCurve) AHC = new Geom2dAdaptor_HCurve(aPCurve, f, l);
0e0f7a7c 262 Handle(Geom2d_Curve) OC;
263 if (AHC->GetType() == GeomAbs_Line)
264 {
c7806cb6 265 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
0e0f7a7c 266 Adaptor3d_OffsetCurve Off(AHC,anOffset);
267 OC = new Geom2d_Line(Off.Line());
268 }
269 else if (AHC->GetType() == GeomAbs_Circle)
270 {
c7806cb6 271 if (E.Orientation() == TopAbs_FORWARD) anOffset *= -1;
0e0f7a7c 272 gp_Circ2d theCirc = AHC->Circle();
c7806cb6 273 if (anOffset > 0. || Abs(anOffset) < theCirc.Radius())
274 OC = new Geom2d_Circle (theCirc.Position(), theCirc.Radius() + anOffset);
275 else
276 {
277 myIsDone = Standard_False;
278 return Standard_False;
279 }
0e0f7a7c 280 }
281 else
282 {
c7806cb6 283 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
0e0f7a7c 284 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(aPCurve, f, l);
285 OC = new Geom2d_OffsetCurve( G2dT, anOffset);
286 }
287 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(mySpine);
6a442250 288 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
0e0f7a7c 289 myShape = BRepLib_MakeEdge(OC, aPlane, f, l);
6a442250 290 BRepLib::BuildCurve3d(TopoDS::Edge(myShape));
291
292 myShape.Orientation(E.Orientation());
293 myShape.Location(L);
294 if (Alt != 0.) {
295 BRepAdaptor_Surface S(mySpine,0);
296 gp_Ax1 Nor = S.Plane().Axis();
297 gp_Trsf T;
298 gp_Vec Trans(Nor.Direction());
299 Trans = Alt*Trans;
300 T.SetTranslation(Trans);
301 myShape.Move(TopLoc_Location(T));
302 }
303
304 TopTools_ListOfShape LL;
305 LL.Append(myShape);
306 myMap.Add(E,LL);
307
308 TopoDS_Edge myEdge = TopoDS::Edge(myShape);
309 myShape = BRepLib_MakeWire(myEdge);
310
311 myIsDone = Standard_True;
312 return Standard_True;
313 }
7fd59977 314
0e0f7a7c 315 return Standard_False;
7fd59977 316}
317
318//=======================================================================
319//function : BRepFill_OffsetWire
320//purpose :
321//=======================================================================
322
323BRepFill_OffsetWire::BRepFill_OffsetWire()
6a442250 324 : myIsOpenResult(Standard_False),
325 myIsDone(Standard_False)
7fd59977 326{
327}
328
329
330//=======================================================================
331//function : BRepFill_OffsetWire
332//purpose :
333//=======================================================================
334
335BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face& Spine,
6a442250 336 const GeomAbs_JoinType Join,
337 const Standard_Boolean IsOpenResult)
7fd59977 338{
6a442250 339 Init(Spine,Join,IsOpenResult);
7fd59977 340}
341
7fd59977 342//=======================================================================
343//function : Init
344//purpose :
345//=======================================================================
346
347void BRepFill_OffsetWire::Init(const TopoDS_Face& Spine,
6a442250 348 const GeomAbs_JoinType Join,
349 const Standard_Boolean IsOpenResult)
7fd59977 350{
7fd59977 351 myIsDone = Standard_False;
352 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
353 mySpine = TopoDS::Face(aLocalShape);
354// mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
355 myJoinType = Join;
6a442250 356 myIsOpenResult = IsOpenResult;
7fd59977 357 myMap.Clear();
358 myMapSpine.Clear();
359 //------------------------------------------------------------------
0d969553 360 // cut the spine for bissectors.
7fd59977 361 //------------------------------------------------------------------
362// Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
363 static BRepMAT2d_Explorer Exp;
364
365 Exp.Perform(mySpine);
366
367// TopoDS_Face anOldSpine = mySpine;
368
369 mySpine = TopoDS::Face(Exp.ModifiedShape(mySpine));
370 PrepareSpine ();
371
372// Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
373 TopoDS_Shape aShape;
86b3805f 374 BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
7fd59977 375 Standard_Boolean Done;
e11c1bc4 376 if (KPartCircle(myWorkSpine,1.,myIsOpenResult,0.,aShape,aMap,Done)) return;
7fd59977 377
378
379 //-----------------------------------------------------
0d969553
Y
380 // Calculate the map of bissectors to the left.
381 // and Links Topology -> base elements of the map.
7fd59977 382 //-----------------------------------------------------
383
384// Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
385// static BRepMAT2d_Explorer Exp;
386// Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
387 Exp.Perform(myWorkSpine);
c19dd45e 388 myBilo.Compute(Exp, 1 ,MAT_Left, myJoinType, myIsOpenResult);
389 myLink.Perform(Exp, myBilo);
7fd59977 390}
391
392
393//=======================================================================
394//function : IsDone
395//purpose :
396//=======================================================================
397
398Standard_Boolean BRepFill_OffsetWire::IsDone() const
399{
400 return myIsDone;
401}
402
403
404//=======================================================================
405//function : Spine
406//purpose :
407//=======================================================================
408
409const TopoDS_Face& BRepFill_OffsetWire::Spine() const
410{
411 return mySpine;
412}
413
414
415//=======================================================================
416//function : Shape
417//purpose :
418//=======================================================================
419
420const TopoDS_Shape& BRepFill_OffsetWire::Shape() const
421{
422 return myShape;
423}
424
425
426//=======================================================================
427//function : GeneratedShapes
428//purpose :
429//=======================================================================
430
431const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
432(const TopoDS_Shape& SpineShape)
433{
434 if (!myCallGen) {
435 if (!myMapSpine.IsEmpty()) {
0d969553 436 // myMapSpine can be empty if passed by PerformWithBilo.
7fd59977 437 TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
438 for (; it.More(); it.Next()) {
86b3805f
J
439 if (myMap.Contains(it.Key())) {
440 if (!myMap.Contains(it.Value())) {
7fd59977 441 TopTools_ListOfShape L;
86b3805f 442 myMap.Add(it.Value(),L);
7fd59977 443 }
444 if ( !it.Value().IsSame(it.Key())) {
86b3805f
J
445 myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
446 //myMap.UnBind(it.Key());
447 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
448 TopTools_ListOfShape LastList;
449 LastList.Append(myMap(myMap.Extent()));
450 myMap.RemoveLast();
451 if (myMap.FindIndex(it.Key()) != 0)
452 myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
7fd59977 453 }
454 }
86b3805f
J
455 if (myMap.Contains(it.Key().Reversed())) {
456 if (!myMap.Contains(it.Value().Reversed())) {
7fd59977 457 TopTools_ListOfShape L;
86b3805f 458 myMap.Add(it.Value().Reversed(),L);
7fd59977 459 }
460 if ( !it.Value().IsSame(it.Key())) {
86b3805f
J
461 myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
462 //myMap.UnBind(it.Key().Reversed());
463 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
464 TopTools_ListOfShape LastList;
465 LastList.Append(myMap(myMap.Extent()));
466 myMap.RemoveLast();
467 if (myMap.FindIndex(it.Key().Reversed()) != 0)
468 myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
7fd59977 469 }
470 }
471 }
472 }
473 myCallGen = Standard_True;
474 }
475
86b3805f
J
476 if (myMap.Contains(SpineShape)) {
477 return myMap.FindFromKey(SpineShape);
7fd59977 478 }
479 else {
480 static TopTools_ListOfShape Empty;
481 return Empty;
482 }
483}
484
485
486//=======================================================================
487//function : JoinType
488//purpose :
489//=======================================================================
490
491GeomAbs_JoinType BRepFill_OffsetWire::JoinType() const
492{
493 return myJoinType;
494}
495
496//=======================================================================
497//function : Perform
498//purpose :
499//=======================================================================
500
501void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
502 const Standard_Real Alt)
503{
91bb31f3 504 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 Begin
505 try
506 {
7fd59977 507 OCC_CATCH_SIGNALS
91bb31f3 508 myCallGen = Standard_False;
e11c1bc4 509 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone)) return;
7fd59977 510
511 TopoDS_Face oldWorkSpain = myWorkSpine;
512
513 TopTools_ListOfShape BadEdges;
514 CheckBadEdges(myWorkSpine,Offset,myBilo,myLink,BadEdges);
515
91bb31f3 516 if(!BadEdges.IsEmpty())
517 {
7fd59977 518 // Modification of myWorkSpine;
519 //cout << "Modification of myWorkSpine : " << BadEdges.Extent() << endl;
520 BRepTools_Substitution aSubst;
521 TopTools_ListIteratorOfListOfShape it(BadEdges);
522 TopTools_ListOfShape aL;
523 Standard_Real aDefl = .01 * Abs(Offset);
524 TColStd_SequenceOfReal Parameters;
525 TColgp_SequenceOfPnt Points;
526
527 for(; it.More(); it.Next()) {
91bb31f3 528 aL.Clear();
529 Parameters.Clear();
530 Points.Clear();
531 const TopoDS_Shape& anE = it.Value();
532
533 TopoDS_Vertex Vf, Vl;
534 TopExp::Vertices(TopoDS::Edge(anE), Vf, Vl);
535
536 Standard_Real f, l;
537 Handle(Geom_Curve) G3d = BRep_Tool::Curve(TopoDS::Edge(anE),f,l);
538 GeomAdaptor_Curve AC(G3d,f,l);
539
540 PerformCurve(Parameters, Points, AC, aDefl, f,
541 l, Precision::Confusion(), 2);
542
543 Standard_Integer NPnts = Points.Length();
544 if(NPnts > 2)
545 {
546 //cout << NPnts << " points " << endl;
547 TopoDS_Vertex FV = Vf;
548 TopoDS_Vertex LV;
549 TopoDS_Edge newE;
550 Standard_Integer np;
551 for(np = 2; np < NPnts; np++) {
552 gp_Pnt LP = Points(np);
553 LV = BRepLib_MakeVertex(LP);
554 newE = BRepLib_MakeEdge(FV, LV);
555 aL.Append(newE);
556 FV = LV;
557 }
558 LV = Vl;
559 newE = BRepLib_MakeEdge(FV, LV);
560 aL.Append(newE);
561 }
562 else
563 {
564 //cout << " 2 points " << endl;
565 TopoDS_Edge newE = BRepLib_MakeEdge(Vf, Vl);
566 aL.Append(newE);
567 }
568 //Update myMapSpine
569 if (myMapSpine.IsBound( anE ))
570 {
571 TopTools_ListIteratorOfListOfShape newit( aL );
572 for (; newit.More(); newit.Next())
573 {
574 TopoDS_Edge NewEdge = TopoDS::Edge( newit.Value() );
575 myMapSpine.Bind( NewEdge, myMapSpine(anE) );
576 TopoDS_Vertex NewV1, NewV2;
577 EdgeVertices( NewEdge, NewV1, NewV2 );
578 if (!myMapSpine.IsBound(NewV1)) myMapSpine.Bind( NewV1, myMapSpine(anE) );
579 if (!myMapSpine.IsBound(NewV2)) myMapSpine.Bind( NewV2, myMapSpine(anE) );
580 }
581 myMapSpine.UnBind( anE );
582 }
583 ///////////////////
584 aSubst.Substitute(anE, aL);
7fd59977 585 }
586
587 TopTools_DataMapOfShapeListOfShape wwmap;
588 TopoDS_Iterator itws( myWorkSpine );
589 for (; itws.More(); itws.Next())
91bb31f3 590 {
591 TopoDS_Shape aWire = itws.Value();
592 aSubst.Build( aWire );
593 if (aSubst.IsCopied(aWire))
594 {
595 TopoDS_Wire NewWire = TopoDS::Wire( aSubst.Copy(aWire).First() );
596 NewWire.Closed( aWire.Closed() );
597 TopTools_ListOfShape Lw;
598 Lw.Append( NewWire );
599 wwmap.Bind( aWire, Lw );
600 }
601 }
7fd59977 602 aSubst.Clear();
603 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itmap( wwmap );
604 for (; itmap.More(); itmap.Next())
91bb31f3 605 aSubst.Substitute( itmap.Key(), itmap.Value() );
606
7fd59977 607 aSubst.Build(myWorkSpine);
91bb31f3 608
7fd59977 609 if(aSubst.IsCopied(myWorkSpine)) {
91bb31f3 610 myWorkSpine = TopoDS::Face(aSubst.Copy(myWorkSpine).First());
ab87e6fc 611
91bb31f3 612 BRepMAT2d_Explorer newExp;
613 newExp.Perform(myWorkSpine);
614 BRepMAT2d_BisectingLocus newBilo;
615 BRepMAT2d_LinkTopoBilo newLink;
c19dd45e 616 newBilo.Compute(newExp, 1, MAT_Left, myJoinType, myIsOpenResult);
ab87e6fc 617
91bb31f3 618 if(!newBilo.IsDone())
619 {
620 myShape.Nullify();
621 myIsDone = Standard_False;
622 return;
623 }
7fd59977 624
91bb31f3 625 newLink.Perform(newExp,newBilo);
626 PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
627 myWorkSpine = oldWorkSpain;
7fd59977 628 }
629 else {
91bb31f3 630 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
7fd59977 631 }
7fd59977 632 }
91bb31f3 633 else
634 {
7fd59977 635 PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
636 }
ab87e6fc 637 }
b350f6ee 638 catch (Standard_Failure)//Every exception was caught.
91bb31f3 639 {
7fd59977 640 myShape.Nullify();
641 myIsDone = Standard_False;
0797d9d3 642#ifdef OCCT_DEBUG
ab87e6fc 643 cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
644 Standard_Failure::Caught()->Print(cout);
645 cout<<endl;
63c629aa 646#endif
91bb31f3 647
7fd59977 648 return;
649 }
ab87e6fc 650
91bb31f3 651 // Modified by skv - Fri Jul 8 11:21:38 2005 OCC9145 End
652 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
6a442250 653 if (!myIsOpenResult)
654 {
655 TopExp_Explorer anExp(myShape, TopAbs_WIRE);
656
657 for (; anExp.More(); anExp.Next()) {
658 const TopoDS_Shape &aWire = anExp.Current();
659
660 if (!aWire.Closed()) {
661 myShape.Nullify();
662 myIsDone = Standard_False;
663 Standard_ConstructionError::Raise("Offset wire is not closed.");
664 }
7fd59977 665 }
666 }
91bb31f3 667 // Modified by Sergey KHROMOV - Thu Mar 14 10:48:16 2002 End
7fd59977 668}
669
670//=======================================================================
671//function : Compute
672//purpose :
673//=======================================================================
674
675void Compute (const TopoDS_Face& Spine,
676 TopoDS_Shape& aShape,
86b3805f 677 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
7fd59977 678 const Standard_Real Alt)
679{
680 BRep_Builder B;
681 B.MakeCompound(TopoDS::Compound(aShape));
682 Standard_Real ALT = Alt;
683 if ( Spine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
684 gp_Trsf T;
685 T.SetTranslation(gp_Vec(0.,0.,ALT));
686 TopLoc_Location L(T);
687
688 for ( TopExp_Explorer exp(Spine,TopAbs_WIRE); exp.More(); exp.Next()) {
689 const TopoDS_Wire& CurW = TopoDS::Wire(exp.Current());
690 TopoDS_Shape aLocalShape = CurW.Moved(L);
691 TopoDS_Wire NewW = TopoDS::Wire(aLocalShape);
692// TopoDS_Wire NewW = TopoDS::Wire(CurW.Moved(L));
693 B.Add(aShape,NewW);
0d969553 694 // update Map.
7fd59977 695 TopoDS_Iterator it1( CurW);
696 TopoDS_Iterator it2( NewW);
697 for ( ; it1.More(); it1.Next(), it2.Next()) {
698 TopTools_ListOfShape List;
699 List.Append(it2.Value());
86b3805f 700 Map.Add(it1.Value(), List);
7fd59977 701 }
702 }
703}
704
705//=======================================================================
706//function : PerformWithBiLo
707//purpose :
708//=======================================================================
709
710void BRepFill_OffsetWire::PerformWithBiLo
711(const TopoDS_Face& Spine,
712 const Standard_Real Offset,
713 const BRepMAT2d_BisectingLocus& Locus,
714 BRepMAT2d_LinkTopoBilo& Link,
715 const GeomAbs_JoinType Join,
716 const Standard_Real Alt)
717{
7fd59977 718 myIsDone = Standard_False;
719 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
720 myWorkSpine = TopoDS::Face(aLocalShape);
721// myWorkSpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
722 myJoinType = Join;
723 myOffset = Offset ;
724 myShape.Nullify();
725
726
727 if (mySpine.IsNull()) {
728 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
729 mySpine = TopoDS::Face(aLocalShape);
730// mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
731}
732 myMap.Clear();
733
7fd59977 734 if ( Abs(myOffset) < Precision::Confusion()) {
735 Compute(mySpine,myShape,myMap,Alt);
736 myIsDone = Standard_True;
737 return;
738 }
739
0d969553
Y
740 //********************************
741 // Calculate for a non null offset
742 //********************************
e11c1bc4 743 if (KPartCircle(myWorkSpine,Offset,myIsOpenResult,Alt,myShape,myMap,myIsDone))
91bb31f3 744 return;
7fd59977 745
746 BRep_Builder myBuilder;
747 myBuilder.MakeCompound(TopoDS::Compound(myShape));
748
749 //---------------------------------------------------------------------
0d969553
Y
750 // MapNodeVertex : associate to each node of the map (key1) and to
751 // each element of the profile (key2) a vertex (item).
752 // MapBis : all edges or vertices (item) generated by
753 // a bisectrice on a face or an edge (key) of revolution tubes.
754 // MapVerPar : Map of parameters of vertices on parallel edges
755 // the list contained in MapVerPar (E) corresponds to
756 // parameters on E of vertices contained in MapBis(E);
7fd59977 757 //---------------------------------------------------------------------
758
759
760 BRepFill_DataMapOfNodeShape MapNodeVertex;
761 TopTools_DataMapOfShapeSequenceOfShape MapBis;
762 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
763
764 TopTools_DataMapOfShapeShape EmptyMap;
765 TopTools_SequenceOfShape EmptySeq;
766 TopTools_ListOfShape EmptyList;
767 TColStd_SequenceOfReal EmptySeqOfReal;
768
769 Standard_Real ALT = Alt;
770 Handle(Geom_Plane) RefPlane =
771 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
772 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
773 RefPlane = Handle(Geom_Plane)::DownCast
774 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
775
776 //---------------------------------------------------------------
0d969553 777 // Construction of Circles and OffsetCurves
7fd59977 778 //---------------------------------------------------------------
6a442250 779
780 TopoDS_Vertex Ends [2];
781 if (myIsOpenResult)
782 {
783 TopoDS_Wire theWire;
784 TopoDS_Iterator iter(mySpine);
785 theWire = TopoDS::Wire(iter.Value());
786 TopExp::Vertices(theWire, Ends[0], Ends[1]);
787 }
788
7fd59977 789 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
790 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
791 TopoDS_Shape& PE = PEE ;
792 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
793 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
794 if (SE.ShapeType() == TopAbs_VERTEX) {
0e0f7a7c 795 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
796 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
797 myWorkSpine,myOffset,myMap,RefPlane);
7fd59977 798 }
799 else {
6a442250 800 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
c7806cb6 801 myIsOpenResult, myJoinType, Ends);
7fd59977 802 PE = SE;
803 }
804 }
805 }
806
807
1896126e 808#ifdef DRAW
7fd59977 809 if (AffichEdge) {
0d969553 810 cout << " End Construction of geometric primitives "<<endl;
7fd59977 811 }
812#endif
813
814
815 //---------------------------------------------------
0d969553 816 // Construction of offset vertices.
7fd59977 817 //---------------------------------------------------
818 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
819 Handle(MAT_Arc) CurrentArc;
820 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
821 Handle(Geom_Curve) CBis;
822 Standard_Boolean Reverse;
823 TopoDS_Edge CurrentEdge;
824 TopoDS_Shape S [2];
825 TopoDS_Edge E [2];
826 TopLoc_Location L;
86b3805f 827 Standard_Integer j, k;
7fd59977 828
829 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
830
831 CurrentArc = Locus.Graph()->Arc(i);
832 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
833
834#ifdef DRAW
835 if ( AffichGeom) {
1896126e 836 char name[256];
7fd59977 837 sprintf(name,"BISSEC_%d",NbBISSEC++);
838 DrawTrSurf::Set(name,Bisec.Value());
839 }
840#endif
841
0d969553
Y
842 //-------------------------------------------------------------------
843 // Return elements of the spine corresponding to separate basicElts.
844 //-------------------------------------------------------------------
7fd59977 845 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
846 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
847
848 TopTools_SequenceOfShape Vertices;
849 TColgp_SequenceOfPnt Params;
850
851 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
852 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
853
854 //-----------------------------------------------------------
0d969553
Y
855 // Return parallel edges on each face.
856 // If no offset generated => move to the next bissectrice.
7fd59977 857 //--------------------------------------------------------------
86b3805f
J
858 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
859 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
860 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
7fd59977 861 }
862 else continue;
863
864 //-----------------------------------------------------------
0d969553
Y
865 // Construction of vertices corresponding to the node of the map.
866 // if they are on the offset.
7fd59977 867 //-----------------------------------------------------------
868 TopoDS_Vertex VS,VE;
869 Handle(MAT_Node) Node1, Node2;
870
871 if (Reverse) {
872 Node1 = CurrentArc->SecondNode();
873 Node2 = CurrentArc->FirstNode();
874 }
875 else {
876 Node1 = CurrentArc->FirstNode();
877 Node2 = CurrentArc->SecondNode();
878 }
879
880 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
881
882 if (!Node1->Infinite()) {
883 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
884 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
885// StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
886// MapNodeVertex,VS);
887 }
888 if (!Node2->Infinite()) {
889 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
890 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
891// EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
892// MapNodeVertex,VE);
893 }
894
895 //---------------------------------------------
0d969553 896 // Construction of geometries.
7fd59977 897 //---------------------------------------------
898 BRepFill_TrimEdgeTool Trim (Bisec,
899 Locus.GeomElt(CurrentArc->FirstElement()),
900 Locus.GeomElt(CurrentArc->SecondElement()),
901 myOffset);
902
903 //-----------------------------------------------------------
0d969553 904 // Construction of vertices on edges parallel to the spine.
7fd59977 905 //-----------------------------------------------------------
906
907 Trim.IntersectWith(E [0], E [1], Params);
908
909 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
910 TopoDS_Vertex VC;
911 myBuilder.MakeVertex (VC);
912 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
913 gp_Pnt PVC(P2.X(),P2.Y(),0.);
914
915 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
916 Vertices.Append(VC);
917 }
918 if (StartOnEdge) {
919 Standard_Boolean Start = 1;
920 Trim.AddOrConfuse(Start, E[0], E[1], Params);
921 if (Params.Length() == Vertices.Length())
922 Vertices.SetValue(1,VS);
923
924 else
0d969553 925 // the point was not found by IntersectWith
7fd59977 926 Vertices.Prepend(VS);
927 }
928 if (EndOnEdge) {
929 Standard_Boolean Start = 0;
930 Trim.AddOrConfuse(Start, E[0], E[1], Params);
931 if (Params.Length() == Vertices.Length())
932 Vertices.SetValue(Params.Length(),VE);
933
934 else
0d969553 935 // the point was not found by IntersectWith
7fd59977 936 Vertices.Append(VE);
937 }
938
939 //------------------------------------------------------------
0d969553
Y
940 // Update Detromp.
941 // Detromp allows to remove vertices on the offset
942 // corresponding to tangency zones
943 // Detromp ranks the vertices that limit
944 // the parts of the bissectrices located between the spine and the
945 // offset.
7fd59977 946 //------------------------------------------------------------
947 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
948 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
949
950
c19dd45e 951 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
7fd59977 952 Bisec, StartOnEdge, EndOnEdge, Trim);
953 //----------------------------------------------
0d969553
Y
954 // Storage of vertices on parallel edges.
955 // fill MapBis and MapVerPar.
7fd59977 956 //----------------------------------------------
957 if (!Vertices.IsEmpty()) {
958 for (k = 0; k <= 1; k++) {
959 if (!MapBis.IsBound(E[k])) {
960 MapBis .Bind(E[k],EmptySeq);
961 MapVerPar.Bind(E[k],EmptySeqOfReal);
962 }
963 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
964 MapBis (E[k]).Append(Vertices.Value(ii));
965 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
966 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
967 }
968 }
969 }
970 else {
971 //------------------------------------------------------------
0d969553
Y
972 // FOR COMPLETE CIRCLES. the parallel line can be contained
973 // in the zone without intersection with the border
974 // no intersection
975 // if myoffset is < distance of nodes the parallel can be valid.
7fd59977 976 //-------------------------------------------------------------
977 for (k = 0; k <= 1; k++) {
978 if (!MapBis.IsBound(E[k])) {
979 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
980 MapBis .Bind(E[k],EmptySeq);
981 MapVerPar.Bind(E[k],EmptySeqOfReal);
982 }
983 }
984 }
985 }
986 }
987
1896126e 988#ifdef DRAW
7fd59977 989 if (AffichEdge) {
0d969553 990 cout << " End Construction of vertices on offsets"<<endl;
7fd59977 991 }
992#endif
993
994 //----------------------------------
0d969553 995 // Construction of parallel edges.
7fd59977 996 //----------------------------------
997 TopTools_IndexedDataMapOfShapeShape MapVV;
998
999 TopoDS_Shape CurrentSpine;
1000
86b3805f 1001 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
7fd59977 1002
86b3805f
J
1003 for (j = 1; j <= myMap.Extent(); j++) {
1004 CurrentSpine = myMap.FindKey(j);
1005 CurrentEdge = TopoDS::Edge(myMap(j).First());
7fd59977 1006
86b3805f 1007 myMap(j).Clear();
7fd59977 1008 if (MapBis.IsBound(CurrentEdge)) {
1009 TopTools_SequenceOfShape S;
1010 if (!MapBis(CurrentEdge).IsEmpty()) {
6a442250 1011 Standard_Integer IndOfE = 0;
1012 if (myIsOpenResult)
1013 {
1014 if (j == 1)
1015 IndOfE = 1;
1016 else if (j == myMap.Extent())
1017 IndOfE = -1;
1018 }
7fd59977 1019 TrimEdge (CurrentEdge,
e11c1bc4 1020 CurrentSpine,
1021 mySpine,
7fd59977 1022 Detromp (CurrentSpine),
1023 MapBis (CurrentEdge) ,
1024 MapVerPar(CurrentEdge) ,
6a442250 1025 S, MapVV, IndOfE);
7fd59977 1026 for ( k = 1; k <= S.Length(); k++) {
86b3805f 1027 myMap(j).Append(S.Value(k));
7fd59977 1028 }
1029 }
1030 else {
1031 //-----------------
0d969553 1032 // Complete circles
7fd59977 1033 //-----------------
86b3805f 1034 myMap(j).Append(CurrentEdge);
7fd59977 1035 }
1036 }
1037 }
1038
1039 Standard_Integer ind;
1040 for (ind = 1; ind <= MapVV.Extent(); ind++)
1041 {
1042 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1043 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1044 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1045 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1046 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1047 TopTools_ListOfShape LV;
1048 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1049 BRepTools_Substitution aSubst;
1050 aSubst.Substitute( OldV, LV );
86b3805f 1051 for (j = 1; j <= myMap.Extent(); j++)
7fd59977 1052 {
86b3805f 1053 TopTools_ListIteratorOfListOfShape itl(myMap(j));
7fd59977 1054 for (; itl.More(); itl.Next())
1055 {
1056 aSubst.Build(itl.Value());
1057 if (aSubst.IsCopied(itl.Value()))
1058 {
1059 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
86b3805f 1060 TopAbs_Orientation SaveOr = itl.Value().Orientation();
7fd59977 1061 itl.Value() = listSh.First();
86b3805f 1062 itl.Value().Orientation(SaveOr);
7fd59977 1063 }
1064 }
1065 }
1066 }
1067
1068 //----------------------------------
0d969553 1069 // Construction of offset wires.
7fd59977 1070 //----------------------------------
1071 MakeWires ();
1072
0d969553 1073 // Update vertices ( Constructed in the plane Z = 0) !!!
7fd59977 1074 TopTools_MapOfShape MapVertex;
1075 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1076 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1077 if ( MapVertex.Add(V)) {
1078 gp_Pnt P = BRep_Tool::Pnt(V);
1079 P = RefPlane->Value(P.X(),P.Y());
1080 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1081 }
1082 }
1083
0d969553 1084 // Construction of curves 3d.
7fd59977 1085 BRepLib::BuildCurves3d(myShape);
1086 MapVertex.Clear();
1087 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1088 for (; Explo.More(); Explo.Next())
1089 {
1090 TopoDS_Edge E = TopoDS::Edge( Explo.Current() );
1091 TopoDS_Vertex V1, V2;
1092 TopExp::Vertices( E, V1, V2 );
1093 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1094 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1095
1096 TopLoc_Location loc;
1097 Standard_Real f, l;
1098 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve( E, loc, f, l );
1099 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1100 theCurve->Transform( loc.Transformation() );
1101 gp_Pnt f3d = theCurve->Value( f );
1102 gp_Pnt l3d = theCurve->Value( l );
1103
1104 Standard_Real dist1, dist2;
1105 dist1 = f3d.Distance( TV1->Pnt() );
1106 dist2 = l3d.Distance( TV2->Pnt() );
1107 if (! MapVertex.Contains( V1 ))
1108 {
1109 TV1->Pnt( f3d );
1110 MapVertex.Add( V1 );
1111 }
1112 else
1113 TV1->UpdateTolerance( 1.5*dist1 );
1114 if (! MapVertex.Contains( V2 ))
1115 {
1116 TV2->Pnt( l3d );
1117 MapVertex.Add( V2 );
1118 }
1119 else
1120 TV2->UpdateTolerance( 1.5*dist2 );
1121 }
1122
1123 FixHoles();
1124
1125 myIsDone = Standard_True;
1126}
1127
1128
1129//=======================================================================
1130//function : Generated
1131//purpose :
1132//=======================================================================
1133
86b3805f 1134BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
7fd59977 1135BRepFill_OffsetWire::Generated()
1136{
1137 return myMap;
1138}
1139
1140
1141//=======================================================================
1142//function : PrepareSpine
1143//purpose :
1144//=======================================================================
1145
1146void BRepFill_OffsetWire::PrepareSpine()
1147{
1148 BRep_Builder B;
1149 TopTools_ListOfShape Cuts;
1150 TopTools_ListIteratorOfListOfShape IteCuts;
1151 TopoDS_Vertex V1,V2;
1152
1153 myWorkSpine.Nullify();
1154 myMapSpine.Clear();
1155
1156 TopLoc_Location L;
1157 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1158 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1159 B.MakeFace(myWorkSpine,S,L,TolF);
1160
1161 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1162
1163 TopoDS_Wire NW;
1164 B.MakeWire (NW);
1165
1166// Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
1167 Standard_Integer ForcedCut = 0;
1168 Standard_Integer nbResEdges = -1;
1169 TopTools_IndexedMapOfShape EdgeMap;
1170
1171 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1172 Standard_Integer nbEdges = EdgeMap.Extent();
1173
6a442250 1174 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
7fd59977 1175 ForcedCut = 2;
1176// Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
1177
1178 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1179
1180 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1181 EdgeVertices(E,V1,V2);
1182 myMapSpine.Bind(V1,V1);
1183 myMapSpine.Bind(V2,V2);
1184 Cuts.Clear();
1185
0d969553 1186 // Cut
7fd59977 1187 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
1188// Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
1189 if (nbEdges == 2 && nbResEdges == 0)
1190 ForcedCut = 1;
1191// Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
1192 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1193
1194 if (Cuts.IsEmpty()) {
1195 B.Add(NW,E);
1196 myMapSpine.Bind(E,E);
1197 }
1198 else {
1199 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1200 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1201 NE.Orientation(E.Orientation());
1202 B.Add(NW,NE);
1203 myMapSpine.Bind(NE,E);
1204 EdgeVertices(NE,V1,V2);
1205 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1206 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1207 }
1208 }
1209 }
1210// Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
1211 TopoDS_Vertex aV1;
1212 TopoDS_Vertex aV2;
1213
1214 TopExp::Vertices(NW, aV1, aV2);
1215
1216 NW.Closed(aV1.IsSame(aV2));
1217// Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
1218 B.Add(myWorkSpine, NW);
1219 }
1220
1221#ifdef DRAW
1222 if ( AffichEdge) {
1896126e 1223 DBRep::Set("WS",myWorkSpine);
7fd59977 1224 }
1225#endif
1226
1227}
1228
1229//=======================================================================
c19dd45e 1230//function : UpdateDetromp
1231//purpose : For each interval on bissectrice defined by parameters
1232// test if the medium point is at a distance > offset
1233// in this case vertices corresponding to the extremities of the interval
1234// are ranked in the proofing.
1235// => If the same vertex appears in the proofing, the
1236// border of the zone of proximity is tangent to the offset .
1237//=======================================================================
1238
1239void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1240 const TopoDS_Shape& Shape1,
1241 const TopoDS_Shape& Shape2,
1242 const TopTools_SequenceOfShape& Vertices,
1243 const TColgp_SequenceOfPnt& Params,
1244 const Bisector_Bisec& Bisec,
1245 const Standard_Boolean SOnE,
1246 const Standard_Boolean EOnE,
1247 const BRepFill_TrimEdgeTool& Trim) const
1248{
c19dd45e 1249 Standard_Integer ii = 1;
1250 Standard_Real U1,U2;
1251 TopoDS_Vertex V1,V2;
1252
1253 Handle(Geom2d_Curve) Bis = Bisec.Value();
1254
1255 U1 = Bis->FirstParameter();
1256
1257 if (SOnE) {
1258 // the first point of the bissectrice is on the offset
1259 V1 = TopoDS::Vertex(Vertices.Value(ii));
1260 ii++;
1261 }
1262
1263 while (ii <= Vertices.Length()) {
1264 U2 = Params.Value(ii).X();
1265 V2 = TopoDS::Vertex(Vertices.Value(ii));
1266
a791eb69 1267 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1268 Standard_Boolean IsP_inside = Standard_True;
1269 if (myJoinType == GeomAbs_Arc)
1270 IsP_inside = Trim.IsInside(P);
1271 if (!IsP_inside) {
c19dd45e 1272 if (!V1.IsNull()) {
1273 Detromp(Shape1).Append(V1);
1274 Detromp(Shape2).Append(V1);
1275 }
1276 Detromp(Shape1).Append(V2);
1277 Detromp(Shape2).Append(V2);
1278 }
1279 U1 = U2;
1280 V1 = V2;
1281 ii ++;
1282 }
1283
1284 // test medium point between the last parameter and the end of the bissectrice.
1285 U2 = Bis->LastParameter();
1286 if (!EOnE) {
1287 if (!Precision::IsInfinite(U2)) {
1288 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
a791eb69 1289 Standard_Boolean IsP_inside = Standard_False;
1290 if (myJoinType == GeomAbs_Arc)
1291 IsP_inside = Trim.IsInside(P);
1292 if (!IsP_inside) {
c19dd45e 1293 if (!V1.IsNull()) {
1294 Detromp(Shape1).Append(V1);
1295 Detromp(Shape2).Append(V1);
1296 }
1297 }
1298 }
1299 else {
1300 if (!V1.IsNull()) {
1301 Detromp(Shape1).Append(V1);
1302 Detromp(Shape2).Append(V1);
1303 }
1304 }
1305 }
1306}
1307
1308//=======================================================================
7fd59977 1309//function : MakeWires
1310//purpose :
1311//=======================================================================
1312
1313void BRepFill_OffsetWire::MakeWires()
1314{
1315 //--------------------------------------------------------
0d969553 1316 // creation of a single list of created parallel edges.
7fd59977 1317 //--------------------------------------------------------
1318 TopTools_SequenceOfShape TheEdges;
1319 TopTools_ListOfShape TheWires;
1320 TopTools_ListIteratorOfListOfShape itl;
86b3805f
J
1321 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1322 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1323 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
7fd59977 1324 TopoDS_Vertex V1,V2,VF,CV;
86b3805f 1325 Standard_Integer i;
7fd59977 1326
86b3805f
J
1327 for (i = 1; i <= myMap.Extent(); i++) {
1328 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
7fd59977 1329 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1330 TopExp::Vertices (E,V1,V2);
1331 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
1332 continue; //remove small closed edges
86b3805f 1333 if (!MVE.Contains(V1)) {
7fd59977 1334 TopTools_ListOfShape empty;
86b3805f 1335 MVE.Add(V1,empty);
7fd59977 1336 }
86b3805f
J
1337 MVE.ChangeFromKey(V1).Append(E);
1338 if (!MVE.Contains(V2)) {
7fd59977 1339 TopTools_ListOfShape empty;
86b3805f 1340 MVE.Add(V2,empty);
7fd59977 1341 }
86b3805f 1342 MVE.ChangeFromKey(V2).Append(E);
7fd59977 1343 }
1344 }
1345
1346 //--------------------------------------
0d969553 1347 // Creation of parallel wires.
7fd59977 1348 //--------------------------------------
1349 BRep_Builder B;
1350
1351// Standard_Integer NbEdges;
1352// Standard_Boolean NewWire = Standard_True;
1353// Standard_Boolean AddEdge = Standard_False;
1354
1355 TopoDS_Wire NW;
1356 Standard_Boolean End;
1357 TopoDS_Edge CE;
1358
1359 while (!MVE.IsEmpty()) {
1360 B.MakeWire(NW);
1361
86b3805f
J
1362 //MVEit.Initialize(MVE);
1363 for (i = 1; i <= MVE.Extent(); i++)
1364 if(MVE(i).Extent() == 1)
1365 break;
7fd59977 1366
86b3805f
J
1367 //if(!MVEit.More()) MVEit.Initialize(MVE);
1368 if (i > MVE.Extent())
1369 i = 1;
7fd59977 1370
86b3805f
J
1371 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1372 CE = TopoDS::Edge(MVE(i).First());
7fd59977 1373 End = Standard_False;
86b3805f 1374 MVE.ChangeFromKey(CV).RemoveFirst();
7fd59977 1375
1376// Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
1377 Standard_Boolean isClosed = Standard_False;
1378// Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
1379
1380 while(!End) {
1381 //-------------------------------
0d969553 1382 // Construction of a wire.
7fd59977 1383 //-------------------------------
1384 TopExp::Vertices(CE,V1,V2);
1385 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1386
1387 B.Add (NW,CE);
1388
86b3805f 1389 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
7fd59977 1390// Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1391 isClosed = VF.IsSame(CV);
1392// Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1393 End = Standard_True;
86b3805f
J
1394 //MVE.UnBind(VF);
1395 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1396 TopTools_ListOfShape LastList;
1397 LastList.Append(MVE(MVE.Extent()));
1398 MVE.RemoveLast();
1399 if (MVE.FindIndex(VF) != 0)
1400 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
7fd59977 1401 }
1402
1403 if (!End) {
86b3805f 1404 if (MVE.FindFromKey(CV).Extent() > 2) {
0d969553 1405 //cout <<"vertex on more that 2 edges in a face."<<endl;
7fd59977 1406 }
86b3805f 1407 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
7fd59977 1408 if (itl.Value().IsSame(CE)) {
86b3805f 1409 MVE.ChangeFromKey(CV).Remove(itl);
7fd59977 1410 break;
1411 }
1412 }
86b3805f
J
1413 if (!MVE.FindFromKey(CV).IsEmpty()) {
1414 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1415 MVE.ChangeFromKey(CV).RemoveFirst();
7fd59977 1416 }
86b3805f
J
1417 if (MVE.FindFromKey(CV).IsEmpty())
1418 {
1419 //MVE.UnBind(CV);
1420 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1421 TopTools_ListOfShape LastList;
1422 LastList.Append(MVE(MVE.Extent()));
1423 MVE.RemoveLast();
1424 if (MVE.FindIndex(CV) != 0)
1425 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1426 }
7fd59977 1427 }
1428 }
1429// Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1430// NW.Closed(Standard_True);
1431 NW.Closed(isClosed);
1432// Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
1433 TheWires.Append(NW);
1434 }
1435
0d969553
Y
1436 // update myShape :
1437 // -- if only one wire : myShape is a Wire
1438 // -- if several wires : myShape is a Compound.
7fd59977 1439 if ( TheWires.Extent() == 1) {
1440 myShape = TheWires.First();
1441 }
1442 else {
1443 TopoDS_Compound R;
1444 B.MakeCompound(R);
1445 TopTools_ListIteratorOfListOfShape it(TheWires);
1446 for ( ; it.More(); it.Next()) {
1447 B.Add(R, it.Value());
1448 }
1449 myShape = R;
1450 }
1451
1452}
1453
1454//=======================================================================
1455//function : FixHoles
1456//purpose :
1457//=======================================================================
1458
1459void BRepFill_OffsetWire::FixHoles()
1460{
1461 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1462
1463 Standard_Real MaxTol = 0.;
1464 Standard_Integer i;
1465 BRep_Builder BB;
1466
1467 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1468 for (; Explo.More(); Explo.Next())
91bb31f3 1469 {
1470 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1471 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1472 if (Tol > MaxTol)
1473 MaxTol = Tol;
1474 }
7fd59977 1475 MaxTol *= 100.;
1476
1477 Explo.Init( myShape, TopAbs_WIRE );
1478 for (; Explo.More(); Explo.Next())
91bb31f3 1479 {
1480 TopoDS_Shape aWire = Explo.Current();
1481 // Remove duplicated edges
1482 TopTools_DataMapOfShapeListOfShape EEmap;
1483 TopoDS_Iterator it( aWire );
1484 for (; it.More(); it.Next())
7fd59977 1485 {
91bb31f3 1486 const TopoDS_Shape& anEdge = it.Value();
1487 if (! EEmap.IsBound( anEdge ))
1488 {
1489 TopTools_ListOfShape LE;
1490 EEmap.Bind( anEdge, LE );
1491 }
7fd59977 1492 else
91bb31f3 1493 EEmap(anEdge).Append( anEdge );
7fd59977 1494 }
91bb31f3 1495 aWire.Free( Standard_True );
1496 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1497 for (; mapit.More(); mapit.Next())
1498 {
1499 const TopTools_ListOfShape& LE = mapit.Value();
1500 TopTools_ListIteratorOfListOfShape itl( LE );
1501 for (; itl.More(); itl.Next())
1502 BB.Remove( aWire, itl.Value() );
1503 }
1504 // Sorting
1505 if (aWire.Closed())
1506 ClosedWires.Append( aWire );
1507 else
1508 UnclosedWires.Append( aWire );
1509 }
1510
7fd59977 1511 while (!UnclosedWires.IsEmpty())
91bb31f3 1512 {
1513 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1514 TopoDS_Vertex Vf, Vl;
1515 TopExp::Vertices( Base, Vf, Vl );
1516 if(Vf.IsNull() || Vl.IsNull())
1517 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
1518 gp_Pnt Pf, Pl;
1519 Pf = BRep_Tool::Pnt(Vf);
1520 Pl = BRep_Tool::Pnt(Vl);
1521 Standard_Real DistF = RealLast(), DistL = RealLast();
1522 Standard_Integer IndexF = 1, IndexL = 1;
1523 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1524 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
7fd59977 1525 {
91bb31f3 1526 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1527 TopoDS_Vertex V1, V2;
1528 TopExp::Vertices( aWire, V1, V2 );
1529
1530 if(V1.IsNull() || V2.IsNull())
ab87e6fc 1531 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
91bb31f3 1532
1533 gp_Pnt P1, P2;
1534 P1 = BRep_Tool::Pnt(V1);
1535 P2 = BRep_Tool::Pnt(V2);
1536 Standard_Real dist = Pf.Distance( P1 );
1537 if (dist < DistF)
1538 {
1539 DistF = dist;
1540 IndexF = i;
1541 IsFirstF = Standard_True;
1542 }
1543 dist = Pf.Distance( P2 );
1544 if (dist < DistF)
1545 {
1546 DistF = dist;
1547 IndexF = i;
1548 IsFirstF = Standard_False;
1549 }
1550 dist = Pl.Distance( P1 );
1551 if (dist < DistL)
1552 {
1553 DistL = dist;
1554 IndexL = i;
1555 IsFirstL = Standard_True;
1556 }
1557 dist = Pl.Distance( P2 );
1558 if (dist < DistL)
1559 {
1560 DistL = dist;
1561 IndexL = i;
1562 IsFirstL = Standard_False;
1563 }
1564 }
1565 TopoDS_Wire theWire;
1566 TopoDS_Edge theEdge;
1567 TopoDS_Vertex theVertex;
1568 Standard_Real CommonTol;
1569 Standard_Boolean TryToClose = Standard_True;
1570 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1571 {
1572 if (DistF < DistL)
1573 {
1574 DistL = RealLast();
1575 IndexL++;
1576 }
1577 else
1578 {
1579 DistF = RealLast();
1580 IndexF++;
1581 }
1582 TryToClose = Standard_False;
1583 }
1584 if (DistF <= MaxTol)
1585 {
1586 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1587 TopoDS_Vertex V1, V2;
1588 TopExp::Vertices( theWire, V1, V2 );
1589 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1590 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1591 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1592 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1593 TopoDS_Iterator it( theWire );
1594 for (; it.More(); it.Next())
1595 {
1596 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1597 if (IsFirstF) anEdge.Reverse();
1598 if (!anEdge.IsSame( theEdge ))
1599 BB.Add( Base, anEdge );
1600 }
1601 theVertex = (IsFirstF)? V1 : V2;
1602 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1603 if (DistF <= CommonTol)
1604 {
1605 theEdge.Free( Standard_True );
1606 Vf.Orientation( theVertex.Orientation() );
1607 BB.Remove( theEdge, theVertex );
1608 BB.Add( theEdge, Vf );
1609 BB.UpdateVertex( Vf, CommonTol );
1610 if (IsFirstF) theEdge.Reverse();
1611 BB.Add( Base, theEdge );
1612 }
1613 else
1614 {
1615 if (IsFirstF) theEdge.Reverse();
1616 BB.Add( Base, theEdge );
1617 // Creating new edge from theVertex to Vf
1618 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1619 BB.Add( Base, NewEdge );
1620 }
1621 }
1622 if (DistL <= MaxTol && IndexL != IndexF)
1623 {
1624 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1625 TopoDS_Vertex V1, V2;
1626 TopExp::Vertices( theWire, V1, V2 );
1627 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1628 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1629 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1630 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1631 TopoDS_Iterator it( theWire );
1632 for (; it.More(); it.Next())
1633 {
1634 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1635 if (!IsFirstL) anEdge.Reverse();
1636 if (!anEdge.IsSame( theEdge ))
1637 BB.Add( Base, anEdge );
1638 }
1639 theVertex = (IsFirstL)? V1 : V2;
1640 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1641 if (DistL <= CommonTol)
1642 {
1643 theEdge.Free( Standard_True );
1644 Vl.Orientation( theVertex.Orientation() );
1645 BB.Remove( theEdge, theVertex );
1646 BB.Add( theEdge, Vl );
1647 BB.UpdateVertex( Vl, CommonTol );
1648 if (!IsFirstL) theEdge.Reverse();
1649 BB.Add( Base, theEdge );
1650 }
1651 else
1652 {
1653 if (!IsFirstL) theEdge.Reverse();
1654 BB.Add( Base, theEdge );
1655 // Creating new edge from Vl to theVertex
1656 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1657 BB.Add( Base, NewEdge );
1658 }
1659 }
1660 // Check if it is possible to close resulting wire
1661 if (TryToClose)
1662 {
1663 TopExp::Vertices( Base, Vf, Vl );
1664 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1665 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1666 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1667 TopoDS_Edge Efirst, Elast;
1668 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1669 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
7fd59977 1670 Pf = BRep_Tool::Pnt(Vf);
1671 Pl = BRep_Tool::Pnt(Vl);
91bb31f3 1672 Standard_Real Dist = Pf.Distance(Pl);
1673 if (Dist <= CommonTol)
1674 {
1675 Elast.Free( Standard_True );
1676 Vf.Orientation( Vl.Orientation() );
1677 BB.Remove( Elast, Vl );
1678 BB.Add( Elast, Vf );
1679 BB.UpdateVertex( Vf, CommonTol );
1680 Base.Closed( Standard_True );
1681 }
1682 else if (Dist <= MaxTol)
1683 {
1684 // Creating new edge from Vl to Vf
1685 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1686 BB.Add( Base, NewEdge );
1687 Base.Closed( Standard_True );
1688 }
7fd59977 1689 }
91bb31f3 1690 // Updating sequences ClosedWires and UnclosedWires
1691 if (DistF <= MaxTol)
1692 UnclosedWires.Remove( IndexF );
1693 if (DistL <= MaxTol && IndexL != IndexF)
7fd59977 1694 {
91bb31f3 1695 if (DistF <= MaxTol && IndexL > IndexF)
1696 IndexL--;
1697 UnclosedWires.Remove( IndexL );
7fd59977 1698 }
91bb31f3 1699 if (Base.Closed())
7fd59977 1700 {
91bb31f3 1701 ClosedWires.Append( Base );
1702 UnclosedWires.Remove( 1 );
7fd59977 1703 }
91bb31f3 1704 else if (DistF > MaxTol && DistL > MaxTol)
1705 {
1706 IsolatedWires.Append( Base );
1707 UnclosedWires.Remove( 1 );
1708 }
1709 }
1710
1711 // Updating myShape
1712 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1713 {
1714 if (!ClosedWires.IsEmpty())
1715 myShape = ClosedWires.First();
1716 else
1717 myShape = IsolatedWires.First();
1718 }
1719 else
1720 {
1721 TopoDS_Compound R;
1722 BB.MakeCompound( R );
1723 for (i = 1; i <= ClosedWires.Length(); i++)
1724 BB.Add( R, ClosedWires(i) );
1725 for (i = 1; i <= IsolatedWires.Length(); i++)
1726 BB.Add( R, IsolatedWires(i) );
1727 myShape = R;
1728 }
7fd59977 1729}
1730
1731//=======================================================================
1732//function : CutEdge
0d969553
Y
1733//purpose : Cut edge at the extrema of curvatures and points of inflexion.
1734// So, closed circles are cut in two.
1735// If <Cuts> is empty, the edge is not modified.
1736// The first and the last vertex of the initial edge
1737// belong to the first and the last parts respectively.
7fd59977 1738//=======================================================================
1739Standard_Integer CutEdge (const TopoDS_Edge& E,
1740 const TopoDS_Face& F,
1741 Standard_Integer ForceCut,
1742 TopTools_ListOfShape& Cuts)
1743{
1744 Cuts.Clear();
1745 MAT2d_CutCurve Cuter;
1746 TColGeom2d_SequenceOfCurve theCurves;
1747 Standard_Real f,l;
1748 Handle(Geom2d_Curve) C2d;
1749 Handle(Geom2d_TrimmedCurve) CT2d;
1750// Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
1751 Standard_Real aTol = BRep_Tool::Tolerance(E);
1752 Handle(Geom_Curve) aC;
1753// Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
1754
1755 TopoDS_Vertex V1,V2,VF,VL;
1756 TopExp::Vertices (E,V1,V2);
1757 BRep_Builder B;
1758
1759 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
1760// Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
1761 aC = BRep_Tool::Curve(E,f,l);
1762// Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
1763 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1764 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1765
1766 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
c6541a0c 1767 ( Abs(f-l) >= M_PI) ) {
7fd59977 1768 return 0;
7fd59977 1769 }
1770
1771 //-------------------------
0d969553 1772 // Cut curve.
7fd59977 1773 //-------------------------
1774 Cuter.Perform(CT2d);
1775
1776// Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
1777 if (ForceCut == 0) {
1778 if (Cuter.UnModified()) {
1779 //-----------------------------
0d969553 1780 // edge not modified => return.
7fd59977 1781 //-----------------------------
1782 return 0;
1783 } else {
1784 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1785 theCurves.Append(Cuter.Value(k));
1786 }
1787 } else if (ForceCut == 1) {
1788 if (Cuter.UnModified()) {
1789 CutCurve (CT2d, 2, theCurves);
1790 } else {
1791 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1792 theCurves.Append(Cuter.Value(k));
1793 }
1794 } else if (ForceCut == 2) {
1795 if (Cuter.UnModified()) {
1796 CutCurve (CT2d, 3, theCurves);
1797 } else {
1798 if (Cuter.NbCurves() == 2) {
1799 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1800
1801 if (CC->LastParameter() > (l+f)/2.) {
1802 CutCurve (CC, 2, theCurves);
1803 theCurves.Append(Cuter.Value(2));
1804 } else {
1805 theCurves.Append(CC);
1806 CutCurve (Cuter.Value(2), 2, theCurves);
1807 }
1808 } else {
1809 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1810 theCurves.Append(Cuter.Value(k));
1811 }
1812 }
1813 }
1814// Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
1815
1816 //--------------------------------------
0d969553 1817 // Creation of cut edges.
7fd59977 1818 //--------------------------------------
1819 VF = V1;
1820
1821 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1822
1823 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1824
1825 if (k == theCurves.Length()) {VL = V2;}
1826 else {
1827// Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
1828 gp_Pnt P = aC->Value(CC->LastParameter());
1829
1830 VL = BRepLib_MakeVertex(P);
1831 B.UpdateVertex(VL, aTol);
1832// Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
1833 }
1834 TopoDS_Shape aLocalShape = E.EmptyCopied();
1835 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
1836// TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
1837 NE.Orientation(TopAbs_FORWARD);
1838 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1839 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1840 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1841 Cuts.Append(NE.Oriented(E.Orientation()));
1842 VF = VL;
1843 }
1844
1845 return theCurves.Length();
1846}
1847
1848// Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1849//=======================================================================
1850//function : CutCurve
1851//purpose :
1852//=======================================================================
1853
1854void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
1855 const Standard_Integer nbParts,
1856 TColGeom2d_SequenceOfCurve& theCurves)
1857{
1858 Handle(Geom2d_TrimmedCurve) TrimC;
1859 Standard_Real UF,UL,UC;
1860 Standard_Real Step;
1861 gp_Pnt2d PF,PL,PC;
1862 Standard_Real PTol = Precision::PConfusion()*10;
1863 Standard_Real Tol = Precision::Confusion()*10;
1864 Standard_Boolean YaCut = Standard_False;
1865
1866 UF = C->FirstParameter();
1867 UL = C->LastParameter ();
1868 PF = C->Value(UF);
1869 PL = C->Value(UL);
1870
1871 Step = (UL - UF)/nbParts;
1872
1873 for (Standard_Integer i = 1; i < nbParts; i++) {
1874
1875 UC = UF + i*Step;
1876 PC = C->Value(UC);
1877
1878 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1879 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
1880 continue;
1881
1882 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1883 theCurves.Append(TrimC);
1884 UF = UC;
1885 PF = PC;
1886 YaCut = Standard_True;
1887 }
1888 }
1889 if (YaCut) {
1890 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1891 theCurves.Append(TrimC);
1892 } else
1893 theCurves.Append(C);
1894}
1895// Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1896
1897//=======================================================================
1898//function : MakeCircle
1899//purpose :
1900//=======================================================================
1901
1902void MakeCircle (const TopoDS_Edge& E,
1903 const TopoDS_Vertex& V,
1904 const TopoDS_Face& F,
1905 const Standard_Real Offset,
86b3805f 1906 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
7fd59977 1907 const Handle(Geom_Plane)& RefPlane)
1908{
0d969553 1909 // evaluate the Axis of the Circle.
7fd59977 1910 Standard_Real f,l;
1911 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
1912 gp_Vec2d DX;
1913 gp_Pnt2d P;
1914
1915 if (E.Orientation() == TopAbs_FORWARD) {
1916 GC->D1(l,P,DX);
1917 DX.Reverse();
1918 }
1919 else GC->D1(f,P,DX);
1920
1921 gp_Ax2d Axis(P,gp_Dir2d(DX));
1922 Handle(Geom2d_Circle) Circ
1923 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
1924
1925 // Bind the edges in my Map.
1926 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
1927 TopTools_ListOfShape LL;
1928
1929 LL.Append(OE);
86b3805f 1930 Map.Add(V,LL);
7fd59977 1931
1932#ifdef DRAW
1933 if ( AffichGeom && !OE.IsNull()) {
1896126e 1934 char name[256];
7fd59977 1935 sprintf(name,"OFFSET_%d",++NbOFFSET);
1936 DBRep::Set(name,OE);
1937 }
1938#endif
1939}
1940
1941//=======================================================================
1942//function : MakeOffset
1943//purpose :
1944//=======================================================================
1945
1946void MakeOffset (const TopoDS_Edge& E,
1947 const TopoDS_Face& F,
1948 const Standard_Real Offset,
86b3805f 1949 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
6a442250 1950 const Handle(Geom_Plane)& RefPlane,
1951 const Standard_Boolean IsOpenResult,
c7806cb6 1952 const GeomAbs_JoinType theJoinType,
6a442250 1953 const TopoDS_Vertex * Ends)
7fd59977 1954{
1955 Standard_Real f,l;
1956 Standard_Real anOffset = Offset;
1957
1958 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
1959
1960 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
1961 Handle(Geom2d_Curve) G2dOC;
1962
6a442250 1963 Standard_Boolean ToExtendFirstPar = Standard_True;
1964 Standard_Boolean ToExtendLastPar = Standard_True;
1965 if (IsOpenResult)
1966 {
1967 TopoDS_Vertex V1, V2;
1968 TopExp::Vertices(E, V1, V2);
1969 if (V1.IsSame(Ends[0]) ||
1970 V1.IsSame(Ends[1]))
1971 ToExtendFirstPar = Standard_False;
1972 if (V2.IsSame(Ends[0]) ||
1973 V2.IsSame(Ends[1]))
1974 ToExtendLastPar = Standard_False;
1975 }
1976
7fd59977 1977 Geom2dAdaptor_Curve AC(G2d,f,l);
1978 if ( AC.GetType() == GeomAbs_Circle) {
0d969553
Y
1979 // if the offset is greater otr equal to the radius and the side of the
1980 // concavity of the circle => edge null.
7fd59977 1981 gp_Circ2d C1(AC.Circle());
7fd59977 1982 gp_Ax22d axes( C1.Axis());
1983 gp_Dir2d Xd = axes.XDirection();
1984 gp_Dir2d Yd = axes.YDirection();
1985 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
1986 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
1987
9ffd84ad 1988 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
0d969553 1989
7fd59977 1990 Handle(Geom2dAdaptor_HCurve) AHC =
1991 new Geom2dAdaptor_HCurve(G2d);
1992 Adaptor3d_OffsetCurve Off(AHC,-anOffset);
1993 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
1994
c6541a0c 1995 Standard_Real Delta = 2*M_PI - l + f;
c7806cb6 1996 if (theJoinType == GeomAbs_Arc)
1997 {
1998 if (ToExtendFirstPar)
1999 f -= 0.2*Delta;
2000 if (ToExtendLastPar)
2001 l += 0.2*Delta;
2002 }
2003 else //GeomAbs_Intersection
2004 {
2005 if (ToExtendFirstPar && ToExtendLastPar)
2006 {
2007 Standard_Real old_l = l;
2008 f = old_l + Delta/2.;
2009 l = f + 2*M_PI;
2010 }
2011 else if (ToExtendFirstPar)
2012 {
2013 f = l;
2014 l = f + 2*M_PI;
2015 }
2016 else if (ToExtendLastPar)
2017 {
2018 l = f + 2*M_PI;
2019 }
2020 }
7fd59977 2021 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2022 }
2023 }
2024 else if (AC.GetType() == GeomAbs_Line) {
2025 Handle(Geom2dAdaptor_HCurve) AHC =
2026 new Geom2dAdaptor_HCurve(G2d);
2027 Adaptor3d_OffsetCurve Off(AHC,anOffset);
2028 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2029 Standard_Real Delta = (l - f);
6a442250 2030 if (ToExtendFirstPar)
c7806cb6 2031 {
2032 if (theJoinType == GeomAbs_Arc)
2033 f -= Delta;
2034 else //GeomAbs_Intersection
2035 f = -Precision::Infinite();
2036 }
6a442250 2037 if (ToExtendLastPar)
c7806cb6 2038 {
2039 if (theJoinType == GeomAbs_Arc)
2040 l += Delta;
2041 else //GeomAbs_Intersection
2042 l = Precision::Infinite();
2043 }
7fd59977 2044 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2045 }
2046 else {
2047
2048 anOffset = -anOffset;
2049 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2050 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2051
2052 }
2053
2054 // Bind the edges in my Map.
2055 if (!G2dOC.IsNull()) {
2056 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2057 OE.Orientation(E.Orientation());
2058 TopTools_ListOfShape LL;
2059 LL.Append(OE);
86b3805f 2060 Map.Add(E,LL);
7fd59977 2061
2062#ifdef DRAW
2063 if (AffichGeom && !OE.IsNull()) {
1896126e 2064 char name[256];
7fd59977 2065 sprintf(name,"OFFSET_%d",++NbOFFSET);
2066 DBRep::Set(name,OE);
2067 Standard_Real ii = 0;
2068 }
2069#endif
2070
2071 }
2072}
2073
7fd59977 2074
2075//=======================================================================
2076//function : VertexFromNode
2077//purpose :
2078//=======================================================================
2079
2080Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
2081 const Standard_Real Offset,
2082 gp_Pnt2d& PN,
2083 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2084 TopoDS_Vertex& VN)
2085{
2086 Standard_Boolean Status;
2087 Standard_Real Tol = Precision::Confusion();
2088 BRep_Builder B;
2089
2090 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2091 //------------------------------------------------
0d969553 2092 // the Node gives a vertex on the offset
7fd59977 2093 //------------------------------------------------
2094 if (MapNodeVertex.IsBound(aNode)) {
2095 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2096 }
2097 else {
2098 gp_Pnt P(PN.X(),PN.Y(),0.);
2099 B.MakeVertex (VN);
2100 B.UpdateVertex(VN,P, Precision::Confusion());
2101 MapNodeVertex.Bind(aNode,VN);
2102 }
2103 Status = Standard_True;
2104 }
2105 else Status = Standard_False;
2106
2107 return Status;
2108}
2109
2110
2111//=======================================================================
2112//function : StoreInMap
2113//purpose :
2114//=======================================================================
2115
2116void StoreInMap (const TopoDS_Shape& V1,
2117 const TopoDS_Shape& V2,
2118 TopTools_IndexedDataMapOfShapeShape& MapVV)
2119{
2120 TopoDS_Shape OldV = V1, NewV = V2;
2121 Standard_Integer i;
2122
2123 if (MapVV.Contains(V2))
2124 NewV = MapVV.FindFromKey(V2);
2125
2126 if (MapVV.Contains(V1))
2127 MapVV.ChangeFromKey(V1) = NewV;
2128
2129 for (i = 1; i <= MapVV.Extent(); i++)
2130 if (MapVV(i).IsSame(V1))
2131 MapVV(i) = NewV;
2132
2133 MapVV.Add(V1, NewV);
2134}
2135
2136//=======================================================================
2137//function : TrimEdge
2138//purpose :
2139//=======================================================================
2140
2141void TrimEdge (const TopoDS_Edge& E,
e11c1bc4 2142 const TopoDS_Shape& ProE,
2143 const TopoDS_Face& AllSpine,
7fd59977 2144 const TopTools_ListOfShape& Detromp,
6a442250 2145 TopTools_SequenceOfShape& TheVer,
2146 TColStd_SequenceOfReal& ThePar,
2147 TopTools_SequenceOfShape& S,
2148 TopTools_IndexedDataMapOfShapeShape& MapVV,
2149 const Standard_Integer IndOfE)
7fd59977 2150{
2151 Standard_Boolean Change = Standard_True;
2152 BRep_Builder TheBuilder;
2153 S.Clear();
2154
2155 //-----------------------------------------------------------
0d969553 2156 // Parse two sequences depending on the parameter on the edge.
7fd59977 2157 //-----------------------------------------------------------
2158 while (Change) {
2159 Change = Standard_False;
2160 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2161 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2162 ThePar.Exchange(i,i+1);
2163 TheVer.Exchange(i,i+1);
2164 Change = Standard_True;
2165 }
2166 }
2167 }
2168
2169 //----------------------------------------------------------
0d969553 2170 // If a vertex is not in the proofing, it is eliminated.
7fd59977 2171 //----------------------------------------------------------
2172 if (!BRep_Tool::Degenerated(E)) {
2173 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2174 if ( DoubleOrNotInside (Detromp,
2175 TopoDS::Vertex(TheVer.Value(k)))) {
2176 TheVer.Remove(k);
2177 ThePar.Remove(k);
2178 k--;
2179 }
2180 }
2181 }
2182
2183 //----------------------------------------------------------
0d969553
Y
2184 // If a vertex_double appears twice in the proofing
2185 // the vertex is removed.
2186 // otherwise preserve only one of its representations.
7fd59977 2187 //----------------------------------------------------------
2188 if (!BRep_Tool::Degenerated(E)) {
2189 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2190 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
2191 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= Precision::PConfusion()) {
2192
2193 if(k+1 == TheVer.Length()) {
2194 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2195 TheVer.Remove(k);
2196 ThePar.Remove(k);
2197 }
2198 else {
2199 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2200 TheVer.Remove(k+1);
2201 ThePar.Remove(k+1);
2202 }
2203 /*
2204 if ( DoubleOrNotInside (Detromp,
2205 TopoDS::Vertex(TheVer.Value(k)))) {
2206 TheVer.Remove(k);
2207 ThePar.Remove(k);
2208 k--;
2209 }
2210 */
2211 k--;
2212 }
2213 }
2214 }
2215 //-----------------------------------------------------------
0d969553
Y
2216 // Creation of edges.
2217 // the number of vertices should be even. The created edges
2218 // go from a vertex with uneven index i to vertex i+1;
7fd59977 2219 //-----------------------------------------------------------
6a442250 2220 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2221 {
7fd59977 2222 TopoDS_Shape aLocalShape = E.EmptyCopied();
2223 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
6a442250 2224 TopoDS_Vertex V1, V2;
2225 TopExp::Vertices(E, V1, V2);
2226 Standard_Real fpar, lpar;
e11c1bc4 2227 Handle(Geom_Surface) aPlane;
2228 TopLoc_Location aLoc;
2229 Handle(Geom2d_Curve) PCurve;
2230 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2231 //BRep_Tool::Range(E, fpar, lpar);
2232
2233 Standard_Real TrPar1, TrPar2;
2234 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2235
6a442250 2236 if (IndOfE == 1) //first edge of open wire
2237 {
2238 if (NewEdge.Orientation() == TopAbs_FORWARD)
2239 {
e11c1bc4 2240 if (ToTrimAsOrigin)
2241 {
2242 fpar = TrPar1;
2243 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2244 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2245 V1 = BRepLib_MakeVertex(TrPnt);
2246 }
6a442250 2247 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2248 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2249 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2250 }
2251 else
2252 {
e11c1bc4 2253 if (ToTrimAsOrigin)
2254 {
2255 lpar = TrPar2;
2256 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2257 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2258 V2 = BRepLib_MakeVertex(TrPnt);
2259 }
6a442250 2260 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2261 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2262 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2263 }
7fd59977 2264 }
6a442250 2265 else //last edge of open wire
2266 {
2267 if (NewEdge.Orientation() == TopAbs_FORWARD)
2268 {
e11c1bc4 2269 if (ToTrimAsOrigin)
2270 {
2271 lpar = TrPar2;
2272 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2273 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2274 V2 = BRepLib_MakeVertex(TrPnt);
2275 }
6a442250 2276 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2277 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2278 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2279 }
2280 else
2281 {
e11c1bc4 2282 if (ToTrimAsOrigin)
2283 {
2284 fpar = TrPar1;
2285 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2286 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2287 V1 = BRepLib_MakeVertex(TrPnt);
2288 }
6a442250 2289 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2290 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2291 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2292 }
7fd59977 2293 }
6a442250 2294 S.Append(NewEdge);
2295 }
2296 else
2297 {
2298 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2299 TopoDS_Shape aLocalShape = E.EmptyCopied();
2300 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2301 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2302
2303 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2304 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2305 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2306 }
2307 else {
2308 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2309 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2310 }
2311
2312
2313 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2314
7fd59977 2315#ifdef DRAW
6a442250 2316 if ( AffichEdge) {
2317 char name[256];
2318 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2319 DBRep::Set(name,NewEdge);
2320 }
2321 if (Affich2d) {
2322 TopLoc_Location L;
2323 Standard_Real f,l;
2324 Handle(Geom_Surface) Surf;
2325 Handle(Geom2d_Curve) C;
2326 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2327 char name[256];
2328 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2329 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2330 Handle(DrawTrSurf_Curve2d) dr =
2331 new DrawTrSurf_Curve2d(C2d,Standard_False);
2332 dr->SetColor(Draw_bleu);
2333 Draw::Set(name,dr);
2334 }
7fd59977 2335#endif
6a442250 2336
2337 S.Append(NewEdge);
2338 }
7fd59977 2339 }
2340}
2341
2342//=======================================================================
e11c1bc4 2343//function : IsInnerEdge
2344//purpose :
2345//=======================================================================
2346
2347static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2348 const TopoDS_Face& AllSpine,
2349 Standard_Real& TrPar1,
2350 Standard_Real& TrPar2)
2351{
2352 if (ProE.ShapeType() != TopAbs_EDGE)
2353 return Standard_False;
2354
2355 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2356
2357 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2358 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2359 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2360 {
2361 const TopTools_ListOfShape& LE = VEmap(i);
2362 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2363 return Standard_False;
2364 }
2365
2366 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2367 return Standard_True;
2368}
2369
2370
2371
2372//=======================================================================
7fd59977 2373//function : DoubleOrNotInside
0d969553 2374//purpose : return True if V appears twice in LV or is not inside.
7fd59977 2375//=======================================================================
2376
2377Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
2378 const TopoDS_Vertex& V)
2379{
2380 Standard_Boolean Vu = Standard_False;
2381 TopTools_ListIteratorOfListOfShape it(LV);
2382
2383 for ( ; it.More(); it.Next()) {
2384 if (V.IsSame(it.Value())) {
2385 if (Vu) return Standard_True;
2386 else Vu = Standard_True;
2387 }
2388 }
2389 if (Vu) return Standard_False;
2390 else return Standard_True;
2391}
2392
2393Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
2394 const TopoDS_Vertex& aVertex)
2395{
2396 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2397 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2398 PV2d.SetCoord( PV.X(), PV.Y() );
2399
2400 Handle(Geom2d_Curve) PCurve;
2401 Handle( BRep_CurveRepresentation ) CurveRep =
2402 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2403 PCurve = CurveRep->PCurve();
2404
2405 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2406 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2407 Pfirst = PCurve->Value(fpar);
2408 Plast = PCurve->Value(lpar);
2409 Pmid = PCurve->Value((fpar + lpar)*0.5);
2410
2411 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2412 theTol *= 1.5;
2413
2414 Standard_Real dist1 = Pfirst.Distance(PV2d);
2415 Standard_Real dist2 = Plast.Distance(PV2d);
2416 Standard_Real dist3 = Pmid.Distance(PV2d);
2417
2418 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2419 return Standard_True;
2420
2421 return Standard_False;
2422}
2423
2424static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
2425 const BRepMAT2d_BisectingLocus& Locus,
2426 const BRepMAT2d_LinkTopoBilo& Link,
2427 TopTools_ListOfShape& BadEdges)
2428{
2429
2430 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2431 Standard_Real eps = Precision::Confusion();
2432 Standard_Real LimCurv = 1./Offset;
2433
2434 TopTools_MapOfShape aMap;
2435
2436 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2437 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2438 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2439 if (SE.ShapeType() == TopAbs_EDGE) {
2440
2441 if (aMap.Contains(SE)) {
2442 //cout << "Edge is treated second time" << endl;
2443 continue;
2444 }
2445
2446 TopoDS_Edge E = TopoDS::Edge(SE);
2447
2448 Standard_Real f,l;
2449
2450 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2451
2452 Geom2dAdaptor_Curve AC(G2d,f,l);
2453 GeomAbs_CurveType aCType = AC.GetType();
2454
2455 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2456
2457 Standard_Boolean reverse = Standard_False;
2458 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2459
2460 gp_Pnt2d P, Pc;
2461 gp_Dir2d N;
2462
2463 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2464
2465 aCLProps.SetParameter(f);
2466 if(!aCLProps.IsTangentDefined()) {
2467 BadEdges.Append(SE);
2468 aMap.Add(SE);
2469 continue;
2470 }
2471
2472 P = aCLProps.Value();
2473 Standard_Real Crv = aCLProps.Curvature();
2474
2475 if(Crv >= eps) {
2476 aCLProps.Tangent(N);
2477 Standard_Real x = N.Y(), y = -N.X();
2478 N.SetCoord(x, y);
2479 if (reverse) N.Reverse();
2480 aCLProps.CentreOfCurvature(Pc);
2481 gp_Vec2d Dir( P, Pc );
2482 if (N.Dot(Dir) > 0.) {
2483 if (LimCurv <= Crv + eps) {
2484 BadEdges.Append(SE);
2485 aMap.Add(SE);
2486 continue;
2487 }
2488 }
2489 }
2490
2491 aCLProps.SetParameter(l);
2492 if(!aCLProps.IsTangentDefined()) {
2493 BadEdges.Append(SE);
2494 aMap.Add(SE);
2495 continue;
2496 }
2497
2498 P = aCLProps.Value();
2499 Crv = aCLProps.Curvature();
2500
2501 if(Crv >= eps) {
2502 aCLProps.Tangent(N);
2503 Standard_Real x = N.Y(), y = -N.X();
2504 N.SetCoord(x, y);
2505 if (reverse) N.Reverse();
2506 aCLProps.CentreOfCurvature(Pc);
2507 gp_Vec2d Dir( P, Pc );
2508 if (N.Dot(Dir) > 0.) {
2509 if (LimCurv <= Crv + eps) {
2510 BadEdges.Append(SE);
2511 aMap.Add(SE);
2512 continue;
2513 }
2514 }
2515 }
2516 }
2517 }
2518 }
2519 }
2520}
2521
2522
2523//=======================================================================
2524//function : PerformCurve
2525//purpose :
2526//=======================================================================
2527
2528static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
2529 TColgp_SequenceOfPnt& Points,
2530 const Adaptor3d_Curve& C,
2531 const Standard_Real Deflection,
2532 const Standard_Real U1,
2533 const Standard_Real U2,
2534 const Standard_Real EPSILON,
2535 const Standard_Integer Nbmin)
2536{
2537 Standard_Real UU1 = Min(U1, U2);
2538 Standard_Real UU2 = Max(U1, U2);
2539
2540 gp_Pnt Pdeb, Pfin;
2541 gp_Vec Ddeb,Dfin;
2542 C.D1(UU1,Pdeb,Ddeb);
2543 Parameters.Append(UU1);
2544 Points.Append(Pdeb);
2545
2546 C.D1(UU2,Pfin,Dfin);
91bb31f3 2547
2548 const Standard_Real aDelta = UU2 - UU1;
2549 const Standard_Real aDist = Pdeb.Distance(Pfin);
2550
2551 if((aDelta/aDist) > 5.0e-14)
2552 {
2553 QuasiFleche(C,Deflection*Deflection,
2554 UU1,Pdeb,
2555 Ddeb,
2556 UU2,Pfin,
2557 Dfin,
2558 Nbmin,
2559 EPSILON*EPSILON,
2560 Parameters,Points);
2561 }
2562
7fd59977 2563 return Standard_True;
2564}
2565//=======================================================================
2566//function : QuasiFleche
2567//purpose :
2568//=======================================================================
2569
2570static void QuasiFleche(const Adaptor3d_Curve& C,
2571 const Standard_Real Deflection2,
2572 const Standard_Real Udeb,
2573 const gp_Pnt& Pdeb,
2574 const gp_Vec& Vdeb,
2575 const Standard_Real Ufin,
2576 const gp_Pnt& Pfin,
2577 const gp_Vec& Vfin,
2578 const Standard_Integer Nbmin,
2579 const Standard_Real Eps,
2580 TColStd_SequenceOfReal& Parameters,
2581 TColgp_SequenceOfPnt& Points)
2582{
2583 Standard_Integer Ptslength = Points.Length();
2584 Standard_Real Udelta = Ufin-Udeb;
2585 gp_Pnt Pdelta;
2586 gp_Vec Vdelta;
2587 if (Nbmin > 2) {
2588 Udelta /=(Nbmin-1);
2589 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2590 }
2591 else {
2592 Pdelta = Pfin;
2593 Vdelta = Vfin;
2594 }
2595
2596
2597 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2598 Standard_Real theFleche=0;
2599 Standard_Boolean flecheok = Standard_False;
2600 if (Norme > Eps) {
0d969553 2601 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
7fd59977 2602 Standard_Real N1 = Vdeb.SquareMagnitude();
2603 Standard_Real N2 = Vdelta.SquareMagnitude();
2604 if (N1 > Eps && N2 > Eps) {
2605 Standard_Real Normediff =
2606 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
2607 if (Normediff > Eps) {
2608 theFleche = Normediff*Norme/64.;
2609 flecheok = Standard_True;
2610 }
2611 }
2612 }
2613 if (!flecheok) {
2614 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2615 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2616 theFleche = Pmid.SquareDistance(Pverif);
2617 }
2618
2619 if (theFleche < Deflection2) {
2620 Parameters.Append(Udeb+Udelta);
2621 Points.Append(Pdelta);
2622 }
2623 else {
2624 QuasiFleche(C,Deflection2,Udeb,Pdeb,
2625 Vdeb,
2626 Udeb+Udelta,Pdelta,
2627 Vdelta,
2628 3,
2629 Eps,
2630 Parameters,Points);
2631
2632 }
2633
2634 if (Nbmin > 2) {
2635 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
2636 Vdelta,
2637 Ufin,Pfin,
2638 Vfin,
2639 Nbmin-(Points.Length()-Ptslength),
2640 Eps,
2641 Parameters,Points);
2642 }
2643}
ab87e6fc 2644