1 // Created on: 1995-02-22
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRep_GCurve.hxx>
20 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
21 #include <BRep_TEdge.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRepAdaptor_Curve.hxx>
24 #include <BRepAdaptor_Curve2d.hxx>
25 #include <BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal.hxx>
26 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepLib_MakeVertex.hxx>
29 #include <BRepOffsetAPI_DraftAngle.hxx>
30 #include <BRepOffsetAPI_SequenceOfSequenceOfReal.hxx>
31 #include <BRepOffsetAPI_SequenceOfSequenceOfShape.hxx>
32 #include <BRepTools.hxx>
33 #include <BRepTools_Substitution.hxx>
34 #include <Draft_Modification.hxx>
35 #include <Geom2d_Curve.hxx>
36 #include <Geom_Surface.hxx>
39 #include <Precision.hxx>
40 #include <Standard_ConstructionError.hxx>
41 #include <Standard_NoSuchObject.hxx>
42 #include <Standard_NullObject.hxx>
43 #include <StdFail_NotDone.hxx>
44 #include <TColgp_SequenceOfPnt.hxx>
45 #include <TColStd_SequenceOfReal.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopLoc_Location.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Iterator.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopoDS_Wire.hxx>
54 #include <TopOpeBRep_EdgesIntersector.hxx>
55 #include <TopOpeBRep_Point2d.hxx>
56 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_SequenceOfShape.hxx>
60 //=======================================================================
61 //function : BRepOffsetAPI_DraftAngle
63 //=======================================================================
64 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle () {}
67 //=======================================================================
68 //function : BRepOffsetAPI_DraftAngle
70 //=======================================================================
72 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle (const TopoDS_Shape& S)
75 myModification = new Draft_Modification(S);
79 //=======================================================================
82 //=======================================================================
84 void BRepOffsetAPI_DraftAngle::Clear ()
86 if (!myModification.IsNull()) {
87 Handle(Draft_Modification)::DownCast (myModification)->Clear();
92 //=======================================================================
95 //=======================================================================
97 void BRepOffsetAPI_DraftAngle::Init (const TopoDS_Shape& S)
101 if (!myModification.IsNull()) {
102 Handle(Draft_Modification)::DownCast (myModification)->Init(S);
105 myModification = new Draft_Modification(S);
110 //=======================================================================
113 //=======================================================================
115 void BRepOffsetAPI_DraftAngle::Add(const TopoDS_Face& F,
117 const Standard_Real Angle,
119 const Standard_Boolean Flag)
121 // POP-DPF : protection
122 if ( Abs(Angle) <= 1.e-04 )
124 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
125 Handle(Draft_Modification)::DownCast (myModification)->Add(F,D,Angle,Plane, Flag);
129 //=======================================================================
132 //=======================================================================
134 Standard_Boolean BRepOffsetAPI_DraftAngle::AddDone () const
136 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
137 return Handle(Draft_Modification)::DownCast (myModification)
138 ->ProblematicShape().IsNull();
142 //=======================================================================
145 //=======================================================================
147 void BRepOffsetAPI_DraftAngle::Remove(const TopoDS_Face& F)
149 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
150 Handle(Draft_Modification)::DownCast (myModification)->Remove(F);
154 //=======================================================================
155 //function : ProblematicShape
157 //=======================================================================
159 const TopoDS_Shape& BRepOffsetAPI_DraftAngle::ProblematicShape () const
161 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
162 return Handle(Draft_Modification)::DownCast (myModification)->ProblematicShape();
166 //=======================================================================
167 //function : ErrorStatus
169 //=======================================================================
171 Draft_ErrorStatus BRepOffsetAPI_DraftAngle::Status () const
173 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
174 return Handle(Draft_Modification)::DownCast (myModification)->Error();
178 //=======================================================================
179 //function : ConnectedFaces
181 //=======================================================================
183 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ConnectedFaces
184 (const TopoDS_Face& F) const
186 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
187 return Handle(Draft_Modification)::DownCast (myModification)->ConnectedFaces(F);
191 //=======================================================================
192 //function : ModifiedFaces
194 //=======================================================================
196 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ModifiedFaces() const
198 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
199 return Handle(Draft_Modification)::DownCast (myModification)->ModifiedFaces();
202 //=======================================================================
203 //function : Generated
205 //=======================================================================
207 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Generated(const TopoDS_Shape& S)
210 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
211 Handle(Draft_Modification) DMod = Handle(Draft_Modification)::DownCast (myModification);
213 if (S.ShapeType() == TopAbs_FACE) {
214 Handle(Geom_Surface) Surf;
217 Standard_Boolean RW,RF;
218 if (DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
219 if(myVtxToReplace.IsEmpty())
221 myGenerated.Append(ModifiedShape (S));
225 myGenerated.Append(mySubs.Value(ModifiedShape (S)));
232 //=======================================================================
233 //function : Modified
235 //=======================================================================
237 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Modified(const TopoDS_Shape& S)
240 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
241 Handle(Draft_Modification) DMod = Handle(Draft_Modification)::DownCast (myModification);
243 if (S.ShapeType() == TopAbs_FACE) {
244 Handle(Geom_Surface) Surf;
247 Standard_Boolean RW,RF;
249 if (!DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
250 // Ce n est pas une generation => peut etre une modif
251 if(myVtxToReplace.IsEmpty())
253 myGenerated.Append(ModifiedShape (S));
257 myGenerated.Append(mySubs.Value(ModifiedShape (S)));
259 if (myGenerated.Extent() == 1 && myGenerated.First().IsSame(S)) {
267 //=======================================================================
268 //function : ModifiedShape
270 //=======================================================================
272 TopoDS_Shape BRepOffsetAPI_DraftAngle::ModifiedShape
273 (const TopoDS_Shape& S) const
275 if(S.ShapeType() == TopAbs_VERTEX)
277 if(myVtxToReplace.IsBound(S))
279 return myVtxToReplace(S);
282 if(myVtxToReplace.IsEmpty())
284 return myModifier.ModifiedShape(S);
288 const TopoDS_Shape& aNS = myModifier.ModifiedShape(S);
289 return mySubs.Value(aNS);
293 //=======================================================================
296 //=======================================================================
298 void BRepOffsetAPI_DraftAngle::Build()
300 Handle(Draft_Modification)::DownCast (myModification)->Perform();
301 if (!Handle(Draft_Modification)::DownCast (myModification)->IsDone()) {
305 DoModif(myInitialShape);
311 //=======================================================================
312 //function : CorrectWires
314 //=======================================================================
316 void BRepOffsetAPI_DraftAngle::CorrectWires()
318 Standard_Real TolInter = 1.e-7;
319 Standard_Integer i, j, k;
321 TopTools_SequenceOfShape Eseq;
322 TopTools_SequenceOfShape Wseq;
323 TopTools_SequenceOfShape Fseq;
324 TopoDS_Shape CurEdge, CurWire, CurFace;
325 TopoDS_Iterator wit, eit;
327 TopExp_Explorer fexp( myShape, TopAbs_FACE );
328 for (; fexp.More(); fexp.Next())
330 CurFace = fexp.Current();
331 wit.Initialize( CurFace );
332 for (; wit.More(); wit.Next())
334 CurWire = wit.Value();
335 TopTools_MapOfShape emap;
336 eit.Initialize( CurWire );
337 for (; eit.More(); eit.Next())
338 emap.Add( eit.Value() );
339 TopTools_MapIteratorOfMapOfShape mapit( emap );
340 for (; mapit.More(); mapit.Next())
342 CurEdge = mapit.Key();
343 if (BRepTools::IsReallyClosed( TopoDS::Edge(CurEdge), TopoDS::Face(CurFace) ))
345 Eseq.Append( CurEdge );
346 Wseq.Append( CurWire );
347 Fseq.Append( CurFace );
353 BRepFill_DataMapOfShapeSequenceOfReal Emap;
355 TopTools_SequenceOfShape NonSeam;
356 TopTools_SequenceOfShape NonSeamWires;
357 BRepOffsetAPI_SequenceOfSequenceOfReal ParsNonSeam;
358 BRepOffsetAPI_SequenceOfSequenceOfShape Seam;
359 BRepOffsetAPI_SequenceOfSequenceOfReal ParsSeam;
361 TopTools_DataMapOfShapeShape WFmap;
362 TopTools_DataMapOfShapeListOfShape WWmap;
363 for (i = 1; i <= Eseq.Length(); i++)
368 wit.Initialize( CurFace );
369 for (; wit.More(); wit.Next())
371 TopoDS_Shape aWire = wit.Value();
372 if (! aWire.IsSame( CurWire ))
374 TColgp_SequenceOfPnt pts;
375 TopTools_SequenceOfShape edges;
376 TColStd_SequenceOfReal pars;
377 Standard_Boolean Wadd = Standard_False;
378 eit.Initialize( aWire );
379 for (; eit.More(); eit.Next())
381 TopoDS_Shape anEdge = eit.Value();
382 TopOpeBRep_EdgesIntersector EInter;
383 EInter.SetFaces( CurFace, CurFace );
384 EInter.ForceTolerances( TolInter, TolInter );
385 EInter.Perform( CurEdge, anEdge );
386 if (EInter.IsEmpty())
388 EInter.Perform( CurEdge.Reversed(), anEdge );
389 if (EInter.IsEmpty())
392 Wadd = Standard_True;
393 if (! WFmap.IsBound( aWire ))
394 WFmap.Bind( aWire, CurFace );
395 Standard_Integer ind = 0;
396 for (j = 1; j <= NonSeam.Length(); j++)
397 if (anEdge.IsSame( NonSeam(j) ))
404 NonSeam.Append( anEdge );
405 NonSeamWires.Append( aWire );
406 ind = NonSeam.Length();
407 TColStd_SequenceOfReal emptyseq1, emptyseq2;
408 TopTools_SequenceOfShape emptyedgeseq;
409 ParsNonSeam.Append( emptyseq1 );
410 Seam.Append( emptyedgeseq );
411 ParsSeam.Append( emptyseq2 );
413 if (! Emap.IsBound( CurEdge ))
415 TColStd_SequenceOfReal emptyseq;
416 Emap.Bind( CurEdge, emptyseq );
419 for (; EInter.MorePoint(); EInter.NextPoint())
421 const TopOpeBRep_Point2d& bp = EInter.Point();
424 gp_Pnt Pnt = bp.Value();
425 Standard_Integer ied = 0;
426 for (j = 1; j <= pts.Length(); j++)
427 if (Pnt.IsEqual( pts(j), Precision::Confusion() ))
435 edges.Append( anEdge );
436 pars.Append( bp.Parameter(2) );
437 Emap(CurEdge).Append( bp.Parameter(1) );
438 ParsNonSeam(ind).Append( bp.Parameter(2) );
439 Seam(ind).Append( CurEdge );
440 ParsSeam(ind).Append( bp.Parameter(1) );
445 Standard_Real ParOnSeam = bp.Parameter(1);
446 Standard_Real Par1 = pars(ied);
447 Standard_Real Par2 = bp.Parameter(2);
448 BRepAdaptor_Curve2d SeamCurve( CurEdge, CurFace );
449 BRepAdaptor_Curve2d Curve1( edges(ied), CurFace );
450 BRepAdaptor_Curve2d Curve2( anEdge. CurFace );
452 gp_Vec2d SeamDer, Der1, Der2;
453 //SeamCurve->D1( ParOnSeam, P2d, SeamDer );
454 //Curve1->D1( Par1, P2d, Der1 );
455 //Curve2->D1( Par2, P2d, Der2 );
456 Standard_Real Crossed1 = SeamDer ^ Der1;
457 Standard_Real Crossed2 = SeamDer ^ Der2;
462 else // ! bp.IsVertex(2)
464 //Temporary the case of tangency is not implemented
465 Emap(CurEdge).Append( bp.Parameter(1) );
466 ParsNonSeam(ind).Append( bp.Parameter(2) );
467 Seam(ind).Append( CurEdge );
468 ParsSeam(ind).Append( bp.Parameter(1) );
470 } //for (; EInter.MorePoint(); EInter.NextPoint())
471 } //for (; eit.More(); eit.Next())
474 if (! WWmap.IsBound( CurWire ))
476 TopTools_ListOfShape emptylist;
477 WWmap.Bind( CurWire, emptylist );
479 WWmap(CurWire).Append( aWire );
481 } //if (! aWire.IsSame( CurWire ))
482 } //for (; wit.More(); wit.Next())
483 } //for (i = 1; i <= Eseq.Length(); i++)
486 for (i = 1; i <= NonSeam.Length(); i++)
487 for (j = 1; j < ParsNonSeam(i).Length(); j++)
488 for (k = j+1; k <= ParsNonSeam(i).Length(); k++)
489 if (ParsNonSeam(i)(k) < ParsNonSeam(i)(j))
491 Standard_Real temp = ParsNonSeam(i)(j);
492 ParsNonSeam(i)(j) = ParsNonSeam(i)(k);
493 ParsNonSeam(i)(k) = temp;
494 TopoDS_Shape tmp = Seam(i)(j);
495 Seam(i)(j) = Seam(i)(k);
497 temp = ParsSeam(i)(j);
498 ParsSeam(i)(j) = ParsSeam(i)(k);
499 ParsSeam(i)(k) = temp;
501 BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal iter( Emap );
502 for (; iter.More(); iter.Next())
504 TColStd_SequenceOfReal Seq;
506 for (i = 1; i < Seq.Length(); i++)
507 for (j = i+1; j <= Seq.Length(); j++)
510 Standard_Real temp = Seq(i);
514 Emap( iter.Key() ) = Seq;
516 BRepFill_DataMapOfShapeSequenceOfReal EPmap;
517 TopTools_DataMapOfShapeSequenceOfShape EVmap; //Seam
518 TopTools_DataMapOfShapeSequenceOfShape EWmap; //Seam and wires intersecting it
519 iter.Initialize( Emap );
520 for (; iter.More(); iter.Next())
522 TColStd_SequenceOfReal parseq;
523 EPmap.Bind( iter.Key(), parseq );
524 TopTools_SequenceOfShape shapeseq;
525 EVmap.Bind( iter.Key(), shapeseq );
526 TopTools_SequenceOfShape shapeseq2;
527 EWmap.Bind( iter.Key(), shapeseq2 );
530 //Reconstruction of non-seam edges
531 BRepTools_Substitution aSub;
533 for (i = 1; i <= NonSeam.Length(); i++)
535 TopoDS_Edge anEdge = TopoDS::Edge( NonSeam(i) );
536 TopTools_ListOfShape NewEdges;
538 TopoDS_Vertex Vfirst, Vlast;
539 TopExp::Vertices( anEdge, Vfirst, Vlast );
540 Standard_Real par, FirstPar, LastPar;
541 BRep_Tool::Range( anEdge, FirstPar, LastPar );
542 Standard_Integer firstind = 1;
543 par = ParsNonSeam(i)(1);
544 TopoDS_Edge SeamEdge = TopoDS::Edge( Seam(i)(1) );
546 for (j = 1; j <= Eseq.Length(); j++)
547 if (SeamEdge.IsSame( Eseq(j) ))
549 TopoDS_Face theFace = TopoDS::Face( Fseq(j) );
551 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( theFace, L );
552 if (Abs(par-FirstPar) <= Precision::Confusion())
554 BB.UpdateVertex( Vfirst, ParsSeam(i)(1), SeamEdge, BRep_Tool::Tolerance(Vfirst) );
555 EPmap( SeamEdge ).Append( ParsSeam(i)(1) );
556 EVmap( SeamEdge ).Append( Vfirst );
557 EWmap( SeamEdge ).Append( NonSeamWires(i) );
560 Standard_Real prevpar = FirstPar;
561 TopoDS_Vertex PrevV = Vfirst;
562 for (j = firstind; j <= ParsNonSeam(i).Length(); j++)
564 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
565 NewE = TopoDS::Edge( aLocalShape );
566 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
568 par = ParsNonSeam(i)(j);
569 BB.Range( NewE, prevpar, par );
570 SeamEdge = TopoDS::Edge( Seam(i)(j) );
571 if (j == ParsNonSeam(i).Length() && Abs(par-LastPar) <= Precision::Confusion())
574 if (firstind == 2 && j == 2)
576 BB.UpdateVertex( Vlast, ParsSeam(i)(j), SeamEdge, BRep_Tool::Tolerance(Vlast) );
577 EPmap( SeamEdge ).Append( ParsSeam(i)(j) );
578 EVmap( SeamEdge ).Append( Vlast );
579 EWmap( SeamEdge ).Append( NonSeamWires(i) );
585 BRepAdaptor_Curve bcur( NewE );
586 gp_Pnt Point = bcur.Value( par );
587 NewV = BRepLib_MakeVertex( Point );
588 BB.UpdateVertex( NewV, par, NewE, 10.*Precision::Confusion() );
590 BB.UpdateVertex( NewV, ParsSeam(i)(j), SeamEdge, 10.*Precision::Confusion() );
591 NewE.Orientation( TopAbs_FORWARD );
592 BB.Add( NewE, PrevV.Oriented(TopAbs_FORWARD) );
593 BB.Add( NewE, NewV.Oriented(TopAbs_REVERSED) );
595 NewEdges.Append( NewE );
596 EPmap( SeamEdge ).Append( ParsSeam(i)(j) );
597 EVmap( SeamEdge ).Append( NewV );
598 EWmap( SeamEdge ).Append( NonSeamWires(i) );
604 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
605 NewE = TopoDS::Edge( aLocalShape );
606 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
608 if (Abs(prevpar-par) > Precision::Confusion())
610 BB.Range( NewE, prevpar, par );
611 NewE.Orientation( TopAbs_FORWARD );
612 BB.Add( NewE, PrevV.Oriented(TopAbs_FORWARD) );
613 BB.Add( NewE, Vlast.Oriented(TopAbs_REVERSED) );
614 NewEdges.Append( NewE );
617 //Substitute anEdge by NewEdges
618 aSub.Substitute( anEdge, NewEdges );
621 //Sorting of EPmap and EVmap and removing repeating points from them
622 iter.Initialize( EPmap );
623 for (; iter.More(); iter.Next())
625 TColStd_SequenceOfReal Seq;
627 TopTools_SequenceOfShape SeqShape;
628 SeqShape = EVmap( iter.Key() );
629 TopTools_SequenceOfShape SeqShape2;
630 SeqShape2 = EWmap( iter.Key() );
631 for (i = 1; i < Seq.Length(); i++)
632 for (j = i+1; j <= Seq.Length(); j++)
635 Standard_Real temp = Seq(i);
638 TopoDS_Shape tmp = SeqShape(i);
639 SeqShape(i) = SeqShape(j);
642 SeqShape2(i) = SeqShape2(j);
645 EPmap( iter.Key() ) = Seq;
646 EVmap( iter.Key() ) = SeqShape;
647 EWmap( iter.Key() ) = SeqShape2;
649 iter.Initialize( EPmap );
650 for (; iter.More(); iter.Next())
652 TColStd_SequenceOfReal Seq;
654 TopTools_SequenceOfShape SeqShape;
655 SeqShape = EVmap( iter.Key() );
656 TopTools_SequenceOfShape SeqShape2;
657 SeqShape2 = EWmap( iter.Key() );
658 Standard_Boolean remove = Standard_True;
661 remove = Standard_False;
662 for (i = 1; i < Seq.Length(); i++)
663 if (Abs(Seq(i)-Seq(i+1)) <= Precision::Confusion())
666 SeqShape.Remove(i+1);
667 SeqShape2.Remove(i+1);
668 remove = Standard_True;
671 EPmap( iter.Key() ) = Seq;
672 EVmap( iter.Key() ) = SeqShape;
673 EWmap( iter.Key() ) = SeqShape2;
676 //Reconstruction of seam edges
677 TopTools_DataMapOfShapeShape VEmap;
678 iter.Initialize( Emap );
679 for (; iter.More(); iter.Next())
681 TopoDS_Edge anEdge = TopoDS::Edge( iter.Key() );
682 Standard_Boolean onepoint = Standard_False;
683 TopTools_ListOfShape NewEdges;
684 TColStd_SequenceOfReal Seq;
686 TColStd_SequenceOfReal Seq2;
687 Seq2 = EPmap( anEdge );
688 TopTools_SequenceOfShape SeqVer;
689 SeqVer = EVmap( anEdge );
690 TopTools_SequenceOfShape SeqWire;
691 SeqWire = EWmap( anEdge );
692 TopoDS_Vertex Vfirst, Vlast;
693 TopExp::Vertices( anEdge, Vfirst, Vlast );
694 Standard_Real fpar, lpar, FirstPar, LastPar;
695 BRep_Tool::Range( anEdge, FirstPar, LastPar );
699 Standard_Integer firstind = 1;
700 if (Abs(fpar-lpar) <= Precision::Confusion())
708 if (Seq.Length()%2 != 0)
710 VEmap.Bind( Vfirst, anEdge );
713 if (Seq.Length() > 2)
716 onepoint = Standard_True;
721 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
722 NewE = TopoDS::Edge( aLocalShape );
723 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
724 BB.Range( NewE, fpar, lpar );
725 NewE.Orientation( TopAbs_FORWARD );
728 BB.Add( NewE, Vfirst.Oriented(TopAbs_FORWARD) );
729 aLocalShape = SeqVer(1).Oriented(TopAbs_REVERSED);
730 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
731 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_REVERSED) ) );
735 aLocalShape = SeqVer(1).Oriented(TopAbs_FORWARD);
736 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
737 aLocalShape = SeqVer(2).Oriented(TopAbs_REVERSED);
738 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
739 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_FORWARD) ) );
740 //BB.Add( NewE, TopoDS::Vertex( SeqVer(2).Oriented(TopAbs_REVERSED) ) );
742 NewEdges.Append( NewE );
745 for (i = firstind; i < Seq.Length(); i += 2)
747 aLocalShape = anEdge.EmptyCopied();
748 NewE = TopoDS::Edge( aLocalShape );
749 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
752 BB.Range( NewE, fpar, lpar );
754 for (j = 1; j <= Seq2.Length(); j++)
755 if (Abs(fpar-Seq2(j)) <= Precision::Confusion())
757 NewE.Orientation( TopAbs_FORWARD );
758 TopoDS_Shape aLocalShapeCur = SeqVer(j).Oriented(TopAbs_FORWARD);
759 BB.Add( NewE, TopoDS::Vertex( aLocalShapeCur) );
760 aLocalShapeCur = SeqVer(j+1).Oriented(TopAbs_REVERSED);
761 BB.Add( NewE, TopoDS::Vertex( aLocalShapeCur ) );
762 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j).Oriented(TopAbs_FORWARD) ) );
763 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j+1).Oriented(TopAbs_REVERSED) ) );
764 NewEdges.Append( NewE );
771 if (Abs(fpar-lpar) <= Precision::Confusion())
773 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
774 NewE = TopoDS::Edge( aLocalShape );
775 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
776 BB.Range( NewE, fpar, lpar );
777 NewE.Orientation( TopAbs_FORWARD );
778 aLocalShape = SeqVer(SeqVer.Length()).Oriented(TopAbs_FORWARD);
779 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
780 //BB.Add( NewE, TopoDS::Vertex( SeqVer(SeqVer.Length()).Oriented(TopAbs_FORWARD) ) );
781 BB.Add( NewE, Vlast.Oriented(TopAbs_REVERSED) );
782 NewEdges.Append( NewE );
784 //Substitute anEdge by NewEdges
785 aSub.Substitute( anEdge, NewEdges );
788 //Removing edges connected with missing extremities of seam edges
789 TopTools_DataMapIteratorOfDataMapOfShapeShape itve( VEmap );
790 for (; itve.More(); itve.Next())
792 TopoDS_Shape V = itve.Key();
793 TopoDS_Shape E = itve.Value();
795 for (i = 1; i <= Eseq.Length(); i++)
796 if (E.IsSame( Eseq(i) ))
801 TopoDS_Shape Etoremove;
803 for (; eit.More(); eit.Next())
805 TopoDS_Edge CurE = TopoDS::Edge( eit.Value() );
806 if (CurE.IsSame( E ))
808 TopoDS_Vertex Vfirst, Vlast;
809 TopExp::Vertices( CurE, Vfirst, Vlast );
810 if (Vfirst.IsSame( V ) || Vlast.IsSame( V ))
816 if (! Etoremove.IsNull())
818 W.Free( Standard_True );
819 BB.Remove( W, Etoremove );
823 aSub.Build( myShape );
824 if (aSub.IsCopied( myShape ))
826 const TopTools_ListOfShape& listSh = aSub.Copy( myShape );
827 if (! listSh.IsEmpty())
828 myShape = listSh.First();
831 //Reconstruction of wires
832 TopTools_ListOfShape theCopy;
833 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itww( WWmap );
834 for (; itww.More(); itww.Next())
836 CurWire = itww.Key();
837 theCopy = aSub.Copy( CurWire );
838 CurWire = theCopy.First();
839 CurWire.Free( Standard_True );
840 TopTools_ListIteratorOfListOfShape itl( itww.Value() );
841 for (; itl.More(); itl.Next())
843 TopoDS_Shape aWire = itl.Value();
844 CurFace = WFmap( aWire );
845 theCopy = aSub.Copy( aWire );
846 aWire = theCopy.First();
849 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( TopoDS::Face(CurFace), L );
850 eit.Initialize( aWire );
851 for (; eit.More(); eit.Next())
853 TopoDS_Edge anEdge = TopoDS::Edge( eit.Value() );
854 gp_Pnt2d Pfirst, Plast, Pmid;
855 BRep_Tool::UVPoints( anEdge, TopoDS::Face(CurFace), Pfirst, Plast );
856 BRepAdaptor_Curve2d bc2d( anEdge, TopoDS::Face(CurFace) );
857 Pmid = bc2d.Value( (bc2d.FirstParameter()+bc2d.LastParameter())/2. );
859 Standard_Boolean translate = Standard_False;
860 if (Pfirst.X()-2.*M_PI > Precision::Confusion() ||
861 Plast.X()-2.*M_PI > Precision::Confusion() ||
862 Pmid.X()-2.*M_PI > Precision::Confusion())
864 offset.SetCoord( -2.*M_PI, 0 );
865 translate = Standard_True;
867 if (Pfirst.X() < -Precision::Confusion() ||
868 Plast.X() < -Precision::Confusion() ||
869 Pmid.X() < -Precision::Confusion())
871 offset.SetCoord( 2.*M_PI, 0 );
872 translate = Standard_True;
876 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
877 BRep_ListIteratorOfListOfCurveRepresentation itcr( TE->ChangeCurves() );
878 Handle(BRep_GCurve) GC;
880 for (; itcr.More(); itcr.Next())
882 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
883 if (!GC.IsNull() && GC->IsCurveOnSurface( theSurf, L ))
885 Handle(Geom2d_Curve) PC = GC->PCurve();
886 PC = Handle(Geom2d_Curve)::DownCast( PC->Translated( offset ) );
888 TE->ChangeCurves().Remove( itcr );
889 TE->ChangeCurves().Append( GC );
896 eit.Initialize( aWire, Standard_False );
897 for (; eit.More(); eit.Next())
899 TopoDS_Shape anEdge = eit.Value();
900 BB.Add( CurWire, anEdge );
902 if (aSub.IsCopied( CurFace ))
904 theCopy = aSub.Copy( CurFace );
905 CurFace = theCopy.First();
907 CurFace.Free( Standard_True );
908 BB.Remove( CurFace, aWire );
912 //=======================================================================
913 //function : CorrectVertexTol
915 //=======================================================================
917 void BRepOffsetAPI_DraftAngle::CorrectVertexTol()
919 TopTools_MapOfShape anInitVertices, anInitEdges, aNewEdges;
920 TopExp_Explorer anExp(myInitialShape, TopAbs_EDGE);
921 for(; anExp.More(); anExp.Next())
923 anInitEdges.Add(anExp.Current());
924 TopoDS_Iterator anIter(anExp.Current());
925 for(; anIter.More(); anIter.Next())
927 anInitVertices.Add(anIter.Value());
933 myVtxToReplace.Clear();
934 anExp.Init(myShape, TopAbs_EDGE);
935 for(; anExp.More(); anExp.Next())
937 const TopoDS_Shape& anE = anExp.Current();
938 //Skip old (not modified) edges
939 if(anInitEdges.Contains(anE))
942 //Skip processed edges
943 if(aNewEdges.Contains(anE))
948 Standard_Real anETol = BRep_Tool::Tolerance(TopoDS::Edge(anE));
949 TopoDS_Iterator anIter(anE);
950 for(; anIter.More(); anIter.Next())
952 const TopoDS_Vertex& aVtx = TopoDS::Vertex(anIter.Value());
953 if(anInitVertices.Contains(aVtx))
955 if(myVtxToReplace.IsBound(aVtx))
957 aBB.UpdateVertex(TopoDS::Vertex(myVtxToReplace(aVtx)), anETol + Epsilon(anETol));
961 Standard_Real aVTol = BRep_Tool::Tolerance(aVtx);
964 TopoDS_Vertex aNewVtx;
965 gp_Pnt aVPnt = BRep_Tool::Pnt(aVtx);
966 aBB.MakeVertex(aNewVtx, aVPnt,anETol + Epsilon(anETol));
967 aNewVtx.Orientation(aVtx.Orientation());
968 myVtxToReplace.Bind(aVtx, aNewVtx);
974 aBB.UpdateVertex(aVtx, anETol + Epsilon(anETol));
979 if(myVtxToReplace.IsEmpty())
985 TopTools_DataMapIteratorOfDataMapOfShapeShape anIter(myVtxToReplace);
986 for(; anIter.More(); anIter.Next())
988 mySubs.Replace(anIter.Key(), anIter.Value());
990 mySubs.Apply( myShape );
991 myShape = mySubs.Value(myShape);