0024153: Adding OpenCL to OCCT prerequisites
[occt.git] / src / AIS / AIS_EllipseRadiusDimension.cxx
CommitLineData
b311480e 1// Created on: 1998-01-22
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <AIS_EllipseRadiusDimension.ixx>
24
25#include <TCollection_ExtendedString.hxx>
26
27#include <ElCLib.hxx>
28#include <ElSLib.hxx>
29
30#include <TopoDS.hxx>
31
32#include <BRepAdaptor_Surface.hxx>
33#include <BRepAdaptor_Curve.hxx>
34
35#include <Geom_Ellipse.hxx>
36#include <Geom_TrimmedCurve.hxx>
37#include <Geom_Plane.hxx>
38#include <Geom_Surface.hxx>
39#include <Geom_CylindricalSurface.hxx>
40#include <Geom_SurfaceOfRevolution.hxx>
41#include <Geom_CylindricalSurface.hxx>
42#include <Geom_SurfaceOfLinearExtrusion.hxx>
43#include <GeomAPI_ExtremaCurveCurve.hxx>
44#include <Geom_Line.hxx>
45#include <GeomAPI.hxx>
46
47#include <gp_Pln.hxx>
48#include <gp_Pnt.hxx>
49#include <gp_Lin.hxx>
50#include <gp_Ax1.hxx>
51#include <gp_Dir.hxx>
52#include <gp_Vec.hxx>
53#include <gp_Elips.hxx>
54
55#include <AIS.hxx>
56
57#include <Precision.hxx>
58
59#include <TopExp_Explorer.hxx>
60
61//=======================================================================
62//function : AIS_EllipseRadiusDimension
63//purpose :
64//=======================================================================
65
66AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape,
67 const TCollection_ExtendedString& aText)
68:AIS_Relation()
69{
70 myFShape = aShape;
71 myText = aText;
72// ComputeGeometry( );
73}
74
75//=======================================================================
76//function : ComputeGeometry
77//purpose :
78//=======================================================================
79
80void AIS_EllipseRadiusDimension::ComputeGeometry()
81{
82
83 switch (myFShape.ShapeType()) {
84 case TopAbs_FACE :
85 {
86 // compute one face case
87 ComputeFaceGeometry ();
88 break;
89 }
90 case TopAbs_EDGE:
91 {
92 ComputeEdgeGeometry ();
93 break;
94 }
95 default:
96 break;
97 }
c6541a0c
D
98 while (myFirstPar > 2*M_PI) myFirstPar -= 2*M_PI;
99 while (myLastPar > 2*M_PI) myLastPar -= 2*M_PI;
100 while (myFirstPar < 0.0) myFirstPar += 2*M_PI;
101 while (myLastPar < 0.0) myLastPar += 2*M_PI;
7fd59977 102}
103
104//=======================================================================
105//function : ComputeFaceGeometry
106//purpose :
107//=======================================================================
108
109void AIS_EllipseRadiusDimension::ComputeFaceGeometry()
110{
111
112 gp_Pln aPln;
113 Handle( Geom_Surface ) aBasisSurf;
114 AIS_KindOfSurface aSurfType;
115 Standard_Real Offset;
116 AIS::GetPlaneFromFace( TopoDS::Face( myFShape),
117 aPln,
118 aBasisSurf,
119 aSurfType,
120 Offset ) ;
121
122 if ( aSurfType == AIS_KOS_Plane )
123 ComputePlanarFaceGeometry( );
124 else
125 ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset );
126
127}
128
129//=======================================================================
130//function : ComputeCylFaceGeometry
131//purpose : defines Ellipse and plane of dimension
132//=======================================================================
133
134void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType,
135 const Handle( Geom_Surface )& aBasisSurf,
136 const Standard_Real Offset)
137{
138
139 BRepAdaptor_Surface surf1(TopoDS::Face(myFShape));
140 Standard_Real vFirst, vLast;
141 vFirst = surf1.FirstVParameter();
142 vLast = surf1.LastVParameter();
143 Standard_Real vMid = (vFirst + vLast)*0.5;
144 gp_Pln aPlane;
145 gp_Ax1 Axis;
146// Standard_Real Param;
147 if (aSurfType == AIS_KOS_Extrusion)
148 {
149 Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
150 ->Direction() );
151 Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf ))
152 ->Direction().XYZ() ) );
153
154 aPlane.SetAxis(Axis);
155 aPlane.SetLocation(myEllipse.Location());
156 myPlane = new Geom_Plane(aPlane);
157
158 Handle(Geom_Curve) aCurve;
159 aCurve = aBasisSurf->VIso(vMid);
160 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
161 {
162 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips
163 myIsAnArc = Standard_False;
164 }
165 else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
166 Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve);
167 aCurve = tCurve->BasisCurve();
168 myFirstPar = tCurve->FirstParameter();
169 myLastPar = tCurve->LastParameter();
170 myIsAnArc = Standard_True;
171 if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
172 {
173 myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips
174 }
175 }
176 else
177 {
178 Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ;
179 return;
180 }
181
182// Offset
183
184 if(surf1.GetType() == GeomAbs_OffsetSurface)
185 {
186 if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ())
187 {
188 Standard_ConstructionError::Raise("AIS:: Absolute value of negative offset is larger than MinorRadius");
189 return;
190 }
191
192 myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset,
193 myPlane->Pln().Axis().Direction());
194 myOffset = Offset;
195 myIsOffset = Standard_True;
196 gp_Elips elips = myEllipse;
197 Standard_Real Val = Offset + elips.MajorRadius ();//simulation
198 myEllipse.SetMajorRadius (Val);
199 Val = Offset + elips.MinorRadius ();
200 myEllipse.SetMinorRadius (Val);
201 }
202 else
203 myIsOffset = Standard_False;
204 }
205}
206
207
208//=======================================================================
209//function : ComputePlanarFaceGeometry
210//purpose :
211//=======================================================================
212
213void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry()
214{
215
216 Standard_Boolean find = Standard_False;
217 gp_Pnt ptfirst,ptend;
218 TopExp_Explorer ExploEd( TopoDS::Face(myFShape), TopAbs_EDGE );
219 for ( ; ExploEd.More(); ExploEd.Next())
220 {
221 TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() );
222 Handle(Geom_Curve) curv;
223 Handle(Geom_Ellipse) ellips;
224 if (AIS::ComputeGeometry(curedge,curv,ptfirst,ptend))
225 {
226 if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse))
227 {
228 ellips = Handle(Geom_Ellipse)::DownCast(curv);
229 if ( !ellips.IsNull() ) {
230 myEllipse = ellips->Elips();
231 find = Standard_True;
232 break;
233 }
234 }
235 }
236 }
237 if( !find )
238 {
239 Standard_ConstructionError::Raise("AIS:: Curve is not an ellipsee or is Null") ;
240 return;
241 }
242
243 if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) )
244 {
245 myIsAnArc = Standard_True;
246 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
247 myLastPar = ElCLib::Parameter(myEllipse, ptend);
248 }
249 else
250 myIsAnArc = Standard_False;
251
252 BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
253 myPlane = new Geom_Plane( surfAlgo.Plane() );
254
255}
256
257
258
259//=======================================================================
260//function : ComputeEdgeGeometry
261//purpose :
262//=======================================================================
263
264void AIS_EllipseRadiusDimension::ComputeEdgeGeometry()
265{
266 gp_Pnt ptfirst,ptend;
267 Handle(Geom_Curve) curv;
268 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return;
269
270 Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv);
271 if ( elips.IsNull()) return;
272
273 myEllipse = elips->Elips();
274 gp_Pln aPlane;
275 aPlane.SetPosition(gp_Ax3(myEllipse.Position()));
276 myPlane = new Geom_Plane(aPlane);
277
278
279 if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) {
280 myIsAnArc = Standard_False;
281 }
282 else {
283 myIsAnArc = Standard_True;
284 myFirstPar = ElCLib::Parameter(myEllipse, ptfirst);
285 myLastPar = ElCLib::Parameter(myEllipse, ptend);
286 }
287}
288//=======================================================================
289//function : KindOfDimension
290//purpose :
291//=======================================================================
292 AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const
293{
294 return AIS_KOD_ELLIPSERADIUS;
295}
296
297//=======================================================================
298//function : IsMovable
299//purpose :
300//=======================================================================
301 Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const
302{
303 return Standard_True;
304}