summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_EqualDistanceRelation.cxx
blob: 9dab353ad405a32e85dd883f9584dca367b4c481 (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
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
// File:	AIS_EqualDistanceRelation.cxx
// Created:	Sat Jan 24 19:03:18 1998
// Author:	Julia GERASIMOVA
//		<jgv@leonox.nnov.matra-dtv.fr>


#include <Standard_NotImplemented.hxx>

#include <AIS_EqualDistanceRelation.ixx>

#include <DsgPrs_EqualDistancePresentation.hxx>
#include <AIS_LengthDimension.hxx>
#include <gp_Lin.hxx>
#include <DsgPrs_EqualDistancePresentation.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <Precision.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRep_Tool.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <Prs3d_LengthAspect.hxx>
#include <Prs3d_ArrowAspect.hxx>
#include <Geom_Line.hxx>
#include <Geom_Circle.hxx>
#include <AIS_Drawer.hxx>
#include <ElCLib.hxx>
//=======================================================================
//function : AIS_EqualDistanceRelation
//purpose  : 
//=======================================================================

AIS_EqualDistanceRelation::AIS_EqualDistanceRelation( const TopoDS_Shape& aShape1,
						      const TopoDS_Shape& aShape2,
						      const TopoDS_Shape& aShape3,
						      const TopoDS_Shape& aShape4,
						      const Handle( Geom_Plane )& aPlane )
     :AIS_Relation()
{
  myFShape = aShape1;
  mySShape = aShape2;
  myShape3 = aShape3;
  myShape4 = aShape4;
  myPlane  = aPlane;

  //Temporary
  myArrowSize = 3.0; //set the concrete value
  mySymbolPrs = DsgPrs_AS_BOTHAR;
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void AIS_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
					 const Handle( Prs3d_Presentation )& aPresentation,
					 const Standard_Integer ) 
{

  aPresentation->Clear();

  gp_Pnt Position12 =  myPosition, Position34 = myPosition;

  Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
  Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
  arr->SetLength(myArrowSize);
// -- ota -- begin
  if (!myAutomaticPosition ){
    gp_Pnt aMiddle12 ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
    gp_Pnt aMiddle34 ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);

    if (myPosition.Distance(aMiddle12) > myPosition.Distance(aMiddle34))
      Position12.SetXYZ((myPoint1.XYZ() + myPoint2.XYZ())*0.5);
    else 	
      Position34.SetXYZ((myPoint3.XYZ() + myPoint4.XYZ())*0.5);

  }
  
  if (myFShape.ShapeType() == TopAbs_EDGE && mySShape.ShapeType() == TopAbs_EDGE)
    AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
						     myDrawer,
						     myArrowSize,
						     TopoDS::Edge(myFShape),
						     TopoDS::Edge(mySShape),
						     myPlane,
						     myAutomaticPosition,
						     myIsSetBndBox,
						     myBndBox,
						     Position12,
						     myAttachPoint1,
						     myAttachPoint2,
						     myPoint1,
						     myPoint2,
						     mySymbolPrs );
	 
  
  else if (myFShape.ShapeType() == TopAbs_VERTEX && mySShape.ShapeType() == TopAbs_VERTEX)
    AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
							myDrawer,
							myArrowSize,
							TopoDS::Vertex(myFShape),
							TopoDS::Vertex(mySShape),
							myPlane,
							myAutomaticPosition,
							myIsSetBndBox,
							myBndBox,
							AIS_TOD_Unknown,
							Position12,
							myAttachPoint1,
							myAttachPoint2,
							myPoint1,
							myPoint2,
							mySymbolPrs );
  else 
    AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
							     myDrawer,
							     myArrowSize,
							     myFShape,
							     mySShape,
							     myPlane,
							     myAutomaticPosition,
							     myIsSetBndBox,
							     myBndBox,
							     Position12,
							     myAttachPoint1,
							     myAttachPoint2,
							     myPoint1,
							     myPoint2,
							     mySymbolPrs );

  if (myShape3.ShapeType() == TopAbs_EDGE && myShape4.ShapeType() == TopAbs_EDGE)
    AIS_EqualDistanceRelation::ComputeTwoEdgesLength(aPresentation,
						     myDrawer,
						     myArrowSize,
						     TopoDS::Edge(myShape3),
						     TopoDS::Edge(myShape4),
						     myPlane,
						     myAutomaticPosition,
						     myIsSetBndBox,
						     myBndBox,
						     Position34,
						     myAttachPoint3,
						     myAttachPoint4,
						     myPoint3,
						     myPoint4,
						     mySymbolPrs );
  
  else if (myShape3.ShapeType() == TopAbs_VERTEX && myShape4.ShapeType() == TopAbs_VERTEX)
    AIS_EqualDistanceRelation::ComputeTwoVerticesLength( aPresentation,
							myDrawer,
							myArrowSize,
							TopoDS::Vertex(myShape3),
							TopoDS::Vertex(myShape4),
							myPlane,
							myAutomaticPosition,
							myIsSetBndBox,
							myBndBox,
							AIS_TOD_Unknown,
							Position34,
							myAttachPoint3,
							myAttachPoint4,
							myPoint3,
							myPoint4,
							mySymbolPrs );
   
  else
    AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( aPresentation,
							     myDrawer,
							     myArrowSize,
							     myShape3,
							     myShape4,
							     myPlane,
							     myAutomaticPosition,
							     myIsSetBndBox,
							     myBndBox,
							     Position34,
							     myAttachPoint3,
							     myAttachPoint4,
							     myPoint3,
							     myPoint4,
							     mySymbolPrs );
  
  DsgPrs_EqualDistancePresentation::Add( aPresentation, myDrawer, 
					myPoint1, myPoint2, myPoint3, myPoint4, myPlane );
}


