0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / RWStepGeom / RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
7fd59977 13
7fd59977 14
42cf5bc1 15#include <Interface_Check.hxx>
7fd59977 16#include <Interface_EntityIterator.hxx>
42cf5bc1 17#include <RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface.hxx>
18#include <StepData_Logical.hxx>
19#include <StepData_StepReaderData.hxx>
20#include <StepData_StepWriter.hxx>
21#include <StepGeom_BSplineSurfaceForm.hxx>
22#include <StepGeom_CartesianPoint.hxx>
23#include <StepGeom_HArray2OfCartesianPoint.hxx>
24#include <StepGeom_RationalBSplineSurface.hxx>
25#include <StepGeom_UniformSurface.hxx>
7fd59977 26#include <StepGeom_UniformSurfaceAndRationalBSplineSurface.hxx>
42cf5bc1 27#include <TColStd_HArray2OfReal.hxx>
7fd59977 28
b311480e 29// --- Enum : BSplineSurfaceForm ---
7fd59977 30static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
31static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
32static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
33static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
34static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
35static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
36static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
37static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
38static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
39static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
40static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
41
42RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface::RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface () {}
43
44void RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface::ReadStep
45 (const Handle(StepData_StepReaderData)& data,
46 const Standard_Integer num0,
47 Handle(Interface_Check)& ach,
48 const Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface)& ent) const
49{
50
51 Standard_Integer num = num0;
52
53
54 // --- Instance of plex componant BoundedSurface ---
55
56 if (!data->CheckNbParams(num,0,ach,"bounded_surface")) return;
57
58 num = data->NextForComplex(num);
59
60 // --- Instance of common supertype BSplineSurface ---
61
62 if (!data->CheckNbParams(num,7,ach,"b_spline_surface")) return;
63 // --- field : uDegree ---
64
65
66 Standard_Integer aUDegree;
67 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
68 data->ReadInteger (num,1,"u_degree",ach,aUDegree);
69 // --- field : vDegree ---
70
71
72 Standard_Integer aVDegree;
73 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
74 data->ReadInteger (num,2,"v_degree",ach,aVDegree);
75 // --- field : controlPointsList ---
76
77
78 Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
79 Handle(StepGeom_CartesianPoint) anent3;
80 Standard_Integer nsub3;
81 if (data->ReadSubList (num,3,"control_points_list",ach,nsub3)) {
82 Standard_Integer nbi3 = data->NbParams(nsub3);
83 Standard_Integer nbj3 = data->NbParams(data->ParamNumber(nsub3,1));
84 aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi3, 1, nbj3);
85 for (Standard_Integer i3 = 1; i3 <= nbi3; i3 ++) {
86 Standard_Integer nsi3;
87 if (data->ReadSubList (nsub3,i3,"sub-part(control_points_list)",ach,nsi3)) {
88 for (Standard_Integer j3 =1; j3 <= nbj3; j3 ++) {
89 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
90 if (data->ReadEntity (nsi3, j3,"cartesian_point", ach,
91 STANDARD_TYPE(StepGeom_CartesianPoint), anent3))
92 aControlPointsList->SetValue(i3, j3, anent3);
93 }
94 }
95 }
96 }
97
98 // --- field : surfaceForm ---
99
100
101 StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
102 if (data->ParamType(num,4) == Interface_ParamEnum) {
103 Standard_CString text = data->ParamCValue(num,4);
104 if (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
105 else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
106 else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
107 else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
108 else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
109 else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
110 else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
111 else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
112 else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
113 else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
114 else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
115 else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
116 }
117 else ach->AddFail("Parameter #4 (surface_form) is not an enumeration");
118 // --- field : uClosed ---
119
120
121 StepData_Logical aUClosed;
122 //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
123 data->ReadLogical (num,5,"u_closed",ach,aUClosed);
124 // --- field : vClosed ---
125
126
127 StepData_Logical aVClosed;
128 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
129 data->ReadLogical (num,6,"v_closed",ach,aVClosed);
130 // --- field : selfIntersect ---
131
132
133 StepData_Logical aSelfIntersect;
134 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
135 data->ReadLogical (num,7,"self_intersect",ach,aSelfIntersect);
136
137 num = data->NextForComplex(num);
138
139 // --- Instance of plex componant GeometricRepresentationItem ---
140
141 if (!data->CheckNbParams(num,0,ach,"geometric_representation_item")) return;
142
143 num = data->NextForComplex(num);
144
145 // --- Instance of plex componant RationalBSplineSurface ---
146
147 if (!data->CheckNbParams(num,1,ach,"rational_b_spline_surface")) return;
148
149 // --- field : weightsData ---
150
151 Handle(TColStd_HArray2OfReal) aWeightsData;
152 Standard_Real aWeightsDataItem;
153 Standard_Integer nsub8;
154 if (data->ReadSubList (num,1,"weights_data",ach,nsub8)) {
155 Standard_Integer nbi8 = data->NbParams(nsub8);
156 Standard_Integer nbj8 = data->NbParams(data->ParamNumber(nsub8,1));
157 aWeightsData = new TColStd_HArray2OfReal (1,nbi8,1,nbj8);
158 for (Standard_Integer i8 = 1; i8 <= nbi8; i8 ++) {
159 Standard_Integer nsi8;
160 if (data->ReadSubList (nsub8,i8,"sub-part(weights_data)",ach,nsi8)) {
161 for (Standard_Integer j8 =1; j8 <= nbj8; j8 ++) {
162 //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
163 if (data->ReadReal (nsi8,j8,"weights_data",ach,aWeightsDataItem))
164 aWeightsData->SetValue(i8,j8,aWeightsDataItem);
165 }
166 }
167 }
168 }
169
170 num = data->NextForComplex(num);
171
172 // --- Instance of plex componant RepresentationItem ---
173
174 if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
175
176 // --- field : name ---
177
178 Handle(TCollection_HAsciiString) aName;
179 //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
180 data->ReadString (num,1,"name",ach,aName);
181
182 num = data->NextForComplex(num);
183
184 // --- Instance of plex componant Surface ---
185
186 if (!data->CheckNbParams(num,0,ach,"surface")) return;
187
188 num = data->NextForComplex(num);
189
190 // --- Instance of plex componant UniformSurface ---
191
192 if (!data->CheckNbParams(num,0,ach,"uniform_surface")) return;
193
194 //--- Initialisation of the red entity ---
195
196 ent->Init(aName,aUDegree,aVDegree,aControlPointsList,aSurfaceForm,aUClosed,aVClosed,aSelfIntersect,aWeightsData);
197}
198
199
200void RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface::WriteStep
201 (StepData_StepWriter& SW,
202 const Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface)& ent) const
203{
204
205 // --- Instance of plex componant BoundedSurface ---
206
207 SW.StartEntity("BOUNDED_SURFACE");
208
209 // --- Instance of common supertype BSplineSurface ---
210
211 SW.StartEntity("B_SPLINE_SURFACE");
212 // --- field : uDegree ---
213
214 SW.Send(ent->UDegree());
215 // --- field : vDegree ---
216
217 SW.Send(ent->VDegree());
218 // --- field : controlPointsList ---
219
220 SW.OpenSub();
221 for (Standard_Integer i3 = 1; i3 <= ent->NbControlPointsListI(); i3 ++) {
222 SW.NewLine(Standard_False);
223 SW.OpenSub();
224 for (Standard_Integer j3 = 1; j3 <= ent->NbControlPointsListJ(); j3 ++) {
225 SW.Send(ent->ControlPointsListValue(i3,j3));
226 SW.JoinLast(Standard_False);
227 }
228 SW.CloseSub();
229 }
230 SW.CloseSub();
231 // --- field : surfaceForm ---
232
233 switch(ent->SurfaceForm()) {
234 case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
235 case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
236 case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
237 case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
238 case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
239 case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
240 case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
241 case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
242 case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
243 case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
244 case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
245 }
246 // --- field : uClosed ---
247
248 SW.SendLogical(ent->UClosed());
249 // --- field : vClosed ---
250
251 SW.SendLogical(ent->VClosed());
252 // --- field : selfIntersect ---
253
254 SW.SendLogical(ent->SelfIntersect());
255
256 // --- Instance of plex componant GeometricRepresentationItem ---
257
258 SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
259
260 // --- Instance of plex componant RationalBSplineSurface ---
261
262 SW.StartEntity("RATIONAL_B_SPLINE_SURFACE");
263 // --- field : weightsData ---
264
265 SW.OpenSub();
266 for (Standard_Integer i8 = 1; i8 <= ent->NbWeightsDataI(); i8 ++) {
267 SW.NewLine(Standard_False);
268 SW.OpenSub();
269 for (Standard_Integer j8 = 1; j8 <= ent->NbWeightsDataJ(); j8 ++) {
270 SW.Send(ent->WeightsDataValue(i8,j8));
271 SW.JoinLast(Standard_False);
272 }
273 SW.CloseSub();
274 }
275 SW.CloseSub();
276
277 // --- Instance of plex componant RepresentationItem ---
278
279 SW.StartEntity("REPRESENTATION_ITEM");
280 // --- field : name ---
281
282 SW.Send(ent->Name());
283
284 // --- Instance of plex componant Surface ---
285
286 SW.StartEntity("SURFACE");
287
288 // --- Instance of plex componant UniformSurface ---
289
290 SW.StartEntity("UNIFORM_SURFACE");
291}
292
293
294void RWStepGeom_RWUniformSurfaceAndRationalBSplineSurface::Share(const Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface)& ent, Interface_EntityIterator& iter) const
295{
296
297 Standard_Integer nbiElem1 = ent->NbControlPointsListI();
298 Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
299 for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
300 for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
301 iter.GetOneItem(ent->ControlPointsListValue(is1,js1));
302 }
303 }
304
305}
306