0024171: Eliminate CLang compiler warning -Wreorder
[occt.git] / src / ShapeCustom / ShapeCustom_SweptToElementary.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18#include <ShapeCustom_SweptToElementary.ixx>
19
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>
25
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>
36
37#include <Adaptor3d_SurfaceOfRevolution.hxx>
38#include <Adaptor3d_SurfaceOfLinearExtrusion.hxx>
39#include <GeomAdaptor_HCurve.hxx>
40
41#include <gp_Pln.hxx>
42#include <gp_Cylinder.hxx>
43#include <gp_Sphere.hxx>
44#include <gp_Cone.hxx>
45#include <gp_Torus.hxx>
46
47#include <ShapeAnalysis_Surface.hxx>
48
49#include <BRepTools.hxx>
50
51
52//=======================================================================
53//function : ShapeCustom_SweptToElementary
54//purpose :
55//=======================================================================
56
57ShapeCustom_SweptToElementary::ShapeCustom_SweptToElementary()
58{
59}
60
61
62//=======================================================================
63//function : IsToConvert
64//purpose : auxilary (Analyze surface: is it to be converted?)
65//=======================================================================
66static Standard_Boolean IsToConvert (const Handle(Geom_Surface) &S,
67 Handle(Geom_SweptSurface) &SS)
68{
69 Handle(Geom_Surface) Stmp;
70
71 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
72 SS = Handle(Geom_SweptSurface)::DownCast(S);
73 return Standard_True;
74 }
75 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
76 Handle(Geom_RectangularTrimmedSurface) RTS =
77 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
78 Stmp = RTS->BasisSurface();
79 }
80 else if(S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
81 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(S);
82 Stmp = OS->BasisSurface();
83 }
84 if(Stmp.IsNull() ) return Standard_False;
85 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
86 SS = Handle(Geom_SweptSurface)::DownCast(Stmp);
87 return Standard_True;
88 }
89 return Standard_False;
90}
91
92
93//=======================================================================
94//function : NewSurface
95//purpose :
96//=======================================================================
97
98Standard_Boolean ShapeCustom_SweptToElementary::NewSurface(const TopoDS_Face& F,
99 Handle(Geom_Surface)& S,
100 TopLoc_Location& L,
101 Standard_Real& Tol,
102 Standard_Boolean& RevWires,
103 Standard_Boolean& RevFace)
104{
105 S = BRep_Tool::Surface(F,L);
106 Handle(Geom_SweptSurface) SS;
107 if(!IsToConvert(S,SS)) return Standard_False;
108
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());
121 // S = Pl;
122 //} break;
123 case GeomAbs_Cylinder : {
124 Handle(Geom_CylindricalSurface) Cy =
125 new Geom_CylindricalSurface(AS.Cylinder());
126 S = Cy;
127 } break;
128 case GeomAbs_Sphere : {
129 Handle(Geom_SphericalSurface) Sp =
130 new Geom_SphericalSurface(AS.Sphere());
131 S = Sp;
132 } break;
133 case GeomAbs_Cone : {
134 Handle(Geom_ConicalSurface) Co =
135 new Geom_ConicalSurface(AS.Cone());
136 S = Co;
137 } break;
138 case GeomAbs_Torus : {
139 Handle(Geom_ToroidalSurface) To =
140 new Geom_ToroidalSurface(AS.Torus());
141 S = To;
142 } break;
143 default : return Standard_False; break;
144 }
145 }
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());
159 // S = Pl;
160 //} break;
161 case GeomAbs_Cylinder : {
162 Handle(Geom_CylindricalSurface) Cy =
163 new Geom_CylindricalSurface(AS.Cylinder());
164 S = Cy;
165 } break;
166 default : return Standard_False; break;
167 }
168 }
169
170 Tol = BRep_Tool::Tolerance(F);
171 RevWires = Standard_False;
172 RevFace = Standard_False;
173 return Standard_True;
174}
175
176
177//=======================================================================
178//function : NewCurve
179//purpose :
180//=======================================================================
181
182Standard_Boolean ShapeCustom_SweptToElementary::NewCurve(const TopoDS_Edge& E,
183 Handle(Geom_Curve)& C,
184 TopLoc_Location& L,
185 Standard_Real& Tol)
186{
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());
189
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;
198 Standard_Real f, l;
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;
203 }
204 return Standard_False;
205}
206
207
208//=======================================================================
209//function : NewPoint
210//purpose :
211//=======================================================================
212
213Standard_Boolean ShapeCustom_SweptToElementary::NewPoint(const TopoDS_Vertex& /*V*/,
214 gp_Pnt& /*P*/,Standard_Real& /*Tol*/)
215{
216 // 3d points are never modified
217 return Standard_False;
218}
219
220
221//=======================================================================
222//function : NewCurve2d
223//purpose :
224//=======================================================================
225
226Standard_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,
231 Standard_Real& Tol)
232{
233 TopLoc_Location L;
234 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
235 Handle(Geom_SweptSurface) SS;
236
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;
239
240 Standard_Real f, l;
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);
250 gp_Pnt P0;
251 SR->D0(U1,V1,P0);
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);
255 C->Translate(shift);
256 }
257 }
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);
261 gp_Pnt PR,PS;
262 Handle(Geom_SphericalSurface) SPH = Handle(Geom_SphericalSurface)::DownCast(NS);
263 Standard_Real US1,US2,VS1,VS2;
264 SPH->Bounds(US1,US2,VS1,VS2);
265 SPH->D0(US1,VS1,PS);
266 Standard_Real UR1,UR2,VR1,VR2;
267 SR->Bounds(UR1,UR2,VR1,VR2);
268 SR->D0(UR1,VR1,PR);
269 gp_Pnt P0 = SPH->Location();
270 gp_Vec VS(P0,PS);
271 gp_Vec VR(P0,PR);
272 Standard_Real angle = VS.Angle(VR);
273 gp_Vec2d shift(0,VS1-VR1+angle);
274 C->Translate(shift);
275 }
276 }
277 }
278
279 Tol = BRep_Tool::Tolerance ( E );
280 return Standard_True;
281}
282
283
284//=======================================================================
285//function : NewParameter
286//purpose :
287//=======================================================================
288
289Standard_Boolean ShapeCustom_SweptToElementary::NewParameter(const TopoDS_Vertex& /*V*/,
290 const TopoDS_Edge& /*E*/,
291 Standard_Real& /*P*/,
292 Standard_Real& /*Tol*/)
293{
294 return Standard_False;
295}
296
297
298//=======================================================================
299//function : Continuity
300//purpose :
301//=======================================================================
302
303GeomAbs_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*/)
309{
310 return BRep_Tool::Continuity(E,F1,F2);
311}
312