1 // Created on: 1998-01-22
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <AIS_EllipseRadiusDimension.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <BRepAdaptor_Surface.hxx>
24 #include <Geom_CylindricalSurface.hxx>
25 #include <Geom_Ellipse.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_OffsetCurve.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_SurfaceOfLinearExtrusion.hxx>
31 #include <Geom_SurfaceOfRevolution.hxx>
32 #include <Geom_TrimmedCurve.hxx>
33 #include <GeomAPI.hxx>
34 #include <GeomAPI_ExtremaCurveCurve.hxx>
37 #include <gp_Elips.hxx>
42 #include <Precision.hxx>
43 #include <Standard_Type.hxx>
44 #include <TCollection_ExtendedString.hxx>
45 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Shape.hxx>
49 //=======================================================================
50 //function : AIS_EllipseRadiusDimension
52 //=======================================================================
53 AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape,
54 const TCollection_ExtendedString& aText)
59 // ComputeGeometry( );
62 //=======================================================================
63 //function : ComputeGeometry
65 //=======================================================================
67 void AIS_EllipseRadiusDimension::ComputeGeometry()
70 switch (myFShape.ShapeType()) {
73 // compute one face case
74 ComputeFaceGeometry ();
79 ComputeEdgeGeometry ();
85 while (myFirstPar > 2*M_PI) myFirstPar -= 2*M_PI;
86 while (myLastPar > 2*M_PI) myLastPar -= 2*M_PI;
87 while (myFirstPar < 0.0) myFirstPar += 2*M_PI;
88 while (myLastPar < 0.0) myLastPar += 2*M_PI;
91 //=======================================================================
92 //function : ComputeFaceGeometry
94 //=======================================================================
96 void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
100 Handle( Geom_Surface ) aBasisSurf;
101 AIS_KindOfSurface aSurfType;
102 Standard_Real Offset;
103 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
109 if ( aSurfType == AIS_KOS_Plane )
110 ComputePlanarFaceGeometry( );
112 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
116 //=======================================================================
117 //function : ComputeCylFaceGeometry
118 //purpose : defines Ellipse and plane of dimension
119 //=======================================================================
121 void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType,
122 const Handle( Geom_Surface )& aBasisSurf,
123 const Standard_Real Offset)
126 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
127 Standard_Real vFirst, vLast;
128 vFirst = surf1.FirstVParameter();
129 vLast = surf1.LastVParameter();
130 Standard_Real vMid = (vFirst + vLast)*0.5;
133 // Standard_Real Param;
134 if (aSurfType == AIS_KOS_Extrusion)
136 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
138 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
139 ->Direction().XYZ() ) );
141 aPlane.SetAxis(Axis);
142 aPlane.SetLocation(myEllipse.Location());
143 myPlane = new Geom_Plane(aPlane);
145 Handle(Geom_Curve) aCurve;
146 aCurve = aBasisSurf->VIso(vMid);
147 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
149 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
150 myIsAnArc = Standard_False;
152 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
153 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
154 aCurve = tCurve->BasisCurve();
155 myFirstPar = tCurve->FirstParameter();
156 myLastPar = tCurve->LastParameter();
157 myIsAnArc = Standard_True;
158 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
160 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
165 Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
171 if(surf1.GetType() == GeomAbs_OffsetSurface)
173 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
175 Standard_ConstructionError::Raise("AIS:: Absolute value of negative offset is larger than MinorRadius");
179 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
180 myPlane->Pln().Axis().Direction());
182 myIsOffset = Standard_True;
183 gp_Elips elips = myEllipse;
184 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
185 myEllipse.SetMajorRadius (Val);
186 Val = Offset + elips.MinorRadius ();
187 myEllipse.SetMinorRadius (Val);
190 myIsOffset = Standard_False;
195 //=======================================================================
196 //function : ComputePlanarFaceGeometry
198 //=======================================================================
200 void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
203 Standard_Boolean find = Standard_False;
204 gp_Pnt ptfirst,ptend;
205 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
206 for ( ; ExploEd.More(); ExploEd.Next())
208 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
209 Handle(Geom_Curve) curv;
210 Handle(Geom_Ellipse) ellips;
211 if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend))
213 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
215 ellips = Handle(Geom_Ellipse)::DownCast(curv);
216 if ( !ellips.IsNull() ) {
217 myEllipse = ellips->Elips();
218 find = Standard_True;
226 Standard_ConstructionError::Raise("AIS:: Curve is not an ellipsee or is Null") ;
230 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
232 myIsAnArc = Standard_True;
233 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
234 myLastPar = ElCLib::Parameter(myEllipse, ptend);
237 myIsAnArc = Standard_False;
239 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
240 myPlane = new Geom_Plane( surfAlgo.Plane() );
246 //=======================================================================
247 //function : ComputeEdgeGeometry
249 //=======================================================================
251 void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
253 gp_Pnt ptfirst,ptend;
254 Handle(Geom_Curve) curv;
255 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
257 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
258 if ( elips.IsNull()) return;
260 myEllipse = elips->Elips();
262 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
263 myPlane = new Geom_Plane(aPlane);
266 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
267 myIsAnArc = Standard_False;
270 myIsAnArc = Standard_True;
271 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
272 myLastPar = ElCLib::Parameter(myEllipse, ptend);
275 //=======================================================================
276 //function : KindOfDimension
278 //=======================================================================
279 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const
281 return AIS_KOD_ELLIPSERADIUS;
284 //=======================================================================
285 //function : IsMovable
287 //=======================================================================
288 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const
290 return Standard_True;