summaryrefslogtreecommitdiff
path: root/src/ShapeAlgo/ShapeAlgo_AlgoContainer.cxx
blob: 9a9141c2b5b97b93a75410d1d8518a27f70c014a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
// File:      ShapeAlgo_AlgoContainer.cxx
// Created:   Mon Feb  7 12:22:00 2000
// Author:    data exchange team
// Copyright: OPEN CASCADE 2000

#include <ShapeAlgo_AlgoContainer.ixx>

#include <GeomInt_WLApprox.hxx>
#include <IntSurf_LineOn2S.hxx>
#include <IntSurf_PntOn2S.hxx>
#include <IntPatch_WLine.hxx>

#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp.hxx>

#include <Precision.hxx>

#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>

#include <ShapeBuild_Edge.hxx>
#include <ShapeConstruct.hxx>
#include <ShapeCustom.hxx>
#include <ShapeCustom_Surface.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeAnalysis_Edge.hxx>
#include <ShapeFix.hxx>
#include <ShapeFix_Edge.hxx>
#include <ShapeUpgrade.hxx>
#include <ShapeUpgrade_ShapeDivideContinuity.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeExtend_WireData.hxx>
#include <TopExp.hxx>
#include <gp_Pnt.hxx>
#include <Precision.hxx>
#include <ShapeFix_Wire.hxx>
#include <BRepTools.hxx>

//=======================================================================
//function : ShapeAlgo_AlgoContainer
//purpose  : 
//=======================================================================

ShapeAlgo_AlgoContainer::ShapeAlgo_AlgoContainer()
{
  myTC = new ShapeAlgo_ToolContainer;
}

//=======================================================================
//function : ConnectNextWire
//purpose  : 
//=======================================================================

Standard_Boolean ShapeAlgo_AlgoContainer::ConnectNextWire (const Handle(ShapeAnalysis_Wire)& saw,
                                                           const Handle(ShapeExtend_WireData)& nextsewd,
                                                           const Standard_Real maxtol,
                                                           Standard_Real& distmin,
                                                           Standard_Boolean& revsewd,
                                                           Standard_Boolean& revnextsewd) const
{
  distmin = 0;
  revsewd = revnextsewd = Standard_False;
  if (nextsewd->NbEdges() == 0) return Standard_True;
  
  Handle(ShapeExtend_WireData) sewd = saw->WireData();
  //add edges into empty WireData
  if(sewd->NbEdges() == 0) {
    sewd->Add (nextsewd);
    return Standard_True;
  }
  
  Standard_Real tailhead, tailtail, headtail, headhead;
  saw->CheckShapeConnect (tailhead, tailtail, headtail, headhead, nextsewd->Wire(), maxtol);
  distmin = tailhead;
  Standard_Real precision = saw->Precision();
  
  if ( tailhead > precision && tailtail > precision &&
       ( saw->LastCheckStatus (ShapeExtend_DONE4) ||
	 saw->LastCheckStatus (ShapeExtend_DONE3) ) ) {
    sewd->Reverse();
    distmin = headhead;
    revsewd = Standard_True;
    if (saw->LastCheckStatus (ShapeExtend_DONE3)) {
      nextsewd->Reverse();
      revnextsewd = Standard_True;
      distmin = headtail;
    }
  }
  else if (!saw->LastCheckStatus (ShapeExtend_FAIL) && !saw->LastCheckStatus (ShapeExtend_DONE5)) {
    nextsewd->Reverse();
    revnextsewd = Standard_True;
    distmin     = tailtail;
  }
  Standard_Boolean OK = !saw->LastCheckStatus (ShapeExtend_FAIL);
  if (OK) sewd->Add (nextsewd);
  return OK;
}

//=======================================================================
//function : ApproxBSplineCurve
//purpose  : 
//=======================================================================

