Warnings on vc14 were eliminated
[occt.git] / src / ShapeCustom / ShapeCustom_SweptToElementary.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14
6b84c3f7 15#include <GeomAdaptor_SurfaceOfLinearExtrusion.hxx>
16#include <GeomAdaptor_SurfaceOfRevolution.hxx>
7fd59977 17#include <BRep_Builder.hxx>
7fd59977 18#include <BRep_GCurve.hxx>
42cf5bc1 19#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
20#include <BRep_TEdge.hxx>
21#include <BRep_Tool.hxx>
22#include <BRepTools.hxx>
23#include <Geom2d_Curve.hxx>
7fd59977 24#include <Geom_ConicalSurface.hxx>
42cf5bc1 25#include <Geom_Curve.hxx>
26#include <Geom_CylindricalSurface.hxx>
27#include <Geom_OffsetSurface.hxx>
7fd59977 28#include <Geom_Plane.hxx>
42cf5bc1 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>
7fd59977 36#include <GeomAdaptor_HCurve.hxx>
42cf5bc1 37#include <gp_Cone.hxx>
7fd59977 38#include <gp_Cylinder.hxx>
42cf5bc1 39#include <gp_Pln.hxx>
40#include <gp_Pnt.hxx>
7fd59977 41#include <gp_Sphere.hxx>
7fd59977 42#include <gp_Torus.hxx>
da2db6a7 43#include <Message_Msg.hxx>
42cf5bc1 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>
7fd59977 51
92efcf78 52IMPLEMENT_STANDARD_RTTIEXT(ShapeCustom_SweptToElementary,ShapeCustom_Modification)
53
7fd59977 54//=======================================================================
55//function : ShapeCustom_SweptToElementary
56//purpose :
57//=======================================================================
7fd59977 58ShapeCustom_SweptToElementary::ShapeCustom_SweptToElementary()
59{
60}
61
62
63//=======================================================================
64//function : IsToConvert
65//purpose : auxilary (Analyze surface: is it to be converted?)
66//=======================================================================
67static Standard_Boolean IsToConvert (const Handle(Geom_Surface) &S,
68 Handle(Geom_SweptSurface) &SS)
69{
70 Handle(Geom_Surface) Stmp;
71
72 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
73 SS = Handle(Geom_SweptSurface)::DownCast(S);
74 return Standard_True;
75 }
76 if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
77 Handle(Geom_RectangularTrimmedSurface) RTS =
78 Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
79 Stmp = RTS->BasisSurface();
80 }
81 else if(S->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
82 Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast(S);
83 Stmp = OS->BasisSurface();
84 }
85 if(Stmp.IsNull() ) return Standard_False;
86 if(S->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
87 SS = Handle(Geom_SweptSurface)::DownCast(Stmp);
88 return Standard_True;
89 }
90 return Standard_False;
91}
92
93
94//=======================================================================
95//function : NewSurface
96//purpose :
97//=======================================================================
98
99Standard_Boolean ShapeCustom_SweptToElementary::NewSurface(const TopoDS_Face& F,
100 Handle(Geom_Surface)& S,
101 TopLoc_Location& L,
102 Standard_Real& Tol,
103 Standard_Boolean& RevWires,
104 Standard_Boolean& RevFace)
105{
106 S = BRep_Tool::Surface(F,L);
107 Handle(Geom_SweptSurface) SS;
108 if(!IsToConvert(S,SS)) return Standard_False;
109
110 // case SurfaceOfRevolution
111 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
112 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
113 Handle(Geom_Curve) bc = SR->BasisCurve();
114 gp_Ax1 ax1 = SR->Axis();
115 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
116 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
6b84c3f7 117 GeomAdaptor_SurfaceOfRevolution AS(HC,ax1);
7fd59977 118 switch(AS.GetType()){
119 // skl 18.12.2003 - plane not used, problems in PRO14665.igs
120 //case GeomAbs_Plane : {
121 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
122 // S = Pl;
123 //} break;
124 case GeomAbs_Cylinder : {
125 Handle(Geom_CylindricalSurface) Cy =
126 new Geom_CylindricalSurface(AS.Cylinder());
127 S = Cy;
128 } break;
129 case GeomAbs_Sphere : {
130 Handle(Geom_SphericalSurface) Sp =
131 new Geom_SphericalSurface(AS.Sphere());
132 S = Sp;
133 } break;
134 case GeomAbs_Cone : {
135 Handle(Geom_ConicalSurface) Co =
136 new Geom_ConicalSurface(AS.Cone());
137 S = Co;
138 } break;
139 case GeomAbs_Torus : {
140 Handle(Geom_ToroidalSurface) To =
141 new Geom_ToroidalSurface(AS.Torus());
142 S = To;
143 } break;
144 default : return Standard_False; break;
145 }
146 }
147 // case SurfaceOfLinearExtrusion
148 else if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
149 Handle(Geom_SurfaceOfLinearExtrusion) SLE =
150 Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(SS);
151 Handle(Geom_Curve) bc = SLE->BasisCurve();
152 gp_Dir dir = SLE->Direction();
153 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve();
154 HC->ChangeCurve().Load(bc,bc->FirstParameter(),bc->LastParameter());
6b84c3f7 155 GeomAdaptor_SurfaceOfLinearExtrusion AS(HC,dir);
7fd59977 156 switch(AS.GetType()){
157 // skl 18.12.2003 - plane not used, problems in ims013.igs
158 //case GeomAbs_Plane : {
159 // Handle(Geom_Plane) Pl = new Geom_Plane(AS.Plane());
160 // S = Pl;
161 //} break;
162 case GeomAbs_Cylinder : {
163 Handle(Geom_CylindricalSurface) Cy =
164 new Geom_CylindricalSurface(AS.Cylinder());
165 S = Cy;
166 } break;
167 default : return Standard_False; break;
168 }
169 }
170
da2db6a7 171 SendMsg( F, Message_Msg("SweptToElementary.NewSurface.MSG0"));
172
7fd59977 173 Tol = BRep_Tool::Tolerance(F);
174 RevWires = Standard_False;
175 RevFace = Standard_False;
176 return Standard_True;
177}
178
179
180//=======================================================================
181//function : NewCurve
182//purpose :
183//=======================================================================
184
185Standard_Boolean ShapeCustom_SweptToElementary::NewCurve(const TopoDS_Edge& E,
186 Handle(Geom_Curve)& C,
187 TopLoc_Location& L,
188 Standard_Real& Tol)
189{
190 //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced
191 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
192
193 // iterate on pcurves
194 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
195 for ( ; itcr.More(); itcr.Next() ) {
196 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
197 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
198 Handle(Geom_Surface) S = GC->Surface();
199 Handle(Geom_SweptSurface) SS;
200 if(!IsToConvert(S,SS)) continue;
201 Standard_Real f, l;
202 C = BRep_Tool::Curve ( E, L, f, l );
203 if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() );
204 Tol = BRep_Tool::Tolerance ( E );
205 return Standard_True;
206 }
207 return Standard_False;
208}
209
210
211//=======================================================================
212//function : NewPoint
213//purpose :
214//=======================================================================
215
216Standard_Boolean ShapeCustom_SweptToElementary::NewPoint(const TopoDS_Vertex& /*V*/,
217 gp_Pnt& /*P*/,Standard_Real& /*Tol*/)
218{
219 // 3d points are never modified
220 return Standard_False;
221}
222
223
224//=======================================================================
225//function : NewCurve2d
226//purpose :
227//=======================================================================
228
229Standard_Boolean ShapeCustom_SweptToElementary::NewCurve2d(const TopoDS_Edge& E,
230 const TopoDS_Face& F,
231 const TopoDS_Edge& NewE,
232 const TopoDS_Face& NewF,
233 Handle(Geom2d_Curve)& C,
234 Standard_Real& Tol)
235{
236 TopLoc_Location L;
237 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
238 Handle(Geom_SweptSurface) SS;
239
240 // just copy pcurve if either its surface is changing or edge was copied
241 if ( !IsToConvert(S,SS) && E.IsSame(NewE) ) return Standard_False;
242
243 Standard_Real f, l;
244 C = BRep_Tool::CurveOnSurface(E,F,f,l);
245 if ( ! C.IsNull() ) {
246 C = Handle(Geom2d_Curve)::DownCast ( C->Copy() );
247 Handle(Geom_Surface) NS = BRep_Tool::Surface(NewF,L);
248 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
249 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
250 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
251 Standard_Real U1,U2,V1,V2;
252 SR->Bounds(U1,U2,V1,V2);
253 gp_Pnt P0;
254 SR->D0(U1,V1,P0);
255 Handle(ShapeAnalysis_Surface) sas = new ShapeAnalysis_Surface(NS);
256 gp_Pnt2d p2d = sas->ValueOfUV(P0,Precision::Confusion());
257 gp_Vec2d shift(p2d.X()-U1,p2d.Y()-V1);
258 C->Translate(shift);
259 }
260 }
261 if ( !NS.IsNull() && NS->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
262 if(SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
263 Handle(Geom_SurfaceOfRevolution) SR = Handle(Geom_SurfaceOfRevolution)::DownCast(SS);
264 gp_Pnt PR,PS;
265 Handle(Geom_SphericalSurface) SPH = Handle(Geom_SphericalSurface)::DownCast(NS);
266 Standard_Real US1,US2,VS1,VS2;
267 SPH->Bounds(US1,US2,VS1,VS2);
268 SPH->D0(US1,VS1,PS);
269 Standard_Real UR1,UR2,VR1,VR2;
270 SR->Bounds(UR1,UR2,VR1,VR2);
271 SR->D0(UR1,VR1,PR);
272 gp_Pnt P0 = SPH->Location();
273 gp_Vec VS(P0,PS);
274 gp_Vec VR(P0,PR);
275 Standard_Real angle = VS.Angle(VR);
276 gp_Vec2d shift(0,VS1-VR1+angle);
277 C->Translate(shift);
278 }
279 }
280 }
281
282 Tol = BRep_Tool::Tolerance ( E );
283 return Standard_True;
284}
285
286
287//=======================================================================
288//function : NewParameter
289//purpose :
290//=======================================================================
291
292Standard_Boolean ShapeCustom_SweptToElementary::NewParameter(const TopoDS_Vertex& /*V*/,
293 const TopoDS_Edge& /*E*/,
294 Standard_Real& /*P*/,
295 Standard_Real& /*Tol*/)
296{
297 return Standard_False;
298}
299
300
301//=======================================================================
302//function : Continuity
303//purpose :
304//=======================================================================
305
306GeomAbs_Shape ShapeCustom_SweptToElementary::Continuity(const TopoDS_Edge& E,
307 const TopoDS_Face& F1,
308 const TopoDS_Face& F2,
309 const TopoDS_Edge& /*NewE*/,
310 const TopoDS_Face& /*NewF1*/,
311 const TopoDS_Face& /*NewF2*/)
312{
313 return BRep_Tool::Continuity(E,F1,F2);
314}
315