0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / RWStepGeom / RWStepGeom_RWUniformCurveAndRationalBSplineCurve.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 <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>
28
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.");
36
37 RWStepGeom_RWUniformCurveAndRationalBSplineCurve::RWStepGeom_RWUniformCurveAndRationalBSplineCurve () {}
38
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
44 {
45
46         Standard_Integer num = num0;
47
48
49         // --- Instance of plex componant BoundedCurve ---
50
51         if (!data->CheckNbParams(num,0,ach,"bounded_curve")) return;
52
53         num = data->NextForComplex(num);
54
55         // --- Instance of common supertype BSplineCurve ---
56
57         if (!data->CheckNbParams(num,5,ach,"b_spline_curve")) return;
58         // --- field : degree ---
59
60
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 ---
65
66
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);
78           }
79         }
80
81         // --- field : curveForm ---
82
83
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");
94         }
95         else ach->AddFail("Parameter #3 (curve_form) is not an enumeration");
96         // --- field : closedCurve ---
97
98
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 ---
103
104
105         StepData_Logical aSelfIntersect;
106         //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
107         data->ReadLogical (num,5,"self_intersect",ach,aSelfIntersect);
108
109         num = data->NextForComplex(num);
110
111         // --- Instance of plex componant Curve ---
112
113         if (!data->CheckNbParams(num,0,ach,"curve")) return;
114
115         num = data->NextForComplex(num);
116
117         // --- Instance of plex componant GeometricRepresentationItem ---
118
119         if (!data->CheckNbParams(num,0,ach,"geometric_representation_item")) return;
120
121         num = data->NextForComplex(num);
122
123         // --- Instance of plex componant RationalBSplineCurve ---
124
125         if (!data->CheckNbParams(num,1,ach,"rational_b_spline_curve")) return;
126
127         // --- field : weightsData ---
128
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);
139           }
140         }
141
142         num = data->NextForComplex(num);
143
144         // --- Instance of plex componant RepresentationItem ---
145
146         if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
147
148         // --- field : name ---
149
150         Handle(TCollection_HAsciiString) aName;
151         //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
152         data->ReadString (num,1,"name",ach,aName);
153
154         num = data->NextForComplex(num);
155
156         // --- Instance of plex componant UniformCurve ---
157
158         if (!data->CheckNbParams(num,0,ach,"uniform_curve")) return;
159
160         //--- Initialisation of the red entity ---
161
162         ent->Init(aName,aDegree,aControlPointsList,aCurveForm,aClosedCurve,aSelfIntersect,aWeightsData);
163 }
164
165
166 void RWStepGeom_RWUniformCurveAndRationalBSplineCurve::WriteStep
167         (StepData_StepWriter& SW,
168          const Handle(StepGeom_UniformCurveAndRationalBSplineCurve)& ent) const
169 {
170
171         // --- Instance of plex componant BoundedCurve ---
172
173         SW.StartEntity("BOUNDED_CURVE");
174
175         // --- Instance of common supertype BSplineCurve ---
176
177         SW.StartEntity("B_SPLINE_CURVE");
178         // --- field : degree ---
179
180         SW.Send(ent->Degree());
181         // --- field : controlPointsList ---
182
183         SW.OpenSub();
184         for (Standard_Integer i2 = 1;  i2 <= ent->NbControlPointsList();  i2 ++) {
185           SW.Send(ent->ControlPointsListValue(i2));
186         }
187         SW.CloseSub();
188         // --- field : curveForm ---
189
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;
197         }
198         // --- field : closedCurve ---
199
200         SW.SendLogical(ent->ClosedCurve());
201         // --- field : selfIntersect ---
202
203         SW.SendLogical(ent->SelfIntersect());
204
205         // --- Instance of plex componant Curve ---
206
207         SW.StartEntity("CURVE");
208
209         // --- Instance of plex componant GeometricRepresentationItem ---
210
211         SW.StartEntity("GEOMETRIC_REPRESENTATION_ITEM");
212
213         // --- Instance of plex componant RationalBSplineCurve ---
214
215         SW.StartEntity("RATIONAL_B_SPLINE_CURVE");
216         // --- field : weightsData ---
217
218         SW.OpenSub();
219         for (Standard_Integer i6 = 1;  i6 <= ent->NbWeightsData();  i6 ++) {
220           SW.Send(ent->WeightsDataValue(i6));
221         }
222         SW.CloseSub();
223
224         // --- Instance of plex componant RepresentationItem ---
225
226         SW.StartEntity("REPRESENTATION_ITEM");
227         // --- field : name ---
228
229         SW.Send(ent->Name());
230
231         // --- Instance of plex componant UniformCurve ---
232
233         SW.StartEntity("UNIFORM_CURVE");
234 }
235
236
237 void RWStepGeom_RWUniformCurveAndRationalBSplineCurve::Share(const Handle(StepGeom_UniformCurveAndRationalBSplineCurve)& ent, Interface_EntityIterator& iter) const
238 {
239
240         Standard_Integer nbElem1 = ent->NbControlPointsList();
241         for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
242           iter.GetOneItem(ent->ControlPointsListValue(is1));
243         }
244
245 }
246