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