void ShapeAlgo_AlgoContainer::ApproxBSplineCurve (const Handle(Geom_BSplineCurve)& bspline,
                                                  TColGeom_SequenceOfCurve& seq) const
{
  seq.Clear();
  Handle(Geom_BSplineCurve)  res, modifCurve;
  TColGeom_SequenceOfCurve SCurve;

  // si la BSpline est de degre 1 , on approxime .
  // on passe par le programme des intersections ou tout le travail
  // est deja fait !!! ( il faut faire des paquets de 30 points
  // maximum , travailler dans un espace 0,1 pour tenir la precision)
  
  if (bspline->Degree() != 1) {
    seq.Append(bspline);
    return;
  }

  // on detecte d`eventuelles cassures par la multiplicite des poles.
  // Puis on approxime chaque "partie" de BSpline 

  Standard_Integer NbKnots = bspline->NbKnots();
  Standard_Integer NbPoles = bspline->NbPoles();
  TColgp_Array1OfPnt      Poles(1,NbPoles);
  TColStd_Array1OfReal    Weigs(1,NbPoles); Weigs.Init(1.);
  TColStd_Array1OfReal    Knots(1,NbKnots);
  TColStd_Array1OfInteger Mults(1,NbKnots); 

  bspline->Poles(Poles);
  if ( bspline->IsRational()) bspline->Weights(Weigs);
  bspline->Knots(Knots);
  bspline->Multiplicities(Mults);
  Standard_Integer deg = bspline->Degree();
  
  Standard_Integer jpole = 1;
  Standard_Integer j, PoleIndex, I1;
  PoleIndex = 1;
  I1 = 1;
  for ( Standard_Integer ipole = 1; ipole < NbPoles; ipole++) {
    if (Poles(ipole).IsEqual(Poles(ipole+1),Precision::Confusion())) {
      if (jpole == 1) {
	PoleIndex++;
      }
      else {
	TColgp_Array1OfPnt      newPoles(1,jpole);
	TColStd_Array1OfReal    newWeigs(1,jpole); Weigs.Init(1.);
	Standard_Integer NbNew = jpole - deg + 1;
	TColStd_Array1OfReal    newKnots(1,NbNew);
	TColStd_Array1OfInteger newMults(1,NbNew);
	for ( j = 1; j <= NbNew; j++) {
	  newKnots(j) = Knots(I1+j-1);
	  newMults(j) = Mults(I1+j-1);
	}
	newMults(1) = newMults(NbNew) = deg+1;
	for ( j = 1; j <= jpole; j++) {
	  newWeigs(j) = Weigs(PoleIndex  );
	  newPoles(j) = Poles(PoleIndex++);
	}
	
	Handle(Geom_BSplineCurve) newC = new Geom_BSplineCurve
	  (newPoles, newWeigs, newKnots, newMults, deg);
	SCurve.Append(newC);
	I1 = ipole+1;
	jpole = 1;
      }
    }
    else {
      jpole++;
    }
  }  
    

  Handle(Geom_BSplineCurve) mycurve;
  Standard_Integer nbcurves = SCurve.Length();
  if (nbcurves == 0) {
    nbcurves = 1;
    SCurve.Append(bspline);
  }
			
  for (Standard_Integer itab = 1; itab <= nbcurves; itab++) { 
    mycurve = Handle(Geom_BSplineCurve)::DownCast(SCurve.Value(itab));
    jpole = mycurve->NbPoles();
    if ( jpole > 2) {
      TColgp_Array1OfPnt newP(1,jpole);      
      mycurve->Poles(newP);
      Handle(IntSurf_LineOn2S) R = new IntSurf_LineOn2S();
      Standard_Real u1,v1,u2,v2;
      u1 = v1 = 0.;
      u2 = v2 = 1.;
      for( j=1; j<=jpole; j++) {
	IntSurf_PntOn2S POn2S;
	POn2S.SetValue(newP(j),u1,v1,u2,v2);
	R->Add(POn2S);
      }
      GeomInt_WLApprox theapp3d;
      Standard_Real Tol = Precision::Approximation();
      theapp3d.SetParameters(Tol, Tol, 4, 8, 0, Standard_True);
      Handle(IntPatch_WLine) WL = new IntPatch_WLine(R, Standard_False);
      Standard_Integer indicemin = 1;
      Standard_Integer indicemax = jpole;
      theapp3d.Perform(WL, Standard_True, Standard_False, 
		       Standard_False, indicemin, indicemax);
      if (!theapp3d.IsDone()) {
	modifCurve = mycurve; 
      }
      else if (theapp3d.NbMultiCurves() != 1) {
	modifCurve = mycurve;
      }
      else {
	const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(1);
	Standard_Integer nbpoles = mbspc.NbPoles();
	TColgp_Array1OfPnt tpoles(1,nbpoles);
	mbspc.Curve(1,tpoles);
	modifCurve = new Geom_BSplineCurve(tpoles,
					   mbspc.Knots(),
					   mbspc.Multiplicities(),
					   mbspc.Degree());
      }
    }
    else {
      modifCurve = mycurve;
    }
    seq.Append(modifCurve);
  }
}

