Warnings on vc14 were eliminated
[occt.git] / src / RWStepGeom / RWStepGeom_RWRationalBSplineCurve.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_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>
27
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.");
35
36 RWStepGeom_RWRationalBSplineCurve::RWStepGeom_RWRationalBSplineCurve () {}
37
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
43 {
44
45
46         // --- Number of Parameter Control ---
47
48         if (!data->CheckNbParams(num,7,ach,"rational_b_spline_curve")) return;
49
50         // --- inherited field : name ---
51
52         Handle(TCollection_HAsciiString) aName;
53         //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
54         data->ReadString (num,1,"name",ach,aName);
55
56         // --- inherited field : degree ---
57
58         Standard_Integer aDegree;
59         //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
60         data->ReadInteger (num,2,"degree",ach,aDegree);
61
62         // --- inherited field : controlPointsList ---
63
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);
75           }
76         }
77
78         // --- inherited field : curveForm ---
79
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");
90         }
91         else ach->AddFail("Parameter #4 (curve_form) is not an enumeration");
92
93         // --- inherited field : closedCurve ---
94
95         StepData_Logical aClosedCurve;
96         //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
97         data->ReadLogical (num,5,"closed_curve",ach,aClosedCurve);
98
99         // --- inherited field : selfIntersect ---
100
101         StepData_Logical aSelfIntersect;
102         //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
103         data->ReadLogical (num,6,"self_intersect",ach,aSelfIntersect);
104
105         // --- own field : weightsData ---
106
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);
117           }
118         }
119
120         //--- Initialisation of the read entity ---
121
122
123         ent->Init(aName, aDegree, aControlPointsList, aCurveForm, aClosedCurve, aSelfIntersect, aWeightsData);
124 }
125
126
127 void RWStepGeom_RWRationalBSplineCurve::WriteStep
128         (StepData_StepWriter& SW,
129          const Handle(StepGeom_RationalBSplineCurve)& ent) const
130 {
131
132         // --- inherited field name ---
133
134         SW.Send(ent->Name());
135
136         // --- inherited field degree ---
137
138         SW.Send(ent->Degree());
139
140         // --- inherited field controlPointsList ---
141
142         SW.OpenSub();
143         for (Standard_Integer i3 = 1;  i3 <= ent->NbControlPointsList();  i3 ++) {
144           SW.Send(ent->ControlPointsListValue(i3));
145         }
146         SW.CloseSub();
147
148         // --- inherited field curveForm ---
149
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;
157         }
158
159         // --- inherited field closedCurve ---
160
161         SW.SendLogical(ent->ClosedCurve());
162
163         // --- inherited field selfIntersect ---
164
165         SW.SendLogical(ent->SelfIntersect());
166
167         // --- own field : weightsData ---
168
169         SW.OpenSub();
170         for (Standard_Integer i7 = 1;  i7 <= ent->NbWeightsData();  i7 ++) {
171           SW.Send(ent->WeightsDataValue(i7));
172         }
173         SW.CloseSub();
174 }
175
176
177 void RWStepGeom_RWRationalBSplineCurve::Share(const Handle(StepGeom_RationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
178 {
179
180         Standard_Integer nbElem1 = ent->NbControlPointsList();
181         for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
182           iter.GetOneItem(ent->ControlPointsListValue(is1));
183         }
184
185 }
186
187
188
189 void RWStepGeom_RWRationalBSplineCurve::Check
190   (const Handle(StepGeom_RationalBSplineCurve)& ent,
191    const Interface_ShareTool& ,
192    Handle(Interface_Check)& ach) const
193 {
194   Standard_Integer nbWght = ent->NbWeightsData();
195   Standard_Integer nbCPL  = ent->NbControlPointsList();
196 //  cout << "RationalBSplineCurve: nbWght=" << nbWght << " nbCPL: " << 
197 //    nbCPL << endl;
198   if(nbWght != nbCPL) {
199     ach->AddFail("ERROR: No.of ControlPoints not equal No.of Weights");
200   }
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");
204     }
205   }
206 }