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