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.
17 #include <PrsDim_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_ExtremaCurveCurve.hxx>
36 #include <gp_Elips.hxx>
39 #include <Precision.hxx>
40 #include <TCollection_ExtendedString.hxx>
41 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Shape.hxx>
45 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_EllipseRadiusDimension, PrsDim_Relation)
47 //=======================================================================
48 //function : PrsDim_EllipseRadiusDimension
50 //=======================================================================
51 PrsDim_EllipseRadiusDimension::PrsDim_EllipseRadiusDimension(const TopoDS_Shape& aShape,
52 const TCollection_ExtendedString& aText)
57 // ComputeGeometry( );
60 //=======================================================================
61 //function : ComputeGeometry
63 //=======================================================================
65 void PrsDim_EllipseRadiusDimension::ComputeGeometry()
68 switch (myFShape.ShapeType()) {
71 // compute one face case
72 ComputeFaceGeometry ();
77 ComputeEdgeGeometry ();
83 while (myFirstPar > 2*M_PI) myFirstPar -= 2*M_PI;
84 while (myLastPar > 2*M_PI) myLastPar -= 2*M_PI;
85 while (myFirstPar < 0.0) myFirstPar += 2*M_PI;
86 while (myLastPar < 0.0) myLastPar += 2*M_PI;
89 //=======================================================================
90 //function : ComputeFaceGeometry
92 //=======================================================================
94 void PrsDim_EllipseRadiusDimension::ComputeFaceGeometry()
98 Handle( Geom_Surface ) aBasisSurf;
99 PrsDim_KindOfSurface aSurfType;
100 Standard_Real Offset;
101 PrsDim::GetPlaneFromFace( TopoDS::Face( myFShape),
107 if ( aSurfType == PrsDim_KOS_Plane )
108 ComputePlanarFaceGeometry( );
110 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
114 //=======================================================================
115 //function : ComputeCylFaceGeometry
116 //purpose : defines Ellipse and plane of dimension
117 //=======================================================================
119 void PrsDim_EllipseRadiusDimension::ComputeCylFaceGeometry(const PrsDim_KindOfSurface aSurfType,
120 const Handle( Geom_Surface )& aBasisSurf,
121 const Standard_Real Offset)
124 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
125 Standard_Real vFirst, vLast;
126 vFirst = surf1.FirstVParameter();
127 vLast = surf1.LastVParameter();
128 Standard_Real vMid = (vFirst + vLast)*0.5;
131 // Standard_Real Param;
132 if (aSurfType == PrsDim_KOS_Extrusion)
134 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
136 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
137 ->Direction().XYZ() ) );
139 aPlane.SetAxis(Axis);
140 aPlane.SetLocation(myEllipse.Location());
141 myPlane = new Geom_Plane(aPlane);
143 Handle(Geom_Curve) aCurve;
144 aCurve = aBasisSurf->VIso(vMid);
145 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
147 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
148 myIsAnArc = Standard_False;
150 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
151 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
152 aCurve = tCurve->BasisCurve();
153 myFirstPar = tCurve->FirstParameter();
154 myLastPar = tCurve->LastParameter();
155 myIsAnArc = Standard_True;
156 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
158 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
163 throw Standard_ConstructionError("PrsDim:: Not expected type of surface") ;
169 if(surf1.GetType() == GeomAbs_OffsetSurface)
171 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
173 throw Standard_ConstructionError("PrsDim:: Absolute value of negative offset is larger than MinorRadius");
177 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
178 myPlane->Pln().Axis().Direction());
180 myIsOffset = Standard_True;
181 gp_Elips elips = myEllipse;
182 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
183 myEllipse.SetMajorRadius (Val);
184 Val = Offset + elips.MinorRadius ();
185 myEllipse.SetMinorRadius (Val);
188 myIsOffset = Standard_False;
193 //=======================================================================
194 //function : ComputePlanarFaceGeometry
196 //=======================================================================
198 void PrsDim_EllipseRadiusDimension::ComputePlanarFaceGeometry()
201 Standard_Boolean find = Standard_False;
202 gp_Pnt ptfirst,ptend;
203 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
204 for ( ; ExploEd.More(); ExploEd.Next())
206 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
207 Handle(Geom_Curve) curv;
208 Handle(Geom_Ellipse) ellips;
209 if (PrsDim::ComputeGeometry(curedge,curv,ptfirst,ptend))
211 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
213 ellips = Handle(Geom_Ellipse)::DownCast(curv);
214 if ( !ellips.IsNull() ) {
215 myEllipse = ellips->Elips();
216 find = Standard_True;
224 throw Standard_ConstructionError("PrsDim:: Curve is not an ellipsee or is Null") ;
228 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
230 myIsAnArc = Standard_True;
231 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
232 myLastPar = ElCLib::Parameter(myEllipse, ptend);
235 myIsAnArc = Standard_False;
237 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
238 myPlane = new Geom_Plane( surfAlgo.Plane() );
242 //=======================================================================
243 //function : ComputeEdgeGeometry
245 //=======================================================================
247 void PrsDim_EllipseRadiusDimension::ComputeEdgeGeometry()
249 gp_Pnt ptfirst,ptend;
250 Handle(Geom_Curve) curv;
251 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
253 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
254 if ( elips.IsNull()) return;
256 myEllipse = elips->Elips();
258 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
259 myPlane = new Geom_Plane(aPlane);
262 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
263 myIsAnArc = Standard_False;
266 myIsAnArc = Standard_True;
267 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
268 myLastPar = ElCLib::Parameter(myEllipse, ptend);