1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Adaptor3d_SurfaceOfLinearExtrusion.hxx>
16 #include <Adaptor3d_SurfaceOfRevolution.hxx>
17 #include <BRep_Builder.hxx>
18 #include <BRep_GCurve.hxx>
19 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
20 #include <BRep_TEdge.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepTools.hxx>
23 #include <Geom2d_Curve.hxx>
24 #include <Geom_ConicalSurface.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_CylindricalSurface.hxx>
27 #include <Geom_OffsetSurface.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_SphericalSurface.hxx>
31 #include <Geom_Surface.hxx>
32 #include <Geom_SurfaceOfLinearExtrusion.hxx>
33 #include <Geom_SurfaceOfRevolution.hxx>
34 #include <Geom_SweptSurface.hxx>
35 #include <Geom_ToroidalSurface.hxx>
36 #include <GeomAdaptor_HCurve.hxx>
37 #include <gp_Cone.hxx>
38 #include <gp_Cylinder.hxx>
41 #include <gp_Sphere.hxx>
42 #include <gp_Torus.hxx>
43 #include <Message_Msg.hxx>
44 #include <ShapeAnalysis_Surface.hxx>
45 #include <ShapeCustom_SweptToElementary.hxx>
46 #include <Standard_Type.hxx>
47 #include <TopLoc_Location.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Vertex.hxx>
52 //=======================================================================
53 //function : ShapeCustom_SweptToElementary
55 //=======================================================================
56 ShapeCustom_SweptToElementary::ShapeCustom_SweptToElementary()
61 //=======================================================================
62 //function : IsToConvert
63 //purpose : auxilary (Analyze surface: is it to be converted?)
64 //=======================================================================
65 static Standard_Boolean IsToConvert (const Handle(Geom_Surface) &S,
66 Handle(Geom_SweptSurface) &SS)
68 Handle(Geom_Surface) Stmp;
70 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
71 SS = Handle(Geom_SweptSurface)::DownCast(S);
74 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
75 Handle(Geom_RectangularTrimmedSurface) RTS =
76 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
77 Stmp = RTS->BasisSurface();
79 else if(S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
80 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(S);
81 Stmp = OS->BasisSurface();
83 if(Stmp.IsNull() ) return Standard_False;
84 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
85 SS = Handle(Geom_SweptSurface)::DownCast(Stmp);
88 return Standard_False;
92 //=======================================================================
93 //function : NewSurface
95 //=======================================================================
97 Standard_Boolean ShapeCustom_SweptToElementary::NewSurface(const TopoDS_Face& F,
98 Handle(Geom_Surface)& S,
101 Standard_Boolean& RevWires,
102 Standard_Boolean& RevFace)
104 S = BRep_Tool::Surface(F,L);
105 Handle(Geom_SweptSurface) SS;
106 if(!IsToConvert(S,SS)) return Standard_False;
108 // case SurfaceOfRevolution
109 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
110 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
111 Handle(Geom_Curve) bc = SR->BasisCurve();
112 gp_Ax1 ax1 = SR->Axis();
113 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
114 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
115 Adaptor3d_SurfaceOfRevolution AS(HC,ax1);
116 switch(AS.GetType()){
117 // skl 18.12.2003 - plane not used, problems in PRO14665.igs
118 //case GeomAbs_Plane : {
119 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
122 case GeomAbs_Cylinder : {
123 Handle(Geom_CylindricalSurface) Cy =
124 new Geom_CylindricalSurface(AS.Cylinder());
127 case GeomAbs_Sphere : {
128 Handle(Geom_SphericalSurface) Sp =
129 new Geom_SphericalSurface(AS.Sphere());
132 case GeomAbs_Cone : {
133 Handle(Geom_ConicalSurface) Co =
134 new Geom_ConicalSurface(AS.Cone());
137 case GeomAbs_Torus : {
138 Handle(Geom_ToroidalSurface) To =
139 new Geom_ToroidalSurface(AS.Torus());
142 default : return Standard_False; break;
145 // case SurfaceOfLinearExtrusion
146 else if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
147 Handle(Geom_SurfaceOfLinearExtrusion) SLE =
148 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(SS);
149 Handle(Geom_Curve) bc = SLE->BasisCurve();
150 gp_Dir dir = SLE->Direction();
151 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
152 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
153 Adaptor3d_SurfaceOfLinearExtrusion AS(HC,dir);
154 switch(AS.GetType()){
155 // skl 18.12.2003 - plane not used, problems in ims013.igs
156 //case GeomAbs_Plane : {
157 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
160 case GeomAbs_Cylinder : {
161 Handle(Geom_CylindricalSurface) Cy =
162 new Geom_CylindricalSurface(AS.Cylinder());
165 default : return Standard_False; break;
169 SendMsg( F, Message_Msg("SweptToElementary.NewSurface.MSG0"));
171 Tol = BRep_Tool::Tolerance(F);
172 RevWires = Standard_False;
173 RevFace = Standard_False;
174 return Standard_True;
178 //=======================================================================
179 //function : NewCurve
181 //=======================================================================
183 Standard_Boolean ShapeCustom_SweptToElementary::NewCurve(const TopoDS_Edge& E,
184 Handle(Geom_Curve)& C,
188 //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced
189 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
191 // iterate on pcurves
192 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
193 for ( ; itcr.More(); itcr.Next() ) {
194 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
195 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
196 Handle(Geom_Surface) S = GC->Surface();
197 Handle(Geom_SweptSurface) SS;
198 if(!IsToConvert(S,SS)) continue;
200 C = BRep_Tool::Curve ( E, L, f, l );
201 if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() );
202 Tol = BRep_Tool::Tolerance ( E );
203 return Standard_True;
205 return Standard_False;
209 //=======================================================================
210 //function : NewPoint
212 //=======================================================================
214 Standard_Boolean ShapeCustom_SweptToElementary::NewPoint(const TopoDS_Vertex& /*V*/,
215 gp_Pnt& /*P*/,Standard_Real& /*Tol*/)
217 // 3d points are never modified
218 return Standard_False;
222 //=======================================================================
223 //function : NewCurve2d
225 //=======================================================================
227 Standard_Boolean ShapeCustom_SweptToElementary::NewCurve2d(const TopoDS_Edge& E,
228 const TopoDS_Face& F,
229 const TopoDS_Edge& NewE,
230 const TopoDS_Face& NewF,
231 Handle(Geom2d_Curve)& C,
235 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
236 Handle(Geom_SweptSurface) SS;
238 // just copy pcurve if either its surface is changing or edge was copied
239 if ( !IsToConvert(S,SS) && E.IsSame(NewE) ) return Standard_False;
242 C = BRep_Tool::CurveOnSurface(E,F,f,l);
243 if ( ! C.IsNull() ) {
244 C = Handle(Geom2d_Curve)::DownCast ( C->Copy() );
245 Handle(Geom_Surface) NS = BRep_Tool::Surface(NewF,L);
246 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
247 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
248 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
249 Standard_Real U1,U2,V1,V2;
250 SR->Bounds(U1,U2,V1,V2);
253 Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface(NS);
254 gp_Pnt2d p2d = sas->ValueOfUV(P0,Precision::Confusion());
255 gp_Vec2d shift(p2d.X()-U1,p2d.Y()-V1);
259 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
260 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
261 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
263 Handle(Geom_SphericalSurface) SPH = Handle(Geom_SphericalSurface)::DownCast(NS);
264 Standard_Real US1,US2,VS1,VS2;
265 SPH->Bounds(US1,US2,VS1,VS2);
267 Standard_Real UR1,UR2,VR1,VR2;
268 SR->Bounds(UR1,UR2,VR1,VR2);
270 gp_Pnt P0 = SPH->Location();
273 Standard_Real angle = VS.Angle(VR);
274 gp_Vec2d shift(0,VS1-VR1+angle);
280 Tol = BRep_Tool::Tolerance ( E );
281 return Standard_True;
285 //=======================================================================
286 //function : NewParameter
288 //=======================================================================
290 Standard_Boolean ShapeCustom_SweptToElementary::NewParameter(const TopoDS_Vertex& /*V*/,
291 const TopoDS_Edge& /*E*/,
292 Standard_Real& /*P*/,
293 Standard_Real& /*Tol*/)
295 return Standard_False;
299 //=======================================================================
300 //function : Continuity
302 //=======================================================================
304 GeomAbs_Shape ShapeCustom_SweptToElementary::Continuity(const TopoDS_Edge& E,
305 const TopoDS_Face& F1,
306 const TopoDS_Face& F2,
307 const TopoDS_Edge& /*NewE*/,
308 const TopoDS_Face& /*NewF1*/,
309 const TopoDS_Face& /*NewF2*/)
311 return BRep_Tool::Continuity(E,F1,F2);