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_RWRationalBSplineCurve.hxx>
19 #include <StepData_Logical.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <StepGeom_BSplineCurveForm.hxx>
23 #include <StepGeom_CartesianPoint.hxx>
24 #include <StepGeom_HArray1OfCartesianPoint.hxx>
25 #include <StepGeom_RationalBSplineCurve.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
28 // --- Enum : BSplineCurveForm ---
29 static TCollection_AsciiString bscfEllipticArc(".ELLIPTIC_ARC.");
30 static TCollection_AsciiString bscfPolylineForm(".POLYLINE_FORM.");
31 static TCollection_AsciiString bscfParabolicArc(".PARABOLIC_ARC.");
32 static TCollection_AsciiString bscfCircularArc(".CIRCULAR_ARC.");
33 static TCollection_AsciiString bscfUnspecified(".UNSPECIFIED.");
34 static TCollection_AsciiString bscfHyperbolicArc(".HYPERBOLIC_ARC.");
36 RWStepGeom_RWRationalBSplineCurve::RWStepGeom_RWRationalBSplineCurve () {}
38 void RWStepGeom_RWRationalBSplineCurve::ReadStep
39 (const Handle(StepData_StepReaderData)& data,
40 const Standard_Integer num,
41 Handle(Interface_Check)& ach,
42 const Handle(StepGeom_RationalBSplineCurve)& ent) const
46 // --- Number of Parameter Control ---
48 if (!data->CheckNbParams(num,7,ach,"rational_b_spline_curve")) return;
50 // --- inherited field : name ---
52 Handle(TCollection_HAsciiString) aName;
53 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
54 data->ReadString (num,1,"name",ach,aName);
56 // --- inherited field : degree ---
58 Standard_Integer aDegree;
59 //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
60 data->ReadInteger (num,2,"degree",ach,aDegree);
62 // --- inherited field : controlPointsList ---
64 Handle(StepGeom_HArray1OfCartesianPoint) aControlPointsList;
65 Handle(StepGeom_CartesianPoint) anent3;
66 Standard_Integer nsub3;
67 if (data->ReadSubList (num,3,"control_points_list",ach,nsub3)) {
68 Standard_Integer nb3 = data->NbParams(nsub3);
69 aControlPointsList = new StepGeom_HArray1OfCartesianPoint (1, nb3);
70 for (Standard_Integer i3 = 1; i3 <= nb3; i3 ++) {
71 //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
72 if (data->ReadEntity (nsub3, i3,"cartesian_point", ach,
73 STANDARD_TYPE(StepGeom_CartesianPoint), anent3))
74 aControlPointsList->SetValue(i3, anent3);
78 // --- inherited field : curveForm ---
80 StepGeom_BSplineCurveForm aCurveForm = StepGeom_bscfPolylineForm;
81 if (data->ParamType(num,4) == Interface_ParamEnum) {
82 Standard_CString text = data->ParamCValue(num,4);
83 if (bscfEllipticArc.IsEqual(text)) aCurveForm = StepGeom_bscfEllipticArc;
84 else if (bscfPolylineForm.IsEqual(text)) aCurveForm = StepGeom_bscfPolylineForm;
85 else if (bscfParabolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfParabolicArc;
86 else if (bscfCircularArc.IsEqual(text)) aCurveForm = StepGeom_bscfCircularArc;
87 else if (bscfUnspecified.IsEqual(text)) aCurveForm = StepGeom_bscfUnspecified;
88 else if (bscfHyperbolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfHyperbolicArc;
89 else ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
91 else ach->AddFail("Parameter #4 (curve_form) is not an enumeration");
93 // --- inherited field : closedCurve ---
95 StepData_Logical aClosedCurve;
96 //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
97 data->ReadLogical (num,5,"closed_curve",ach,aClosedCurve);
99 // --- inherited field : selfIntersect ---
101 StepData_Logical aSelfIntersect;
102 //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
103 data->ReadLogical (num,6,"self_intersect",ach,aSelfIntersect);
105 // --- own field : weightsData ---
107 Handle(TColStd_HArray1OfReal) aWeightsData;
108 Standard_Real aWeightsDataItem;
109 Standard_Integer nsub7;
110 if (data->ReadSubList (num,7,"weights_data",ach,nsub7)) {
111 Standard_Integer nb7 = data->NbParams(nsub7);
112 aWeightsData = new TColStd_HArray1OfReal (1, nb7);
113 for (Standard_Integer i7 = 1; i7 <= nb7; i7 ++) {
114 //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
115 if (data->ReadReal (nsub7,i7,"weights_data",ach,aWeightsDataItem))
116 aWeightsData->SetValue(i7,aWeightsDataItem);
120 //--- Initialisation of the read entity ---
123 ent->Init(aName, aDegree, aControlPointsList, aCurveForm, aClosedCurve, aSelfIntersect, aWeightsData);
127 void RWStepGeom_RWRationalBSplineCurve::WriteStep
128 (StepData_StepWriter& SW,
129 const Handle(StepGeom_RationalBSplineCurve)& ent) const
132 // --- inherited field name ---
134 SW.Send(ent->Name());
136 // --- inherited field degree ---
138 SW.Send(ent->Degree());
140 // --- inherited field controlPointsList ---
143 for (Standard_Integer i3 = 1; i3 <= ent->NbControlPointsList(); i3 ++) {
144 SW.Send(ent->ControlPointsListValue(i3));
148 // --- inherited field curveForm ---
150 switch(ent->CurveForm()) {
151 case StepGeom_bscfEllipticArc : SW.SendEnum (bscfEllipticArc); break;
152 case StepGeom_bscfPolylineForm : SW.SendEnum (bscfPolylineForm); break;
153 case StepGeom_bscfParabolicArc : SW.SendEnum (bscfParabolicArc); break;
154 case StepGeom_bscfCircularArc : SW.SendEnum (bscfCircularArc); break;
155 case StepGeom_bscfUnspecified : SW.SendEnum (bscfUnspecified); break;
156 case StepGeom_bscfHyperbolicArc : SW.SendEnum (bscfHyperbolicArc); break;
159 // --- inherited field closedCurve ---
161 SW.SendLogical(ent->ClosedCurve());
163 // --- inherited field selfIntersect ---
165 SW.SendLogical(ent->SelfIntersect());
167 // --- own field : weightsData ---
170 for (Standard_Integer i7 = 1; i7 <= ent->NbWeightsData(); i7 ++) {
171 SW.Send(ent->WeightsDataValue(i7));
177 void RWStepGeom_RWRationalBSplineCurve::Share(const Handle(StepGeom_RationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
180 Standard_Integer nbElem1 = ent->NbControlPointsList();
181 for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
182 iter.GetOneItem(ent->ControlPointsListValue(is1));
189 void RWStepGeom_RWRationalBSplineCurve::Check
190 (const Handle(StepGeom_RationalBSplineCurve)& ent,
191 const Interface_ShareTool& ,
192 Handle(Interface_Check)& ach) const
194 Standard_Integer nbWght = ent->NbWeightsData();
195 Standard_Integer nbCPL = ent->NbControlPointsList();
196 // std::cout << "RationalBSplineCurve: nbWght=" << nbWght << " nbCPL: " <<
197 // nbCPL << std::endl;
198 if(nbWght != nbCPL) {
199 ach->AddFail("ERROR: No.of ControlPoints not equal No.of Weights");
201 for(Standard_Integer i=1; i<=nbWght; i++) {
202 if(ent->WeightsDataValue(i) < RealEpsilon()) {
203 ach->AddFail("ERROR: WeightsData Value not greater than 0.0");