summaryrefslogtreecommitdiff
path: root/src/ChFiDS/ChFiDS_FilSpine.cxx
blob: 81ec811e673af9a837a81107a2ed5231731af422 (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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
// File:	ChFiDS_FilSpine.cxx
// Created:	Mon Apr 24 17:04:22 1995
// Author:	Modelistation
//		<model@phylox>


#include <ChFiDS_FilSpine.ixx>
#include <ChFiDS_ListIteratorOfListOfHElSpine.hxx>
#include <Precision.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <gp_XY.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <ElCLib.hxx>
#include <Law_ListIteratorOfLaws.hxx>
#include <Law_Constant.hxx>
#include <Law_S.hxx>
#include <Law_Interpol.hxx>
#include <Standard_DomainError.hxx>

//=======================================================================
//function : ChFiDS_FilSpine
//purpose  : 
//=======================================================================

ChFiDS_FilSpine::ChFiDS_FilSpine() {}

ChFiDS_FilSpine::ChFiDS_FilSpine(const Standard_Real Tol) :
ChFiDS_Spine(Tol)
{}

//=======================================================================
//function : Reset
//purpose  : 
//=======================================================================

void ChFiDS_FilSpine::Reset(const Standard_Boolean AllData)
{
  ChFiDS_Spine::Reset(AllData);
  laws.Clear();
  if(AllData)
    parandrad.Clear();
  else //Complete parandrad
    {
      Standard_Real spinedeb = FirstParameter();
      Standard_Real spinefin = LastParameter();

      gp_XY FirstUandR = parandrad.First();
      gp_XY LastUandR  = parandrad.Last();
      if (Abs( spinedeb - FirstUandR.X() ) > gp::Resolution())
	{
	  FirstUandR.SetX( spinedeb );
	  parandrad.Prepend( FirstUandR );
	}
      if (Abs( spinefin - LastUandR.X() ) > gp::Resolution())
	{
	  LastUandR.SetX( spinefin );
	  parandrad.Append( LastUandR );
	}

      if (IsPeriodic())
	parandrad(parandrad.Length()).SetY( parandrad(1).Y() );
    }
}

//=======================================================================
//function : SetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::SetRadius(const Standard_Real Radius,
				 const TopoDS_Edge&  E)
{
  splitdone = Standard_False;
  Standard_Integer IE = Index(E);
  gp_XY FirstUandR( 0., Radius ), LastUandR( 1., Radius );
  SetRadius( FirstUandR, IE );
  SetRadius( LastUandR, IE );
}

//=======================================================================
//function : UnSetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::UnSetRadius(const TopoDS_Edge&  E)
{
  splitdone = Standard_False;
  Standard_Integer IE = Index(E);

  Standard_Real Uf = FirstParameter(IE);
  Standard_Real Ul = LastParameter(IE);
  Standard_Integer ifirst = 0, ilast = 0;
  for (Standard_Integer i = 1; i <= parandrad.Length(); i++)
    {
      if (Abs(parandrad(i).X()-Uf) <= gp::Resolution())
	ifirst = i;
      if (Abs(parandrad(i).X()-Ul) <= gp::Resolution())
	ilast = i;
    }
  if (ifirst != 0 && ilast != 0)
    parandrad.Remove( ifirst, ilast );
}

//=======================================================================
//function : SetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::SetRadius(const Standard_Real  Radius,
				 const TopoDS_Vertex& V)
{
  Standard_Real npar = Absc(V);
  gp_XY UandR( npar, Radius );
  SetRadius( UandR, 0 );
}

//=======================================================================
//function : SetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::SetRadius(const Standard_Real  Radius)
{
  parandrad.Clear();
  gp_XY FirstUandR( FirstParameter(), Radius );
  gp_XY LastUandR( LastParameter(), Radius );
  SetRadius( FirstUandR, 0 );
  SetRadius( LastUandR, 0 );
}

