summaryrefslogtreecommitdiff
path: root/src/RWStepGeom/RWStepGeom_RWBSplineCurveWithKnots.cxx
blob: 812edba00f6d776e0e1aea024eb1345ac0192592 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

#include <RWStepGeom_RWBSplineCurveWithKnots.ixx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <StepGeom_KnotType.hxx>
#include <StepGeom_HArray1OfCartesianPoint.hxx>
#include <StepGeom_CartesianPoint.hxx>
#include <StepGeom_BSplineCurveForm.hxx>
#include <StepData_Logical.hxx>


#include <Interface_EntityIterator.hxx>


#include <StepGeom_BSplineCurveWithKnots.hxx>

#include <TCollection_AsciiString.hxx>


	// --- Enum : KnotType ---
static TCollection_AsciiString ktUniformKnots(".UNIFORM_KNOTS.");
static TCollection_AsciiString ktQuasiUniformKnots(".QUASI_UNIFORM_KNOTS.");
static TCollection_AsciiString ktPiecewiseBezierKnots(".PIECEWISE_BEZIER_KNOTS.");
static TCollection_AsciiString ktUnspecified(".UNSPECIFIED.");


	// --- Enum : BSplineCurveForm ---
static TCollection_AsciiString bscfEllipticArc(".ELLIPTIC_ARC.");
static TCollection_AsciiString bscfPolylineForm(".POLYLINE_FORM.");
static TCollection_AsciiString bscfParabolicArc(".PARABOLIC_ARC.");
static TCollection_AsciiString bscfCircularArc(".CIRCULAR_ARC.");
static TCollection_AsciiString bscfUnspecified(".UNSPECIFIED.");
static TCollection_AsciiString bscfHyperbolicArc(".HYPERBOLIC_ARC.");

RWStepGeom_RWBSplineCurveWithKnots::RWStepGeom_RWBSplineCurveWithKnots () {}

