1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <GeomAdaptor_SurfaceOfLinearExtrusion.hxx>
16 #include <GeomAdaptor_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_Curve.hxx>
37 #include <gp_Cone.hxx>
38 #include <gp_Cylinder.hxx>
39 #include <gp_Pln.hxx>
40 #include <gp_Pnt.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>
51
IMPLEMENT_STANDARD_RTTIEXT(ShapeCustom_SweptToElementary,ShapeCustom_Modification)52 IMPLEMENT_STANDARD_RTTIEXT(ShapeCustom_SweptToElementary,ShapeCustom_Modification)
53
54 //=======================================================================
55 //function : ShapeCustom_SweptToElementary
56 //purpose :
57 //=======================================================================
58 ShapeCustom_SweptToElementary::ShapeCustom_SweptToElementary()
59 {
60 }
61
62
63 //=======================================================================
64 //function : IsToConvert
65 //purpose : auxiliary (Analyze surface: is it to be converted?)
66 //=======================================================================
IsToConvert(const Handle (Geom_Surface)& S,Handle (Geom_SweptSurface)& SS)67 static 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
NewSurface(const TopoDS_Face & F,Handle (Geom_Surface)& S,TopLoc_Location & L,Standard_Real & Tol,Standard_Boolean & RevWires,Standard_Boolean & RevFace)99 Standard_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_Curve) HC = new GeomAdaptor_Curve();
116 HC->Load(bc,bc->FirstParameter(),bc->LastParameter());
117 GeomAdaptor_SurfaceOfRevolution AS(HC,ax1);
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_Curve) HC = new GeomAdaptor_Curve();
154 HC->Load(bc,bc->FirstParameter(),bc->LastParameter());
155 GeomAdaptor_SurfaceOfLinearExtrusion AS(HC,dir);
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
171 SendMsg( F, Message_Msg("SweptToElementary.NewSurface.MSG0"));
172
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
NewCurve(const TopoDS_Edge & E,Handle (Geom_Curve)& C,TopLoc_Location & L,Standard_Real & Tol)185 Standard_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
NewPoint(const TopoDS_Vertex &,gp_Pnt &,Standard_Real &)216 Standard_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
NewCurve2d(const TopoDS_Edge & E,const TopoDS_Face & F,const TopoDS_Edge & NewE,const TopoDS_Face & NewF,Handle (Geom2d_Curve)& C,Standard_Real & Tol)229 Standard_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
NewParameter(const TopoDS_Vertex &,const TopoDS_Edge &,Standard_Real &,Standard_Real &)292 Standard_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
Continuity(const TopoDS_Edge & E,const TopoDS_Face & F1,const TopoDS_Face & F2,const TopoDS_Edge &,const TopoDS_Face &,const TopoDS_Face &)306 GeomAbs_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
316