0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / GeomToStep / GeomToStep_MakeBSplineSurfaceWithKnots.cxx
1 // Created on: 1993-08-05
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
18 #include <Geom_BSplineSurface.hxx>
19 #include <GeomAbs_BSplKnotDistribution.hxx>
20 #include <GeomToStep_MakeBSplineSurfaceWithKnots.hxx>
21 #include <GeomToStep_MakeCartesianPoint.hxx>
22 #include <StdFail_NotDone.hxx>
23 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
24 #include <StepGeom_CartesianPoint.hxx>
25 #include <StepGeom_HArray2OfCartesianPoint.hxx>
26 #include <StepGeom_KnotType.hxx>
27 #include <TColgp_Array2OfPnt.hxx>
28 #include <TCollection_HAsciiString.hxx>
29 #include <TColStd_HArray1OfInteger.hxx>
30 #include <TColStd_HArray1OfReal.hxx>
31 #include <TColStd_HArray2OfReal.hxx>
32
33 //=============================================================================
34 // Creation d' une bspline_Surface_with_knots_and_rational_bspline_Surface de
35 // prostep a partir d' une BSplineSurface de Geom
36 //=============================================================================
37 GeomToStep_MakeBSplineSurfaceWithKnots::
38   GeomToStep_MakeBSplineSurfaceWithKnots( const
39     Handle(Geom_BSplineSurface)& BS )
40                                                                       
41 {
42   Handle(StepGeom_BSplineSurfaceWithKnots) BSWK;
43   Standard_Integer aUDegree, aVDegree, NU, NV, i, j, NUknots, NVknots, itampon;
44   Standard_Real rtampon;
45   Handle(StepGeom_CartesianPoint) Pt = new StepGeom_CartesianPoint; 
46   Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
47   StepGeom_BSplineSurfaceForm aSurfaceForm;
48   StepData_Logical aUClosed, aVClosed, aSelfIntersect;
49   Handle(TColStd_HArray1OfInteger) aUMultiplicities, aVMultiplicities;
50   Handle(TColStd_HArray1OfReal) aUKnots, aVKnots;
51   Handle(TColStd_HArray2OfReal) aWeightsData;
52   GeomAbs_BSplKnotDistribution UDistribution, VDistribution;
53   StepGeom_KnotType KnotSpec;
54
55   aUDegree = BS->UDegree();
56   aVDegree = BS->VDegree();
57
58   NU = BS->NbUPoles();
59   NV = BS->NbVPoles();
60   TColgp_Array2OfPnt P(1,NU,1,NV);
61   BS->Poles(P);
62   aControlPointsList = new StepGeom_HArray2OfCartesianPoint(1,NU,1,NV);
63   for ( i=P.LowerRow(); i<=P.UpperRow(); i++) {
64     for ( j=P.LowerCol(); j<=P.UpperCol(); j++) { 
65       GeomToStep_MakeCartesianPoint MkPoint(P.Value(i,j));
66       Pt = MkPoint.Value();
67       aControlPointsList->SetValue(i, j, Pt);
68     }
69   }
70
71   aSurfaceForm = StepGeom_bssfUnspecified;
72
73   if (BS->IsUClosed())
74     aUClosed = StepData_LTrue;
75   else
76     aUClosed = StepData_LFalse;
77
78   if (BS->IsVClosed())
79     aVClosed = StepData_LTrue;
80   else
81     aVClosed = StepData_LFalse;
82
83   aSelfIntersect = StepData_LFalse;
84
85   NUknots = BS->NbUKnots();
86   NVknots = BS->NbVKnots();
87   TColStd_Array1OfInteger MU(1,NUknots);
88   BS->UMultiplicities(MU);
89   aUMultiplicities = new TColStd_HArray1OfInteger(1,NUknots);
90   for ( i=MU.Lower(); i<=MU.Upper(); i++) { 
91     itampon = MU.Value(i);
92     aUMultiplicities->SetValue(i, itampon);
93   }
94   TColStd_Array1OfInteger MV(1,NVknots);
95   BS->VMultiplicities(MV);
96   aVMultiplicities = new TColStd_HArray1OfInteger(1,NVknots);
97   for ( i=MV.Lower(); i<=MV.Upper(); i++) { 
98     itampon = MV.Value(i);
99     aVMultiplicities->SetValue(i, itampon);
100   }
101   
102   TColStd_Array1OfReal KU(1,NUknots);
103   TColStd_Array1OfReal KV(1,NVknots);
104   BS->UKnots(KU);
105   BS->VKnots(KV);
106   aUKnots = new TColStd_HArray1OfReal(1,NUknots);
107   aVKnots = new TColStd_HArray1OfReal(1,NVknots);
108   for ( i=KU.Lower(); i<=KU.Upper(); i++) { 
109     rtampon = KU.Value(i);
110     aUKnots->SetValue(i, rtampon);
111   }
112   for ( i=KV.Lower(); i<=KV.Upper(); i++) { 
113     rtampon = KV.Value(i);
114     aVKnots->SetValue(i, rtampon);
115   }
116   
117   UDistribution = BS->UKnotDistribution();
118   VDistribution = BS->VKnotDistribution();
119   if ( UDistribution == GeomAbs_NonUniform &&
120        VDistribution == GeomAbs_NonUniform )
121     KnotSpec = StepGeom_ktUnspecified;
122   else if ( UDistribution == GeomAbs_Uniform &&
123             VDistribution == GeomAbs_Uniform )
124     KnotSpec = StepGeom_ktUniformKnots;
125   else if ( UDistribution == GeomAbs_QuasiUniform &&
126             VDistribution == GeomAbs_QuasiUniform )
127     KnotSpec = StepGeom_ktQuasiUniformKnots;
128   else if ( UDistribution == GeomAbs_PiecewiseBezier &&
129             VDistribution == GeomAbs_PiecewiseBezier )
130     KnotSpec = StepGeom_ktPiecewiseBezierKnots;
131   else 
132     KnotSpec = StepGeom_ktUnspecified;
133   
134   BSWK = new StepGeom_BSplineSurfaceWithKnots; 
135   Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString("");
136   BSWK->Init(name, aUDegree, aVDegree, aControlPointsList, aSurfaceForm, 
137              aUClosed, aVClosed, aSelfIntersect, aUMultiplicities, 
138              aVMultiplicities, aUKnots, aVKnots, KnotSpec );
139              
140   theBSplineSurfaceWithKnots = BSWK;
141   done = Standard_True;
142 }
143
144 //=============================================================================
145 // renvoi des valeurs
146 //=============================================================================
147
148 const Handle(StepGeom_BSplineSurfaceWithKnots) &
149       GeomToStep_MakeBSplineSurfaceWithKnots::Value() const
150 {
151   StdFail_NotDone_Raise_if (!done, "GeomToStep_MakeBSplineSurfaceWithKnots::Value() - no result");
152   return theBSplineSurfaceWithKnots;
153 }