void RWStepGeom_RWBSplineCurveWithKnots::ReadStep
	(const Handle(StepData_StepReaderData)& data,
	 const Standard_Integer num,
	 Handle(Interface_Check)& ach,
	 const Handle(StepGeom_BSplineCurveWithKnots)& ent) const
{


	// --- Number of Parameter Control ---

	if (!data->CheckNbParams(num,9,ach,"b_spline_curve_with_knots")) return;

	// --- inherited field : name ---

	Handle(TCollection_HAsciiString) aName;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
	data->ReadString (num,1,"name",ach,aName);

	// --- inherited field : degree ---

	Standard_Integer aDegree;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
	data->ReadInteger (num,2,"degree",ach,aDegree);

	// --- inherited field : controlPointsList ---

	Handle(StepGeom_HArray1OfCartesianPoint) aControlPointsList;
	Handle(StepGeom_CartesianPoint) anent3;
	Standard_Integer nsub3;
	if (data->ReadSubList (num,3,"control_points_list",ach,nsub3)) {
	  Standard_Integer nb3 = data->NbParams(nsub3);
	  aControlPointsList = new StepGeom_HArray1OfCartesianPoint (1, nb3);
	  for (Standard_Integer i3 = 1; i3 <= nb3; i3 ++) {
	    //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
	    if (data->ReadEntity (nsub3, i3,"cartesian_point", ach,
				  STANDARD_TYPE(StepGeom_CartesianPoint), anent3))
	      aControlPointsList->SetValue(i3, anent3);
	  }
	}

	// --- inherited field : curveForm ---

	StepGeom_BSplineCurveForm aCurveForm = StepGeom_bscfPolylineForm;
	if (data->ParamType(num,4) == Interface_ParamEnum) {
	  Standard_CString text = data->ParamCValue(num,4);
	  if      (bscfEllipticArc.IsEqual(text)) aCurveForm = StepGeom_bscfEllipticArc;
	  else if (bscfPolylineForm.IsEqual(text)) aCurveForm = StepGeom_bscfPolylineForm;
	  else if (bscfParabolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfParabolicArc;
	  else if (bscfCircularArc.IsEqual(text)) aCurveForm = StepGeom_bscfCircularArc;
	  else if (bscfUnspecified.IsEqual(text)) aCurveForm = StepGeom_bscfUnspecified;
	  else if (bscfHyperbolicArc.IsEqual(text)) aCurveForm = StepGeom_bscfHyperbolicArc;
	  else ach->AddFail("Enumeration b_spline_curve_form has not an allowed value");
	}
	else ach->AddFail("Parameter #4 (curve_form) is not an enumeration");

	// --- inherited field : closedCurve ---

	StepData_Logical aClosedCurve;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
	data->ReadLogical (num,5,"closed_curve",ach,aClosedCurve);

	// --- inherited field : selfIntersect ---

	StepData_Logical aSelfIntersect;
	//szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
	data->ReadLogical (num,6,"self_intersect",ach,aSelfIntersect);

	// --- own field : knotMultiplicities ---

	Handle(TColStd_HArray1OfInteger) aKnotMultiplicities;
	Standard_Integer aKnotMultiplicitiesItem;
	Standard_Integer nsub7;
	if (data->ReadSubList (num,7,"knot_multiplicities",ach,nsub7)) {
	  Standard_Integer nb7 = data->NbParams(nsub7);
	  aKnotMultiplicities = new TColStd_HArray1OfInteger (1, nb7);
	  for (Standard_Integer i7 = 1; i7 <= nb7; i7 ++) {
	    //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
	    if (data->ReadInteger (nsub7,i7,"knot_multiplicities",ach,aKnotMultiplicitiesItem))
	      aKnotMultiplicities->SetValue(i7,aKnotMultiplicitiesItem);
	  }
	}

	// --- own field : knots ---

	Handle(TColStd_HArray1OfReal) aKnots;
	Standard_Real aKnotsItem;
	Standard_Integer nsub8;
	if (data->ReadSubList (num,8,"knots",ach,nsub8)) {
	  Standard_Integer nb8 = data->NbParams(nsub8);
	  aKnots = new TColStd_HArray1OfReal (1, nb8);
	  for (Standard_Integer i8 = 1; i8 <= nb8; i8 ++) {
	    //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
	    if (data->ReadReal (nsub8,i8,"knots",ach,aKnotsItem))
	      aKnots->SetValue(i8,aKnotsItem);
	  }
	}

	// --- own field : knotSpec ---

	StepGeom_KnotType aKnotSpec = StepGeom_ktUniformKnots;
	if (data->ParamType(num,9) == Interface_ParamEnum) {
	  Standard_CString text = data->ParamCValue(num,9);
	  if      (ktUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktUniformKnots;
	  else if (ktQuasiUniformKnots.IsEqual(text)) aKnotSpec = StepGeom_ktQuasiUniformKnots;
	  else if (ktPiecewiseBezierKnots.IsEqual(text)) aKnotSpec = StepGeom_ktPiecewiseBezierKnots;
	  else if (ktUnspecified.IsEqual(text)) aKnotSpec = StepGeom_ktUnspecified;
	  else ach->AddFail("Enumeration knot_type has not an allowed value");
	}
	else ach->AddFail("Parameter #9 (knot_spec) is not an enumeration");

	//--- Initialisation of the read entity ---


	ent->Init(aName, aDegree, aControlPointsList, aCurveForm, aClosedCurve, aSelfIntersect, aKnotMultiplicities, aKnots, aKnotSpec);
}


void RWStepGeom_RWBSplineCurveWithKnots::WriteStep
	(StepData_StepWriter& SW,
	 const Handle(StepGeom_BSplineCurveWithKnots)& ent) const
{

	// --- inherited field name ---

	SW.Send(ent->Name());

	// --- inherited field degree ---

	SW.Send(ent->Degree());

	// --- inherited field controlPointsList ---

	SW.OpenSub();
	for (Standard_Integer i3 = 1;  i3 <= ent->NbControlPointsList();  i3 ++) {
	  SW.Send(ent->ControlPointsListValue(i3));
	}
	SW.CloseSub();

	// --- inherited field curveForm ---

	switch(ent->CurveForm()) {
	  case StepGeom_bscfEllipticArc : SW.SendEnum (bscfEllipticArc); break;
	  case StepGeom_bscfPolylineForm : SW.SendEnum (bscfPolylineForm); break;
	  case StepGeom_bscfParabolicArc : SW.SendEnum (bscfParabolicArc); break;
	  case StepGeom_bscfCircularArc : SW.SendEnum (bscfCircularArc); break;
	  case StepGeom_bscfUnspecified : SW.SendEnum (bscfUnspecified); break;
	  case StepGeom_bscfHyperbolicArc : SW.SendEnum (bscfHyperbolicArc); break;
	}

	// --- inherited field closedCurve ---

	SW.SendLogical(ent->ClosedCurve());

	// --- inherited field selfIntersect ---

	SW.SendLogical(ent->SelfIntersect());

	// --- own field : knotMultiplicities ---

	SW.OpenSub();
	for (Standard_Integer i7 = 1;  i7 <= ent->NbKnotMultiplicities();  i7 ++) {
	  SW.Send(ent->KnotMultiplicitiesValue(i7));
	}
	SW.CloseSub();

	// --- own field : knots ---

	SW.OpenSub();
	for (Standard_Integer i8 = 1;  i8 <= ent->NbKnots();  i8 ++) {
	  SW.Send(ent->KnotsValue(i8));
	}
	SW.CloseSub();

	// --- own field : knotSpec ---

	switch(ent->KnotSpec()) {
	  case StepGeom_ktUniformKnots : SW.SendEnum (ktUniformKnots); break;
	  case StepGeom_ktQuasiUniformKnots : SW.SendEnum (ktQuasiUniformKnots); break;
	  case StepGeom_ktPiecewiseBezierKnots : SW.SendEnum (ktPiecewiseBezierKnots); break;
	  case StepGeom_ktUnspecified : SW.SendEnum (ktUnspecified); break;
	}
}


void RWStepGeom_RWBSplineCurveWithKnots::Share(const Handle(StepGeom_BSplineCurveWithKnots)& ent, Interface_EntityIterator& iter) const
{

	Standard_Integer nbElem1 = ent->NbControlPointsList();
	for (Standard_Integer is1=1; is1<=nbElem1; is1 ++) {
	  iter.GetOneItem(ent->ControlPointsListValue(is1));
	}

}

void RWStepGeom_RWBSplineCurveWithKnots::Check
(const Handle(StepGeom_BSplineCurveWithKnots)& ent,
 const Interface_ShareTool& ,
 Handle(Interface_Check)& ach) const
{
  Standard_Integer nbCPL  = ent->NbControlPointsList();
  Standard_Integer dgBSC  = ent->Degree();
  Standard_Integer nbMult = ent->NbKnotMultiplicities();
  Standard_Integer nbKno  = ent->NbKnots();
  Standard_Integer sumMult = 0;
//  cout << "BSplineCurveWithKnots: nbMult=" << nbMult << " nbKno= " << 
//    nbKno << " nbCPL= " << nbCPL << " degree= " << dgBSC << endl;
  if(nbMult != nbKno) {
    ach->AddFail("ERROR: No.of KnotMultiplicities not equal No.of Knots");
  }
  Standard_Integer i;//svv Jan 10 2000: porting on DEC 
  for (i=1; i<=nbMult-1; i++) {
    sumMult = sumMult + ent->KnotMultiplicitiesValue(i);
  }
  Standard_Integer sumNonP = nbCPL + dgBSC + 1;
  Standard_Integer mult1 = ent->KnotMultiplicitiesValue(1);
  Standard_Integer multN = ent->KnotMultiplicitiesValue(nbMult);
//  cout << "BSplineCurveWithKnots: mult1=" << mult1 << " multN= " <<
//    multN << " sumMult= " << sumMult << endl;
  if((sumMult + multN) == sumNonP) {
  }
  else if((sumMult == nbCPL) && (mult1 == multN)) {
  }
  else {
    ach->AddFail("ERROR: wrong number of Knot Multiplicities");
  }
  for(i=2; i<=nbKno; i++) {
    Standard_Real distKn  = ent->KnotsValue(i-1) - ent->KnotsValue(i);
    if(Abs(distKn) <= RealEpsilon())
      ach->AddWarning("WARNING: Curve contains identical KnotsValues");
    else if(distKn > RealEpsilon())
      ach->AddFail("ERROR: Curve contains descending KnotsValues");
  }
}