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