1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <ShapeCustom_SweptToElementary.ixx>
20 #include <BRep_Builder.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRep_TEdge.hxx>
23 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
24 #include <BRep_GCurve.hxx>
26 #include <Geom_SweptSurface.hxx>
27 #include <Geom_SurfaceOfRevolution.hxx>
28 #include <Geom_SurfaceOfLinearExtrusion.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_OffsetSurface.hxx>
31 #include <Geom_ToroidalSurface.hxx>
32 #include <Geom_SphericalSurface.hxx>
33 #include <Geom_CylindricalSurface.hxx>
34 #include <Geom_ConicalSurface.hxx>
35 #include <Geom_Plane.hxx>
37 #include <Adaptor3d_SurfaceOfRevolution.hxx>
38 #include <Adaptor3d_SurfaceOfLinearExtrusion.hxx>
39 #include <GeomAdaptor_HCurve.hxx>
42 #include <gp_Cylinder.hxx>
43 #include <gp_Sphere.hxx>
44 #include <gp_Cone.hxx>
45 #include <gp_Torus.hxx>
47 #include <ShapeAnalysis_Surface.hxx>
49 #include <BRepTools.hxx>
52 //=======================================================================
53 //function : ShapeCustom_SweptToElementary
55 //=======================================================================
57 ShapeCustom_SweptToElementary::ShapeCustom_SweptToElementary()
62 //=======================================================================
63 //function : IsToConvert
64 //purpose : auxilary (Analyze surface: is it to be converted?)
65 //=======================================================================
66 static Standard_Boolean IsToConvert (const Handle(Geom_Surface) &S,
67 Handle(Geom_SweptSurface) &SS)
69 Handle(Geom_Surface) Stmp;
71 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
72 SS = Handle(Geom_SweptSurface)::DownCast(S);
75 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
76 Handle(Geom_RectangularTrimmedSurface) RTS =
77 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
78 Stmp = RTS->BasisSurface();
80 else if(S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
81 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(S);
82 Stmp = OS->BasisSurface();
84 if(Stmp.IsNull() ) return Standard_False;
85 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
86 SS = Handle(Geom_SweptSurface)::DownCast(Stmp);
89 return Standard_False;
93 //=======================================================================
94 //function : NewSurface
96 //=======================================================================
98 Standard_Boolean ShapeCustom_SweptToElementary::NewSurface(const TopoDS_Face& F,
99 Handle(Geom_Surface)& S,
102 Standard_Boolean& RevWires,
103 Standard_Boolean& RevFace)
105 S = BRep_Tool::Surface(F,L);
106 Handle(Geom_SweptSurface) SS;
107 if(!IsToConvert(S,SS)) return Standard_False;
109 // case SurfaceOfRevolution
110 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
111 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
112 Handle(Geom_Curve) bc = SR->BasisCurve();
113 gp_Ax1 ax1 = SR->Axis();
114 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
115 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
116 Adaptor3d_SurfaceOfRevolution AS(HC,ax1);
117 switch(AS.GetType()){
118 // skl 18.12.2003 - plane not used, problems in PRO14665.igs
119 //case GeomAbs_Plane : {
120 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
123 case GeomAbs_Cylinder : {
124 Handle(Geom_CylindricalSurface) Cy =
125 new Geom_CylindricalSurface(AS.Cylinder());
128 case GeomAbs_Sphere : {
129 Handle(Geom_SphericalSurface) Sp =
130 new Geom_SphericalSurface(AS.Sphere());
133 case GeomAbs_Cone : {
134 Handle(Geom_ConicalSurface) Co =
135 new Geom_ConicalSurface(AS.Cone());
138 case GeomAbs_Torus : {
139 Handle(Geom_ToroidalSurface) To =
140 new Geom_ToroidalSurface(AS.Torus());
143 default : return Standard_False; break;
146 // case SurfaceOfLinearExtrusion
147 else if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
148 Handle(Geom_SurfaceOfLinearExtrusion) SLE =
149 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(SS);
150 Handle(Geom_Curve) bc = SLE->BasisCurve();
151 gp_Dir dir = SLE->Direction();
152 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
153 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
154 Adaptor3d_SurfaceOfLinearExtrusion AS(HC,dir);
155 switch(AS.GetType()){
156 // skl 18.12.2003 - plane not used, problems in ims013.igs
157 //case GeomAbs_Plane : {
158 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
161 case GeomAbs_Cylinder : {
162 Handle(Geom_CylindricalSurface) Cy =
163 new Geom_CylindricalSurface(AS.Cylinder());
166 default : return Standard_False; break;
170 Tol = BRep_Tool::Tolerance(F);
171 RevWires = Standard_False;
172 RevFace = Standard_False;
173 return Standard_True;
177 //=======================================================================
178 //function : NewCurve
180 //=======================================================================
182 Standard_Boolean ShapeCustom_SweptToElementary::NewCurve(const TopoDS_Edge& E,
183 Handle(Geom_Curve)& C,
187 //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced
188 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
190 // iterate on pcurves
191 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
192 for ( ; itcr.More(); itcr.Next() ) {
193 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
194 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
195 Handle(Geom_Surface) S = GC->Surface();
196 Handle(Geom_SweptSurface) SS;
197 if(!IsToConvert(S,SS)) continue;
199 C = BRep_Tool::Curve ( E, L, f, l );
200 if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() );
201 Tol = BRep_Tool::Tolerance ( E );
202 return Standard_True;
204 return Standard_False;
208 //=======================================================================
209 //function : NewPoint
211 //=======================================================================
213 Standard_Boolean ShapeCustom_SweptToElementary::NewPoint(const TopoDS_Vertex& /*V*/,
214 gp_Pnt& /*P*/,Standard_Real& /*Tol*/)
216 // 3d points are never modified
217 return Standard_False;
221 //=======================================================================
222 //function : NewCurve2d
224 //=======================================================================
226 Standard_Boolean ShapeCustom_SweptToElementary::NewCurve2d(const TopoDS_Edge& E,
227 const TopoDS_Face& F,
228 const TopoDS_Edge& NewE,
229 const TopoDS_Face& NewF,
230 Handle(Geom2d_Curve)& C,
234 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
235 Handle(Geom_SweptSurface) SS;
237 // just copy pcurve if either its surface is changing or edge was copied
238 if ( !IsToConvert(S,SS) && E.IsSame(NewE) ) return Standard_False;
241 C = BRep_Tool::CurveOnSurface(E,F,f,l);
242 if ( ! C.IsNull() ) {
243 C = Handle(Geom2d_Curve)::DownCast ( C->Copy() );
244 Handle(Geom_Surface) NS = BRep_Tool::Surface(NewF,L);
245 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
246 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
247 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
248 Standard_Real U1,U2,V1,V2;
249 SR->Bounds(U1,U2,V1,V2);
252 Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface(NS);
253 gp_Pnt2d p2d = sas->ValueOfUV(P0,Precision::Confusion());
254 gp_Vec2d shift(p2d.X()-U1,p2d.Y()-V1);
258 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
259 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
260 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
262 Handle(Geom_SphericalSurface) SPH = Handle(Geom_SphericalSurface)::DownCast(NS);
263 Standard_Real US1,US2,VS1,VS2;
264 SPH->Bounds(US1,US2,VS1,VS2);
266 Standard_Real UR1,UR2,VR1,VR2;
267 SR->Bounds(UR1,UR2,VR1,VR2);
269 gp_Pnt P0 = SPH->Location();
272 Standard_Real angle = VS.Angle(VR);
273 gp_Vec2d shift(0,VS1-VR1+angle);
279 Tol = BRep_Tool::Tolerance ( E );
280 return Standard_True;
284 //=======================================================================
285 //function : NewParameter
287 //=======================================================================
289 Standard_Boolean ShapeCustom_SweptToElementary::NewParameter(const TopoDS_Vertex& /*V*/,
290 const TopoDS_Edge& /*E*/,
291 Standard_Real& /*P*/,
292 Standard_Real& /*Tol*/)
294 return Standard_False;
298 //=======================================================================
299 //function : Continuity
301 //=======================================================================
303 GeomAbs_Shape ShapeCustom_SweptToElementary::Continuity(const TopoDS_Edge& E,
304 const TopoDS_Face& F1,
305 const TopoDS_Face& F2,
306 const TopoDS_Edge& /*NewE*/,
307 const TopoDS_Face& /*NewF1*/,
308 const TopoDS_Face& /*NewF2*/)
310 return BRep_Tool::Continuity(E,F1,F2);