//=======================================================================
//function : SetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::SetRadius(const gp_XY&           UandR,
				 const Standard_Integer IinC)
{
  Standard_Real W;
  if (IinC == 0)
    W = UandR.X();
  else
    {
      Standard_Real Uf = FirstParameter(IinC);
      Standard_Real Ul = LastParameter(IinC);
      W = Uf + UandR.X()*( Ul - Uf );
    }

  gp_XY pr( W, UandR.Y() );
  Standard_Integer i;
  for(i = 1; i <= parandrad.Length(); i++){
    if(parandrad.Value(i).X() == W) {
      parandrad.ChangeValue(i).SetY( UandR.Y() );
      if (!splitdone) return;
      else break;
    }
    else if(parandrad.Value(i).X() > W) {
      parandrad.InsertBefore(i,pr);
      if (!splitdone) return;
      else break;
    }
  }
  if (i == parandrad.Length()+1) parandrad.Append(pr);

  //si le split est done il faut rejouer la law 
  //correspondant au parametre W 
  if (splitdone) {
    ChFiDS_ListIteratorOfListOfHElSpine It(elspines);
    Law_ListIteratorOfLaws Itl(laws);
    Handle(ChFiDS_HElSpine) Els = It.Value();
    if (Els->IsPeriodic()) Itl.Value() = ComputeLaw(Els);
    else{
      for (; It.More(); It.Next(), Itl.Next()) {
	Els = It.Value();
	Standard_Real uf = Els->FirstParameter();
	Standard_Real ul = Els->LastParameter();
	if(uf <= W && W <= ul) {
	  Itl.Value() = ComputeLaw(Els);
	}
      }  
    }
  }
}

//=======================================================================
//function : UnSetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::UnSetRadius(const TopoDS_Vertex& V)
{
  Standard_Real npar = Absc(V);
  for(Standard_Integer i = 1; i <= parandrad.Length(); i++){
    if(parandrad.Value(i).X() == npar) {
      parandrad.Remove(i);
      break;
    }
  }
}

//=======================================================================
//function : SetRadius
//purpose  : 
//=======================================================================

void  ChFiDS_FilSpine::SetRadius(const Handle(Law_Function)& C,
				 const Standard_Integer      IinC)
{
  splitdone = Standard_False;
  Handle(Law_Composite) prout = new Law_Composite();
  Law_Laws& lst = prout->ChangeLaws();
  lst.Append(C);
  parandrad.Clear();
}


//=======================================================================
//function : IsConstant
//purpose  : 
//=======================================================================

Standard_Boolean  ChFiDS_FilSpine::IsConstant()const 
{
  if (parandrad.IsEmpty())
    return Standard_False;

  Standard_Boolean isconst = Standard_True;
  Standard_Real Radius = parandrad(1).Y();
  for (Standard_Integer i = 2; i <= parandrad.Length(); i++)
    if (Abs( Radius - parandrad(i).Y() ) > Precision::Confusion())
      {
	isconst = Standard_False;
	break;
      }
  return isconst;
}

//=======================================================================
//function : IsConstant
//purpose  : 
//=======================================================================

Standard_Boolean  ChFiDS_FilSpine::IsConstant(const Standard_Integer IE)const 
{
  Standard_Real Uf = FirstParameter(IE);
  Standard_Real Ul = LastParameter(IE);

  Standard_Real StartRad = 0, par, rad;
  Standard_Integer i;
  for (i = 1; i < parandrad.Length(); i++)
    {
      par = parandrad(i).X();
      rad = parandrad(i).Y();
      Standard_Real nextpar = parandrad(i+1).X();
      if (Abs( Uf-par ) <= gp::Resolution() ||
	  (par < Uf && Uf < nextpar && nextpar-Uf > gp::Resolution()))
	{
	  StartRad = rad;
	  break;
	}
    }
  for (i++; i <= parandrad.Length(); i++)
    {
      par = parandrad(i).X();
      rad = parandrad(i).Y();
      if (Abs( rad-StartRad ) > Precision::Confusion())
	return Standard_False;
      if (Abs( Ul-par ) <= gp::Resolution())
	return Standard_True;
      if (par > Ul)
	return Standard_True;
    }
  return Standard_True;
}

//=======================================================================
//function : Radius
//purpose  : 
//=======================================================================

Standard_Real  ChFiDS_FilSpine::Radius(const TopoDS_Edge& E)const 
{
  Standard_Integer IE = Index(E);
  return Radius(IE);
}

//=======================================================================
//function : Radius
//purpose  : 
//=======================================================================

