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 <TopTools_DataMapOfShapeSequenceOfShape.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_SequenceOfShape.hxx>
58 #include <Geom2dInt_GInter.hxx>
59 #include <IntRes2d_IntersectionPoint.hxx>
61 //=======================================================================
62 //function : BRepOffsetAPI_DraftAngle
64 //=======================================================================
65 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle () {}
68 //=======================================================================
69 //function : BRepOffsetAPI_DraftAngle
71 //=======================================================================
73 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle (const TopoDS_Shape& S)
76 myModification = new Draft_Modification(S);
80 //=======================================================================
83 //=======================================================================
85 void BRepOffsetAPI_DraftAngle::Clear ()
87 if (!myModification.IsNull()) {
88 Handle(Draft_Modification)::DownCast (myModification)->Clear();
93 //=======================================================================
96 //=======================================================================
98 void BRepOffsetAPI_DraftAngle::Init (const TopoDS_Shape& S)
102 if (!myModification.IsNull()) {
103 Handle(Draft_Modification)::DownCast (myModification)->Init(S);
106 myModification = new Draft_Modification(S);
111 //=======================================================================
114 //=======================================================================
116 void BRepOffsetAPI_DraftAngle::Add(const TopoDS_Face& F,
118 const Standard_Real Angle,
120 const Standard_Boolean Flag)
122 // POP-DPF : protection
123 if ( Abs(Angle) <= 1.e-04 )
125 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
126 "BRepOffsetAPI_DraftAngle::Add() - initial shape is not set");
127 Handle(Draft_Modification)::DownCast (myModification)->Add(F,D,Angle,Plane, Flag);
131 //=======================================================================
134 //=======================================================================
136 Standard_Boolean BRepOffsetAPI_DraftAngle::AddDone () const
138 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
139 "BRepOffsetAPI_DraftAngle::AddDone() - initial shape is not set");
140 return Handle(Draft_Modification)::DownCast (myModification)
141 ->ProblematicShape().IsNull();
145 //=======================================================================
148 //=======================================================================
150 void BRepOffsetAPI_DraftAngle::Remove(const TopoDS_Face& F)
152 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
153 "BRepOffsetAPI_DraftAngle::Remove() - initial shape is not set");
154 Handle(Draft_Modification)::DownCast (myModification)->Remove(F);
158 //=======================================================================
159 //function : ProblematicShape
161 //=======================================================================
163 const TopoDS_Shape& BRepOffsetAPI_DraftAngle::ProblematicShape () const
165 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
166 "BRepOffsetAPI_DraftAngle::ProblematicShape() - initial shape is not set");
167 return Handle(Draft_Modification)::DownCast (myModification)->ProblematicShape();
171 //=======================================================================
174 //=======================================================================
176 Draft_ErrorStatus BRepOffsetAPI_DraftAngle::Status () const
178 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
179 "BRepOffsetAPI_DraftAngle::Status() - initial shape is not set");
180 return Handle(Draft_Modification)::DownCast (myModification)->Error();
184 //=======================================================================
185 //function : ConnectedFaces
187 //=======================================================================
189 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ConnectedFaces
190 (const TopoDS_Face& F) const
192 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
193 "BRepOffsetAPI_DraftAngle::ConnectedFaces() - initial shape is not set");
194 return Handle(Draft_Modification)::DownCast (myModification)->ConnectedFaces(F);
198 //=======================================================================
199 //function : ModifiedFaces
201 //=======================================================================
203 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ModifiedFaces() const
205 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
206 "BRepOffsetAPI_DraftAngle::ModifiedFaces() - initial shape is not set");
207 return Handle(Draft_Modification)::DownCast (myModification)->ModifiedFaces();
210 //=======================================================================
211 //function : Generated
213 //=======================================================================
215 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Generated(const TopoDS_Shape& S)
218 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
219 "BRepOffsetAPI_DraftAngle::Generated() - initial shape is not set");
220 Handle(Draft_Modification) DMod = Handle(Draft_Modification)::DownCast (myModification);
222 if (S.ShapeType() == TopAbs_FACE) {
223 Handle(Geom_Surface) Surf;
226 Standard_Boolean RW,RF;
227 if (DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
228 if(myVtxToReplace.IsEmpty())
230 myGenerated.Append(ModifiedShape (S));
234 myGenerated.Append(mySubs.Value(ModifiedShape (S)));
241 //=======================================================================
242 //function : Modified
244 //=======================================================================
246 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Modified(const TopoDS_Shape& S)
249 Standard_NullObject_Raise_if (myInitialShape.IsNull(),
250 "BRepOffsetAPI_DraftAngle::Modified() - initial shape is not set");
251 Handle(Draft_Modification) DMod = Handle(Draft_Modification)::DownCast (myModification);
253 if (S.ShapeType() == TopAbs_FACE) {
254 Handle(Geom_Surface) Surf;
257 Standard_Boolean RW,RF;
259 if (!DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
260 // Ce n est pas une generation => peut etre une modif
261 if(myVtxToReplace.IsEmpty())
263 myGenerated.Append(ModifiedShape (S));
267 myGenerated.Append(mySubs.Value(ModifiedShape (S)));
269 if (myGenerated.Extent() == 1 && myGenerated.First().IsSame(S)) {
277 //=======================================================================
278 //function : ModifiedShape
280 //=======================================================================
282 TopoDS_Shape BRepOffsetAPI_DraftAngle::ModifiedShape
283 (const TopoDS_Shape& S) const
285 if(S.ShapeType() == TopAbs_VERTEX)
287 if(myVtxToReplace.IsBound(S))
289 return myVtxToReplace(S);
292 if(myVtxToReplace.IsEmpty())
294 return myModifier.ModifiedShape(S);
298 const TopoDS_Shape& aNS = myModifier.ModifiedShape(S);
299 return mySubs.Value(aNS);
303 //=======================================================================
306 //=======================================================================
308 void BRepOffsetAPI_DraftAngle::Build()
310 Handle(Draft_Modification)::DownCast (myModification)->Perform();
311 if (!Handle(Draft_Modification)::DownCast (myModification)->IsDone()) {
315 DoModif(myInitialShape);
321 //=======================================================================
322 //function : CorrectWires
324 //=======================================================================
326 void BRepOffsetAPI_DraftAngle::CorrectWires()
328 Standard_Real TolInter = 1.e-7;
329 Standard_Integer i, j, k;
331 TopTools_SequenceOfShape Eseq;
332 TopTools_SequenceOfShape Wseq;
333 TopTools_SequenceOfShape Fseq;
334 TopoDS_Shape CurEdge, CurWire, CurFace;
335 TopoDS_Iterator wit, eit;
337 TopExp_Explorer fexp( myShape, TopAbs_FACE );
338 for (; fexp.More(); fexp.Next())
340 CurFace = fexp.Current();
341 wit.Initialize( CurFace );
342 for (; wit.More(); wit.Next())
344 CurWire = wit.Value();
345 TopTools_MapOfShape emap;
346 eit.Initialize( CurWire );
347 for (; eit.More(); eit.Next())
348 emap.Add( eit.Value() );
349 TopTools_MapIteratorOfMapOfShape mapit( emap );
350 for (; mapit.More(); mapit.Next())
352 CurEdge = mapit.Key();
353 if (BRepTools::IsReallyClosed( TopoDS::Edge(CurEdge), TopoDS::Face(CurFace) ))
355 Eseq.Append( CurEdge );
356 Wseq.Append( CurWire );
357 Fseq.Append( CurFace );
363 BRepFill_DataMapOfShapeSequenceOfReal Emap;
365 TopTools_SequenceOfShape NonSeam;
366 TopTools_SequenceOfShape NonSeamWires;
367 BRepOffsetAPI_SequenceOfSequenceOfReal ParsNonSeam;
368 BRepOffsetAPI_SequenceOfSequenceOfShape Seam;
369 BRepOffsetAPI_SequenceOfSequenceOfReal ParsSeam;
371 TopTools_DataMapOfShapeShape WFmap;
372 TopTools_DataMapOfShapeListOfShape WWmap;
373 for (i = 1; i <= Eseq.Length(); i++)
379 const TopoDS_Face& aFace = TopoDS::Face(CurFace);
381 // Prepare 2D adaptors for intersection.
382 // The seam edge has two 2D curve, thus we have to create 2 adaptors
383 BRepAdaptor_Curve2d aBAC2D1(TopoDS::Edge(CurEdge), aFace);
384 BRepAdaptor_Curve2d aBAC2D1R(TopoDS::Edge(CurEdge.Reversed()), aFace);
385 // Get surface of the face to get 3D intersection point
386 TopLoc_Location aLoc;
387 const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLoc);
388 // Get the tolerance of the current edge to compare intersection points
389 Standard_Real aTolCurE = BRep_Tool::Tolerance(TopoDS::Edge(CurEdge));
391 wit.Initialize( CurFace );
392 for (; wit.More(); wit.Next())
394 TopoDS_Shape aWire = wit.Value();
395 if (! aWire.IsSame( CurWire ))
397 TColgp_SequenceOfPnt pts;
398 Standard_Boolean Wadd = Standard_False;
399 eit.Initialize( aWire );
400 for (; eit.More(); eit.Next())
402 const TopoDS_Edge& anEdge = TopoDS::Edge(eit.Value());
404 // Prepare 2D adaptor for intersection
405 BRepAdaptor_Curve2d aBAC2D2(anEdge, aFace);
406 // Perform intersection
407 Geom2dInt_GInter aGInter;
408 aGInter.Perform(aBAC2D1, aBAC2D2, TolInter, TolInter);
409 if (!aGInter.IsDone() || aGInter.IsEmpty()) {
410 // If first intersection is empty try intersection with reversed edge
411 aGInter.Perform(aBAC2D1R, aBAC2D2, TolInter, TolInter);
412 if (!aGInter.IsDone() || aGInter.IsEmpty()) {
417 Wadd = Standard_True;
418 if (! WFmap.IsBound( aWire ))
419 WFmap.Bind( aWire, CurFace );
420 Standard_Integer ind = 0;
421 for (j = 1; j <= NonSeam.Length(); j++) {
422 if (anEdge.IsSame(NonSeam(j)))
430 NonSeam.Append(anEdge);
431 NonSeamWires.Append(aWire);
432 ind = NonSeam.Length();
433 TColStd_SequenceOfReal emptyseq1, emptyseq2;
434 TopTools_SequenceOfShape emptyedgeseq;
435 ParsNonSeam.Append(emptyseq1);
436 Seam.Append(emptyedgeseq);
437 ParsSeam.Append(emptyseq2);
439 if (!Emap.IsBound(CurEdge))
441 TColStd_SequenceOfReal emptyseq;
442 Emap.Bind(CurEdge, emptyseq);
445 // Get the tolerance of edge to compare intersection points
446 Standard_Real aTolE = BRep_Tool::Tolerance(anEdge);
447 // Tolerance to compare the intersection points is the maximal
448 // tolerance of intersecting edges
449 Standard_Real aTolCmp = Max(aTolCurE, aTolE);
451 Standard_Integer aNbIntPnt = aGInter.NbPoints();
452 for (k = 1; k <= aNbIntPnt; ++k) {
453 const IntRes2d_IntersectionPoint& aP2DInt = aGInter.Point(k);
454 const gp_Pnt2d& aP2D = aP2DInt.Value();
455 gp_Pnt aP3D = aSurf->Value(aP2D.X(), aP2D.Y());
457 // Check if the intersection point is new
458 Standard_Integer ied = 0;
459 for (j = 1; j <= pts.Length(); j++) {
460 if (aP3D.IsEqual(pts(j), aTolCmp))
469 Emap(CurEdge).Append(aP2DInt.ParamOnFirst());
470 ParsNonSeam(ind).Append(aP2DInt.ParamOnSecond());
471 Seam(ind).Append(CurEdge);
472 ParsSeam(ind).Append(aP2DInt.ParamOnFirst());
475 } //for (; eit.More(); eit.Next())
478 if (! WWmap.IsBound( CurWire ))
480 TopTools_ListOfShape emptylist;
481 WWmap.Bind( CurWire, emptylist );
483 WWmap(CurWire).Append( aWire );
485 } //if (! aWire.IsSame( CurWire ))
486 } //for (; wit.More(); wit.Next())
487 } //for (i = 1; i <= Eseq.Length(); i++)
490 for (i = 1; i <= NonSeam.Length(); i++)
492 for (j = 1; j < ParsNonSeam(i).Length(); j++)
494 for (k = j+1; k <= ParsNonSeam(i).Length(); k++)
496 if (ParsNonSeam(i)(k) < ParsNonSeam(i)(j))
498 Standard_Real temp = ParsNonSeam(i)(j);
499 ParsNonSeam(i)(j) = ParsNonSeam(i)(k);
500 ParsNonSeam(i)(k) = temp;
501 TopoDS_Shape tmp = Seam(i)(j);
502 Seam(i)(j) = Seam(i)(k);
504 temp = ParsSeam(i)(j);
505 ParsSeam(i)(j) = ParsSeam(i)(k);
506 ParsSeam(i)(k) = temp;
511 BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal iter (Emap);
512 for (; iter.More (); iter.Next ())
514 TColStd_SequenceOfReal Seq = iter.Value ();
515 for (i = 1; i < Seq.Length (); i++)
517 for (j = i + 1; j <= Seq.Length (); j++)
519 if (Seq (j) < Seq (i))
521 Standard_Real temp = Seq (i);
527 Emap (iter.Key ()) = Seq;
529 BRepFill_DataMapOfShapeSequenceOfReal EPmap;
530 TopTools_DataMapOfShapeSequenceOfShape EVmap; //Seam
531 TopTools_DataMapOfShapeSequenceOfShape EWmap; //Seam and wires intersecting it
532 iter.Initialize (Emap);
533 for (; iter.More (); iter.Next ())
535 TColStd_SequenceOfReal parseq;
536 EPmap.Bind (iter.Key (), parseq);
537 TopTools_SequenceOfShape shapeseq;
538 EVmap.Bind (iter.Key (), shapeseq);
539 TopTools_SequenceOfShape shapeseq2;
540 EWmap.Bind (iter.Key (), shapeseq2);
543 //Reconstruction of non-seam edges
544 BRepTools_Substitution aSub;
546 for (i = 1; i <= NonSeam.Length (); i++)
548 TopoDS_Edge anEdge = TopoDS::Edge (NonSeam (i));
549 TopTools_ListOfShape NewEdges;
551 TopoDS_Vertex Vfirst, Vlast;
552 TopExp::Vertices (anEdge, Vfirst, Vlast);
553 Standard_Real par, FirstPar, LastPar;
554 BRep_Tool::Range (anEdge, FirstPar, LastPar);
555 Standard_Integer firstind = 1;
556 par = ParsNonSeam (i)(1);
557 TopoDS_Edge SeamEdge = TopoDS::Edge (Seam (i)(1));
559 for (j = 1; j <= Eseq.Length (); j++)
560 if (SeamEdge.IsSame (Eseq (j)))
562 TopoDS_Face theFace = TopoDS::Face (Fseq (j));
564 Handle (Geom_Surface) theSurf = BRep_Tool::Surface (theFace, L);
565 if (Abs (par - FirstPar) <= Precision::Confusion ())
567 BB.UpdateVertex (Vfirst, ParsSeam (i)(1), SeamEdge, BRep_Tool::Tolerance (Vfirst));
568 EPmap (SeamEdge).Append (ParsSeam (i)(1));
569 EVmap (SeamEdge).Append (Vfirst);
570 EWmap (SeamEdge).Append (NonSeamWires (i));
573 Standard_Real prevpar = FirstPar;
574 TopoDS_Vertex PrevV = Vfirst;
575 for (j = firstind; j <= ParsNonSeam (i).Length (); j++)
577 TopoDS_Shape aLocalShape = anEdge.EmptyCopied ();
578 NewE = TopoDS::Edge (aLocalShape);
579 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
581 par = ParsNonSeam (i)(j);
582 BB.Range (NewE, prevpar, par);
583 SeamEdge = TopoDS::Edge (Seam (i)(j));
584 if (j == ParsNonSeam (i).Length () && Abs (par - LastPar) <= Precision::Confusion ())
587 if (firstind == 2 && j == 2)
589 BB.UpdateVertex (Vlast, ParsSeam (i)(j), SeamEdge, BRep_Tool::Tolerance (Vlast));
590 EPmap (SeamEdge).Append (ParsSeam (i)(j));
591 EVmap (SeamEdge).Append (Vlast);
592 EWmap (SeamEdge).Append (NonSeamWires (i));
598 BRepAdaptor_Curve bcur (NewE);
599 gp_Pnt Point = bcur.Value (par);
600 NewV = BRepLib_MakeVertex (Point);
601 BB.UpdateVertex (NewV, par, NewE, 10.*Precision::Confusion ());
603 BB.UpdateVertex (NewV, ParsSeam (i)(j), SeamEdge, 10.*Precision::Confusion ());
604 NewE.Orientation (TopAbs_FORWARD);
605 BB.Add (NewE, PrevV.Oriented (TopAbs_FORWARD));
606 BB.Add (NewE, NewV.Oriented (TopAbs_REVERSED));
608 NewEdges.Append (NewE);
609 EPmap (SeamEdge).Append (ParsSeam (i)(j));
610 EVmap (SeamEdge).Append (NewV);
611 EWmap (SeamEdge).Append (NonSeamWires (i));
617 TopoDS_Shape aLocalShape = anEdge.EmptyCopied ();
618 NewE = TopoDS::Edge (aLocalShape);
619 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
621 if (Abs (prevpar - par) > Precision::Confusion ())
623 BB.Range (NewE, prevpar, par);
624 NewE.Orientation (TopAbs_FORWARD);
625 BB.Add (NewE, PrevV.Oriented (TopAbs_FORWARD));
626 BB.Add (NewE, Vlast.Oriented (TopAbs_REVERSED));
627 NewEdges.Append (NewE);
630 //Substitute anEdge by NewEdges
631 aSub.Substitute (anEdge, NewEdges);
634 //Sorting of EPmap and EVmap and removing repeating points from them
635 iter.Initialize (EPmap);
636 for (; iter.More (); iter.Next ())
638 TColStd_SequenceOfReal Seq;
640 TopTools_SequenceOfShape SeqShape;
641 SeqShape = EVmap (iter.Key ());
642 TopTools_SequenceOfShape SeqShape2;
643 SeqShape2 = EWmap (iter.Key ());
644 for (i = 1; i < Seq.Length (); i++)
646 for (j = i + 1; j <= Seq.Length (); j++)
648 if (Seq (j) < Seq (i))
650 Standard_Real temp = Seq (i);
653 TopoDS_Shape tmp = SeqShape (i);
654 SeqShape (i) = SeqShape (j);
657 SeqShape2 (i) = SeqShape2 (j);
663 EPmap (iter.Key ()) = Seq;
664 EVmap (iter.Key ()) = SeqShape;
665 EWmap (iter.Key ()) = SeqShape2;
667 iter.Initialize (EPmap);
668 for (; iter.More (); iter.Next ())
670 TColStd_SequenceOfReal Seq;
672 TopTools_SequenceOfShape SeqShape;
673 SeqShape = EVmap (iter.Key ());
674 TopTools_SequenceOfShape SeqShape2;
675 SeqShape2 = EWmap (iter.Key ());
676 Standard_Boolean remove = Standard_True;
679 remove = Standard_False;
680 for (i = 1; i < Seq.Length (); i++)
682 if (Abs (Seq (i) - Seq (i + 1)) <= Precision::Confusion ())
685 SeqShape.Remove (i + 1);
686 SeqShape2.Remove (i + 1);
687 remove = Standard_True;
691 EPmap (iter.Key ()) = Seq;
692 EVmap (iter.Key ()) = SeqShape;
693 EWmap (iter.Key ()) = SeqShape2;
696 //Reconstruction of seam edges
697 TopTools_DataMapOfShapeShape VEmap;
698 iter.Initialize (Emap);
699 for (; iter.More (); iter.Next ())
701 TopoDS_Edge anEdge = TopoDS::Edge (iter.Key ());
702 Standard_Boolean onepoint = Standard_False;
703 TopTools_ListOfShape NewEdges;
704 TColStd_SequenceOfReal Seq;
706 TColStd_SequenceOfReal Seq2;
707 Seq2 = EPmap (anEdge);
708 TopTools_SequenceOfShape SeqVer;
709 SeqVer = EVmap (anEdge);
710 TopTools_SequenceOfShape SeqWire;
711 SeqWire = EWmap (anEdge);
712 TopoDS_Vertex Vfirst, Vlast;
713 TopExp::Vertices (anEdge, Vfirst, Vlast);
714 Standard_Real fpar, lpar, FirstPar, LastPar;
715 BRep_Tool::Range (anEdge, FirstPar, LastPar);
719 Standard_Integer firstind = 1;
720 if (Abs (fpar - lpar) <= Precision::Confusion ())
728 if (Seq.Length () % 2 != 0)
730 VEmap.Bind (Vfirst, anEdge);
733 if (Seq.Length () > 2)
736 onepoint = Standard_True;
741 TopoDS_Shape aLocalShape = anEdge.EmptyCopied ();
742 NewE = TopoDS::Edge (aLocalShape);
743 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
744 BB.Range (NewE, fpar, lpar);
745 NewE.Orientation (TopAbs_FORWARD);
748 BB.Add (NewE, Vfirst.Oriented (TopAbs_FORWARD));
749 aLocalShape = SeqVer (1).Oriented (TopAbs_REVERSED);
750 BB.Add (NewE, TopoDS::Vertex (aLocalShape));
751 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_REVERSED) ) );
755 aLocalShape = SeqVer (1).Oriented (TopAbs_FORWARD);
756 BB.Add (NewE, TopoDS::Vertex (aLocalShape));
757 aLocalShape = SeqVer (2).Oriented (TopAbs_REVERSED);
758 BB.Add (NewE, TopoDS::Vertex (aLocalShape));
759 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_FORWARD) ) );
760 //BB.Add( NewE, TopoDS::Vertex( SeqVer(2).Oriented(TopAbs_REVERSED) ) );
762 NewEdges.Append (NewE);
765 for (i = firstind; i < Seq.Length (); i += 2)
767 aLocalShape = anEdge.EmptyCopied ();
768 NewE = TopoDS::Edge (aLocalShape);
769 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
772 BB.Range (NewE, fpar, lpar);
774 for (j = 1; j <= Seq2.Length (); j++)
776 if (Abs (fpar - Seq2 (j)) <= Precision::Confusion ())
781 NewE.Orientation (TopAbs_FORWARD);
782 TopoDS_Shape aLocalShapeCur = SeqVer (j).Oriented (TopAbs_FORWARD);
783 BB.Add (NewE, TopoDS::Vertex (aLocalShapeCur));
784 aLocalShapeCur = SeqVer (j + 1).Oriented (TopAbs_REVERSED);
785 BB.Add (NewE, TopoDS::Vertex (aLocalShapeCur));
786 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j).Oriented(TopAbs_FORWARD) ) );
787 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j+1).Oriented(TopAbs_REVERSED) ) );
788 NewEdges.Append (NewE);
795 if (Abs (fpar - lpar) <= Precision::Confusion ())
797 TopoDS_Shape aLocalShape = anEdge.EmptyCopied ();
798 NewE = TopoDS::Edge (aLocalShape);
799 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
800 BB.Range (NewE, fpar, lpar);
801 NewE.Orientation (TopAbs_FORWARD);
802 aLocalShape = SeqVer (SeqVer.Length ()).Oriented (TopAbs_FORWARD);
803 BB.Add (NewE, TopoDS::Vertex (aLocalShape));
804 //BB.Add( NewE, TopoDS::Vertex( SeqVer(SeqVer.Length()).Oriented(TopAbs_FORWARD) ) );
805 BB.Add (NewE, Vlast.Oriented (TopAbs_REVERSED));
806 NewEdges.Append (NewE);
808 //Substitute anEdge by NewEdges
809 aSub.Substitute (anEdge, NewEdges);
812 //Removing edges connected with missing extremities of seam edges
813 TopTools_DataMapIteratorOfDataMapOfShapeShape itve (VEmap);
814 for (; itve.More (); itve.Next ())
816 TopoDS_Shape V = itve.Key ();
817 TopoDS_Shape E = itve.Value ();
819 for (i = 1; i <= Eseq.Length (); i++)
821 if (E.IsSame (Eseq (i)))
827 TopoDS_Shape Etoremove;
829 for (; eit.More (); eit.Next ())
831 TopoDS_Edge CurE = TopoDS::Edge (eit.Value ());
834 TopoDS_Vertex Vfirst, Vlast;
835 TopExp::Vertices (CurE, Vfirst, Vlast);
836 if (Vfirst.IsSame (V) || Vlast.IsSame (V))
842 if (!Etoremove.IsNull ())
844 W.Free (Standard_True);
845 BB.Remove (W, Etoremove);
849 aSub.Build (myShape);
850 if (aSub.IsCopied (myShape))
852 const TopTools_ListOfShape& listSh = aSub.Copy (myShape);
853 if (!listSh.IsEmpty ())
854 myShape = listSh.First ();
857 //Reconstruction of wires
858 TopTools_ListOfShape theCopy;
859 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itww (WWmap);
860 for (; itww.More (); itww.Next ())
862 CurWire = itww.Key ();
863 theCopy = aSub.Copy (CurWire);
864 CurWire = theCopy.First ();
865 CurWire.Free (Standard_True);
866 TopTools_ListIteratorOfListOfShape itl (itww.Value ());
867 for (; itl.More (); itl.Next ())
869 TopoDS_Shape aWire = itl.Value ();
870 CurFace = WFmap (aWire);
871 theCopy = aSub.Copy (aWire);
872 aWire = theCopy.First ();
875 Handle (Geom_Surface) theSurf = BRep_Tool::Surface (TopoDS::Face (CurFace), L);
876 eit.Initialize (aWire);
877 for (; eit.More (); eit.Next ())
879 TopoDS_Edge anEdge = TopoDS::Edge (eit.Value ());
880 gp_Pnt2d Pfirst, Plast, Pmid;
881 BRep_Tool::UVPoints (anEdge, TopoDS::Face (CurFace), Pfirst, Plast);
882 BRepAdaptor_Curve2d bc2d (anEdge, TopoDS::Face (CurFace));
883 Pmid = bc2d.Value ((bc2d.FirstParameter () + bc2d.LastParameter ()) / 2.);
885 Standard_Boolean translate = Standard_False;
886 if (Pfirst.X () - 2.*M_PI > Precision::Confusion () ||
887 Plast.X () - 2.*M_PI > Precision::Confusion () ||
888 Pmid.X () - 2.*M_PI > Precision::Confusion ())
890 offset.SetCoord (-2.*M_PI, 0);
891 translate = Standard_True;
893 if (Pfirst.X () < -Precision::Confusion () ||
894 Plast.X () < -Precision::Confusion () ||
895 Pmid.X () < -Precision::Confusion ())
897 offset.SetCoord (2.*M_PI, 0);
898 translate = Standard_True;
902 const Handle (BRep_TEdge)& TE = *((Handle (BRep_TEdge)*) &anEdge.TShape ());
903 BRep_ListIteratorOfListOfCurveRepresentation itcr (TE->ChangeCurves ());
904 Handle (BRep_GCurve) GC;
906 for (; itcr.More (); itcr.Next ())
908 GC = Handle (BRep_GCurve)::DownCast (itcr.Value ());
909 if (!GC.IsNull () && GC->IsCurveOnSurface (theSurf, L))
911 Handle (Geom2d_Curve) PC = GC->PCurve ();
912 PC = Handle (Geom2d_Curve)::DownCast (PC->Translated (offset));
914 TE->ChangeCurves ().Remove (itcr);
915 TE->ChangeCurves ().Append (GC);
922 eit.Initialize (aWire, Standard_False);
923 for (; eit.More (); eit.Next ())
925 TopoDS_Shape anEdge = eit.Value ();
926 BB.Add (CurWire, anEdge);
928 if (aSub.IsCopied (CurFace))
930 theCopy = aSub.Copy (CurFace);
931 CurFace = theCopy.First ();
933 CurFace.Free (Standard_True);
934 BB.Remove (CurFace, aWire);
938 //=======================================================================
939 //function : CorrectVertexTol
941 //=======================================================================
943 void BRepOffsetAPI_DraftAngle::CorrectVertexTol()
945 TopTools_MapOfShape anInitVertices, anInitEdges, aNewEdges;
946 TopExp_Explorer anExp(myInitialShape, TopAbs_EDGE);
947 for(; anExp.More(); anExp.Next())
949 anInitEdges.Add(anExp.Current());
950 TopoDS_Iterator anIter(anExp.Current());
951 for(; anIter.More(); anIter.Next())
953 anInitVertices.Add(anIter.Value());
959 myVtxToReplace.Clear();
960 anExp.Init(myShape, TopAbs_EDGE);
961 for(; anExp.More(); anExp.Next())
963 const TopoDS_Shape& anE = anExp.Current();
964 //Skip old (not modified) edges
965 if(anInitEdges.Contains(anE))
968 //Skip processed edges
969 if(aNewEdges.Contains(anE))
974 Standard_Real anETol = BRep_Tool::Tolerance(TopoDS::Edge(anE));
975 TopoDS_Iterator anIter(anE);
976 for(; anIter.More(); anIter.Next())
978 const TopoDS_Vertex& aVtx = TopoDS::Vertex(anIter.Value());
979 if(anInitVertices.Contains(aVtx))
981 if(myVtxToReplace.IsBound(aVtx))
983 aBB.UpdateVertex(TopoDS::Vertex(myVtxToReplace(aVtx)), anETol + Epsilon(anETol));
987 Standard_Real aVTol = BRep_Tool::Tolerance(aVtx);
990 TopoDS_Vertex aNewVtx;
991 gp_Pnt aVPnt = BRep_Tool::Pnt(aVtx);
992 aBB.MakeVertex(aNewVtx, aVPnt,anETol + Epsilon(anETol));
993 aNewVtx.Orientation(aVtx.Orientation());
994 myVtxToReplace.Bind(aVtx, aNewVtx);
1000 aBB.UpdateVertex(aVtx, anETol + Epsilon(anETol));
1005 if(myVtxToReplace.IsEmpty())
1011 TopTools_DataMapIteratorOfDataMapOfShapeShape anIter(myVtxToReplace);
1012 for(; anIter.More(); anIter.Next())
1014 mySubs.Replace(anIter.Key(), anIter.Value());
1016 mySubs.Apply( myShape );
1017 myShape = mySubs.Value(myShape);