1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
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.");
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.");
51 RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::
52 RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface()
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
63 Standard_Integer num = 0; // num0
64 data->NamedForComplex("BOUNDED_SURFACE", "BNDSRF", num0, num, ach);
66 // num = data->NextForComplex(num);
67 data->NamedForComplex("B_SPLINE_SURFACE", "BSPSR", num0, num, ach);
69 // --- Instance of common supertype BSplineSurface ---
71 if (!data->CheckNbParams(num, 7, ach, "b_spline_surface"))
73 // --- field : uDegree ---
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 ---
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 ---
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))
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++)
95 Standard_Integer nsi3temp;
96 if (data->ReadSubList(nsub3, i3, "sub-part(control_points_list)", ach, nsi3temp))
98 Standard_Integer nsi3 = data->ParamNumber(nsub3, i3);
99 for (Standard_Integer j3 = 1; j3 <= nbj3; j3++)
101 // szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
102 if (data->ReadEntity(nsi3,
106 STANDARD_TYPE(StepGeom_CartesianPoint),
108 aControlPointsList->SetValue(i3, j3, anent3);
114 // --- field : surfaceForm ---
116 StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
117 if (data->ParamType(num, 4) == Interface_ParamEnum)
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;
143 ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
146 ach->AddFail("Parameter #4 (surface_form) is not an enumeration");
147 // --- field : uClosed ---
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 ---
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 ---
159 StepData_Logical aSelfIntersect;
160 // szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
161 data->ReadLogical(num, 7, "self_intersect", ach, aSelfIntersect);
163 // num = data->NextForComplex(num);
164 data->NamedForComplex("B_SPLINE_SURFACE_WITH_KNOTS", "BSSWK", num0, num, ach);
166 // --- Instance of plex component BSplineSurfaceWithKnots ---
168 if (!data->CheckNbParams(num, 5, ach, "b_spline_surface_with_knots"))
171 // --- field : uMultiplicities ---
173 Handle(TColStd_HArray1OfInteger) aUMultiplicities;
174 Standard_Integer aUMultiplicitiesItem;
175 Standard_Integer nsub8;
176 if (data->ReadSubList(num, 1, "u_multiplicities", ach, nsub8))
178 Standard_Integer nb8 = data->NbParams(nsub8);
179 aUMultiplicities = new TColStd_HArray1OfInteger(1, nb8);
180 for (Standard_Integer i8 = 1; i8 <= nb8; i8++)
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);
188 // --- field : vMultiplicities ---
190 Handle(TColStd_HArray1OfInteger) aVMultiplicities;
191 Standard_Integer aVMultiplicitiesItem;
192 Standard_Integer nsub9;
193 if (data->ReadSubList(num, 2, "v_multiplicities", ach, nsub9))
195 Standard_Integer nb9 = data->NbParams(nsub9);
196 aVMultiplicities = new TColStd_HArray1OfInteger(1, nb9);
197 for (Standard_Integer i9 = 1; i9 <= nb9; i9++)
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);
205 // --- field : uKnots ---
207 Handle(TColStd_HArray1OfReal) aUKnots;
208 Standard_Real aUKnotsItem;
209 Standard_Integer nsub10;
210 if (data->ReadSubList(num, 3, "u_knots", ach, nsub10))
212 Standard_Integer nb10 = data->NbParams(nsub10);
213 aUKnots = new TColStd_HArray1OfReal(1, nb10);
214 for (Standard_Integer i10 = 1; i10 <= nb10; i10++)
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);
222 // --- field : vKnots ---
224 Handle(TColStd_HArray1OfReal) aVKnots;
225 Standard_Real aVKnotsItem;
226 Standard_Integer nsub11;
227 if (data->ReadSubList(num, 4, "v_knots", ach, nsub11))
229 Standard_Integer nb11 = data->NbParams(nsub11);
230 aVKnots = new TColStd_HArray1OfReal(1, nb11);
231 for (Standard_Integer i11 = 1; i11 <= nb11; i11++)
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);
239 // --- field : knotSpec ---
241 StepGeom_KnotType aKnotSpec = StepGeom_ktUniformKnots;
242 if (data->ParamType(num, 5) == Interface_ParamEnum)
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;
254 ach->AddFail("Enumeration knot_type has not an allowed value");
257 ach->AddFail("Parameter #5 (knot_spec) is not an enumeration");
259 // num = data->NextForComplex(num);
260 data->NamedForComplex("GEOMETRIC_REPRESENTATION_ITEM", "GMRPIT", num0, num, ach);
262 // num = data->NextForComplex(num);
263 data->NamedForComplex("RATIONAL_B_SPLINE_SURFACE", "RBSS", num0, num, ach);
265 // --- Instance of plex component RationalBSplineSurface ---
267 if (!data->CheckNbParams(num, 1, ach, "rational_b_spline_surface"))
270 // --- field : weightsData ---
272 Handle(TColStd_HArray2OfReal) aWeightsData;
273 Standard_Real aWeightsDataItem;
274 Standard_Integer nsub13;
275 if (data->ReadSubList(num, 1, "weights_data", ach, nsub13))
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++)
282 Standard_Integer nsi13temp;
283 if (data->ReadSubList(nsub13, i13, "sub-part(weights_data)", ach, nsi13temp))
285 Standard_Integer nsi13 = data->ParamNumber(nsub13, i13);
286 for (Standard_Integer j13 = 1; j13 <= nbj13; j13++)
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);
296 // num = data->NextForComplex(num);
297 data->NamedForComplex("REPRESENTATION_ITEM", "RPRITM", num0, num, ach);
299 // --- Instance of plex component RepresentationItem ---
301 // --- field : name ---
303 Handle(TCollection_HAsciiString) aName;
305 if (!data->CheckNbParams(num, 1, ach, "representation_item"))
307 aName = new TCollection_HAsciiString("");
311 // szv#4:S4163:12Mar99 `Standard_Boolean stat14 =` not needed
312 data->ReadString(num, 1, "name", ach, aName);
315 // num = data->NextForComplex(num);
316 data->NamedForComplex("SURFACE", "SRFC", num0, num, ach);
318 //--- Initialisation of the red entity ---
336 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::WriteStep(
337 StepData_StepWriter& SW,
338 const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent) const
341 // --- Instance of plex component BoundedSurface ---
343 SW.StartEntity("BOUNDED_SURFACE");
345 // --- Instance of common supertype BSplineSurface ---
347 SW.StartEntity("B_SPLINE_SURFACE");
348 // --- field : uDegree ---
350 SW.Send(ent->UDegree());
351 // --- field : vDegree ---
353 SW.Send(ent->VDegree());
354 // --- field : controlPointsList ---
357 for (Standard_Integer i3 = 1; i3 <= ent->NbControlPointsListI(); i3++)
359 SW.NewLine(Standard_False);
361 for (Standard_Integer j3 = 1; j3 <= ent->NbControlPointsListJ(); j3++)
363 SW.Send(ent->ControlPointsListValue(i3, j3));
364 SW.JoinLast(Standard_False);
369 // --- field : surfaceForm ---
371 switch (ent->SurfaceForm())
373 case StepGeom_bssfSurfOfLinearExtrusion:
374 SW.SendEnum(bssfSurfOfLinearExtrusion);
376 case StepGeom_bssfPlaneSurf:
377 SW.SendEnum(bssfPlaneSurf);
379 case StepGeom_bssfGeneralisedCone:
380 SW.SendEnum(bssfGeneralisedCone);
382 case StepGeom_bssfToroidalSurf:
383 SW.SendEnum(bssfToroidalSurf);
385 case StepGeom_bssfConicalSurf:
386 SW.SendEnum(bssfConicalSurf);
388 case StepGeom_bssfSphericalSurf:
389 SW.SendEnum(bssfSphericalSurf);
391 case StepGeom_bssfUnspecified:
392 SW.SendEnum(bssfUnspecified);
394 case StepGeom_bssfRuledSurf:
395 SW.SendEnum(bssfRuledSurf);
397 case StepGeom_bssfSurfOfRevolution:
398 SW.SendEnum(bssfSurfOfRevolution);
400 case StepGeom_bssfCylindricalSurf:
401 SW.SendEnum(bssfCylindricalSurf);
403 case StepGeom_bssfQuadricSurf:
404 SW.SendEnum(bssfQuadricSurf);
407 // --- field : uClosed ---
409 SW.SendLogical(ent->UClosed());
410 // --- field : vClosed ---
412 SW.SendLogical(ent->VClosed());
413 // --- field : selfIntersect ---
415 SW.SendLogical(ent->SelfIntersect());
417 // --- Instance of plex component BSplineSurfaceWithKnots ---
419 SW.StartEntity("B_SPLINE_SURFACE_WITH_KNOTS");
420 // --- field : uMultiplicities ---
423 for (Standard_Integer i8 = 1; i8 <= ent->NbUMultiplicities(); i8++)
425 SW.Send(ent->UMultiplicitiesValue(i8));
428 // --- field : vMultiplicities ---
431 for (Standard_Integer i9 = 1; i9 <= ent->NbVMultiplicities(); i9++)
433 SW.Send(ent->VMultiplicitiesValue(i9));
436 // --- field : uKnots ---
439 for (Standard_Integer i10 = 1; i10 <= ent->NbUKnots(); i10++)
441 SW.Send(ent->UKnotsValue(i10));
444 // --- field : vKnots ---
447 for (Standard_Integer i11 = 1; i11 <= ent->NbVKnots(); i11++)
449 SW.Send(ent->VKnotsValue(i11));
452 // --- field : knotSpec ---
454 switch (ent->KnotSpec())
456 case StepGeom_ktUniformKnots:
457 SW.SendEnum(ktUniformKnots);
459 case StepGeom_ktQuasiUniformKnots:
460 SW.SendEnum(ktQuasiUniformKnots);
462 case StepGeom_ktPiecewiseBezierKnots:
463 SW.SendEnum(ktPiecewiseBezierKnots);
465 case StepGeom_ktUnspecified:
466 SW.SendEnum(ktUnspecified);
470 // --- Instance of plex component GeometricRepresentationItem ---
472 SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
474 // --- Instance of plex component RationalBSplineSurface ---
476 SW.StartEntity("RATIONAL_B_SPLINE_SURFACE");
477 // --- field : weightsData ---
480 for (Standard_Integer i13 = 1; i13 <= ent->NbWeightsDataI(); i13++)
482 SW.NewLine(Standard_False);
484 for (Standard_Integer j13 = 1; j13 <= ent->NbWeightsDataJ(); j13++)
486 SW.Send(ent->WeightsDataValue(i13, j13));
487 SW.JoinLast(Standard_False);
493 // --- Instance of plex component RepresentationItem ---
495 SW.StartEntity("REPRESENTATION_ITEM");
496 // --- field : name ---
498 SW.Send(ent->Name());
500 // --- Instance of plex component Surface ---
502 SW.StartEntity("SURFACE");
505 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::Share(
506 const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent,
507 Interface_EntityIterator& iter) const
510 Standard_Integer nbiElem1 = ent->NbControlPointsListI();
511 Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
512 for (Standard_Integer is1 = 1; is1 <= nbiElem1; is1++)
514 for (Standard_Integer js1 = 1; js1 <= nbjElem1; js1++)
516 iter.GetOneItem(ent->ControlPointsListValue(is1, js1));
521 void RWStepGeom_RWBSplineSurfaceWithKnotsAndRationalBSplineSurface::Check(
522 const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)& ent,
523 const Interface_ShareTool& aShto,
524 Handle(Interface_Check)& ach) const
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);