Standard_Real  ChFiDS_FilSpine::Radius(const Standard_Integer IE)const 
{
  Standard_Real Uf = FirstParameter(IE);
  Standard_Real Ul = LastParameter(IE);

  Standard_Real StartRad = 0, par, rad;
  Standard_Integer i;
  for (i = 1; i < parandrad.Length(); i++)
    {
      par = parandrad(i).X();
      rad = parandrad(i).Y();
      Standard_Real nextpar = parandrad(i+1).X();
      if (Abs( Uf-par ) <= gp::Resolution() ||
	  (par < Uf && Uf < nextpar && nextpar-Uf > gp::Resolution()))
	{
	  StartRad = rad;
	  break;
	}
    }
  for (i++; i <= parandrad.Length(); i++)
    {
      par = parandrad(i).X();
      rad = parandrad(i).Y();
      if (Abs( rad-StartRad ) > Precision::Confusion())
	Standard_DomainError::Raise("Edge is not constant");
      if (Abs( Ul-par ) <= gp::Resolution())
	return StartRad;
      if (par > Ul)
	return StartRad;
    }
  return StartRad;
}

//=======================================================================
//function : Radius
//purpose  : 
//=======================================================================

Standard_Real  ChFiDS_FilSpine::Radius()const 
{
  if (!IsConstant()) Standard_DomainError::Raise("Spine is not constant");
  return parandrad(1).Y();
}

//=======================================================================
//function : AppendElSpine
//purpose  : 
//=======================================================================

void ChFiDS_FilSpine::AppendElSpine(const Handle(ChFiDS_HElSpine)& Els)
{
  ChFiDS_Spine::AppendElSpine(Els);
  AppendLaw(Els);
}

//=======================================================================
//function : AppendLaw
//purpose  : 
//=======================================================================

void ChFiDS_FilSpine::AppendLaw(const Handle(ChFiDS_HElSpine)& Els)
{
  Handle(Law_Composite) l = ComputeLaw(Els);
  laws.Append(l);
}

static void mklaw(Law_Laws&                  res, 
		  const TColgp_SequenceOfXY& pr,
		  const Standard_Real        curdeb,
		  const Standard_Real        curfin,
		  const Standard_Real        Rdeb,
		  const Standard_Real        Rfin,
		  const Standard_Boolean     recadre,
		  const Standard_Real        deb,
		  const Standard_Real        fin,
		  const Standard_Real        tol3d)
{
  TColgp_SequenceOfXY npr;
  Standard_Real rad = Rdeb, raf = Rfin;
  Standard_Boolean yaunpointsurledeb = Standard_False;
  Standard_Boolean yaunpointsurlefin = Standard_False;
  if(!pr.IsEmpty()){
    for (Standard_Integer i = 1; i <= pr.Length(); i++){
      const gp_XY& cur = pr.Value(i);
      Standard_Real wcur = cur.X();
      if(recadre) wcur = ElCLib::InPeriod(wcur,deb,fin);
      if( curdeb - tol3d <= wcur && wcur <= curfin + tol3d) {
	if(wcur - curdeb < tol3d) {
	  yaunpointsurledeb = Standard_True;
	  gp_XY ncur = cur;
	  if(Rdeb < 0.) rad = cur.Y();
	  ncur.SetCoord(curdeb,rad);
	  npr.Append(ncur);
	}  
	else if(curfin - wcur < tol3d) {
	  yaunpointsurlefin = Standard_True;
	  gp_XY ncur = cur;
	  if(Rfin < 0.) raf = cur.Y();
	  ncur.SetCoord(curfin,raf);
	  npr.Append(ncur);
	}  
	else npr.Append(gp_XY(wcur,cur.Y()));
      }
    }
  }

  if(npr.IsEmpty()){
    if( Rdeb < 0. && Rfin <0. ) 
      Standard_DomainError::Raise("Impossible to create the law");
    else if(Rdeb < 0. || Rfin <0.){
      Standard_Real r = (Rfin<0.)? Rdeb  : Rfin;
      Handle(Law_Constant) loi = new Law_Constant();
      loi->Set(r,curdeb,curfin);
      res.Append(loi);
    }
    else{
      Handle(Law_S) loi = new Law_S();
      loi->Set(curdeb,Rdeb,curfin,Rfin);
      res.Append(loi);
    }
  }
  else{
    if(!yaunpointsurledeb && Rdeb >= 0.) npr.Append(gp_XY(curdeb,Rdeb));
    if(!yaunpointsurlefin && Rfin >= 0.) npr.Append(gp_XY(curfin,Rfin));
    Standard_Integer nbp = npr.Length();
//    for(Standard_Integer i = 1; i < nbp; i++){
    Standard_Integer i;
    for(i = 1; i < nbp; i++){
      for(Standard_Integer j = i + 1; j <= nbp; j++){
	if(npr.Value(i).X() > npr.Value(j).X()){
	  gp_XY temp = npr.Value(i);
	  npr.ChangeValue(i) = npr.Value(j);
	  npr.ChangeValue(j) = temp;
	}
      }      
    }
    //Duplicates are removed.
    Standard_Boolean fini = (nbp <= 1);
    i = 1;
    while (!fini) {
      if(fabs(npr.Value(i).X() - npr.Value(i+1).X()) < tol3d) {
	npr.Remove(i);
	nbp--;
      }
      else i++;
      fini = (i >= nbp);
    }

    if(rad < 0.) {
      Handle(Law_Constant) loi = new Law_Constant();
      loi->Set(npr.First().Y(),curdeb,npr.First().X());
      res.Append(loi);
    }
    if(nbp > 1){
      TColgp_Array1OfPnt2d tpr(1,nbp);
      for (Standard_Integer l = 1; l <= nbp; l++) {
	tpr(l).SetXY(npr.Value(l));
      }
      Handle(Law_Interpol) curloi = new Law_Interpol();
      curloi->Set(tpr,0.,0.,Standard_False);
      res.Append(curloi);
    }
    if(raf < 0.) {
      Handle(Law_Constant) loi = new Law_Constant();
      loi->Set(npr.Last().Y(),npr.Last().X(),curfin);
      res.Append(loi);
    }
  }
}
				  
