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