summaryrefslogtreecommitdiff
path: root/src/DrawDim/DrawDim_Distance.cxx
blob: a925fd12946f86f1c70946e467ca006504555eff (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
// File:	DrawDim_Distance.cxx
// Created:	Mon Apr 21 14:38:30 1997
// Author:	Denis PASCAL

#include <DrawDim_Distance.ixx>
#include <DrawDim.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <gp_Pln.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <Precision.hxx>
#include <TCollection_AsciiString.hxx>


//=======================================================================
//function : DrawDim_Distance
//purpose  : 
//=======================================================================

DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1,
				    const TopoDS_Face& plane2)
{
  myPlane1 = plane1;
  myPlane2 = plane2;
}


//=======================================================================
//function : DrawDim_Distance
//purpose  : 
//=======================================================================

DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1)

{
  myPlane1 = plane1;
}

//=======================================================================
//function : Plane1
//purpose  : 
//=======================================================================

const TopoDS_Face& DrawDim_Distance::Plane1() const
{
  return myPlane1;
}

//=======================================================================
//function : Plane1
//purpose  : 
//=======================================================================

 void DrawDim_Distance::Plane1(const TopoDS_Face& face) 
{
  myPlane1 = face;
}

//=======================================================================
//function : Plane2
//purpose  : 
//=======================================================================

const TopoDS_Face& DrawDim_Distance::Plane2() const
{
  return myPlane2;
}

//=======================================================================
//function : Plane2
//purpose  : 
//=======================================================================

void DrawDim_Distance::Plane2(const TopoDS_Face& face) 
{ 
  myPlane2 = face;
}


//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================

void DrawDim_Distance::DrawOn(Draw_Display& dis) const
{

  // compute the points and the direction
  BRepAdaptor_Surface surf1(myPlane1);

  // today we process only planar faces
  if (surf1.GetType() != GeomAbs_Plane)
    return;
  
  const gp_Ax1& anAx1 = surf1.Plane().Axis();
  gp_Vec V = anAx1.Direction();

  // output
  gp_Pnt FAttach;   // first attach point
  gp_Pnt SAttach;   // second attach point

  // first point, try a vertex
  TopExp_Explorer explo(myPlane1,TopAbs_VERTEX);
  if (explo.More()) {
    FAttach = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
  }
  else {
    // no vertex, use the origin
    FAttach = anAx1.Location();
  }
  

  if (!myPlane2.IsNull()) {
    // translate the point until the second face
    BRepAdaptor_Surface surf2(myPlane2);
    surf2.D0(0,0,SAttach);
    Standard_Real r = V.Dot(gp_Vec(FAttach,SAttach));
    V *= r;
  }
    
  SAttach = FAttach;
  SAttach.Translate(V);

  // DISPLAY
  dis.Draw (FAttach,SAttach);
  V *= 0.5;
  FAttach.Translate(V);
  dis.DrawMarker(FAttach, Draw_Losange);
  DrawText(FAttach,dis);
}