0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / StepToGeom / StepToGeom_MakeBoundedCurve.cxx
1 // Created on: 1993-07-02
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //:n6 abv 15.02.99: S4132: adding translation of polyline
18 //:p0 abv 19.02.99: management of 'done' flag improved; trimmed_curve treated
19
20 #include <StepToGeom_MakeBoundedCurve.ixx>
21
22 #include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
23 #include <StepGeom_BSplineCurveWithKnots.hxx>
24 #include <StepGeom_BezierCurve.hxx>
25 #include <StepGeom_UniformCurve.hxx>
26 #include <StepGeom_UniformCurveAndRationalBSplineCurve.hxx>
27 #include <StepGeom_QuasiUniformCurve.hxx>
28 #include <StepGeom_QuasiUniformCurveAndRationalBSplineCurve.hxx>
29 #include <StepGeom_Polyline.hxx>
30 #include <StepGeom_TrimmedCurve.hxx>
31 #include <StepGeom_KnotType.hxx>
32 #include <StepToGeom_MakeBSplineCurve.hxx>
33 #include <StepGeom_Polyline.hxx>
34 #include <StepToGeom_MakePolyline.hxx>
35 #include <StepToGeom_MakeTrimmedCurve.hxx>
36
37 #include <TColStd_HArray1OfInteger.hxx>
38 #include <TColStd_HArray1OfReal.hxx>
39
40 //=============================================================================
41 // Creation d' une BoundedCurve de Geom a partir d' une BoundedCurve de Step
42 //=============================================================================
43
44 Standard_Boolean StepToGeom_MakeBoundedCurve::Convert
45     (const Handle(StepGeom_BoundedCurve)& SC,
46      Handle(Geom_BoundedCurve)& CC)
47 {
48   if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
49     const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
50       Bspli = Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC);
51         return StepToGeom_MakeBSplineCurve::Convert(Bspli,*((Handle(Geom_BSplineCurve)*)&CC));
52   }
53   if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnots))) {
54     const Handle(StepGeom_BSplineCurveWithKnots)
55       Bspli = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
56         return StepToGeom_MakeBSplineCurve::Convert(Bspli,*((Handle(Geom_BSplineCurve)*)&CC));
57   }
58   if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve))) {
59     const Handle(StepGeom_TrimmedCurve) L = Handle(StepGeom_TrimmedCurve)::DownCast(SC);
60         return StepToGeom_MakeTrimmedCurve::Convert(L,*((Handle(Geom_TrimmedCurve)*)&CC));
61   }
62   // STEP BezierCurve, UniformCurve and QuasiUniformCurve are transformed into
63   // STEP BSplineCurve before being mapped onto CAS.CADE/SF
64   if (SC->IsKind(STANDARD_TYPE(StepGeom_BezierCurve))) {
65     const Handle(StepGeom_BezierCurve) BzC = Handle(StepGeom_BezierCurve)::DownCast(SC);
66     const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
67     BSPL->SetDegree(BzC->Degree());
68     BSPL->SetControlPointsList(BzC->ControlPointsList());
69     BSPL->SetCurveForm(BzC->CurveForm());
70     BSPL->SetClosedCurve(BzC->ClosedCurve());
71     BSPL->SetSelfIntersect(BzC->SelfIntersect());
72     // Compute Knots and KnotsMultiplicity
73     const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,2);
74     const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,2);
75     Kmult->SetValue(1, BzC->Degree() + 1);
76     Kmult->SetValue(2, BzC->Degree() + 1);
77     Knots->SetValue(1, 0.);
78     Knots->SetValue(2, 1.);
79     BSPL->SetKnotMultiplicities(Kmult);
80     BSPL->SetKnots(Knots);
81         return StepToGeom_MakeBSplineCurve::Convert(BSPL,*((Handle(Geom_BSplineCurve)*)&CC));
82   }
83   if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurve))) {
84     const Handle(StepGeom_UniformCurve) UC = Handle(StepGeom_UniformCurve)::DownCast(SC);
85     const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
86     BSPL->SetDegree(UC->Degree());
87     BSPL->SetControlPointsList(UC->ControlPointsList());
88     BSPL->SetCurveForm(UC->CurveForm());
89     BSPL->SetClosedCurve(UC->ClosedCurve());
90     BSPL->SetSelfIntersect(UC->SelfIntersect());
91     // Compute Knots and KnotsMultiplicity
92     const Standard_Integer nbK = BSPL->NbControlPointsList() + BSPL->Degree() + 1;
93     const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
94     const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
95     for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
96       Kmult->SetValue(iUC, 1);
97       Knots->SetValue(iUC, iUC - 1.);
98     }
99     BSPL->SetKnotMultiplicities(Kmult);
100     BSPL->SetKnots(Knots);
101         return StepToGeom_MakeBSplineCurve::Convert(BSPL,*((Handle(Geom_BSplineCurve)*)&CC));
102   }
103   if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurve))) {
104     const Handle(StepGeom_QuasiUniformCurve) QUC = 
105       Handle(StepGeom_QuasiUniformCurve)::DownCast(SC);
106     const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
107     BSPL->SetDegree(QUC->Degree());
108     BSPL->SetControlPointsList(QUC->ControlPointsList());
109     BSPL->SetCurveForm(QUC->CurveForm());
110     BSPL->SetClosedCurve(QUC->ClosedCurve());
111     BSPL->SetSelfIntersect(QUC->SelfIntersect());
112     // Compute Knots and KnotsMultiplicity
113     const Standard_Integer nbK = BSPL->NbControlPointsList() - BSPL->Degree() + 1;
114     const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
115     const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
116     for (Standard_Integer iQUC = 1 ; iQUC <= nbK ; iQUC ++) {
117       Kmult->SetValue(iQUC, 1);
118       Knots->SetValue(iQUC, iQUC - 1.);
119     }
120     Kmult->SetValue(1, BSPL->Degree() + 1);
121     Kmult->SetValue(nbK, BSPL->Degree() + 1);
122     BSPL->SetKnotMultiplicities(Kmult);
123     BSPL->SetKnots(Knots);
124         return StepToGeom_MakeBSplineCurve::Convert(BSPL,*((Handle(Geom_BSplineCurve)*)&CC));
125   }
126   if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurveAndRationalBSplineCurve))) {
127     const Handle(StepGeom_UniformCurveAndRationalBSplineCurve) RUC = 
128       Handle(StepGeom_UniformCurveAndRationalBSplineCurve)::DownCast(SC);
129     const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL = 
130       new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
131     // Compute Knots and KnotsMultiplicity
132     const Standard_Integer nbK = RUC->NbControlPointsList() + RUC->Degree() + 1;
133     const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
134     const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
135     for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
136       Kmult->SetValue(iUC, 1);
137       Knots->SetValue(iUC, iUC - 1.);
138     }
139     // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
140     RBSPL->Init(RUC->Name(), RUC->Degree(), RUC->ControlPointsList(), RUC->CurveForm(),
141                 RUC->ClosedCurve(), RUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
142                 RUC->WeightsData());
143         return StepToGeom_MakeBSplineCurve::Convert(RBSPL,*((Handle(Geom_BSplineCurve)*)&CC));
144   }
145   if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurveAndRationalBSplineCurve))) {
146     const Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve) RQUC = 
147       Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve)::DownCast(SC);
148     const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL = 
149       new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
150     // Compute Knots and KnotsMultiplicity
151     const Standard_Integer nbK = RQUC->NbControlPointsList() - RQUC->Degree() + 1;
152     const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
153     const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
154     for (Standard_Integer iRQUC = 1 ; iRQUC <= nbK ; iRQUC ++) {
155       Kmult->SetValue(iRQUC, 1);
156       Knots->SetValue(iRQUC, iRQUC - 1.);
157     }
158     Kmult->SetValue(1, RQUC->Degree() + 1);
159     Kmult->SetValue(nbK, RQUC->Degree() + 1);
160     // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
161     RBSPL->Init(RQUC->Name(), RQUC->Degree(), RQUC->ControlPointsList(), RQUC->CurveForm(),
162                 RQUC->ClosedCurve(), RQUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
163                 RQUC->WeightsData());
164         return StepToGeom_MakeBSplineCurve::Convert(RBSPL,*((Handle(Geom_BSplineCurve)*)&CC));
165   }
166   if (SC->IsKind(STANDARD_TYPE(StepGeom_Polyline))) { //:n6 abv 15 Feb 99
167     const Handle(StepGeom_Polyline) PL = Handle(StepGeom_Polyline)::DownCast (SC);
168     return StepToGeom_MakePolyline::Convert(PL,*((Handle(Geom_BSplineCurve)*)&CC));
169   }
170   return Standard_False;
171 }