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_RWUniformCurveAndRationalBSplineCurve.hxx>
18 #include <StepData_Logical.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepGeom_BSplineCurveForm.hxx>
22 #include <StepGeom_CartesianPoint.hxx>
23 #include <StepGeom_HArray1OfCartesianPoint.hxx>
24 #include <StepGeom_RationalBSplineCurve.hxx>
25 #include <StepGeom_UniformCurve.hxx>
26 #include <StepGeom_UniformCurveAndRationalBSplineCurve.hxx>
27 #include <TColStd_HArray1OfReal.hxx>
29 // --- Enum : BSplineCurveForm ---
30 static TCollection_AsciiString bscfEllipticArc(".ELLIPTIC_ARC.");
31 static TCollection_AsciiString bscfPolylineForm(".POLYLINE_FORM.");
32 static TCollection_AsciiString bscfParabolicArc(".PARABOLIC_ARC.");
33 static TCollection_AsciiString bscfCircularArc(".CIRCULAR_ARC.");
34 static TCollection_AsciiString bscfUnspecified(".UNSPECIFIED.");
35 static TCollection_AsciiString bscfHyperbolicArc(".HYPERBOLIC_ARC.");
37 RWStepGeom_RWUniformCurveAndRationalBSplineCurve::RWStepGeom_RWUniformCurveAndRationalBSplineCurve () {}
39 void RWStepGeom_RWUniformCurveAndRationalBSplineCurve::ReadStep
40 (const Handle(StepData_StepReaderData)& data,
41 const Standard_Integer num0,
42 Handle(Interface_Check)& ach,
43 const Handle(StepGeom_UniformCurveAndRationalBSplineCurve)& ent) const
46 Standard_Integer num = num0;
49 // --- Instance of plex componant BoundedCurve ---
51 if (!data->CheckNbParams(num,0,ach,"bounded_curve")) return;
53 num = data->NextForComplex(num);
55 // --- Instance of common supertype BSplineCurve ---
57 if (!data->CheckNbParams(num,5,ach,"b_spline_curve")) return;
58 // --- field : degree ---
61 Standard_Integer aDegree;
62 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
63 data->ReadInteger (num,1,"degree",ach,aDegree);
64 // --- field : controlPointsList ---
67 Handle(StepGeom_HArray1OfCartesianPoint) aControlPointsList;
68 Handle(StepGeom_CartesianPoint) anent2;
69 Standard_Integer nsub2;
70 if (data->ReadSubList (num,2,"control_points_list",ach,nsub2)) {
71 Standard_Integer nb2 = data->NbParams(nsub2);
72 aControlPointsList = new StepGeom_HArray1OfCartesianPoint (1, nb2);
73 for (Standard_Integer i2 = 1; i2 <= nb2; i2 ++) {
74 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
75 if (data->ReadEntity (nsub2, i2,"cartesian_point", ach,
76 STANDARD_TYPE(StepGeom_CartesianPoint), anent2))
77 aControlPointsList->SetValue(i2, anent2);
81 // --- field : curveForm ---
84 StepGeom_BSplineCurveForm aCurveForm = StepGeom_bscfPolylineForm;
85 if (data->ParamType(num,3) == Interface_ParamEnum) {
86 Standard_CString text = data->ParamCValue(num,3);
87 if (bscfEllipticArc.IsEqual(text)) aCurveForm = StepGeom_bscfEllipticArc;
88 else if (bscfPolylineForm.IsEqual(text)) aCurveForm = StepGeom_bscfPolylineForm;
89 else if (bscfParabolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfParabolicArc;
90 else if (bscfCircularArc.IsEqual(text)) aCurveForm = StepGeom_bscfCircularArc;
91 else if (bscfUnspecified.IsEqual(text)) aCurveForm = StepGeom_bscfUnspecified;
92 else if (bscfHyperbolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfHyperbolicArc;
93 else ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
95 else ach->AddFail("Parameter #3 (curve_form) is not an enumeration");
96 // --- field : closedCurve ---
99 StepData_Logical aClosedCurve;
100 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
101 data->ReadLogical (num,4,"closed_curve",ach,aClosedCurve);
102 // --- field : selfIntersect ---
105 StepData_Logical aSelfIntersect;
106 //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
107 data->ReadLogical (num,5,"self_intersect",ach,aSelfIntersect);
109 num = data->NextForComplex(num);
111 // --- Instance of plex componant Curve ---
113 if (!data->CheckNbParams(num,0,ach,"curve")) return;
115 num = data->NextForComplex(num);
117 // --- Instance of plex componant GeometricRepresentationItem ---
119 if (!data->CheckNbParams(num,0,ach,"geometric_representation_item")) return;
121 num = data->NextForComplex(num);
123 // --- Instance of plex componant RationalBSplineCurve ---
125 if (!data->CheckNbParams(num,1,ach,"rational_b_spline_curve")) return;
127 // --- field : weightsData ---
129 Handle(TColStd_HArray1OfReal) aWeightsData;
130 Standard_Real aWeightsDataItem;
131 Standard_Integer nsub6;
132 if (data->ReadSubList (num,1,"weights_data",ach,nsub6)) {
133 Standard_Integer nb6 = data->NbParams(nsub6);
134 aWeightsData = new TColStd_HArray1OfReal (1, nb6);
135 for (Standard_Integer i6 = 1; i6 <= nb6; i6 ++) {
136 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
137 if (data->ReadReal (nsub6,i6,"weights_data",ach,aWeightsDataItem))
138 aWeightsData->SetValue(i6,aWeightsDataItem);
142 num = data->NextForComplex(num);
144 // --- Instance of plex componant RepresentationItem ---
146 if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
148 // --- field : name ---
150 Handle(TCollection_HAsciiString) aName;
151 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
152 data->ReadString (num,1,"name",ach,aName);
154 num = data->NextForComplex(num);
156 // --- Instance of plex componant UniformCurve ---
158 if (!data->CheckNbParams(num,0,ach,"uniform_curve")) return;
160 //--- Initialisation of the red entity ---
162 ent->Init(aName,aDegree,aControlPointsList,aCurveForm,aClosedCurve,aSelfIntersect,aWeightsData);
166 void RWStepGeom_RWUniformCurveAndRationalBSplineCurve::WriteStep
167 (StepData_StepWriter& SW,
168 const Handle(StepGeom_UniformCurveAndRationalBSplineCurve)& ent) const
171 // --- Instance of plex componant BoundedCurve ---
173 SW.StartEntity("BOUNDED_CURVE");
175 // --- Instance of common supertype BSplineCurve ---
177 SW.StartEntity("B_SPLINE_CURVE");
178 // --- field : degree ---
180 SW.Send(ent->Degree());
181 // --- field : controlPointsList ---
184 for (Standard_Integer i2 = 1; i2 <= ent->NbControlPointsList(); i2 ++) {
185 SW.Send(ent->ControlPointsListValue(i2));
188 // --- field : curveForm ---
190 switch(ent->CurveForm()) {
191 case StepGeom_bscfEllipticArc : SW.SendEnum (bscfEllipticArc); break;
192 case StepGeom_bscfPolylineForm : SW.SendEnum (bscfPolylineForm); break;
193 case StepGeom_bscfParabolicArc : SW.SendEnum (bscfParabolicArc); break;
194 case StepGeom_bscfCircularArc : SW.SendEnum (bscfCircularArc); break;
195 case StepGeom_bscfUnspecified : SW.SendEnum (bscfUnspecified); break;
196 case StepGeom_bscfHyperbolicArc : SW.SendEnum (bscfHyperbolicArc); break;
198 // --- field : closedCurve ---
200 SW.SendLogical(ent->ClosedCurve());
201 // --- field : selfIntersect ---
203 SW.SendLogical(ent->SelfIntersect());
205 // --- Instance of plex componant Curve ---
207 SW.StartEntity("CURVE");
209 // --- Instance of plex componant GeometricRepresentationItem ---
211 SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
213 // --- Instance of plex componant RationalBSplineCurve ---
215 SW.StartEntity("RATIONAL_B_SPLINE_CURVE");
216 // --- field : weightsData ---
219 for (Standard_Integer i6 = 1; i6 <= ent->NbWeightsData(); i6 ++) {
220 SW.Send(ent->WeightsDataValue(i6));
224 // --- Instance of plex componant RepresentationItem ---
226 SW.StartEntity("REPRESENTATION_ITEM");
227 // --- field : name ---
229 SW.Send(ent->Name());
231 // --- Instance of plex componant UniformCurve ---
233 SW.StartEntity("UNIFORM_CURVE");
237 void RWStepGeom_RWUniformCurveAndRationalBSplineCurve::Share(const Handle(StepGeom_UniformCurveAndRationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
240 Standard_Integer nbElem1 = ent->NbControlPointsList();
241 for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
242 iter.GetOneItem(ent->ControlPointsListValue(is1));