0023666: Wrong section curve between attached faces
[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);
302 if (Alt != 0.) {
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
778 Standard_Real ALT = Alt;
779 Handle(Geom_Plane) RefPlane =
780 Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(myWorkSpine));
781 if ( myWorkSpine.Orientation() == TopAbs_REVERSED) ALT = -Alt;
782 RefPlane = Handle(Geom_Plane)::DownCast
783 (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
784
785 //---------------------------------------------------------------
0d969553 786 // Construction of Circles and OffsetCurves
7fd59977 787 //---------------------------------------------------------------
6a442250 788
789 TopoDS_Vertex Ends [2];
790 if (myIsOpenResult)
791 {
792 TopoDS_Wire theWire;
793 TopoDS_Iterator iter(mySpine);
794 theWire = TopoDS::Wire(iter.Value());
795 TopExp::Vertices(theWire, Ends[0], Ends[1]);
796 }
873c119f 797
7fd59977 798 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
799 TopoDS_Shape PEE = Link.GeneratingShape(Locus.BasicElt(ic,Locus.NumberOfElts(ic)));
800 TopoDS_Shape& PE = PEE ;
801 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
802 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
803 if (SE.ShapeType() == TopAbs_VERTEX) {
0e0f7a7c 804 if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
805 MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
806 myWorkSpine,myOffset,myMap,RefPlane);
7fd59977 807 }
808 else {
873c119f 809 MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
c7806cb6 810 myIsOpenResult, myJoinType, Ends);
873c119f 811 PE = SE;
7fd59977 812 }
813 }
814 }
815
016dfb16 816 //Remove possible hanging arcs on vertices
817 if (myIsOpenResult && myJoinType == GeomAbs_Arc)
818 {
819 if (!myMap.IsEmpty() &&
820 myMap.FindKey(1).ShapeType() == TopAbs_VERTEX)
821 {
822 //myMap.RemoveFirst();
823 TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
824 TopTools_ListOfShape LastList;
825 LastList.Append(myMap(myMap.Extent()));
826 myMap.RemoveLast();
827 if (!myMap.IsEmpty())
828 myMap.Substitute(1, LastShape, LastList);
829 }
830 if (!myMap.IsEmpty() &&
831 myMap.FindKey(myMap.Extent()).ShapeType() == TopAbs_VERTEX)
832 myMap.RemoveLast();
833 }
7fd59977 834
873c119f 835#ifdef OCCT_DEBUG
1896126e 836#ifdef DRAW
7fd59977 837 if (AffichEdge) {
0d969553 838 cout << " End Construction of geometric primitives "<<endl;
7fd59977 839 }
840#endif
873c119f 841#endif
7fd59977 842
843
844 //---------------------------------------------------
0d969553 845 // Construction of offset vertices.
7fd59977 846 //---------------------------------------------------
847 BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
848 Handle(MAT_Arc) CurrentArc;
849 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
850 Handle(Geom_Curve) CBis;
851 Standard_Boolean Reverse;
852 TopoDS_Edge CurrentEdge;
853 TopoDS_Shape S [2];
854 TopoDS_Edge E [2];
855 TopLoc_Location L;
86b3805f 856 Standard_Integer j, k;
7fd59977 857
858 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
859
860 CurrentArc = Locus.Graph()->Arc(i);
861 Bisector_Bisec Bisec = Locus.GeomBis(CurrentArc,Reverse);
873c119f 862#ifdef OCCT_DEBUG
7fd59977 863#ifdef DRAW
873c119f 864
865 if ( AffichGeom) {
866 char name[256];
867 sprintf(name,"BISSEC_%d",NbBISSEC++);
868 DrawTrSurf::Set(name,Bisec.Value());
869 }
870#endif
7fd59977 871#endif
872
0d969553
Y
873 //-------------------------------------------------------------------
874 // Return elements of the spine corresponding to separate basicElts.
875 //-------------------------------------------------------------------
7fd59977 876 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
877 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
878
879 TopTools_SequenceOfShape Vertices;
880 TColgp_SequenceOfPnt Params;
873c119f 881
7fd59977 882 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
883 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
884
885 //-----------------------------------------------------------
0d969553
Y
886 // Return parallel edges on each face.
887 // If no offset generated => move to the next bissectrice.
7fd59977 888 //--------------------------------------------------------------
86b3805f
J
889 if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
890 E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
891 E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
7fd59977 892 }
893 else continue;
894
895 //-----------------------------------------------------------
0d969553
Y
896 // Construction of vertices corresponding to the node of the map.
897 // if they are on the offset.
7fd59977 898 //-----------------------------------------------------------
899 TopoDS_Vertex VS,VE;
900 Handle(MAT_Node) Node1, Node2;
901
902 if (Reverse) {
903 Node1 = CurrentArc->SecondNode();
904 Node2 = CurrentArc->FirstNode();
905 }
906 else {
907 Node1 = CurrentArc->FirstNode();
908 Node2 = CurrentArc->SecondNode();
909 }
873c119f 910
7fd59977 911 Standard_Boolean StartOnEdge = 0, EndOnEdge = 0;
873c119f 912
7fd59977 913 if (!Node1->Infinite()) {
914 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node1);
915 StartOnEdge = VertexFromNode(Node1, myOffset, aLocalPnt2d ,MapNodeVertex,VS);
873c119f 916 // StartOnEdge = VertexFromNode(Node1, myOffset, Locus.GeomElt(Node1),
917 // MapNodeVertex,VS);
7fd59977 918 }
919 if (!Node2->Infinite()) {
920 gp_Pnt2d aLocalPnt2d = Locus.GeomElt(Node2) ;
921 EndOnEdge = VertexFromNode(Node2, myOffset, aLocalPnt2d ,MapNodeVertex,VE);
873c119f 922 // EndOnEdge = VertexFromNode(Node2, myOffset, Locus.GeomElt(Node2),
923 // MapNodeVertex,VE);
7fd59977 924 }
925
9eb68d38 926 if (myJoinType == GeomAbs_Intersection)
927 StartOnEdge = EndOnEdge = 0;
928
7fd59977 929 //---------------------------------------------
0d969553 930 // Construction of geometries.
7fd59977 931 //---------------------------------------------
932 BRepFill_TrimEdgeTool Trim (Bisec,
873c119f 933 Locus.GeomElt(CurrentArc->FirstElement()),
934 Locus.GeomElt(CurrentArc->SecondElement()),
935 myOffset);
7fd59977 936
937 //-----------------------------------------------------------
0d969553 938 // Construction of vertices on edges parallel to the spine.
7fd59977 939 //-----------------------------------------------------------
940
46767247 941 Trim.IntersectWith(E[0], E[1], S[0], S[1], Ends[0], Ends[1],
942 myJoinType, myIsOpenResult, Params);
7fd59977 943
944 for (Standard_Integer s = 1; s <= Params.Length(); s++) {
945 TopoDS_Vertex VC;
946 myBuilder.MakeVertex (VC);
947 gp_Pnt2d P2 = Bisec.Value()->Value(Params.Value(s).X());
948 gp_Pnt PVC(P2.X(),P2.Y(),0.);
949
950 myBuilder.UpdateVertex(VC,PVC,Precision::Confusion());
951 Vertices.Append(VC);
952 }
953 if (StartOnEdge) {
954 Standard_Boolean Start = 1;
955 Trim.AddOrConfuse(Start, E[0], E[1], Params);
956 if (Params.Length() == Vertices.Length())
873c119f 957 Vertices.SetValue(1,VS);
7fd59977 958
959 else
873c119f 960 // the point was not found by IntersectWith
961 Vertices.Prepend(VS);
7fd59977 962 }
963 if (EndOnEdge) {
964 Standard_Boolean Start = 0;
965 Trim.AddOrConfuse(Start, E[0], E[1], Params);
966 if (Params.Length() == Vertices.Length())
873c119f 967 Vertices.SetValue(Params.Length(),VE);
7fd59977 968
969 else
873c119f 970 // the point was not found by IntersectWith
971 Vertices.Append(VE);
7fd59977 972 }
973
974 //------------------------------------------------------------
0d969553
Y
975 // Update Detromp.
976 // Detromp allows to remove vertices on the offset
977 // corresponding to tangency zones
978 // Detromp ranks the vertices that limit
979 // the parts of the bissectrices located between the spine and the
980 // offset.
7fd59977 981 //------------------------------------------------------------
982 if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
983 if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
984
985
c19dd45e 986 UpdateDetromp (Detromp, S[0], S[1], Vertices, Params,
873c119f 987 Bisec, StartOnEdge, EndOnEdge, Trim);
7fd59977 988 //----------------------------------------------
0d969553
Y
989 // Storage of vertices on parallel edges.
990 // fill MapBis and MapVerPar.
7fd59977 991 //----------------------------------------------
992 if (!Vertices.IsEmpty()) {
993 for (k = 0; k <= 1; k++) {
873c119f 994 if (!MapBis.IsBound(E[k])) {
995 MapBis .Bind(E[k],EmptySeq);
996 MapVerPar.Bind(E[k],EmptySeqOfReal);
997 }
998 for (Standard_Integer ii = 1; ii <= Vertices.Length(); ii++) {
999 MapBis (E[k]).Append(Vertices.Value(ii));
1000 if (k == 0) MapVerPar (E[k]).Append(Params.Value(ii).Y());
1001 else MapVerPar (E[k]).Append(Params.Value(ii).Z());
1002 }
7fd59977 1003 }
1004 }
1005 else {
1006 //------------------------------------------------------------
0d969553
Y
1007 // FOR COMPLETE CIRCLES. the parallel line can be contained
1008 // in the zone without intersection with the border
1009 // no intersection
1010 // if myoffset is < distance of nodes the parallel can be valid.
7fd59977 1011 //-------------------------------------------------------------
1012 for (k = 0; k <= 1; k++) {
873c119f 1013 if (!MapBis.IsBound(E[k])) {
1014 if (Node1->Distance() > myOffset && Node2->Distance() > myOffset) {
1015 MapBis .Bind(E[k],EmptySeq);
1016 MapVerPar.Bind(E[k],EmptySeqOfReal);
1017 }
1018 }
7fd59977 1019 }
1020 }
1021 }
873c119f 1022
1023#ifdef OCCT_DEBUG
1896126e 1024#ifdef DRAW
7fd59977 1025 if (AffichEdge) {
0d969553 1026 cout << " End Construction of vertices on offsets"<<endl;
7fd59977 1027 }
1028#endif
873c119f 1029#endif
7fd59977 1030
1031 //----------------------------------
0d969553 1032 // Construction of parallel edges.
7fd59977 1033 //----------------------------------
1034 TopTools_IndexedDataMapOfShapeShape MapVV;
1035
1036 TopoDS_Shape CurrentSpine;
1037
86b3805f 1038 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;
7fd59977 1039
86b3805f
J
1040 for (j = 1; j <= myMap.Extent(); j++) {
1041 CurrentSpine = myMap.FindKey(j);
1042 CurrentEdge = TopoDS::Edge(myMap(j).First());
7fd59977 1043
86b3805f 1044 myMap(j).Clear();
7fd59977 1045 if (MapBis.IsBound(CurrentEdge)) {
51740958 1046 TopTools_SequenceOfShape aSeqOfShape;
7fd59977 1047 if (!MapBis(CurrentEdge).IsEmpty()) {
6a442250 1048 Standard_Integer IndOfE = 0;
1049 if (myIsOpenResult)
1050 {
1051 if (j == 1)
1052 IndOfE = 1;
1053 else if (j == myMap.Extent())
1054 IndOfE = -1;
1055 }
873c119f 1056 TrimEdge (CurrentEdge,
1057 CurrentSpine,
1058 mySpine,
1059 Detromp (CurrentSpine),
1060 MapBis (CurrentEdge) ,
1061 MapVerPar(CurrentEdge) ,
51740958 1062 aSeqOfShape, MapVV, IndOfE);
1063 for ( k = 1; k <= aSeqOfShape.Length(); k++) {
1064 myMap(j).Append(aSeqOfShape.Value(k));
873c119f 1065 }
7fd59977 1066 }
1067 else {
873c119f 1068 //-----------------
1069 // Complete circles
1070 //-----------------
1071 myMap(j).Append(CurrentEdge);
7fd59977 1072 }
1073 }
1074 }
873c119f 1075
7fd59977 1076 Standard_Integer ind;
1077 for (ind = 1; ind <= MapVV.Extent(); ind++)
873c119f 1078 {
1079 TopoDS_Vertex OldV = TopoDS::Vertex(MapVV.FindKey(ind));
1080 TopoDS_Vertex NewV = TopoDS::Vertex(MapVV(ind));
1081 gp_Pnt P1 = BRep_Tool::Pnt(OldV);
1082 gp_Pnt P2 = BRep_Tool::Pnt(NewV);
1083 myBuilder.UpdateVertex(NewV, P1.Distance(P2));
1084 TopTools_ListOfShape LV;
1085 LV.Append( NewV.Oriented(TopAbs_FORWARD) );
1086 BRepTools_Substitution aSubst;
1087 aSubst.Substitute( OldV, LV );
1088 for (j = 1; j <= myMap.Extent(); j++)
7fd59977 1089 {
873c119f 1090 TopTools_ListIteratorOfListOfShape itl(myMap(j));
1091 for (; itl.More(); itl.Next())
1092 {
1093 aSubst.Build(itl.Value());
1094 if (aSubst.IsCopied(itl.Value()))
1095 {
1096 const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
1097 TopAbs_Orientation SaveOr = itl.Value().Orientation();
1098 itl.Value() = listSh.First();
1099 itl.Value().Orientation(SaveOr);
1100 }
1101 }
7fd59977 1102 }
873c119f 1103 }
7fd59977 1104
1105 //----------------------------------
0d969553 1106 // Construction of offset wires.
7fd59977 1107 //----------------------------------
1108 MakeWires ();
1109
0d969553 1110 // Update vertices ( Constructed in the plane Z = 0) !!!
7fd59977 1111 TopTools_MapOfShape MapVertex;
1112 for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
1113 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
1114 if ( MapVertex.Add(V)) {
1115 gp_Pnt P = BRep_Tool::Pnt(V);
1116 P = RefPlane->Value(P.X(),P.Y());
1117 myBuilder.UpdateVertex(V,P, Precision::Confusion());
1118 }
1119 }
1120
0d969553 1121 // Construction of curves 3d.
7fd59977 1122 BRepLib::BuildCurves3d(myShape);
1123 MapVertex.Clear();
1124 TopExp_Explorer Explo( myShape, TopAbs_EDGE );
1125 for (; Explo.More(); Explo.Next())
873c119f 1126 {
51740958 1127 TopoDS_Edge anEdge = TopoDS::Edge( Explo.Current() );
873c119f 1128 TopoDS_Vertex V1, V2;
51740958 1129 TopExp::Vertices(anEdge, V1, V2 );
873c119f 1130 Handle(BRep_TVertex)& TV1 = *((Handle(BRep_TVertex)*) &(V1).TShape());
1131 Handle(BRep_TVertex)& TV2 = *((Handle(BRep_TVertex)*) &(V2).TShape());
1132
1133 TopLoc_Location loc;
1134 Standard_Real f, l;
51740958 1135 Handle( Geom_Curve ) theCurve = BRep_Tool::Curve(anEdge, loc, f, l );
873c119f 1136 theCurve = Handle( Geom_Curve )::DownCast( theCurve->Copy() );
1137 theCurve->Transform( loc.Transformation() );
1138 gp_Pnt f3d = theCurve->Value( f );
1139 gp_Pnt l3d = theCurve->Value( l );
1140
1141 Standard_Real dist1, dist2;
1142 dist1 = f3d.Distance( TV1->Pnt() );
1143 dist2 = l3d.Distance( TV2->Pnt() );
1144 if (! MapVertex.Contains( V1 ))
7fd59977 1145 {
7fd59977 1146
873c119f 1147 TV1->Pnt( f3d );
1148 MapVertex.Add( V1 );
7fd59977 1149 }
873c119f 1150 else
1151 TV1->UpdateTolerance( 1.5*dist1 );
1152 if (! MapVertex.Contains( V2 ))
1153 {
1154 TV2->Pnt( l3d );
1155 MapVertex.Add( V2 );
1156 }
1157 else
1158 TV2->UpdateTolerance( 1.5*dist2 );
1159 }
7fd59977 1160
1867dc32 1161 if (!myIsOpenResult)
1162 FixHoles();
7fd59977 1163
1164 myIsDone = Standard_True;
1165}
1166
1167
1168//=======================================================================
1169//function : Generated
1170//purpose :
1171//=======================================================================
1172
86b3805f 1173BRepFill_IndexedDataMapOfOrientedShapeListOfShape&
873c119f 1174 BRepFill_OffsetWire::Generated()
7fd59977 1175{
1176 return myMap;
1177}
1178
1179
1180//=======================================================================
1181//function : PrepareSpine
1182//purpose :
1183//=======================================================================
1184
1185void BRepFill_OffsetWire::PrepareSpine()
1186{
1187 BRep_Builder B;
1188 TopTools_ListOfShape Cuts;
1189 TopTools_ListIteratorOfListOfShape IteCuts;
1190 TopoDS_Vertex V1,V2;
1191
1192 myWorkSpine.Nullify();
1193 myMapSpine.Clear();
1194
1195 TopLoc_Location L;
1196 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1197 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1198 B.MakeFace(myWorkSpine,S,L,TolF);
1199
1200 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1201
1202 TopoDS_Wire NW;
1203 B.MakeWire (NW);
1204
873c119f 1205 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:55 2000 Begin
7fd59977 1206 Standard_Integer ForcedCut = 0;
1207 Standard_Integer nbResEdges = -1;
1208 TopTools_IndexedMapOfShape EdgeMap;
1209
1210 TopExp::MapShapes(IteF.Value(), TopAbs_EDGE, EdgeMap);
1211 Standard_Integer nbEdges = EdgeMap.Extent();
1212
6a442250 1213 if (nbEdges == 1 && !myIsOpenResult) //in case of open wire there's no need to do it
7fd59977 1214 ForcedCut = 2;
873c119f 1215 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:48 2000 End
7fd59977 1216
1217 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1218
1219 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1220 EdgeVertices(E,V1,V2);
1221 myMapSpine.Bind(V1,V1);
1222 myMapSpine.Bind(V2,V2);
1223 Cuts.Clear();
1224
0d969553 1225 // Cut
7fd59977 1226 TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
873c119f 1227 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
7fd59977 1228 if (nbEdges == 2 && nbResEdges == 0)
873c119f 1229 ForcedCut = 1;
1230 // Modified by Sergey KHROMOV - Thu Nov 16 17:29:33 2000 End
7fd59977 1231 nbResEdges = CutEdge (TopoDS::Edge(aLocalShape), mySpine, ForcedCut, Cuts);
1232
1233 if (Cuts.IsEmpty()) {
873c119f 1234 B.Add(NW,E);
1235 myMapSpine.Bind(E,E);
7fd59977 1236 }
1237 else {
873c119f 1238 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1239 TopoDS_Edge NE = TopoDS::Edge(IteCuts.Value());
1240 NE.Orientation(E.Orientation());
1241 B.Add(NW,NE);
1242 myMapSpine.Bind(NE,E);
1243 EdgeVertices(NE,V1,V2);
1244 if (!myMapSpine.IsBound(V1)) myMapSpine.Bind(V1,E);
1245 if (!myMapSpine.IsBound(V2)) myMapSpine.Bind(V2,E);
1246 }
7fd59977 1247 }
1248 }
873c119f 1249 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:41 2002 Begin
7fd59977 1250 TopoDS_Vertex aV1;
1251 TopoDS_Vertex aV2;
1252
1253 TopExp::Vertices(NW, aV1, aV2);
1254
1255 NW.Closed(aV1.IsSame(aV2));
873c119f 1256
1257 // Modified by Sergey KHROMOV - Thu Mar 7 09:17:43 2002 End
7fd59977 1258 B.Add(myWorkSpine, NW);
1259 }
1260
873c119f 1261#ifdef OCCT_DEBUG
7fd59977 1262#ifdef DRAW
1263 if ( AffichEdge) {
1896126e 1264 DBRep::Set("WS",myWorkSpine);
873c119f 1265 DBRep::Set("MS",mySpine);
1266 BRepTools::Write(myWorkSpine, "WS");
1267 BRepTools::Write(mySpine, "MS");
7fd59977 1268 }
1269#endif
873c119f 1270#endif
7fd59977 1271
1272}
1273
1274//=======================================================================
c19dd45e 1275//function : UpdateDetromp
1276//purpose : For each interval on bissectrice defined by parameters
1277// test if the medium point is at a distance > offset
1278// in this case vertices corresponding to the extremities of the interval
1279// are ranked in the proofing.
1280// => If the same vertex appears in the proofing, the
1281// border of the zone of proximity is tangent to the offset .
1282//=======================================================================
1283
1284void BRepFill_OffsetWire::UpdateDetromp (BRepFill_DataMapOfOrientedShapeListOfShape& Detromp,
1285 const TopoDS_Shape& Shape1,
1286 const TopoDS_Shape& Shape2,
1287 const TopTools_SequenceOfShape& Vertices,
1288 const TColgp_SequenceOfPnt& Params,
1289 const Bisector_Bisec& Bisec,
1290 const Standard_Boolean SOnE,
1291 const Standard_Boolean EOnE,
1292 const BRepFill_TrimEdgeTool& Trim) const
1293{
c19dd45e 1294 Standard_Integer ii = 1;
c19dd45e 1295
46767247 1296 if (myJoinType == GeomAbs_Intersection)
1297 {
1298 for (; ii <= Vertices.Length(); ii++)
1299 {
1300 const TopoDS_Vertex& aVertex = TopoDS::Vertex(Vertices.Value(ii));
1301 Detromp(Shape1).Append(aVertex);
1302 Detromp(Shape2).Append(aVertex);
c19dd45e 1303 }
c19dd45e 1304 }
46767247 1305 else //myJoinType == GeomAbs_Arc
1306 {
1307 Standard_Real U1,U2;
1308 TopoDS_Vertex V1,V2;
1309
1310 const Handle(Geom2d_Curve)& Bis = Bisec.Value();
1311
1312 U1 = Bis->FirstParameter();
1313
1314 if (SOnE) {
1315 // the first point of the bissectrice is on the offset
1316 V1 = TopoDS::Vertex(Vertices.Value(ii));
1317 ii++;
1318 }
1319
1320 while (ii <= Vertices.Length()) {
1321 U2 = Params.Value(ii).X();
1322 V2 = TopoDS::Vertex(Vertices.Value(ii));
1323
1324 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1325 if (!Trim.IsInside(P)) {
873c119f 1326 if (!V1.IsNull()) {
1327 Detromp(Shape1).Append(V1);
1328 Detromp(Shape2).Append(V1);
1329 }
46767247 1330 Detromp(Shape1).Append(V2);
1331 Detromp(Shape2).Append(V2);
c19dd45e 1332 }
46767247 1333 U1 = U2;
1334 V1 = V2;
1335 ii ++;
c19dd45e 1336 }
46767247 1337
1338 // test medium point between the last parameter and the end of the bissectrice.
1339 U2 = Bis->LastParameter();
1340 if (!EOnE) {
1341 if (!Precision::IsInfinite(U2)) {
1342 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
1343 if (!Trim.IsInside(P)) {
1344 if (!V1.IsNull()) {
1345 Detromp(Shape1).Append(V1);
1346 Detromp(Shape2).Append(V1);
1347 }
1348 }
c19dd45e 1349 }
46767247 1350 else {
1351 if (!V1.IsNull()) {
1352 Detromp(Shape1).Append(V1);
1353 Detromp(Shape2).Append(V1);
1354 }
1355 }
1356 }
1357 //else if(myJoinType != GeomAbs_Arc)
1358 //{
1359 // if (!V1.IsNull()) {
1360 // Detromp(Shape1).Append(V1);
1361 // Detromp(Shape2).Append(V1);
1362 // }
1363 //}
1364 } //end of else (myJoinType==GeomAbs_Arc)
c19dd45e 1365}
1366
1367//=======================================================================
7fd59977 1368//function : MakeWires
1369//purpose :
1370//=======================================================================
1371
1372void BRepFill_OffsetWire::MakeWires()
1373{
1374 //--------------------------------------------------------
0d969553 1375 // creation of a single list of created parallel edges.
7fd59977 1376 //--------------------------------------------------------
1377 TopTools_SequenceOfShape TheEdges;
1378 TopTools_ListOfShape TheWires;
1379 TopTools_ListIteratorOfListOfShape itl;
86b3805f
J
1380 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1381 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1382 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
7fd59977 1383 TopoDS_Vertex V1,V2,VF,CV;
86b3805f 1384 Standard_Integer i;
7fd59977 1385
86b3805f
J
1386 for (i = 1; i <= myMap.Extent(); i++) {
1387 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
7fd59977 1388 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1389 TopExp::Vertices (E,V1,V2);
1390 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
873c119f 1391 continue; //remove small closed edges
7642e2d0 1392 if (!CheckSmallParamOnEdge(E))
1393 continue;
86b3805f 1394 if (!MVE.Contains(V1)) {
873c119f 1395 TopTools_ListOfShape empty;
1396 MVE.Add(V1,empty);
7fd59977 1397 }
86b3805f
J
1398 MVE.ChangeFromKey(V1).Append(E);
1399 if (!MVE.Contains(V2)) {
873c119f 1400 TopTools_ListOfShape empty;
1401 MVE.Add(V2,empty);
7fd59977 1402 }
86b3805f 1403 MVE.ChangeFromKey(V2).Append(E);
7fd59977 1404 }
1405 }
1406
1407 //--------------------------------------
0d969553 1408 // Creation of parallel wires.
7fd59977 1409 //--------------------------------------
1410 BRep_Builder B;
1411
873c119f 1412
1413 // Standard_Integer NbEdges;
1414 // Standard_Boolean NewWire = Standard_True;
1415 // Standard_Boolean AddEdge = Standard_False;
7fd59977 1416
1417 TopoDS_Wire NW;
1418 Standard_Boolean End;
1419 TopoDS_Edge CE;
1420
1421 while (!MVE.IsEmpty()) {
1422 B.MakeWire(NW);
1423
86b3805f
J
1424 //MVEit.Initialize(MVE);
1425 for (i = 1; i <= MVE.Extent(); i++)
1426 if(MVE(i).Extent() == 1)
1427 break;
7fd59977 1428
86b3805f
J
1429 //if(!MVEit.More()) MVEit.Initialize(MVE);
1430 if (i > MVE.Extent())
1431 i = 1;
7fd59977 1432
86b3805f
J
1433 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1434 CE = TopoDS::Edge(MVE(i).First());
7fd59977 1435 End = Standard_False;
1867dc32 1436 MVE.ChangeFromKey(CV).RemoveFirst();
1437
1438 if (myIsOpenResult && MVE.FindFromKey(CV).IsEmpty())
1439 {
1440 //MVE.UnBind(CV);
1441 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1442 TopTools_ListOfShape LastList;
1443 LastList.Append(MVE(MVE.Extent()));
1444 MVE.RemoveLast();
1445 if (MVE.FindIndex(CV) != 0)
1446 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1447 }
1448
7fd59977 1449
873c119f 1450 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
7fd59977 1451 Standard_Boolean isClosed = Standard_False;
873c119f 1452
1453 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
7fd59977 1454
1455 while(!End) {
1456 //-------------------------------
0d969553 1457 // Construction of a wire.
7fd59977 1458 //-------------------------------
1459 TopExp::Vertices(CE,V1,V2);
1460 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1461
1462 B.Add (NW,CE);
1463
86b3805f 1464 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
873c119f 1465 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1466 isClosed = VF.IsSame(CV);
1467 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1468 End = Standard_True;
1469 //MVE.UnBind(VF);
86b3805f
J
1470 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1471 TopTools_ListOfShape LastList;
1472 LastList.Append(MVE(MVE.Extent()));
1473 MVE.RemoveLast();
1474 if (MVE.FindIndex(VF) != 0)
1475 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
7fd59977 1476 }
1477
1478 if (!End) {
873c119f 1479 if (MVE.FindFromKey(CV).Extent() > 2) {
1480 //cout <<"vertex on more that 2 edges in a face."<<endl;
1481 }
1482 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1483 if (itl.Value().IsSame(CE)) {
1484 MVE.ChangeFromKey(CV).Remove(itl);
1485 break;
1486 }
1487 }
1488 if (!MVE.FindFromKey(CV).IsEmpty()) {
1489 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1490 MVE.ChangeFromKey(CV).RemoveFirst();
1491 }
1867dc32 1492 else if (myIsOpenResult)//CV was a vertex with one edge
1493 End = Standard_True;
1494
873c119f 1495 if (MVE.FindFromKey(CV).IsEmpty())
86b3805f
J
1496 {
1497 //MVE.UnBind(CV);
1498 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1499 TopTools_ListOfShape LastList;
1500 LastList.Append(MVE(MVE.Extent()));
1501 MVE.RemoveLast();
1502 if (MVE.FindIndex(CV) != 0)
1503 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1504 }
7fd59977 1505 }
1506 }
873c119f 1507 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1508 // NW.Closed(Standard_True);
7fd59977 1509 NW.Closed(isClosed);
873c119f 1510 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
7fd59977 1511 TheWires.Append(NW);
1512 }
1513
0d969553
Y
1514 // update myShape :
1515 // -- if only one wire : myShape is a Wire
1516 // -- if several wires : myShape is a Compound.
7fd59977 1517 if ( TheWires.Extent() == 1) {
1518 myShape = TheWires.First();
1519 }
1520 else {
1521 TopoDS_Compound R;
1522 B.MakeCompound(R);
1523 TopTools_ListIteratorOfListOfShape it(TheWires);
1524 for ( ; it.More(); it.Next()) {
1525 B.Add(R, it.Value());
1526 }
1527 myShape = R;
1528 }
1529
1530}
1531
1532//=======================================================================
1533//function : FixHoles
1534//purpose :
1535//=======================================================================
1536
1537void BRepFill_OffsetWire::FixHoles()
1538{
1539 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1540
1541 Standard_Real MaxTol = 0.;
7fd59977 1542 BRep_Builder BB;
1543
1544 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1545 for (; Explo.More(); Explo.Next())
91bb31f3 1546 {
1547 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1548 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1549 if (Tol > MaxTol)
1550 MaxTol = Tol;
1551 }
7fd59977 1552 MaxTol *= 100.;
1553
1554 Explo.Init( myShape, TopAbs_WIRE );
1555 for (; Explo.More(); Explo.Next())
91bb31f3 1556 {
1557 TopoDS_Shape aWire = Explo.Current();
1558 // Remove duplicated edges
1559 TopTools_DataMapOfShapeListOfShape EEmap;
1560 TopoDS_Iterator it( aWire );
1561 for (; it.More(); it.Next())
7fd59977 1562 {
91bb31f3 1563 const TopoDS_Shape& anEdge = it.Value();
1564 if (! EEmap.IsBound( anEdge ))
1565 {
1566 TopTools_ListOfShape LE;
1567 EEmap.Bind( anEdge, LE );
1568 }
7fd59977 1569 else
91bb31f3 1570 EEmap(anEdge).Append( anEdge );
7fd59977 1571 }
91bb31f3 1572 aWire.Free( Standard_True );
1573 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1574 for (; mapit.More(); mapit.Next())
1575 {
1576 const TopTools_ListOfShape& LE = mapit.Value();
1577 TopTools_ListIteratorOfListOfShape itl( LE );
1578 for (; itl.More(); itl.Next())
1579 BB.Remove( aWire, itl.Value() );
1580 }
1581 // Sorting
1582 if (aWire.Closed())
1583 ClosedWires.Append( aWire );
1584 else
1585 UnclosedWires.Append( aWire );
1586 }
1587
7fd59977 1588 while (!UnclosedWires.IsEmpty())
91bb31f3 1589 {
1590 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1591 TopoDS_Vertex Vf, Vl;
1592 TopExp::Vertices( Base, Vf, Vl );
1593 if(Vf.IsNull() || Vl.IsNull())
873c119f 1594 {
91bb31f3 1595 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
873c119f 1596#ifdef OCCT_DEBUG
1597 BRepTools::Write(Base, "Base");
1598#endif
1599 }
91bb31f3 1600 gp_Pnt Pf, Pl;
1601 Pf = BRep_Tool::Pnt(Vf);
1602 Pl = BRep_Tool::Pnt(Vl);
1603 Standard_Real DistF = RealLast(), DistL = RealLast();
1232a766 1604 Standard_Integer IndexF = 0, IndexL = 0;
91bb31f3 1605 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1606 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
7fd59977 1607 {
91bb31f3 1608 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1609 TopoDS_Vertex V1, V2;
1610 TopExp::Vertices( aWire, V1, V2 );
1611
1612 if(V1.IsNull() || V2.IsNull())
873c119f 1613 {
ab87e6fc 1614 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
873c119f 1615#ifdef OCCT_DEBUG
1616 BRepTools::Write(Base, "Base");
1617 char name[128];
1618 sprintf(name,"Wire_%d",i);
1619 BRepTools::Write(aWire, name);
1620#endif
1621 }
91bb31f3 1622
1623 gp_Pnt P1, P2;
1624 P1 = BRep_Tool::Pnt(V1);
1625 P2 = BRep_Tool::Pnt(V2);
1626 Standard_Real dist = Pf.Distance( P1 );
1627 if (dist < DistF)
1628 {
1629 DistF = dist;
1630 IndexF = i;
1631 IsFirstF = Standard_True;
1632 }
1633 dist = Pf.Distance( P2 );
1634 if (dist < DistF)
1635 {
1636 DistF = dist;
1637 IndexF = i;
1638 IsFirstF = Standard_False;
1639 }
1640 dist = Pl.Distance( P1 );
1641 if (dist < DistL)
1642 {
1643 DistL = dist;
1644 IndexL = i;
1645 IsFirstL = Standard_True;
1646 }
1647 dist = Pl.Distance( P2 );
1648 if (dist < DistL)
1649 {
1650 DistL = dist;
1651 IndexL = i;
1652 IsFirstL = Standard_False;
1653 }
1654 }
1232a766 1655 if (DistF > MaxTol)
1656 IndexF = 0;
1657 if (DistL > MaxTol)
1658 IndexL = 0;
91bb31f3 1659 TopoDS_Wire theWire;
1660 TopoDS_Edge theEdge;
1661 TopoDS_Vertex theVertex;
1662 Standard_Real CommonTol;
1663 Standard_Boolean TryToClose = Standard_True;
1664 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1665 {
1666 if (DistF < DistL)
1667 {
1668 DistL = RealLast();
1669 IndexL++;
1670 }
1671 else
1672 {
1673 DistF = RealLast();
1674 IndexF++;
1675 }
1676 TryToClose = Standard_False;
1677 }
1678 if (DistF <= MaxTol)
1679 {
1680 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1681 TopoDS_Vertex V1, V2;
1682 TopExp::Vertices( theWire, V1, V2 );
1683 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1684 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1685 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1686 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1687 TopoDS_Iterator it( theWire );
1688 for (; it.More(); it.Next())
1689 {
1690 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1691 if (IsFirstF) anEdge.Reverse();
1692 if (!anEdge.IsSame( theEdge ))
1693 BB.Add( Base, anEdge );
1694 }
1695 theVertex = (IsFirstF)? V1 : V2;
1696 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1697 if (DistF <= CommonTol)
1698 {
1699 theEdge.Free( Standard_True );
1700 Vf.Orientation( theVertex.Orientation() );
1701 BB.Remove( theEdge, theVertex );
1702 BB.Add( theEdge, Vf );
1703 BB.UpdateVertex( Vf, CommonTol );
1704 if (IsFirstF) theEdge.Reverse();
1705 BB.Add( Base, theEdge );
1706 }
1707 else
1708 {
1709 if (IsFirstF) theEdge.Reverse();
1710 BB.Add( Base, theEdge );
1711 // Creating new edge from theVertex to Vf
1712 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1713 BB.Add( Base, NewEdge );
1714 }
1715 }
1716 if (DistL <= MaxTol && IndexL != IndexF)
1717 {
1718 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1719 TopoDS_Vertex V1, V2;
1720 TopExp::Vertices( theWire, V1, V2 );
1721 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1722 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1723 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1724 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1725 TopoDS_Iterator it( theWire );
1726 for (; it.More(); it.Next())
1727 {
1728 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1729 if (!IsFirstL) anEdge.Reverse();
1730 if (!anEdge.IsSame( theEdge ))
1731 BB.Add( Base, anEdge );
1732 }
1733 theVertex = (IsFirstL)? V1 : V2;
1734 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1735 if (DistL <= CommonTol)
1736 {
1737 theEdge.Free( Standard_True );
1738 Vl.Orientation( theVertex.Orientation() );
1739 BB.Remove( theEdge, theVertex );
1740 BB.Add( theEdge, Vl );
1741 BB.UpdateVertex( Vl, CommonTol );
1742 if (!IsFirstL) theEdge.Reverse();
1743 BB.Add( Base, theEdge );
1744 }
1745 else
1746 {
1747 if (!IsFirstL) theEdge.Reverse();
1748 BB.Add( Base, theEdge );
1749 // Creating new edge from Vl to theVertex
1750 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1751 BB.Add( Base, NewEdge );
1752 }
1753 }
1754 // Check if it is possible to close resulting wire
1755 if (TryToClose)
1756 {
1757 TopExp::Vertices( Base, Vf, Vl );
1758 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1759 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1760 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1761 TopoDS_Edge Efirst, Elast;
1762 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1763 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
7fd59977 1764 Pf = BRep_Tool::Pnt(Vf);
1765 Pl = BRep_Tool::Pnt(Vl);
91bb31f3 1766 Standard_Real Dist = Pf.Distance(Pl);
1767 if (Dist <= CommonTol)
1768 {
1769 Elast.Free( Standard_True );
1770 Vf.Orientation( Vl.Orientation() );
1771 BB.Remove( Elast, Vl );
1772 BB.Add( Elast, Vf );
1773 BB.UpdateVertex( Vf, CommonTol );
1774 Base.Closed( Standard_True );
1775 }
1776 else if (Dist <= MaxTol)
1777 {
1778 // Creating new edge from Vl to Vf
1779 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1780 BB.Add( Base, NewEdge );
1781 Base.Closed( Standard_True );
1782 }
7fd59977 1783 }
91bb31f3 1784 // Updating sequences ClosedWires and UnclosedWires
1785 if (DistF <= MaxTol)
1786 UnclosedWires.Remove( IndexF );
1787 if (DistL <= MaxTol && IndexL != IndexF)
7fd59977 1788 {
91bb31f3 1789 if (DistF <= MaxTol && IndexL > IndexF)
1790 IndexL--;
1791 UnclosedWires.Remove( IndexL );
7fd59977 1792 }
91bb31f3 1793 if (Base.Closed())
7fd59977 1794 {
91bb31f3 1795 ClosedWires.Append( Base );
1796 UnclosedWires.Remove( 1 );
7fd59977 1797 }
91bb31f3 1798 else if (DistF > MaxTol && DistL > MaxTol)
1799 {
1800 IsolatedWires.Append( Base );
1801 UnclosedWires.Remove( 1 );
1802 }
1803 }
1804
1805 // Updating myShape
1806 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1807 {
1808 if (!ClosedWires.IsEmpty())
1809 myShape = ClosedWires.First();
1810 else
1811 myShape = IsolatedWires.First();
1812 }
1813 else
1814 {
1815 TopoDS_Compound R;
1816 BB.MakeCompound( R );
51740958 1817 Standard_Integer i;
91bb31f3 1818 for (i = 1; i <= ClosedWires.Length(); i++)
1819 BB.Add( R, ClosedWires(i) );
1820 for (i = 1; i <= IsolatedWires.Length(); i++)
1821 BB.Add( R, IsolatedWires(i) );
1822 myShape = R;
1823 }
7fd59977 1824}
1825
1826//=======================================================================
1827//function : CutEdge
0d969553
Y
1828//purpose : Cut edge at the extrema of curvatures and points of inflexion.
1829// So, closed circles are cut in two.
1830// If <Cuts> is empty, the edge is not modified.
1831// The first and the last vertex of the initial edge
1832// belong to the first and the last parts respectively.
7fd59977 1833//=======================================================================
1834Standard_Integer CutEdge (const TopoDS_Edge& E,
873c119f 1835 const TopoDS_Face& F,
1836 Standard_Integer ForceCut,
1837 TopTools_ListOfShape& Cuts)
7fd59977 1838{
1839 Cuts.Clear();
1840 MAT2d_CutCurve Cuter;
1841 TColGeom2d_SequenceOfCurve theCurves;
1842 Standard_Real f,l;
1843 Handle(Geom2d_Curve) C2d;
1844 Handle(Geom2d_TrimmedCurve) CT2d;
873c119f 1845 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
7fd59977 1846 Standard_Real aTol = BRep_Tool::Tolerance(E);
1847 Handle(Geom_Curve) aC;
873c119f 1848 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
7fd59977 1849
1850 TopoDS_Vertex V1,V2,VF,VL;
1851 TopExp::Vertices (E,V1,V2);
1852 BRep_Builder B;
1853
1854 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
873c119f 1855 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
7fd59977 1856 aC = BRep_Tool::Curve(E,f,l);
873c119f 1857 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
7fd59977 1858 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1859 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1860
1861 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
873c119f 1862 ( Abs(f-l) >= M_PI) ) {
1863 return 0;
7fd59977 1864 }
1865
1866 //-------------------------
0d969553 1867 // Cut curve.
7fd59977 1868 //-------------------------
1869 Cuter.Perform(CT2d);
1870
873c119f 1871 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
7fd59977 1872 if (ForceCut == 0) {
1873 if (Cuter.UnModified()) {
873c119f 1874 //-----------------------------
1875 // edge not modified => return.
1876 //-----------------------------
7fd59977 1877 return 0;
1878 } else {
1879 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
873c119f 1880 theCurves.Append(Cuter.Value(k));
7fd59977 1881 }
1882 } else if (ForceCut == 1) {
1883 if (Cuter.UnModified()) {
1884 CutCurve (CT2d, 2, theCurves);
1885 } else {
1886 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
873c119f 1887
1888 theCurves.Append(Cuter.Value(k));
7fd59977 1889 }
1890 } else if (ForceCut == 2) {
1891 if (Cuter.UnModified()) {
1892 CutCurve (CT2d, 3, theCurves);
1893 } else {
1894 if (Cuter.NbCurves() == 2) {
873c119f 1895
1896 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1897
1898 if (CC->LastParameter() > (l+f)/2.) {
1899 CutCurve (CC, 2, theCurves);
1900 theCurves.Append(Cuter.Value(2));
1901 } else {
1902 theCurves.Append(CC);
1903 CutCurve (Cuter.Value(2), 2, theCurves);
1904 }
7fd59977 1905 } else {
873c119f 1906 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1907 theCurves.Append(Cuter.Value(k));
7fd59977 1908 }
1909 }
1910 }
873c119f 1911
1912 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
7fd59977 1913
1914 //--------------------------------------
0d969553 1915 // Creation of cut edges.
7fd59977 1916 //--------------------------------------
1917 VF = V1;
1918
1919 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1920
1921 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1922
1923 if (k == theCurves.Length()) {VL = V2;}
1924 else {
873c119f 1925 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
7fd59977 1926 gp_Pnt P = aC->Value(CC->LastParameter());
1927
1928 VL = BRepLib_MakeVertex(P);
1929 B.UpdateVertex(VL, aTol);
873c119f 1930 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
7fd59977 1931 }
1932 TopoDS_Shape aLocalShape = E.EmptyCopied();
1933 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
873c119f 1934 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
7fd59977 1935 NE.Orientation(TopAbs_FORWARD);
1936 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1937 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1938 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1939 Cuts.Append(NE.Oriented(E.Orientation()));
1940 VF = VL;
1941 }
1942
1943 return theCurves.Length();
1944}
1945
1946// Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1947//=======================================================================
1948//function : CutCurve
1949//purpose :
1950//=======================================================================
1951
1952void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
873c119f 1953 const Standard_Integer nbParts,
1954 TColGeom2d_SequenceOfCurve& theCurves)
7fd59977 1955{
1956 Handle(Geom2d_TrimmedCurve) TrimC;
1957 Standard_Real UF,UL,UC;
1958 Standard_Real Step;
1959 gp_Pnt2d PF,PL,PC;
1960 Standard_Real PTol = Precision::PConfusion()*10;
1961 Standard_Real Tol = Precision::Confusion()*10;
1962 Standard_Boolean YaCut = Standard_False;
1963
1964 UF = C->FirstParameter();
1965 UL = C->LastParameter ();
1966 PF = C->Value(UF);
1967 PL = C->Value(UL);
1968
1969 Step = (UL - UF)/nbParts;
1970
1971 for (Standard_Integer i = 1; i < nbParts; i++) {
1972
1973 UC = UF + i*Step;
1974 PC = C->Value(UC);
1975
1976 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1977 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
873c119f 1978 continue;
7fd59977 1979
1980 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1981 theCurves.Append(TrimC);
1982 UF = UC;
1983 PF = PC;
1984 YaCut = Standard_True;
1985 }
1986 }
1987 if (YaCut) {
1988 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1989 theCurves.Append(TrimC);
1990 } else
1991 theCurves.Append(C);
1992}
1993// Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
1994
1995//=======================================================================
1996//function : MakeCircle
1997//purpose :
1998//=======================================================================
1999
2000void MakeCircle (const TopoDS_Edge& E,
873c119f 2001 const TopoDS_Vertex& V,
2002 const TopoDS_Face& F,
2003 const Standard_Real Offset,
2004 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
2005 const Handle(Geom_Plane)& RefPlane)
7fd59977 2006{
0d969553 2007 // evaluate the Axis of the Circle.
7fd59977 2008 Standard_Real f,l;
2009 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
2010 gp_Vec2d DX;
2011 gp_Pnt2d P;
2012
2013 if (E.Orientation() == TopAbs_FORWARD) {
2014 GC->D1(l,P,DX);
2015 DX.Reverse();
2016 }
2017 else GC->D1(f,P,DX);
2018
2019 gp_Ax2d Axis(P,gp_Dir2d(DX));
2020 Handle(Geom2d_Circle) Circ
2021 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
2022
2023 // Bind the edges in my Map.
2024 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
2025 TopTools_ListOfShape LL;
2026
2027 LL.Append(OE);
86b3805f 2028 Map.Add(V,LL);
7fd59977 2029
873c119f 2030#ifdef OCCT_DEBUG
7fd59977 2031#ifdef DRAW
2032 if ( AffichGeom && !OE.IsNull()) {
1896126e 2033 char name[256];
7fd59977 2034 sprintf(name,"OFFSET_%d",++NbOFFSET);
2035 DBRep::Set(name,OE);
2036 }
2037#endif
873c119f 2038#endif
7fd59977 2039}
2040
2041//=======================================================================
2042//function : MakeOffset
2043//purpose :
2044//=======================================================================
2045
2046void MakeOffset (const TopoDS_Edge& E,
873c119f 2047 const TopoDS_Face& F,
2048 const Standard_Real Offset,
2049 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
2050 const Handle(Geom_Plane)& RefPlane,
2051 const Standard_Boolean IsOpenResult,
c7806cb6 2052 const GeomAbs_JoinType theJoinType,
873c119f 2053 const TopoDS_Vertex * Ends)
7fd59977 2054{
2055 Standard_Real f,l;
2056 Standard_Real anOffset = Offset;
2057
2058 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
2059
2060 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2061 Handle(Geom2d_Curve) G2dOC;
2062
6a442250 2063 Standard_Boolean ToExtendFirstPar = Standard_True;
2064 Standard_Boolean ToExtendLastPar = Standard_True;
2065 if (IsOpenResult)
2066 {
2067 TopoDS_Vertex V1, V2;
2068 TopExp::Vertices(E, V1, V2);
2069 if (V1.IsSame(Ends[0]) ||
873c119f 2070 V1.IsSame(Ends[1]))
6a442250 2071 ToExtendFirstPar = Standard_False;
2072 if (V2.IsSame(Ends[0]) ||
873c119f 2073 V2.IsSame(Ends[1]))
6a442250 2074 ToExtendLastPar = Standard_False;
2075 }
2076
7fd59977 2077 Geom2dAdaptor_Curve AC(G2d,f,l);
2078 if ( AC.GetType() == GeomAbs_Circle) {
0d969553
Y
2079 // if the offset is greater otr equal to the radius and the side of the
2080 // concavity of the circle => edge null.
7fd59977 2081 gp_Circ2d C1(AC.Circle());
7fd59977 2082 gp_Ax22d axes( C1.Axis());
2083 gp_Dir2d Xd = axes.XDirection();
2084 gp_Dir2d Yd = axes.YDirection();
2085 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
2086 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
2087
9ffd84ad 2088 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
0d969553 2089
7fd59977 2090 Handle(Geom2dAdaptor_HCurve) AHC =
873c119f 2091 new Geom2dAdaptor_HCurve(G2d);
5201d3e6 2092 Adaptor2d_OffsetCurve Off(AHC,-anOffset);
7fd59977 2093 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
2094
c6541a0c 2095 Standard_Real Delta = 2*M_PI - l + f;
c7806cb6 2096 if (theJoinType == GeomAbs_Arc)
2097 {
873c119f 2098 if (ToExtendFirstPar)
2099 f -= 0.2*Delta;
2100 if (ToExtendLastPar)
2101 l += 0.2*Delta;
c7806cb6 2102 }
2103 else //GeomAbs_Intersection
2104 {
2105 if (ToExtendFirstPar && ToExtendLastPar)
2106 {
2107 Standard_Real old_l = l;
2108 f = old_l + Delta/2.;
2109 l = f + 2*M_PI;
2110 }
2111 else if (ToExtendFirstPar)
2112 {
2113 f = l;
2114 l = f + 2*M_PI;
2115 }
2116 else if (ToExtendLastPar)
2117 {
2118 l = f + 2*M_PI;
2119 }
2120 }
7fd59977 2121 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2122 }
2123 }
2124 else if (AC.GetType() == GeomAbs_Line) {
2125 Handle(Geom2dAdaptor_HCurve) AHC =
2126 new Geom2dAdaptor_HCurve(G2d);
5201d3e6 2127 Adaptor2d_OffsetCurve Off(AHC,anOffset);
7fd59977 2128 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2129 Standard_Real Delta = (l - f);
6a442250 2130 if (ToExtendFirstPar)
c7806cb6 2131 {
2132 if (theJoinType == GeomAbs_Arc)
873c119f 2133 f -= Delta;
c7806cb6 2134 else //GeomAbs_Intersection
2135 f = -Precision::Infinite();
2136 }
6a442250 2137 if (ToExtendLastPar)
c7806cb6 2138 {
2139 if (theJoinType == GeomAbs_Arc)
873c119f 2140 l += Delta;
c7806cb6 2141 else //GeomAbs_Intersection
2142 l = Precision::Infinite();
2143 }
7fd59977 2144 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2145 }
2146 else {
2147
2148 anOffset = -anOffset;
2149 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2150 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2151
2152 }
2153
2154 // Bind the edges in my Map.
2155 if (!G2dOC.IsNull()) {
2156 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2157 OE.Orientation(E.Orientation());
2158 TopTools_ListOfShape LL;
2159 LL.Append(OE);
86b3805f 2160 Map.Add(E,LL);
7fd59977 2161
873c119f 2162#ifdef OCCT_DEBUG
7fd59977 2163#ifdef DRAW
2164 if (AffichGeom && !OE.IsNull()) {
1896126e 2165 char name[256];
7fd59977 2166 sprintf(name,"OFFSET_%d",++NbOFFSET);
2167 DBRep::Set(name,OE);
873c119f 2168 //Standard_Real ii = 0;
7fd59977 2169 }
2170#endif
873c119f 2171#endif
2172
7fd59977 2173 }
2174}
2175
7fd59977 2176
2177//=======================================================================
2178//function : VertexFromNode
2179//purpose :
2180//=======================================================================
2181
2182Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
873c119f 2183 const Standard_Real Offset,
2184 gp_Pnt2d& PN,
2185 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2186 TopoDS_Vertex& VN)
7fd59977 2187{
2188 Standard_Boolean Status;
2189 Standard_Real Tol = Precision::Confusion();
2190 BRep_Builder B;
2191
2192 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2193 //------------------------------------------------
0d969553 2194 // the Node gives a vertex on the offset
7fd59977 2195 //------------------------------------------------
2196 if (MapNodeVertex.IsBound(aNode)) {
2197 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2198 }
2199 else {
2200 gp_Pnt P(PN.X(),PN.Y(),0.);
2201 B.MakeVertex (VN);
2202 B.UpdateVertex(VN,P, Precision::Confusion());
2203 MapNodeVertex.Bind(aNode,VN);
2204 }
2205 Status = Standard_True;
2206 }
2207 else Status = Standard_False;
2208
2209 return Status;
2210}
2211
2212
2213//=======================================================================
2214//function : StoreInMap
2215//purpose :
2216//=======================================================================
2217
2218void StoreInMap (const TopoDS_Shape& V1,
873c119f 2219 const TopoDS_Shape& V2,
2220 TopTools_IndexedDataMapOfShapeShape& MapVV)
7fd59977 2221{
2222 TopoDS_Shape OldV = V1, NewV = V2;
2223 Standard_Integer i;
2224
2225 if (MapVV.Contains(V2))
2226 NewV = MapVV.FindFromKey(V2);
2227
2228 if (MapVV.Contains(V1))
2229 MapVV.ChangeFromKey(V1) = NewV;
2230
2231 for (i = 1; i <= MapVV.Extent(); i++)
2232 if (MapVV(i).IsSame(V1))
2233 MapVV(i) = NewV;
2234
2235 MapVV.Add(V1, NewV);
2236}
2237
2238//=======================================================================
2239//function : TrimEdge
2240//purpose :
2241//=======================================================================
2242
2243void TrimEdge (const TopoDS_Edge& E,
e11c1bc4 2244 const TopoDS_Shape& ProE,
2245 const TopoDS_Face& AllSpine,
7fd59977 2246 const TopTools_ListOfShape& Detromp,
6a442250 2247 TopTools_SequenceOfShape& TheVer,
2248 TColStd_SequenceOfReal& ThePar,
2249 TopTools_SequenceOfShape& S,
2250 TopTools_IndexedDataMapOfShapeShape& MapVV,
2251 const Standard_Integer IndOfE)
7fd59977 2252{
2253 Standard_Boolean Change = Standard_True;
2254 BRep_Builder TheBuilder;
2255 S.Clear();
2256
2257 //-----------------------------------------------------------
0d969553 2258 // Parse two sequences depending on the parameter on the edge.
7fd59977 2259 //-----------------------------------------------------------
2260 while (Change) {
2261 Change = Standard_False;
2262 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2263 if (ThePar.Value(i) > ThePar.Value(i+1)) {
873c119f 2264 ThePar.Exchange(i,i+1);
2265 TheVer.Exchange(i,i+1);
2266 Change = Standard_True;
7fd59977 2267 }
2268 }
2269 }
2270
2271 //----------------------------------------------------------
0d969553 2272 // If a vertex is not in the proofing, it is eliminated.
7fd59977 2273 //----------------------------------------------------------
2274 if (!BRep_Tool::Degenerated(E)) {
2275 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2276 if ( DoubleOrNotInside (Detromp,
873c119f 2277 TopoDS::Vertex(TheVer.Value(k)))) {
2278 TheVer.Remove(k);
2279 ThePar.Remove(k);
2280 k--;
7fd59977 2281 }
2282 }
2283 }
2284
2285 //----------------------------------------------------------
0d969553
Y
2286 // If a vertex_double appears twice in the proofing
2287 // the vertex is removed.
2288 // otherwise preserve only one of its representations.
7fd59977 2289 //----------------------------------------------------------
2290 if (!BRep_Tool::Degenerated(E)) {
94f71cad 2291 Standard_Real aParTol = 2.0 * Precision::PConfusion();
7fd59977 2292 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2293 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
94f71cad 2294 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= aParTol) {
873c119f 2295
2296 if(k+1 == TheVer.Length()) {
2297 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2298 TheVer.Remove(k);
2299 ThePar.Remove(k);
2300 }
2301 else {
2302 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2303 TheVer.Remove(k+1);
2304 ThePar.Remove(k+1);
2305 }
2306 /*
2307 if ( DoubleOrNotInside (Detromp,
2308 TopoDS::Vertex(TheVer.Value(k)))) {
2309 TheVer.Remove(k);
2310 ThePar.Remove(k);
2311 k--;
2312 }
2313 */
2314 k--;
7fd59977 2315 }
2316 }
2317 }
2318 //-----------------------------------------------------------
0d969553
Y
2319 // Creation of edges.
2320 // the number of vertices should be even. The created edges
2321 // go from a vertex with uneven index i to vertex i+1;
7fd59977 2322 //-----------------------------------------------------------
6a442250 2323 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2324 {
7fd59977 2325 TopoDS_Shape aLocalShape = E.EmptyCopied();
2326 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
6a442250 2327 TopoDS_Vertex V1, V2;
2328 TopExp::Vertices(E, V1, V2);
2329 Standard_Real fpar, lpar;
e11c1bc4 2330 Handle(Geom_Surface) aPlane;
2331 TopLoc_Location aLoc;
2332 Handle(Geom2d_Curve) PCurve;
2333 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2334 //BRep_Tool::Range(E, fpar, lpar);
2335
2336 Standard_Real TrPar1, TrPar2;
2337 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2338
6a442250 2339 if (IndOfE == 1) //first edge of open wire
2340 {
2341 if (NewEdge.Orientation() == TopAbs_FORWARD)
2342 {
e11c1bc4 2343 if (ToTrimAsOrigin)
2344 {
2345 fpar = TrPar1;
2346 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2347 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2348 V1 = BRepLib_MakeVertex(TrPnt);
2349 }
6a442250 2350 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2351 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2352 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2353 }
2354 else
2355 {
e11c1bc4 2356 if (ToTrimAsOrigin)
2357 {
2358 lpar = TrPar2;
2359 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2360 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2361 V2 = BRepLib_MakeVertex(TrPnt);
2362 }
6a442250 2363 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2364 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2365 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2366 }
7fd59977 2367 }
6a442250 2368 else //last edge of open wire
2369 {
2370 if (NewEdge.Orientation() == TopAbs_FORWARD)
2371 {
e11c1bc4 2372 if (ToTrimAsOrigin)
2373 {
2374 lpar = TrPar2;
2375 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2376 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2377 V2 = BRepLib_MakeVertex(TrPnt);
2378 }
6a442250 2379 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2380 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2381 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2382 }
2383 else
2384 {
e11c1bc4 2385 if (ToTrimAsOrigin)
2386 {
2387 fpar = TrPar1;
2388 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2389 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2390 V1 = BRepLib_MakeVertex(TrPnt);
2391 }
6a442250 2392 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2393 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2394 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2395 }
7fd59977 2396 }
6a442250 2397 S.Append(NewEdge);
2398 }
2399 else
2400 {
2401 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2402 TopoDS_Shape aLocalShape = E.EmptyCopied();
2403 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2404 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2405
2406 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2407 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2408 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2409 }
2410 else {
2411 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2412 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2413 }
2414
2415
2416 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2417
873c119f 2418#ifdef OCCT_DEBUG
7fd59977 2419#ifdef DRAW
6a442250 2420 if ( AffichEdge) {
2421 char name[256];
2422 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2423 DBRep::Set(name,NewEdge);
2424 }
2425 if (Affich2d) {
2426 TopLoc_Location L;
2427 Standard_Real f,l;
2428 Handle(Geom_Surface) Surf;
2429 Handle(Geom2d_Curve) C;
2430 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2431 char name[256];
2432 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2433 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2434 Handle(DrawTrSurf_Curve2d) dr =
2435 new DrawTrSurf_Curve2d(C2d,Standard_False);
2436 dr->SetColor(Draw_bleu);
2437 Draw::Set(name,dr);
2438 }
7fd59977 2439#endif
873c119f 2440#endif
6a442250 2441 S.Append(NewEdge);
2442 }
7fd59977 2443 }
2444}
2445
2446//=======================================================================
e11c1bc4 2447//function : IsInnerEdge
2448//purpose :
2449//=======================================================================
2450
2451static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2452 const TopoDS_Face& AllSpine,
2453 Standard_Real& TrPar1,
2454 Standard_Real& TrPar2)
2455{
2456 if (ProE.ShapeType() != TopAbs_EDGE)
2457 return Standard_False;
2458
2459 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2460
2461 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2462 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2463 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2464 {
2465 const TopTools_ListOfShape& LE = VEmap(i);
2466 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2467 return Standard_False;
2468 }
2469
2470 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2471 return Standard_True;
2472}
2473
2474
2475
2476//=======================================================================
7fd59977 2477//function : DoubleOrNotInside
0d969553 2478//purpose : return True if V appears twice in LV or is not inside.
7fd59977 2479//=======================================================================
2480
2481Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
873c119f 2482 const TopoDS_Vertex& V)
7fd59977 2483{
2484 Standard_Boolean Vu = Standard_False;
2485 TopTools_ListIteratorOfListOfShape it(LV);
2486
2487 for ( ; it.More(); it.Next()) {
2488 if (V.IsSame(it.Value())) {
2489 if (Vu) return Standard_True;
2490 else Vu = Standard_True;
2491 }
2492 }
2493 if (Vu) return Standard_False;
2494 else return Standard_True;
2495}
2496
2497Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
873c119f 2498 const TopoDS_Vertex& aVertex)
7fd59977 2499{
2500 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2501 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2502 PV2d.SetCoord( PV.X(), PV.Y() );
2503
2504 Handle(Geom2d_Curve) PCurve;
2505 Handle( BRep_CurveRepresentation ) CurveRep =
2506 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2507 PCurve = CurveRep->PCurve();
2508
2509 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2510 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2511 Pfirst = PCurve->Value(fpar);
2512 Plast = PCurve->Value(lpar);
2513 Pmid = PCurve->Value((fpar + lpar)*0.5);
2514
2515 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2516 theTol *= 1.5;
2517
2518 Standard_Real dist1 = Pfirst.Distance(PV2d);
2519 Standard_Real dist2 = Plast.Distance(PV2d);
2520 Standard_Real dist3 = Pmid.Distance(PV2d);
2521
2522 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2523 return Standard_True;
2524
2525 return Standard_False;
2526}
2527
2528static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
873c119f 2529 const BRepMAT2d_BisectingLocus& Locus,
2530 const BRepMAT2d_LinkTopoBilo& Link,
2531 TopTools_ListOfShape& BadEdges)
7fd59977 2532{
2533
2534 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2535 Standard_Real eps = Precision::Confusion();
2536 Standard_Real LimCurv = 1./Offset;
2537
2538 TopTools_MapOfShape aMap;
2539
2540 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2541 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2542 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2543 if (SE.ShapeType() == TopAbs_EDGE) {
2544
873c119f 2545
2546 if (aMap.Contains(SE)) {
2547 //cout << "Edge is treated second time" << endl;
2548 continue;
2549 }
2550
2551
2552 TopoDS_Edge E = TopoDS::Edge(SE);
2553
2554
2555 Standard_Real f,l;
2556
2557
2558 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2559
2560
2561 Geom2dAdaptor_Curve AC(G2d,f,l);
2562 GeomAbs_CurveType aCType = AC.GetType();
2563
2564
2565 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2566
2567
2568 Standard_Boolean reverse = Standard_False;
2569 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2570
2571
2572 gp_Pnt2d P, Pc;
2573 gp_Dir2d N;
2574
2575
2576 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2577
2578
2579 aCLProps.SetParameter(f);
2580 if(!aCLProps.IsTangentDefined()) {
2581 BadEdges.Append(SE);
2582 aMap.Add(SE);
2583 continue;
2584 }
2585
2586
2587 P = aCLProps.Value();
2588 Standard_Real Crv = aCLProps.Curvature();
2589
2590
2591 if(Crv >= eps) {
2592 aCLProps.Tangent(N);
2593 Standard_Real x = N.Y(), y = -N.X();
2594 N.SetCoord(x, y);
2595 if (reverse) N.Reverse();
2596 aCLProps.CentreOfCurvature(Pc);
2597 gp_Vec2d Dir( P, Pc );
2598 if (N.Dot(Dir) > 0.) {
2599 if (LimCurv <= Crv + eps) {
2600 BadEdges.Append(SE);
2601 aMap.Add(SE);
2602 continue;
2603 }
2604 }
2605 }
2606
2607
2608 aCLProps.SetParameter(l);
2609 if(!aCLProps.IsTangentDefined()) {
2610 BadEdges.Append(SE);
2611 aMap.Add(SE);
2612 continue;
2613 }
2614
2615
2616 P = aCLProps.Value();
2617 Crv = aCLProps.Curvature();
2618
2619
2620 if(Crv >= eps) {
2621 aCLProps.Tangent(N);
2622 Standard_Real x = N.Y(), y = -N.X();
2623 N.SetCoord(x, y);
2624 if (reverse) N.Reverse();
2625 aCLProps.CentreOfCurvature(Pc);
2626 gp_Vec2d Dir( P, Pc );
2627 if (N.Dot(Dir) > 0.) {
2628 if (LimCurv <= Crv + eps) {
2629 BadEdges.Append(SE);
2630 aMap.Add(SE);
2631 continue;
2632 }
2633 }
2634 }
2635 }
7fd59977 2636 }
2637 }
2638 }
2639}
2640
2641
2642//=======================================================================
2643//function : PerformCurve
2644//purpose :
2645//=======================================================================
2646
2647static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
873c119f 2648
2649 TColgp_SequenceOfPnt& Points,
2650 const Adaptor3d_Curve& C,
2651 const Standard_Real Deflection,
2652 const Standard_Real U1,
2653 const Standard_Real U2,
2654 const Standard_Real EPSILON,
2655 const Standard_Integer Nbmin)
7fd59977 2656{
2657 Standard_Real UU1 = Min(U1, U2);
2658 Standard_Real UU2 = Max(U1, U2);
2659
2660 gp_Pnt Pdeb, Pfin;
2661 gp_Vec Ddeb,Dfin;
2662 C.D1(UU1,Pdeb,Ddeb);
2663 Parameters.Append(UU1);
2664 Points.Append(Pdeb);
2665
2666 C.D1(UU2,Pfin,Dfin);
91bb31f3 2667
2668 const Standard_Real aDelta = UU2 - UU1;
2669 const Standard_Real aDist = Pdeb.Distance(Pfin);
2670
2671 if((aDelta/aDist) > 5.0e-14)
2672 {
2673 QuasiFleche(C,Deflection*Deflection,
873c119f 2674
2675 UU1,Pdeb,
2676 Ddeb,
2677 UU2,Pfin,
2678 Dfin,
2679 Nbmin,
2680 EPSILON*EPSILON,
2681 Parameters,Points);
91bb31f3 2682 }
2683
7fd59977 2684 return Standard_True;
2685}
2686//=======================================================================
2687//function : QuasiFleche
2688//purpose :
2689//=======================================================================
2690
2691static void QuasiFleche(const Adaptor3d_Curve& C,
873c119f 2692
2693 const Standard_Real Deflection2,
2694 const Standard_Real Udeb,
2695 const gp_Pnt& Pdeb,
2696 const gp_Vec& Vdeb,
2697 const Standard_Real Ufin,
2698 const gp_Pnt& Pfin,
2699 const gp_Vec& Vfin,
2700 const Standard_Integer Nbmin,
2701 const Standard_Real Eps,
2702 TColStd_SequenceOfReal& Parameters,
2703 TColgp_SequenceOfPnt& Points)
7fd59977 2704{
2705 Standard_Integer Ptslength = Points.Length();
2706 Standard_Real Udelta = Ufin-Udeb;
2707 gp_Pnt Pdelta;
2708 gp_Vec Vdelta;
2709 if (Nbmin > 2) {
2710 Udelta /=(Nbmin-1);
2711 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2712 }
2713 else {
2714 Pdelta = Pfin;
2715 Vdelta = Vfin;
2716 }
2717
2718
2719 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2720 Standard_Real theFleche=0;
2721 Standard_Boolean flecheok = Standard_False;
2722 if (Norme > Eps) {
0d969553 2723 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
7fd59977 2724 Standard_Real N1 = Vdeb.SquareMagnitude();
2725 Standard_Real N2 = Vdelta.SquareMagnitude();
2726 if (N1 > Eps && N2 > Eps) {
2727 Standard_Real Normediff =
873c119f 2728
2729 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
7fd59977 2730 if (Normediff > Eps) {
873c119f 2731
2732 theFleche = Normediff*Norme/64.;
2733 flecheok = Standard_True;
7fd59977 2734 }
2735 }
2736 }
2737 if (!flecheok) {
2738 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2739 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2740 theFleche = Pmid.SquareDistance(Pverif);
2741 }
2742
2743 if (theFleche < Deflection2) {
2744 Parameters.Append(Udeb+Udelta);
2745 Points.Append(Pdelta);
2746 }
2747 else {
2748 QuasiFleche(C,Deflection2,Udeb,Pdeb,
873c119f 2749
2750 Vdeb,
2751 Udeb+Udelta,Pdelta,
2752 Vdelta,
2753 3,
2754 Eps,
2755 Parameters,Points);
7fd59977 2756
2757 }
2758
2759 if (Nbmin > 2) {
2760 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
873c119f 2761
2762 Vdelta,
2763 Ufin,Pfin,
2764 Vfin,
2765 Nbmin-(Points.Length()-Ptslength),
2766 Eps,
2767 Parameters,Points);
7fd59977 2768 }
2769}
ab87e6fc 2770
7642e2d0 2771Standard_Boolean CheckSmallParamOnEdge(const TopoDS_Edge& anEdge)
2772{
2773 const BRep_ListOfCurveRepresentation& aList = ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves());
2774 if (!aList.IsEmpty())
2775 {
2776 Handle( BRep_CurveRepresentation ) CRep = ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2777 Standard_Real f = (Handle(BRep_GCurve)::DownCast(CRep))->First();
2778 Standard_Real l = (Handle(BRep_GCurve)::DownCast(CRep))->Last();
2779 if (Abs (l - f) < Precision::PConfusion())
2780 return Standard_False;
2781 }
2782 return Standard_True;
2783}
2784
2785