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 IMPLEMENT_STANDARD_RTTIEXT(AIS_EllipseRadiusDimension,AIS_Relation)
51 //=======================================================================
52 //function : AIS_EllipseRadiusDimension
54 //=======================================================================
55 AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape,
56 const TCollection_ExtendedString& aText)
61 // ComputeGeometry( );
64 //=======================================================================
65 //function : ComputeGeometry
67 //=======================================================================
69 void AIS_EllipseRadiusDimension::ComputeGeometry()
72 switch (myFShape.ShapeType()) {
75 // compute one face case
76 ComputeFaceGeometry ();
81 ComputeEdgeGeometry ();
87 while (myFirstPar > 2*M_PI) myFirstPar -= 2*M_PI;
88 while (myLastPar > 2*M_PI) myLastPar -= 2*M_PI;
89 while (myFirstPar < 0.0) myFirstPar += 2*M_PI;
90 while (myLastPar < 0.0) myLastPar += 2*M_PI;
93 //=======================================================================
94 //function : ComputeFaceGeometry
96 //=======================================================================
98 void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
102 Handle( Geom_Surface ) aBasisSurf;
103 AIS_KindOfSurface aSurfType;
104 Standard_Real Offset;
105 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
111 if ( aSurfType == AIS_KOS_Plane )
112 ComputePlanarFaceGeometry( );
114 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
118 //=======================================================================
119 //function : ComputeCylFaceGeometry
120 //purpose : defines Ellipse and plane of dimension
121 //=======================================================================
123 void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType,
124 const Handle( Geom_Surface )& aBasisSurf,
125 const Standard_Real Offset)
128 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
129 Standard_Real vFirst, vLast;
130 vFirst = surf1.FirstVParameter();
131 vLast = surf1.LastVParameter();
132 Standard_Real vMid = (vFirst + vLast)*0.5;
135 // Standard_Real Param;
136 if (aSurfType == AIS_KOS_Extrusion)
138 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
140 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
141 ->Direction().XYZ() ) );
143 aPlane.SetAxis(Axis);
144 aPlane.SetLocation(myEllipse.Location());
145 myPlane = new Geom_Plane(aPlane);
147 Handle(Geom_Curve) aCurve;
148 aCurve = aBasisSurf->VIso(vMid);
149 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
151 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
152 myIsAnArc = Standard_False;
154 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
155 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
156 aCurve = tCurve->BasisCurve();
157 myFirstPar = tCurve->FirstParameter();
158 myLastPar = tCurve->LastParameter();
159 myIsAnArc = Standard_True;
160 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
162 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
167 throw Standard_ConstructionError("AIS:: Not expected type of surface") ;
173 if(surf1.GetType() == GeomAbs_OffsetSurface)
175 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
177 throw Standard_ConstructionError("AIS:: Absolute value of negative offset is larger than MinorRadius");
181 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
182 myPlane->Pln().Axis().Direction());
184 myIsOffset = Standard_True;
185 gp_Elips elips = myEllipse;
186 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
187 myEllipse.SetMajorRadius (Val);
188 Val = Offset + elips.MinorRadius ();
189 myEllipse.SetMinorRadius (Val);
192 myIsOffset = Standard_False;
197 //=======================================================================
198 //function : ComputePlanarFaceGeometry
200 //=======================================================================
202 void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
205 Standard_Boolean find = Standard_False;
206 gp_Pnt ptfirst,ptend;
207 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
208 for ( ; ExploEd.More(); ExploEd.Next())
210 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
211 Handle(Geom_Curve) curv;
212 Handle(Geom_Ellipse) ellips;
213 if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend))
215 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
217 ellips = Handle(Geom_Ellipse)::DownCast(curv);
218 if ( !ellips.IsNull() ) {
219 myEllipse = ellips->Elips();
220 find = Standard_True;
228 throw Standard_ConstructionError("AIS:: Curve is not an ellipsee or is Null") ;
232 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
234 myIsAnArc = Standard_True;
235 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
236 myLastPar = ElCLib::Parameter(myEllipse, ptend);
239 myIsAnArc = Standard_False;
241 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
242 myPlane = new Geom_Plane( surfAlgo.Plane() );
248 //=======================================================================
249 //function : ComputeEdgeGeometry
251 //=======================================================================
253 void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
255 gp_Pnt ptfirst,ptend;
256 Handle(Geom_Curve) curv;
257 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
259 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
260 if ( elips.IsNull()) return;
262 myEllipse = elips->Elips();
264 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
265 myPlane = new Geom_Plane(aPlane);
268 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
269 myIsAnArc = Standard_False;
272 myIsAnArc = Standard_True;
273 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
274 myLastPar = ElCLib::Parameter(myEllipse, ptend);
277 //=======================================================================
278 //function : KindOfDimension
280 //=======================================================================
281 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const
283 return AIS_KOD_ELLIPSERADIUS;
286 //=======================================================================
287 //function : IsMovable
289 //=======================================================================
290 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const
292 return Standard_True;