Commit | Line | Data |
---|---|---|
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 | |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <AIS.hxx> |
19 | #include <AIS_EllipseRadiusDimension.hxx> | |
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 <Standard_Type.hxx> |
44 | #include <TCollection_ExtendedString.hxx> | |
7fd59977 | 45 | #include <TopExp_Explorer.hxx> |
42cf5bc1 | 46 | #include <TopoDS.hxx> |
47 | #include <TopoDS_Shape.hxx> | |
7fd59977 | 48 | |
92efcf78 | 49 | IMPLEMENT_STANDARD_RTTIEXT(AIS_EllipseRadiusDimension,AIS_Relation) |
50 | ||
7fd59977 | 51 | //======================================================================= |
52 | //function : AIS_EllipseRadiusDimension | |
53 | //purpose : | |
54 | //======================================================================= | |
7fd59977 | 55 | AIS_EllipseRadiusDimension::AIS_EllipseRadiusDimension(const TopoDS_Shape& aShape, |
56 | const TCollection_ExtendedString& aText) | |
57 | :AIS_Relation() | |
58 | { | |
59 | myFShape = aShape; | |
60 | myText = aText; | |
61 | // ComputeGeometry( ); | |
62 | } | |
63 | ||
64 | //======================================================================= | |
65 | //function : ComputeGeometry | |
66 | //purpose : | |
67 | //======================================================================= | |
68 | ||
69 | void AIS_EllipseRadiusDimension::ComputeGeometry() | |
70 | { | |
71 | ||
72 | switch (myFShape.ShapeType()) { | |
73 | case TopAbs_FACE : | |
74 | { | |
75 | // compute one face case | |
76 | ComputeFaceGeometry (); | |
77 | break; | |
78 | } | |
79 | case TopAbs_EDGE: | |
80 | { | |
81 | ComputeEdgeGeometry (); | |
82 | break; | |
83 | } | |
84 | default: | |
85 | break; | |
86 | } | |
c6541a0c D |
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; | |
7fd59977 | 91 | } |
92 | ||
93 | //======================================================================= | |
94 | //function : ComputeFaceGeometry | |
95 | //purpose : | |
96 | //======================================================================= | |
97 | ||
98 | void AIS_EllipseRadiusDimension::ComputeFaceGeometry() | |
99 | { | |
100 | ||
101 | gp_Pln aPln; | |
102 | Handle( Geom_Surface ) aBasisSurf; | |
103 | AIS_KindOfSurface aSurfType; | |
104 | Standard_Real Offset; | |
105 | AIS::GetPlaneFromFace( TopoDS::Face( myFShape), | |
106 | aPln, | |
107 | aBasisSurf, | |
108 | aSurfType, | |
109 | Offset ) ; | |
110 | ||
111 | if ( aSurfType == AIS_KOS_Plane ) | |
112 | ComputePlanarFaceGeometry( ); | |
113 | else | |
114 | ComputeCylFaceGeometry( aSurfType, aBasisSurf, Offset ); | |
115 | ||
116 | } | |
117 | ||
118 | //======================================================================= | |
119 | //function : ComputeCylFaceGeometry | |
120 | //purpose : defines Ellipse and plane of dimension | |
121 | //======================================================================= | |
122 | ||
123 | void AIS_EllipseRadiusDimension::ComputeCylFaceGeometry(const AIS_KindOfSurface aSurfType, | |
124 | const Handle( Geom_Surface )& aBasisSurf, | |
125 | const Standard_Real Offset) | |
126 | { | |
127 | ||
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; | |
133 | gp_Pln aPlane; | |
134 | gp_Ax1 Axis; | |
135 | // Standard_Real Param; | |
136 | if (aSurfType == AIS_KOS_Extrusion) | |
137 | { | |
138 | Axis.SetDirection((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf )) | |
139 | ->Direction() ); | |
140 | Axis.SetLocation( gp_Pnt((Handle( Geom_SurfaceOfLinearExtrusion )::DownCast( aBasisSurf )) | |
141 | ->Direction().XYZ() ) ); | |
142 | ||
143 | aPlane.SetAxis(Axis); | |
144 | aPlane.SetLocation(myEllipse.Location()); | |
145 | myPlane = new Geom_Plane(aPlane); | |
146 | ||
147 | Handle(Geom_Curve) aCurve; | |
148 | aCurve = aBasisSurf->VIso(vMid); | |
149 | if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) | |
150 | { | |
151 | myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)-> Elips();//gp_Elips | |
152 | myIsAnArc = Standard_False; | |
153 | } | |
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)) | |
161 | { | |
162 | myEllipse = Handle(Geom_Ellipse)::DownCast(aCurve)->Elips();//gp_Elips | |
163 | } | |
164 | } | |
165 | else | |
166 | { | |
9775fa61 | 167 | throw Standard_ConstructionError("AIS:: Not expected type of surface") ; |
7fd59977 | 168 | return; |
169 | } | |
170 | ||
171 | // Offset | |
172 | ||
173 | if(surf1.GetType() == GeomAbs_OffsetSurface) | |
174 | { | |
175 | if(Offset <0.0 && Abs(Offset) > myEllipse.MinorRadius ()) | |
176 | { | |
9775fa61 | 177 | throw Standard_ConstructionError("AIS:: Absolute value of negative offset is larger than MinorRadius"); |
7fd59977 | 178 | return; |
179 | } | |
180 | ||
181 | myOffsetCurve = new Geom_OffsetCurve(new Geom_Ellipse(myEllipse), Offset, | |
182 | myPlane->Pln().Axis().Direction()); | |
183 | myOffset = Offset; | |
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); | |
190 | } | |
191 | else | |
192 | myIsOffset = Standard_False; | |
193 | } | |
194 | } | |
195 | ||
196 | ||
197 | //======================================================================= | |
198 | //function : ComputePlanarFaceGeometry | |
199 | //purpose : | |
200 | //======================================================================= | |
201 | ||
202 | void AIS_EllipseRadiusDimension::ComputePlanarFaceGeometry() | |
203 | { | |
204 | ||
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()) | |
209 | { | |
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)) | |
214 | { | |
215 | if (curv->DynamicType() == STANDARD_TYPE(Geom_Ellipse)) | |
216 | { | |
217 | ellips = Handle(Geom_Ellipse)::DownCast(curv); | |
218 | if ( !ellips.IsNull() ) { | |
219 | myEllipse = ellips->Elips(); | |
220 | find = Standard_True; | |
221 | break; | |
222 | } | |
223 | } | |
224 | } | |
225 | } | |
226 | if( !find ) | |
227 | { | |
9775fa61 | 228 | throw Standard_ConstructionError("AIS:: Curve is not an ellipsee or is Null") ; |
7fd59977 | 229 | return; |
230 | } | |
231 | ||
232 | if ( !ptfirst.IsEqual(ptend, Precision::Confusion()) ) | |
233 | { | |
234 | myIsAnArc = Standard_True; | |
235 | myFirstPar = ElCLib::Parameter(myEllipse, ptfirst); | |
236 | myLastPar = ElCLib::Parameter(myEllipse, ptend); | |
237 | } | |
238 | else | |
239 | myIsAnArc = Standard_False; | |
240 | ||
241 | BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape)); | |
242 | myPlane = new Geom_Plane( surfAlgo.Plane() ); | |
243 | ||
244 | } | |
245 | ||
246 | ||
247 | ||
248 | //======================================================================= | |
249 | //function : ComputeEdgeGeometry | |
250 | //purpose : | |
251 | //======================================================================= | |
252 | ||
253 | void AIS_EllipseRadiusDimension::ComputeEdgeGeometry() | |
254 | { | |
255 | gp_Pnt ptfirst,ptend; | |
256 | Handle(Geom_Curve) curv; | |
257 | if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return; | |
258 | ||
259 | Handle(Geom_Ellipse) elips = Handle(Geom_Ellipse)::DownCast(curv); | |
260 | if ( elips.IsNull()) return; | |
261 | ||
262 | myEllipse = elips->Elips(); | |
263 | gp_Pln aPlane; | |
264 | aPlane.SetPosition(gp_Ax3(myEllipse.Position())); | |
265 | myPlane = new Geom_Plane(aPlane); | |
266 | ||
267 | ||
268 | if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) { | |
269 | myIsAnArc = Standard_False; | |
270 | } | |
271 | else { | |
272 | myIsAnArc = Standard_True; | |
273 | myFirstPar = ElCLib::Parameter(myEllipse, ptfirst); | |
274 | myLastPar = ElCLib::Parameter(myEllipse, ptend); | |
275 | } | |
276 | } | |
277 | //======================================================================= | |
278 | //function : KindOfDimension | |
279 | //purpose : | |
280 | //======================================================================= | |
281 | AIS_KindOfDimension AIS_EllipseRadiusDimension::KindOfDimension() const | |
282 | { | |
283 | return AIS_KOD_ELLIPSERADIUS; | |
284 | } | |
285 | ||
286 | //======================================================================= | |
287 | //function : IsMovable | |
288 | //purpose : | |
289 | //======================================================================= | |
290 | Standard_Boolean AIS_EllipseRadiusDimension::IsMovable() const | |
291 | { | |
292 | return Standard_True; | |
293 | } |