0022312: Translation of french commentaries in OCCT files
[occt.git] / src / DrawDim / DrawDim_Angle.cxx
CommitLineData
7fd59977 1// File: DrawDim_Angle.cxx
2// Created: Tue May 28 12:36:20 1996
3// Author: Denis PASCAL
4// <dp@zerox>
5
6
7#include <DrawDim_Angle.ixx>
8#include <DrawDim.hxx>
9
10#include <BRepAdaptor_Surface.hxx>
11#include <BRep_Tool.hxx>
12#include <ElCLib.hxx>
13#include <ElSLib.hxx>
14#include <gp_Pnt.hxx>
15#include <gp_Pln.hxx>
16#include <gp_Lin.hxx>
17#include <gp_Dir.hxx>
18#include <gp_Ax1.hxx>
19#include <TopoDS.hxx>
20#include <IntAna_QuadQuadGeo.hxx>
21#include <Precision.hxx>
22#include <TopExp_Explorer.hxx>
23#include <TopoDS_Vertex.hxx>
24#include <IntAna_QuadQuadGeo.hxx>
25
26//=======================================================================
27//function : DrawDim_Angle
28//purpose :
29//=======================================================================
30
31DrawDim_Angle::DrawDim_Angle(const TopoDS_Face& plane1, const TopoDS_Face& plane2)
32{
33 myPlane1 = plane1;
34 myPlane2 = plane2;
35}
36
37//=======================================================================
38//function : Plane1
39//purpose :
40//=======================================================================
41
42const TopoDS_Face& DrawDim_Angle::Plane1() const
43{
44 return myPlane1;
45}
46
47//=======================================================================
48//function : Plane1
49//purpose :
50//=======================================================================
51
52void DrawDim_Angle::Plane1(const TopoDS_Face& plane)
53{
54 myPlane1 = plane;
55}
56
57//=======================================================================
58//function : Plane2
59//purpose :
60//=======================================================================
61
62const TopoDS_Face& DrawDim_Angle::Plane2() const
63{
64 return myPlane2;
65}
66
67//=======================================================================
68//function : Plane2
69//purpose :
70//=======================================================================
71
72void DrawDim_Angle::Plane2(const TopoDS_Face& plane)
73{
74 myPlane2 = plane;
75}
76
77
78//=======================================================================
79//function : DrawOn
80//purpose :
81//=======================================================================
82
83void DrawDim_Angle::DrawOn(Draw_Display& ) const
84{
85
86 // input
87 TopoDS_Shape myFShape = myPlane1;
88 TopoDS_Shape mySShape = myPlane2;
89 Standard_Real myVal = GetValue();
90 gp_Ax1 myAxis;
91
92
93 // output
94#ifdef DEB
95 gp_Dir myDirAttach;
96#endif
97 gp_Pnt myFAttach;
98 gp_Pnt mySAttach;
99 gp_Pnt myPosition(0.,0.,0.);
100 gp_Pnt myCenter;
101 gp_Dir myFDir;
102 gp_Dir mySDir;
103 Standard_Boolean myAutomaticPosition = Standard_True;
104
105
106
0d969553 107 // calculation of myAxis
7fd59977 108 gp_Pln pln1, pln2;
109 if (!DrawDim::Pln(myPlane1,pln1)) return;
110 if (!DrawDim::Pln(myPlane2,pln2)) return;
111 IntAna_QuadQuadGeo ip (pln1,pln2,Precision::Confusion(), Precision::Angular());
112 if (!ip.IsDone()) return;
113#ifdef DEB
114 gp_Lin linter =
115#endif
116 ip.Line(1);
117
118 //Handle(Geom_Surface) curve1 = BRep_Tool::Surface(myPlane1);
119 //Handle(Geom_PlaneLine) line1 = Handle(Geom_Line)::DownCast(curve1);
120
121
122
123//=======================================================================
124//function : ComputeTwoFacesAngle
125//purpose :
126//=======================================================================
127
128// void AIS_AngleDimension::ComputeTwoFacesAngle(const Handle(Prs3d_Presentation)& aPresentation)
129// {
0d969553 130 // Return planes
7fd59977 131
132 gp_Pnt curpos;
133 gp_Ax1 AxePos = myAxis;
134 gp_Dir theAxisDir = AxePos.Direction();
135 gp_Lin theaxis= gp_Lin (myAxis);
136
137 if (myAutomaticPosition) {
138 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
139 Standard_Real curdist = 0;
140 while (explo1.More()) {
141 TopoDS_Vertex vertref = TopoDS::Vertex(explo1.Current());
142 gp_Pnt curpt = BRep_Tool::Pnt(vertref);
143 if (theaxis.Distance(curpt) > curdist) {
144 curdist = theaxis.Distance(curpt);
145 myFAttach = BRep_Tool::Pnt(vertref);
146 }
147 explo1.Next();
148 }
149 curpos = myFAttach.Rotated(AxePos,myVal/2.);
150 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,curpos),theaxis);
151 Standard_Real thedista = myCenter.Distance(myFAttach);
152 if (thedista > Precision::Confusion()) {
153 curpos.Scale(myCenter,1.05);
154 }
155 myPosition = curpos;
156 myAutomaticPosition = Standard_True;
157 }
158 else {
159 curpos = myPosition;
0d969553 160 //myFAttach = the point of myFShape closest to curpos (except for the case when this is a point on the axis)
7fd59977 161 Standard_Real dist = RealLast();
162 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
163 gp_Pnt AxePosition = AxePos.Location();
164 gp_Vec AxeVector (theAxisDir);
165 gp_XYZ AxeXYZ = AxeVector.XYZ();
166 while (explo1.More()) {
167 gp_Pnt curpt = BRep_Tool::Pnt(TopoDS::Vertex(explo1.Current()));
168 gp_Vec curvec (AxePosition, curpt);
169 gp_XYZ curXYZ = curvec.XYZ();
170 gp_XYZ Norm (curXYZ.Crossed(AxeXYZ));
171#ifdef DEB
172 Standard_Real NormMod =
173#endif
174 Norm.Modulus();
175 if (Norm.Modulus() > gp::Resolution()) {
176 Standard_Real curdist = curpos.Distance (curpt);
177 if (curdist < dist) {
178 myFAttach = curpt;
179 dist = curdist;
180 }
181 }
182 explo1.Next();
183 }
184 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,myFAttach),theaxis);
185 }
186
187 mySAttach = myFAttach.Rotated(AxePos,myVal);
188
189 gp_Vec FVec (myCenter, myFAttach);
190 myFDir.SetXYZ (FVec.XYZ());
191 gp_Vec SVec (myCenter, mySAttach);
192 mySDir.SetXYZ (SVec.XYZ());
193
194 if (!myAutomaticPosition) {
0d969553 195 //Projection of the position on the plane defined by myFDir mySDir and normal theAxisDir
7fd59977 196 gp_Pln aPln (myCenter, theAxisDir);
197 Standard_Real U,V;
198 ElSLib::Parameters (aPln, curpos, U, V);
199 curpos = ElSLib::Value (U, V, aPln);
200 }
201
202 // DISPLAY
203 // Add (myVal, myText,myCenter,myFAttach,mySAttach,myFDir,mySDir,theAxisDir,curpos)
204
205
206}
207
208
209
210
211
212
213
214
215