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.
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_ShareTool.hxx>
18 #include <RWStepGeom_RWBSplineSurfaceWithKnots.hxx>
19 #include <StepData_Logical.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <StepGeom_BSplineSurfaceForm.hxx>
23 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
24 #include <StepGeom_CartesianPoint.hxx>
25 #include <StepGeom_HArray2OfCartesianPoint.hxx>
26 #include <StepGeom_KnotType.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TColStd_HArray1OfInteger.hxx>
29 #include <TColStd_HArray1OfReal.hxx>
31 // --- Enum : KnotType ---
32 static TCollection_AsciiString ktUniformKnots(".UNIFORM_KNOTS.");
33 static TCollection_AsciiString ktQuasiUniformKnots(".QUASI_UNIFORM_KNOTS.");
34 static TCollection_AsciiString ktPiecewiseBezierKnots(".PIECEWISE_BEZIER_KNOTS.");
35 static TCollection_AsciiString ktUnspecified(".UNSPECIFIED.");
38 // --- Enum : BSplineSurfaceForm ---
39 static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
40 static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
41 static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
42 static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
43 static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
44 static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
45 static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
46 static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
47 static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
48 static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
49 static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
51 RWStepGeom_RWBSplineSurfaceWithKnots::RWStepGeom_RWBSplineSurfaceWithKnots () {}
53 void RWStepGeom_RWBSplineSurfaceWithKnots::ReadStep
54 (const Handle(StepData_StepReaderData)& data,
55 const Standard_Integer num,
56 Handle(Interface_Check)& ach,
57 const Handle(StepGeom_BSplineSurfaceWithKnots)& ent) const
61 // --- Number of Parameter Control ---
63 if (!data->CheckNbParams(num,13,ach,"b_spline_surface_with_knots")) return;
65 // --- inherited field : name ---
67 Handle(TCollection_HAsciiString) aName;
68 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
69 data->ReadString (num,1,"name",ach,aName);
71 // --- inherited field : uDegree ---
73 Standard_Integer aUDegree;
74 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
75 data->ReadInteger (num,2,"u_degree",ach,aUDegree);
77 // --- inherited field : vDegree ---
79 Standard_Integer aVDegree;
80 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
81 data->ReadInteger (num,3,"v_degree",ach,aVDegree);
83 // --- inherited field : controlPointsList ---
85 Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
86 Handle(StepGeom_CartesianPoint) anent4;
87 Standard_Integer nsub4;
88 if (data->ReadSubList (num,4,"control_points_list",ach,nsub4)) {
89 Standard_Integer nbi4 = data->NbParams(nsub4);
90 Standard_Integer nbj4 = data->NbParams(data->ParamNumber(nsub4,1));
91 aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi4, 1, nbj4);
92 for (Standard_Integer i4 = 1; i4 <= nbi4; i4 ++) {
93 Standard_Integer nsi4;
94 if (data->ReadSubList (nsub4,i4,"sub-part(control_points_list)",ach,nsi4)) {
95 for (Standard_Integer j4 =1; j4 <= nbj4; j4 ++) {
96 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
97 if (data->ReadEntity (nsi4, j4,"cartesian_point", ach,
98 STANDARD_TYPE(StepGeom_CartesianPoint), anent4))
99 aControlPointsList->SetValue(i4, j4, anent4);
105 // --- inherited field : surfaceForm ---
107 StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
108 if (data->ParamType(num,5) == Interface_ParamEnum) {
109 Standard_CString text = data->ParamCValue(num,5);
110 if (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
111 else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
112 else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
113 else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
114 else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
115 else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
116 else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
117 else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
118 else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
119 else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
120 else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
121 else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
123 else ach->AddFail("Parameter #5 (surface_form) is not an enumeration");
125 // --- inherited field : uClosed ---
127 StepData_Logical aUClosed;
128 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
129 data->ReadLogical (num,6,"u_closed",ach,aUClosed);
131 // --- inherited field : vClosed ---
133 StepData_Logical aVClosed;
134 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
135 data->ReadLogical (num,7,"v_closed",ach,aVClosed);
137 // --- inherited field : selfIntersect ---
139 StepData_Logical aSelfIntersect;
140 //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
141 data->ReadLogical (num,8,"self_intersect",ach,aSelfIntersect);
143 // --- own field : uMultiplicities ---
145 Handle(TColStd_HArray1OfInteger) aUMultiplicities;
146 Standard_Integer aUMultiplicitiesItem;
147 Standard_Integer nsub9;
148 if (data->ReadSubList (num,9,"u_multiplicities",ach,nsub9)) {
149 Standard_Integer nb9 = data->NbParams(nsub9);
150 aUMultiplicities = new TColStd_HArray1OfInteger (1, nb9);
151 for (Standard_Integer i9 = 1; i9 <= nb9; i9 ++) {
152 //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
153 if (data->ReadInteger (nsub9,i9,"u_multiplicities",ach,aUMultiplicitiesItem))
154 aUMultiplicities->SetValue(i9,aUMultiplicitiesItem);
158 // --- own field : vMultiplicities ---
160 Handle(TColStd_HArray1OfInteger) aVMultiplicities;
161 Standard_Integer aVMultiplicitiesItem;
162 Standard_Integer nsub10;
163 if (data->ReadSubList (num,10,"v_multiplicities",ach,nsub10)) {
164 Standard_Integer nb10 = data->NbParams(nsub10);
165 aVMultiplicities = new TColStd_HArray1OfInteger (1, nb10);
166 for (Standard_Integer i10 = 1; i10 <= nb10; i10 ++) {
167 //szv#4:S4163:12Mar99 `Standard_Boolean stat10 =` not needed
168 if (data->ReadInteger (nsub10,i10,"v_multiplicities",ach,aVMultiplicitiesItem))
169 aVMultiplicities->SetValue(i10,aVMultiplicitiesItem);
173 // --- own field : uKnots ---
175 Handle(TColStd_HArray1OfReal) aUKnots;
176 Standard_Real aUKnotsItem;
177 Standard_Integer nsub11;
178 if (data->ReadSubList (num,11,"u_knots",ach,nsub11)) {
179 Standard_Integer nb11 = data->NbParams(nsub11);
180 aUKnots = new TColStd_HArray1OfReal (1, nb11);
181 for (Standard_Integer i11 = 1; i11 <= nb11; i11 ++) {
182 //szv#4:S4163:12Mar99 `Standard_Boolean stat11 =` not needed
183 if (data->ReadReal (nsub11,i11,"u_knots",ach,aUKnotsItem))
184 aUKnots->SetValue(i11,aUKnotsItem);
188 // --- own field : vKnots ---
190 Handle(TColStd_HArray1OfReal) aVKnots;
191 Standard_Real aVKnotsItem;
192 Standard_Integer nsub12;
193 if (data->ReadSubList (num,12,"v_knots",ach,nsub12)) {
194 Standard_Integer nb12 = data->NbParams(nsub12);
195 aVKnots = new TColStd_HArray1OfReal (1, nb12);
196 for (Standard_Integer i12 = 1; i12 <= nb12; i12 ++) {
197 //szv#4:S4163:12Mar99 `Standard_Boolean stat12 =` not needed
198 if (data->ReadReal (nsub12,i12,"v_knots",ach,aVKnotsItem))
199 aVKnots->SetValue(i12,aVKnotsItem);
203 // --- own field : knotSpec ---
205 StepGeom_KnotType aKnotSpec = StepGeom_ktUniformKnots;
206 if (data->ParamType(num,13) == Interface_ParamEnum) {
207 Standard_CString text = data->ParamCValue(num,13);
208 if (ktUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktUniformKnots;
209 else if (ktQuasiUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktQuasiUniformKnots;
210 else if (ktPiecewiseBezierKnots.IsEqual(text)) aKnotSpec = StepGeom_ktPiecewiseBezierKnots;
211 else if (ktUnspecified.IsEqual(text)) aKnotSpec = StepGeom_ktUnspecified;
212 else ach->AddFail("Enumeration knot_type has not an allowed value");
214 else ach->AddFail("Parameter #13 (knot_spec) is not an enumeration");
216 //--- Initialisation of the read entity ---
219 ent->Init(aName, aUDegree, aVDegree, aControlPointsList, aSurfaceForm, aUClosed, aVClosed, aSelfIntersect, aUMultiplicities, aVMultiplicities, aUKnots, aVKnots, aKnotSpec);
223 void RWStepGeom_RWBSplineSurfaceWithKnots::WriteStep
224 (StepData_StepWriter& SW,
225 const Handle(StepGeom_BSplineSurfaceWithKnots)& ent) const
228 // --- inherited field name ---
230 SW.Send(ent->Name());
232 // --- inherited field uDegree ---
234 SW.Send(ent->UDegree());
236 // --- inherited field vDegree ---
238 SW.Send(ent->VDegree());
240 // --- inherited field controlPointsList ---
243 for (Standard_Integer i4 = 1; i4 <= ent->NbControlPointsListI(); i4 ++) {
244 SW.NewLine(Standard_False);
246 for (Standard_Integer j4 = 1; j4 <= ent->NbControlPointsListJ(); j4 ++) {
247 SW.Send(ent->ControlPointsListValue(i4,j4));
248 SW.JoinLast(Standard_False);
254 // --- inherited field surfaceForm ---
256 switch(ent->SurfaceForm()) {
257 case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
258 case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
259 case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
260 case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
261 case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
262 case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
263 case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
264 case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
265 case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
266 case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
267 case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
270 // --- inherited field uClosed ---
272 SW.SendLogical(ent->UClosed());
274 // --- inherited field vClosed ---
276 SW.SendLogical(ent->VClosed());
278 // --- inherited field selfIntersect ---
280 SW.SendLogical(ent->SelfIntersect());
282 // --- own field : uMultiplicities ---
285 for (Standard_Integer i9 = 1; i9 <= ent->NbUMultiplicities(); i9 ++) {
286 SW.Send(ent->UMultiplicitiesValue(i9));
290 // --- own field : vMultiplicities ---
293 for (Standard_Integer i10 = 1; i10 <= ent->NbVMultiplicities(); i10 ++) {
294 SW.Send(ent->VMultiplicitiesValue(i10));
298 // --- own field : uKnots ---
301 for (Standard_Integer i11 = 1; i11 <= ent->NbUKnots(); i11 ++) {
302 SW.Send(ent->UKnotsValue(i11));
306 // --- own field : vKnots ---
309 for (Standard_Integer i12 = 1; i12 <= ent->NbVKnots(); i12 ++) {
310 SW.Send(ent->VKnotsValue(i12));
314 // --- own field : knotSpec ---
316 switch(ent->KnotSpec()) {
317 case StepGeom_ktUniformKnots : SW.SendEnum (ktUniformKnots); break;
318 case StepGeom_ktQuasiUniformKnots : SW.SendEnum (ktQuasiUniformKnots); break;
319 case StepGeom_ktPiecewiseBezierKnots : SW.SendEnum (ktPiecewiseBezierKnots); break;
320 case StepGeom_ktUnspecified : SW.SendEnum (ktUnspecified); break;
325 void RWStepGeom_RWBSplineSurfaceWithKnots::Share(const Handle(StepGeom_BSplineSurfaceWithKnots)& ent, Interface_EntityIterator& iter) const
328 Standard_Integer nbiElem1 = ent->NbControlPointsListI();
329 Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
330 for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
331 for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
332 iter.GetOneItem(ent->ControlPointsListValue(is1,js1));
340 void RWStepGeom_RWBSplineSurfaceWithKnots::Check
341 (const Handle(StepGeom_BSplineSurfaceWithKnots)& ent,
342 const Interface_ShareTool& ,
343 Handle(Interface_Check)& ach) const
345 Standard_Integer nbCPLU = ent->NbControlPointsListI();
346 Standard_Integer nbCPLV = ent->NbControlPointsListJ();
347 Standard_Integer dgBSSU = ent->UDegree();
348 Standard_Integer dgBSSV = ent->VDegree();
349 Standard_Integer nbMulU = ent->NbUMultiplicities();
350 Standard_Integer nbMulV = ent->NbVMultiplicities();
351 Standard_Integer nbKnoU = ent->NbUKnots();
352 Standard_Integer nbKnoV = ent->NbVKnots();
353 Standard_Integer sumMulU = 0;
354 Standard_Integer sumMulV = 0;
356 // std::cout << "BSplineSurfaceWithKnots: nbMulU=" << nbMulU << " nbKnoU= " <<
357 // nbKnoU << " nbCPLU= " << nbCPLU << " degreeU= " << dgBSSU << std::endl;
358 // std::cout << " nbMulV=" << nbMulV << " nbKnoV= " <<
359 // nbKnoV << " nbCPLV= " << nbCPLV << " degreeV= " << dgBSSV << std::endl;
360 if(nbMulU != nbKnoU) {
361 ach->AddFail("ERROR: No.of KnotMultiplicities not equal No.of Knots in U");
363 if(nbMulV != nbKnoV) {
364 ach->AddFail("ERROR: No.of KnotMultiplicities not equal No.of Knots in V");
367 // check in U direction
369 for(i=1; i<=nbMulU-1; i++) {
370 sumMulU = sumMulU + ent->UMultiplicitiesValue(i);
372 Standard_Integer sumNonPU = nbCPLU + dgBSSU + 1;
373 Standard_Integer mult1U = ent->UMultiplicitiesValue(1);
374 Standard_Integer multNU = ent->UMultiplicitiesValue(nbMulU);
375 // std::cout << "BSplineSurfaceWithKnots: mult1U=" << mult1U << " multNU= " <<
376 // multNU << " sumMulU= " << sumMulU << std::endl;
377 if((sumMulU + multNU) == sumNonPU) {
379 else if((sumMulU == nbCPLU) && (mult1U == multNU)) {
382 ach->AddFail("ERROR: wrong number of Knot Multiplicities in U");
384 for(i=2; i<=nbKnoU; i++) {
385 Standard_Real distKn = ent->UKnotsValue(i-1) - ent->UKnotsValue(i);
386 if(Abs(distKn) <= RealEpsilon())
387 ach->AddWarning("WARNING: Surface contains identical KnotsValues in U");
388 else if(distKn > RealEpsilon())
389 ach->AddFail("ERROR: Surface contains descending KnotsValues in U");
392 // check in V direction
394 for(i=1; i<=nbMulV-1; i++) {
395 sumMulV = sumMulV + ent->VMultiplicitiesValue(i);
397 Standard_Integer sumNonPV = nbCPLV + dgBSSV + 1;
398 Standard_Integer mult1V = ent->VMultiplicitiesValue(1);
399 Standard_Integer multNV = ent->VMultiplicitiesValue(nbMulV);
400 // std::cout << " : mult1V=" << mult1V << " multNV= " <<
401 // multNV << " sumMulV= " << sumMulV << std::endl;
402 if((sumMulV + multNV) == sumNonPV) {
404 else if((sumMulV == nbCPLV) && (mult1V == multNV)) {
407 ach->AddFail("ERROR: wrong number of Knot Multiplicities in V");
409 for(i=2; i<=nbKnoV; i++) {
410 Standard_Real distKn = ent->VKnotsValue(i-1) - ent->VKnotsValue(i);
411 if(Abs(distKn) <= RealEpsilon())
412 ach->AddWarning("WARNING: Surface contains identical KnotsValues in V");
413 else if(distKn > RealEpsilon())
414 ach->AddFail("ERROR: Surface contains descending KnotsValues in V");