b311480e |
1 | // Created on: 1999-06-17 |
2 | // Created by: data exchange team |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <ShapeCustom_ConvertToBSpline.ixx> |
18 | #include <Geom_RectangularTrimmedSurface.hxx> |
19 | #include <Geom_OffsetSurface.hxx> |
20 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
21 | #include <Geom_SurfaceOfRevolution.hxx> |
22 | #include <Geom_BSplineSurface.hxx> |
23 | #include <Geom_Plane.hxx> |
24 | #include <BRep_Tool.hxx> |
25 | #include <ShapeConstruct.hxx> |
26 | #include <Precision.hxx> |
27 | #include <BRep_TEdge.hxx> |
28 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
29 | #include <BRep_GCurve.hxx> |
30 | #include <BRepTools.hxx> |
31 | |
32 | //======================================================================= |
33 | //function : ShapeCustom_ConvertToBSpline |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | ShapeCustom_ConvertToBSpline::ShapeCustom_ConvertToBSpline(): |
38 | myExtrMode(Standard_True), myRevolMode(Standard_True), |
39 | myOffsetMode(Standard_True), myPlaneMode(Standard_False) |
40 | { |
41 | } |
42 | |
43 | //======================================================================= |
44 | //function : IsToConvert |
45 | //purpose : |
46 | //======================================================================= |
47 | |
48 | Standard_Boolean ShapeCustom_ConvertToBSpline::IsToConvert(const Handle(Geom_Surface) &S, |
49 | Handle(Geom_Surface) &SS) const |
50 | { |
51 | SS = S; |
52 | if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
53 | Handle(Geom_RectangularTrimmedSurface) RTS = |
54 | Handle(Geom_RectangularTrimmedSurface)::DownCast ( S ); |
55 | SS = RTS->BasisSurface(); |
56 | } |
eafb234b |
57 | if(SS->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { |
7fd59977 |
58 | if(myOffsetMode) |
59 | return Standard_True; |
60 | else { |
61 | Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast ( SS ); |
62 | Handle(Geom_Surface) basis = OS->BasisSurface(); |
63 | Handle(Geom_Surface) tmp; |
64 | return IsToConvert(basis,tmp); |
65 | } |
eafb234b |
66 | } |
7fd59977 |
67 | if ( SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) ) |
68 | return myExtrMode; |
69 | if ( SS->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)) ) |
70 | return myRevolMode; |
71 | if ( SS->IsKind(STANDARD_TYPE(Geom_Plane)) ) |
72 | return myPlaneMode; |
73 | return Standard_False; |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : NewSurface |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | Standard_Boolean ShapeCustom_ConvertToBSpline::NewSurface (const TopoDS_Face& F, |
82 | Handle(Geom_Surface)& S, |
83 | TopLoc_Location& L, |
84 | Standard_Real& Tol, |
85 | Standard_Boolean& RevWires, |
86 | Standard_Boolean& RevFace) |
87 | { |
88 | S = BRep_Tool::Surface(F,L); |
89 | Standard_Real U1,U2,V1,V2; |
90 | S->Bounds(U1,U2,V1,V2); |
91 | Standard_Real Umin, Umax,Vmin,Vmax; |
92 | BRepTools::UVBounds(F,Umin, Umax, Vmin, Vmax); |
93 | if(Precision::IsInfinite(U1) || Precision::IsInfinite(U2)) { |
94 | U1 = Umin; |
95 | U2 = Umax; |
96 | } |
97 | if(Precision::IsInfinite(V1) || Precision::IsInfinite(V2)) { |
98 | V1 = Vmin; |
99 | V2 = Vmax; |
100 | } |
101 | |
102 | Handle(Geom_Surface) surf; |
103 | if ( ! IsToConvert ( S, surf) ) return Standard_False; |
104 | |
105 | Handle(Geom_Surface) res; |
106 | if(surf->IsKind(STANDARD_TYPE(Geom_OffsetSurface))&&!myOffsetMode) { |
107 | Handle(Geom_OffsetSurface) OS = Handle(Geom_OffsetSurface)::DownCast ( surf ); |
108 | Handle(Geom_Surface) basis = OS->BasisSurface(); |
109 | Standard_Real offset = OS->Offset(); |
110 | Handle(Geom_BSplineSurface) bspl = ShapeConstruct:: |
111 | ConvertSurfaceToBSpline(basis,U1,U2,V1,V2,Precision::Approximation(), |
112 | surf->Continuity(),10000,15); |
113 | Handle(Geom_OffsetSurface) nOff = new Geom_OffsetSurface(bspl,offset); |
114 | res = nOff; |
115 | } |
116 | else { |
117 | GeomAbs_Shape cnt = surf->Continuity(); |
118 | if(surf->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) |
119 | cnt = GeomAbs_C0; //pdn 30.06.99 because of hang-up in GeomConvert_ApproxSurface |
120 | res = ShapeConstruct::ConvertSurfaceToBSpline(surf,U1,U2,V1,V2,Precision::Approximation(), |
121 | cnt,10000,15); |
122 | } |
123 | if(S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ) { |
124 | Handle(Geom_RectangularTrimmedSurface) RTS = |
125 | Handle(Geom_RectangularTrimmedSurface)::DownCast ( S ); |
126 | Standard_Real UF, UL, VF, VL; |
127 | RTS->Bounds ( UF, UL, VF, VL ); |
128 | S = new Geom_RectangularTrimmedSurface ( res, UF, UL, VF, VL ); |
129 | } |
130 | else |
131 | S = res; |
132 | |
133 | Tol = BRep_Tool::Tolerance(F); |
134 | RevWires = Standard_False; |
135 | RevFace = Standard_False; |
136 | return Standard_True; |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : NewCurve |
141 | //purpose : |
142 | //======================================================================= |
143 | |
144 | Standard_Boolean ShapeCustom_ConvertToBSpline::NewCurve (const TopoDS_Edge& E, |
145 | Handle(Geom_Curve)& C, |
146 | TopLoc_Location& L, |
147 | Standard_Real& Tol) |
148 | { |
149 | //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced |
150 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape()); |
151 | |
152 | // iterate on pcurves |
153 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); |
154 | for ( ; itcr.More(); itcr.Next() ) { |
155 | Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value()); |
156 | if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue; |
157 | Handle(Geom_Surface) S = GC->Surface(); |
158 | Handle(Geom_Surface) ES; |
159 | if ( ! IsToConvert ( S, ES ) ) continue; |
160 | Standard_Real f, l; |
161 | C = BRep_Tool::Curve ( E, L, f, l ); |
162 | if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() ); |
163 | Tol = BRep_Tool::Tolerance ( E ); |
164 | return Standard_True; |
165 | } |
166 | return Standard_False; |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : NewPoint |
171 | //purpose : |
172 | //======================================================================= |
173 | |
174 | Standard_Boolean ShapeCustom_ConvertToBSpline::NewPoint (const TopoDS_Vertex& /*V*/, |
175 | gp_Pnt& /*P*/, Standard_Real& /*Tol*/) |
176 | { |
177 | return Standard_False; |
178 | } |
179 | |
180 | //======================================================================= |
181 | //function : NewCurve2d |
182 | //purpose : |
183 | //======================================================================= |
184 | |
185 | Standard_Boolean ShapeCustom_ConvertToBSpline::NewCurve2d (const TopoDS_Edge& E, |
186 | const TopoDS_Face& F, |
187 | const TopoDS_Edge& NewE, |
188 | const TopoDS_Face& /*NewF*/, |
189 | Handle(Geom2d_Curve)& C, |
190 | Standard_Real& Tol) |
191 | { |
192 | TopLoc_Location L; |
193 | Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
194 | Handle(Geom_Surface) ES; |
195 | |
196 | // just copy pcurve if either its surface is changing or edge was copied |
197 | if ( ! IsToConvert ( S, ES ) && E.IsSame ( NewE ) ) return Standard_False; |
198 | |
199 | Standard_Real f, l; |
200 | C = BRep_Tool::CurveOnSurface(E,F,f,l); |
201 | if ( ! C.IsNull() ) |
202 | C = Handle(Geom2d_Curve)::DownCast ( C->Copy() ); |
203 | |
204 | Tol = BRep_Tool::Tolerance ( E ); |
205 | return Standard_True; |
206 | } |
207 | |
208 | //======================================================================= |
209 | //function : NewParameter |
210 | //purpose : |
211 | //======================================================================= |
212 | |
213 | Standard_Boolean ShapeCustom_ConvertToBSpline::NewParameter (const TopoDS_Vertex& /*V*/, |
214 | const TopoDS_Edge& /*E*/, |
215 | Standard_Real& /*P*/, |
216 | Standard_Real& /*Tol*/) |
217 | { |
218 | return Standard_False; |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : Continuity |
223 | //purpose : |
224 | //======================================================================= |
225 | |
226 | GeomAbs_Shape ShapeCustom_ConvertToBSpline::Continuity (const TopoDS_Edge& E, |
227 | const TopoDS_Face& F1, |
228 | const TopoDS_Face& F2, |
229 | const TopoDS_Edge& /*NewE*/, |
230 | const TopoDS_Face& /*NewF1*/, |
231 | const TopoDS_Face& /*NewF2*/) |
232 | { |
233 | return BRep_Tool::Continuity(E,F1,F2); |
234 | } |
235 | |
236 | void ShapeCustom_ConvertToBSpline::SetExtrusionMode(const Standard_Boolean extrMode) |
237 | { |
238 | myExtrMode = extrMode; |
239 | } |
240 | |
241 | void ShapeCustom_ConvertToBSpline::SetRevolutionMode(const Standard_Boolean revolMode) |
242 | { |
243 | myRevolMode = revolMode; |
244 | } |
245 | |
246 | void ShapeCustom_ConvertToBSpline::SetOffsetMode(const Standard_Boolean offsetMode) |
247 | { |
248 | myOffsetMode = offsetMode; |
249 | } |
250 | |
251 | void ShapeCustom_ConvertToBSpline::SetPlaneMode(const Standard_Boolean planeMode) |
252 | { |
253 | myPlaneMode = planeMode; |
254 | } |