//=======================================================================
//function : Compute
//purpose  : to avoid warning at compilation (SUN)
//=======================================================================

void AIS_EqualDistanceRelation::Compute( const Handle( Prs3d_Projector )& aProjector,
					 const Handle( Prs3d_Presentation )& aPresentation) 
{
// Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::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_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager2d )& aPresentationManager2d,
					 const Handle( Graphic2d_GraphicObject )& aGraphicObject,
					 const Standard_Integer anInteger) 
{
// Standard_NotImplemented::Raise("AIS_EqualDistanceRelation::Compute( const Handle( PrsMgr_PresentationManager2d )&,
//  const Handle( Graphic2d_GraphicObject )&,const Standard_Integer )");
// PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
}

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

//=======================================================================
//function : ComputeSelection
//purpose  : 
//=======================================================================

void AIS_EqualDistanceRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
						  const Standard_Integer ) 
{
  Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
  Handle( Select3D_SensitiveSegment ) seg;

  seg = new Select3D_SensitiveSegment( own, myPoint1, myPoint2 );
  aSelection->Add( seg );

  seg = new Select3D_SensitiveSegment( own, myPoint3, myPoint4 );
  aSelection->Add( seg );

  // Line between two middles
  gp_Pnt Middle12( (myPoint1.XYZ() + myPoint2.XYZ()) * 0.5 ), 
         Middle34( (myPoint3.XYZ() + myPoint4.XYZ()) *0.5 );
  seg = new Select3D_SensitiveSegment( own, Middle12, Middle34 );
  aSelection->Add( seg );

  gp_Pnt Middle((Middle12.XYZ() +  Middle34.XYZ())*0.5);
  Standard_Real SmallDist = .001;
  Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
								  Middle.X() - SmallDist,
								  Middle.Y() - SmallDist,
								  Middle.Z() - SmallDist,
								  Middle.X() + SmallDist,
								  Middle.Y() + SmallDist,
								  Middle.Z() + SmallDist );
  aSelection->Add(box);

  if (myFShape.ShapeType() == TopAbs_EDGE){
    BRepAdaptor_Curve aCurve(TopoDS::Edge(myFShape));
    if (aCurve.GetType() == GeomAbs_Line){
	//add sensetive element - line
      seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
      aSelection->Add( seg );
    }
    else if (aCurve.GetType() == GeomAbs_Circle){
      Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
      Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint1),
                    LastPar  = ElCLib::Parameter(aCircle->Circ(), myPoint1);
      if (LastPar < FirstPar ) LastPar+=PI*2;
      //add sensetive arc
      Handle(Select3D_SensitiveCircle) circ = 
	new Select3D_SensitiveCircle( own, aCircle,  FirstPar, LastPar);
      aSelection->Add( circ );
    }
  }
  else {
      seg = new Select3D_SensitiveSegment( own, myAttachPoint1, myPoint1);
      aSelection->Add( seg );
    }
  
  if (mySShape.ShapeType() == TopAbs_EDGE){
    BRepAdaptor_Curve aCurve(TopoDS::Edge(mySShape));
    if (aCurve.GetType() == GeomAbs_Line) {
      //add sensetive element - line
      seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
      aSelection->Add( seg );
    }
    else if (aCurve.GetType() == GeomAbs_Circle){
      Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
      Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint2),
      LastPar  = ElCLib::Parameter(aCircle->Circ(), myPoint2);
      if (LastPar < FirstPar ) LastPar+=PI*2;
      //add sensetive arc
      Handle(Select3D_SensitiveCircle) circ = 
	new Select3D_SensitiveCircle( own,aCircle,  FirstPar, LastPar);
      aSelection->Add( circ );
    }
  }
  else {
    seg = new Select3D_SensitiveSegment( own, myAttachPoint2, myPoint2);
    aSelection->Add( seg );
  }
    
  if (myShape3.ShapeType() == TopAbs_EDGE){
    BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape3));
    if (aCurve.GetType() == GeomAbs_Line) {
      //add sensetive element - line
      seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
      aSelection->Add( seg );
    }
    else if (aCurve.GetType() == GeomAbs_Circle){
      Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
      Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint3),
      LastPar  = ElCLib::Parameter(aCircle->Circ(), myPoint3);
      if (LastPar < FirstPar ) LastPar+=PI*2;
      Handle(Select3D_SensitiveCircle) circ = 
	new Select3D_SensitiveCircle( own, aCircle,  FirstPar, LastPar);
      aSelection->Add( circ );
    }
    else {
      seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
      aSelection->Add( seg );
    }
  }
  else {
    seg = new Select3D_SensitiveSegment( own, myAttachPoint3, myPoint3);
    aSelection->Add( seg );
  }

  if (myShape4.ShapeType() == TopAbs_EDGE){
    BRepAdaptor_Curve aCurve(TopoDS::Edge(myShape4));
    if (aCurve.GetType() == GeomAbs_Line) {
      //add sensetive element - line
      seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
      aSelection->Add( seg );
    }
    else if (aCurve.GetType() == GeomAbs_Circle){
      Handle(Geom_Circle) aCircle = Handle(Geom_Circle)::DownCast(aCurve.Curve().Curve());
      Standard_Real FirstPar = ElCLib::Parameter(aCircle->Circ(), myAttachPoint4),
      LastPar  = ElCLib::Parameter(aCircle->Circ(), myPoint4);
      if (LastPar < FirstPar ) LastPar+=PI*2;
      //add sensetive arc
      Handle(Select3D_SensitiveCircle) circ = 
	new Select3D_SensitiveCircle( own,aCircle,  FirstPar, LastPar);
      aSelection->Add( circ );
    }
  }
  else {
    seg = new Select3D_SensitiveSegment( own, myAttachPoint4, myPoint4);
    aSelection->Add( seg );
  }
}