//=======================================================================
//function : ComputeLaw
//purpose  : 
//=======================================================================

Handle(Law_Composite) ChFiDS_FilSpine::ComputeLaw
(const Handle(ChFiDS_HElSpine)& Els)
{
  Standard_Real tol3d = Precision::Confusion();
  Standard_Real deb,fin,curdeb,curfin;
  curdeb = deb = Els->FirstParameter();
  curfin = fin = Els->LastParameter();
  Standard_Integer ideb = Index(deb,Standard_True);
  Standard_Integer ifin = Index(fin,Standard_False);
  Standard_Integer len = NbEdges();
  // if the spine is periodic, attention to the index and parameters
  Standard_Real spinedeb = FirstParameter();
  Standard_Real spinefin = LastParameter();

  Standard_Integer nbed = ifin - ideb + 1;
  Standard_Integer biddeb = ideb, bidfin = ifin;

  Handle(Law_Composite) loi = new Law_Composite();
  Law_Laws& list = loi->ChangeLaws();
#ifndef DEB
  Standard_Real Rdeb = 0., Rfin = 0., Rcur;
#else
  Standard_Real Rdeb, Rfin, Rcur;
#endif
  Standard_Integer icur = 1;
  Handle(Law_S) sl;
  Handle(Law_Constant) lastloi;
  Standard_Boolean lawencours = Standard_False;


  if(IsPeriodic()){
    if(deb < 0 && ideb > ifin)  bidfin += len;
    else if(fin > LastParameter(len) && ideb > ifin)  bidfin += len;
    nbed = bidfin - biddeb + 1;
  }
  TColStd_Array1OfInteger ind(1,nbed);
  Standard_Integer j = 1;
  for(Standard_Integer i = biddeb; i <= bidfin; i++){
    ind(j++) = ((i - 1)%len) + 1; 
  }

  if(Els->IsPeriodic()){
    // A pereodic composite is created at range, which is eventually  
    // offset relatively to the elspine, to avoid a single point at 
    // origin.
    loi->SetPeriodic();
    //Is there a constant edge?
//    for(Standard_Integer k = 1; k <= len; k++){
    Standard_Integer k;
    for( k = 1; k <= len; k++){
      if (IsConstant(k)){ // yes  !
	spinedeb = deb = curdeb = FirstParameter(k);
	spinefin = fin = deb + Period();
	for(Standard_Integer l = 1; l <= len; l++){
	  ind(l) = ((k + l -2)%len) + 1; 
	}
	Rdeb = Rfin = Radius(k);
	icur++;
	if(len == 1) curfin = LastParameter(k);//because InPeriod will make 0.!!!
	else curfin = ElCLib::InPeriod(LastParameter(k),spinedeb,spinefin);
	Handle(Law_Constant) curloi = new Law_Constant();
	curloi->Set(Rdeb,curdeb,curfin);
	list.Append(curloi);
	curdeb = curfin;
	break;
      }
    }
    if(k > len){ // no !
      if(parandrad.IsEmpty()) 
	Standard_DomainError::Raise("Radius not defined");
      Standard_Integer nbp = parandrad.Length();
      if(nbp > 1){
	deb = parandrad.First().X();
	fin = deb + Period();
	if(parandrad.Last().X() - fin <  - tol3d) nbp++;
      }
      else nbp++;
      TColgp_Array1OfPnt2d pr(1,nbp);
      for (Standard_Integer l = 1; l < nbp; l++) {
	pr(l).SetXY(parandrad(l));
      }
      pr(nbp).SetCoord(fin,pr(1).Y());
      Handle(Law_Interpol) curloi = new Law_Interpol();
      curloi->Set(pr,Standard_True);
      list.Append(curloi);
      return loi;
    }
  }
  else if(IsPeriodic()){
    // start radius.
    if (IsConstant(ind(1))) {
      Rdeb = Radius(ind(1));
      curfin = LastParameter(ind(1));
      curfin = ElCLib::InPeriod(curfin,spinedeb + tol3d, spinefin + tol3d);
      curfin = Min(fin,curfin);
      Handle(Law_Constant) curloi = new Law_Constant();
      curloi->Set(Rdeb,curdeb,curfin);
      list.Append(curloi);
      curdeb = curfin;
      icur++;
    } 
    else{
      // There is inevitably kpart right before!
      Standard_Integer iprec = (ind(1) - 1);
      if(iprec == 0) iprec = len;
      if (IsConstant(iprec)){
	Rdeb = Radius(iprec);
      }
      else Standard_DomainError::Raise("AppendLaw : previous constant is missing!");
      lawencours = Standard_True;
    }
    // the raduis at end.
    if (IsConstant(ind(nbed))) Rfin = Radius(ind(nbed));
    else{
      // There is inevitably kpart right after!
      Standard_Integer isuiv = (ind(nbed) + 1);
      if(isuiv == len + 1) isuiv = 1;
      if (IsConstant(isuiv)) {
	Rfin = Radius(isuiv);
      }
      else Standard_DomainError::Raise("AppendLaw : next constant is missing!");
    }
  }
  else{
    // the radius at start.
    if (IsConstant(ind(1))) {
      Rdeb = Radius(ind(1));
      curfin = Min(fin,LastParameter(ind(1)));
      Handle(Law_Constant) curloi = new Law_Constant();
      curloi->Set(Rdeb,curdeb,curfin);
      list.Append(curloi);
      curdeb = curfin;
      icur++;
    } 
    else{
      if(ind(1) > 1){
	if (IsConstant(ind(1) - 1)){
	  Rdeb = Radius(ind(1) - 1);
	}
	else Standard_DomainError::Raise("AppendLaw : previous constant is missing");
      }
      else if(parandrad.IsEmpty()){
	Standard_DomainError::Raise("AppendLaw : no radius on vertex");
      }
      else Rdeb = -1.;
      lawencours = Standard_True;
    }
    // the radius at end.
    if (IsConstant(ind(nbed))) Rfin = Radius(ind(nbed));
    else{
      if(ind(nbed) < len){
	if (IsConstant(ind(nbed) + 1)) Rfin = Radius(ind(nbed) + 1);
	else Standard_DomainError::Raise("AppendLaw : next constant is missing");
      }
      else if(parandrad.IsEmpty()){
	Standard_DomainError::Raise("AppendLaw : no radius on vertex");
      }
      else Rfin = -1.;
    }
  }

  // There are infos on the extremities of the elspine, 
  // all edges are parsed 
  for(; icur <= nbed; icur++){
    if (IsConstant(ind(icur))) {
      Rcur = Radius(ind(icur));
      if(lawencours){
	Law_Laws temp;
	mklaw(temp,parandrad,curdeb,curfin,Rdeb,Rcur,
	      IsPeriodic(),spinedeb,spinefin,tol3d);
	list.Append(temp);
	lawencours = Standard_False;
	curdeb = curfin;
      }
      curfin = LastParameter(ind(icur));
      if(IsPeriodic()){ 
	curfin = ElCLib::InPeriod(curfin,spinedeb + tol3d, spinefin + tol3d);
	if(ind(icur) == ind(nbed)){
	  // Attention the curfin can be wrong if the last edge passes 
	  // above the  origin periodic spline.
	  Standard_Real biddeb = FirstParameter(ind(icur));
	  biddeb = ElCLib::InPeriod(biddeb,spinedeb + tol3d, spinefin + tol3d);
	  if(biddeb >= curfin) curfin = fin;
	  else curfin = Min(fin,curfin);
	}
	else curfin = Min(fin,curfin);
      }
      if((curfin - curdeb) > tol3d){
	Rdeb = Rcur;
	Handle(Law_Constant) curloi = new Law_Constant();
	curloi->Set(Rdeb,curdeb,curfin);
	list.Append(curloi);
	curdeb = curfin;
      }
    }
    else {
      curfin = LastParameter(ind(icur));
      if(IsPeriodic()) 
	curfin = ElCLib::InPeriod(curfin,spinedeb + tol3d, spinefin + tol3d);
      curfin = Min(fin,curfin);
      lawencours = Standard_True;
      if(ind(icur) == ind(nbed)){
	// Attention the curfin can be wrong if the last edge passes 
	  // above the  origin periodic spline.
	if(IsPeriodic()) {
	  Standard_Real biddeb = FirstParameter(ind(icur));
	  curfin = LastParameter(ind(icur));
	  biddeb = ElCLib::InPeriod(biddeb,spinedeb + tol3d, spinefin + tol3d);
	  curfin = ElCLib::InPeriod(curfin,spinedeb + tol3d, spinefin + tol3d);
	  if(biddeb >= curfin) curfin = fin;
	  else curfin = Min(fin,curfin);
	}
	// or if it is the end of spine with extension.
	else if(ind(icur) == len) curfin = fin;
	Law_Laws temp;
	mklaw(temp,parandrad,curdeb,curfin,Rdeb,Rfin,
	      IsPeriodic(),spinedeb,spinefin,tol3d);
	list.Append(temp);
      }
    }
  }
  if(!lastloi.IsNull()) list.Append(lastloi);
  return loi;
}

