1 // Created on: 1993-07-02
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //:n6 abv 15.02.99: S4132: adding translation of polyline
18 //:p0 abv 19.02.99: management of 'done' flag improved; trimmed_curve treated
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_TrimmedCurve.hxx>
22 #include <StepGeom_BezierCurve.hxx>
23 #include <StepGeom_BoundedCurve.hxx>
24 #include <StepGeom_BSplineCurveWithKnots.hxx>
25 #include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
26 #include <StepGeom_KnotType.hxx>
27 #include <StepGeom_Polyline.hxx>
28 #include <StepGeom_QuasiUniformCurve.hxx>
29 #include <StepGeom_QuasiUniformCurveAndRationalBSplineCurve.hxx>
30 #include <StepGeom_TrimmedCurve.hxx>
31 #include <StepGeom_UniformCurve.hxx>
32 #include <StepGeom_UniformCurveAndRationalBSplineCurve.hxx>
33 #include <StepToGeom_MakeBoundedCurve.hxx>
34 #include <StepToGeom_MakeBSplineCurve.hxx>
35 #include <StepToGeom_MakePolyline.hxx>
36 #include <StepToGeom_MakeTrimmedCurve.hxx>
37 #include <TColStd_HArray1OfInteger.hxx>
38 #include <TColStd_HArray1OfReal.hxx>
40 //=============================================================================
41 // Creation d' une BoundedCurve de Geom a partir d' une BoundedCurve de Step
42 //=============================================================================
43 Standard_Boolean StepToGeom_MakeBoundedCurve::Convert
44 (const Handle(StepGeom_BoundedCurve)& SC,
45 Handle(Geom_BoundedCurve)& CC)
47 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
48 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
49 Bspli = Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC);
50 return StepToGeom_MakeBSplineCurve::Convert(Bspli,Handle(Geom_BSplineCurve)::DownCast (CC));
52 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnots))) {
53 const Handle(StepGeom_BSplineCurveWithKnots)
54 Bspli = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
55 return StepToGeom_MakeBSplineCurve::Convert(Bspli,Handle(Geom_BSplineCurve)::DownCast (CC));
57 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve))) {
58 const Handle(StepGeom_TrimmedCurve) L = Handle(StepGeom_TrimmedCurve)::DownCast(SC);
59 return StepToGeom_MakeTrimmedCurve::Convert(L,Handle(Geom_TrimmedCurve)::DownCast (CC));
61 // STEP BezierCurve, UniformCurve and QuasiUniformCurve are transformed into
62 // STEP BSplineCurve before being mapped onto CAS.CADE/SF
63 if (SC->IsKind(STANDARD_TYPE(StepGeom_BezierCurve))) {
64 const Handle(StepGeom_BezierCurve) BzC = Handle(StepGeom_BezierCurve)::DownCast(SC);
65 Standard_Integer aDegree = BzC->Degree();
66 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
67 return Standard_False;
68 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
69 BSPL->SetDegree(aDegree);
70 BSPL->SetControlPointsList(BzC->ControlPointsList());
71 BSPL->SetCurveForm(BzC->CurveForm());
72 BSPL->SetClosedCurve(BzC->ClosedCurve());
73 BSPL->SetSelfIntersect(BzC->SelfIntersect());
74 // Compute Knots and KnotsMultiplicity
75 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,2);
76 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,2);
77 Kmult->SetValue(1, BzC->Degree() + 1);
78 Kmult->SetValue(2, BzC->Degree() + 1);
79 Knots->SetValue(1, 0.);
80 Knots->SetValue(2, 1.);
81 BSPL->SetKnotMultiplicities(Kmult);
82 BSPL->SetKnots(Knots);
83 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
85 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurve))) {
86 const Handle(StepGeom_UniformCurve) UC = Handle(StepGeom_UniformCurve)::DownCast(SC);
87 Standard_Integer aDegree = UC->Degree();
88 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
89 return Standard_False;
90 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
91 BSPL->SetDegree(aDegree);
92 BSPL->SetControlPointsList(UC->ControlPointsList());
93 BSPL->SetCurveForm(UC->CurveForm());
94 BSPL->SetClosedCurve(UC->ClosedCurve());
95 BSPL->SetSelfIntersect(UC->SelfIntersect());
96 // Compute Knots and KnotsMultiplicity
97 const Standard_Integer nbK = BSPL->NbControlPointsList() + BSPL->Degree() + 1;
98 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
99 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
100 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
101 Kmult->SetValue(iUC, 1);
102 Knots->SetValue(iUC, iUC - 1.);
104 BSPL->SetKnotMultiplicities(Kmult);
105 BSPL->SetKnots(Knots);
106 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
108 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurve))) {
109 const Handle(StepGeom_QuasiUniformCurve) QUC =
110 Handle(StepGeom_QuasiUniformCurve)::DownCast(SC);
111 Standard_Integer aDegree = QUC->Degree();
112 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
113 return Standard_False;
114 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
115 BSPL->SetDegree(aDegree);
116 BSPL->SetControlPointsList(QUC->ControlPointsList());
117 BSPL->SetCurveForm(QUC->CurveForm());
118 BSPL->SetClosedCurve(QUC->ClosedCurve());
119 BSPL->SetSelfIntersect(QUC->SelfIntersect());
120 // Compute Knots and KnotsMultiplicity
121 const Standard_Integer nbK = BSPL->NbControlPointsList() - BSPL->Degree() + 1;
122 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
123 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
124 for (Standard_Integer iQUC = 1 ; iQUC <= nbK ; iQUC ++) {
125 Kmult->SetValue(iQUC, 1);
126 Knots->SetValue(iQUC, iQUC - 1.);
128 Kmult->SetValue(1, BSPL->Degree() + 1);
129 Kmult->SetValue(nbK, BSPL->Degree() + 1);
130 BSPL->SetKnotMultiplicities(Kmult);
131 BSPL->SetKnots(Knots);
132 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
134 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurveAndRationalBSplineCurve))) {
135 const Handle(StepGeom_UniformCurveAndRationalBSplineCurve) RUC =
136 Handle(StepGeom_UniformCurveAndRationalBSplineCurve)::DownCast(SC);
137 Standard_Integer aDegree = RUC->Degree();
138 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
139 return Standard_False;
140 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
141 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
142 // Compute Knots and KnotsMultiplicity
143 const Standard_Integer nbK = RUC->NbControlPointsList() + aDegree + 1;
144 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
145 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
146 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
147 Kmult->SetValue(iUC, 1);
148 Knots->SetValue(iUC, iUC - 1.);
150 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
151 RBSPL->Init(RUC->Name(), aDegree, RUC->ControlPointsList(), RUC->CurveForm(),
152 RUC->ClosedCurve(), RUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
154 return StepToGeom_MakeBSplineCurve::Convert(RBSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
156 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurveAndRationalBSplineCurve))) {
157 const Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve) RQUC =
158 Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve)::DownCast(SC);
159 Standard_Integer aDegree = RQUC->Degree();
160 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
161 return Standard_False;
162 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
163 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
164 // Compute Knots and KnotsMultiplicity
165 const Standard_Integer nbK = RQUC->NbControlPointsList() - aDegree + 1;
166 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
167 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
168 for (Standard_Integer iRQUC = 1 ; iRQUC <= nbK ; iRQUC ++) {
169 Kmult->SetValue(iRQUC, 1);
170 Knots->SetValue(iRQUC, iRQUC - 1.);
172 Kmult->SetValue(1, aDegree + 1);
173 Kmult->SetValue(nbK, aDegree + 1);
174 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
175 RBSPL->Init(RQUC->Name(), aDegree, RQUC->ControlPointsList(), RQUC->CurveForm(),
176 RQUC->ClosedCurve(), RQUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
177 RQUC->WeightsData());
178 return StepToGeom_MakeBSplineCurve::Convert(RBSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
180 if (SC->IsKind(STANDARD_TYPE(StepGeom_Polyline))) { //:n6 abv 15 Feb 99
181 const Handle(StepGeom_Polyline) PL = Handle(StepGeom_Polyline)::DownCast (SC);
182 return StepToGeom_MakePolyline::Convert(PL,Handle(Geom_BSplineCurve)::DownCast (CC));
184 return Standard_False;