//=======================================================================
//function : ComputeTwoEdgesLength
//purpose  : 
//=======================================================================
void AIS_EqualDistanceRelation::ComputeTwoEdgesLength( const Handle( Prs3d_Presentation )& aPresentation,
						      const Handle( AIS_Drawer )& aDrawer,
						      const Standard_Real ArrowSize,
						      const TopoDS_Edge & FirstEdge,
						      const TopoDS_Edge & SecondEdge,
						      const Handle( Geom_Plane )& Plane,
						      const Standard_Boolean AutomaticPos,
						      const Standard_Boolean IsSetBndBox,
						      const Bnd_Box & BndBox,
						      gp_Pnt& Position,
						      gp_Pnt& FirstAttach,
						      gp_Pnt& SecondAttach,
						      gp_Pnt& FirstExtreme,
						      gp_Pnt& SecondExtreme, 
						      DsgPrs_ArrowSide & SymbolPrs )
{ 
  gp_Dir DirAttach;
  BRepAdaptor_Curve cu1( FirstEdge );
  BRepAdaptor_Curve cu2( SecondEdge );
  
  // 3d lines
  Handle(Geom_Curve) geom1,geom2;
  gp_Pnt ptat11,ptat12,ptat21,ptat22;
  
  Standard_Boolean isInfinite1(Standard_False),isInfinite2(Standard_False);
  Handle(Geom_Curve) extCurv;
  Standard_Real arrsize = ArrowSize;// size
  Standard_Real Val=0.;
  Standard_Boolean isInPlane1, isInPlane2;

  if(!AIS::ComputeGeometry(FirstEdge,geom1, ptat11, ptat12,extCurv,isInfinite1,isInPlane1, Plane ))
    return;
  if(!AIS::ComputeGeometry(SecondEdge, geom2, ptat21, ptat22, extCurv, isInfinite2,isInPlane2, Plane))
    return;
  
  aPresentation->SetInfiniteState(isInfinite1 || isInfinite2);
  
  if (cu1.GetType() == GeomAbs_Line && cu2.GetType() == GeomAbs_Line) 
    {
      const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
      const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
      const gp_Lin& l1 = geom_lin1->Lin();
      const gp_Lin& l2 = geom_lin2->Lin();
      
      //Get Val value
      Val = l1.Distance( l2 );
      
      DirAttach = l1.Direction();
      
      if (AutomaticPos) {
	// compute position of offset point
	gp_Pnt curpos;
	Standard_Real par1=0., par2=0.;
	if(!(isInfinite1 || isInfinite2))
	  {
	    par1 = ElCLib::Parameter(l1,ptat11);
	    par2 = ElCLib::Parameter(l1,ptat21);
	    if (par1 <par2){//project ptat11 on l2
	      gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
	      curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
	    }
	    else {//project ptat21 on l1
	      gp_Pnt p2 = ElCLib::Value(par2, l1);
	      curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())*0.5);
	    }
	  }
	else if (!isInfinite1){
	  par2 = ElCLib::Parameter(l1,ptat21);
	  gp_Pnt p2 = ElCLib::Value(par2,l1);
	  curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.);
	}
	else if (!isInfinite2) {
	  gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2);
	  curpos.SetXYZ((ptat11.XYZ()+p2.XYZ())*0.5);
	}
	else   
	  curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())*0.5);
 
    // compute  offset
    gp_Vec offset(DirAttach);
    offset = offset*ArrowSize*(-10.);
    curpos.Translate(offset);
    Position = curpos;
  }
  else {    // project point on the plane
    Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
  }

  // find attach points
  if (!isInfinite1) {
    if (Position.Distance(ptat11) > Position.Distance(ptat12)) FirstAttach = ptat12;
    else FirstAttach = ptat11;
  }
  else {
    FirstAttach = ElCLib::Value(ElCLib::Parameter(l1,Position),l1);
  }
  
  if (!isInfinite2) {
    if (Position.Distance(ptat21) > Position.Distance(ptat22)) SecondAttach = ptat22;
    else SecondAttach = ptat21;
  }
  else {
    SecondAttach = ElCLib::Value(ElCLib::Parameter(l2,Position),l2);
  }

  Standard_Real confusion(Precision::Confusion());
  if (arrsize < confusion) arrsize = Val*0.1;
  if (Abs(Val) <= confusion) {arrsize = 0.;}

  Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
  Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();  
  arr->SetLength(arrsize);
  arr = la->Arrow2Aspect();
  arr->SetLength(arrsize);

  if (AutomaticPos && IsSetBndBox)
    Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
 
   DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
						aDrawer,
						FirstAttach,
						SecondAttach,
						DirAttach,
						Position,
						SymbolPrs,
						FirstExtreme,
						SecondExtreme);
						
      
}
  if (cu1.GetType() == GeomAbs_Circle && cu2.GetType() == GeomAbs_Circle){
    //Get first and last points of circles
    const Handle(Geom_Circle)& aCir1 = Handle(Geom_Circle)::DownCast(geom1);
    const Handle(Geom_Circle)& aCir2 = Handle(Geom_Circle)::DownCast(geom2);
    gp_Circ aCirc1 = aCir1->Circ();
    gp_Circ aCirc2 = aCir2->Circ();

    //To avoid circles with different orientaion
    Standard_Real aTol = Precision::Confusion();
    if(aCirc2.Axis().IsOpposite(aCirc1.Axis(), aTol) ||
       aCirc2.XAxis().IsOpposite(aCirc1.XAxis(), aTol) || 
       aCirc2.YAxis().IsOpposite(aCirc1.YAxis(), aTol) )
      {
	aCirc2.SetPosition(aCirc1.Position());
	aCirc2.SetAxis(aCirc1.Axis());
      }
    
    if (AutomaticPos){ 
      Standard_Real par1 = 0, par2 = 0;
      gp_Pln aPln =  Plane->Pln();
      //Project ptat12 and ptat22 on constraint plane
      gp_Pnt PrPnt12 = AIS::ProjectPointOnPlane(ptat12, aPln);
      gp_Pnt PrPnt22 = AIS::ProjectPointOnPlane(ptat22, aPln);
      //Project circles center on constraint plane
      gp_Pnt PrCenter = AIS::ProjectPointOnPlane(aCirc1.Location(), aPln);

      gp_Dir XDir = aPln.XAxis().Direction();
      gp_Dir YDir = aPln.YAxis().Direction();
      
      
      if (PrPnt12.Distance(PrCenter) >Precision::Confusion())
	{
	  gp_Dir aDir1(PrPnt12.XYZ() - PrCenter.XYZ());
	  Standard_Real anAngle = aDir1.Angle(XDir); //Get the angle in range [0, PI]
	  if (aDir1.Dot(YDir) < 0)
	    anAngle = 2*Standard_PI - anAngle;
	  par1 = anAngle;
	}
      
      if (PrPnt22.Distance(PrCenter) >Precision::Confusion())
	{
	  gp_Dir aDir2(PrPnt22.XYZ() - PrCenter.XYZ());
	  Standard_Real anAngle = aDir2.Angle(XDir); //Get the angle in range [0, PI]
	  if (aDir2.Dot(YDir) < 0)
	    anAngle = 2*Standard_PI - anAngle;
	  par2 = anAngle;
	}
      
      
      if(par1 > par2 ){
	FirstExtreme = ptat12;
	Standard_Real aPar1 = ElCLib::Parameter(aCirc2, ptat12);
	SecondExtreme = ElCLib::Value(aPar1, aCirc2);
      }
      else {
	Standard_Real aPar2 =  ElCLib::Parameter(aCirc1, ptat22);
	FirstExtreme = ElCLib::Value(aPar2, aCirc1);
	SecondExtreme = ptat22;
      }
    }
    else {
      Standard_Real pospar = ElCLib::Parameter(aCirc1, Position);
      FirstExtreme  =  ElCLib::Value(pospar, aCirc1);
      pospar = ElCLib::Parameter(aCirc2, Position);
      SecondExtreme =  ElCLib::Value(pospar, aCirc2);
    }

    DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
								aDrawer,
								aCirc1,
								aCirc2,
								ptat12,
								FirstExtreme, 
								ptat22,
								SecondExtreme,
								SymbolPrs);
    
    FirstAttach = ptat12; SecondAttach = ptat22; //assign attach points
    Position.SetXYZ( (FirstAttach.XYZ() + SecondAttach.XYZ())*0.5);
  }

  if (arrsize < Precision::Confusion()) arrsize = Val*0.1;
  if (Abs(Val) <=  Precision::Confusion()) {arrsize = 0.;}

