a0ee4cb35dcd3fd7ae66e186187f5b8519076c6b
[occt.git] / src / StepToGeom / StepToGeom_MakeBoundedSurface.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 //:p0 abv 19.02.99: management of 'done' flag improved
18 //:j7 abv 05.04.99: S4136: ass-tol2.stp #9861: avoid using CheckSurfaceClosure
19 //    rln 02.06.99 removing #include <StepToGeom_CheckSurfaceClosure.hxx>
20
21 #include <StepToGeom_MakeBoundedSurface.ixx>
22
23 #include <Geom_BSplineSurface.hxx>
24
25 //rln 02.06.99 #include <StepToGeom_CheckSurfaceClosure.hxx>
26
27 #include <StepToGeom_MakeBoundedSurface.hxx>
28 #include <StepToGeom_MakeBSplineSurface.hxx>
29 #include <StepToGeom_MakeRectangularTrimmedSurface.hxx>
30
31 #include <StepGeom_RectangularTrimmedSurface.hxx>
32 #include <StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
33 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
34
35 #include <TColStd_HArray1OfInteger.hxx>
36 #include <TColStd_HArray1OfReal.hxx>
37
38 #include <StepGeom_BezierSurface.hxx>
39 #include <StepGeom_UniformSurface.hxx>
40 #include <StepGeom_QuasiUniformSurface.hxx>
41 #include <StepGeom_UniformSurfaceAndRationalBSplineSurface.hxx>
42 #include <StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface.hxx>
43 #include <StepGeom_KnotType.hxx>
44
45 //=============================================================================
46 // Creation d' une BoundedSurface de Geom a partir d' une BoundedSurface
47 // de Step
48 //=============================================================================
49
50 Standard_Boolean StepToGeom_MakeBoundedSurface::Convert (const Handle(StepGeom_BoundedSurface)& SS, Handle(Geom_BoundedSurface)& CS)
51 {
52   if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) { 
53     const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) BS =
54       Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)::DownCast(SS);
55         return StepToGeom_MakeBSplineSurface::Convert(BS,*((Handle(Geom_BSplineSurface)*)&CS));
56   }
57   if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnots))) {
58     const Handle(StepGeom_BSplineSurfaceWithKnots) BS
59       = Handle(StepGeom_BSplineSurfaceWithKnots)::DownCast(SS);
60         return StepToGeom_MakeBSplineSurface::Convert(BS,*((Handle(Geom_BSplineSurface)*)&CS));
61   }
62   if (SS->IsKind(STANDARD_TYPE(StepGeom_RectangularTrimmedSurface))) {
63     const Handle(StepGeom_RectangularTrimmedSurface) Sur = 
64       Handle(StepGeom_RectangularTrimmedSurface)::DownCast(SS);
65     return StepToGeom_MakeRectangularTrimmedSurface::Convert(Sur,*((Handle(Geom_RectangularTrimmedSurface)*)&CS));
66   }
67   // STEP BezierSurface, UniformSurface and QuasiUniformSurface are transformed
68   // into STEP BSplineSurface before being mapped onto CAS.CADE/SF
69   if (SS->IsKind(STANDARD_TYPE(StepGeom_BezierSurface))) {
70     const Handle(StepGeom_BezierSurface) BzS = Handle(StepGeom_BezierSurface)::DownCast(SS);
71     const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
72     BSPL->SetUDegree(BzS->UDegree());
73     BSPL->SetVDegree(BzS->VDegree());
74     BSPL->SetControlPointsList(BzS->ControlPointsList());
75     BSPL->SetSurfaceForm(BzS->SurfaceForm());
76     BSPL->SetUClosed(BzS->UClosed());
77     BSPL->SetVClosed(BzS->VClosed());
78     BSPL->SetSelfIntersect(BzS->SelfIntersect());
79     // Compute Knots and KnotsMultiplicity
80     const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,2);
81     const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,2);
82     const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,2);
83     const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,2);
84     UKmult->SetValue(1, BzS->UDegree() + 1);
85     UKmult->SetValue(2, BzS->UDegree() + 1);
86     VKmult->SetValue(1, BzS->VDegree() + 1);
87     VKmult->SetValue(2, BzS->VDegree() + 1);
88     UKnots->SetValue(1, 0.);
89     UKnots->SetValue(2, 1.);
90     VKnots->SetValue(1, 0.);
91     VKnots->SetValue(2, 1.);
92     BSPL->SetUMultiplicities(UKmult);
93     BSPL->SetVMultiplicities(VKmult);
94     BSPL->SetUKnots(UKnots);
95     BSPL->SetVKnots(VKnots);
96         return StepToGeom_MakeBSplineSurface::Convert(BSPL,*((Handle(Geom_BSplineSurface)*)&CS));
97   }
98   if (SS->IsKind(STANDARD_TYPE(StepGeom_UniformSurface))) {
99     const Handle(StepGeom_UniformSurface) US = Handle(StepGeom_UniformSurface)::DownCast(SS);
100     const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
101     BSPL->SetUDegree(US->UDegree());
102     BSPL->SetVDegree(US->VDegree());
103     BSPL->SetControlPointsList(US->ControlPointsList());
104     BSPL->SetSurfaceForm(US->SurfaceForm());
105     BSPL->SetUClosed(US->UClosed());
106     BSPL->SetVClosed(US->VClosed());
107     BSPL->SetSelfIntersect(US->SelfIntersect());
108     // Compute Knots and KnotsMultiplicity for U Direction
109     const Standard_Integer nbKU = BSPL->NbControlPointsListI() + BSPL->UDegree() + 1;
110     const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
111     const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
112     for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
113       UKmult->SetValue(iU, 1);
114       UKnots->SetValue(iU, iU - 1.);
115     }
116     BSPL->SetUMultiplicities(UKmult);
117     BSPL->SetUKnots(UKnots);
118     // Compute Knots and KnotsMultiplicity for V Direction
119     const Standard_Integer nbKV = BSPL->NbControlPointsListJ() + BSPL->VDegree() + 1;
120     const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
121     const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
122     for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
123       VKmult->SetValue(iV, 1);
124       VKnots->SetValue(iV, iV - 1.);
125     }
126     BSPL->SetVMultiplicities(VKmult);
127     BSPL->SetVKnots(VKnots);
128         return StepToGeom_MakeBSplineSurface::Convert(BSPL,*((Handle(Geom_BSplineSurface)*)&CS));
129   }
130   if (SS->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformSurface))) {
131     const Handle(StepGeom_QuasiUniformSurface) QUS = 
132       Handle(StepGeom_QuasiUniformSurface)::DownCast(SS);
133     const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
134     BSPL->SetUDegree(QUS->UDegree());
135     BSPL->SetVDegree(QUS->VDegree());
136     BSPL->SetControlPointsList(QUS->ControlPointsList());
137     BSPL->SetSurfaceForm(QUS->SurfaceForm());
138     BSPL->SetUClosed(QUS->UClosed());
139     BSPL->SetVClosed(QUS->VClosed());
140     BSPL->SetSelfIntersect(QUS->SelfIntersect());
141     // Compute Knots and KnotsMultiplicity for U Direction
142     const Standard_Integer nbKU = BSPL->NbControlPointsListI() - BSPL->UDegree() + 1;
143     const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
144     const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
145     for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
146       UKmult->SetValue(iU, 1);
147       UKnots->SetValue(iU, iU - 1.);
148     }
149     UKmult->SetValue(1, BSPL->UDegree() + 1);
150     UKmult->SetValue(nbKU, BSPL->UDegree() + 1);
151     BSPL->SetUMultiplicities(UKmult);
152     BSPL->SetUKnots(UKnots);
153     // Compute Knots and KnotsMultiplicity for V Direction
154     const Standard_Integer nbKV = BSPL->NbControlPointsListJ() - BSPL->VDegree() + 1;
155     const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
156     const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
157     for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
158       VKmult->SetValue(iV, 1);
159       VKnots->SetValue(iV, iV - 1.);
160     }
161     VKmult->SetValue(1, BSPL->VDegree() + 1);
162     VKmult->SetValue(nbKV, BSPL->VDegree() + 1);
163     BSPL->SetVMultiplicities(VKmult);
164     BSPL->SetVKnots(VKnots);
165         return StepToGeom_MakeBSplineSurface::Convert(BSPL,*((Handle(Geom_BSplineSurface)*)&CS));
166   }
167   if (SS->IsKind(STANDARD_TYPE(StepGeom_UniformSurfaceAndRationalBSplineSurface))) {
168     const Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface) RUS = 
169       Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface)::DownCast(SS);
170     const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) RBSPL = 
171       new StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface;
172     // Compute Knots and KnotsMultiplicity for U Direction
173     const Standard_Integer nbKU = RUS->NbControlPointsListI() + RUS->UDegree() + 1;
174     const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
175     const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
176     for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
177       UKmult->SetValue(iU, 1);
178       UKnots->SetValue(iU, iU - 1.);
179     }
180     // Compute Knots and KnotsMultiplicity for V Direction
181     const Standard_Integer nbKV = RUS->NbControlPointsListJ() + RUS->VDegree() + 1;
182     const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
183     const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
184     for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
185       VKmult->SetValue(iV, 1);
186       VKnots->SetValue(iV, iV - 1.);
187     }
188     // Initialize the BSplineSurfaceWithKnotsAndRationalBSplineSurface
189     RBSPL->Init(RUS->Name(), RUS->UDegree(), RUS->VDegree(), 
190                 RUS->ControlPointsList(), RUS->SurfaceForm(),
191                 RUS->UClosed(), RUS->VClosed(), RUS->SelfIntersect(), 
192                 UKmult, VKmult, UKnots, VKnots, StepGeom_ktUnspecified,
193                 RUS->WeightsData());
194         return StepToGeom_MakeBSplineSurface::Convert(RBSPL,*((Handle(Geom_BSplineSurface)*)&CS));
195   }
196   if (SS->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface))) {
197     const Handle(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface) RQUS = 
198       Handle(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface)::DownCast(SS);
199     const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) RBSPL = 
200       new StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface;
201     // Compute Knots and KnotsMultiplicity for U Direction
202     const Standard_Integer nbKU = RQUS->NbControlPointsListI() - RQUS->UDegree() + 1;
203     const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
204     const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
205     for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
206       UKmult->SetValue(iU, 1);
207       UKnots->SetValue(iU, iU - 1.);
208     }
209     UKmult->SetValue(1, RQUS->UDegree() + 1);
210     UKmult->SetValue(nbKU, RQUS->UDegree() + 1);
211     // Compute Knots and KnotsMultiplicity for V Direction
212     const Standard_Integer nbKV = RQUS->NbControlPointsListJ() - RQUS->VDegree() + 1;
213     const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
214     const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
215     for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
216       VKmult->SetValue(iV, 1);
217       VKnots->SetValue(iV, iV - 1.);
218     }
219     VKmult->SetValue(1, RQUS->VDegree() + 1);
220     VKmult->SetValue(nbKV, RQUS->VDegree() + 1);
221     // Initialize the BSplineSurfaceWithKnotsAndRationalBSplineSurface
222     RBSPL->Init(RQUS->Name(), RQUS->UDegree(), RQUS->VDegree(), RQUS->ControlPointsList(), 
223                 RQUS->SurfaceForm(), RQUS->UClosed(), RQUS->VClosed(), 
224                 RQUS->SelfIntersect(), UKmult, VKmult, UKnots, VKnots, StepGeom_ktUnspecified,
225                 RQUS->WeightsData());
226         return StepToGeom_MakeBSplineSurface::Convert(RBSPL,*((Handle(Geom_BSplineSurface)*)&CS));
227   }
228 /* //:S4136: ass-tol2.stp #9861
229   // UPDATE FMA 15-03-96
230   // For BSplineSurface, the surface could be U and/or VClosed within the 
231   // file tolerance. In this case, the closure flag is enforced
232   
233   if (done && //:i6
234       theBoundedSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
235
236     Handle(Geom_BSplineSurface) theBSP = 
237       Handle(Geom_BSplineSurface)::DownCast(theBoundedSurface);
238     if (!theBSP->IsURational() &&
239         !theBSP->IsVRational()) {
240       StepToGeom_CheckSurfaceClosure CheckClose(theBSP);
241       theBoundedSurface = CheckClose.Surface();
242     }
243   }
244 */  
245   return Standard_False;
246 }