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.
17 #include <BRepOffsetAPI_DraftAngle.ixx>
19 #include <Draft_Modification.hxx>
21 #include <Geom_Surface.hxx>
22 #include <TopLoc_Location.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 #include <BRepLib.hxx>
27 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
28 #include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
29 #include <TopTools_SequenceOfShape.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopExp_Explorer.hxx>
32 #include <BRepTools.hxx>
33 #include <TColgp_SequenceOfPnt.hxx>
34 #include <TColStd_SequenceOfReal.hxx>
35 #include <TopOpeBRep_EdgesIntersector.hxx>
36 #include <TopOpeBRep_Point2d.hxx>
37 #include <Precision.hxx>
38 #include <BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal.hxx>
39 #include <BRepOffsetAPI_SequenceOfSequenceOfReal.hxx>
40 #include <BRepOffsetAPI_SequenceOfSequenceOfShape.hxx>
41 #include <BRepTools_Substitution.hxx>
42 #include <BRep_Builder.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <BRepLib_MakeVertex.hxx>
47 #include <BRep_TEdge.hxx>
48 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
49 #include <BRep_GCurve.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <BRepAdaptor_Curve2d.hxx>
53 //=======================================================================
54 //function : BRepOffsetAPI_DraftAngle
56 //=======================================================================
58 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle () {}
61 //=======================================================================
62 //function : BRepOffsetAPI_DraftAngle
64 //=======================================================================
66 BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle (const TopoDS_Shape& S)
69 myModification = new Draft_Modification(S);
73 //=======================================================================
76 //=======================================================================
78 void BRepOffsetAPI_DraftAngle::Clear ()
80 if (!myModification.IsNull()) {
81 (*((Handle(Draft_Modification)*)&myModification))->Clear();
86 //=======================================================================
89 //=======================================================================
91 void BRepOffsetAPI_DraftAngle::Init (const TopoDS_Shape& S)
95 if (!myModification.IsNull()) {
96 (*((Handle(Draft_Modification)*)&myModification))->Init(S);
99 myModification = new Draft_Modification(S);
104 //=======================================================================
107 //=======================================================================
109 void BRepOffsetAPI_DraftAngle::Add(const TopoDS_Face& F,
111 const Standard_Real Angle,
113 const Standard_Boolean Flag)
115 // POP-DPF : protection
116 if ( Abs(Angle) <= 1.e-04 )
118 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
119 (*((Handle(Draft_Modification)*)&myModification))->Add(F,D,Angle,Plane, Flag);
123 //=======================================================================
126 //=======================================================================
128 Standard_Boolean BRepOffsetAPI_DraftAngle::AddDone () const
130 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
131 return (*((Handle(Draft_Modification)*)&myModification))
132 ->ProblematicShape().IsNull();
136 //=======================================================================
139 //=======================================================================
141 void BRepOffsetAPI_DraftAngle::Remove(const TopoDS_Face& F)
143 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
144 (*((Handle(Draft_Modification)*)&myModification))->Remove(F);
148 //=======================================================================
149 //function : ProblematicShape
151 //=======================================================================
153 const TopoDS_Shape& BRepOffsetAPI_DraftAngle::ProblematicShape () const
155 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
156 return (*((Handle(Draft_Modification)*)&myModification))->ProblematicShape();
160 //=======================================================================
161 //function : ErrorStatus
163 //=======================================================================
165 Draft_ErrorStatus BRepOffsetAPI_DraftAngle::Status () const
167 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
168 return (*((Handle(Draft_Modification)*)&myModification))->Error();
172 //=======================================================================
173 //function : ConnectedFaces
175 //=======================================================================
177 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ConnectedFaces
178 (const TopoDS_Face& F) const
180 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
181 return (*((Handle(Draft_Modification)*)&myModification))->ConnectedFaces(F);
185 //=======================================================================
186 //function : ModifiedFaces
188 //=======================================================================
190 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ModifiedFaces() const
192 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
193 return (*((Handle(Draft_Modification)*)&myModification))->ModifiedFaces();
196 //=======================================================================
197 //function : ModifiedFaces
199 //=======================================================================
201 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Generated(const TopoDS_Shape& S)
204 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
205 Handle(Draft_Modification) DMod = (*((Handle(Draft_Modification)*)&myModification));
207 if (S.ShapeType() == TopAbs_FACE) {
208 Handle(Geom_Surface) Surf;
211 Standard_Boolean RW,RF;
212 if (DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
213 myGenerated.Append(ModifiedShape (S));
220 //=======================================================================
221 //function : ModifiedFaces
223 //=======================================================================
225 const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Modified(const TopoDS_Shape& S)
228 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
229 Handle(Draft_Modification) DMod = (*((Handle(Draft_Modification)*)&myModification));
231 if (S.ShapeType() == TopAbs_FACE) {
232 Handle(Geom_Surface) Surf;
235 Standard_Boolean RW,RF;
237 if (!DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
238 // Ce n est pas une generation => peut etre une modif
239 myGenerated.Append(ModifiedShape (S));
240 if (myGenerated.Extent() == 1 && myGenerated.First().IsSame(S)) {
249 //=======================================================================
252 //=======================================================================
254 void BRepOffsetAPI_DraftAngle::Build()
256 (*((Handle(Draft_Modification)*)&myModification))->Perform();
257 if (!(*((Handle(Draft_Modification)*)&myModification))->IsDone()) {
261 DoModif(myInitialShape);
262 //BRepLib::SameParameter( myShape, 1.0e-7, Standard_True ); //patch
264 BRepLib::SameParameter( myShape, 1.0e-7, Standard_True ); //patch
268 //=======================================================================
269 //function : CorrectWires
271 //=======================================================================
273 void BRepOffsetAPI_DraftAngle::CorrectWires()
275 Standard_Real TolInter = 1.e-7;
276 Standard_Integer i, j, k;
278 TopTools_SequenceOfShape Eseq;
279 TopTools_SequenceOfShape Wseq;
280 TopTools_SequenceOfShape Fseq;
281 TopoDS_Shape CurEdge, CurWire, CurFace;
282 TopoDS_Iterator wit, eit;
284 TopExp_Explorer fexp( myShape, TopAbs_FACE );
285 for (; fexp.More(); fexp.Next())
287 CurFace = fexp.Current();
288 wit.Initialize( CurFace );
289 for (; wit.More(); wit.Next())
291 CurWire = wit.Value();
292 TopTools_MapOfShape emap;
293 eit.Initialize( CurWire );
294 for (; eit.More(); eit.Next())
295 emap.Add( eit.Value() );
296 TopTools_MapIteratorOfMapOfShape mapit( emap );
297 for (; mapit.More(); mapit.Next())
299 CurEdge = mapit.Key();
300 if (BRepTools::IsReallyClosed( TopoDS::Edge(CurEdge), TopoDS::Face(CurFace) ))
302 Eseq.Append( CurEdge );
303 Wseq.Append( CurWire );
304 Fseq.Append( CurFace );
310 BRepFill_DataMapOfShapeSequenceOfReal Emap;
312 TopTools_SequenceOfShape NonSeam;
313 TopTools_SequenceOfShape NonSeamWires;
314 BRepOffsetAPI_SequenceOfSequenceOfReal ParsNonSeam;
315 BRepOffsetAPI_SequenceOfSequenceOfShape Seam;
316 BRepOffsetAPI_SequenceOfSequenceOfReal ParsSeam;
318 TopTools_DataMapOfShapeShape WFmap;
319 TopTools_DataMapOfShapeListOfShape WWmap;
320 for (i = 1; i <= Eseq.Length(); i++)
325 wit.Initialize( CurFace );
326 for (; wit.More(); wit.Next())
328 TopoDS_Shape aWire = wit.Value();
329 if (! aWire.IsSame( CurWire ))
331 TColgp_SequenceOfPnt pts;
332 TopTools_SequenceOfShape edges;
333 TColStd_SequenceOfReal pars;
334 Standard_Boolean Wadd = Standard_False;
335 eit.Initialize( aWire );
336 for (; eit.More(); eit.Next())
338 TopoDS_Shape anEdge = eit.Value();
339 TopOpeBRep_EdgesIntersector EInter;
340 EInter.SetFaces( CurFace, CurFace );
341 EInter.ForceTolerances( TolInter, TolInter );
342 EInter.Perform( CurEdge, anEdge );
343 if (EInter.IsEmpty())
345 EInter.Perform( CurEdge.Reversed(), anEdge );
346 if (EInter.IsEmpty())
349 Wadd = Standard_True;
350 if (! WFmap.IsBound( aWire ))
351 WFmap.Bind( aWire, CurFace );
352 Standard_Integer ind = 0;
353 for (j = 1; j <= NonSeam.Length(); j++)
354 if (anEdge.IsSame( NonSeam(j) ))
361 NonSeam.Append( anEdge );
362 NonSeamWires.Append( aWire );
363 ind = NonSeam.Length();
364 TColStd_SequenceOfReal emptyseq1, emptyseq2;
365 TopTools_SequenceOfShape emptyedgeseq;
366 ParsNonSeam.Append( emptyseq1 );
367 Seam.Append( emptyedgeseq );
368 ParsSeam.Append( emptyseq2 );
370 if (! Emap.IsBound( CurEdge ))
372 TColStd_SequenceOfReal emptyseq;
373 Emap.Bind( CurEdge, emptyseq );
376 for (; EInter.MorePoint(); EInter.NextPoint())
378 const TopOpeBRep_Point2d& bp = EInter.Point();
381 gp_Pnt Pnt = bp.Value();
382 Standard_Integer ied = 0;
383 for (j = 1; j <= pts.Length(); j++)
384 if (Pnt.IsEqual( pts(j), Precision::Confusion() ))
392 edges.Append( anEdge );
393 pars.Append( bp.Parameter(2) );
394 Emap(CurEdge).Append( bp.Parameter(1) );
395 ParsNonSeam(ind).Append( bp.Parameter(2) );
396 Seam(ind).Append( CurEdge );
397 ParsSeam(ind).Append( bp.Parameter(1) );
402 Standard_Real ParOnSeam = bp.Parameter(1);
403 Standard_Real Par1 = pars(ied);
404 Standard_Real Par2 = bp.Parameter(2);
405 BRepAdaptor_Curve2d SeamCurve( CurEdge, CurFace );
406 BRepAdaptor_Curve2d Curve1( edges(ied), CurFace );
407 BRepAdaptor_Curve2d Curve2( anEdge. CurFace );
409 gp_Vec2d SeamDer, Der1, Der2;
410 //SeamCurve->D1( ParOnSeam, P2d, SeamDer );
411 //Curve1->D1( Par1, P2d, Der1 );
412 //Curve2->D1( Par2, P2d, Der2 );
413 Standard_Real Crossed1 = SeamDer ^ Der1;
414 Standard_Real Crossed2 = SeamDer ^ Der2;
419 else // ! bp.IsVertex(2)
421 //Temporary the case of tangency is not implemented
422 Emap(CurEdge).Append( bp.Parameter(1) );
423 ParsNonSeam(ind).Append( bp.Parameter(2) );
424 Seam(ind).Append( CurEdge );
425 ParsSeam(ind).Append( bp.Parameter(1) );
427 } //for (; EInter.MorePoint(); EInter.NextPoint())
428 } //for (; eit.More(); eit.Next())
431 if (! WWmap.IsBound( CurWire ))
433 TopTools_ListOfShape emptylist;
434 WWmap.Bind( CurWire, emptylist );
436 WWmap(CurWire).Append( aWire );
438 } //if (! aWire.IsSame( CurWire ))
439 } //for (; wit.More(); wit.Next())
440 } //for (i = 1; i <= Eseq.Length(); i++)
443 for (i = 1; i <= NonSeam.Length(); i++)
444 for (j = 1; j < ParsNonSeam(i).Length(); j++)
445 for (k = j+1; k <= ParsNonSeam(i).Length(); k++)
446 if (ParsNonSeam(i)(k) < ParsNonSeam(i)(j))
448 Standard_Real temp = ParsNonSeam(i)(j);
449 ParsNonSeam(i)(j) = ParsNonSeam(i)(k);
450 ParsNonSeam(i)(k) = temp;
451 TopoDS_Shape tmp = Seam(i)(j);
452 Seam(i)(j) = Seam(i)(k);
454 temp = ParsSeam(i)(j);
455 ParsSeam(i)(j) = ParsSeam(i)(k);
456 ParsSeam(i)(k) = temp;
458 BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal iter( Emap );
459 for (; iter.More(); iter.Next())
461 TColStd_SequenceOfReal Seq;
463 for (i = 1; i < Seq.Length(); i++)
464 for (j = i+1; j <= Seq.Length(); j++)
467 Standard_Real temp = Seq(i);
471 Emap( iter.Key() ) = Seq;
473 BRepFill_DataMapOfShapeSequenceOfReal EPmap;
474 TopTools_DataMapOfShapeSequenceOfShape EVmap; //Seam
475 TopTools_DataMapOfShapeSequenceOfShape EWmap; //Seam and wires intersecting it
476 iter.Initialize( Emap );
477 for (; iter.More(); iter.Next())
479 TColStd_SequenceOfReal parseq;
480 EPmap.Bind( iter.Key(), parseq );
481 TopTools_SequenceOfShape shapeseq;
482 EVmap.Bind( iter.Key(), shapeseq );
483 TopTools_SequenceOfShape shapeseq2;
484 EWmap.Bind( iter.Key(), shapeseq2 );
487 //Reconstruction of non-seam edges
488 BRepTools_Substitution aSub;
490 for (i = 1; i <= NonSeam.Length(); i++)
492 TopoDS_Edge anEdge = TopoDS::Edge( NonSeam(i) );
493 TopTools_ListOfShape NewEdges;
495 TopoDS_Vertex Vfirst, Vlast;
496 TopExp::Vertices( anEdge, Vfirst, Vlast );
497 Standard_Real par, FirstPar, LastPar;
498 BRep_Tool::Range( anEdge, FirstPar, LastPar );
499 Standard_Integer firstind = 1;
500 par = ParsNonSeam(i)(1);
501 TopoDS_Edge SeamEdge = TopoDS::Edge( Seam(i)(1) );
503 for (j = 1; j <= Eseq.Length(); j++)
504 if (SeamEdge.IsSame( Eseq(j) ))
506 TopoDS_Face theFace = TopoDS::Face( Fseq(j) );
508 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( theFace, L );
509 if (Abs(par-FirstPar) <= Precision::Confusion())
511 BB.UpdateVertex( Vfirst, ParsSeam(i)(1), SeamEdge, BRep_Tool::Tolerance(Vfirst) );
512 EPmap( SeamEdge ).Append( ParsSeam(i)(1) );
513 EVmap( SeamEdge ).Append( Vfirst );
514 EWmap( SeamEdge ).Append( NonSeamWires(i) );
517 Standard_Real prevpar = FirstPar;
518 TopoDS_Vertex PrevV = Vfirst;
519 for (j = firstind; j <= ParsNonSeam(i).Length(); j++)
521 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
522 NewE = TopoDS::Edge( aLocalShape );
523 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
525 par = ParsNonSeam(i)(j);
526 BB.Range( NewE, prevpar, par );
527 SeamEdge = TopoDS::Edge( Seam(i)(j) );
528 if (j == ParsNonSeam(i).Length() && Abs(par-LastPar) <= Precision::Confusion())
531 if (firstind == 2 && j == 2)
533 BB.UpdateVertex( Vlast, ParsSeam(i)(j), SeamEdge, BRep_Tool::Tolerance(Vlast) );
534 EPmap( SeamEdge ).Append( ParsSeam(i)(j) );
535 EVmap( SeamEdge ).Append( Vlast );
536 EWmap( SeamEdge ).Append( NonSeamWires(i) );
542 BRepAdaptor_Curve bcur( NewE );
543 gp_Pnt Point = bcur.Value( par );
544 NewV = BRepLib_MakeVertex( Point );
545 BB.UpdateVertex( NewV, par, NewE, 10.*Precision::Confusion() );
547 BB.UpdateVertex( NewV, ParsSeam(i)(j), SeamEdge, 10.*Precision::Confusion() );
548 NewE.Orientation( TopAbs_FORWARD );
549 BB.Add( NewE, PrevV.Oriented(TopAbs_FORWARD) );
550 BB.Add( NewE, NewV.Oriented(TopAbs_REVERSED) );
552 NewEdges.Append( NewE );
553 EPmap( SeamEdge ).Append( ParsSeam(i)(j) );
554 EVmap( SeamEdge ).Append( NewV );
555 EWmap( SeamEdge ).Append( NonSeamWires(i) );
561 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
562 NewE = TopoDS::Edge( aLocalShape );
563 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
565 if (Abs(prevpar-par) > Precision::Confusion())
567 BB.Range( NewE, prevpar, par );
568 NewE.Orientation( TopAbs_FORWARD );
569 BB.Add( NewE, PrevV.Oriented(TopAbs_FORWARD) );
570 BB.Add( NewE, Vlast.Oriented(TopAbs_REVERSED) );
571 NewEdges.Append( NewE );
574 //Substitute anEdge by NewEdges
575 aSub.Substitute( anEdge, NewEdges );
578 //Sorting of EPmap and EVmap and removing repeating points from them
579 iter.Initialize( EPmap );
580 for (; iter.More(); iter.Next())
582 TColStd_SequenceOfReal Seq;
584 TopTools_SequenceOfShape SeqShape;
585 SeqShape = EVmap( iter.Key() );
586 TopTools_SequenceOfShape SeqShape2;
587 SeqShape2 = EWmap( iter.Key() );
588 for (i = 1; i < Seq.Length(); i++)
589 for (j = i+1; j <= Seq.Length(); j++)
592 Standard_Real temp = Seq(i);
595 TopoDS_Shape tmp = SeqShape(i);
596 SeqShape(i) = SeqShape(j);
599 SeqShape2(i) = SeqShape2(j);
602 EPmap( iter.Key() ) = Seq;
603 EVmap( iter.Key() ) = SeqShape;
604 EWmap( iter.Key() ) = SeqShape2;
606 iter.Initialize( EPmap );
607 for (; iter.More(); iter.Next())
609 TColStd_SequenceOfReal Seq;
611 TopTools_SequenceOfShape SeqShape;
612 SeqShape = EVmap( iter.Key() );
613 TopTools_SequenceOfShape SeqShape2;
614 SeqShape2 = EWmap( iter.Key() );
615 Standard_Boolean remove = Standard_True;
618 remove = Standard_False;
619 for (i = 1; i < Seq.Length(); i++)
620 if (Abs(Seq(i)-Seq(i+1)) <= Precision::Confusion())
623 SeqShape.Remove(i+1);
624 SeqShape2.Remove(i+1);
625 remove = Standard_True;
628 EPmap( iter.Key() ) = Seq;
629 EVmap( iter.Key() ) = SeqShape;
630 EWmap( iter.Key() ) = SeqShape2;
633 //Reconstruction of seam edges
634 TopTools_DataMapOfShapeShape VEmap;
635 iter.Initialize( Emap );
636 for (; iter.More(); iter.Next())
638 TopoDS_Edge anEdge = TopoDS::Edge( iter.Key() );
639 Standard_Boolean onepoint = Standard_False;
640 TopTools_ListOfShape NewEdges;
641 TColStd_SequenceOfReal Seq;
643 TColStd_SequenceOfReal Seq2;
644 Seq2 = EPmap( anEdge );
645 TopTools_SequenceOfShape SeqVer;
646 SeqVer = EVmap( anEdge );
647 TopTools_SequenceOfShape SeqWire;
648 SeqWire = EWmap( anEdge );
649 TopoDS_Vertex Vfirst, Vlast;
650 TopExp::Vertices( anEdge, Vfirst, Vlast );
651 Standard_Real fpar, lpar, FirstPar, LastPar;
652 BRep_Tool::Range( anEdge, FirstPar, LastPar );
656 Standard_Integer firstind = 1;
657 if (Abs(fpar-lpar) <= Precision::Confusion())
665 if (Seq.Length()%2 != 0)
667 VEmap.Bind( Vfirst, anEdge );
670 if (Seq.Length() > 2)
673 onepoint = Standard_True;
678 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
679 NewE = TopoDS::Edge( aLocalShape );
680 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
681 BB.Range( NewE, fpar, lpar );
682 NewE.Orientation( TopAbs_FORWARD );
685 BB.Add( NewE, Vfirst.Oriented(TopAbs_FORWARD) );
686 aLocalShape = SeqVer(1).Oriented(TopAbs_REVERSED);
687 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
688 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_REVERSED) ) );
692 aLocalShape = SeqVer(1).Oriented(TopAbs_FORWARD);
693 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
694 aLocalShape = SeqVer(2).Oriented(TopAbs_REVERSED);
695 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
696 //BB.Add( NewE, TopoDS::Vertex( SeqVer(1).Oriented(TopAbs_FORWARD) ) );
697 //BB.Add( NewE, TopoDS::Vertex( SeqVer(2).Oriented(TopAbs_REVERSED) ) );
699 NewEdges.Append( NewE );
702 for (i = firstind; i < Seq.Length(); i += 2)
704 aLocalShape = anEdge.EmptyCopied();
705 NewE = TopoDS::Edge( aLocalShape );
706 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
709 BB.Range( NewE, fpar, lpar );
711 for (j = 1; j <= Seq2.Length(); j++)
712 if (Abs(fpar-Seq2(j)) <= Precision::Confusion())
714 NewE.Orientation( TopAbs_FORWARD );
715 TopoDS_Shape aLocalShape = SeqVer(j).Oriented(TopAbs_FORWARD);
716 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
717 aLocalShape = SeqVer(j+1).Oriented(TopAbs_REVERSED);
718 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
719 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j).Oriented(TopAbs_FORWARD) ) );
720 //BB.Add( NewE, TopoDS::Vertex( SeqVer(j+1).Oriented(TopAbs_REVERSED) ) );
721 NewEdges.Append( NewE );
728 if (Abs(fpar-lpar) <= Precision::Confusion())
730 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
731 NewE = TopoDS::Edge( aLocalShape );
732 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
733 BB.Range( NewE, fpar, lpar );
734 NewE.Orientation( TopAbs_FORWARD );
735 aLocalShape = SeqVer(SeqVer.Length()).Oriented(TopAbs_FORWARD);
736 BB.Add( NewE, TopoDS::Vertex( aLocalShape ) );
737 //BB.Add( NewE, TopoDS::Vertex( SeqVer(SeqVer.Length()).Oriented(TopAbs_FORWARD) ) );
738 BB.Add( NewE, Vlast.Oriented(TopAbs_REVERSED) );
739 NewEdges.Append( NewE );
741 //Substitute anEdge by NewEdges
742 aSub.Substitute( anEdge, NewEdges );
745 //Removing edges connected with missing extremities of seam edges
746 TopTools_DataMapIteratorOfDataMapOfShapeShape itve( VEmap );
747 for (; itve.More(); itve.Next())
749 TopoDS_Shape V = itve.Key();
750 TopoDS_Shape E = itve.Value();
752 for (i = 1; i <= Eseq.Length(); i++)
753 if (E.IsSame( Eseq(i) ))
758 TopoDS_Shape Etoremove;
760 for (; eit.More(); eit.Next())
762 TopoDS_Edge CurE = TopoDS::Edge( eit.Value() );
763 if (CurE.IsSame( E ))
765 TopoDS_Vertex Vfirst, Vlast;
766 TopExp::Vertices( CurE, Vfirst, Vlast );
767 if (Vfirst.IsSame( V ) || Vlast.IsSame( V ))
773 if (! Etoremove.IsNull())
775 W.Free( Standard_True );
776 BB.Remove( W, Etoremove );
780 aSub.Build( myShape );
781 if (aSub.IsCopied( myShape ))
783 const TopTools_ListOfShape& listSh = aSub.Copy( myShape );
784 if (! listSh.IsEmpty())
785 myShape = listSh.First();
788 //Reconstruction of wires
789 TopTools_ListOfShape theCopy;
790 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itww( WWmap );
791 for (; itww.More(); itww.Next())
793 CurWire = itww.Key();
794 theCopy = aSub.Copy( CurWire );
795 CurWire = theCopy.First();
796 CurWire.Free( Standard_True );
797 TopTools_ListIteratorOfListOfShape itl( itww.Value() );
798 for (; itl.More(); itl.Next())
800 TopoDS_Shape aWire = itl.Value();
801 CurFace = WFmap( aWire );
802 theCopy = aSub.Copy( aWire );
803 aWire = theCopy.First();
806 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( TopoDS::Face(CurFace), L );
807 eit.Initialize( aWire );
808 for (; eit.More(); eit.Next())
810 TopoDS_Edge anEdge = TopoDS::Edge( eit.Value() );
811 gp_Pnt2d Pfirst, Plast, Pmid;
812 BRep_Tool::UVPoints( anEdge, TopoDS::Face(CurFace), Pfirst, Plast );
813 BRepAdaptor_Curve2d bc2d( anEdge, TopoDS::Face(CurFace) );
814 Pmid = bc2d.Value( (bc2d.FirstParameter()+bc2d.LastParameter())/2. );
816 Standard_Boolean translate = Standard_False;
817 if (Pfirst.X()-2.*M_PI > Precision::Confusion() ||
818 Plast.X()-2.*M_PI > Precision::Confusion() ||
819 Pmid.X()-2.*M_PI > Precision::Confusion())
821 offset.SetCoord( -2.*M_PI, 0 );
822 translate = Standard_True;
824 if (Pfirst.X() < -Precision::Confusion() ||
825 Plast.X() < -Precision::Confusion() ||
826 Pmid.X() < -Precision::Confusion())
828 offset.SetCoord( 2.*M_PI, 0 );
829 translate = Standard_True;
833 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
834 BRep_ListIteratorOfListOfCurveRepresentation itcr( TE->ChangeCurves() );
835 Handle(BRep_GCurve) GC;
837 for (; itcr.More(); itcr.Next())
839 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
840 if (!GC.IsNull() && GC->IsCurveOnSurface( theSurf, L ))
842 Handle(Geom2d_Curve) PC = GC->PCurve();
843 PC = Handle(Geom2d_Curve)::DownCast( PC->Translated( offset ) );
845 TE->ChangeCurves().Remove( itcr );
846 TE->ChangeCurves().Append( GC );
853 eit.Initialize( aWire, Standard_False );
854 for (; eit.More(); eit.Next())
856 TopoDS_Shape anEdge = eit.Value();
857 BB.Add( CurWire, anEdge );
859 if (aSub.IsCopied( CurFace ))
861 theCopy = aSub.Copy( CurFace );
862 CurFace = theCopy.First();
864 CurFace.Free( Standard_True );
865 BB.Remove( CurFace, aWire );