Integration of OCCT 6.5.0 from SVN
[occt.git] / src / AIS / AIS_EllipseRadiusDimension.cxx
CommitLineData
7fd59977 1// File: AIS_EllipseRadiusDimension.cxx
2// Created: Thu Jan 22 10:24:00 1998
3// Author: Sergey ZARITCHNY
4// <szy@androx.nnov.matra-dtv.fr>
5
6
7#include <AIS_EllipseRadiusDimension.ixx>
8
9#include <TCollection_ExtendedString.hxx>
10
11#include <ElCLib.hxx>
12#include <ElSLib.hxx>
13
14#include <TopoDS.hxx>
15
16#include <BRepAdaptor_Surface.hxx>
17#include <BRepAdaptor_Curve.hxx>
18
19#include <Geom_Ellipse.hxx>
20#include <Geom_TrimmedCurve.hxx>
21#include <Geom_Plane.hxx>
22#include <Geom_Surface.hxx>
23#include <Geom_CylindricalSurface.hxx>
24#include <Geom_SurfaceOfRevolution.hxx>
25#include <Geom_CylindricalSurface.hxx>
26#include <Geom_SurfaceOfLinearExtrusion.hxx>
27#include <GeomAPI_ExtremaCurveCurve.hxx>
28#include <Geom_Line.hxx>
29#include <GeomAPI.hxx>
30
31#include <gp_Pln.hxx>
32#include <gp_Pnt.hxx>
33#include <gp_Lin.hxx>
34#include <gp_Ax1.hxx>
35#include <gp_Dir.hxx>
36#include <gp_Vec.hxx>
37#include <gp_Elips.hxx>
38
39#include <AIS.hxx>
40
41#include <Precision.hxx>
42
43#include <TopExp_Explorer.hxx>
44
45//=======================================================================
46//function : AIS_EllipseRadiusDimension
47//purpose :
48//=======================================================================
49
50AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape,
51 const TCollection_ExtendedString& aText)
52:AIS_Relation()
53{
54 myFShape = aShape;
55 myText = aText;
56// ComputeGeometry( );
57}
58
59//=======================================================================
60//function : ComputeGeometry
61//purpose :
62//=======================================================================
63
64void AIS_EllipseRadiusDimension::ComputeGeometry()
65{
66
67 switch (myFShape.ShapeType()) {
68 case TopAbs_FACE :
69 {
70 // compute one face case
71 ComputeFaceGeometry ();
72 break;
73 }
74 case TopAbs_EDGE:
75 {
76 ComputeEdgeGeometry ();
77 break;
78 }
79 default:
80 break;
81 }
82 while (myFirstPar > 2*PI) myFirstPar -= 2*PI;
83 while (myLastPar > 2*PI) myLastPar -= 2*PI;
84 while (myFirstPar < 0.0) myFirstPar += 2*PI;
85 while (myLastPar < 0.0) myLastPar += 2*PI;
86}
87
88//=======================================================================
89//function : ComputeFaceGeometry
90//purpose :
91//=======================================================================
92
93void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
94{
95
96 gp_Pln aPln;
97 Handle( Geom_Surface ) aBasisSurf;
98 AIS_KindOfSurface aSurfType;
99 Standard_Real Offset;
100 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
101 aPln,
102 aBasisSurf,
103 aSurfType,
104 Offset ) ;
105
106 if ( aSurfType == AIS_KOS_Plane )
107 ComputePlanarFaceGeometry( );
108 else
109 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
110
111}
112
113//=======================================================================
114//function : ComputeCylFaceGeometry
115//purpose : defines Ellipse and plane of dimension
116//=======================================================================
117
118void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType,
119 const Handle( Geom_Surface )& aBasisSurf,
120 const Standard_Real Offset)
121{
122
123 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
124 Standard_Real vFirst, vLast;
125 vFirst = surf1.FirstVParameter();
126 vLast = surf1.LastVParameter();
127 Standard_Real vMid = (vFirst + vLast)*0.5;
128 gp_Pln aPlane;
129 gp_Ax1 Axis;
130// Standard_Real Param;
131 if (aSurfType == AIS_KOS_Extrusion)
132 {
133 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
134 ->Direction() );
135 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
136 ->Direction().XYZ() ) );
137
138 aPlane.SetAxis(Axis);
139 aPlane.SetLocation(myEllipse.Location());
140 myPlane = new Geom_Plane(aPlane);
141
142 Handle(Geom_Curve) aCurve;
143 aCurve = aBasisSurf->VIso(vMid);
144 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
145 {
146 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
147 myIsAnArc = Standard_False;
148 }
149 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
150 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
151 aCurve = tCurve->BasisCurve();
152 myFirstPar = tCurve->FirstParameter();
153 myLastPar = tCurve->LastParameter();
154 myIsAnArc = Standard_True;
155 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
156 {
157 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
158 }
159 }
160 else
161 {
162 Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
163 return;
164 }
165
166// Offset
167
168 if(surf1.GetType() == GeomAbs_OffsetSurface)
169 {
170 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
171 {
172 Standard_ConstructionError::Raise("AIS:: Absolute value of negative offset is larger than MinorRadius");
173 return;
174 }
175
176 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
177 myPlane->Pln().Axis().Direction());
178 myOffset = Offset;
179 myIsOffset = Standard_True;
180 gp_Elips elips = myEllipse;
181 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
182 myEllipse.SetMajorRadius (Val);
183 Val = Offset + elips.MinorRadius ();
184 myEllipse.SetMinorRadius (Val);
185 }
186 else
187 myIsOffset = Standard_False;
188 }
189}
190
191
192//=======================================================================
193//function : ComputePlanarFaceGeometry
194//purpose :
195//=======================================================================
196
197void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
198{
199
200 Standard_Boolean find = Standard_False;
201 gp_Pnt ptfirst,ptend;
202 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
203 for ( ; ExploEd.More(); ExploEd.Next())
204 {
205 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
206 Handle(Geom_Curve) curv;
207 Handle(Geom_Ellipse) ellips;
208 if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend))
209 {
210 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
211 {
212 ellips = Handle(Geom_Ellipse)::DownCast(curv);
213 if ( !ellips.IsNull() ) {
214 myEllipse = ellips->Elips();
215 find = Standard_True;
216 break;
217 }
218 }
219 }
220 }
221 if( !find )
222 {
223 Standard_ConstructionError::Raise("AIS:: Curve is not an ellipsee or is Null") ;
224 return;
225 }
226
227 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
228 {
229 myIsAnArc = Standard_True;
230 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
231 myLastPar = ElCLib::Parameter(myEllipse, ptend);
232 }
233 else
234 myIsAnArc = Standard_False;
235
236 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
237 myPlane = new Geom_Plane( surfAlgo.Plane() );
238
239}
240
241
242
243//=======================================================================
244//function : ComputeEdgeGeometry
245//purpose :
246//=======================================================================
247
248void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
249{
250 gp_Pnt ptfirst,ptend;
251 Handle(Geom_Curve) curv;
252 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
253
254 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
255 if ( elips.IsNull()) return;
256
257 myEllipse = elips->Elips();
258 gp_Pln aPlane;
259 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
260 myPlane = new Geom_Plane(aPlane);
261
262
263 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
264 myIsAnArc = Standard_False;
265 }
266 else {
267 myIsAnArc = Standard_True;
268 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
269 myLastPar = ElCLib::Parameter(myEllipse, ptend);
270 }
271}
272//=======================================================================
273//function : KindOfDimension
274//purpose :
275//=======================================================================
276 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const
277{
278 return AIS_KOD_ELLIPSERADIUS;
279}
280
281//=======================================================================
282//function : IsMovable
283//purpose :
284//=======================================================================
285 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const
286{
287 return Standard_True;
288}