0028389: Data Exchange - Import of STEP Saved Views and Clipping Planes
[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();
c65f8201 1313 Standard_Boolean ForceAdd = Standard_False;
1314 Handle(Geom2d_TrimmedCurve) aTC = Handle(Geom2d_TrimmedCurve)::DownCast(Bis);
1315 if(!aTC.IsNull() && aTC->BasisCurve()->IsPeriodic())
1316 {
1317 gp_Pnt2d Pf = Bis->Value(Bis->FirstParameter());
1318 gp_Pnt2d Pl = Bis->Value(Bis->LastParameter());
1319 ForceAdd = Pf.Distance(Pl) <= Precision::Confusion();
1320 }
1321
46767247 1322 U1 = Bis->FirstParameter();
1323
1324 if (SOnE) {
1325 // the first point of the bissectrice is on the offset
1326 V1 = TopoDS::Vertex(Vertices.Value(ii));
1327 ii++;
1328 }
1329
1330 while (ii <= Vertices.Length()) {
1331 U2 = Params.Value(ii).X();
1332 V2 = TopoDS::Vertex(Vertices.Value(ii));
1333
1334 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
c65f8201 1335 if (!Trim.IsInside(P) || ForceAdd) {
873c119f 1336 if (!V1.IsNull()) {
1337 Detromp(Shape1).Append(V1);
1338 Detromp(Shape2).Append(V1);
1339 }
46767247 1340 Detromp(Shape1).Append(V2);
1341 Detromp(Shape2).Append(V2);
c19dd45e 1342 }
46767247 1343 U1 = U2;
1344 V1 = V2;
1345 ii ++;
c19dd45e 1346 }
46767247 1347
1348 // test medium point between the last parameter and the end of the bissectrice.
1349 U2 = Bis->LastParameter();
1350 if (!EOnE) {
1351 if (!Precision::IsInfinite(U2)) {
1352 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
c65f8201 1353 if (!Trim.IsInside(P) || ForceAdd) {
46767247 1354 if (!V1.IsNull()) {
1355 Detromp(Shape1).Append(V1);
1356 Detromp(Shape2).Append(V1);
1357 }
1358 }
c19dd45e 1359 }
46767247 1360 else {
1361 if (!V1.IsNull()) {
1362 Detromp(Shape1).Append(V1);
1363 Detromp(Shape2).Append(V1);
1364 }
1365 }
1366 }
1367 //else if(myJoinType != GeomAbs_Arc)
1368 //{
1369 // if (!V1.IsNull()) {
1370 // Detromp(Shape1).Append(V1);
1371 // Detromp(Shape2).Append(V1);
1372 // }
1373 //}
1374 } //end of else (myJoinType==GeomAbs_Arc)
c19dd45e 1375}
1376
1377//=======================================================================
7fd59977 1378//function : MakeWires
1379//purpose :
1380//=======================================================================
1381
1382void BRepFill_OffsetWire::MakeWires()
1383{
1384 //--------------------------------------------------------
0d969553 1385 // creation of a single list of created parallel edges.
7fd59977 1386 //--------------------------------------------------------
1387 TopTools_SequenceOfShape TheEdges;
1388 TopTools_ListOfShape TheWires;
1389 TopTools_ListIteratorOfListOfShape itl;
86b3805f
J
1390 //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;
1391 TopTools_IndexedDataMapOfShapeListOfShape MVE;
1392 //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape MVEit;
7fd59977 1393 TopoDS_Vertex V1,V2,VF,CV;
86b3805f 1394 Standard_Integer i;
7fd59977 1395
86b3805f
J
1396 for (i = 1; i <= myMap.Extent(); i++) {
1397 for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
7fd59977 1398 const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
1399 TopExp::Vertices (E,V1,V2);
1400 if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
873c119f 1401 continue; //remove small closed edges
7642e2d0 1402 if (!CheckSmallParamOnEdge(E))
1403 continue;
86b3805f 1404 if (!MVE.Contains(V1)) {
873c119f 1405 TopTools_ListOfShape empty;
1406 MVE.Add(V1,empty);
7fd59977 1407 }
86b3805f
J
1408 MVE.ChangeFromKey(V1).Append(E);
1409 if (!MVE.Contains(V2)) {
873c119f 1410 TopTools_ListOfShape empty;
1411 MVE.Add(V2,empty);
7fd59977 1412 }
86b3805f 1413 MVE.ChangeFromKey(V2).Append(E);
7fd59977 1414 }
1415 }
1416
1417 //--------------------------------------
0d969553 1418 // Creation of parallel wires.
7fd59977 1419 //--------------------------------------
1420 BRep_Builder B;
1421
873c119f 1422
1423 // Standard_Integer NbEdges;
1424 // Standard_Boolean NewWire = Standard_True;
1425 // Standard_Boolean AddEdge = Standard_False;
7fd59977 1426
1427 TopoDS_Wire NW;
1428 Standard_Boolean End;
1429 TopoDS_Edge CE;
1430
1431 while (!MVE.IsEmpty()) {
1432 B.MakeWire(NW);
1433
86b3805f
J
1434 //MVEit.Initialize(MVE);
1435 for (i = 1; i <= MVE.Extent(); i++)
1436 if(MVE(i).Extent() == 1)
1437 break;
7fd59977 1438
86b3805f
J
1439 //if(!MVEit.More()) MVEit.Initialize(MVE);
1440 if (i > MVE.Extent())
1441 i = 1;
7fd59977 1442
86b3805f
J
1443 CV = VF = TopoDS::Vertex(MVE.FindKey(i));
1444 CE = TopoDS::Edge(MVE(i).First());
7fd59977 1445 End = Standard_False;
1867dc32 1446 MVE.ChangeFromKey(CV).RemoveFirst();
1447
1448 if (myIsOpenResult && MVE.FindFromKey(CV).IsEmpty())
1449 {
1450 //MVE.UnBind(CV);
1451 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1452 TopTools_ListOfShape LastList;
1453 LastList.Append(MVE(MVE.Extent()));
1454 MVE.RemoveLast();
1455 if (MVE.FindIndex(CV) != 0)
1456 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1457 }
1458
7fd59977 1459
873c119f 1460 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
7fd59977 1461 Standard_Boolean isClosed = Standard_False;
873c119f 1462
1463 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:00 2002 End
7fd59977 1464
1465 while(!End) {
1466 //-------------------------------
0d969553 1467 // Construction of a wire.
7fd59977 1468 //-------------------------------
1469 TopExp::Vertices(CE,V1,V2);
1470 if (!CV.IsSame(V1)) CV = V1; else CV = V2;
1471
1472 B.Add (NW,CE);
1473
86b3805f 1474 if (VF.IsSame(CV) || !MVE.Contains(CV)) {
873c119f 1475 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
1476 isClosed = VF.IsSame(CV);
1477 // Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
1478 End = Standard_True;
1479 //MVE.UnBind(VF);
86b3805f
J
1480 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1481 TopTools_ListOfShape LastList;
1482 LastList.Append(MVE(MVE.Extent()));
1483 MVE.RemoveLast();
1484 if (MVE.FindIndex(VF) != 0)
1485 MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
7fd59977 1486 }
1487
1488 if (!End) {
873c119f 1489 if (MVE.FindFromKey(CV).Extent() > 2) {
1490 //cout <<"vertex on more that 2 edges in a face."<<endl;
1491 }
1492 for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
1493 if (itl.Value().IsSame(CE)) {
1494 MVE.ChangeFromKey(CV).Remove(itl);
1495 break;
1496 }
1497 }
1498 if (!MVE.FindFromKey(CV).IsEmpty()) {
1499 CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
1500 MVE.ChangeFromKey(CV).RemoveFirst();
1501 }
1867dc32 1502 else if (myIsOpenResult)//CV was a vertex with one edge
1503 End = Standard_True;
1504
873c119f 1505 if (MVE.FindFromKey(CV).IsEmpty())
86b3805f
J
1506 {
1507 //MVE.UnBind(CV);
1508 TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
1509 TopTools_ListOfShape LastList;
1510 LastList.Append(MVE(MVE.Extent()));
1511 MVE.RemoveLast();
1512 if (MVE.FindIndex(CV) != 0)
1513 MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
1514 }
7fd59977 1515 }
1516 }
873c119f 1517 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
1518 // NW.Closed(Standard_True);
7fd59977 1519 NW.Closed(isClosed);
873c119f 1520 // Modified by Sergey KHROMOV - Thu Mar 14 11:29:37 2002 End
7fd59977 1521 TheWires.Append(NW);
1522 }
1523
0d969553
Y
1524 // update myShape :
1525 // -- if only one wire : myShape is a Wire
1526 // -- if several wires : myShape is a Compound.
7fd59977 1527 if ( TheWires.Extent() == 1) {
1528 myShape = TheWires.First();
1529 }
1530 else {
1531 TopoDS_Compound R;
1532 B.MakeCompound(R);
1533 TopTools_ListIteratorOfListOfShape it(TheWires);
1534 for ( ; it.More(); it.Next()) {
1535 B.Add(R, it.Value());
1536 }
1537 myShape = R;
1538 }
1539
1540}
1541
1542//=======================================================================
1543//function : FixHoles
1544//purpose :
1545//=======================================================================
1546
1547void BRepFill_OffsetWire::FixHoles()
1548{
1549 TopTools_SequenceOfShape ClosedWires, UnclosedWires, IsolatedWires;
1550
1551 Standard_Real MaxTol = 0.;
7fd59977 1552 BRep_Builder BB;
1553
1554 TopExp_Explorer Explo( mySpine, TopAbs_VERTEX );
1555 for (; Explo.More(); Explo.Next())
91bb31f3 1556 {
1557 const TopoDS_Vertex& aVertex = TopoDS::Vertex( Explo.Current() );
1558 Standard_Real Tol = BRep_Tool::Tolerance(aVertex);
1559 if (Tol > MaxTol)
1560 MaxTol = Tol;
1561 }
7fd59977 1562 MaxTol *= 100.;
1563
1564 Explo.Init( myShape, TopAbs_WIRE );
1565 for (; Explo.More(); Explo.Next())
91bb31f3 1566 {
1567 TopoDS_Shape aWire = Explo.Current();
1568 // Remove duplicated edges
1569 TopTools_DataMapOfShapeListOfShape EEmap;
1570 TopoDS_Iterator it( aWire );
1571 for (; it.More(); it.Next())
7fd59977 1572 {
91bb31f3 1573 const TopoDS_Shape& anEdge = it.Value();
1574 if (! EEmap.IsBound( anEdge ))
1575 {
1576 TopTools_ListOfShape LE;
1577 EEmap.Bind( anEdge, LE );
1578 }
7fd59977 1579 else
91bb31f3 1580 EEmap(anEdge).Append( anEdge );
7fd59977 1581 }
91bb31f3 1582 aWire.Free( Standard_True );
1583 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape mapit( EEmap );
1584 for (; mapit.More(); mapit.Next())
1585 {
1586 const TopTools_ListOfShape& LE = mapit.Value();
1587 TopTools_ListIteratorOfListOfShape itl( LE );
1588 for (; itl.More(); itl.Next())
1589 BB.Remove( aWire, itl.Value() );
1590 }
1591 // Sorting
1592 if (aWire.Closed())
1593 ClosedWires.Append( aWire );
1594 else
1595 UnclosedWires.Append( aWire );
1596 }
1597
7fd59977 1598 while (!UnclosedWires.IsEmpty())
91bb31f3 1599 {
1600 TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
1601 TopoDS_Vertex Vf, Vl;
1602 TopExp::Vertices( Base, Vf, Vl );
1603 if(Vf.IsNull() || Vl.IsNull())
873c119f 1604 {
91bb31f3 1605 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
873c119f 1606#ifdef OCCT_DEBUG
1607 BRepTools::Write(Base, "Base");
1608#endif
1609 }
91bb31f3 1610 gp_Pnt Pf, Pl;
1611 Pf = BRep_Tool::Pnt(Vf);
1612 Pl = BRep_Tool::Pnt(Vl);
1613 Standard_Real DistF = RealLast(), DistL = RealLast();
1232a766 1614 Standard_Integer IndexF = 0, IndexL = 0;
91bb31f3 1615 Standard_Boolean IsFirstF = Standard_False, IsFirstL = Standard_False;
1616 for (Standard_Integer i = 2; i <= UnclosedWires.Length(); i++)
7fd59977 1617 {
91bb31f3 1618 TopoDS_Wire aWire = TopoDS::Wire( UnclosedWires(i) );
1619 TopoDS_Vertex V1, V2;
1620 TopExp::Vertices( aWire, V1, V2 );
1621
1622 if(V1.IsNull() || V2.IsNull())
873c119f 1623 {
ab87e6fc 1624 Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
873c119f 1625#ifdef OCCT_DEBUG
1626 BRepTools::Write(Base, "Base");
1627 char name[128];
1628 sprintf(name,"Wire_%d",i);
1629 BRepTools::Write(aWire, name);
1630#endif
1631 }
91bb31f3 1632
1633 gp_Pnt P1, P2;
1634 P1 = BRep_Tool::Pnt(V1);
1635 P2 = BRep_Tool::Pnt(V2);
1636 Standard_Real dist = Pf.Distance( P1 );
1637 if (dist < DistF)
1638 {
1639 DistF = dist;
1640 IndexF = i;
1641 IsFirstF = Standard_True;
1642 }
1643 dist = Pf.Distance( P2 );
1644 if (dist < DistF)
1645 {
1646 DistF = dist;
1647 IndexF = i;
1648 IsFirstF = Standard_False;
1649 }
1650 dist = Pl.Distance( P1 );
1651 if (dist < DistL)
1652 {
1653 DistL = dist;
1654 IndexL = i;
1655 IsFirstL = Standard_True;
1656 }
1657 dist = Pl.Distance( P2 );
1658 if (dist < DistL)
1659 {
1660 DistL = dist;
1661 IndexL = i;
1662 IsFirstL = Standard_False;
1663 }
1664 }
1232a766 1665 if (DistF > MaxTol)
1666 IndexF = 0;
1667 if (DistL > MaxTol)
1668 IndexL = 0;
91bb31f3 1669 TopoDS_Wire theWire;
1670 TopoDS_Edge theEdge;
1671 TopoDS_Vertex theVertex;
1672 Standard_Real CommonTol;
1673 Standard_Boolean TryToClose = Standard_True;
1674 if (DistF <= MaxTol && DistL <= MaxTol && IndexF == IndexL && IsFirstF == IsFirstL)
1675 {
1676 if (DistF < DistL)
1677 {
1678 DistL = RealLast();
1679 IndexL++;
1680 }
1681 else
1682 {
1683 DistF = RealLast();
1684 IndexF++;
1685 }
1686 TryToClose = Standard_False;
1687 }
1688 if (DistF <= MaxTol)
1689 {
1690 theWire = TopoDS::Wire( UnclosedWires(IndexF) );
1691 TopoDS_Vertex V1, V2;
1692 TopExp::Vertices( theWire, V1, V2 );
1693 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1694 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1695 theEdge = (IsFirstF)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1696 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1697 TopoDS_Iterator it( theWire );
1698 for (; it.More(); it.Next())
1699 {
1700 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1701 if (IsFirstF) anEdge.Reverse();
1702 if (!anEdge.IsSame( theEdge ))
1703 BB.Add( Base, anEdge );
1704 }
1705 theVertex = (IsFirstF)? V1 : V2;
1706 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(theVertex) );
1707 if (DistF <= CommonTol)
1708 {
1709 theEdge.Free( Standard_True );
1710 Vf.Orientation( theVertex.Orientation() );
1711 BB.Remove( theEdge, theVertex );
1712 BB.Add( theEdge, Vf );
1713 BB.UpdateVertex( Vf, CommonTol );
1714 if (IsFirstF) theEdge.Reverse();
1715 BB.Add( Base, theEdge );
1716 }
1717 else
1718 {
1719 if (IsFirstF) theEdge.Reverse();
1720 BB.Add( Base, theEdge );
1721 // Creating new edge from theVertex to Vf
1722 TopoDS_Edge NewEdge = BRepLib_MakeEdge( theVertex, Vf );
1723 BB.Add( Base, NewEdge );
1724 }
1725 }
1726 if (DistL <= MaxTol && IndexL != IndexF)
1727 {
1728 theWire = TopoDS::Wire( UnclosedWires(IndexL) );
1729 TopoDS_Vertex V1, V2;
1730 TopExp::Vertices( theWire, V1, V2 );
1731 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1732 TopExp::MapShapesAndAncestors( theWire, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1733 theEdge = (IsFirstL)? TopoDS::Edge(VEmap.FindFromKey( V1 ).First()) :
1734 TopoDS::Edge(VEmap.FindFromKey( V2 ).First());
1735 TopoDS_Iterator it( theWire );
1736 for (; it.More(); it.Next())
1737 {
1738 TopoDS_Edge anEdge = TopoDS::Edge( it.Value() );
1739 if (!IsFirstL) anEdge.Reverse();
1740 if (!anEdge.IsSame( theEdge ))
1741 BB.Add( Base, anEdge );
1742 }
1743 theVertex = (IsFirstL)? V1 : V2;
1744 CommonTol = Max( BRep_Tool::Tolerance(Vl), BRep_Tool::Tolerance(theVertex) );
1745 if (DistL <= CommonTol)
1746 {
1747 theEdge.Free( Standard_True );
1748 Vl.Orientation( theVertex.Orientation() );
1749 BB.Remove( theEdge, theVertex );
1750 BB.Add( theEdge, Vl );
1751 BB.UpdateVertex( Vl, CommonTol );
1752 if (!IsFirstL) theEdge.Reverse();
1753 BB.Add( Base, theEdge );
1754 }
1755 else
1756 {
1757 if (!IsFirstL) theEdge.Reverse();
1758 BB.Add( Base, theEdge );
1759 // Creating new edge from Vl to theVertex
1760 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vl, theVertex );
1761 BB.Add( Base, NewEdge );
1762 }
1763 }
1764 // Check if it is possible to close resulting wire
1765 if (TryToClose)
1766 {
1767 TopExp::Vertices( Base, Vf, Vl );
1768 CommonTol = Max( BRep_Tool::Tolerance(Vf), BRep_Tool::Tolerance(Vl) );
1769 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
1770 TopExp::MapShapesAndAncestors( Base, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
1771 TopoDS_Edge Efirst, Elast;
1772 Efirst = TopoDS::Edge(VEmap.FindFromKey( Vf ).First());
1773 Elast = TopoDS::Edge(VEmap.FindFromKey( Vl ).First());
7fd59977 1774 Pf = BRep_Tool::Pnt(Vf);
1775 Pl = BRep_Tool::Pnt(Vl);
91bb31f3 1776 Standard_Real Dist = Pf.Distance(Pl);
1777 if (Dist <= CommonTol)
1778 {
1779 Elast.Free( Standard_True );
1780 Vf.Orientation( Vl.Orientation() );
1781 BB.Remove( Elast, Vl );
1782 BB.Add( Elast, Vf );
1783 BB.UpdateVertex( Vf, CommonTol );
1784 Base.Closed( Standard_True );
1785 }
1786 else if (Dist <= MaxTol)
1787 {
1788 // Creating new edge from Vl to Vf
1789 TopoDS_Edge NewEdge = BRepLib_MakeEdge( Vf, Vl );
1790 BB.Add( Base, NewEdge );
1791 Base.Closed( Standard_True );
1792 }
7fd59977 1793 }
91bb31f3 1794 // Updating sequences ClosedWires and UnclosedWires
1795 if (DistF <= MaxTol)
1796 UnclosedWires.Remove( IndexF );
1797 if (DistL <= MaxTol && IndexL != IndexF)
7fd59977 1798 {
91bb31f3 1799 if (DistF <= MaxTol && IndexL > IndexF)
1800 IndexL--;
1801 UnclosedWires.Remove( IndexL );
7fd59977 1802 }
91bb31f3 1803 if (Base.Closed())
7fd59977 1804 {
91bb31f3 1805 ClosedWires.Append( Base );
1806 UnclosedWires.Remove( 1 );
7fd59977 1807 }
91bb31f3 1808 else if (DistF > MaxTol && DistL > MaxTol)
1809 {
1810 IsolatedWires.Append( Base );
1811 UnclosedWires.Remove( 1 );
1812 }
1813 }
1814
1815 // Updating myShape
1816 if (ClosedWires.Length() + IsolatedWires.Length() == 1)
1817 {
1818 if (!ClosedWires.IsEmpty())
1819 myShape = ClosedWires.First();
1820 else
1821 myShape = IsolatedWires.First();
1822 }
1823 else
1824 {
1825 TopoDS_Compound R;
1826 BB.MakeCompound( R );
51740958 1827 Standard_Integer i;
91bb31f3 1828 for (i = 1; i <= ClosedWires.Length(); i++)
1829 BB.Add( R, ClosedWires(i) );
1830 for (i = 1; i <= IsolatedWires.Length(); i++)
1831 BB.Add( R, IsolatedWires(i) );
1832 myShape = R;
1833 }
7fd59977 1834}
1835
1836//=======================================================================
1837//function : CutEdge
0d969553
Y
1838//purpose : Cut edge at the extrema of curvatures and points of inflexion.
1839// So, closed circles are cut in two.
1840// If <Cuts> is empty, the edge is not modified.
1841// The first and the last vertex of the initial edge
1842// belong to the first and the last parts respectively.
7fd59977 1843//=======================================================================
1844Standard_Integer CutEdge (const TopoDS_Edge& E,
873c119f 1845 const TopoDS_Face& F,
1846 Standard_Integer ForceCut,
1847 TopTools_ListOfShape& Cuts)
7fd59977 1848{
1849 Cuts.Clear();
1850 MAT2d_CutCurve Cuter;
1851 TColGeom2d_SequenceOfCurve theCurves;
1852 Standard_Real f,l;
1853 Handle(Geom2d_Curve) C2d;
1854 Handle(Geom2d_TrimmedCurve) CT2d;
873c119f 1855 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 Begin
7fd59977 1856 Standard_Real aTol = BRep_Tool::Tolerance(E);
1857 Handle(Geom_Curve) aC;
873c119f 1858 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:25 2002 End
7fd59977 1859
1860 TopoDS_Vertex V1,V2,VF,VL;
1861 TopExp::Vertices (E,V1,V2);
1862 BRep_Builder B;
1863
1864 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
873c119f 1865 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 Begin
7fd59977 1866 aC = BRep_Tool::Curve(E,f,l);
873c119f 1867 // Modified by Sergey KHROMOV - Wed Mar 6 17:36:54 2002 End
7fd59977 1868 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
1869 //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
1870
1871 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
873c119f 1872 ( Abs(f-l) >= M_PI) ) {
1873 return 0;
7fd59977 1874 }
1875
1876 //-------------------------
0d969553 1877 // Cut curve.
7fd59977 1878 //-------------------------
1879 Cuter.Perform(CT2d);
1880
873c119f 1881 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:29 2000 Begin
7fd59977 1882 if (ForceCut == 0) {
1883 if (Cuter.UnModified()) {
873c119f 1884 //-----------------------------
1885 // edge not modified => return.
1886 //-----------------------------
7fd59977 1887 return 0;
1888 } else {
1889 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
873c119f 1890 theCurves.Append(Cuter.Value(k));
7fd59977 1891 }
1892 } else if (ForceCut == 1) {
1893 if (Cuter.UnModified()) {
1894 CutCurve (CT2d, 2, theCurves);
1895 } else {
1896 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
873c119f 1897
1898 theCurves.Append(Cuter.Value(k));
7fd59977 1899 }
1900 } else if (ForceCut == 2) {
1901 if (Cuter.UnModified()) {
1902 CutCurve (CT2d, 3, theCurves);
1903 } else {
1904 if (Cuter.NbCurves() == 2) {
873c119f 1905
1906 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(1);
1907
1908 if (CC->LastParameter() > (l+f)/2.) {
1909 CutCurve (CC, 2, theCurves);
1910 theCurves.Append(Cuter.Value(2));
1911 } else {
1912 theCurves.Append(CC);
1913 CutCurve (Cuter.Value(2), 2, theCurves);
1914 }
7fd59977 1915 } else {
873c119f 1916 for (Standard_Integer k = 1; k <= Cuter.NbCurves(); k++)
1917 theCurves.Append(Cuter.Value(k));
7fd59977 1918 }
1919 }
1920 }
873c119f 1921
1922 // Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
7fd59977 1923
1924 //--------------------------------------
0d969553 1925 // Creation of cut edges.
7fd59977 1926 //--------------------------------------
1927 VF = V1;
1928
1929 for (Standard_Integer k = 1; k <= theCurves.Length(); k++) {
1930
1931 Handle(Geom2d_TrimmedCurve)CC = Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(k));
1932
1933 if (k == theCurves.Length()) {VL = V2;}
1934 else {
873c119f 1935 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:02 2002 Begin
7fd59977 1936 gp_Pnt P = aC->Value(CC->LastParameter());
1937
1938 VL = BRepLib_MakeVertex(P);
1939 B.UpdateVertex(VL, aTol);
873c119f 1940 // Modified by Sergey KHROMOV - Wed Mar 6 17:38:05 2002 End
7fd59977 1941 }
1942 TopoDS_Shape aLocalShape = E.EmptyCopied();
1943 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
873c119f 1944 // TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
7fd59977 1945 NE.Orientation(TopAbs_FORWARD);
1946 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
1947 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
1948 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
1949 Cuts.Append(NE.Oriented(E.Orientation()));
1950 VF = VL;
1951 }
1952
1953 return theCurves.Length();
1954}
1955
1956// Modified by Sergey KHROMOV - Thu Nov 16 17:27:56 2000 Begin
1957//=======================================================================
1958//function : CutCurve
1959//purpose :
1960//=======================================================================
1961
1962void CutCurve (const Handle(Geom2d_TrimmedCurve)& C,
873c119f 1963 const Standard_Integer nbParts,
1964 TColGeom2d_SequenceOfCurve& theCurves)
7fd59977 1965{
1966 Handle(Geom2d_TrimmedCurve) TrimC;
1967 Standard_Real UF,UL,UC;
1968 Standard_Real Step;
1969 gp_Pnt2d PF,PL,PC;
1970 Standard_Real PTol = Precision::PConfusion()*10;
1971 Standard_Real Tol = Precision::Confusion()*10;
1972 Standard_Boolean YaCut = Standard_False;
1973
1974 UF = C->FirstParameter();
1975 UL = C->LastParameter ();
1976 PF = C->Value(UF);
1977 PL = C->Value(UL);
1978
1979 Step = (UL - UF)/nbParts;
1980
1981 for (Standard_Integer i = 1; i < nbParts; i++) {
1982
1983 UC = UF + i*Step;
1984 PC = C->Value(UC);
1985
1986 if (UC - UF > PTol && PC.Distance(PF) > Tol) {
1987 if ( UL - UC < PTol || PL.Distance(PC) < Tol)
873c119f 1988 continue;
7fd59977 1989
1990 TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
1991 theCurves.Append(TrimC);
1992 UF = UC;
1993 PF = PC;
1994 YaCut = Standard_True;
1995 }
1996 }
1997 if (YaCut) {
1998 TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
1999 theCurves.Append(TrimC);
2000 } else
2001 theCurves.Append(C);
2002}
2003// Modified by Sergey KHROMOV - Thu Nov 16 17:28:13 2000 End
2004
2005//=======================================================================
2006//function : MakeCircle
2007//purpose :
2008//=======================================================================
2009
2010void MakeCircle (const TopoDS_Edge& E,
873c119f 2011 const TopoDS_Vertex& V,
2012 const TopoDS_Face& F,
2013 const Standard_Real Offset,
2014 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
2015 const Handle(Geom_Plane)& RefPlane)
7fd59977 2016{
0d969553 2017 // evaluate the Axis of the Circle.
7fd59977 2018 Standard_Real f,l;
2019 Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
2020 gp_Vec2d DX;
2021 gp_Pnt2d P;
2022
2023 if (E.Orientation() == TopAbs_FORWARD) {
2024 GC->D1(l,P,DX);
2025 DX.Reverse();
2026 }
2027 else GC->D1(f,P,DX);
2028
2029 gp_Ax2d Axis(P,gp_Dir2d(DX));
2030 Handle(Geom2d_Circle) Circ
2031 = new Geom2d_Circle(Axis, Abs(Offset), Offset < 0.);
2032
2033 // Bind the edges in my Map.
2034 TopoDS_Edge OE = BRepLib_MakeEdge(Circ, RefPlane);
2035 TopTools_ListOfShape LL;
2036
2037 LL.Append(OE);
86b3805f 2038 Map.Add(V,LL);
7fd59977 2039
873c119f 2040#ifdef OCCT_DEBUG
7fd59977 2041#ifdef DRAW
2042 if ( AffichGeom && !OE.IsNull()) {
1896126e 2043 char name[256];
7fd59977 2044 sprintf(name,"OFFSET_%d",++NbOFFSET);
2045 DBRep::Set(name,OE);
2046 }
2047#endif
873c119f 2048#endif
7fd59977 2049}
2050
2051//=======================================================================
2052//function : MakeOffset
2053//purpose :
2054//=======================================================================
2055
2056void MakeOffset (const TopoDS_Edge& E,
873c119f 2057 const TopoDS_Face& F,
2058 const Standard_Real Offset,
2059 BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
2060 const Handle(Geom_Plane)& RefPlane,
2061 const Standard_Boolean IsOpenResult,
c7806cb6 2062 const GeomAbs_JoinType theJoinType,
873c119f 2063 const TopoDS_Vertex * Ends)
7fd59977 2064{
2065 Standard_Real f,l;
2066 Standard_Real anOffset = Offset;
2067
2068 if (E.Orientation() == TopAbs_REVERSED) anOffset *= -1;
2069
2070 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2071 Handle(Geom2d_Curve) G2dOC;
2072
6a442250 2073 Standard_Boolean ToExtendFirstPar = Standard_True;
2074 Standard_Boolean ToExtendLastPar = Standard_True;
2075 if (IsOpenResult)
2076 {
2077 TopoDS_Vertex V1, V2;
2078 TopExp::Vertices(E, V1, V2);
2079 if (V1.IsSame(Ends[0]) ||
873c119f 2080 V1.IsSame(Ends[1]))
6a442250 2081 ToExtendFirstPar = Standard_False;
2082 if (V2.IsSame(Ends[0]) ||
873c119f 2083 V2.IsSame(Ends[1]))
6a442250 2084 ToExtendLastPar = Standard_False;
2085 }
2086
7fd59977 2087 Geom2dAdaptor_Curve AC(G2d,f,l);
2088 if ( AC.GetType() == GeomAbs_Circle) {
0d969553
Y
2089 // if the offset is greater otr equal to the radius and the side of the
2090 // concavity of the circle => edge null.
7fd59977 2091 gp_Circ2d C1(AC.Circle());
7fd59977 2092 gp_Ax22d axes( C1.Axis());
2093 gp_Dir2d Xd = axes.XDirection();
2094 gp_Dir2d Yd = axes.YDirection();
2095 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
2096 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
2097
9ffd84ad 2098 if (anOffset*Signe < AC.Circle().Radius() - Precision::Confusion()) {
0d969553 2099
7fd59977 2100 Handle(Geom2dAdaptor_HCurve) AHC =
873c119f 2101 new Geom2dAdaptor_HCurve(G2d);
5201d3e6 2102 Adaptor2d_OffsetCurve Off(AHC,-anOffset);
7fd59977 2103 Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());
2104
c6541a0c 2105 Standard_Real Delta = 2*M_PI - l + f;
c7806cb6 2106 if (theJoinType == GeomAbs_Arc)
2107 {
873c119f 2108 if (ToExtendFirstPar)
2109 f -= 0.2*Delta;
2110 if (ToExtendLastPar)
2111 l += 0.2*Delta;
c7806cb6 2112 }
2113 else //GeomAbs_Intersection
2114 {
2115 if (ToExtendFirstPar && ToExtendLastPar)
2116 {
2117 Standard_Real old_l = l;
2118 f = old_l + Delta/2.;
2119 l = f + 2*M_PI;
2120 }
2121 else if (ToExtendFirstPar)
2122 {
2123 f = l;
2124 l = f + 2*M_PI;
2125 }
2126 else if (ToExtendLastPar)
2127 {
2128 l = f + 2*M_PI;
2129 }
2130 }
7fd59977 2131 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2132 }
2133 }
2134 else if (AC.GetType() == GeomAbs_Line) {
2135 Handle(Geom2dAdaptor_HCurve) AHC =
2136 new Geom2dAdaptor_HCurve(G2d);
5201d3e6 2137 Adaptor2d_OffsetCurve Off(AHC,anOffset);
7fd59977 2138 Handle(Geom2d_Line) CC = new Geom2d_Line(Off.Line());
2139 Standard_Real Delta = (l - f);
6a442250 2140 if (ToExtendFirstPar)
c7806cb6 2141 {
2142 if (theJoinType == GeomAbs_Arc)
873c119f 2143 f -= Delta;
c7806cb6 2144 else //GeomAbs_Intersection
2145 f = -Precision::Infinite();
2146 }
6a442250 2147 if (ToExtendLastPar)
c7806cb6 2148 {
2149 if (theJoinType == GeomAbs_Arc)
873c119f 2150 l += Delta;
c7806cb6 2151 else //GeomAbs_Intersection
2152 l = Precision::Infinite();
2153 }
7fd59977 2154 G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
2155 }
2156 else {
2157
2158 anOffset = -anOffset;
2159 Handle(Geom2d_TrimmedCurve) G2dT = new Geom2d_TrimmedCurve(G2d,f,l);
2160 G2dOC = new Geom2d_OffsetCurve( G2dT, anOffset);
2161
2162 }
2163
2164 // Bind the edges in my Map.
2165 if (!G2dOC.IsNull()) {
2166 TopoDS_Edge OE = BRepLib_MakeEdge(G2dOC, RefPlane);
2167 OE.Orientation(E.Orientation());
2168 TopTools_ListOfShape LL;
2169 LL.Append(OE);
86b3805f 2170 Map.Add(E,LL);
7fd59977 2171
873c119f 2172#ifdef OCCT_DEBUG
7fd59977 2173#ifdef DRAW
2174 if (AffichGeom && !OE.IsNull()) {
1896126e 2175 char name[256];
7fd59977 2176 sprintf(name,"OFFSET_%d",++NbOFFSET);
2177 DBRep::Set(name,OE);
873c119f 2178 //Standard_Real ii = 0;
7fd59977 2179 }
2180#endif
873c119f 2181#endif
2182
7fd59977 2183 }
2184}
2185
7fd59977 2186
2187//=======================================================================
2188//function : VertexFromNode
2189//purpose :
2190//=======================================================================
2191
2192Standard_Boolean VertexFromNode (const Handle(MAT_Node)& aNode,
873c119f 2193 const Standard_Real Offset,
2194 gp_Pnt2d& PN,
2195 BRepFill_DataMapOfNodeShape& MapNodeVertex,
2196 TopoDS_Vertex& VN)
7fd59977 2197{
2198 Standard_Boolean Status;
2199 Standard_Real Tol = Precision::Confusion();
2200 BRep_Builder B;
2201
2202 if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
2203 //------------------------------------------------
0d969553 2204 // the Node gives a vertex on the offset
7fd59977 2205 //------------------------------------------------
2206 if (MapNodeVertex.IsBound(aNode)) {
2207 VN = TopoDS::Vertex(MapNodeVertex(aNode));
2208 }
2209 else {
2210 gp_Pnt P(PN.X(),PN.Y(),0.);
2211 B.MakeVertex (VN);
2212 B.UpdateVertex(VN,P, Precision::Confusion());
2213 MapNodeVertex.Bind(aNode,VN);
2214 }
2215 Status = Standard_True;
2216 }
2217 else Status = Standard_False;
2218
2219 return Status;
2220}
2221
2222
2223//=======================================================================
2224//function : StoreInMap
2225//purpose :
2226//=======================================================================
2227
2228void StoreInMap (const TopoDS_Shape& V1,
873c119f 2229 const TopoDS_Shape& V2,
2230 TopTools_IndexedDataMapOfShapeShape& MapVV)
7fd59977 2231{
2232 TopoDS_Shape OldV = V1, NewV = V2;
2233 Standard_Integer i;
2234
2235 if (MapVV.Contains(V2))
2236 NewV = MapVV.FindFromKey(V2);
2237
2238 if (MapVV.Contains(V1))
2239 MapVV.ChangeFromKey(V1) = NewV;
2240
2241 for (i = 1; i <= MapVV.Extent(); i++)
2242 if (MapVV(i).IsSame(V1))
2243 MapVV(i) = NewV;
2244
2245 MapVV.Add(V1, NewV);
2246}
2247
2248//=======================================================================
2249//function : TrimEdge
2250//purpose :
2251//=======================================================================
2252
2253void TrimEdge (const TopoDS_Edge& E,
e11c1bc4 2254 const TopoDS_Shape& ProE,
2255 const TopoDS_Face& AllSpine,
7fd59977 2256 const TopTools_ListOfShape& Detromp,
6a442250 2257 TopTools_SequenceOfShape& TheVer,
2258 TColStd_SequenceOfReal& ThePar,
2259 TopTools_SequenceOfShape& S,
2260 TopTools_IndexedDataMapOfShapeShape& MapVV,
2261 const Standard_Integer IndOfE)
7fd59977 2262{
2263 Standard_Boolean Change = Standard_True;
2264 BRep_Builder TheBuilder;
2265 S.Clear();
2266
2267 //-----------------------------------------------------------
0d969553 2268 // Parse two sequences depending on the parameter on the edge.
7fd59977 2269 //-----------------------------------------------------------
2270 while (Change) {
2271 Change = Standard_False;
2272 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2273 if (ThePar.Value(i) > ThePar.Value(i+1)) {
873c119f 2274 ThePar.Exchange(i,i+1);
2275 TheVer.Exchange(i,i+1);
2276 Change = Standard_True;
7fd59977 2277 }
2278 }
2279 }
2280
2281 //----------------------------------------------------------
0d969553 2282 // If a vertex is not in the proofing, it is eliminated.
7fd59977 2283 //----------------------------------------------------------
2284 if (!BRep_Tool::Degenerated(E)) {
2285 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2286 if ( DoubleOrNotInside (Detromp,
873c119f 2287 TopoDS::Vertex(TheVer.Value(k)))) {
2288 TheVer.Remove(k);
2289 ThePar.Remove(k);
2290 k--;
7fd59977 2291 }
2292 }
2293 }
2294
2295 //----------------------------------------------------------
0d969553
Y
2296 // If a vertex_double appears twice in the proofing
2297 // the vertex is removed.
2298 // otherwise preserve only one of its representations.
7fd59977 2299 //----------------------------------------------------------
2300 if (!BRep_Tool::Degenerated(E)) {
94f71cad 2301 Standard_Real aParTol = 2.0 * Precision::PConfusion();
7fd59977 2302 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2303 if (TheVer.Value(k).IsSame(TheVer.Value(k+1)) ||
94f71cad 2304 Abs(ThePar.Value(k)-ThePar.Value(k+1)) <= aParTol) {
873c119f 2305
2306 if(k+1 == TheVer.Length()) {
2307 StoreInMap(TheVer(k), TheVer(k+1), MapVV);
2308 TheVer.Remove(k);
2309 ThePar.Remove(k);
2310 }
2311 else {
2312 StoreInMap(TheVer(k+1), TheVer(k), MapVV);
2313 TheVer.Remove(k+1);
2314 ThePar.Remove(k+1);
2315 }
2316 /*
2317 if ( DoubleOrNotInside (Detromp,
2318 TopoDS::Vertex(TheVer.Value(k)))) {
2319 TheVer.Remove(k);
2320 ThePar.Remove(k);
2321 k--;
2322 }
2323 */
2324 k--;
7fd59977 2325 }
2326 }
2327 }
2328 //-----------------------------------------------------------
0d969553
Y
2329 // Creation of edges.
2330 // the number of vertices should be even. The created edges
2331 // go from a vertex with uneven index i to vertex i+1;
7fd59977 2332 //-----------------------------------------------------------
6a442250 2333 if (IndOfE == 1 || IndOfE == -1) //open result and extreme edges of result
2334 {
7fd59977 2335 TopoDS_Shape aLocalShape = E.EmptyCopied();
2336 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
6a442250 2337 TopoDS_Vertex V1, V2;
2338 TopExp::Vertices(E, V1, V2);
2339 Standard_Real fpar, lpar;
e11c1bc4 2340 Handle(Geom_Surface) aPlane;
2341 TopLoc_Location aLoc;
2342 Handle(Geom2d_Curve) PCurve;
2343 BRep_Tool::CurveOnSurface(E, PCurve, aPlane, aLoc, fpar, lpar);
2344 //BRep_Tool::Range(E, fpar, lpar);
2345
2346 Standard_Real TrPar1, TrPar2;
2347 Standard_Boolean ToTrimAsOrigin = IsInnerEdge(ProE, AllSpine, TrPar1, TrPar2);
2348
6a442250 2349 if (IndOfE == 1) //first edge of open wire
2350 {
2351 if (NewEdge.Orientation() == TopAbs_FORWARD)
2352 {
e11c1bc4 2353 if (ToTrimAsOrigin)
2354 {
2355 fpar = TrPar1;
2356 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2357 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2358 V1 = BRepLib_MakeVertex(TrPnt);
2359 }
6a442250 2360 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_FORWARD));
2361 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2362 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2363 }
2364 else
2365 {
e11c1bc4 2366 if (ToTrimAsOrigin)
2367 {
2368 lpar = TrPar2;
2369 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2370 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2371 V2 = BRepLib_MakeVertex(TrPnt);
2372 }
6a442250 2373 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_REVERSED));
2374 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_FORWARD));
2375 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2376 }
7fd59977 2377 }
6a442250 2378 else //last edge of open wire
2379 {
2380 if (NewEdge.Orientation() == TopAbs_FORWARD)
2381 {
e11c1bc4 2382 if (ToTrimAsOrigin)
2383 {
2384 lpar = TrPar2;
2385 gp_Pnt2d TrPnt2d = PCurve->Value(lpar);
2386 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2387 V2 = BRepLib_MakeVertex(TrPnt);
2388 }
6a442250 2389 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2390 TheBuilder.Add(NewEdge, V2.Oriented(TopAbs_REVERSED));
2391 TheBuilder.Range(NewEdge, ThePar.First(), lpar);
2392 }
2393 else
2394 {
e11c1bc4 2395 if (ToTrimAsOrigin)
2396 {
2397 fpar = TrPar1;
2398 gp_Pnt2d TrPnt2d = PCurve->Value(fpar);
2399 gp_Pnt TrPnt(TrPnt2d.X(), TrPnt2d.Y(), 0.);
2400 V1 = BRepLib_MakeVertex(TrPnt);
2401 }
6a442250 2402 TheBuilder.Add(NewEdge, V1.Oriented(TopAbs_REVERSED));
2403 TheBuilder.Add(NewEdge, TheVer.First().Oriented(TopAbs_FORWARD));
2404 TheBuilder.Range(NewEdge, fpar, ThePar.First());
2405 }
7fd59977 2406 }
6a442250 2407 S.Append(NewEdge);
2408 }
2409 else
2410 {
2411 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2412 TopoDS_Shape aLocalShape = E.EmptyCopied();
2413 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2414 // TopoDS_Edge NewEdge = TopoDS::Edge(E.EmptyCopied());
2415
2416 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2417 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2418 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2419 }
2420 else {
2421 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2422 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2423 }
2424
2425
2426 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2427
873c119f 2428#ifdef OCCT_DEBUG
7fd59977 2429#ifdef DRAW
6a442250 2430 if ( AffichEdge) {
2431 char name[256];
2432 sprintf(name,"TRIMEDGE_%d",NbTRIMEDGES);
2433 DBRep::Set(name,NewEdge);
2434 }
2435 if (Affich2d) {
2436 TopLoc_Location L;
2437 Standard_Real f,l;
2438 Handle(Geom_Surface) Surf;
2439 Handle(Geom2d_Curve) C;
2440 BRep_Tool::CurveOnSurface(NewEdge,C,Surf,L,f,l);
2441 char name[256];
2442 sprintf(name,"OFFSET2d_%d",NbTRIMEDGES++);
2443 Handle(Geom2d_TrimmedCurve) C2d = new Geom2d_TrimmedCurve(C,f,l);
2444 Handle(DrawTrSurf_Curve2d) dr =
2445 new DrawTrSurf_Curve2d(C2d,Standard_False);
2446 dr->SetColor(Draw_bleu);
2447 Draw::Set(name,dr);
2448 }
7fd59977 2449#endif
873c119f 2450#endif
6a442250 2451 S.Append(NewEdge);
2452 }
7fd59977 2453 }
2454}
2455
2456//=======================================================================
e11c1bc4 2457//function : IsInnerEdge
2458//purpose :
2459//=======================================================================
2460
2461static Standard_Boolean IsInnerEdge(const TopoDS_Shape& ProE,
2462 const TopoDS_Face& AllSpine,
2463 Standard_Real& TrPar1,
2464 Standard_Real& TrPar2)
2465{
2466 if (ProE.ShapeType() != TopAbs_EDGE)
2467 return Standard_False;
2468
2469 TopoDS_Edge anEdge = TopoDS::Edge(ProE);
2470
2471 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2472 TopExp::MapShapesAndAncestors(AllSpine, TopAbs_VERTEX, TopAbs_EDGE, VEmap);
2473 for (Standard_Integer i = 1; i <= VEmap.Extent(); i++)
2474 {
2475 const TopTools_ListOfShape& LE = VEmap(i);
2476 if (LE.Extent() == 1 && anEdge.IsSame(LE.First()))
2477 return Standard_False;
2478 }
2479
2480 BRep_Tool::Range(anEdge, TrPar1, TrPar2);
2481 return Standard_True;
2482}
2483
2484
2485
2486//=======================================================================
7fd59977 2487//function : DoubleOrNotInside
0d969553 2488//purpose : return True if V appears twice in LV or is not inside.
7fd59977 2489//=======================================================================
2490
2491Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
873c119f 2492 const TopoDS_Vertex& V)
7fd59977 2493{
2494 Standard_Boolean Vu = Standard_False;
2495 TopTools_ListIteratorOfListOfShape it(LV);
2496
2497 for ( ; it.More(); it.Next()) {
2498 if (V.IsSame(it.Value())) {
2499 if (Vu) return Standard_True;
2500 else Vu = Standard_True;
2501 }
2502 }
2503 if (Vu) return Standard_False;
2504 else return Standard_True;
2505}
2506
2507Standard_Boolean IsSmallClosedEdge(const TopoDS_Edge& anEdge,
873c119f 2508 const TopoDS_Vertex& aVertex)
7fd59977 2509{
2510 gp_Pnt PV = BRep_Tool::Pnt(aVertex);
2511 gp_Pnt2d PV2d, Pfirst, Plast, Pmid;
2512 PV2d.SetCoord( PV.X(), PV.Y() );
2513
2514 Handle(Geom2d_Curve) PCurve;
2515 Handle( BRep_CurveRepresentation ) CurveRep =
2516 ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2517 PCurve = CurveRep->PCurve();
2518
2519 Standard_Real fpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
2520 Standard_Real lpar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
2521 Pfirst = PCurve->Value(fpar);
2522 Plast = PCurve->Value(lpar);
2523 Pmid = PCurve->Value((fpar + lpar)*0.5);
2524
2525 Standard_Real theTol = BRep_Tool::Tolerance(aVertex);
2526 theTol *= 1.5;
2527
2528 Standard_Real dist1 = Pfirst.Distance(PV2d);
2529 Standard_Real dist2 = Plast.Distance(PV2d);
2530 Standard_Real dist3 = Pmid.Distance(PV2d);
2531
2532 if (dist1 <= theTol && dist2 <= theTol && dist3 <= theTol)
2533 return Standard_True;
2534
2535 return Standard_False;
2536}
2537
2538static void CheckBadEdges(const TopoDS_Face& Spine, const Standard_Real Offset,
873c119f 2539 const BRepMAT2d_BisectingLocus& Locus,
2540 const BRepMAT2d_LinkTopoBilo& Link,
2541 TopTools_ListOfShape& BadEdges)
7fd59977 2542{
2543
2544 TopoDS_Face F = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
2545 Standard_Real eps = Precision::Confusion();
2546 Standard_Real LimCurv = 1./Offset;
2547
2548 TopTools_MapOfShape aMap;
2549
2550 for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
2551 for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
2552 const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
2553 if (SE.ShapeType() == TopAbs_EDGE) {
2554
873c119f 2555
2556 if (aMap.Contains(SE)) {
2557 //cout << "Edge is treated second time" << endl;
2558 continue;
2559 }
2560
2561
2562 TopoDS_Edge E = TopoDS::Edge(SE);
2563
2564
2565 Standard_Real f,l;
2566
2567
2568 Handle(Geom2d_Curve) G2d = BRep_Tool::CurveOnSurface(E,F,f,l);
2569
2570
2571 Geom2dAdaptor_Curve AC(G2d,f,l);
2572 GeomAbs_CurveType aCType = AC.GetType();
2573
2574
2575 if(aCType != GeomAbs_Line && aCType != GeomAbs_Circle) {
2576
2577
2578 Standard_Boolean reverse = Standard_False;
2579 if (E.Orientation() == TopAbs_FORWARD) reverse = Standard_True;
2580
2581
2582 gp_Pnt2d P, Pc;
2583 gp_Dir2d N;
2584
2585
2586 Geom2dLProp_CLProps2d aCLProps(G2d, 2, eps);
2587
2588
2589 aCLProps.SetParameter(f);
2590 if(!aCLProps.IsTangentDefined()) {
2591 BadEdges.Append(SE);
2592 aMap.Add(SE);
2593 continue;
2594 }
2595
2596
2597 P = aCLProps.Value();
2598 Standard_Real Crv = aCLProps.Curvature();
2599
2600
2601 if(Crv >= eps) {
2602 aCLProps.Tangent(N);
2603 Standard_Real x = N.Y(), y = -N.X();
2604 N.SetCoord(x, y);
2605 if (reverse) N.Reverse();
2606 aCLProps.CentreOfCurvature(Pc);
2607 gp_Vec2d Dir( P, Pc );
2608 if (N.Dot(Dir) > 0.) {
2609 if (LimCurv <= Crv + eps) {
2610 BadEdges.Append(SE);
2611 aMap.Add(SE);
2612 continue;
2613 }
2614 }
2615 }
2616
2617
2618 aCLProps.SetParameter(l);
2619 if(!aCLProps.IsTangentDefined()) {
2620 BadEdges.Append(SE);
2621 aMap.Add(SE);
2622 continue;
2623 }
2624
2625
2626 P = aCLProps.Value();
2627 Crv = aCLProps.Curvature();
2628
2629
2630 if(Crv >= eps) {
2631 aCLProps.Tangent(N);
2632 Standard_Real x = N.Y(), y = -N.X();
2633 N.SetCoord(x, y);
2634 if (reverse) N.Reverse();
2635 aCLProps.CentreOfCurvature(Pc);
2636 gp_Vec2d Dir( P, Pc );
2637 if (N.Dot(Dir) > 0.) {
2638 if (LimCurv <= Crv + eps) {
2639 BadEdges.Append(SE);
2640 aMap.Add(SE);
2641 continue;
2642 }
2643 }
2644 }
2645 }
7fd59977 2646 }
2647 }
2648 }
2649}
2650
2651
2652//=======================================================================
2653//function : PerformCurve
2654//purpose :
2655//=======================================================================
2656
2657static Standard_Boolean PerformCurve (TColStd_SequenceOfReal& Parameters,
873c119f 2658
2659 TColgp_SequenceOfPnt& Points,
2660 const Adaptor3d_Curve& C,
2661 const Standard_Real Deflection,
2662 const Standard_Real U1,
2663 const Standard_Real U2,
2664 const Standard_Real EPSILON,
2665 const Standard_Integer Nbmin)
7fd59977 2666{
2667 Standard_Real UU1 = Min(U1, U2);
2668 Standard_Real UU2 = Max(U1, U2);
2669
2670 gp_Pnt Pdeb, Pfin;
2671 gp_Vec Ddeb,Dfin;
2672 C.D1(UU1,Pdeb,Ddeb);
2673 Parameters.Append(UU1);
2674 Points.Append(Pdeb);
2675
2676 C.D1(UU2,Pfin,Dfin);
91bb31f3 2677
2678 const Standard_Real aDelta = UU2 - UU1;
2679 const Standard_Real aDist = Pdeb.Distance(Pfin);
2680
2681 if((aDelta/aDist) > 5.0e-14)
2682 {
2683 QuasiFleche(C,Deflection*Deflection,
873c119f 2684
2685 UU1,Pdeb,
2686 Ddeb,
2687 UU2,Pfin,
2688 Dfin,
2689 Nbmin,
2690 EPSILON*EPSILON,
2691 Parameters,Points);
91bb31f3 2692 }
2693
7fd59977 2694 return Standard_True;
2695}
2696//=======================================================================
2697//function : QuasiFleche
2698//purpose :
2699//=======================================================================
2700
2701static void QuasiFleche(const Adaptor3d_Curve& C,
873c119f 2702
2703 const Standard_Real Deflection2,
2704 const Standard_Real Udeb,
2705 const gp_Pnt& Pdeb,
2706 const gp_Vec& Vdeb,
2707 const Standard_Real Ufin,
2708 const gp_Pnt& Pfin,
2709 const gp_Vec& Vfin,
2710 const Standard_Integer Nbmin,
2711 const Standard_Real Eps,
2712 TColStd_SequenceOfReal& Parameters,
2713 TColgp_SequenceOfPnt& Points)
7fd59977 2714{
2715 Standard_Integer Ptslength = Points.Length();
2716 Standard_Real Udelta = Ufin-Udeb;
2717 gp_Pnt Pdelta;
2718 gp_Vec Vdelta;
2719 if (Nbmin > 2) {
2720 Udelta /=(Nbmin-1);
2721 C.D1(Udeb+Udelta,Pdelta,Vdelta);
2722 }
2723 else {
2724 Pdelta = Pfin;
2725 Vdelta = Vfin;
2726 }
2727
2728
2729 Standard_Real Norme = gp_Vec(Pdeb,Pdelta).SquareMagnitude();
2730 Standard_Real theFleche=0;
2731 Standard_Boolean flecheok = Standard_False;
2732 if (Norme > Eps) {
0d969553 2733 // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
7fd59977 2734 Standard_Real N1 = Vdeb.SquareMagnitude();
2735 Standard_Real N2 = Vdelta.SquareMagnitude();
2736 if (N1 > Eps && N2 > Eps) {
2737 Standard_Real Normediff =
873c119f 2738
2739 (Vdeb.Normalized().XYZ()-Vdelta.Normalized().XYZ()).SquareModulus();
7fd59977 2740 if (Normediff > Eps) {
873c119f 2741
2742 theFleche = Normediff*Norme/64.;
2743 flecheok = Standard_True;
7fd59977 2744 }
2745 }
2746 }
2747 if (!flecheok) {
2748 gp_Pnt Pmid((Pdeb.XYZ()+Pdelta.XYZ())/2.);
2749 gp_Pnt Pverif(C.Value(Udeb+Udelta/2.));
2750 theFleche = Pmid.SquareDistance(Pverif);
2751 }
2752
2753 if (theFleche < Deflection2) {
2754 Parameters.Append(Udeb+Udelta);
2755 Points.Append(Pdelta);
2756 }
2757 else {
2758 QuasiFleche(C,Deflection2,Udeb,Pdeb,
873c119f 2759
2760 Vdeb,
2761 Udeb+Udelta,Pdelta,
2762 Vdelta,
2763 3,
2764 Eps,
2765 Parameters,Points);
7fd59977 2766
2767 }
2768
2769 if (Nbmin > 2) {
2770 QuasiFleche(C,Deflection2,Udeb+Udelta,Pdelta,
873c119f 2771
2772 Vdelta,
2773 Ufin,Pfin,
2774 Vfin,
2775 Nbmin-(Points.Length()-Ptslength),
2776 Eps,
2777 Parameters,Points);
7fd59977 2778 }
2779}
ab87e6fc 2780
7642e2d0 2781Standard_Boolean CheckSmallParamOnEdge(const TopoDS_Edge& anEdge)
2782{
2783 const BRep_ListOfCurveRepresentation& aList = ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves());
2784 if (!aList.IsEmpty())
2785 {
2786 Handle( BRep_CurveRepresentation ) CRep = ((Handle(BRep_TEdge)::DownCast(anEdge.TShape()))->Curves()).First();
2787 Standard_Real f = (Handle(BRep_GCurve)::DownCast(CRep))->First();
2788 Standard_Real l = (Handle(BRep_GCurve)::DownCast(CRep))->Last();
2789 if (Abs (l - f) < Precision::PConfusion())
2790 return Standard_False;
2791 }
2792 return Standard_True;
2793}
2794
2795