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