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