summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_MidPointRelation.cxx
blob: cc5f44c8ae6d8766d40103dcf18a9d7cc5f5e5af (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
// File:	AIS_MidPointRelation.cxx
// Created:	Fri Oct 20 16:00:58 2000
// Author:	Julia DOROVSKIKH
//		<jfa@androx.nnov.matra-dtv.fr>

#include <AIS_MidPointRelation.ixx>

#include <Standard_NotImplemented.hxx>

#include <Precision.hxx>

#include <AIS.hxx>
#include <AIS_Drawer.hxx>

#include <gce_MakeLin.hxx>
#include <ElCLib.hxx>
#include <gp_Lin.hxx>
#include <gp_Circ.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <gp_Dir.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>

#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_TrimmedCurve.hxx>

#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveCurve.hxx>

#include <TopoDS.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve.hxx>

#include <Prs3d_Drawer.hxx>
#include <Prs3d_ArrowAspect.hxx>
#include <Prs3d_LengthAspect.hxx>

#include <DsgPrs_MidPointPresentation.hxx>
#include <TopoDS_Vertex.hxx>

//=======================================================================
//function : AIS_MidPointRelation
//purpose  : 
//=======================================================================
AIS_MidPointRelation::AIS_MidPointRelation(const TopoDS_Shape& aMidPointTool, 
					   const TopoDS_Shape& FirstShape, 
					   const TopoDS_Shape& SecondShape, 
					   const Handle(Geom_Plane)& aPlane)
:AIS_Relation(),
 myTool(aMidPointTool)
{
 SetFirstShape(FirstShape);
 SetSecondShape(SecondShape);
 SetPlane(aPlane);
 myPosition = aPlane->Pln().Location();
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, 
				   const Handle(Prs3d_Presentation)& aprs, 
				   const Standard_Integer)
{
  aprs->Clear();
  
  if (myTool.ShapeType() == TopAbs_VERTEX)
    {
      gp_Pnt pp;
      Standard_Boolean isonplane;
      if ( AIS::ComputeGeometry(TopoDS::Vertex(myTool),pp,myPlane,isonplane) )
	{
	  if ( !isonplane ) ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myTool),pp);
	}
      myMidPoint = pp;
    }
  else return;

  if ( myAutomaticPosition ) myPosition = myMidPoint;  

  switch (myFShape.ShapeType())
    {
    case TopAbs_FACE :
      {
	ComputeFaceFromPnt(aprs, Standard_True);
      }
      break;
    case TopAbs_EDGE :
      {
	ComputeEdgeFromPnt(aprs, Standard_True);
      }
      break;
    case TopAbs_VERTEX :
      {
	ComputeVertexFromPnt(aprs, Standard_True);
      }
      break;
    default:
      break;
    }

  switch (mySShape.ShapeType())
    {
    case TopAbs_FACE :
      {
	ComputeFaceFromPnt(aprs, Standard_False);
      }
      break;
    case TopAbs_EDGE :
      {
	ComputeEdgeFromPnt(aprs, Standard_False);
      }
      break;
    case TopAbs_VERTEX :
      {
	ComputeVertexFromPnt(aprs, Standard_False);
      }
      break;
    default:
      break;
    }
}

//=======================================================================
//function : Compute
//purpose  : to avoid warning at compilation (SUN)
//=======================================================================
void AIS_MidPointRelation::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
				   const Handle(Prs3d_Presentation)& /*aPresentation*/)
{
// Standard_NotImplemented::Raise("AIS_MidPointRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
// PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
}

//=======================================================================
//function : Compute
//purpose  : to avoid warning at compilation (SUN)
//=======================================================================
void AIS_MidPointRelation::Compute(const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager2d*/,
                                   const Handle(Graphic2d_GraphicObject)& /*aGraphicObject*/,
                                   const Standard_Integer /*anInteger*/)
{
// Standard_NotImplemented::Raise("AIS_MidPointRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
// PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
}