//=======================================================================
//function : Law
//purpose  : 
//=======================================================================

Handle(Law_Composite) ChFiDS_FilSpine::Law(const Handle(ChFiDS_HElSpine)& Els) const 
{
  ChFiDS_ListIteratorOfListOfHElSpine Itsp(elspines);
  Law_ListIteratorOfLaws Itl(laws);
  for(; Itsp.More(); Itsp.Next(), Itl.Next()){
    if(Els == Itsp.Value()){
      return Handle(Law_Composite)::DownCast(Itl.Value());
    }
  }
  return Handle(Law_Composite)();
}

//=======================================================================
//function : Law
//purpose  : 
//=======================================================================

Handle(Law_Function)& ChFiDS_FilSpine::ChangeLaw(const TopoDS_Edge& E)
{
  if(!SplitDone()) {
    Standard_DomainError::Raise("ChFiDS_FilSpine::ChangeLaw : the limits are not up-to-date");
  }
  Standard_Integer IE = Index(E);
  if (IsConstant(IE)) {
    Standard_DomainError::Raise("ChFiDS_FilSpine::ChangeLaw : no law on constant edges");
  }
  Handle(ChFiDS_HElSpine) hsp = ElSpine(IE);
  Standard_Real w = 0.5*(FirstParameter(IE) + LastParameter(IE));
  Handle(Law_Composite) lc = Law(hsp);
  return lc->ChangeElementaryLaw(w);
}


//=======================================================================
//function : Radius
//purpose  : 
//=======================================================================

Standard_Real  ChFiDS_FilSpine::MaxRadFromSeqAndLaws()const 
{
  Standard_Real MaxRad = 0.;

  for (Standard_Integer i = 1; i <= parandrad.Length(); i++)
    if (parandrad(i).Y() > MaxRad)
      MaxRad = parandrad(i).Y();

  Law_ListIteratorOfLaws itl( laws );
  for (; itl.More(); itl.Next())
    {
      Handle(Law_Function) law = itl.Value();
      Standard_Real fpar, lpar, par, delta, rad;
      law->Bounds( fpar, lpar );
      delta = (lpar - fpar)*0.2;
      for (Standard_Integer i = 0; i <= 4; i++)
	{
	  par = fpar + i*delta;
	  rad = law->Value(par);
	  if (rad > MaxRad)
	    MaxRad = rad;
	}
      rad = law->Value(lpar);
      if (rad > MaxRad)
	MaxRad = rad;
    }
  
  return MaxRad;
}