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