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