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