0027104: DownCast() cannot return null for mismatched handle
[occt.git] / src / RWStepGeom / RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
7fd59977 15
42cf5bc1 16#include <Interface_Check.hxx>
17#include <Interface_EntityIterator.hxx>
18#include <Interface_ShareTool.hxx>
7fd59977 19#include <RWStepGeom_RWBSplineCurveWithKnots.hxx>
42cf5bc1 20#include <RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
7fd59977 21#include <RWStepGeom_RWRationalBSplineCurve.hxx>
42cf5bc1 22#include <StepData_Logical.hxx>
23#include <StepData_StepReaderData.hxx>
24#include <StepData_StepWriter.hxx>
25#include <StepGeom_BSplineCurveForm.hxx>
26#include <StepGeom_BSplineCurveWithKnots.hxx>
7fd59977 27#include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
42cf5bc1 28#include <StepGeom_CartesianPoint.hxx>
29#include <StepGeom_HArray1OfCartesianPoint.hxx>
30#include <StepGeom_KnotType.hxx>
31#include <StepGeom_RationalBSplineCurve.hxx>
32#include <TColStd_HArray1OfInteger.hxx>
33#include <TColStd_HArray1OfReal.hxx>
7fd59977 34
b311480e 35// --- Enum : BSplineCurveForm ---
7fd59977 36static TCollection_AsciiString bscfEllipticArc(".ELLIPTIC_ARC.");
37static TCollection_AsciiString bscfPolylineForm(".POLYLINE_FORM.");
38static TCollection_AsciiString bscfParabolicArc(".PARABOLIC_ARC.");
39static TCollection_AsciiString bscfCircularArc(".CIRCULAR_ARC.");
40static TCollection_AsciiString bscfUnspecified(".UNSPECIFIED.");
41static TCollection_AsciiString bscfHyperbolicArc(".HYPERBOLIC_ARC.");
42
43 // --- Enum : KnotType ---
44static TCollection_AsciiString ktUniformKnots(".UNIFORM_KNOTS.");
45static TCollection_AsciiString ktQuasiUniformKnots(".QUASI_UNIFORM_KNOTS.");
46static TCollection_AsciiString ktPiecewiseBezierKnots(".PIECEWISE_BEZIER_KNOTS.");
47static TCollection_AsciiString ktUnspecified(".UNSPECIFIED.");
48
49RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve () {}
50
51void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::ReadStep
52 (const Handle(StepData_StepReaderData)& data,
53 const Standard_Integer num0,
54 Handle(Interface_Check)& ach,
55 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent) const
56{
57
58// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
59 Standard_Integer num = 0; // num0
a7197ef3 60 data->NamedForComplex("BOUNDED_CURVE", "BNDCRV",num0,num,ach);
7fd59977 61
62// num = data->NextForComplex(num);
63// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
64// num = 0; gka TRJ9
a7197ef3 65 data->NamedForComplex("B_SPLINE_CURVE", "BSPCR",num0,num,ach);
7fd59977 66
67 // --- Instance of common supertype BSplineCurve ---
68
69 if (!data->CheckNbParams(num,5,ach,"b_spline_curve")) return;
70 // --- field : degree ---
71
72
73 Standard_Integer aDegree;
74 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
75 data->ReadInteger (num,1,"degree",ach,aDegree);
76 // --- field : controlPointsList ---
77
78
79 Handle(StepGeom_HArray1OfCartesianPoint) aControlPointsList;
80 Handle(StepGeom_CartesianPoint) anent2;
81 Standard_Integer nsub2;
82 if (data->ReadSubList (num,2,"control_points_list",ach,nsub2)) {
83 Standard_Integer nb2 = data->NbParams(nsub2);
84 aControlPointsList = new StepGeom_HArray1OfCartesianPoint (1, nb2);
85 for (Standard_Integer i2 = 1; i2 <= nb2; i2 ++) {
86 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
87 if (data->ReadEntity (nsub2, i2,"cartesian_point", ach,
88 STANDARD_TYPE(StepGeom_CartesianPoint), anent2))
89 aControlPointsList->SetValue(i2, anent2);
90 }
91 }
92
93 // --- field : curveForm ---
94
95
96 StepGeom_BSplineCurveForm aCurveForm = StepGeom_bscfPolylineForm;
97 if (data->ParamType(num,3) == Interface_ParamEnum) {
98 Standard_CString text = data->ParamCValue(num,3);
99 if (bscfEllipticArc.IsEqual(text)) aCurveForm = StepGeom_bscfEllipticArc;
100 else if (bscfPolylineForm.IsEqual(text)) aCurveForm = StepGeom_bscfPolylineForm;
101 else if (bscfParabolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfParabolicArc;
102 else if (bscfCircularArc.IsEqual(text)) aCurveForm = StepGeom_bscfCircularArc;
103 else if (bscfUnspecified.IsEqual(text)) aCurveForm = StepGeom_bscfUnspecified;
104 else if (bscfHyperbolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfHyperbolicArc;
105 else ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
106 }
107 else ach->AddFail("Parameter #3 (curve_form) is not an enumeration");
108 // --- field : closedCurve ---
109
110
111 StepData_Logical aClosedCurve;
112 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
113 data->ReadLogical (num,4,"closed_curve",ach,aClosedCurve);
114 // --- field : selfIntersect ---
115
116
117 StepData_Logical aSelfIntersect;
118 //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
119 data->ReadLogical (num,5,"self_intersect",ach,aSelfIntersect);
120
121// num = data->NextForComplex(num);
122// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
123// num = 0; //gka TRJ9
a7197ef3 124 data->NamedForComplex("B_SPLINE_CURVE_WITH_KNOTS", "BSCWK",num0,num,ach);
7fd59977 125
126 // --- Instance of plex componant BSplineCurveWithKnots ---
127
128 if (!data->CheckNbParams(num,3,ach,"b_spline_curve_with_knots")) return;
129
130 // --- field : knotMultiplicities ---
131
132 Handle(TColStd_HArray1OfInteger) aKnotMultiplicities;
133 Standard_Integer aKnotMultiplicitiesItem;
134 Standard_Integer nsub6;
135 if (data->ReadSubList (num,1,"knot_multiplicities",ach,nsub6)) {
136 Standard_Integer nb6 = data->NbParams(nsub6);
137 aKnotMultiplicities = new TColStd_HArray1OfInteger (1, nb6);
138 for (Standard_Integer i6 = 1; i6 <= nb6; i6 ++) {
139 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
140 if (data->ReadInteger (nsub6,i6,"knot_multiplicities",ach,aKnotMultiplicitiesItem))
141 aKnotMultiplicities->SetValue(i6,aKnotMultiplicitiesItem);
142 }
143 }
144
145 // --- field : knots ---
146
147 Handle(TColStd_HArray1OfReal) aKnots;
148 Standard_Real aKnotsItem;
149 Standard_Integer nsub7;
150 if (data->ReadSubList (num,2,"knots",ach,nsub7)) {
151 Standard_Integer nb7 = data->NbParams(nsub7);
152 aKnots = new TColStd_HArray1OfReal (1, nb7);
153 for (Standard_Integer i7 = 1; i7 <= nb7; i7 ++) {
154 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
155 if (data->ReadReal (nsub7,i7,"knots",ach,aKnotsItem))
156 aKnots->SetValue(i7,aKnotsItem);
157 }
158 }
159
160 // --- field : knotSpec ---
161
162 StepGeom_KnotType aKnotSpec = StepGeom_ktUniformKnots;
163 if (data->ParamType(num,3) == Interface_ParamEnum) {
164 Standard_CString text = data->ParamCValue(num,3);
165 if (ktUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktUniformKnots;
166 else if (ktQuasiUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktQuasiUniformKnots;
167 else if (ktPiecewiseBezierKnots.IsEqual(text)) aKnotSpec = StepGeom_ktPiecewiseBezierKnots;
168 else if (ktUnspecified.IsEqual(text)) aKnotSpec = StepGeom_ktUnspecified;
169 else ach->AddFail("Enumeration knot_type has not an allowed value");
170 }
171 else ach->AddFail("Parameter #3 (knot_spec) is not an enumeration");
172
173// num = data->NextForComplex(num);
174// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
175// num = 0; gka TRJ9
176 data->NamedForComplex("CURVE",num0,num,ach);
177
7fd59977 178// num = data->NextForComplex(num);
179// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
180 //num = 0;
a7197ef3 181 data->NamedForComplex("GEOMETRIC_REPRESENTATION_ITEM", "GMRPIT",num0,num,ach);
7fd59977 182
183// num = data->NextForComplex(num);
184// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
185 //num = 0;
a7197ef3 186 data->NamedForComplex("RATIONAL_B_SPLINE_CURVE", "RBSC",num0,num,ach);
7fd59977 187
188 // --- Instance of plex componant RationalBSplineCurve ---
189
190 if (!data->CheckNbParams(num,1,ach,"rational_b_spline_curve")) return;
191
192 // --- field : weightsData ---
193
194 Handle(TColStd_HArray1OfReal) aWeightsData;
195 Standard_Real aWeightsDataItem;
196 Standard_Integer nsub9;
197 if (data->ReadSubList (num,1,"weights_data",ach,nsub9)) {
198 Standard_Integer nb9 = data->NbParams(nsub9);
199 aWeightsData = new TColStd_HArray1OfReal (1, nb9);
200 for (Standard_Integer i9 = 1; i9 <= nb9; i9 ++) {
201 //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
202 if (data->ReadReal (nsub9,i9,"weights_data",ach,aWeightsDataItem))
203 aWeightsData->SetValue(i9,aWeightsDataItem);
204 }
205 }
206
207// num = data->NextForComplex(num);
208// sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
209 //num = 0;
a7197ef3 210 data->NamedForComplex("REPRESENTATION_ITEM", "RPRITM",num0,num,ach);
7fd59977 211
212 // --- Instance of plex componant RepresentationItem ---
213
214 if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
215
216 // --- field : name ---
217
218 Handle(TCollection_HAsciiString) aName;
219 //szv#4:S4163:12Mar99 `Standard_Boolean stat10 =` not needed
220 data->ReadString (num,1,"name",ach,aName);
221
222 //--- Initialisation of the red entity ---
223
224 ent->Init(aName,aDegree,aControlPointsList,aCurveForm,aClosedCurve,aSelfIntersect,aKnotMultiplicities,aKnots,aKnotSpec,aWeightsData);
225}
226
227
228void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::WriteStep
229 (StepData_StepWriter& SW,
230 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent) const
231{
232
233 // --- Instance of plex componant BoundedCurve ---
234
235 SW.StartEntity("BOUNDED_CURVE");
236
237 // --- Instance of common supertype BSplineCurve ---
238
239 SW.StartEntity("B_SPLINE_CURVE");
240 // --- field : degree ---
241
242 SW.Send(ent->Degree());
243 // --- field : controlPointsList ---
244
245 SW.OpenSub();
246 for (Standard_Integer i2 = 1; i2 <= ent->NbControlPointsList(); i2 ++) {
247 SW.Send(ent->ControlPointsListValue(i2));
248 }
249 SW.CloseSub();
250 // --- field : curveForm ---
251
252 switch(ent->CurveForm()) {
253 case StepGeom_bscfEllipticArc : SW.SendEnum (bscfEllipticArc); break;
254 case StepGeom_bscfPolylineForm : SW.SendEnum (bscfPolylineForm); break;
255 case StepGeom_bscfParabolicArc : SW.SendEnum (bscfParabolicArc); break;
256 case StepGeom_bscfCircularArc : SW.SendEnum (bscfCircularArc); break;
257 case StepGeom_bscfUnspecified : SW.SendEnum (bscfUnspecified); break;
258 case StepGeom_bscfHyperbolicArc : SW.SendEnum (bscfHyperbolicArc); break;
259 }
260 // --- field : closedCurve ---
261
262 SW.SendLogical(ent->ClosedCurve());
263 // --- field : selfIntersect ---
264
265 SW.SendLogical(ent->SelfIntersect());
266
267 // --- Instance of plex componant BSplineCurveWithKnots ---
268
269 SW.StartEntity("B_SPLINE_CURVE_WITH_KNOTS");
270 // --- field : knotMultiplicities ---
271
272 SW.OpenSub();
273 for (Standard_Integer i6 = 1; i6 <= ent->NbKnotMultiplicities(); i6 ++) {
274 SW.Send(ent->KnotMultiplicitiesValue(i6));
275 }
276 SW.CloseSub();
277 // --- field : knots ---
278
279 SW.OpenSub();
280 for (Standard_Integer i7 = 1; i7 <= ent->NbKnots(); i7 ++) {
281 SW.Send(ent->KnotsValue(i7));
282 }
283 SW.CloseSub();
284 // --- field : knotSpec ---
285
286 switch(ent->KnotSpec()) {
287 case StepGeom_ktUniformKnots : SW.SendEnum (ktUniformKnots); break;
288 case StepGeom_ktQuasiUniformKnots : SW.SendEnum (ktQuasiUniformKnots); break;
289 case StepGeom_ktPiecewiseBezierKnots : SW.SendEnum (ktPiecewiseBezierKnots); break;
290 case StepGeom_ktUnspecified : SW.SendEnum (ktUnspecified); break;
291 }
292
293 // --- Instance of plex componant Curve ---
294
295 SW.StartEntity("CURVE");
296
297 // --- Instance of plex componant GeometricRepresentationItem ---
298
299 SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
300
301 // --- Instance of plex componant RationalBSplineCurve ---
302
303 SW.StartEntity("RATIONAL_B_SPLINE_CURVE");
304 // --- field : weightsData ---
305
306 SW.OpenSub();
307 for (Standard_Integer i9 = 1; i9 <= ent->NbWeightsData(); i9 ++) {
308 SW.Send(ent->WeightsDataValue(i9));
309 }
310 SW.CloseSub();
311
312 // --- Instance of plex componant RepresentationItem ---
313
314 SW.StartEntity("REPRESENTATION_ITEM");
315 // --- field : name ---
316
317 SW.Send(ent->Name());
318}
319
320
321void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::Share(const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
322{
323
324 Standard_Integer nbElem1 = ent->NbControlPointsList();
325 for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
326 iter.GetOneItem(ent->ControlPointsListValue(is1));
327 }
328
329}
330
331
332
333void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::Check
334 (const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent,
335 const Interface_ShareTool& aShto,
336 Handle(Interface_Check)& ach) const
337{
a9dde4a3 338 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) aRationalBSC = ent;
7fd59977 339 Handle(StepGeom_BSplineCurveWithKnots) aBSCWK =
340 aRationalBSC->BSplineCurveWithKnots();
341 RWStepGeom_RWBSplineCurveWithKnots t1;
342 t1.Check(aBSCWK,aShto,ach);
343 Handle(StepGeom_RationalBSplineCurve) aRBSC =
344 aRationalBSC->RationalBSplineCurve();
345 RWStepGeom_RWRationalBSplineCurve t2;
346 t2.Check(aRBSC,aShto,ach);
347}