//=======================================================================
//function : ApproxBSplineCurve
//purpose  : 
//=======================================================================

void ShapeAlgo_AlgoContainer::ApproxBSplineCurve (const Handle(Geom2d_BSplineCurve)& bspline,
                                                  TColGeom2d_SequenceOfCurve& seq) const
{
  seq.Clear();
  Handle(Geom2d_BSplineCurve)  res, modifCurve;
  TColGeom2d_SequenceOfCurve SCurve;

  // si la BSpline est de degre 1 , on approxime .
  // on passe par le programme des intersections ou tout le travail
  // est deja fait !!! ( il faut faire des paquets de 30 points
  // maximum , travailler dans un espace 0,1 pour tenir la precision
  // puis reconstruire une BSpline somme des toutes les Bspline).

  if (bspline->Degree() != 1) {
    seq.Append(bspline);
    return;
  }

  // on detecte d`eventuelles cassures par la multiplicite des poles.
  // Puis on approxime chaque "partie" de BSpline et on reconstruit 
  // une BSpline = somme des BSplines traitees 

  Standard_Integer NbKnots = bspline->NbKnots();
  Standard_Integer NbPoles = bspline->NbPoles();
  TColgp_Array1OfPnt2d    Poles(1,NbPoles);
  TColStd_Array1OfReal    Weigs(1,NbPoles); Weigs.Init(1.);
  TColStd_Array1OfReal    Knots(1,NbKnots);
  TColStd_Array1OfInteger Mults(1,NbKnots); 

  bspline->Poles(Poles);
  if ( bspline->IsRational()) bspline->Weights(Weigs);
  bspline->Knots(Knots);
  bspline->Multiplicities(Mults);
  Standard_Integer deg = bspline->Degree();
  
  Standard_Integer jpole = 1;
  Standard_Integer j, PoleIndex, I1;
  PoleIndex = 1;
  I1 = 1;
  for ( Standard_Integer ipole = 1; ipole < NbPoles; ipole++) {
    if (Poles(ipole).IsEqual(Poles(ipole+1),Precision::PConfusion())) {
      if (jpole == 1) {
	PoleIndex++;
      }
      else {
	TColgp_Array1OfPnt2d    newPoles(1,jpole);
	TColStd_Array1OfReal    newWeigs(1,jpole); Weigs.Init(1.);
	Standard_Integer NbNew = jpole - deg + 1;
	TColStd_Array1OfReal    newKnots(1,NbNew);
	TColStd_Array1OfInteger newMults(1,NbNew);
	for ( j = 1; j <= NbNew; j++) {
	  newKnots(j) = Knots(I1+j-1);
	  newMults(j) = Mults(I1+j-1);
	}
	newMults(1) = newMults(NbNew) = deg+1;
	for ( j = 1; j <= jpole; j++) {
	  newWeigs(j) = Weigs(PoleIndex  );
	  newPoles(j) = Poles(PoleIndex++);
	}
	
	Handle(Geom2d_BSplineCurve) newC = new Geom2d_BSplineCurve
	  (newPoles, newWeigs, newKnots, newMults, deg);
	SCurve.Append(newC);
	I1 = ipole+1;
	jpole = 1;
      }
    }
    else {
      jpole++;
    }
  }  
    

  Handle(Geom2d_BSplineCurve) mycurve;
  Standard_Integer nbcurves = SCurve.Length();
  if (nbcurves == 0) {
    nbcurves = 1;
    SCurve.Append(bspline);
  }
  
  for (Standard_Integer itab = 1; itab <= nbcurves; itab++) { 
    mycurve = Handle(Geom2d_BSplineCurve)::DownCast(SCurve.Value(itab));
    jpole = mycurve->NbPoles();
    if ( jpole > 10) {
      TColgp_Array1OfPnt P(1,jpole);      
      TColgp_Array1OfPnt2d newP(1,jpole);      
      mycurve->Poles(newP);
      Handle(IntSurf_LineOn2S) R = new IntSurf_LineOn2S();
      Standard_Real u2,v2;
      u2 = v2 = 1.;
      for( j=1; j<=jpole; j++) {
	IntSurf_PntOn2S POn2S;
	POn2S.SetValue(P(j),newP(j).X(),newP(j).Y(),u2,v2);
	R->Add(POn2S);
      }
      GeomInt_WLApprox theapp3d;
      Standard_Real Tol = Precision::PApproximation();
      theapp3d.SetParameters(Tol, Tol, 4, 8, 0, Standard_True);
      Handle(IntPatch_WLine) WL = new IntPatch_WLine(R, Standard_False);
      Standard_Integer indicemin = 1;
      Standard_Integer indicemax = jpole;
      theapp3d.Perform(WL, Standard_False, Standard_True, 
		       Standard_False, indicemin, indicemax);
      if (!theapp3d.IsDone()) {
	modifCurve = mycurve; 
      }
      else if (theapp3d.NbMultiCurves() != 1) {
	modifCurve = mycurve;
      }
      else {
	const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(1);
	Standard_Integer nbpoles = mbspc.NbPoles();
	TColgp_Array1OfPnt2d tpoles(1,nbpoles);
	mbspc.Curve(1,tpoles);
	for( j=1; j<=jpole; j++) {	
	}
	modifCurve = new Geom2d_BSplineCurve(tpoles,
					     mbspc.Knots(),
					     mbspc.Multiplicities(),
					     mbspc.Degree());
      }
    }
    else {
      modifCurve = mycurve;
    }
    seq.Append(modifCurve);
  }
}

