0022627: Change OCCT memory management defaults
[occt.git] / src / StepToGeom / StepToGeom_MakeBSplineCurve.pxx
CommitLineData
7fd59977 1// File: StepToGeom_MakeBSplineCurve.pxx
2// Created: Fri Jul 2 15:16:54 1993
3// Author: Martine LANGLOIS
4
5{
6 Handle(StepGeom_BSplineCurveWithKnots) BSCW;
7 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) BSCWR;
8
9 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
10 BSCWR =
11 Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
12 ::DownCast(SC);
13 BSCW =
14 Handle(StepGeom_BSplineCurveWithKnots)
15 ::DownCast(BSCWR->BSplineCurveWithKnots());
16 }
17 else
18 BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
19
20 const Standard_Integer Deg = BSCW->Degree();
21 const Standard_Integer NbPoles = BSCW->NbControlPointsList();
22 //aControlPointsList = new StepGeom_HArray1OfCartesianPoint(1,NbPoles);
23 const Handle(StepGeom_HArray1OfCartesianPoint)& aControlPointsList = BSCW->ControlPointsList();
24 Array1OfPnt_gen Poles(1,NbPoles);
25
26 Standard_Integer i;
27 CartesianPoint_gen P;
28 for (i=1; i<=NbPoles; i++)
29 {
30 if (StepToGeom_MakeCartesianPoint_gen::Convert(aControlPointsList->Value(i),P))
31 Poles.SetValue(i,P->Pnt_fonc());
32 else
33 return Standard_False;
34 }
35
36 const Standard_Integer NbKnots = BSCW->NbKnotMultiplicities();
37
38 //aKnotMultiplicities = new TColStd_HArray1OfInteger(1,NbKnots);
39 const Handle(TColStd_HArray1OfInteger)& aKnotMultiplicities = BSCW->KnotMultiplicities();
40 TColStd_Array1OfInteger Mult(1,NbKnots);
41 for (i=1; i<=NbKnots; i++) {
42 Mult.SetValue(i,aKnotMultiplicities->Value(i));
43 }
44
45 //aKnots = new TColStd_HArray1OfReal(1,NbKnots);
46 const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots();
47 TColStd_Array1OfReal Kn(1,NbKnots);
48 for (i=1; i<=NbKnots; i++) {
49 Kn.SetValue(i,aKnots->Value(i));
50 }
51
52 // --- Does the Curve descriptor LOOKS like a periodic descriptor ? ---
53
54 Standard_Integer SumMult = 0;
55 for (i=1; i<=NbKnots; i++) {
56 SumMult += aKnotMultiplicities->Value(i);
57 }
58
59 Standard_Boolean shouldBePeriodic;
60 if (SumMult == (NbPoles + Deg + 1)) {
61 shouldBePeriodic = Standard_False;
62 }
63 else if ((aKnotMultiplicities->Value(1) ==
64 aKnotMultiplicities->Value(NbKnots)) &&
65 ((SumMult - aKnotMultiplicities->Value(1)) == NbPoles)) {
66 shouldBePeriodic = Standard_True;
67 }
68 else { // --- What is that ??? ---
69 shouldBePeriodic = Standard_False;
70 //cout << "Strange BSpline Curve Descriptor" << endl;
71 }
72
73 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
74 const Handle(TColStd_HArray1OfReal)& aWeight = BSCWR->WeightsData();
75 TColStd_Array1OfReal W(1,NbPoles);
76 for (i=1; i<=NbPoles; i++)
77 W.SetValue(i,aWeight->Value(i));
78 CC = new BSplineCurve_gen(Poles, W, Kn, Mult, Deg, shouldBePeriodic);
79 }
80 else
81 CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic);
82
83 // abv 04.07.00 CAX-IF TRJ4: trj4_k1_top-md-203.stp #716 (face #581):
84 // force periodicity on closed curves
85 if ( SC->ClosedCurve() && CC->Degree() >1 && CC->IsClosed() ) {
86 CC->SetPeriodic();
87//#ifdef DEB
88// cout << "Warning: "__FILE__": Closed curve made periodic" << endl;
89//#endif
90 }
91 return Standard_True;
92}