b311480e |
1 | // Created on: 1993-04-21 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1993-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 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | |
6b84c3f7 |
17 | #include <GeomAdaptor_SurfaceOfLinearExtrusion.hxx> |
42cf5bc1 |
18 | |
19 | #include <Adaptor3d_HCurve.hxx> |
6b84c3f7 |
20 | #include <GeomAdaptor_HSurfaceOfLinearExtrusion.hxx> |
21 | #include <GeomEvaluator_SurfaceOfExtrusion.hxx> |
42cf5bc1 |
22 | #include <Standard_NoSuchObject.hxx> |
7fd59977 |
23 | |
24 | //======================================================================= |
6b84c3f7 |
25 | //function : GeomAdaptor_SurfaceOfLinearExtrusion |
7fd59977 |
26 | //purpose : |
27 | //======================================================================= |
6b84c3f7 |
28 | GeomAdaptor_SurfaceOfLinearExtrusion::GeomAdaptor_SurfaceOfLinearExtrusion() |
29 | : myHaveDir(Standard_False) |
7fd59977 |
30 | {} |
31 | |
32 | //======================================================================= |
6b84c3f7 |
33 | //function : GeomAdaptor_SurfaceOfLinearExtrusion |
7fd59977 |
34 | //purpose : |
35 | //======================================================================= |
36 | |
6b84c3f7 |
37 | GeomAdaptor_SurfaceOfLinearExtrusion::GeomAdaptor_SurfaceOfLinearExtrusion |
7fd59977 |
38 | (const Handle(Adaptor3d_HCurve)& C) |
6b84c3f7 |
39 | : myHaveDir(Standard_False) |
7fd59977 |
40 | { |
6b84c3f7 |
41 | Load(C); |
7fd59977 |
42 | } |
43 | |
44 | //======================================================================= |
6b84c3f7 |
45 | //function : GeomAdaptor_SurfaceOfLinearExtrusion |
7fd59977 |
46 | //purpose : |
47 | //======================================================================= |
48 | |
6b84c3f7 |
49 | GeomAdaptor_SurfaceOfLinearExtrusion::GeomAdaptor_SurfaceOfLinearExtrusion |
7fd59977 |
50 | (const Handle(Adaptor3d_HCurve)& C, |
51 | const gp_Dir& V) |
6b84c3f7 |
52 | : myHaveDir(Standard_False) |
7fd59977 |
53 | { |
6b84c3f7 |
54 | Load(C); |
55 | Load(V); |
7fd59977 |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : Load |
60 | //purpose : |
61 | //======================================================================= |
62 | |
6b84c3f7 |
63 | void GeomAdaptor_SurfaceOfLinearExtrusion::Load(const Handle(Adaptor3d_HCurve)& C) |
7fd59977 |
64 | { |
65 | myBasisCurve = C; |
6b84c3f7 |
66 | if (myHaveDir) |
67 | Load(myDirection); |
7fd59977 |
68 | } |
69 | |
70 | //======================================================================= |
71 | //function : Load |
72 | //purpose : |
73 | //======================================================================= |
74 | |
6b84c3f7 |
75 | void GeomAdaptor_SurfaceOfLinearExtrusion::Load(const gp_Dir& V) |
7fd59977 |
76 | { |
6b84c3f7 |
77 | myHaveDir = Standard_True; |
7fd59977 |
78 | myDirection = V; |
6b84c3f7 |
79 | |
80 | mySurfaceType = GeomAbs_SurfaceOfExtrusion; |
81 | myNestedEvaluator = new GeomEvaluator_SurfaceOfExtrusion(myBasisCurve, myDirection); |
7fd59977 |
82 | } |
83 | |
84 | //======================================================================= |
85 | //function : FirstUParameter |
86 | //purpose : |
87 | //======================================================================= |
88 | |
6b84c3f7 |
89 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::FirstUParameter() const |
7fd59977 |
90 | { |
91 | return myBasisCurve->FirstParameter(); |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : LastUParameter |
96 | //purpose : |
97 | //======================================================================= |
98 | |
6b84c3f7 |
99 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::LastUParameter() const |
7fd59977 |
100 | { |
101 | return myBasisCurve->LastParameter(); |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : FirstVParameter |
106 | //purpose : |
107 | //======================================================================= |
108 | |
6b84c3f7 |
109 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::FirstVParameter() const |
7fd59977 |
110 | { |
111 | return RealFirst(); |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : LastVParameter |
116 | //purpose : |
117 | //======================================================================= |
118 | |
6b84c3f7 |
119 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::LastVParameter() const |
7fd59977 |
120 | { |
121 | return RealLast(); |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : UContinuity |
126 | //purpose : |
127 | //======================================================================= |
128 | |
6b84c3f7 |
129 | GeomAbs_Shape GeomAdaptor_SurfaceOfLinearExtrusion::UContinuity() const |
7fd59977 |
130 | { |
131 | return myBasisCurve->Continuity(); |
132 | } |
133 | |
134 | //======================================================================= |
135 | //function : VContinuity |
136 | //purpose : |
137 | //======================================================================= |
138 | |
6b84c3f7 |
139 | GeomAbs_Shape GeomAdaptor_SurfaceOfLinearExtrusion::VContinuity() const |
7fd59977 |
140 | { |
141 | return GeomAbs_CN; |
142 | } |
143 | |
144 | //======================================================================= |
145 | //function : NbUIntervals |
146 | //purpose : |
147 | //======================================================================= |
148 | |
6b84c3f7 |
149 | Standard_Integer GeomAdaptor_SurfaceOfLinearExtrusion::NbUIntervals |
7fd59977 |
150 | (const GeomAbs_Shape S) const |
151 | { |
152 | return myBasisCurve->NbIntervals(S); |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : NbVIntervals |
157 | //purpose : |
158 | //======================================================================= |
159 | |
6b84c3f7 |
160 | Standard_Integer GeomAdaptor_SurfaceOfLinearExtrusion::NbVIntervals |
7fd59977 |
161 | (const GeomAbs_Shape ) const |
162 | { |
163 | return 1; |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : UIntervals |
168 | //purpose : |
169 | //======================================================================= |
170 | |
6b84c3f7 |
171 | void GeomAdaptor_SurfaceOfLinearExtrusion::UIntervals |
7fd59977 |
172 | (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const |
173 | { |
174 | myBasisCurve->Intervals(T,S); |
175 | } |
176 | |
177 | //======================================================================= |
178 | //function : VIntervals |
179 | //purpose : |
180 | //======================================================================= |
181 | |
6b84c3f7 |
182 | void GeomAdaptor_SurfaceOfLinearExtrusion::VIntervals |
7fd59977 |
183 | (TColStd_Array1OfReal& T, const GeomAbs_Shape ) const |
184 | { |
185 | T(T.Lower()) = FirstVParameter() ; |
186 | T(T.Lower() + 1) = LastVParameter() ; |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : VTrim |
191 | //purpose : |
192 | //======================================================================= |
193 | |
6b84c3f7 |
194 | Handle(Adaptor3d_HSurface) GeomAdaptor_SurfaceOfLinearExtrusion::VTrim |
195 | (const Standard_Real First, |
7fd59977 |
196 | const Standard_Real Last, |
197 | const Standard_Real Tol) const |
198 | { |
6b84c3f7 |
199 | Handle(Adaptor3d_HCurve) HC = BasisCurve()->Trim(First,Last,Tol); |
200 | Handle(GeomAdaptor_HSurfaceOfLinearExtrusion) HR = new GeomAdaptor_HSurfaceOfLinearExtrusion( |
201 | GeomAdaptor_SurfaceOfLinearExtrusion(HC, myDirection)); |
202 | return HR; |
7fd59977 |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : UTrim |
207 | //purpose : |
208 | //======================================================================= |
209 | |
6b84c3f7 |
210 | Handle(Adaptor3d_HSurface) GeomAdaptor_SurfaceOfLinearExtrusion::UTrim |
7fd59977 |
211 | (const Standard_Real , |
212 | const Standard_Real , |
213 | const Standard_Real ) const |
214 | { |
6b84c3f7 |
215 | Handle(GeomAdaptor_HSurfaceOfLinearExtrusion) HR = new GeomAdaptor_HSurfaceOfLinearExtrusion( |
216 | GeomAdaptor_SurfaceOfLinearExtrusion(myBasisCurve, myDirection)); |
217 | return HR; |
7fd59977 |
218 | } |
219 | |
220 | //======================================================================= |
221 | //function : IsUClosed |
222 | //purpose : |
223 | //======================================================================= |
224 | |
6b84c3f7 |
225 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsUClosed() const |
7fd59977 |
226 | { |
227 | return myBasisCurve->IsClosed(); |
228 | } |
229 | |
230 | //======================================================================= |
231 | //function : IsVClosed |
232 | //purpose : |
233 | //======================================================================= |
234 | |
6b84c3f7 |
235 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsVClosed() const |
7fd59977 |
236 | { |
6b84c3f7 |
237 | return Standard_False; |
7fd59977 |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : IsUPeriodic |
242 | //purpose : |
243 | //======================================================================= |
244 | |
6b84c3f7 |
245 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsUPeriodic() const |
7fd59977 |
246 | { |
247 | return myBasisCurve->IsPeriodic(); |
248 | } |
249 | |
250 | //======================================================================= |
251 | //function : UPeriod |
252 | //purpose : |
253 | //======================================================================= |
254 | |
6b84c3f7 |
255 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::UPeriod() const |
7fd59977 |
256 | { |
257 | return myBasisCurve->Period() ; |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : IsVPeriodic |
262 | //purpose : |
263 | //======================================================================= |
264 | |
6b84c3f7 |
265 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsVPeriodic() const |
7fd59977 |
266 | { |
267 | return Standard_False; |
268 | } |
269 | |
270 | //======================================================================= |
271 | //function : VPeriod |
272 | //purpose : |
273 | //======================================================================= |
274 | |
6b84c3f7 |
275 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::VPeriod() const |
7fd59977 |
276 | { |
9775fa61 |
277 | throw Standard_DomainError("GeomAdaptor_SurfaceOfLinearExtrusion::VPeriod"); |
7fd59977 |
278 | } |
279 | |
7fd59977 |
280 | //======================================================================= |
281 | //function : UResolution |
282 | //purpose : |
283 | //======================================================================= |
284 | |
6b84c3f7 |
285 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::UResolution |
7fd59977 |
286 | (const Standard_Real R3d) const |
287 | { |
288 | return myBasisCurve->Resolution(R3d); |
289 | } |
290 | |
291 | //======================================================================= |
292 | //function : VResolution |
293 | //purpose : |
294 | //======================================================================= |
295 | |
6b84c3f7 |
296 | Standard_Real GeomAdaptor_SurfaceOfLinearExtrusion::VResolution |
7fd59977 |
297 | (const Standard_Real R3d) const |
298 | { |
299 | return R3d; |
300 | } |
301 | |
302 | //======================================================================= |
303 | //function : GetType |
304 | //purpose : |
305 | //======================================================================= |
306 | |
6b84c3f7 |
307 | GeomAbs_SurfaceType GeomAdaptor_SurfaceOfLinearExtrusion::GetType() const |
7fd59977 |
308 | { |
309 | switch ( myBasisCurve->GetType()) { |
310 | |
311 | case GeomAbs_Line: |
312 | { |
313 | gp_Dir D = myBasisCurve->Line().Direction(); |
6b84c3f7 |
314 | if (!myDirection.IsParallel( D, Precision::Angular())) |
d3f26155 |
315 | return GeomAbs_Plane; |
6b84c3f7 |
316 | break; |
7fd59977 |
317 | } |
318 | |
319 | case GeomAbs_Circle: |
320 | { |
321 | gp_Dir D = (myBasisCurve->Circle()).Axis().Direction(); |
6b84c3f7 |
322 | if ( myDirection.IsParallel( D, Precision::Angular())) |
d3f26155 |
323 | return GeomAbs_Cylinder; |
6b84c3f7 |
324 | else if (myDirection.IsNormal(D, Precision::Angular())) |
d3f26155 |
325 | return GeomAbs_Plane; |
6b84c3f7 |
326 | break; |
7fd59977 |
327 | } |
7fd59977 |
328 | |
329 | case GeomAbs_Ellipse: |
330 | { |
331 | gp_Dir D = (myBasisCurve->Ellipse()).Axis().Direction(); |
6b84c3f7 |
332 | if (myDirection.IsNormal(D, Precision::Angular())) |
d3f26155 |
333 | return GeomAbs_Plane; |
6b84c3f7 |
334 | break; |
7fd59977 |
335 | } |
336 | |
337 | case GeomAbs_Parabola: |
338 | { |
339 | gp_Dir D = (myBasisCurve->Parabola()).Axis().Direction(); |
6b84c3f7 |
340 | if (myDirection.IsNormal(D, Precision::Angular())) |
d3f26155 |
341 | return GeomAbs_Plane; |
6b84c3f7 |
342 | break; |
7fd59977 |
343 | } |
344 | |
345 | case GeomAbs_Hyperbola: |
346 | { |
347 | gp_Dir D = (myBasisCurve->Hyperbola()).Axis().Direction(); |
6b84c3f7 |
348 | if (myDirection.IsNormal(D, Precision::Angular())) |
d3f26155 |
349 | return GeomAbs_Plane; |
6b84c3f7 |
350 | break; |
7fd59977 |
351 | } |
352 | |
353 | default: |
6b84c3f7 |
354 | break; |
7fd59977 |
355 | } |
6b84c3f7 |
356 | |
357 | return GeomAbs_SurfaceOfExtrusion; |
7fd59977 |
358 | } |
359 | |
360 | //======================================================================= |
361 | //function : Plane |
362 | //purpose : |
363 | //======================================================================= |
364 | |
6b84c3f7 |
365 | gp_Pln GeomAdaptor_SurfaceOfLinearExtrusion::Plane() const |
7fd59977 |
366 | { |
367 | Standard_NoSuchObject_Raise_if (GetType() != GeomAbs_Plane, |
6b84c3f7 |
368 | "GeomAdaptor_SurfaceOfLinearExtrusion::Plane"); |
7fd59977 |
369 | |
370 | gp_Pnt P; |
371 | gp_Vec D1u, newZ; |
372 | Standard_Real UFirst = myBasisCurve->FirstParameter(); |
373 | Standard_Real ULast = myBasisCurve->LastParameter(); |
374 | if (Precision::IsNegativeInfinite(UFirst) && |
375 | Precision::IsPositiveInfinite(ULast)) { |
376 | UFirst = -100.; |
377 | ULast = 100.; |
378 | } |
379 | else if (Precision::IsNegativeInfinite(UFirst)) { |
380 | UFirst = ULast - 200.; |
381 | } |
382 | else if (Precision::IsPositiveInfinite(ULast)) { |
383 | ULast = UFirst + 200.; |
384 | } |
385 | Standard_Real deltau = (ULast-UFirst)/20.; |
386 | for (Standard_Integer i =1; i<=21; i++) { |
387 | Standard_Real prm = UFirst + (i-1)*deltau; |
388 | myBasisCurve->D1(prm,P,D1u); |
389 | newZ = D1u.Normalized().Crossed(myDirection); |
390 | if (newZ.Magnitude() > 1.e-12) break; |
391 | } |
392 | gp_Ax3 Ax3(P,gp_Dir(newZ),gp_Dir(D1u)); |
393 | if (myDirection.Dot(Ax3.YDirection())<0.){ |
394 | Ax3.YReverse(); |
395 | } |
396 | return gp_Pln(Ax3); |
397 | } |
398 | |
399 | |
400 | //======================================================================= |
401 | //function : Cylinder |
402 | //purpose : |
403 | //======================================================================= |
404 | |
6b84c3f7 |
405 | gp_Cylinder GeomAdaptor_SurfaceOfLinearExtrusion::Cylinder() const |
7fd59977 |
406 | { |
407 | Standard_NoSuchObject_Raise_if |
408 | (GetType() != GeomAbs_Cylinder, |
6b84c3f7 |
409 | "GeomAdaptor_SurfaceOfLinearExtrusion::Cylinder"); |
7fd59977 |
410 | |
411 | gp_Circ C = myBasisCurve->Circle() ; |
412 | gp_Ax3 Ax3(C.Position()); |
413 | if(myDirection.Dot((C.Axis()).Direction())<0.){ |
414 | Ax3.ZReverse(); |
415 | } |
416 | return gp_Cylinder(Ax3,C.Radius()); |
417 | } |
418 | |
419 | //======================================================================= |
420 | //function : Cone |
421 | //purpose : |
422 | //======================================================================= |
423 | |
6b84c3f7 |
424 | gp_Cone GeomAdaptor_SurfaceOfLinearExtrusion::Cone() const |
7fd59977 |
425 | { |
9775fa61 |
426 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::Cone"); |
7fd59977 |
427 | } |
428 | |
429 | //======================================================================= |
430 | //function : Sphere |
431 | //purpose : |
432 | //======================================================================= |
433 | |
6b84c3f7 |
434 | gp_Sphere GeomAdaptor_SurfaceOfLinearExtrusion::Sphere() const |
7fd59977 |
435 | { |
9775fa61 |
436 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::Sphere"); |
7fd59977 |
437 | } |
438 | |
439 | //======================================================================= |
440 | //function : Torus |
441 | //purpose : |
442 | //======================================================================= |
443 | |
6b84c3f7 |
444 | gp_Torus GeomAdaptor_SurfaceOfLinearExtrusion::Torus() const |
7fd59977 |
445 | { |
9775fa61 |
446 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::Torus"); |
7fd59977 |
447 | } |
448 | |
449 | |
450 | //======================================================================= |
451 | //function : Axis |
452 | //purpose : |
453 | //======================================================================= |
454 | |
6b84c3f7 |
455 | gp_Ax1 GeomAdaptor_SurfaceOfLinearExtrusion::AxeOfRevolution() const |
7fd59977 |
456 | { |
9775fa61 |
457 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::Axes"); |
7fd59977 |
458 | } |
459 | |
460 | //======================================================================= |
461 | //function : UDegree |
462 | //purpose : |
463 | //======================================================================= |
464 | |
6b84c3f7 |
465 | Standard_Integer GeomAdaptor_SurfaceOfLinearExtrusion::UDegree() const |
7fd59977 |
466 | { |
6b84c3f7 |
467 | return myBasisCurve->Degree(); |
7fd59977 |
468 | } |
469 | //======================================================================= |
470 | //function : NbUPoles |
471 | //purpose : |
472 | //======================================================================= |
473 | |
6b84c3f7 |
474 | Standard_Integer GeomAdaptor_SurfaceOfLinearExtrusion::NbUPoles() const |
7fd59977 |
475 | { |
476 | return myBasisCurve->NbPoles(); |
477 | } |
7fd59977 |
478 | |
7fd59977 |
479 | //======================================================================= |
480 | //function : IsURational |
481 | //purpose : |
482 | //======================================================================= |
483 | |
6b84c3f7 |
484 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsURational() const |
7fd59977 |
485 | { |
9775fa61 |
486 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::IsURational"); |
7fd59977 |
487 | } |
488 | //======================================================================= |
489 | //function : IsVRational |
490 | //purpose : |
491 | //======================================================================= |
492 | |
6b84c3f7 |
493 | Standard_Boolean GeomAdaptor_SurfaceOfLinearExtrusion::IsVRational() const |
7fd59977 |
494 | { |
9775fa61 |
495 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::IsVRational"); |
7fd59977 |
496 | } |
497 | //======================================================================= |
498 | //function : Bezier |
499 | //purpose : |
500 | //======================================================================= |
501 | |
502 | |
6b84c3f7 |
503 | Handle(Geom_BezierSurface) GeomAdaptor_SurfaceOfLinearExtrusion::Bezier() const |
7fd59977 |
504 | { |
9775fa61 |
505 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::Bezier"); |
7fd59977 |
506 | } |
507 | |
508 | //======================================================================= |
509 | //function : BSpline |
510 | //purpose : |
511 | //======================================================================= |
512 | |
6b84c3f7 |
513 | Handle(Geom_BSplineSurface) GeomAdaptor_SurfaceOfLinearExtrusion::BSpline() const |
7fd59977 |
514 | { |
9775fa61 |
515 | throw Standard_NoSuchObject("GeomAdaptor_SurfaceOfLinearExtrusion::BSpline"); |
7fd59977 |
516 | } |
517 | |
518 | //======================================================================= |
519 | //function : Direction |
520 | //purpose : |
521 | //======================================================================= |
522 | |
6b84c3f7 |
523 | gp_Dir GeomAdaptor_SurfaceOfLinearExtrusion::Direction() const |
7fd59977 |
524 | { |
525 | return myDirection; |
526 | } |
527 | |
528 | //======================================================================= |
529 | //function : BasisCurve |
530 | //purpose : |
531 | //======================================================================= |
532 | |
6b84c3f7 |
533 | Handle(Adaptor3d_HCurve) GeomAdaptor_SurfaceOfLinearExtrusion::BasisCurve() const |
7fd59977 |
534 | { |
535 | return myBasisCurve; |
536 | } |