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 <RWStepGeom_RWBezierSurface.hxx>
18 #include <StepData_Logical.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepGeom_BezierSurface.hxx>
22 #include <StepGeom_BSplineSurfaceForm.hxx>
23 #include <StepGeom_CartesianPoint.hxx>
24 #include <StepGeom_HArray2OfCartesianPoint.hxx>
26 // --- Enum : BSplineSurfaceForm ---
27 static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
28 static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
29 static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
30 static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
31 static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
32 static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
33 static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
34 static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
35 static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
36 static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
37 static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
39 RWStepGeom_RWBezierSurface::RWStepGeom_RWBezierSurface () {}
41 void RWStepGeom_RWBezierSurface::ReadStep
42 (const Handle(StepData_StepReaderData)& data,
43 const Standard_Integer num,
44 Handle(Interface_Check)& ach,
45 const Handle(StepGeom_BezierSurface)& ent) const
49 // --- Number of Parameter Control ---
51 if (!data->CheckNbParams(num,8,ach,"bezier_surface")) return;
53 // --- inherited field : name ---
55 Handle(TCollection_HAsciiString) aName;
56 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
57 data->ReadString (num,1,"name",ach,aName);
59 // --- inherited field : uDegree ---
61 Standard_Integer aUDegree;
62 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
63 data->ReadInteger (num,2,"u_degree",ach,aUDegree);
65 // --- inherited field : vDegree ---
67 Standard_Integer aVDegree;
68 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
69 data->ReadInteger (num,3,"v_degree",ach,aVDegree);
71 // --- inherited field : controlPointsList ---
73 Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
74 Handle(StepGeom_CartesianPoint) anent4;
75 Standard_Integer nsub4;
76 if (data->ReadSubList (num,4,"control_points_list",ach,nsub4)) {
77 Standard_Integer nbi4 = data->NbParams(nsub4);
78 Standard_Integer nbj4 = data->NbParams(data->ParamNumber(nsub4,1));
79 aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi4, 1, nbj4);
80 for (Standard_Integer i4 = 1; i4 <= nbi4; i4 ++) {
81 Standard_Integer nsi4;
82 if (data->ReadSubList (nsub4,i4,"sub-part(control_points_list)",ach,nsi4)) {
83 for (Standard_Integer j4 =1; j4 <= nbj4; j4 ++) {
84 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
85 if (data->ReadEntity (nsi4, j4,"cartesian_point", ach,
86 STANDARD_TYPE(StepGeom_CartesianPoint), anent4))
87 aControlPointsList->SetValue(i4, j4, anent4);
93 // --- inherited field : surfaceForm ---
95 StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
96 if (data->ParamType(num,5) == Interface_ParamEnum) {
97 Standard_CString text = data->ParamCValue(num,5);
98 if (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
99 else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
100 else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
101 else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
102 else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
103 else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
104 else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
105 else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
106 else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
107 else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
108 else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
109 else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
111 else ach->AddFail("Parameter #5 (surface_form) is not an enumeration");
113 // --- inherited field : uClosed ---
115 StepData_Logical aUClosed;
116 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
117 data->ReadLogical (num,6,"u_closed",ach,aUClosed);
119 // --- inherited field : vClosed ---
121 StepData_Logical aVClosed;
122 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
123 data->ReadLogical (num,7,"v_closed",ach,aVClosed);
125 // --- inherited field : selfIntersect ---
127 StepData_Logical aSelfIntersect;
128 //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
129 data->ReadLogical (num,8,"self_intersect",ach,aSelfIntersect);
131 //--- Initialisation of the read entity ---
134 ent->Init(aName, aUDegree, aVDegree, aControlPointsList, aSurfaceForm, aUClosed, aVClosed, aSelfIntersect);
138 void RWStepGeom_RWBezierSurface::WriteStep
139 (StepData_StepWriter& SW,
140 const Handle(StepGeom_BezierSurface)& ent) const
143 // --- inherited field name ---
145 SW.Send(ent->Name());
147 // --- inherited field uDegree ---
149 SW.Send(ent->UDegree());
151 // --- inherited field vDegree ---
153 SW.Send(ent->VDegree());
155 // --- inherited field controlPointsList ---
158 for (Standard_Integer i4 = 1; i4 <= ent->NbControlPointsListI(); i4 ++) {
159 SW.NewLine(Standard_False);
161 for (Standard_Integer j4 = 1; j4 <= ent->NbControlPointsListJ(); j4 ++) {
162 SW.Send(ent->ControlPointsListValue(i4,j4));
163 SW.JoinLast(Standard_False);
169 // --- inherited field surfaceForm ---
171 switch(ent->SurfaceForm()) {
172 case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
173 case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
174 case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
175 case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
176 case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
177 case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
178 case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
179 case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
180 case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
181 case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
182 case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
185 // --- inherited field uClosed ---
187 SW.SendLogical(ent->UClosed());
189 // --- inherited field vClosed ---
191 SW.SendLogical(ent->VClosed());
193 // --- inherited field selfIntersect ---
195 SW.SendLogical(ent->SelfIntersect());
199 void RWStepGeom_RWBezierSurface::Share(const Handle(StepGeom_BezierSurface)& ent, Interface_EntityIterator& iter) const
202 Standard_Integer nbiElem1 = ent->NbControlPointsListI();
203 Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
204 for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
205 for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
206 iter.GetOneItem(ent->ControlPointsListValue(is1,js1));