0024624: Lost word in license statement in source files
[occt.git] / src / Adaptor3d / Adaptor3d_SurfaceOfLinearExtrusion.cxx
1 // Created on: 1993-04-21
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Adaptor3d_SurfaceOfLinearExtrusion.ixx>
18 #include <Adaptor3d_HSurfaceOfLinearExtrusion.hxx>
19 #include <Precision.hxx>
20 #include <gp.hxx>
21
22 //=======================================================================
23 //function : Adaptor3d_SurfaceOfLinearExtrusion
24 //purpose  : 
25 //=======================================================================
26
27 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion()
28 {}
29
30 //=======================================================================
31 //function : Adaptor3d_SurfaceOfLinearExtrusion
32 //purpose  : 
33 //=======================================================================
34
35 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion
36 (const Handle(Adaptor3d_HCurve)& C)
37 {
38   Load( C);
39 }
40
41 //=======================================================================
42 //function : Adaptor3d_SurfaceOfLinearExtrusion
43 //purpose  : 
44 //=======================================================================
45
46 Adaptor3d_SurfaceOfLinearExtrusion::Adaptor3d_SurfaceOfLinearExtrusion
47 (const Handle(Adaptor3d_HCurve)& C,
48  const gp_Dir&        V)
49 {
50   Load( C);
51   Load( V);
52 }
53
54 //=======================================================================
55 //function : Load
56 //purpose  : 
57 //=======================================================================
58
59 void Adaptor3d_SurfaceOfLinearExtrusion::Load( const Handle(Adaptor3d_HCurve)& C)
60 {
61   myBasisCurve = C;
62 }
63
64 //=======================================================================
65 //function : Load
66 //purpose  : 
67 //=======================================================================
68
69 void Adaptor3d_SurfaceOfLinearExtrusion::Load( const gp_Dir& V)
70 {
71   myDirection = V;
72 }
73
74 //=======================================================================
75 //function : FirstUParameter
76 //purpose  : 
77 //=======================================================================
78
79 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::FirstUParameter() const 
80 {
81   return myBasisCurve->FirstParameter();
82 }
83
84 //=======================================================================
85 //function : LastUParameter
86 //purpose  : 
87 //=======================================================================
88
89 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::LastUParameter() const 
90 {
91   return myBasisCurve->LastParameter();
92 }
93
94 //=======================================================================
95 //function : FirstVParameter
96 //purpose  : 
97 //=======================================================================
98
99 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::FirstVParameter() const 
100 {
101   return RealFirst();
102 }
103
104 //=======================================================================
105 //function : LastVParameter
106 //purpose  : 
107 //=======================================================================
108
109 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::LastVParameter() const 
110 {
111   return RealLast();
112 }
113
114 //=======================================================================
115 //function : UContinuity
116 //purpose  : 
117 //=======================================================================
118
119 GeomAbs_Shape Adaptor3d_SurfaceOfLinearExtrusion::UContinuity() const 
120 {
121   return myBasisCurve->Continuity();
122 }
123
124 //=======================================================================
125 //function : VContinuity
126 //purpose  : 
127 //=======================================================================
128
129 GeomAbs_Shape Adaptor3d_SurfaceOfLinearExtrusion::VContinuity() const 
130 {
131   return GeomAbs_CN;
132 }
133
134 //=======================================================================
135 //function : NbUIntervals
136 //purpose  : 
137 //=======================================================================
138
139 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUIntervals
140 (const GeomAbs_Shape S)  const 
141 {
142   return   myBasisCurve->NbIntervals(S);
143 }
144
145 //=======================================================================
146 //function : NbVIntervals
147 //purpose  : 
148 //=======================================================================
149
150 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVIntervals
151 (const GeomAbs_Shape ) const 
152 {
153   return 1;
154 }
155
156 //=======================================================================
157 //function : UIntervals
158 //purpose  : 
159 //=======================================================================
160
161 void Adaptor3d_SurfaceOfLinearExtrusion::UIntervals
162 (TColStd_Array1OfReal&  T, const GeomAbs_Shape S) const 
163 {
164   myBasisCurve->Intervals(T,S);
165 }
166
167 //=======================================================================
168 //function : VIntervals
169 //purpose  : 
170 //=======================================================================
171
172 void Adaptor3d_SurfaceOfLinearExtrusion::VIntervals
173 //(TColStd_Array1OfReal&  T, const GeomAbs_Shape S) const 
174 (TColStd_Array1OfReal&  T, const GeomAbs_Shape ) const 
175 {
176  T(T.Lower()) = FirstVParameter() ;
177  T(T.Lower() + 1) = LastVParameter() ;
178 }
179
180 //=======================================================================
181 //function : VTrim
182 //purpose  : 
183 //=======================================================================
184
185 Handle(Adaptor3d_HSurface)  Adaptor3d_SurfaceOfLinearExtrusion::VTrim
186 (const Standard_Real First ,
187  const Standard_Real Last,
188  const Standard_Real Tol) const 
189 {
190   Handle(Adaptor3d_HCurve) newBasisCurve =
191   myBasisCurve->Trim(First, Last, Tol);
192   
193   Adaptor3d_SurfaceOfLinearExtrusion * SurfacePtr =
194   new  Adaptor3d_SurfaceOfLinearExtrusion(newBasisCurve, myDirection) ;
195
196   return new Adaptor3d_HSurfaceOfLinearExtrusion(*SurfacePtr);
197 }
198
199 //=======================================================================
200 //function : UTrim
201 //purpose  : 
202 //=======================================================================
203
204 Handle(Adaptor3d_HSurface)  Adaptor3d_SurfaceOfLinearExtrusion::UTrim
205 //(const Standard_Real First ,
206 // const Standard_Real Last,
207 // const Standard_Real Tol) const 
208 (const Standard_Real ,
209  const Standard_Real ,
210  const Standard_Real ) const 
211 {
212   Adaptor3d_SurfaceOfLinearExtrusion * SurfacePtr = 
213   new  Adaptor3d_SurfaceOfLinearExtrusion(myBasisCurve,myDirection);
214
215   return new Adaptor3d_HSurfaceOfLinearExtrusion(*SurfacePtr) ;
216 }
217
218 //=======================================================================
219 //function : IsUClosed
220 //purpose  : 
221 //=======================================================================
222
223 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsUClosed() const 
224 {
225   return myBasisCurve->IsClosed();
226 }
227
228 //=======================================================================
229 //function : IsVClosed
230 //purpose  : 
231 //=======================================================================
232
233 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVClosed() const 
234 {
235   return Standard_True;
236 }
237
238 //=======================================================================
239 //function : IsUPeriodic
240 //purpose  : 
241 //=======================================================================
242
243 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsUPeriodic() const 
244 {
245   return myBasisCurve->IsPeriodic();
246 }
247
248 //=======================================================================
249 //function : UPeriod
250 //purpose  : 
251 //=======================================================================
252
253 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::UPeriod() const 
254 {
255   return myBasisCurve->Period() ;
256 }
257
258 //=======================================================================
259 //function : IsVPeriodic
260 //purpose  : 
261 //=======================================================================
262
263 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVPeriodic() const 
264 {
265   return Standard_False;
266 }
267
268 //=======================================================================
269 //function : VPeriod
270 //purpose  : 
271 //=======================================================================
272
273 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::VPeriod() const 
274 {
275   Standard_DomainError::Raise("Adaptor3d_SurfaceOfLinearExtrusion::VPeriod");
276   return 0.0e0 ;
277 }
278
279 //=======================================================================
280 //function : Value
281 //purpose  : 
282 //=======================================================================
283
284 gp_Pnt Adaptor3d_SurfaceOfLinearExtrusion::Value(const Standard_Real U, 
285                                                  const Standard_Real V)
286      const 
287 {
288   gp_Pnt P;
289   P = myBasisCurve->Value(U);
290   P.Translate( V * gp_Vec(myDirection));
291   return P;
292 }
293
294 //=======================================================================
295 //function : D0
296 //purpose  : 
297 //=======================================================================
298
299 void Adaptor3d_SurfaceOfLinearExtrusion::D0(const Standard_Real U,
300                                             const Standard_Real V, 
301                                             gp_Pnt&             P) const 
302 {
303   myBasisCurve->D0(U,P);
304   P.Translate( V * gp_Vec(myDirection));
305 }
306
307 //=======================================================================
308 //function : D1
309 //purpose  : 
310 //=======================================================================
311
312 void Adaptor3d_SurfaceOfLinearExtrusion::D1(const Standard_Real U, 
313                                             const Standard_Real V, 
314                                                   gp_Pnt& P, 
315                                                   gp_Vec& D1U, 
316                                                   gp_Vec& D1V) const 
317 {
318   myBasisCurve->D1(U,P,D1U);
319   D0(U,V,P);
320   D1V = gp_Vec(myDirection);
321 }
322
323 //=======================================================================
324 //function : D2
325 //purpose  : 
326 //=======================================================================
327
328 void Adaptor3d_SurfaceOfLinearExtrusion::D2(const Standard_Real U, 
329                                             const Standard_Real V,
330                                             gp_Pnt& P, 
331                                             gp_Vec& D1U, gp_Vec& D1V,
332                                             gp_Vec& D2U, gp_Vec& D2V, 
333                                             gp_Vec& D2UV) const 
334 {
335   myBasisCurve->D2(U,P,D1U,D2U);
336   D1V = gp_Vec(myDirection);
337   D2V.SetCoord( 0., 0., 0.);
338   D2UV.SetCoord( 0., 0., 0.);
339   D0(U,V,P);
340 }
341
342 //=======================================================================
343 //function : D3
344 //purpose  : 
345 //=======================================================================
346
347 void Adaptor3d_SurfaceOfLinearExtrusion::D3(const Standard_Real U, 
348                                             const Standard_Real V,
349                                             gp_Pnt& P,
350                                             gp_Vec& D1U, gp_Vec& D1V,
351                                             gp_Vec& D2U, gp_Vec& D2V, 
352                                             gp_Vec& D2UV,
353                                             gp_Vec& D3U, gp_Vec& D3V, 
354                                             gp_Vec& D3UUV, gp_Vec& D3UVV) const 
355 {
356   myBasisCurve->D3(U,P,D1U,D2U,D3U);
357   D1V = gp_Vec(myDirection);
358   D2V.SetCoord( 0., 0., 0.);
359   D2UV.SetCoord( 0., 0., 0.);
360   D3V.SetCoord( 0., 0., 0.);
361   D3UUV.SetCoord( 0., 0., 0.);
362   D3UVV.SetCoord( 0., 0., 0.);
363   D0(U,V,P);
364 }
365
366 //=======================================================================
367 //function : DN
368 //purpose  : 
369 //=======================================================================
370
371 gp_Vec Adaptor3d_SurfaceOfLinearExtrusion::DN
372 (const Standard_Real    U, 
373 // const Standard_Real    V,
374  const Standard_Real    ,
375  const Standard_Integer NU, 
376  const Standard_Integer NV) const 
377 {
378   if ( (NU+NV)<1 || NU<0 || NV<0) {
379     Standard_DomainError::Raise("Adaptor3d_SurfaceOfLinearExtrusion::DN");
380     return gp_Vec();
381   }
382   else {
383     if (NU == 0 && NV ==1) return gp_Vec( myDirection);
384     else if (NV == 0)      return myBasisCurve->DN(U,NU);
385     else                   return gp_Vec( 0., 0., 0.);
386   }   
387 }
388
389 //=======================================================================
390 //function : UResolution
391 //purpose  : 
392 //=======================================================================
393
394 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::UResolution
395 (const Standard_Real R3d) const 
396 {
397   return myBasisCurve->Resolution(R3d);
398 }
399
400 //=======================================================================
401 //function : VResolution
402 //purpose  : 
403 //=======================================================================
404
405 Standard_Real Adaptor3d_SurfaceOfLinearExtrusion::VResolution
406 (const Standard_Real R3d) const 
407 {
408   return R3d;
409 }
410
411 //=======================================================================
412 //function : GetType
413 //purpose  : 
414 //=======================================================================
415
416 GeomAbs_SurfaceType Adaptor3d_SurfaceOfLinearExtrusion::GetType() const 
417 {
418   switch ( myBasisCurve->GetType()) {
419     
420   case GeomAbs_Line:
421     {
422       gp_Dir D = myBasisCurve->Line().Direction();
423       if (myDirection.IsParallel( D, Precision::Angular())) {
424         return GeomAbs_SurfaceOfExtrusion;
425       }
426       else {
427         return GeomAbs_Plane;
428       }
429     }
430     
431   case GeomAbs_Circle:
432     {
433       gp_Dir D = (myBasisCurve->Circle()).Axis().Direction();
434       if ( myDirection.IsParallel( D, Precision::Angular())) {
435         return GeomAbs_Cylinder;
436       }
437       // JAG 10.11.95
438       else if (myDirection.IsNormal(D, Precision::Angular())) {
439         return GeomAbs_Plane;
440       }
441       else {
442         return GeomAbs_SurfaceOfExtrusion;
443       }
444     }
445     // JAG 10.11.95
446     
447   case GeomAbs_Ellipse:
448     {
449       gp_Dir D = (myBasisCurve->Ellipse()).Axis().Direction();
450       if (myDirection.IsNormal(D, Precision::Angular())) {
451         return GeomAbs_Plane;
452       }
453       else {
454         return GeomAbs_SurfaceOfExtrusion;
455       }
456     }
457     
458   case GeomAbs_Parabola:
459     {
460       gp_Dir D = (myBasisCurve->Parabola()).Axis().Direction();
461       if (myDirection.IsNormal(D, Precision::Angular())) {
462         return GeomAbs_Plane;
463       }
464       else {
465         return GeomAbs_SurfaceOfExtrusion;
466       }
467     }
468     
469   case GeomAbs_Hyperbola:
470     {
471       gp_Dir D = (myBasisCurve->Hyperbola()).Axis().Direction();
472       if (myDirection.IsNormal(D, Precision::Angular())) {
473         return GeomAbs_Plane;
474       }
475       else {
476         return GeomAbs_SurfaceOfExtrusion;
477       }
478     }
479
480   default:
481     return GeomAbs_SurfaceOfExtrusion;
482
483   }
484 }
485
486 //=======================================================================
487 //function : Plane
488 //purpose  : 
489 //=======================================================================
490
491 gp_Pln Adaptor3d_SurfaceOfLinearExtrusion::Plane() const 
492
493   Standard_NoSuchObject_Raise_if (GetType() != GeomAbs_Plane,
494                   "Adaptor3d_SurfaceOfLinearExtrusion::Plane");
495 /*
496   gp_Pnt P;
497   gp_Vec Ox, Oy;
498   D1( 0., 0., P, Ox, Oy);
499   gp_Ax3 Ax3(P,gp_Dir(Ox^Oy),gp_Dir(Ox));
500   if (gp_Dir(Oy).Dot(Ax3.YDirection())<0.){
501     Ax3.YReverse();
502   }
503   return gp_Pln(Ax3);
504 */
505
506   gp_Pnt P;
507   gp_Vec D1u, newZ;
508   Standard_Real UFirst = myBasisCurve->FirstParameter();
509   Standard_Real ULast  = myBasisCurve->LastParameter();
510   if (Precision::IsNegativeInfinite(UFirst) &&
511       Precision::IsPositiveInfinite(ULast)) {
512     UFirst = -100.;
513     ULast  = 100.;
514   }
515   else if (Precision::IsNegativeInfinite(UFirst)) {
516     UFirst = ULast - 200.;
517   }
518   else if (Precision::IsPositiveInfinite(ULast)) {
519     ULast = UFirst + 200.;
520   }
521   Standard_Real deltau = (ULast-UFirst)/20.;
522   for (Standard_Integer i =1; i<=21; i++) {
523     Standard_Real prm = UFirst + (i-1)*deltau;
524     myBasisCurve->D1(prm,P,D1u);
525     newZ = D1u.Normalized().Crossed(myDirection);
526     if (newZ.Magnitude() > 1.e-12) break;
527   }
528   gp_Ax3 Ax3(P,gp_Dir(newZ),gp_Dir(D1u));
529   if (myDirection.Dot(Ax3.YDirection())<0.){
530     Ax3.YReverse();
531   }
532   return gp_Pln(Ax3);
533 }
534
535
536 //=======================================================================
537 //function : Cylinder
538 //purpose  : 
539 //=======================================================================
540
541 gp_Cylinder Adaptor3d_SurfaceOfLinearExtrusion::Cylinder() const 
542 {
543   Standard_NoSuchObject_Raise_if 
544     (GetType() != GeomAbs_Cylinder,
545      "Adaptor3d_SurfaceOfLinearExtrusion::Cylinder");
546
547   gp_Circ C =  myBasisCurve->Circle() ;
548   gp_Ax3 Ax3(C.Position());
549   if(myDirection.Dot((C.Axis()).Direction())<0.){
550     Ax3.ZReverse();
551   }
552   return gp_Cylinder(Ax3,C.Radius());
553 }
554
555 //=======================================================================
556 //function : Cone
557 //purpose  : 
558 //=======================================================================
559
560 gp_Cone Adaptor3d_SurfaceOfLinearExtrusion::Cone() const 
561 {
562   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Cone");
563   return gp_Cone();
564 }
565
566 //=======================================================================
567 //function : Sphere
568 //purpose  : 
569 //=======================================================================
570
571 gp_Sphere Adaptor3d_SurfaceOfLinearExtrusion::Sphere() const 
572 {
573   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Sphere");
574   return gp_Sphere();
575 }
576
577 //=======================================================================
578 //function : Torus
579 //purpose  : 
580 //=======================================================================
581
582 gp_Torus Adaptor3d_SurfaceOfLinearExtrusion::Torus() const 
583 {
584   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Torus");
585   return gp_Torus();
586 }
587
588
589 //=======================================================================
590 //function : Axis
591 //purpose  : 
592 //=======================================================================
593
594 gp_Ax1 Adaptor3d_SurfaceOfLinearExtrusion::AxeOfRevolution() const 
595 {
596   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
597   return gp_Ax1();
598 }
599
600 //=======================================================================
601 //function : UDegree
602 //purpose  : 
603 //=======================================================================
604
605 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::UDegree() const 
606 {
607   return myBasisCurve -> Degree();
608 }
609 //=======================================================================
610 //function : NbUPoles
611 //purpose  : 
612 //=======================================================================
613
614 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUPoles() const 
615 {
616   return myBasisCurve->NbPoles();
617 }
618 //=======================================================================
619 //function : VDegree
620 //purpose  : 
621 //=======================================================================
622
623 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::VDegree() const 
624 {
625   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::VDegree");
626   return 0;
627 }
628
629 //=======================================================================
630 //function : NbVPoles
631 //purpose  : 
632 //=======================================================================
633
634 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVPoles() const 
635 {
636   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::NbVPoles");
637   return 0;
638 }
639
640 //=======================================================================
641 //function : NbUKnots
642 //purpose  : 
643 //=======================================================================
644
645 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbUKnots() const 
646 {
647   Standard_NoSuchObject::Raise
648     ("Adaptor3d_SurfaceOfLinearExtrusion::NbUKnots");
649   return 0;
650 }
651 //=======================================================================
652 //function : NbVKnots
653 //purpose  : 
654 //=======================================================================
655
656 Standard_Integer Adaptor3d_SurfaceOfLinearExtrusion::NbVKnots() const 
657 {
658   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::NbVKnots");
659   return 0;
660 }
661 //=======================================================================
662 //function : IsURational
663 //purpose  : 
664 //=======================================================================
665
666 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsURational() const 
667 {
668   Standard_NoSuchObject::Raise
669     ("Adaptor3d_SurfaceOfLinearExtrusion::IsURational");
670   return Standard_False;
671 }
672 //=======================================================================
673 //function : IsVRational
674 //purpose  : 
675 //=======================================================================
676
677 Standard_Boolean Adaptor3d_SurfaceOfLinearExtrusion::IsVRational() const 
678 {
679   Standard_NoSuchObject::Raise
680     ("Adaptor3d_SurfaceOfLinearExtrusion::IsVRational");
681   return Standard_False;
682 }
683 //=======================================================================
684 //function : Bezier
685 //purpose  : 
686 //=======================================================================
687
688
689 Handle(Geom_BezierSurface)  Adaptor3d_SurfaceOfLinearExtrusion::Bezier() const 
690 {
691   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
692   return Handle(Geom_BezierSurface)() ;
693 }
694
695 //=======================================================================
696 //function : BSpline
697 //purpose  : 
698 //=======================================================================
699
700 Handle(Geom_BSplineSurface)  Adaptor3d_SurfaceOfLinearExtrusion::BSpline() const 
701 {
702   Standard_NoSuchObject::Raise("Adaptor3d_SurfaceOfLinearExtrusion::Axes");
703   return Handle(Geom_BSplineSurface)() ;
704 }
705
706 //=======================================================================
707 //function : Direction
708 //purpose  : 
709 //=======================================================================
710
711 gp_Dir Adaptor3d_SurfaceOfLinearExtrusion::Direction() const
712 {
713   return myDirection;
714 }
715
716 //=======================================================================
717 //function : BasisCurve
718 //purpose  : 
719 //=======================================================================
720
721 Handle(Adaptor3d_HCurve) Adaptor3d_SurfaceOfLinearExtrusion::BasisCurve() const 
722 {
723   return myBasisCurve;
724 }