0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / GeomAdaptor / GeomAdaptor.cxx
1 // Created on: 1995-05-03
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-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
18 #include <Adaptor3d_Curve.hxx>
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
21 #include <Adaptor3d_Surface.hxx>
22 #include <Geom_BezierCurve.hxx>
23 #include <Geom_BezierSurface.hxx>
24 #include <Geom_BSplineCurve.hxx>
25 #include <Geom_BSplineSurface.hxx>
26 #include <Geom_Circle.hxx>
27 #include <Geom_ConicalSurface.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom_CylindricalSurface.hxx>
30 #include <Geom_Ellipse.hxx>
31 #include <Geom_Hyperbola.hxx>
32 #include <Geom_Line.hxx>
33 #include <Geom_OffsetSurface.hxx>
34 #include <Geom_Parabola.hxx>
35 #include <Geom_Plane.hxx>
36 #include <Geom_RectangularTrimmedSurface.hxx>
37 #include <Geom_SphericalSurface.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom_SurfaceOfLinearExtrusion.hxx>
40 #include <Geom_SurfaceOfRevolution.hxx>
41 #include <Geom_ToroidalSurface.hxx>
42 #include <Geom_TrimmedCurve.hxx>
43 #include <GeomAdaptor.hxx>
44
45 //=======================================================================
46 //function : MakeCurve
47 //purpose  : 
48 //=======================================================================
49 Handle(Geom_Curve) GeomAdaptor::MakeCurve (const Adaptor3d_Curve& HC)
50 {
51   Handle(Geom_Curve) C;
52   
53   switch (HC.GetType())
54   {
55   case GeomAbs_Line:
56     C = new Geom_Line(HC.Line());
57     break;
58
59   case GeomAbs_Circle:
60     C = new Geom_Circle(HC.Circle());
61     break;
62
63   case GeomAbs_Ellipse:
64     C = new Geom_Ellipse(HC.Ellipse());
65     break;
66
67   case GeomAbs_Parabola:
68     C = new Geom_Parabola(HC.Parabola());
69     break;
70
71   case GeomAbs_Hyperbola:
72     C = new Geom_Hyperbola(HC.Hyperbola());
73     break;
74
75   case GeomAbs_BezierCurve:
76     C = Handle(Geom_BezierCurve)::DownCast(HC.Bezier()->Copy());
77     break;
78
79   case GeomAbs_BSplineCurve:
80     C = Handle(Geom_BSplineCurve)::DownCast(HC.BSpline()->Copy());
81     break;
82
83   case GeomAbs_OtherCurve:
84     Standard_DomainError::Raise("GeomAdaptor::MakeCurve : OtherCurve");
85
86   }
87
88   // trim the curve if necassary.
89   if ((! C.IsNull() &&
90       (HC.FirstParameter() != C->FirstParameter())) ||
91       (HC.LastParameter()  != C->LastParameter())) {
92
93     C = new Geom_TrimmedCurve(C,HC.FirstParameter(),HC.LastParameter());
94   }
95
96   return C;
97 }
98
99
100 //=======================================================================
101 //function : MakeSurface
102 //purpose  : 
103 //=======================================================================
104
105 Handle(Geom_Surface) GeomAdaptor::MakeSurface(const Adaptor3d_Surface& HS)
106 {
107   Handle(Geom_Surface) S;
108
109   switch ( HS.GetType())
110   {
111   case GeomAbs_Plane:
112     S = new Geom_Plane(HS.Plane());
113     break;
114
115   case GeomAbs_Cylinder:
116     S = new Geom_CylindricalSurface(HS.Cylinder());
117     break;
118
119   case GeomAbs_Cone:
120     S = new Geom_ConicalSurface(HS.Cone());
121     break;
122
123   case GeomAbs_Sphere:
124     S = new Geom_SphericalSurface(HS.Sphere());
125     break;
126
127   case GeomAbs_Torus:
128     S = new Geom_ToroidalSurface(HS.Torus());
129     break;
130
131   case GeomAbs_BezierSurface:
132     S = Handle(Geom_BezierSurface)::DownCast(HS.Bezier()->Copy());
133     break;
134
135   case GeomAbs_BSplineSurface:
136     S = Handle(Geom_BSplineSurface)::DownCast(HS.BSpline()->Copy());
137     break;
138
139   case GeomAbs_SurfaceOfRevolution:
140     S = new Geom_SurfaceOfRevolution
141       (GeomAdaptor::MakeCurve(HS.BasisCurve()->Curve()),HS.AxeOfRevolution());
142     break;
143
144   case GeomAbs_SurfaceOfExtrusion:
145     S = new Geom_SurfaceOfLinearExtrusion
146       (GeomAdaptor::MakeCurve(HS.BasisCurve()->Curve()),HS.Direction());
147     break;
148
149   case GeomAbs_OffsetSurface:
150     S = new Geom_OffsetSurface(GeomAdaptor::MakeSurface(HS.BasisSurface()->Surface()),
151                                HS.OffsetValue());
152     break;
153
154   case GeomAbs_OtherSurface:
155     Standard_DomainError::Raise("GeomAdaptor::MakeSurface : OtherSurface");
156     break;
157   }
158
159   if ( S.IsNull() )
160     return S;
161
162   // trim the surface if necassary.
163   Standard_Real U1, U2, V1, V2;
164   S->Bounds(U1, U2, V1, V2);
165   if ((HS.FirstUParameter() != U1 ) ||
166       (HS.LastUParameter () != U2 ) ||
167       (HS.FirstVParameter() != V1 ) ||
168       (HS.LastVParameter () != V2 )   ) {
169
170     S = new Geom_RectangularTrimmedSurface
171       (S,HS.FirstUParameter(),HS.LastUParameter(),
172          HS.FirstVParameter(),HS.LastVParameter());
173   }
174
175   return S;
176 }