summaryrefslogtreecommitdiff
path: root/src/DsgPrs/DsgPrs_EqualRadiusPresentation.cxx
blob: 341f6112d641fa2baf883146d3515871cede460a (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
// File:	DsgPrs_EqualRadiusPresentation.cxx
// Created:	Tue Jan 20 20:51:19 1998
// Author:	Julia GERASIMOVA
//		<jgv@orthodox.nnov.matra-dtv.fr>


#include <DsgPrs_EqualRadiusPresentation.ixx>

#include <DsgPrs.hxx>
#include <Graphic3d_Group.hxx>
#include <Prs3d_LengthAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Graphic3d_Array1OfVertex.hxx>
#include <Prs3d_Root.hxx>
#include <gp_Dir.hxx>
#include <gce_MakeDir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pln.hxx>
#include <Precision.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Prs3d_Text.hxx>

void DsgPrs_EqualRadiusPresentation::Add( const Handle( Prs3d_Presentation )& aPresentation,
					  const Handle( Prs3d_Drawer )& aDrawer,
					  const gp_Pnt& FirstCenter,
					  const gp_Pnt& SecondCenter,
					  const gp_Pnt& FirstPoint,
					  const gp_Pnt& SecondPoint,
					  const Handle( Geom_Plane )& Plane )
{
  Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
  Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );

  Graphic3d_Array1OfVertex VertexArray( 1, 2 );
  Quantity_Length X,Y,Z;

  // Radius lines
  FirstCenter.Coord( X, Y, Z );
  VertexArray( 1 ).SetCoord( X, Y, Z );
  FirstPoint.Coord( X, Y, Z );
  VertexArray( 2 ).SetCoord( X, Y, Z );
  Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );

  SecondCenter.Coord( X, Y, Z );
  VertexArray( 1 ).SetCoord( X, Y, Z );
  SecondPoint.Coord( X, Y, Z );
  VertexArray( 2 ).SetCoord( X, Y, Z );
  Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );

  // Add presentation of arrows
  gp_Dir FirstDir = gce_MakeDir( FirstCenter, FirstPoint ), SecondDir = gce_MakeDir( SecondCenter, SecondPoint );
  DsgPrs::ComputeSymbol( aPresentation, LA,
			 FirstCenter, FirstPoint,
			 FirstDir.Reversed(), FirstDir,
			 DsgPrs_AS_FIRSTPT_LASTAR );
  DsgPrs::ComputeSymbol( aPresentation, LA,
			 SecondCenter, SecondPoint,
			 SecondDir.Reversed(), SecondDir,
			 DsgPrs_AS_FIRSTPT_LASTAR );

  // Line between two centers
  FirstCenter.Coord( X, Y, Z );
  VertexArray( 2 ).SetCoord( X, Y, Z );
  Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );
  
//ota === beging ===

  gp_Pnt Middle( (FirstCenter.XYZ() + SecondCenter.XYZ()) *0.5 ), aTextPos;
  Standard_Real SmallDist;
  //Mark of constraint
  TCollection_ExtendedString aText("==");
  
  Standard_Real Dist = FirstCenter.Distance( SecondCenter );
  if (Dist > Precision::Confusion())
    {
      SmallDist = Dist * 0.05; // take 1/20 part of length;
      if (SmallDist <= Precision::Confusion())
	SmallDist = Dist;
      gp_Dir LineDir = gce_MakeDir( FirstCenter, SecondCenter );
      gp_Dir OrtDir  = Plane->Pln().Axis().Direction() ^ LineDir;

      gp_Vec OrtVec  = gp_Vec( OrtDir ) * SmallDist;
      
      //Compute the text position
      aTextPos = Middle.Translated(OrtVec);
    }
  else
    {
      Standard_Real Rad = Max(FirstCenter.Distance( FirstPoint ),
			      SecondCenter.Distance(SecondPoint));
      
      SmallDist = Rad *0.05; // take 1/20 part of length;
      if (SmallDist <= Precision::Confusion())
	SmallDist = Rad;

      gp_Vec aVec(SmallDist, SmallDist, SmallDist);
      
      //Compute the text position
      aTextPos = FirstCenter.Translated(aVec);
    }
  
  //Draw the text
  Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText, aTextPos);
//ota === end ===     
}