void AIS_MidPointRelation::Compute(const Handle_Prs3d_Projector& aProjector,
				   const Handle_Geom_Transformation& aTransformation,
				   const Handle_Prs3d_Presentation& aPresentation)
{
 Standard_NotImplemented::Raise("AIS_MidPointRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
}

//=======================================================================
//function : ComputeSelection
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel, 
					    const Standard_Integer)
{
  Handle(Select3D_SensitiveSegment) seg;
  Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);

  if ( !myMidPoint.IsEqual(myFAttach,Precision::Confusion()) )
    {
      // segment from mid point to the first geometry
      seg = new Select3D_SensitiveSegment(own,myFAttach,myMidPoint);
      aSel->Add(seg);
      // segment from mid point to the second geometry
      seg = new Select3D_SensitiveSegment(own,mySAttach,myMidPoint);
      aSel->Add(seg);
    }
  if ( !myMidPoint.IsEqual(myPosition,Precision::Confusion()) )
    {
      // segment from mid point to the text position
      seg = new Select3D_SensitiveSegment(own,myMidPoint,myPosition);
      aSel->Add(seg);
    }

  // center of the symmetry - circle around the MidPoint
  gp_Ax2 ax = myPlane->Pln().Position().Ax2();
  ax.SetLocation(myMidPoint);
  Standard_Real rad = myFAttach.Distance(myMidPoint)/20.0;
  gp_Circ aCircleM (ax,rad);
  Handle(Geom_Circle) thecir = new Geom_Circle(aCircleM);
  Handle(Select3D_SensitiveCurve) scurv = new Select3D_SensitiveCurve(own, thecir);
  aSel->Add(scurv);

  Handle(Geom_Curve) curv;
  gp_Pnt firstp,lastp;
  Standard_Boolean isInfinite,isOnPlane;
  Handle(Geom_Curve) extCurv;

  // segment on first curve
  if ( myFShape.ShapeType() == TopAbs_EDGE )
    {
      TopoDS_Edge E = TopoDS::Edge(myFShape);
      if ( !AIS::ComputeGeometry(E,curv,firstp,lastp,extCurv,isInfinite,isOnPlane,myPlane) ) return;
      if ( curv->IsInstance(STANDARD_TYPE(Geom_Line)) ) // case of line
	{
	  // segment on line
	  seg = new Select3D_SensitiveSegment(own,myFirstPnt1,myFirstPnt2);
	  aSel->Add(seg);
	}
      else if ( curv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) // case of circle
	{
	  // segment on circle
	  Handle(Geom_Circle) thecirc = (Handle(Geom_Circle)&) curv;
	  Standard_Real udeb = ElCLib::Parameter(thecirc->Circ(),myFirstPnt1);
	  Standard_Real ufin = ElCLib::Parameter(thecirc->Circ(),myFirstPnt2);
	  Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(thecirc,udeb,ufin);
	  
	  scurv = new Select3D_SensitiveCurve(own, thecu);
	  aSel->Add(scurv);
	}
      else if ( curv->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) // case of ellipse
	{
	  // segment on ellipse
	  Handle(Geom_Ellipse) theEll = (Handle(Geom_Ellipse)&) curv;
	  Standard_Real udeb = ElCLib::Parameter(theEll->Elips(),myFirstPnt1);
	  Standard_Real ufin = ElCLib::Parameter(theEll->Elips(),myFirstPnt2);
	  Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(theEll,udeb,ufin);
	  
	  scurv = new Select3D_SensitiveCurve(own, thecu);
	  aSel->Add(scurv);
	}
    }

  // segment on second curve
  if ( mySShape.ShapeType() == TopAbs_EDGE )
    {
      TopoDS_Edge E = TopoDS::Edge(mySShape);
      if ( !AIS::ComputeGeometry(E,curv,firstp,lastp,extCurv,isInfinite,isOnPlane,myPlane) ) return;
      if ( curv->IsInstance(STANDARD_TYPE(Geom_Line)) ) // case of line
	{
	  // segment on line
	  seg = new Select3D_SensitiveSegment(own,mySecondPnt1,mySecondPnt2);
	  aSel->Add(seg);
	}
      else if ( curv->IsInstance(STANDARD_TYPE(Geom_Circle)) ) // case of circle
	{
	  // segment on circle
	  Handle(Geom_Circle) thecirc = (Handle(Geom_Circle)&) curv;
	  Standard_Real udeb = ElCLib::Parameter(thecirc->Circ(),mySecondPnt1);
	  Standard_Real ufin = ElCLib::Parameter(thecirc->Circ(),mySecondPnt2);
	  Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(thecirc,udeb,ufin);
	  
	  scurv = new Select3D_SensitiveCurve(own, thecu);
	  aSel->Add(scurv);
	}
      else if ( curv->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) // case of ellipse
	{
	  // segment on ellipse
	  Handle(Geom_Ellipse) theEll = (Handle(Geom_Ellipse)&) curv;
	  Standard_Real udeb = ElCLib::Parameter(theEll->Elips(),mySecondPnt1);
	  Standard_Real ufin = ElCLib::Parameter(theEll->Elips(),mySecondPnt2);
	  Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(theEll,udeb,ufin);
	  
	  scurv = new Select3D_SensitiveCurve(own, thecu);
	  aSel->Add(scurv);
	}
    }
}

