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