8da2b2f6bce4bb46c7bdfebbd8ff7540cc77a7be
[occt.git] / src / RWStepGeom / RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve.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 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
15
16 #include <Interface_Check.hxx>
17 #include <Interface_EntityIterator.hxx>
18 #include <Interface_ShareTool.hxx>
19 #include <RWStepGeom_RWBSplineCurveWithKnots.hxx>
20 #include <RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
21 #include <RWStepGeom_RWRationalBSplineCurve.hxx>
22 #include <StepData_Logical.hxx>
23 #include <StepData_StepReaderData.hxx>
24 #include <StepData_StepWriter.hxx>
25 #include <StepGeom_BSplineCurveForm.hxx>
26 #include <StepGeom_BSplineCurveWithKnots.hxx>
27 #include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
28 #include <StepGeom_CartesianPoint.hxx>
29 #include <StepGeom_HArray1OfCartesianPoint.hxx>
30 #include <StepGeom_KnotType.hxx>
31 #include <StepGeom_RationalBSplineCurve.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33 #include <TColStd_HArray1OfReal.hxx>
34
35 // --- Enum : BSplineCurveForm ---
36 static TCollection_AsciiString bscfEllipticArc(".ELLIPTIC_ARC.");
37 static TCollection_AsciiString bscfPolylineForm(".POLYLINE_FORM.");
38 static TCollection_AsciiString bscfParabolicArc(".PARABOLIC_ARC.");
39 static TCollection_AsciiString bscfCircularArc(".CIRCULAR_ARC.");
40 static TCollection_AsciiString bscfUnspecified(".UNSPECIFIED.");
41 static TCollection_AsciiString bscfHyperbolicArc(".HYPERBOLIC_ARC.");
42
43         // --- Enum : KnotType ---
44 static TCollection_AsciiString ktUniformKnots(".UNIFORM_KNOTS.");
45 static TCollection_AsciiString ktQuasiUniformKnots(".QUASI_UNIFORM_KNOTS.");
46 static TCollection_AsciiString ktPiecewiseBezierKnots(".PIECEWISE_BEZIER_KNOTS.");
47 static TCollection_AsciiString ktUnspecified(".UNSPECIFIED.");
48
49 RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve () {}
50
51 void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::ReadStep
52         (const Handle(StepData_StepReaderData)& data,
53          const Standard_Integer num0,
54          Handle(Interface_Check)& ach,
55          const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent) const
56 {
57
58 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
59         Standard_Integer num = 0;  // num0
60         data->NamedForComplex("BOUNDED_CURVE BNDCRV",num0,num,ach);
61
62         // --- Instance of plex componant BoundedCurve ---
63
64         if (!data->CheckNbParams(num,0,ach,"bounded_curve")) return;
65
66 //      num = data->NextForComplex(num);
67 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
68 //        num =  0; gka TRJ9
69         data->NamedForComplex("B_SPLINE_CURVE BSPCR",num0,num,ach);
70
71         // --- Instance of common supertype BSplineCurve ---
72
73         if (!data->CheckNbParams(num,5,ach,"b_spline_curve")) return;
74         // --- field : degree ---
75
76
77         Standard_Integer aDegree;
78         //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
79         data->ReadInteger (num,1,"degree",ach,aDegree);
80         // --- field : controlPointsList ---
81
82
83         Handle(StepGeom_HArray1OfCartesianPoint) aControlPointsList;
84         Handle(StepGeom_CartesianPoint) anent2;
85         Standard_Integer nsub2;
86         if (data->ReadSubList (num,2,"control_points_list",ach,nsub2)) {
87           Standard_Integer nb2 = data->NbParams(nsub2);
88           aControlPointsList = new StepGeom_HArray1OfCartesianPoint (1, nb2);
89           for (Standard_Integer i2 = 1; i2 <= nb2; i2 ++) {
90             //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
91             if (data->ReadEntity (nsub2, i2,"cartesian_point", ach,
92                                   STANDARD_TYPE(StepGeom_CartesianPoint), anent2))
93               aControlPointsList->SetValue(i2, anent2);
94           }
95         }
96
97         // --- field : curveForm ---
98
99
100         StepGeom_BSplineCurveForm aCurveForm = StepGeom_bscfPolylineForm;
101         if (data->ParamType(num,3) == Interface_ParamEnum) {
102           Standard_CString text = data->ParamCValue(num,3);
103           if      (bscfEllipticArc.IsEqual(text)) aCurveForm = StepGeom_bscfEllipticArc;
104           else if (bscfPolylineForm.IsEqual(text)) aCurveForm = StepGeom_bscfPolylineForm;
105           else if (bscfParabolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfParabolicArc;
106           else if (bscfCircularArc.IsEqual(text)) aCurveForm = StepGeom_bscfCircularArc;
107           else if (bscfUnspecified.IsEqual(text)) aCurveForm = StepGeom_bscfUnspecified;
108           else if (bscfHyperbolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfHyperbolicArc;
109           else ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
110         }
111         else ach->AddFail("Parameter #3 (curve_form) is not an enumeration");
112         // --- field : closedCurve ---
113
114
115         StepData_Logical aClosedCurve;
116         //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
117         data->ReadLogical (num,4,"closed_curve",ach,aClosedCurve);
118         // --- field : selfIntersect ---
119
120
121         StepData_Logical aSelfIntersect;
122         //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
123         data->ReadLogical (num,5,"self_intersect",ach,aSelfIntersect);
124
125 //      num = data->NextForComplex(num);
126 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
127 //        num =  0; //gka TRJ9
128         data->NamedForComplex("B_SPLINE_CURVE_WITH_KNOTS BSCWK",num0,num,ach);
129
130         // --- Instance of plex componant BSplineCurveWithKnots ---
131
132         if (!data->CheckNbParams(num,3,ach,"b_spline_curve_with_knots")) return;
133
134         // --- field : knotMultiplicities ---
135
136         Handle(TColStd_HArray1OfInteger) aKnotMultiplicities;
137         Standard_Integer aKnotMultiplicitiesItem;
138         Standard_Integer nsub6;
139         if (data->ReadSubList (num,1,"knot_multiplicities",ach,nsub6)) {
140           Standard_Integer nb6 = data->NbParams(nsub6);
141           aKnotMultiplicities = new TColStd_HArray1OfInteger (1, nb6);
142           for (Standard_Integer i6 = 1; i6 <= nb6; i6 ++) {
143             //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
144             if (data->ReadInteger (nsub6,i6,"knot_multiplicities",ach,aKnotMultiplicitiesItem))
145               aKnotMultiplicities->SetValue(i6,aKnotMultiplicitiesItem);
146           }
147         }
148
149         // --- field : knots ---
150
151         Handle(TColStd_HArray1OfReal) aKnots;
152         Standard_Real aKnotsItem;
153         Standard_Integer nsub7;
154         if (data->ReadSubList (num,2,"knots",ach,nsub7)) {
155           Standard_Integer nb7 = data->NbParams(nsub7);
156           aKnots = new TColStd_HArray1OfReal (1, nb7);
157           for (Standard_Integer i7 = 1; i7 <= nb7; i7 ++) {
158             //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
159             if (data->ReadReal (nsub7,i7,"knots",ach,aKnotsItem))
160               aKnots->SetValue(i7,aKnotsItem);
161           }
162         }
163
164         // --- field : knotSpec ---
165
166         StepGeom_KnotType aKnotSpec = StepGeom_ktUniformKnots;
167         if (data->ParamType(num,3) == Interface_ParamEnum) {
168           Standard_CString text = data->ParamCValue(num,3);
169           if      (ktUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktUniformKnots;
170           else if (ktQuasiUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktQuasiUniformKnots;
171           else if (ktPiecewiseBezierKnots.IsEqual(text)) aKnotSpec = StepGeom_ktPiecewiseBezierKnots;
172           else if (ktUnspecified.IsEqual(text)) aKnotSpec = StepGeom_ktUnspecified;
173           else ach->AddFail("Enumeration knot_type has not an allowed value");
174         }
175         else ach->AddFail("Parameter #3 (knot_spec) is not an enumeration");
176
177 //      num = data->NextForComplex(num);
178 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
179 //        num =  0; gka TRJ9
180         data->NamedForComplex("CURVE",num0,num,ach);
181
182         // --- Instance of plex componant Curve ---
183
184         if (!data->CheckNbParams(num,0,ach,"curve")) return;
185
186 //      num = data->NextForComplex(num);
187 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
188         //num =  0;
189         data->NamedForComplex("GEOMETRIC_REPRESENTATION_ITEM GMRPIT",num0,num,ach);
190
191         // --- Instance of plex componant GeometricRepresentationItem ---
192
193         if (!data->CheckNbParams(num,0,ach,"geometric_representation_item")) return;
194
195 //      num = data->NextForComplex(num);
196 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
197         //num =  0;
198         data->NamedForComplex("RATIONAL_B_SPLINE_CURVE RBSC",num0,num,ach);
199
200         // --- Instance of plex componant RationalBSplineCurve ---
201
202         if (!data->CheckNbParams(num,1,ach,"rational_b_spline_curve")) return;
203
204         // --- field : weightsData ---
205
206         Handle(TColStd_HArray1OfReal) aWeightsData;
207         Standard_Real aWeightsDataItem;
208         Standard_Integer nsub9;
209         if (data->ReadSubList (num,1,"weights_data",ach,nsub9)) {
210           Standard_Integer nb9 = data->NbParams(nsub9);
211           aWeightsData = new TColStd_HArray1OfReal (1, nb9);
212           for (Standard_Integer i9 = 1; i9 <= nb9; i9 ++) {
213             //szv#4:S4163:12Mar99 `Standard_Boolean stat9 =` not needed
214             if (data->ReadReal (nsub9,i9,"weights_data",ach,aWeightsDataItem))
215               aWeightsData->SetValue(i9,aWeightsDataItem);
216           }
217         }
218
219 //      num = data->NextForComplex(num);
220 // sln 04.10.2001. BUC61003. Correction of looking for items of complex entity
221         //num =  0;
222         data->NamedForComplex("REPRESENTATION_ITEM RPRITM",num0,num,ach);
223
224         // --- Instance of plex componant RepresentationItem ---
225
226         if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
227
228         // --- field : name ---
229
230         Handle(TCollection_HAsciiString) aName;
231         //szv#4:S4163:12Mar99 `Standard_Boolean stat10 =` not needed
232         data->ReadString (num,1,"name",ach,aName);
233
234         //--- Initialisation of the red entity ---
235
236         ent->Init(aName,aDegree,aControlPointsList,aCurveForm,aClosedCurve,aSelfIntersect,aKnotMultiplicities,aKnots,aKnotSpec,aWeightsData);
237 }
238
239
240 void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::WriteStep
241         (StepData_StepWriter& SW,
242          const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent) const
243 {
244
245         // --- Instance of plex componant BoundedCurve ---
246
247         SW.StartEntity("BOUNDED_CURVE");
248
249         // --- Instance of common supertype BSplineCurve ---
250
251         SW.StartEntity("B_SPLINE_CURVE");
252         // --- field : degree ---
253
254         SW.Send(ent->Degree());
255         // --- field : controlPointsList ---
256
257         SW.OpenSub();
258         for (Standard_Integer i2 = 1;  i2 <= ent->NbControlPointsList();  i2 ++) {
259           SW.Send(ent->ControlPointsListValue(i2));
260         }
261         SW.CloseSub();
262         // --- field : curveForm ---
263
264         switch(ent->CurveForm()) {
265           case StepGeom_bscfEllipticArc : SW.SendEnum (bscfEllipticArc); break;
266           case StepGeom_bscfPolylineForm : SW.SendEnum (bscfPolylineForm); break;
267           case StepGeom_bscfParabolicArc : SW.SendEnum (bscfParabolicArc); break;
268           case StepGeom_bscfCircularArc : SW.SendEnum (bscfCircularArc); break;
269           case StepGeom_bscfUnspecified : SW.SendEnum (bscfUnspecified); break;
270           case StepGeom_bscfHyperbolicArc : SW.SendEnum (bscfHyperbolicArc); break;
271         }
272         // --- field : closedCurve ---
273
274         SW.SendLogical(ent->ClosedCurve());
275         // --- field : selfIntersect ---
276
277         SW.SendLogical(ent->SelfIntersect());
278
279         // --- Instance of plex componant BSplineCurveWithKnots ---
280
281         SW.StartEntity("B_SPLINE_CURVE_WITH_KNOTS");
282         // --- field : knotMultiplicities ---
283
284         SW.OpenSub();
285         for (Standard_Integer i6 = 1;  i6 <= ent->NbKnotMultiplicities();  i6 ++) {
286           SW.Send(ent->KnotMultiplicitiesValue(i6));
287         }
288         SW.CloseSub();
289         // --- field : knots ---
290
291         SW.OpenSub();
292         for (Standard_Integer i7 = 1;  i7 <= ent->NbKnots();  i7 ++) {
293           SW.Send(ent->KnotsValue(i7));
294         }
295         SW.CloseSub();
296         // --- field : knotSpec ---
297
298         switch(ent->KnotSpec()) {
299           case StepGeom_ktUniformKnots : SW.SendEnum (ktUniformKnots); break;
300           case StepGeom_ktQuasiUniformKnots : SW.SendEnum (ktQuasiUniformKnots); break;
301           case StepGeom_ktPiecewiseBezierKnots : SW.SendEnum (ktPiecewiseBezierKnots); break;
302           case StepGeom_ktUnspecified : SW.SendEnum (ktUnspecified); break;
303         }
304
305         // --- Instance of plex componant Curve ---
306
307         SW.StartEntity("CURVE");
308
309         // --- Instance of plex componant GeometricRepresentationItem ---
310
311         SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
312
313         // --- Instance of plex componant RationalBSplineCurve ---
314
315         SW.StartEntity("RATIONAL_B_SPLINE_CURVE");
316         // --- field : weightsData ---
317
318         SW.OpenSub();
319         for (Standard_Integer i9 = 1;  i9 <= ent->NbWeightsData();  i9 ++) {
320           SW.Send(ent->WeightsDataValue(i9));
321         }
322         SW.CloseSub();
323
324         // --- Instance of plex componant RepresentationItem ---
325
326         SW.StartEntity("REPRESENTATION_ITEM");
327         // --- field : name ---
328
329         SW.Send(ent->Name());
330 }
331
332
333 void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::Share(const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
334 {
335
336         Standard_Integer nbElem1 = ent->NbControlPointsList();
337         for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
338           iter.GetOneItem(ent->ControlPointsListValue(is1));
339         }
340
341 }
342
343
344
345 void RWStepGeom_RWBSplineCurveWithKnotsAndRationalBSplineCurve::Check
346   (const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)& ent,
347    const Interface_ShareTool& aShto,
348    Handle(Interface_Check)& ach) const
349 {
350   Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) aRationalBSC =
351     Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(ent);
352   Handle(StepGeom_BSplineCurveWithKnots) aBSCWK =
353     aRationalBSC->BSplineCurveWithKnots();
354   RWStepGeom_RWBSplineCurveWithKnots t1;
355   t1.Check(aBSCWK,aShto,ach);
356   Handle(StepGeom_RationalBSplineCurve) aRBSC =
357     aRationalBSC->RationalBSplineCurve();
358   RWStepGeom_RWRationalBSplineCurve t2;
359   t2.Check(aRBSC,aShto,ach);
360 }