//=======================================================================
//function : ComputeFaceFromPnt
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputeFaceFromPnt(const Handle(Prs3d_Presentation)&,
					      const Standard_Boolean /*first*/)
{
}

//=======================================================================
//function : ComputeEdgeFromPnt
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputeEdgeFromPnt(const Handle(Prs3d_Presentation)& aprs,
					      const Standard_Boolean first)
{
  TopoDS_Edge E;
  if ( first ) E = TopoDS::Edge(myFShape);
  else         E = TopoDS::Edge(mySShape);

  Handle(Geom_Curve) geom;
  gp_Pnt ptat1,ptat2;
  Handle(Geom_Curve) extCurv;
  Standard_Boolean isInfinite,isOnPlane;
  if ( !AIS::ComputeGeometry(E, geom, ptat1, ptat2, extCurv, isInfinite, isOnPlane, myPlane) ) return;

  gp_Ax2 ax = myPlane->Pln().Position().Ax2();

  if ( geom->IsInstance(STANDARD_TYPE(Geom_Line)) )
    {
      if ( !isInfinite ) ComputePointsOnLine(ptat1,ptat2,first);
      else
	{
	  const gp_Lin& line = ((Handle(Geom_Line)&) geom)->Lin();
	  ComputePointsOnLine(line,first);
	}
      if ( first ) DsgPrs_MidPointPresentation::Add(aprs,myDrawer,ax,myMidPoint,myPosition,
						    myFAttach,myFirstPnt1,myFirstPnt2,first);
      else         DsgPrs_MidPointPresentation::Add(aprs,myDrawer,ax,myMidPoint,myPosition,
						    mySAttach,mySecondPnt1,mySecondPnt2,first);
    }
  else if ( geom->IsInstance(STANDARD_TYPE(Geom_Circle)) )
    {
      const Handle(Geom_Circle)& geom_cir = (Handle(Geom_Circle)&) geom;
      gp_Circ circ (geom_cir->Circ());
      ComputePointsOnCirc(circ,ptat1,ptat2,first);
      if ( first ) DsgPrs_MidPointPresentation::Add(aprs,myDrawer,circ,myMidPoint,myPosition,
						    myFAttach,myFirstPnt1,myFirstPnt2,first);
      else         DsgPrs_MidPointPresentation::Add(aprs,myDrawer,circ,myMidPoint,myPosition,
						    mySAttach,mySecondPnt1,mySecondPnt2,first);
    }
  else if ( geom->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
    {
      const Handle(Geom_Ellipse)& geom_ell = (Handle(Geom_Ellipse)&) geom;
      gp_Elips elips (geom_ell->Elips());
      ComputePointsOnElips(elips,ptat1,ptat2,first);
      if ( first ) DsgPrs_MidPointPresentation::Add(aprs,myDrawer,elips,myMidPoint,myPosition,
						    myFAttach,myFirstPnt1,myFirstPnt2,first);
      else         DsgPrs_MidPointPresentation::Add(aprs,myDrawer,elips,myMidPoint,myPosition,
						    mySAttach,mySecondPnt1,mySecondPnt2,first);
    }
  else return;

  // projection on myPlane
  if ( !isOnPlane ) ComputeProjEdgePresentation(aprs,E,geom,ptat1,ptat2);
}

//=======================================================================
//function : ComputeVertexFromPnt
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputeVertexFromPnt(const Handle(Prs3d_Presentation)& aprs,
						const Standard_Boolean first)
{
  gp_Ax2 ax = myPlane->Pln().Position().Ax2();
  if ( first )
    {
      Standard_Boolean isOnPlane;
      TopoDS_Vertex V = TopoDS::Vertex(myFShape);
      AIS::ComputeGeometry(V, myFAttach, myPlane, isOnPlane);
      DsgPrs_MidPointPresentation::Add(aprs,myDrawer,ax,myMidPoint,myPosition,myFAttach,first);
      if ( !isOnPlane ) ComputeProjVertexPresentation(aprs,V,myFAttach);
    }
  else
    {
      Standard_Boolean isOnPlane;
      TopoDS_Vertex V = TopoDS::Vertex(mySShape);
      AIS::ComputeGeometry(V, mySAttach, myPlane, isOnPlane);
      DsgPrs_MidPointPresentation::Add(aprs,myDrawer,ax,myMidPoint,myPosition,mySAttach,first);
      if ( !isOnPlane ) ComputeProjVertexPresentation(aprs,V,mySAttach);
    }
}

//=======================================================================
//function : ComputePointsOnLine
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputePointsOnLine(const gp_Lin& aLin,
					       const Standard_Boolean first)
{
  Standard_Real ppar = ElCLib::Parameter(aLin,myMidPoint);
  gp_Pnt anAttach = ElCLib::Value(ppar,aLin);

  Standard_Real dist = anAttach.Distance(myMidPoint)/10.0;
  if ( dist < Precision::Confusion() ) dist = 10.0;

  Standard_Real fpar = ppar + dist;
  Standard_Real spar = ppar - dist;

  gp_Pnt aPnt1 = ElCLib::Value(fpar,aLin);
  gp_Pnt aPnt2 = ElCLib::Value(spar,aLin);

  if ( first )
    {
      myFAttach = anAttach;
      myFirstPnt1 = aPnt1;
      myFirstPnt2 = aPnt2;
    }
  else
    {
      mySAttach = anAttach;
      mySecondPnt1 = aPnt1;
      mySecondPnt2 = aPnt2;
    }
}

//=======================================================================
//function : ComputePointsOnLine
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputePointsOnLine(const gp_Pnt& pnt1, const gp_Pnt& pnt2,
					       const Standard_Boolean first)
{
  gp_Vec aVec (pnt1,pnt2);
  gp_Lin aLin (pnt1,gp_Dir(aVec));

  Standard_Real fpar = ElCLib::Parameter(aLin,pnt1);
  Standard_Real spar = ElCLib::Parameter(aLin,pnt2);
  Standard_Real ppar = ElCLib::Parameter(aLin,myMidPoint);

  gp_Pnt aProjPnt = ElCLib::Value(ppar,aLin);
  Standard_Real dist = myMidPoint.Distance(aProjPnt);
  Standard_Real ll = pnt1.Distance(pnt2);
  Standard_Real segm = Min(dist,ll)*0.75;
  if ( dist < Precision::Confusion() ) segm = ll*0.75;

  gp_Pnt anAttach,aPnt1,aPnt2;
  anAttach = aProjPnt;
  gp_Vec aVecTr;
  if ( ppar <= fpar )
    {
      aPnt2 = pnt1;
      aVecTr = gp_Vec(pnt2,pnt1);
      aVecTr.Normalize();
      aPnt1 = aProjPnt.Translated(aVecTr*segm);
    }
  else if ( ppar >= spar )
    {
      aPnt1 = pnt2;
      aVecTr = gp_Vec(pnt1,pnt2);
      aVecTr.Normalize();
      aPnt2 = aProjPnt.Translated(aVecTr*segm);
    }
  else
    {
      Standard_Real dp1 = aProjPnt.Distance(pnt1);
      Standard_Real dp2 = aProjPnt.Distance(pnt2);

      segm = Min(dist,dp1)*0.75;
      aVecTr = gp_Vec(aProjPnt,pnt1);
      aVecTr.Normalize();
      aPnt1 = aProjPnt.Translated(aVecTr*segm);

      segm = Min(dist,dp2)*0.75;
      aVecTr = gp_Vec(aProjPnt,pnt2);
      aVecTr.Normalize();
      aPnt2 = aProjPnt.Translated(aVecTr*segm);
    }

  if ( first )
    {
      myFAttach = anAttach;
      myFirstPnt1 = aPnt1;
      myFirstPnt2 = aPnt2;
    }
  else
    {
      mySAttach = anAttach;
      mySecondPnt1 = aPnt1;
      mySecondPnt2 = aPnt2;
    }
}

//=======================================================================
//function : ComputePointsOnCirc
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputePointsOnCirc(const gp_Circ& aCirc,
					       const gp_Pnt& pnt1, const gp_Pnt& pnt2,
					       const Standard_Boolean first)
{
  gp_Pnt curpos = myMidPoint;

  // Case of confusion between the current position and the center 
  // of the circle -> we move the current position
  Standard_Real confusion (Precision::Confusion());
  gp_Pnt aCenter = aCirc.Location();
  if ( aCenter.Distance(curpos) <= confusion )
    {
      gp_Vec vprec(aCenter, pnt1);
      vprec.Normalize();
      curpos.Translate(vprec*1e-5);
    }
  
  Standard_Real pcurpos = ElCLib::Parameter(aCirc,curpos);

  Standard_Real rad = Standard_PI/5.0;
  Standard_Real segm;

  Standard_Real pFPnt;
  Standard_Real pSPnt;

  if ( pnt1.IsEqual(pnt2,confusion) ) // full circle
    {
      pFPnt = pcurpos - rad;
      pSPnt = pcurpos + rad;
    }
  else
    {
      Standard_Real pFAttach = ElCLib::Parameter(aCirc,pnt1);
      Standard_Real pSAttach = ElCLib::Parameter(aCirc,pnt2);

      Standard_Real pSAttachM = pSAttach;
      Standard_Real deltap = pSAttachM - pFAttach;
      if ( deltap < 0 )
	{
	  deltap += 2*Standard_PI;
	  pSAttachM += 2*Standard_PI;
	}
      pSAttachM -= pFAttach;

      Standard_Real pmiddleout = pSAttachM/2.0 + Standard_PI;

      Standard_Real pcurpos1 = pcurpos;
      // define where curpos lays
      if ( pcurpos1 < pFAttach )
	{
	  pcurpos1 = pcurpos1 + 2*Standard_PI - pFAttach;
	  if ( pcurpos1 > pSAttachM ) // out
	    {
	      segm = Min(rad,deltap*0.75);
	      if ( pcurpos1 > pmiddleout )
		{
		  pcurpos = pFAttach;
		  pFPnt = pFAttach;
		  pSPnt = pFAttach + segm;
		}
	      else
		{
		  pcurpos = pSAttach;
		  pFPnt = pSAttach - segm;
		  pSPnt = pSAttach;
		}
	    }
	  else // on arc
	    {
	      Standard_Real dp1 = pcurpos1 - pFAttach;
	      Standard_Real dp2 = pSAttachM - pcurpos1;

	      segm = Min(rad,dp1*0.75);
	      pFPnt = pcurpos - segm;
	      
	      segm = Min(rad,dp2*0.75);
	      pSPnt = pcurpos + segm;
	    }
	}
      else if ( pcurpos1 > (pFAttach + deltap) ) // out
	{
	  pcurpos1 -= pFAttach;
	  segm = Min(rad,deltap*0.75);
	  if ( pcurpos1 > pmiddleout )
	    {
	      pcurpos = pFAttach;
	      pFPnt = pFAttach;
	      pSPnt = pFAttach + segm;
	    }
	  else
	    {
	      pcurpos = pSAttach;
	      pFPnt = pSAttach - segm;
	      pSPnt = pSAttach;
	    }
	}
      else // on arc
	{
	  Standard_Real dp1 = pcurpos1 - pFAttach;
	  Standard_Real dp2 = pSAttach - pcurpos1;

	  segm = Min(rad,dp1*0.75);
	  pFPnt = pcurpos - segm;
	  
	  segm = Min(rad,dp2*0.75);
	  pSPnt = pcurpos + segm;
	}
    }

  if ( first )
    {
      myFAttach   = ElCLib::Value(pcurpos,aCirc);
      myFirstPnt1 = ElCLib::Value(pFPnt,aCirc);
      myFirstPnt2 = ElCLib::Value(pSPnt,aCirc);
    }
  else
    {
      mySAttach    = ElCLib::Value(pcurpos,aCirc);
      mySecondPnt1 = ElCLib::Value(pFPnt,aCirc);
      mySecondPnt2 = ElCLib::Value(pSPnt,aCirc);
    }
}

//=======================================================================
//function : ComputePointsOnElips
//purpose  : 
//=======================================================================
void AIS_MidPointRelation::ComputePointsOnElips(const gp_Elips& anEll,
						const gp_Pnt& pnt1, const gp_Pnt& pnt2,
					        const Standard_Boolean first)
{
  gp_Pnt curpos = myMidPoint;

  // Case of confusion between the current position and the center 
  // of the circle -> we move the current position
  Standard_Real confusion (Precision::Confusion());
  gp_Pnt aCenter = anEll.Location();
  if ( aCenter.Distance(curpos) <= confusion )
    {
      gp_Vec vprec(aCenter, pnt1);
      vprec.Normalize();
      curpos.Translate(vprec*1e-5);
    }
  
  Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos);

  Standard_Real rad = Standard_PI/5.0;
  Standard_Real segm;

  Standard_Real pFPnt;
  Standard_Real pSPnt;

  if ( pnt1.IsEqual(pnt2,confusion) ) // full circle
    {
      pFPnt = pcurpos - rad;
      pSPnt = pcurpos + rad;
    }
  else
    {
      Standard_Real pFAttach = ElCLib::Parameter(anEll,pnt1);
      Standard_Real pSAttach = ElCLib::Parameter(anEll,pnt2);

      Standard_Real pSAttachM = pSAttach;
      Standard_Real deltap = pSAttachM - pFAttach;
      if ( deltap < 0 )
	{
	  deltap += 2*Standard_PI;
	  pSAttachM += 2*Standard_PI;
	}
      pSAttachM -= pFAttach;

      Standard_Real pmiddleout = pSAttachM/2.0 + Standard_PI;

      Standard_Real pcurpos1 = pcurpos;
      // define where curpos lays
      if ( pcurpos1 < pFAttach )
	{
	  pcurpos1 = pcurpos1 + 2*Standard_PI - pFAttach;
	  if ( pcurpos1 > pSAttachM ) // out
	    {
	      segm = Min(rad,deltap*0.75);
	      if ( pcurpos1 > pmiddleout )
		{
		  pcurpos = pFAttach;
		  pFPnt = pFAttach;
		  pSPnt = pFAttach + segm;
		}
	      else
		{
		  pcurpos = pSAttach;
		  pFPnt = pSAttach - segm;
		  pSPnt = pSAttach;
		}
	    }
	  else // on arc
	    {
	      Standard_Real dp1 = pcurpos1 - pFAttach;
	      Standard_Real dp2 = pSAttachM - pcurpos1;

	      segm = Min(rad,dp1*0.75);
	      pFPnt = pcurpos - segm;
	      
	      segm = Min(rad,dp2*0.75);
	      pSPnt = pcurpos + segm;
	    }
	}
      else if ( pcurpos1 > (pFAttach + deltap) ) // out
	{
	  pcurpos1 -= pFAttach;
	  segm = Min(rad,deltap*0.75);
	  if ( pcurpos1 > pmiddleout )
	    {
	      pcurpos = pFAttach;
	      pFPnt = pFAttach;
	      pSPnt = pFAttach + segm;
	    }
	  else
	    {
	      pcurpos = pSAttach;
	      pFPnt = pSAttach - segm;
	      pSPnt = pSAttach;
	    }
	}
      else // on arc
	{
	  Standard_Real dp1 = pcurpos1 - pFAttach;
	  Standard_Real dp2 = pSAttach - pcurpos1;

	  segm = Min(rad,dp1*0.75);
	  pFPnt = pcurpos - segm;
	  
	  segm = Min(rad,dp2*0.75);
	  pSPnt = pcurpos + segm;
	}
    }

  if ( first )
    {
      myFAttach   = ElCLib::Value(pcurpos,anEll);
      myFirstPnt1 = ElCLib::Value(pFPnt,anEll);
      myFirstPnt2 = ElCLib::Value(pSPnt,anEll);
    }
  else
    {
      mySAttach    = ElCLib::Value(pcurpos,anEll);
      mySecondPnt1 = ElCLib::Value(pFPnt,anEll);
      mySecondPnt2 = ElCLib::Value(pSPnt,anEll);
    }
}