0028389: Data Exchange - Import of STEP Saved Views and Clipping Planes
[occt.git] / src / GeomAdaptor / GeomAdaptor.cxx
CommitLineData
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
7fd59977 17
42cf5bc1 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>
7fd59977 26#include <Geom_Circle.hxx>
42cf5bc1 27#include <Geom_ConicalSurface.hxx>
28#include <Geom_Curve.hxx>
29#include <Geom_CylindricalSurface.hxx>
7fd59977 30#include <Geom_Ellipse.hxx>
7fd59977 31#include <Geom_Hyperbola.hxx>
42cf5bc1 32#include <Geom_Line.hxx>
33#include <Geom_OffsetSurface.hxx>
34#include <Geom_Parabola.hxx>
7fd59977 35#include <Geom_Plane.hxx>
42cf5bc1 36#include <Geom_RectangularTrimmedSurface.hxx>
7fd59977 37#include <Geom_SphericalSurface.hxx>
42cf5bc1 38#include <Geom_Surface.hxx>
7fd59977 39#include <Geom_SurfaceOfLinearExtrusion.hxx>
42cf5bc1 40#include <Geom_SurfaceOfRevolution.hxx>
41#include <Geom_ToroidalSurface.hxx>
42#include <Geom_TrimmedCurve.hxx>
43#include <GeomAdaptor.hxx>
7fd59977 44
45//=======================================================================
46//function : MakeCurve
47//purpose :
48//=======================================================================
7fd59977 49Handle(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
1aec3320 83 default:
7fd59977 84 Standard_DomainError::Raise("GeomAdaptor::MakeCurve : OtherCurve");
85
86 }
87
88 // trim the curve if necassary.
0ebaa4db 89 if ((! C.IsNull() &&
90 (HC.FirstParameter() != C->FirstParameter())) ||
7fd59977 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//=======================================================================
7afe616f 104Handle(Geom_Surface) GeomAdaptor::MakeSurface(const Adaptor3d_Surface& HS,
105 const Standard_Boolean theTrimFlag)
7fd59977 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()),
7afe616f 151 HS.OffsetValue());
7fd59977 152 break;
153
154 case GeomAbs_OtherSurface:
155 Standard_DomainError::Raise("GeomAdaptor::MakeSurface : OtherSurface");
156 break;
157 }
158
7afe616f 159 if ( S.IsNull() || !theTrimFlag)
7fd59977 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}