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