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