0024510: Remove unused local variables
[occt.git] / src / DrawDim / DrawDim_Angle.cxx
CommitLineData
b311480e 1// Created on: 1996-05-28
2// Created by: Denis PASCAL
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <DrawDim_Angle.ixx>
18#include <DrawDim.hxx>
19
20#include <BRepAdaptor_Surface.hxx>
21#include <BRep_Tool.hxx>
22#include <ElCLib.hxx>
23#include <ElSLib.hxx>
24#include <gp_Pnt.hxx>
25#include <gp_Pln.hxx>
26#include <gp_Lin.hxx>
27#include <gp_Dir.hxx>
28#include <gp_Ax1.hxx>
29#include <TopoDS.hxx>
30#include <IntAna_QuadQuadGeo.hxx>
31#include <Precision.hxx>
32#include <TopExp_Explorer.hxx>
33#include <TopoDS_Vertex.hxx>
34#include <IntAna_QuadQuadGeo.hxx>
35
36//=======================================================================
37//function : DrawDim_Angle
38//purpose :
39//=======================================================================
40
41DrawDim_Angle::DrawDim_Angle(const TopoDS_Face& plane1, const TopoDS_Face& plane2)
42{
43 myPlane1 = plane1;
44 myPlane2 = plane2;
45}
46
47//=======================================================================
48//function : Plane1
49//purpose :
50//=======================================================================
51
52const TopoDS_Face& DrawDim_Angle::Plane1() const
53{
54 return myPlane1;
55}
56
57//=======================================================================
58//function : Plane1
59//purpose :
60//=======================================================================
61
62void DrawDim_Angle::Plane1(const TopoDS_Face& plane)
63{
64 myPlane1 = plane;
65}
66
67//=======================================================================
68//function : Plane2
69//purpose :
70//=======================================================================
71
72const TopoDS_Face& DrawDim_Angle::Plane2() const
73{
74 return myPlane2;
75}
76
77//=======================================================================
78//function : Plane2
79//purpose :
80//=======================================================================
81
82void DrawDim_Angle::Plane2(const TopoDS_Face& plane)
83{
84 myPlane2 = plane;
85}
86
87
88//=======================================================================
89//function : DrawOn
90//purpose :
91//=======================================================================
92
93void DrawDim_Angle::DrawOn(Draw_Display& ) const
94{
95
96 // input
97 TopoDS_Shape myFShape = myPlane1;
98 TopoDS_Shape mySShape = myPlane2;
99 Standard_Real myVal = GetValue();
100 gp_Ax1 myAxis;
101
102
103 // output
7fd59977 104 gp_Pnt myFAttach;
105 gp_Pnt mySAttach;
106 gp_Pnt myPosition(0.,0.,0.);
107 gp_Pnt myCenter;
108 gp_Dir myFDir;
109 gp_Dir mySDir;
110 Standard_Boolean myAutomaticPosition = Standard_True;
7fd59977 111
0d969553 112 // calculation of myAxis
7fd59977 113 gp_Pln pln1, pln2;
114 if (!DrawDim::Pln(myPlane1,pln1)) return;
115 if (!DrawDim::Pln(myPlane2,pln2)) return;
116 IntAna_QuadQuadGeo ip (pln1,pln2,Precision::Confusion(), Precision::Angular());
117 if (!ip.IsDone()) return;
7fd59977 118
119 gp_Pnt curpos;
120 gp_Ax1 AxePos = myAxis;
121 gp_Dir theAxisDir = AxePos.Direction();
122 gp_Lin theaxis= gp_Lin (myAxis);
123
124 if (myAutomaticPosition) {
125 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
126 Standard_Real curdist = 0;
127 while (explo1.More()) {
128 TopoDS_Vertex vertref = TopoDS::Vertex(explo1.Current());
129 gp_Pnt curpt = BRep_Tool::Pnt(vertref);
130 if (theaxis.Distance(curpt) > curdist) {
131 curdist = theaxis.Distance(curpt);
132 myFAttach = BRep_Tool::Pnt(vertref);
133 }
134 explo1.Next();
135 }
136 curpos = myFAttach.Rotated(AxePos,myVal/2.);
137 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,curpos),theaxis);
138 Standard_Real thedista = myCenter.Distance(myFAttach);
139 if (thedista > Precision::Confusion()) {
140 curpos.Scale(myCenter,1.05);
141 }
142 myPosition = curpos;
143 myAutomaticPosition = Standard_True;
144 }
145 else {
146 curpos = myPosition;
0d969553 147 //myFAttach = the point of myFShape closest to curpos (except for the case when this is a point on the axis)
7fd59977 148 Standard_Real dist = RealLast();
149 TopExp_Explorer explo1(myFShape,TopAbs_VERTEX);
150 gp_Pnt AxePosition = AxePos.Location();
151 gp_Vec AxeVector (theAxisDir);
152 gp_XYZ AxeXYZ = AxeVector.XYZ();
153 while (explo1.More()) {
154 gp_Pnt curpt = BRep_Tool::Pnt(TopoDS::Vertex(explo1.Current()));
155 gp_Vec curvec (AxePosition, curpt);
156 gp_XYZ curXYZ = curvec.XYZ();
157 gp_XYZ Norm (curXYZ.Crossed(AxeXYZ));
6e6cd5d9 158
7fd59977 159 if (Norm.Modulus() > gp::Resolution()) {
160 Standard_Real curdist = curpos.Distance (curpt);
161 if (curdist < dist) {
162 myFAttach = curpt;
163 dist = curdist;
164 }
165 }
166 explo1.Next();
167 }
168 myCenter = ElCLib::Value(ElCLib::Parameter(theaxis,myFAttach),theaxis);
169 }
170
171 mySAttach = myFAttach.Rotated(AxePos,myVal);
172
173 gp_Vec FVec (myCenter, myFAttach);
174 myFDir.SetXYZ (FVec.XYZ());
175 gp_Vec SVec (myCenter, mySAttach);
176 mySDir.SetXYZ (SVec.XYZ());
177
178 if (!myAutomaticPosition) {
0d969553 179 //Projection of the position on the plane defined by myFDir mySDir and normal theAxisDir
7fd59977 180 gp_Pln aPln (myCenter, theAxisDir);
181 Standard_Real U,V;
182 ElSLib::Parameters (aPln, curpos, U, V);
183 curpos = ElSLib::Value (U, V, aPln);
184 }
185
186 // DISPLAY
187 // Add (myVal, myText,myCenter,myFAttach,mySAttach,myFDir,mySDir,theAxisDir,curpos)
188
189
190}
191
192
193
194
195
196
197
198
199