0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / RWStepGeom / RWStepGeom_RWRationalBSplineSurface.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_RWRationalBSplineSurface.hxx>
19 #include <StepData_Logical.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <StepGeom_BSplineSurfaceForm.hxx>
23 #include <StepGeom_CartesianPoint.hxx>
24 #include <StepGeom_HArray2OfCartesianPoint.hxx>
25 #include <StepGeom_RationalBSplineSurface.hxx>
26 #include <TColStd_HArray2OfReal.hxx>
27
28 // --- Enum : BSplineSurfaceForm ---
29 static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
30 static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
31 static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
32 static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
33 static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
34 static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
35 static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
36 static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
37 static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
38 static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
39 static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
40
41 RWStepGeom_RWRationalBSplineSurface::RWStepGeom_RWRationalBSplineSurface () {}
42
43 void RWStepGeom_RWRationalBSplineSurface::ReadStep
44         (const Handle(StepData_StepReaderData)& data,
45          const Standard_Integer num,
46          Handle(Interface_Check)& ach,
47          const Handle(StepGeom_RationalBSplineSurface)& ent) const
48 {
49
50
51         // --- Number of Parameter Control ---
52
53         if (!data->CheckNbParams(num,9,ach,"rational_b_spline_surface")) return;
54
55         // --- inherited field : name ---
56
57         Handle(TCollection_HAsciiString) aName;
58         //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
59         data->ReadString (num,1,"name",ach,aName);
60
61         // --- inherited field : uDegree ---
62
63         Standard_Integer aUDegree;
64         //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
65         data->ReadInteger (num,2,"u_degree",ach,aUDegree);
66
67         // --- inherited field : vDegree ---
68
69         Standard_Integer aVDegree;
70         //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
71         data->ReadInteger (num,3,"v_degree",ach,aVDegree);
72
73         // --- inherited field : controlPointsList ---
74
75         Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
76         Handle(StepGeom_CartesianPoint) anent4;
77         Standard_Integer nsub4;
78         if (data->ReadSubList (num,4,"control_points_list",ach,nsub4)) {
79           Standard_Integer nbi4 = data->NbParams(nsub4);
80           Standard_Integer nbj4 = data->NbParams(data->ParamNumber(nsub4,1));
81           aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi4, 1, nbj4);
82           for (Standard_Integer i4 = 1; i4 <= nbi4; i4 ++) {
83             Standard_Integer nsi4;
84             if (data->ReadSubList (nsub4,i4,"sub-part(control_points_list)",ach,nsi4)) {
85               for (Standard_Integer j4 =1; j4 <= nbj4; j4 ++) {
86                 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
87                 if (data->ReadEntity (nsi4, j4,"cartesian_point", ach,
88                                       STANDARD_TYPE(StepGeom_CartesianPoint), anent4))
89                   aControlPointsList->SetValue(i4, j4, anent4);
90               }
91             }
92           }
93         }
94
95         // --- inherited field : surfaceForm ---
96
97         StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
98         if (data->ParamType(num,5) == Interface_ParamEnum) {
99           Standard_CString text = data->ParamCValue(num,5);
100           if      (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
101           else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
102           else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
103           else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
104           else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
105           else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
106           else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
107           else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
108           else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
109           else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
110           else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
111           else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
112         }
113         else ach->AddFail("Parameter #5 (surface_form) is not an enumeration");
114
115         // --- inherited field : uClosed ---
116
117         StepData_Logical aUClosed;
118         //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
119         data->ReadLogical (num,6,"u_closed",ach,aUClosed);
120
121         // --- inherited field : vClosed ---
122
123         StepData_Logical aVClosed;
124         //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
125         data->ReadLogical (num,7,"v_closed",ach,aVClosed);
126
127         // --- inherited field : selfIntersect ---
128
129         StepData_Logical aSelfIntersect;
130         //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
131         data->ReadLogical (num,8,"self_intersect",ach,aSelfIntersect);
132
133         // --- own field : weightsData ---
134
135         Handle(TColStd_HArray2OfReal) aWeightsData;
136           Standard_Real aWeightsDataItem;
137         Standard_Integer nsub9;
138         if (data->ReadSubList (num,9,"weights_data",ach,nsub9)) {
139           Standard_Integer nbi9 = data->NbParams(nsub9);
140           Standard_Integer nbj9 = data->NbParams(data->ParamNumber(nsub9,1));
141           aWeightsData = new TColStd_HArray2OfReal (1,nbi9,1,nbj9);
142           for (Standard_Integer i9 = 1; i9 <= nbi9; i9 ++) {
143             Standard_Integer nsi9;
144             if (data->ReadSubList (nsub9,i9,"sub-part(weights_data)",ach,nsi9)) {
145               for (Standard_Integer j9 =1; j9 <= nbj9; j9 ++) {
146                 //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
147                 if (data->ReadReal (nsi9,j9,"weights_data",ach,aWeightsDataItem))
148                   aWeightsData->SetValue(i9,j9,aWeightsDataItem);
149               }
150             }
151           }
152         }
153
154         //--- Initialisation of the read entity ---
155
156
157         ent->Init(aName, aUDegree, aVDegree, aControlPointsList, aSurfaceForm, aUClosed, aVClosed, aSelfIntersect, aWeightsData);
158 }
159
160
161 void RWStepGeom_RWRationalBSplineSurface::WriteStep
162         (StepData_StepWriter& SW,
163          const Handle(StepGeom_RationalBSplineSurface)& ent) const
164 {
165
166         // --- inherited field name ---
167
168         SW.Send(ent->Name());
169
170         // --- inherited field uDegree ---
171
172         SW.Send(ent->UDegree());
173
174         // --- inherited field vDegree ---
175
176         SW.Send(ent->VDegree());
177
178         // --- inherited field controlPointsList ---
179
180         SW.OpenSub();
181         for (Standard_Integer i4 = 1;  i4 <= ent->NbControlPointsListI(); i4 ++) {
182           SW.NewLine(Standard_False);
183           SW.OpenSub();
184           for (Standard_Integer j4 = 1;  j4 <= ent->NbControlPointsListJ(); j4 ++) {
185             SW.Send(ent->ControlPointsListValue(i4,j4));
186             SW.JoinLast(Standard_False);
187           }
188           SW.CloseSub();
189         }
190         SW.CloseSub();
191
192         // --- inherited field surfaceForm ---
193
194         switch(ent->SurfaceForm()) {
195           case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
196           case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
197           case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
198           case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
199           case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
200           case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
201           case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
202           case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
203           case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
204           case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
205           case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
206         }
207
208         // --- inherited field uClosed ---
209
210         SW.SendLogical(ent->UClosed());
211
212         // --- inherited field vClosed ---
213
214         SW.SendLogical(ent->VClosed());
215
216         // --- inherited field selfIntersect ---
217
218         SW.SendLogical(ent->SelfIntersect());
219
220         // --- own field : weightsData ---
221
222         SW.OpenSub();
223         for (Standard_Integer i9 = 1;  i9 <= ent->NbWeightsDataI(); i9 ++) {
224           SW.NewLine(Standard_False);
225           SW.OpenSub();
226           for (Standard_Integer j9 = 1;  j9 <= ent->NbWeightsDataJ(); j9 ++) {
227             SW.Send(ent->WeightsDataValue(i9,j9));
228             SW.JoinLast(Standard_False);
229           }
230           SW.CloseSub();
231         }
232         SW.CloseSub();
233 }
234
235
236 void RWStepGeom_RWRationalBSplineSurface::Share(const Handle(StepGeom_RationalBSplineSurface)& ent, Interface_EntityIterator& iter) const
237 {
238
239         Standard_Integer nbiElem1 = ent->NbControlPointsListI();
240         Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
241         for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
242           for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
243             iter.GetOneItem(ent->ControlPointsListValue(is1,js1));
244           }
245         }
246
247 }
248
249
250
251 void RWStepGeom_RWRationalBSplineSurface::Check
252   (const Handle(StepGeom_RationalBSplineSurface)& ent,
253    const Interface_ShareTool& ,
254    Handle(Interface_Check)& ach) const
255 {
256   Standard_Integer nbWgtU = ent->NbWeightsDataI();
257   Standard_Integer nbWgtV = ent->NbWeightsDataJ();
258   Standard_Integer nbCPLU = ent->NbControlPointsListI();
259   Standard_Integer nbCPLV = ent->NbControlPointsListJ();
260   Standard_Integer i;
261   Standard_Integer j;
262 //  std::cout << "RationalBSplineCurve: nbWgtU=" << nbWgtU << " nbCPLU: " << 
263 //    nbCPLU << std::endl;
264 //  std::cout << "                      nbWgtV=" << nbWgtV << " nbCPLV: " << 
265 //    nbCPLV << std::endl;
266   if(nbWgtU != nbCPLU) {
267     ach->AddFail("ERROR: No.of ControlPoints not equal No.of Weights in U");
268   }
269   if(nbWgtV != nbCPLV) {
270     ach->AddFail("ERROR: No.of ControlPoints not equal No.of Weights in V");
271   }
272   for(i=1; i<=nbWgtU; i++) {
273     for(j=1; j<=nbWgtV; j++) {
274       if(ent->WeightsDataValue(i,j) < RealEpsilon()) {
275         ach->AddFail("ERROR: WeightsData Value not greater than 0.0");
276       }
277     }
278   }
279 }