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