//=======================================================================
//function : C0ShapeToC1Shape
//purpose  : 
//=======================================================================

 TopoDS_Shape ShapeAlgo_AlgoContainer::C0ShapeToC1Shape (const TopoDS_Shape& shape,
							    const Standard_Real tol) const
{
  ShapeUpgrade_ShapeDivideContinuity sdc(shape);
  sdc.SetTolerance(tol);
  sdc.SetBoundaryCriterion(GeomAbs_C1);
  sdc.SetSurfaceCriterion(GeomAbs_C1);
  sdc.Perform();
  return sdc.Result();
}

//=======================================================================
//function : ConvertSurfaceToBSpline
//purpose  : 
//=======================================================================

 Handle(Geom_BSplineSurface) ShapeAlgo_AlgoContainer::ConvertSurfaceToBSpline(const Handle(Geom_Surface)& surf,
										 const Standard_Real UF,
										 const Standard_Real UL,
										 const Standard_Real VF,
										 const Standard_Real VL) const
{
  return ShapeConstruct::ConvertSurfaceToBSpline(surf, UF, UL, VF, VL,
						    Precision::Confusion(), GeomAbs_C1, 100,
						    Geom_BSplineSurface::MaxDegree());
}

//=======================================================================
//function : HomoWires
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAlgo_AlgoContainer::HomoWires(const TopoDS_Wire& wireIn1,
							const TopoDS_Wire& wireIn2,
							TopoDS_Wire& wireOut1,
							TopoDS_Wire& wireOut2,
							const Standard_Boolean) const
{
  //Standard_Boolean res = Standard_False; //szv#4:S4163:12Mar99 not needed
  TopoDS_Iterator  Cook,      Perry;
  TopoDS_Edge      edge1,     edge2;
  TopLoc_Location  loc1,      loc2;
//  BRepBuilderAPI_MakeWire makeWire1, makeWire2;
  ShapeExtend_WireData makeWire1, makeWire2;
  Standard_Boolean iterCook,  iterPerry;
  Standard_Integer nEdges1,   nEdges2;
  Standard_Real    length1,   length2;
  Standard_Real    first1,    first2;
  Standard_Real    last1,     last2;
  Standard_Real    delta1,    delta2;

  Handle (Geom_Curve) crv1;
  Handle (Geom_Curve) crv2;

  //Standard_Boolean notEnd  = Standard_True; //szv#4:S4163:12Mar99 unused
  Standard_Integer nbCreatedEdges = 0;
  // gka
  //TopoDS_Vertex v11,v12,v21,v22
  Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire();
  sfw->Load(wireIn1);
  sfw->FixReorder();
  TopoDS_Wire wireIn11 = sfw->Wire() ;
  sfw->Load(wireIn2);
  sfw->FixReorder();
  TopoDS_Wire wireIn22 = sfw->Wire() ;
  
  iterCook = iterPerry = Standard_True;
  length1  = length2   = 0.;
  nEdges1  = nEdges2   = 0;
  for (Cook.Initialize(wireIn11); Cook.More(); Cook.Next()) {
    nEdges1++;
    edge1    = TopoDS::Edge(Cook.Value());
    crv1     = BRep_Tool::Curve(edge1, loc1, first1, last1);
    length1 += last1 - first1;
  }
  for (Perry.Initialize(wireIn22); Perry.More(); Perry.Next()) {
    nEdges2++;
    edge2    = TopoDS::Edge(Perry.Value());
    crv2     = BRep_Tool::Curve(edge2, loc2, first2, last2);
    length2 += last2 - first2;
  }
  Standard_Real epsilon = Precision::PConfusion() * (length1 + length2);
  if (nEdges1 == 1 && nEdges2 == 1){
    wireOut1 = wireIn11;
    wireOut2 = wireIn22;
    return Standard_True; //szv#4:S4163:12Mar99 `res=` not needed
  }

  if (length1 < epsilon) { 
    Cook.Initialize(wireIn11);
    for (Perry.Initialize(wireIn22); Perry.More(); Perry.Next()) {
      edge1  = TopoDS::Edge(Cook.Value());
      makeWire1.Add(edge1);
    }
    wireOut1 = makeWire1.Wire();
    wireOut2 = wireIn22;
    return Standard_True; //szv#4:S4163:12Mar99 `res=` not needed
  }
  if (length2 < epsilon) {
    Perry.Initialize(wireIn22);
    for (Cook.Initialize(wireIn11); Cook.More(); Cook.Next()) {
      edge2 = TopoDS::Edge(Perry.Value());
      makeWire2.Add(edge2);
    }
    wireOut1 = wireIn11;
    wireOut2 = makeWire2.Wire();
    return Standard_True; //szv#4:S4163:12Mar99 `res=` not needed
  }


  Standard_Real ratio = length2 / length1;

  Cook.Initialize(wireIn11);
  Perry.Initialize(wireIn22);
  edge1  = TopoDS::Edge(Cook.Value());
  edge2  = TopoDS::Edge(Perry.Value());
  // essai mjm du 22/05/97 
  Standard_Boolean IsToReverse1 = Standard_False;
  Standard_Boolean IsToReverse2 = Standard_False;
  if (edge1.Orientation() == TopAbs_REVERSED)
    IsToReverse1 = Standard_True;
  if (edge2.Orientation() == TopAbs_REVERSED)
    IsToReverse2 = Standard_True;
  crv1   = BRep_Tool::Curve(edge1, loc1, first1, last1);
  crv2   = BRep_Tool::Curve(edge2, loc2, first2, last2);
  delta1 = last1 - first1;
  delta2 = last2 - first2;
  while (nbCreatedEdges < (nEdges1 + nEdges2-1)) {  /*just a security. */

    if ((delta1*ratio - delta2) > epsilon) {
      BRepBuilderAPI_MakeEdge makeEdge1;
      if(!IsToReverse1) {
	makeEdge1.Init(crv1, first1, first1 + delta2/ratio);
	first1+= delta2/ratio;
      }
      else {                                               // gka BUC60685
	makeEdge1.Init(crv1, last1 - delta2/ratio , last1);
	last1 -= delta2/ratio;
      }
      BRepBuilderAPI_MakeEdge makeEdge2(crv2, first2, last2);
      edge1 = makeEdge1.Edge();
      edge2 = makeEdge2.Edge();
// essai mjm du 22/05/97
      iterCook  = Standard_False;
      //first1   += delta2/ratio;
      delta1    = last1 - first1;
      iterPerry = Standard_True;
      nbCreatedEdges++;
    }
    else if (Abs(delta1*ratio - delta2) <= epsilon) {
      BRepBuilderAPI_MakeEdge makeEdge1(crv1, first1, last1);
      BRepBuilderAPI_MakeEdge makeEdge2(crv2, first2, last2);
      edge1 = makeEdge1.Edge();
      edge2 = makeEdge2.Edge();
      iterCook  = Standard_True;
      iterPerry = Standard_True;
      nbCreatedEdges += 2;
    }
    else /*((delta1*ratio - delta2) < -epsilon)*/ {
      BRepBuilderAPI_MakeEdge makeEdge1(crv1, first1, last1);
      edge1 = makeEdge1.Edge();
      BRepBuilderAPI_MakeEdge makeEdge2;
      if(!IsToReverse2) {
	makeEdge2.Init(crv2, first2, first2 + delta1*ratio);
	first2   += delta1*ratio;
      }
      else {                                              // gka BUC60685
	makeEdge2.Init(crv2, last2 - delta1*ratio, last2);
	last2 -= delta1*ratio;
      }
      edge1 = makeEdge1.Edge();
      edge2 = makeEdge2.Edge();
      iterCook  = Standard_True;
      iterPerry = Standard_False;
      //first2   += delta1*ratio;
      delta2    = last2 - first2;
      nbCreatedEdges++;
    }
    edge1.Move(loc1);
    edge2.Move(loc2);
    if ( IsToReverse1) edge1.Reverse();
    if ( IsToReverse2) edge2.Reverse();
    makeWire1.Add(edge1);
    makeWire2.Add(edge2);

    if (iterCook && iterPerry) {
      TopoDS_Iterator Copernic = Cook;
      if (Copernic.More())
	  Copernic.Next();
      if (!Copernic.More()) {
	  wireOut1 = makeWire1.Wire();
	  wireOut2 = makeWire2.Wire();
	return Standard_True; //szv#4:S4163:12Mar99 `res=` not needed
      }
    }
    if (iterCook) {
      Cook.Next();
      edge1  = TopoDS::Edge(Cook.Value());
      if (edge1.Orientation() == TopAbs_REVERSED)
	IsToReverse1 = Standard_True;
      else IsToReverse1 = Standard_False;
      crv1   = BRep_Tool::Curve(edge1, loc1, first1, last1);
      delta1 = last1 - first1;
    }
    if (iterPerry) {
      Perry.Next();
      edge2  = TopoDS::Edge(Perry.Value());
      if (edge2.Orientation() == TopAbs_REVERSED)
	IsToReverse2 = Standard_True;
      else IsToReverse2 = Standard_False;
      crv2   = BRep_Tool::Curve(edge2, loc2, first2, last2);
      delta2 = last2 - first2;
    }

  }
  return Standard_False; //szv#4:S4163:12Mar99 `res=` not needed
}