//  gp_Pnt pf, pl;
  if (!isInPlane1) {
    AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, FirstEdge, geom1, ptat11, ptat12);
  }
  if(!isInPlane2) {
    AIS::ComputeProjEdgePresentation( aPresentation, aDrawer, SecondEdge, geom2, ptat21, ptat22);
  }
}

//=======================================================================
//function : ComputeTwoVerticesLength
//purpose  : 
//=======================================================================

void AIS_EqualDistanceRelation::ComputeTwoVerticesLength( const Handle( Prs3d_Presentation )& aPresentation,
							 const Handle( AIS_Drawer )& aDrawer,
							 const Standard_Real ArrowSize,
							 const TopoDS_Vertex& FirstVertex,
							 const TopoDS_Vertex& SecondVertex,
							 const Handle( Geom_Plane )& Plane,
							 const Standard_Boolean AutomaticPos,
							 const Standard_Boolean IsSetBndBox,
							 const Bnd_Box& BndBox,
							 const AIS_TypeOfDist TypeDist,
							 gp_Pnt& Position,
							 gp_Pnt& FirstAttach,
							 gp_Pnt& SecondAttach,
							 gp_Pnt& FirstExtreme,
							 gp_Pnt& SecondExtreme, 
							 DsgPrs_ArrowSide& SymbolPrs )
{
  Standard_Boolean isOnPlane1, isOnPlane2;
  gp_Dir DirAttach;
  AIS::ComputeGeometry( FirstVertex, FirstAttach, Plane, isOnPlane1);
  AIS::ComputeGeometry( SecondVertex, SecondAttach, Plane, isOnPlane2);

  Standard_Real confusion(Precision::Confusion());
  Standard_Boolean samePoint(FirstAttach.IsEqual(SecondAttach,confusion));

  if (TypeDist == AIS_TOD_Vertical) DirAttach =  Plane->Pln().XAxis().Direction();
  else if (TypeDist == AIS_TOD_Horizontal) DirAttach =  Plane->Pln().YAxis().Direction();
  else {
    if (!samePoint) {
      DirAttach.SetXYZ(SecondAttach.XYZ() - FirstAttach.XYZ());
      DirAttach.Rotate(Plane->Pln().Axis(),PI/2.);
    }
  }
  
  // size
  if (AutomaticPos) {
   if (!samePoint) {
     gp_Pnt curpos((FirstAttach.XYZ()+SecondAttach.XYZ())*0.5);
     // make offset of curpos
     gp_Vec offset(DirAttach);
     offset = offset*ArrowSize*(-10.);
     curpos.Translate(offset);
     Position = curpos;
   }
   else {  
     const gp_Dir& aDir = Plane->Pln().Axis().Direction();
     gp_Vec aVec (aDir.XYZ()*10*ArrowSize);
     //Position = gp_Pnt(FirstAttach.XYZ()+gp_XYZ(1.,1.,1.)); // not correct
     Position = FirstAttach.Translated(aVec);
     Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );//not needed really
     DirAttach.SetXYZ(Position.XYZ() - FirstAttach.XYZ());
   }
  }
  else {   
    Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
  }

 
  Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
  Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();  
  arr->SetLength(ArrowSize);
  arr = la->Arrow2Aspect();
  arr->SetLength(ArrowSize);

  if (AutomaticPos && IsSetBndBox)
    Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );

  DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
						aDrawer,
						FirstAttach,
						SecondAttach,
						DirAttach,
						Position,
						SymbolPrs,
						FirstExtreme, //returned
						SecondExtreme); //returned

  // Compute projection
  if ( !isOnPlane1)
    AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, FirstVertex, FirstAttach);
  if ( !isOnPlane2)
    AIS::ComputeProjVertexPresentation(aPresentation, aDrawer, SecondVertex, SecondAttach);

} 


