0022627: Change OCCT memory management defaults
[occt.git] / src / DrawDim / DrawDim_Distance.cxx
1 // File:        DrawDim_Distance.cxx
2 // Created:     Mon Apr 21 14:38:30 1997
3 // Author:      Denis PASCAL
4
5 #include <DrawDim_Distance.ixx>
6 #include <DrawDim.hxx>
7 #include <TopoDS_Shape.hxx>
8 #include <TopoDS.hxx>
9 #include <BRepAdaptor_Surface.hxx>
10 #include <gp_Pln.hxx>
11 #include <gp_Ax1.hxx>
12 #include <gp_Ax2.hxx>
13 #include <gp_Dir.hxx>
14 #include <gp_Vec.hxx>
15 #include <TopExp_Explorer.hxx>
16 #include <TopoDS_Vertex.hxx>
17 #include <BRep_Tool.hxx>
18 #include <Precision.hxx>
19 #include <TCollection_AsciiString.hxx>
20
21
22 //=======================================================================
23 //function : DrawDim_Distance
24 //purpose  : 
25 //=======================================================================
26
27 DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1,
28                                     const TopoDS_Face& plane2)
29 {
30   myPlane1 = plane1;
31   myPlane2 = plane2;
32 }
33
34
35 //=======================================================================
36 //function : DrawDim_Distance
37 //purpose  : 
38 //=======================================================================
39
40 DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1)
41
42 {
43   myPlane1 = plane1;
44 }
45
46 //=======================================================================
47 //function : Plane1
48 //purpose  : 
49 //=======================================================================
50
51 const TopoDS_Face& DrawDim_Distance::Plane1() const
52 {
53   return myPlane1;
54 }
55
56 //=======================================================================
57 //function : Plane1
58 //purpose  : 
59 //=======================================================================
60
61  void DrawDim_Distance::Plane1(const TopoDS_Face& face) 
62 {
63   myPlane1 = face;
64 }
65
66 //=======================================================================
67 //function : Plane2
68 //purpose  : 
69 //=======================================================================
70
71 const TopoDS_Face& DrawDim_Distance::Plane2() const
72 {
73   return myPlane2;
74 }
75
76 //=======================================================================
77 //function : Plane2
78 //purpose  : 
79 //=======================================================================
80
81 void DrawDim_Distance::Plane2(const TopoDS_Face& face) 
82
83   myPlane2 = face;
84 }
85
86
87 //=======================================================================
88 //function : DrawOn
89 //purpose  : 
90 //=======================================================================
91
92 void DrawDim_Distance::DrawOn(Draw_Display& dis) const
93 {
94
95   // compute the points and the direction
96   BRepAdaptor_Surface surf1(myPlane1);
97
98   // today we process only planar faces
99   if (surf1.GetType() != GeomAbs_Plane)
100     return;
101   
102   const gp_Ax1& anAx1 = surf1.Plane().Axis();
103   gp_Vec V = anAx1.Direction();
104
105   // output
106   gp_Pnt FAttach;   // first attach point
107   gp_Pnt SAttach;   // second attach point
108
109   // first point, try a vertex
110   TopExp_Explorer explo(myPlane1,TopAbs_VERTEX);
111   if (explo.More()) {
112     FAttach = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
113   }
114   else {
115     // no vertex, use the origin
116     FAttach = anAx1.Location();
117   }
118   
119
120   if (!myPlane2.IsNull()) {
121     // translate the point until the second face
122     BRepAdaptor_Surface surf2(myPlane2);
123     surf2.D0(0,0,SAttach);
124     Standard_Real r = V.Dot(gp_Vec(FAttach,SAttach));
125     V *= r;
126   }
127     
128   SAttach = FAttach;
129   SAttach.Translate(V);
130
131   // DISPLAY
132   dis.Draw (FAttach,SAttach);
133   V *= 0.5;
134   FAttach.Translate(V);
135   dis.DrawMarker(FAttach, Draw_Losange);
136   DrawText(FAttach,dis);
137 }