0027104: DownCast() cannot return null for mismatched handle
[occt.git] / src / RWStepGeom / RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_ShareTool.hxx>
18 #include <RWStepGeom_RWBSplineSurfaceWithKnots.hxx>
19 #include <RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
20 #include <RWStepGeom_RWRationalBSplineSurface.hxx>
21 #include <StepData_Logical.hxx>
22 #include <StepData_StepReaderData.hxx>
23 #include <StepData_StepWriter.hxx>
24 #include <StepGeom_BSplineSurfaceForm.hxx>
25 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
26 #include <StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
27 #include <StepGeom_CartesianPoint.hxx>
28 #include <StepGeom_HArray2OfCartesianPoint.hxx>
29 #include <StepGeom_KnotType.hxx>
30 #include <StepGeom_RationalBSplineSurface.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 #include <TColStd_HArray1OfReal.hxx>
33 #include <TColStd_HArray2OfReal.hxx>
34
35 // --- Enum : BSplineSurfaceForm ---
36 static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
37 static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
38 static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
39 static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
40 static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
41 static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
42 static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
43 static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
44 static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
45 static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
46 static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
47
48         // --- Enum : KnotType ---
49 static TCollection_AsciiString ktUniformKnots(".UNIFORM_KNOTS.");
50 static TCollection_AsciiString ktQuasiUniformKnots(".QUASI_UNIFORM_KNOTS.");
51 static TCollection_AsciiString ktPiecewiseBezierKnots(".PIECEWISE_BEZIER_KNOTS.");
52 static TCollection_AsciiString ktUnspecified(".UNSPECIFIED.");
53
54 RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface () {}
55
56 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::ReadStep
57         (const Handle(StepData_StepReaderData)& data,
58          const Standard_Integer num0,
59          Handle(Interface_Check)& ach,
60          const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent) const
61 {
62
63         Standard_Integer num = 0;    // num0
64         data->NamedForComplex("BOUNDED_SURFACE", "BNDSRF",num0,num,ach);
65
66 //      num = data->NextForComplex(num);
67         data->NamedForComplex("B_SPLINE_SURFACE", "BSPSR",num0,num,ach);
68
69         // --- Instance of common supertype BSplineSurface ---
70
71         if (!data->CheckNbParams(num,7,ach,"b_spline_surface")) return;
72         // --- field : uDegree ---
73
74
75         Standard_Integer aUDegree;
76         //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
77         data->ReadInteger (num,1,"u_degree",ach,aUDegree);
78         // --- field : vDegree ---
79
80
81         Standard_Integer aVDegree;
82         //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
83         data->ReadInteger (num,2,"v_degree",ach,aVDegree);
84         // --- field : controlPointsList ---
85
86
87         Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
88         Handle(StepGeom_CartesianPoint) anent3;
89         Standard_Integer nsub3;
90         if (data->ReadSubList (num,3,"control_points_list",ach,nsub3)) {
91           Standard_Integer nbi3 = data->NbParams(nsub3);
92           Standard_Integer nbj3 = data->NbParams(data->ParamNumber(nsub3,1));
93           aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi3, 1, nbj3);
94           for (Standard_Integer i3 = 1; i3 <= nbi3; i3 ++) {
95             Standard_Integer nsi3temp;
96             if (data->ReadSubList (nsub3,i3,"sub-part(control_points_list)",ach,nsi3temp)) {
97               Standard_Integer nsi3 = data->ParamNumber(nsub3,i3);
98               for (Standard_Integer j3 =1; j3 <= nbj3; j3 ++) {
99                 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
100                 if (data->ReadEntity (nsi3, j3,"cartesian_point", ach,
101                                       STANDARD_TYPE(StepGeom_CartesianPoint), anent3))
102                   aControlPointsList->SetValue(i3, j3, anent3);
103               }
104             }
105           }
106         }
107
108         // --- field : surfaceForm ---
109
110
111         StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
112         if (data->ParamType(num,4) == Interface_ParamEnum) {
113           Standard_CString text = data->ParamCValue(num,4);
114           if      (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
115           else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
116           else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
117           else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
118           else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
119           else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
120           else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
121           else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
122           else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
123           else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
124           else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
125           else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
126         }
127         else ach->AddFail("Parameter #4 (surface_form) is not an enumeration");
128         // --- field : uClosed ---
129
130
131         StepData_Logical aUClosed;
132         //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
133         data->ReadLogical (num,5,"u_closed",ach,aUClosed);
134         // --- field : vClosed ---
135
136
137         StepData_Logical aVClosed;
138         //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
139         data->ReadLogical (num,6,"v_closed",ach,aVClosed);
140         // --- field : selfIntersect ---
141
142
143         StepData_Logical aSelfIntersect;
144         //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
145         data->ReadLogical (num,7,"self_intersect",ach,aSelfIntersect);
146
147 //      num = data->NextForComplex(num);
148         data->NamedForComplex("B_SPLINE_SURFACE_WITH_KNOTS", "BSSWK",num0,num,ach);
149
150         // --- Instance of plex componant BSplineSurfaceWithKnots ---
151
152         if (!data->CheckNbParams(num,5,ach,"b_spline_surface_with_knots")) return;
153
154         // --- field : uMultiplicities ---
155
156         Handle(TColStd_HArray1OfInteger) aUMultiplicities;
157         Standard_Integer aUMultiplicitiesItem;
158         Standard_Integer nsub8;
159         if (data->ReadSubList (num,1,"u_multiplicities",ach,nsub8)) {
160           Standard_Integer nb8 = data->NbParams(nsub8);
161           aUMultiplicities = new TColStd_HArray1OfInteger (1, nb8);
162           for (Standard_Integer i8 = 1; i8 <= nb8; i8 ++) {
163             //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
164             if (data->ReadInteger (nsub8,i8,"u_multiplicities",ach,aUMultiplicitiesItem))
165               aUMultiplicities->SetValue(i8,aUMultiplicitiesItem);
166           }
167         }
168
169         // --- field : vMultiplicities ---
170
171         Handle(TColStd_HArray1OfInteger) aVMultiplicities;
172         Standard_Integer aVMultiplicitiesItem;
173         Standard_Integer nsub9;
174         if (data->ReadSubList (num,2,"v_multiplicities",ach,nsub9)) {
175           Standard_Integer nb9 = data->NbParams(nsub9);
176           aVMultiplicities = new TColStd_HArray1OfInteger (1, nb9);
177           for (Standard_Integer i9 = 1; i9 <= nb9; i9 ++) {
178             //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
179             if (data->ReadInteger (nsub9,i9,"v_multiplicities",ach,aVMultiplicitiesItem))
180               aVMultiplicities->SetValue(i9,aVMultiplicitiesItem);
181           }
182         }
183
184         // --- field : uKnots ---
185
186         Handle(TColStd_HArray1OfReal) aUKnots;
187         Standard_Real aUKnotsItem;
188         Standard_Integer nsub10;
189         if (data->ReadSubList (num,3,"u_knots",ach,nsub10)) {
190           Standard_Integer nb10 = data->NbParams(nsub10);
191           aUKnots = new TColStd_HArray1OfReal (1, nb10);
192           for (Standard_Integer i10 = 1; i10 <= nb10; i10 ++) {
193             //szv#4:S4163:12Mar99 `Standard_Boolean stat10 =` not needed
194             if (data->ReadReal (nsub10,i10,"u_knots",ach,aUKnotsItem))
195               aUKnots->SetValue(i10,aUKnotsItem);
196           }
197         }
198
199         // --- field : vKnots ---
200
201         Handle(TColStd_HArray1OfReal) aVKnots;
202         Standard_Real aVKnotsItem;
203         Standard_Integer nsub11;
204         if (data->ReadSubList (num,4,"v_knots",ach,nsub11)) {
205           Standard_Integer nb11 = data->NbParams(nsub11);
206           aVKnots = new TColStd_HArray1OfReal (1, nb11);
207           for (Standard_Integer i11 = 1; i11 <= nb11; i11 ++) {
208             //szv#4:S4163:12Mar99 `Standard_Boolean stat11 =` not needed
209             if (data->ReadReal (nsub11,i11,"v_knots",ach,aVKnotsItem))
210               aVKnots->SetValue(i11,aVKnotsItem);
211           }
212         }
213
214         // --- field : knotSpec ---
215
216         StepGeom_KnotType aKnotSpec =  StepGeom_ktUniformKnots;
217         if (data->ParamType(num,5) == Interface_ParamEnum) {
218           Standard_CString text = data->ParamCValue(num,5);
219           if      (ktUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktUniformKnots;
220           else if (ktQuasiUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktQuasiUniformKnots;
221           else if (ktPiecewiseBezierKnots.IsEqual(text)) aKnotSpec = StepGeom_ktPiecewiseBezierKnots;
222           else if (ktUnspecified.IsEqual(text)) aKnotSpec = StepGeom_ktUnspecified;
223           else ach->AddFail("Enumeration knot_type has not an allowed value");
224         }
225         else ach->AddFail("Parameter #5 (knot_spec) is not an enumeration");
226
227 //      num = data->NextForComplex(num);
228         data->NamedForComplex("GEOMETRIC_REPRESENTATION_ITEM", "GMRPIT",num0,num,ach);
229
230 //      num = data->NextForComplex(num);
231         data->NamedForComplex("RATIONAL_B_SPLINE_SURFACE", "RBSS",num0,num,ach);
232
233         // --- Instance of plex componant RationalBSplineSurface ---
234
235         if (!data->CheckNbParams(num,1,ach,"rational_b_spline_surface")) return;
236
237         // --- field : weightsData ---
238
239         Handle(TColStd_HArray2OfReal) aWeightsData;
240           Standard_Real aWeightsDataItem;
241         Standard_Integer nsub13;
242         if (data->ReadSubList (num,1,"weights_data",ach,nsub13)) {
243           Standard_Integer nbi13 = data->NbParams(nsub13);
244           Standard_Integer nbj13 = data->NbParams(data->ParamNumber(nsub13,1));
245           aWeightsData = new TColStd_HArray2OfReal (1,nbi13,1,nbj13);
246           for (Standard_Integer i13 = 1; i13 <= nbi13; i13 ++) {
247             Standard_Integer nsi13temp;
248             if (data->ReadSubList (nsub13,i13,"sub-part(weights_data)",ach,nsi13temp)) {
249               Standard_Integer nsi13 = data->ParamNumber(nsub13,i13);
250               for (Standard_Integer j13 =1; j13 <= nbj13; j13 ++) {
251                 //szv#4:S4163:12Mar99 `Standard_Boolean stat13 =` not needed
252                 if (data->ReadReal (nsi13,j13,"weights_data",ach,aWeightsDataItem))
253                   aWeightsData->SetValue(i13,j13,aWeightsDataItem);
254               }
255             }
256           }
257         }
258
259 //      num = data->NextForComplex(num);
260         data->NamedForComplex("REPRESENTATION_ITEM", "RPRITM",num0,num,ach);
261
262         // --- Instance of plex componant RepresentationItem ---
263
264         if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
265
266         // --- field : name ---
267
268         Handle(TCollection_HAsciiString) aName;
269         //szv#4:S4163:12Mar99 `Standard_Boolean stat14 =` not needed
270         data->ReadString (num,1,"name",ach,aName);
271
272 //      num = data->NextForComplex(num);
273         data->NamedForComplex("SURFACE", "SRFC",num0,num,ach);
274
275         //--- Initialisation of the red entity ---
276
277         ent->Init(aName,aUDegree,aVDegree,aControlPointsList,aSurfaceForm,aUClosed,aVClosed,aSelfIntersect,aUMultiplicities,aVMultiplicities,aUKnots,aVKnots,aKnotSpec,aWeightsData);
278 }
279
280
281 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::WriteStep
282         (StepData_StepWriter& SW,
283          const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent) const
284 {
285
286         // --- Instance of plex componant BoundedSurface ---
287
288         SW.StartEntity("BOUNDED_SURFACE");
289
290         // --- Instance of common supertype BSplineSurface ---
291
292         SW.StartEntity("B_SPLINE_SURFACE");
293         // --- field : uDegree ---
294
295         SW.Send(ent->UDegree());
296         // --- field : vDegree ---
297
298         SW.Send(ent->VDegree());
299         // --- field : controlPointsList ---
300
301         SW.OpenSub();
302         for (Standard_Integer i3 = 1;  i3 <= ent->NbControlPointsListI(); i3 ++) {
303           SW.NewLine(Standard_False);
304           SW.OpenSub();
305           for (Standard_Integer j3 = 1;  j3 <= ent->NbControlPointsListJ(); j3 ++) {
306             SW.Send(ent->ControlPointsListValue(i3,j3));
307             SW.JoinLast(Standard_False);
308           }
309           SW.CloseSub();
310         }
311         SW.CloseSub();
312         // --- field : surfaceForm ---
313
314         switch(ent->SurfaceForm()) {
315           case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
316           case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
317           case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
318           case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
319           case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
320           case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
321           case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
322           case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
323           case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
324           case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
325           case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
326         }
327         // --- field : uClosed ---
328
329         SW.SendLogical(ent->UClosed());
330         // --- field : vClosed ---
331
332         SW.SendLogical(ent->VClosed());
333         // --- field : selfIntersect ---
334
335         SW.SendLogical(ent->SelfIntersect());
336
337         // --- Instance of plex componant BSplineSurfaceWithKnots ---
338
339         SW.StartEntity("B_SPLINE_SURFACE_WITH_KNOTS");
340         // --- field : uMultiplicities ---
341
342         SW.OpenSub();
343         for (Standard_Integer i8 = 1;  i8 <= ent->NbUMultiplicities();  i8 ++) {
344           SW.Send(ent->UMultiplicitiesValue(i8));
345         }
346         SW.CloseSub();
347         // --- field : vMultiplicities ---
348
349         SW.OpenSub();
350         for (Standard_Integer i9 = 1;  i9 <= ent->NbVMultiplicities();  i9 ++) {
351           SW.Send(ent->VMultiplicitiesValue(i9));
352         }
353         SW.CloseSub();
354         // --- field : uKnots ---
355
356         SW.OpenSub();
357         for (Standard_Integer i10 = 1;  i10 <= ent->NbUKnots();  i10 ++) {
358           SW.Send(ent->UKnotsValue(i10));
359         }
360         SW.CloseSub();
361         // --- field : vKnots ---
362
363         SW.OpenSub();
364         for (Standard_Integer i11 = 1;  i11 <= ent->NbVKnots();  i11 ++) {
365           SW.Send(ent->VKnotsValue(i11));
366         }
367         SW.CloseSub();
368         // --- field : knotSpec ---
369
370         switch(ent->KnotSpec()) {
371           case StepGeom_ktUniformKnots : SW.SendEnum (ktUniformKnots); break;
372           case StepGeom_ktQuasiUniformKnots : SW.SendEnum (ktQuasiUniformKnots); break;
373           case StepGeom_ktPiecewiseBezierKnots : SW.SendEnum (ktPiecewiseBezierKnots); break;
374           case StepGeom_ktUnspecified : SW.SendEnum (ktUnspecified); break;
375         }
376
377         // --- Instance of plex componant GeometricRepresentationItem ---
378
379         SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
380
381         // --- Instance of plex componant RationalBSplineSurface ---
382
383         SW.StartEntity("RATIONAL_B_SPLINE_SURFACE");
384         // --- field : weightsData ---
385
386         SW.OpenSub();
387         for (Standard_Integer i13 = 1;  i13 <= ent->NbWeightsDataI(); i13 ++) {
388           SW.NewLine(Standard_False);
389           SW.OpenSub();
390           for (Standard_Integer j13 = 1;  j13 <= ent->NbWeightsDataJ(); j13 ++) {
391             SW.Send(ent->WeightsDataValue(i13,j13));
392             SW.JoinLast(Standard_False);
393           }
394           SW.CloseSub();
395         }
396         SW.CloseSub();
397
398         // --- Instance of plex componant RepresentationItem ---
399
400         SW.StartEntity("REPRESENTATION_ITEM");
401         // --- field : name ---
402
403         SW.Send(ent->Name());
404
405         // --- Instance of plex componant Surface ---
406
407         SW.StartEntity("SURFACE");
408 }
409
410
411 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::Share(const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent, Interface_EntityIterator& iter) const
412 {
413
414         Standard_Integer nbiElem1 = ent->NbControlPointsListI();
415         Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
416         for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
417           for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
418             iter.GetOneItem(ent->ControlPointsListValue(is1,js1));
419           }
420         }
421
422 }
423
424
425
426 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::Check
427   (const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent,
428    const Interface_ShareTool& aShto,
429    Handle(Interface_Check)& ach) const
430 {
431   Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) aRationalBSS = ent;
432   Handle(StepGeom_BSplineSurfaceWithKnots) aBSSWK =
433     aRationalBSS->BSplineSurfaceWithKnots();
434   RWStepGeom_RWBSplineSurfaceWithKnots t1;
435   t1.Check(aBSSWK,aShto,ach);
436   Handle(StepGeom_RationalBSplineSurface) aRBSS =
437     aRationalBSS->RationalBSplineSurface();
438   RWStepGeom_RWRationalBSplineSurface t2;
439   t2.Check(aRBSS,aShto,ach);
440 }