0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / BRepOffsetAPI / BRepOffsetAPI_DraftAngle.cxx
CommitLineData
b311480e 1// Created on: 1995-02-22
2// Created by: Jacques GOUSSARD
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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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#include <BRepOffsetAPI_DraftAngle.ixx>
18
19#include <Draft_Modification.hxx>
20#include <TopoDS.hxx>
21#include <Geom_Surface.hxx>
22#include <TopLoc_Location.hxx>
23
24#include <TopTools_ListIteratorOfListOfShape.hxx>
25
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>
43#include <TopExp.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>
52
53//=======================================================================
54//function : BRepOffsetAPI_DraftAngle
55//purpose :
56//=======================================================================
57
58BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle () {}
59
60
61//=======================================================================
62//function : BRepOffsetAPI_DraftAngle
63//purpose :
64//=======================================================================
65
66BRepOffsetAPI_DraftAngle::BRepOffsetAPI_DraftAngle (const TopoDS_Shape& S)
67{
68 myInitialShape = S;
69 myModification = new Draft_Modification(S);
70}
71
72
73//=======================================================================
74//function : Clear
75//purpose :
76//=======================================================================
77
78void BRepOffsetAPI_DraftAngle::Clear ()
79{
80 if (!myModification.IsNull()) {
81 (*((Handle(Draft_Modification)*)&myModification))->Clear();
82 }
83}
84
85
86//=======================================================================
87//function : Init
88//purpose :
89//=======================================================================
90
91void BRepOffsetAPI_DraftAngle::Init (const TopoDS_Shape& S)
92{
93 myInitialShape = S;
94 NotDone();
95 if (!myModification.IsNull()) {
96 (*((Handle(Draft_Modification)*)&myModification))->Init(S);
97 }
98 else {
99 myModification = new Draft_Modification(S);
100 }
101}
102
103
104//=======================================================================
105//function : Add
106//purpose :
107//=======================================================================
108
109void BRepOffsetAPI_DraftAngle::Add(const TopoDS_Face& F,
110 const gp_Dir& D,
111 const Standard_Real Angle,
112 const gp_Pln& Plane,
113 const Standard_Boolean Flag)
114{
115// POP-DPF : protection
116 if ( Abs(Angle) <= 1.e-04 )
117 return;
118 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
119 (*((Handle(Draft_Modification)*)&myModification))->Add(F,D,Angle,Plane, Flag);
120}
121
122
123//=======================================================================
124//function : AddDone
125//purpose :
126//=======================================================================
127
128Standard_Boolean BRepOffsetAPI_DraftAngle::AddDone () const
129{
130 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
131 return (*((Handle(Draft_Modification)*)&myModification))
132 ->ProblematicShape().IsNull();
133}
134
135
136//=======================================================================
137//function : Remove
138//purpose :
139//=======================================================================
140
141void BRepOffsetAPI_DraftAngle::Remove(const TopoDS_Face& F)
142{
143 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
144 (*((Handle(Draft_Modification)*)&myModification))->Remove(F);
145}
146
147
148//=======================================================================
149//function : ProblematicShape
150//purpose :
151//=======================================================================
152
153const TopoDS_Shape& BRepOffsetAPI_DraftAngle::ProblematicShape () const
154{
155 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
156 return (*((Handle(Draft_Modification)*)&myModification))->ProblematicShape();
157}
158
159
160//=======================================================================
161//function : ErrorStatus
162//purpose :
163//=======================================================================
164
165Draft_ErrorStatus BRepOffsetAPI_DraftAngle::Status () const
166{
167 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
168 return (*((Handle(Draft_Modification)*)&myModification))->Error();
169}
170
171
172//=======================================================================
173//function : ConnectedFaces
174//purpose :
175//=======================================================================
176
177const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ConnectedFaces
178 (const TopoDS_Face& F) const
179{
180 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
181 return (*((Handle(Draft_Modification)*)&myModification))->ConnectedFaces(F);
182}
183
184
185//=======================================================================
186//function : ModifiedFaces
187//purpose :
188//=======================================================================
189
190const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::ModifiedFaces() const
191{
192 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
193 return (*((Handle(Draft_Modification)*)&myModification))->ModifiedFaces();
194}
195
196//=======================================================================
197//function : ModifiedFaces
198//purpose :
199//=======================================================================
200
201const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Generated(const TopoDS_Shape& S)
202{
203 myGenerated.Clear();
204 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
205 Handle(Draft_Modification) DMod = (*((Handle(Draft_Modification)*)&myModification));
206
207 if (S.ShapeType() == TopAbs_FACE) {
208 Handle(Geom_Surface) Surf;
209 TopLoc_Location L;
210 Standard_Real Tol;
211 Standard_Boolean RW,RF;
212 if (DMod->NewSurface(TopoDS::Face(S), Surf, L, Tol, RW, RF)) {
213 myGenerated.Append(ModifiedShape (S));
214
215 }
216 }
217 return myGenerated;
218}
219
220//=======================================================================
221//function : ModifiedFaces
222//purpose :
223//=======================================================================
224
225const TopTools_ListOfShape& BRepOffsetAPI_DraftAngle::Modified(const TopoDS_Shape& S)
226{
227 myGenerated.Clear();
228 Standard_NullObject_Raise_if(myInitialShape.IsNull(),"");
229 Handle(Draft_Modification) DMod = (*((Handle(Draft_Modification)*)&myModification));
230
231 if (S.ShapeType() == TopAbs_FACE) {
232 Handle(Geom_Surface) Surf;
233 TopLoc_Location L;
234 Standard_Real Tol;
235 Standard_Boolean RW,RF;
236
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)) {
241 myGenerated.Clear();
242 }
243 }
244 }
245 return myGenerated;
246}
247
248
249//=======================================================================
250//function : Build
251//purpose :
252//=======================================================================
253
254void BRepOffsetAPI_DraftAngle::Build()
255{
256 (*((Handle(Draft_Modification)*)&myModification))->Perform();
257 if (!(*((Handle(Draft_Modification)*)&myModification))->IsDone()) {
258 NotDone();
259 }
260 else {
261 DoModif(myInitialShape);
262 //BRepLib::SameParameter( myShape, 1.0e-7, Standard_True ); //patch
263 CorrectWires();
264 BRepLib::SameParameter( myShape, 1.0e-7, Standard_True ); //patch
265 }
266}
267
268//=======================================================================
269//function : CorrectWires
270//purpose :
271//=======================================================================
272
273void BRepOffsetAPI_DraftAngle::CorrectWires()
274{
275 Standard_Real TolInter = 1.e-7;
276 Standard_Integer i, j, k;
277
278 TopTools_SequenceOfShape Eseq;
279 TopTools_SequenceOfShape Wseq;
280 TopTools_SequenceOfShape Fseq;
281 TopoDS_Shape CurEdge, CurWire, CurFace;
282 TopoDS_Iterator wit, eit;
283
284 TopExp_Explorer fexp( myShape, TopAbs_FACE );
285 for (; fexp.More(); fexp.Next())
286 {
287 CurFace = fexp.Current();
288 wit.Initialize( CurFace );
289 for (; wit.More(); wit.Next())
290 {
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())
298 {
299 CurEdge = mapit.Key();
300 if (BRepTools::IsReallyClosed( TopoDS::Edge(CurEdge), TopoDS::Face(CurFace) ))
301 {
302 Eseq.Append( CurEdge );
303 Wseq.Append( CurWire );
304 Fseq.Append( CurFace );
305 }
306 }
307 }
308 }
309
310 BRepFill_DataMapOfShapeSequenceOfReal Emap;
311
312 TopTools_SequenceOfShape NonSeam;
313 TopTools_SequenceOfShape NonSeamWires;
314 BRepOffsetAPI_SequenceOfSequenceOfReal ParsNonSeam;
315 BRepOffsetAPI_SequenceOfSequenceOfShape Seam;
316 BRepOffsetAPI_SequenceOfSequenceOfReal ParsSeam;
317
318 TopTools_DataMapOfShapeShape WFmap;
319 TopTools_DataMapOfShapeListOfShape WWmap;
320 for (i = 1; i <= Eseq.Length(); i++)
321 {
322 CurEdge = Eseq(i);
323 CurWire = Wseq(i);
324 CurFace = Fseq(i);
325 wit.Initialize( CurFace );
326 for (; wit.More(); wit.Next())
327 {
328 TopoDS_Shape aWire = wit.Value();
329 if (! aWire.IsSame( CurWire ))
330 {
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())
337 {
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())
344 {
345 EInter.Perform( CurEdge.Reversed(), anEdge );
346 if (EInter.IsEmpty())
347 continue;
348 }
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) ))
355 {
356 ind = j;
357 break;
358 }
359 if (ind == 0)
360 {
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 );
369 }
370 if (! Emap.IsBound( CurEdge ))
371 {
372 TColStd_SequenceOfReal emptyseq;
373 Emap.Bind( CurEdge, emptyseq );
374 }
375 EInter.InitPoint();
376 for (; EInter.MorePoint(); EInter.NextPoint())
377 {
378 const TopOpeBRep_Point2d& bp = EInter.Point();
379 if (bp.IsVertex(2))
380 {
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() ))
385 {
386 ied = j;
387 break;
388 }
389 if (ied == 0)
390 {
391 pts.Append( Pnt );
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) );
398 }
399 /*
400 else
401 {
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 );
408 gp_Pnt2d P2d;
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;
415 //if (Crossed1 > 0
416 }
417 */
418 }
419 else // ! bp.IsVertex(2)
420 {
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) );
426 }
427 } //for (; EInter.MorePoint(); EInter.NextPoint())
428 } //for (; eit.More(); eit.Next())
429 if (Wadd)
430 {
431 if (! WWmap.IsBound( CurWire ))
432 {
433 TopTools_ListOfShape emptylist;
434 WWmap.Bind( CurWire, emptylist );
435 }
436 WWmap(CurWire).Append( aWire );
437 }
438 } //if (! aWire.IsSame( CurWire ))
439 } //for (; wit.More(); wit.Next())
440 } //for (i = 1; i <= Eseq.Length(); i++)
441
442 //Sorting
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))
447 {
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);
453 Seam(i)(k) = tmp;
454 temp = ParsSeam(i)(j);
455 ParsSeam(i)(j) = ParsSeam(i)(k);
456 ParsSeam(i)(k) = temp;
457 }
458 BRepFill_DataMapIteratorOfDataMapOfShapeSequenceOfReal iter( Emap );
459 for (; iter.More(); iter.Next())
460 {
461 TColStd_SequenceOfReal Seq;
462 Seq = iter.Value();
463 for (i = 1; i < Seq.Length(); i++)
464 for (j = i+1; j <= Seq.Length(); j++)
465 if (Seq(j) < Seq(i))
466 {
467 Standard_Real temp = Seq(i);
468 Seq(i) = Seq(j);
469 Seq(j) = temp;
470 }
471 Emap( iter.Key() ) = Seq;
472 }
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())
478 {
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 );
485 }
486
487 //Reconstruction of non-seam edges
488 BRepTools_Substitution aSub;
489 BRep_Builder BB;
490 for (i = 1; i <= NonSeam.Length(); i++)
491 {
492 TopoDS_Edge anEdge = TopoDS::Edge( NonSeam(i) );
493 TopTools_ListOfShape NewEdges;
494 TopoDS_Edge NewE;
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) );
502 //Find the face
503 for (j = 1; j <= Eseq.Length(); j++)
504 if (SeamEdge.IsSame( Eseq(j) ))
505 break;
506 TopoDS_Face theFace = TopoDS::Face( Fseq(j) );
507 TopLoc_Location L;
508 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( theFace, L );
509 if (Abs(par-FirstPar) <= Precision::Confusion())
510 {
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) );
515 firstind = 2;
516 }
517 Standard_Real prevpar = FirstPar;
518 TopoDS_Vertex PrevV = Vfirst;
519 for (j = firstind; j <= ParsNonSeam(i).Length(); j++)
520 {
521 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
522 NewE = TopoDS::Edge( aLocalShape );
523 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
524 TopoDS_Vertex NewV;
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())
529 {
530 NewV = Vlast;
531 if (firstind == 2 && j == 2)
532 {
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) );
537 break;
538 }
539 }
540 else
541 {
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() );
546 }
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) );
551
552 NewEdges.Append( NewE );
553 EPmap( SeamEdge ).Append( ParsSeam(i)(j) );
554 EVmap( SeamEdge ).Append( NewV );
555 EWmap( SeamEdge ).Append( NonSeamWires(i) );
556
557 prevpar = par;
558 PrevV = NewV;
559 }
560 //The last edge
561 TopoDS_Shape aLocalShape = anEdge.EmptyCopied();
562 NewE = TopoDS::Edge( aLocalShape );
563 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
564 par = LastPar;
565 if (Abs(prevpar-par) > Precision::Confusion())
566 {
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 );
572 }
573
574 //Substitute anEdge by NewEdges
575 aSub.Substitute( anEdge, NewEdges );
576 }
577
578 //Sorting of EPmap and EVmap and removing repeating points from them
579 iter.Initialize( EPmap );
580 for (; iter.More(); iter.Next())
581 {
582 TColStd_SequenceOfReal Seq;
583 Seq = iter.Value();
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++)
590 if (Seq(j) < Seq(i))
591 {
592 Standard_Real temp = Seq(i);
593 Seq(i) = Seq(j);
594 Seq(j) = temp;
595 TopoDS_Shape tmp = SeqShape(i);
596 SeqShape(i) = SeqShape(j);
597 SeqShape(j) = tmp;
598 tmp = SeqShape2(i);
599 SeqShape2(i) = SeqShape2(j);
600 SeqShape2(j) = tmp;
601 }
602 EPmap( iter.Key() ) = Seq;
603 EVmap( iter.Key() ) = SeqShape;
604 EWmap( iter.Key() ) = SeqShape2;
605 }
606 iter.Initialize( EPmap );
607 for (; iter.More(); iter.Next())
608 {
609 TColStd_SequenceOfReal Seq;
610 Seq = iter.Value();
611 TopTools_SequenceOfShape SeqShape;
612 SeqShape = EVmap( iter.Key() );
613 TopTools_SequenceOfShape SeqShape2;
614 SeqShape2 = EWmap( iter.Key() );
615 Standard_Boolean remove = Standard_True;
616 while (remove)
617 {
618 remove = Standard_False;
619 for (i = 1; i < Seq.Length(); i++)
620 if (Abs(Seq(i)-Seq(i+1)) <= Precision::Confusion())
621 {
622 Seq.Remove(i+1);
623 SeqShape.Remove(i+1);
624 SeqShape2.Remove(i+1);
625 remove = Standard_True;
626 }
627 }
628 EPmap( iter.Key() ) = Seq;
629 EVmap( iter.Key() ) = SeqShape;
630 EWmap( iter.Key() ) = SeqShape2;
631 }
632
633 //Reconstruction of seam edges
634 TopTools_DataMapOfShapeShape VEmap;
635 iter.Initialize( Emap );
636 for (; iter.More(); iter.Next())
637 {
638 TopoDS_Edge anEdge = TopoDS::Edge( iter.Key() );
639 Standard_Boolean onepoint = Standard_False;
640 TopTools_ListOfShape NewEdges;
641 TColStd_SequenceOfReal Seq;
642 Seq = iter.Value();
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 );
653 fpar = FirstPar;
654 lpar = Seq(1);
655 TopoDS_Edge NewE;
656 Standard_Integer firstind = 1;
657 if (Abs(fpar-lpar) <= Precision::Confusion())
658 {
659 firstind = 2;
660 fpar = Seq(1);
661 lpar = Seq(2);
662 }
663 else
664 {
665 if (Seq.Length()%2 != 0)
666 {
667 VEmap.Bind( Vfirst, anEdge );
668 firstind = 2;
669 fpar = Seq(1);
670 if (Seq.Length() > 2)
671 lpar = Seq(2);
672 else
673 onepoint = Standard_True;
674 }
675 }
676 if (!onepoint)
677 {
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 );
683 if (firstind == 1)
684 {
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) ) );
689 }
690 else
691 {
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) ) );
698 }
699 NewEdges.Append( NewE );
700
701 firstind++;
702 for (i = firstind; i < Seq.Length(); i += 2)
703 {
704 aLocalShape = anEdge.EmptyCopied();
705 NewE = TopoDS::Edge( aLocalShape );
706 //NewE = TopoDS::Edge( anEdge.EmptyCopied() );
707 fpar = Seq(i);
708 lpar = Seq(i+1);
709 BB.Range( NewE, fpar, lpar );
710 //Find vertices
711 for (j = 1; j <= Seq2.Length(); j++)
712 if (Abs(fpar-Seq2(j)) <= Precision::Confusion())
713 break;
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 );
722 }
723 }
724
725 i = Seq.Length();
726 fpar = Seq(i);
727 lpar = LastPar;
728 if (Abs(fpar-lpar) <= Precision::Confusion())
729 continue;
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 );
740
741 //Substitute anEdge by NewEdges
742 aSub.Substitute( anEdge, NewEdges );
743 }
744
745 //Removing edges connected with missing extremities of seam edges
746 TopTools_DataMapIteratorOfDataMapOfShapeShape itve( VEmap );
747 for (; itve.More(); itve.Next())
748 {
749 TopoDS_Shape V = itve.Key();
750 TopoDS_Shape E = itve.Value();
751 TopoDS_Shape W;
752 for (i = 1; i <= Eseq.Length(); i++)
753 if (E.IsSame( Eseq(i) ))
754 {
755 W = Wseq(i);
756 break;
757 }
758 TopoDS_Shape Etoremove;
759 eit.Initialize( W );
760 for (; eit.More(); eit.Next())
761 {
762 TopoDS_Edge CurE = TopoDS::Edge( eit.Value() );
763 if (CurE.IsSame( E ))
764 continue;
765 TopoDS_Vertex Vfirst, Vlast;
766 TopExp::Vertices( CurE, Vfirst, Vlast );
767 if (Vfirst.IsSame( V ) || Vlast.IsSame( V ))
768 {
769 Etoremove = CurE;
770 break;
771 }
772 }
773 if (! Etoremove.IsNull())
774 {
775 W.Free( Standard_True );
776 BB.Remove( W, Etoremove );
777 }
778 }
779
780 aSub.Build( myShape );
781 if (aSub.IsCopied( myShape ))
782 {
783 const TopTools_ListOfShape& listSh = aSub.Copy( myShape );
784 if (! listSh.IsEmpty())
785 myShape = listSh.First();
786 }
787
788 //Reconstruction of wires
789 TopTools_ListOfShape theCopy;
790 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itww( WWmap );
791 for (; itww.More(); itww.Next())
792 {
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())
799 {
800 TopoDS_Shape aWire = itl.Value();
801 CurFace = WFmap( aWire );
802 theCopy = aSub.Copy( aWire );
803 aWire = theCopy.First();
804 //Adjusting period
805 TopLoc_Location L;
806 Handle( Geom_Surface ) theSurf = BRep_Tool::Surface( TopoDS::Face(CurFace), L );
807 eit.Initialize( aWire );
808 for (; eit.More(); eit.Next())
809 {
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. );
815 gp_Vec2d offset;
816 Standard_Boolean translate = Standard_False;
c6541a0c
D
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())
7fd59977 820 {
c6541a0c 821 offset.SetCoord( -2.*M_PI, 0 );
7fd59977 822 translate = Standard_True;
823 }
824 if (Pfirst.X() < -Precision::Confusion() ||
825 Plast.X() < -Precision::Confusion() ||
826 Pmid.X() < -Precision::Confusion())
827 {
c6541a0c 828 offset.SetCoord( 2.*M_PI, 0 );
7fd59977 829 translate = Standard_True;
830 }
831 if (translate)
832 {
833 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
834 BRep_ListIteratorOfListOfCurveRepresentation itcr( TE->ChangeCurves() );
835 Handle(BRep_GCurve) GC;
836
837 for (; itcr.More(); itcr.Next())
838 {
839 GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
840 if (!GC.IsNull() && GC->IsCurveOnSurface( theSurf, L ))
841 {
842 Handle(Geom2d_Curve) PC = GC->PCurve();
843 PC = Handle(Geom2d_Curve)::DownCast( PC->Translated( offset ) );
844 GC->PCurve( PC );
845 TE->ChangeCurves().Remove( itcr );
846 TE->ChangeCurves().Append( GC );
847 break;
848 }
849 }
850 }
851 }
852 ///////////////////
853 eit.Initialize( aWire, Standard_False );
854 for (; eit.More(); eit.Next())
855 {
856 TopoDS_Shape anEdge = eit.Value();
857 BB.Add( CurWire, anEdge );
858 }
859 if (aSub.IsCopied( CurFace ))
860 {
861 theCopy = aSub.Copy( CurFace );
862 CurFace = theCopy.First();
863 }
864 CurFace.Free( Standard_True );
865 BB.Remove( CurFace, aWire );
866 }
867 }
868}