//=======================================================================
//function : C0BSplineToSequenceOfC1BSplineCurve
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAlgo_AlgoContainer::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom_BSplineCurve)& BS,
									       Handle(TColGeom_HSequenceOfBoundedCurve)& seqBS) const 
{
  return ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve (BS, seqBS);
}

//=======================================================================
//function : C0BSplineToSequenceOfC1BSplineCurve
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAlgo_AlgoContainer::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom2d_BSplineCurve)& BS,
									       Handle(TColGeom2d_HSequenceOfBoundedCurve)& seqBS) const
{
  return ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve (BS, seqBS);
}

//=======================================================================
//function : OuterWire
//purpose  : 
//=======================================================================

TopoDS_Wire ShapeAlgo_AlgoContainer::OuterWire(const TopoDS_Face& face) const
{
  return ShapeAnalysis::OuterWire(face);
}

//=======================================================================
//function : ConvertToPeriodic
//purpose  : 
//=======================================================================

 Handle(Geom_Surface) ShapeAlgo_AlgoContainer::ConvertToPeriodic (const Handle(Geom_Surface)& surf) const
{
  ShapeCustom_Surface scs (surf);
  return scs.ConvertToPeriodic (Standard_False);
}

//=======================================================================
//function : GetFaceUVBounds
//purpose  : 
//=======================================================================

 void ShapeAlgo_AlgoContainer::GetFaceUVBounds (const TopoDS_Face& F,
						Standard_Real& Umin,
						Standard_Real& Umax,
						Standard_Real& Vmin,
						Standard_Real& Vmax) const
{
  ShapeAnalysis::GetFaceUVBounds (F, Umin, Umax, Vmin, Vmax);
}

//=======================================================================
//function : ConvertCurveToBSpline
//purpose  : 
//=======================================================================

Handle(Geom_BSplineCurve) ShapeAlgo_AlgoContainer::ConvertCurveToBSpline(const Handle(Geom_Curve)& C3D,
									 const Standard_Real First,
									 const Standard_Real Last,
									 const Standard_Real Tol3d,
									 const GeomAbs_Shape Continuity, 
									 const Standard_Integer MaxSegments,
									 const Standard_Integer MaxDegree) const
{
  return  ShapeConstruct::ConvertCurveToBSpline(C3D, First, Last, Tol3d, Continuity,  MaxSegments, MaxDegree);
}