//=======================================================================
//function : ComputeOneEdgeOneVertexLength
//purpose  : 
//=======================================================================

void AIS_EqualDistanceRelation::ComputeOneEdgeOneVertexLength( const Handle( Prs3d_Presentation )& aPresentation,
							      const Handle( AIS_Drawer )& aDrawer,
							      const Standard_Real ArrowSize,
							      const TopoDS_Shape & FirstShape,
							      const TopoDS_Shape & SecondShape,
							      const Handle( Geom_Plane )& Plane,
							      const Standard_Boolean AutomaticPos,
							      const Standard_Boolean IsSetBndBox,
							      const Bnd_Box & BndBox,
							      gp_Pnt & Position,
							      gp_Pnt & FirstAttach,
							      gp_Pnt & SecondAttach,
							      gp_Pnt& FirstExtreme,
							      gp_Pnt& SecondExtreme, 
							      DsgPrs_ArrowSide & SymbolPrs )
{
  TopoDS_Vertex thevertex;
  TopoDS_Edge theedge;
  
  gp_Pnt ptonedge1,ptonedge2;
  Handle(Geom_Curve) aCurve;
  Handle(Geom_Curve) extCurv;
  Standard_Boolean isInfinite;
  Standard_Real Val;
  Standard_Boolean isOnPlanEdge, isOnPlanVertex;
  Standard_Integer edgenum ;

  if (FirstShape.ShapeType() == TopAbs_VERTEX) {  
    thevertex = TopoDS::Vertex(FirstShape);
    theedge   = TopoDS::Edge(SecondShape);
    edgenum   = 2; //edge is the second shape
  }
  else {
    thevertex = TopoDS::Vertex(SecondShape);
    theedge   = TopoDS::Edge(FirstShape);
    edgenum   = 1;//edge is the first shape
  }
  if (!AIS::ComputeGeometry(theedge,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,Plane))
    return;
  aPresentation->SetInfiniteState(isInfinite);
  AIS::ComputeGeometry(thevertex, FirstAttach, Plane, isOnPlanVertex);

  if ( aCurve->IsInstance(STANDARD_TYPE(Geom_Line)) ) 
    {
  const Handle(Geom_Line)& geom_lin = (Handle(Geom_Line)&) aCurve;
  const gp_Lin& l = geom_lin->Lin();

  // computation of Val
  Val = l.Distance( FirstAttach );

  gp_Dir DirAttach = l.Direction();
  // size
  Standard_Real arrsize = ArrowSize;
  if (Abs(Val) <= Precision::Confusion()) {arrsize = 0.;}

  if (AutomaticPos) {
    gp_Pnt p = ElCLib::Value(ElCLib::Parameter(l,FirstAttach),l);
    gp_Pnt curpos((FirstAttach.XYZ()+p.XYZ())*0.5);
    // make offset 
    gp_Vec offset(DirAttach);
    offset = offset*ArrowSize*(-10.);
    curpos.Translate(offset);
    Position = curpos;
  }
  else { // project point on the plane
    Position = AIS::ProjectPointOnPlane( Position, Plane->Pln() );
  }
  
  if (!isInfinite) {
    if (Position.Distance(ptonedge1) > Position.Distance(ptonedge2)) SecondAttach = ptonedge2;
    else SecondAttach = ptonedge1;
  }
  else {
    SecondAttach = ElCLib::Value(ElCLib::Parameter(l,Position),l);
  }
  
  Handle(Prs3d_LengthAspect) la = aDrawer->LengthAspect();
  Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();  
  arr->SetLength(arrsize);
  arr = la->Arrow2Aspect();
  arr->SetLength(arrsize);

  if (AutomaticPos && IsSetBndBox)
    Position = AIS::TranslatePointToBound( Position, DirAttach, BndBox );
  DsgPrs_EqualDistancePresentation::AddInterval(aPresentation,
						aDrawer,
						FirstAttach,
						SecondAttach,
						DirAttach,
						Position,
						SymbolPrs,
						FirstExtreme,
						SecondExtreme);
  
}
  if (aCurve->IsInstance(STANDARD_TYPE(Geom_Circle))){
    gp_Circ aCirc1 = (Handle(Geom_Circle)::DownCast(aCurve))->Circ();
    gp_Circ aCirc2(aCirc1); aCirc2.SetRadius(0); //create the second formal circle
    if(AutomaticPos)
      {
	SecondAttach = ptonedge2; //a vertex
	Position.SetXYZ((SecondAttach.XYZ() + aCirc1.Location().XYZ())*0.5);
      }
    else {
      Standard_Real aPar =  ElCLib::Parameter(aCirc1, Position);
      SecondAttach =  ElCLib::Value(aPar, aCirc1);
    }

    Handle(Geom_Circle) aCurve2 = new Geom_Circle(aCirc2);
    DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(aPresentation,
								aDrawer,
								aCirc1, //circle or arc
								aCirc2, //really vertex
								ptonedge2, //last point of aCirc1
								SecondAttach,
								FirstAttach, //vertex really
								FirstAttach, 
								SymbolPrs);
    
    //Assign arc points 
    if (edgenum == 1){
      FirstExtreme = SecondAttach; SecondExtreme = FirstAttach;
      SecondAttach = FirstAttach; FirstAttach = ptonedge2; 
    } else { //vertex is the first shape, circle is sthe last.
      FirstExtreme = FirstAttach; SecondExtreme = SecondAttach;
      SecondAttach = ptonedge2;
    }
  }
 
  // computation of Val
  Val = FirstAttach.Distance(SecondAttach);
  
  //Display the pieces of attached to the curve if it is not 
  // in the WP
  if (!isOnPlanEdge) { // add presentation of projection of the edge in WP
      AIS::ComputeProjEdgePresentation(aPresentation,aDrawer,theedge,aCurve,ptonedge1,ptonedge2);
      }
  if (!isOnPlanVertex) { // add presentation of projection of the vertex in WP 
    AIS::ComputeProjVertexPresentation(aPresentation,aDrawer,thevertex,FirstAttach);
    }
  
}
// -- ota -- end