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 <StepToGeom_MakeBoundedCurve.ixx>
22 #include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
23 #include <StepGeom_BSplineCurveWithKnots.hxx>
24 #include <StepGeom_BezierCurve.hxx>
25 #include <StepGeom_UniformCurve.hxx>
26 #include <StepGeom_UniformCurveAndRationalBSplineCurve.hxx>
27 #include <StepGeom_QuasiUniformCurve.hxx>
28 #include <StepGeom_QuasiUniformCurveAndRationalBSplineCurve.hxx>
29 #include <StepGeom_Polyline.hxx>
30 #include <StepGeom_TrimmedCurve.hxx>
31 #include <StepGeom_KnotType.hxx>
32 #include <StepToGeom_MakeBSplineCurve.hxx>
33 #include <StepGeom_Polyline.hxx>
34 #include <StepToGeom_MakePolyline.hxx>
35 #include <StepToGeom_MakeTrimmedCurve.hxx>
36 #include <Geom_BSplineCurve.hxx>
38 #include <TColStd_HArray1OfInteger.hxx>
39 #include <TColStd_HArray1OfReal.hxx>
41 //=============================================================================
42 // Creation d' une BoundedCurve de Geom a partir d' une BoundedCurve de Step
43 //=============================================================================
45 Standard_Boolean StepToGeom_MakeBoundedCurve::Convert
46 (const Handle(StepGeom_BoundedCurve)& SC,
47 Handle(Geom_BoundedCurve)& CC)
49 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
50 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
51 Bspli = Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC);
52 return StepToGeom_MakeBSplineCurve::Convert(Bspli,Handle(Geom_BSplineCurve)::DownCast (CC));
54 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnots))) {
55 const Handle(StepGeom_BSplineCurveWithKnots)
56 Bspli = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
57 return StepToGeom_MakeBSplineCurve::Convert(Bspli,Handle(Geom_BSplineCurve)::DownCast (CC));
59 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve))) {
60 const Handle(StepGeom_TrimmedCurve) L = Handle(StepGeom_TrimmedCurve)::DownCast(SC);
61 return StepToGeom_MakeTrimmedCurve::Convert(L,Handle(Geom_TrimmedCurve)::DownCast (CC));
63 // STEP BezierCurve, UniformCurve and QuasiUniformCurve are transformed into
64 // STEP BSplineCurve before being mapped onto CAS.CADE/SF
65 if (SC->IsKind(STANDARD_TYPE(StepGeom_BezierCurve))) {
66 const Handle(StepGeom_BezierCurve) BzC = Handle(StepGeom_BezierCurve)::DownCast(SC);
67 Standard_Integer aDegree = BzC->Degree();
68 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
69 return Standard_False;
70 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
71 BSPL->SetDegree(aDegree);
72 BSPL->SetControlPointsList(BzC->ControlPointsList());
73 BSPL->SetCurveForm(BzC->CurveForm());
74 BSPL->SetClosedCurve(BzC->ClosedCurve());
75 BSPL->SetSelfIntersect(BzC->SelfIntersect());
76 // Compute Knots and KnotsMultiplicity
77 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,2);
78 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,2);
79 Kmult->SetValue(1, BzC->Degree() + 1);
80 Kmult->SetValue(2, BzC->Degree() + 1);
81 Knots->SetValue(1, 0.);
82 Knots->SetValue(2, 1.);
83 BSPL->SetKnotMultiplicities(Kmult);
84 BSPL->SetKnots(Knots);
85 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
87 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurve))) {
88 const Handle(StepGeom_UniformCurve) UC = Handle(StepGeom_UniformCurve)::DownCast(SC);
89 Standard_Integer aDegree = UC->Degree();
90 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
91 return Standard_False;
92 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
93 BSPL->SetDegree(aDegree);
94 BSPL->SetControlPointsList(UC->ControlPointsList());
95 BSPL->SetCurveForm(UC->CurveForm());
96 BSPL->SetClosedCurve(UC->ClosedCurve());
97 BSPL->SetSelfIntersect(UC->SelfIntersect());
98 // Compute Knots and KnotsMultiplicity
99 const Standard_Integer nbK = BSPL->NbControlPointsList() + BSPL->Degree() + 1;
100 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
101 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
102 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
103 Kmult->SetValue(iUC, 1);
104 Knots->SetValue(iUC, iUC - 1.);
106 BSPL->SetKnotMultiplicities(Kmult);
107 BSPL->SetKnots(Knots);
108 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
110 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurve))) {
111 const Handle(StepGeom_QuasiUniformCurve) QUC =
112 Handle(StepGeom_QuasiUniformCurve)::DownCast(SC);
113 Standard_Integer aDegree = QUC->Degree();
114 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
115 return Standard_False;
116 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
117 BSPL->SetDegree(aDegree);
118 BSPL->SetControlPointsList(QUC->ControlPointsList());
119 BSPL->SetCurveForm(QUC->CurveForm());
120 BSPL->SetClosedCurve(QUC->ClosedCurve());
121 BSPL->SetSelfIntersect(QUC->SelfIntersect());
122 // Compute Knots and KnotsMultiplicity
123 const Standard_Integer nbK = BSPL->NbControlPointsList() - BSPL->Degree() + 1;
124 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
125 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
126 for (Standard_Integer iQUC = 1 ; iQUC <= nbK ; iQUC ++) {
127 Kmult->SetValue(iQUC, 1);
128 Knots->SetValue(iQUC, iQUC - 1.);
130 Kmult->SetValue(1, BSPL->Degree() + 1);
131 Kmult->SetValue(nbK, BSPL->Degree() + 1);
132 BSPL->SetKnotMultiplicities(Kmult);
133 BSPL->SetKnots(Knots);
134 return StepToGeom_MakeBSplineCurve::Convert(BSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
136 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurveAndRationalBSplineCurve))) {
137 const Handle(StepGeom_UniformCurveAndRationalBSplineCurve) RUC =
138 Handle(StepGeom_UniformCurveAndRationalBSplineCurve)::DownCast(SC);
139 Standard_Integer aDegree = RUC->Degree();
140 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
141 return Standard_False;
142 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
143 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
144 // Compute Knots and KnotsMultiplicity
145 const Standard_Integer nbK = RUC->NbControlPointsList() + aDegree + 1;
146 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
147 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
148 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
149 Kmult->SetValue(iUC, 1);
150 Knots->SetValue(iUC, iUC - 1.);
152 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
153 RBSPL->Init(RUC->Name(), aDegree, RUC->ControlPointsList(), RUC->CurveForm(),
154 RUC->ClosedCurve(), RUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
156 return StepToGeom_MakeBSplineCurve::Convert(RBSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
158 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurveAndRationalBSplineCurve))) {
159 const Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve) RQUC =
160 Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve)::DownCast(SC);
161 Standard_Integer aDegree = RQUC->Degree();
162 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
163 return Standard_False;
164 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
165 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
166 // Compute Knots and KnotsMultiplicity
167 const Standard_Integer nbK = RQUC->NbControlPointsList() - aDegree + 1;
168 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
169 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
170 for (Standard_Integer iRQUC = 1 ; iRQUC <= nbK ; iRQUC ++) {
171 Kmult->SetValue(iRQUC, 1);
172 Knots->SetValue(iRQUC, iRQUC - 1.);
174 Kmult->SetValue(1, aDegree + 1);
175 Kmult->SetValue(nbK, aDegree + 1);
176 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
177 RBSPL->Init(RQUC->Name(), aDegree, RQUC->ControlPointsList(), RQUC->CurveForm(),
178 RQUC->ClosedCurve(), RQUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
179 RQUC->WeightsData());
180 return StepToGeom_MakeBSplineCurve::Convert(RBSPL,Handle(Geom_BSplineCurve)::DownCast (CC));
182 if (SC->IsKind(STANDARD_TYPE(StepGeom_Polyline))) { //:n6 abv 15 Feb 99
183 const Handle(StepGeom_Polyline) PL = Handle(StepGeom_Polyline)::DownCast (SC);
184 return StepToGeom_MakePolyline::Convert(PL,Handle(Geom_BSplineCurve)::DownCast (CC));
186 return Standard_False;