1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15 
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
18 
19 #include <gp_GTrsf.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_XYZ.hxx>
22 #include <IGESGeom_BSplineCurve.hxx>
23 #include <Standard_DimensionMismatch.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <Standard_Type.hxx>
26 
IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_BSplineCurve,IGESData_IGESEntity)27 IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_BSplineCurve,IGESData_IGESEntity)
28 
29 IGESGeom_BSplineCurve::IGESGeom_BSplineCurve ()    {  }
30 
31 
Init(const Standard_Integer anIndex,const Standard_Integer aDegree,const Standard_Boolean aPlanar,const Standard_Boolean aClosed,const Standard_Boolean aPolynom,const Standard_Boolean aPeriodic,const Handle (TColStd_HArray1OfReal)& allKnots,const Handle (TColStd_HArray1OfReal)& allWeights,const Handle (TColgp_HArray1OfXYZ)& allPoles,const Standard_Real aUmin,const Standard_Real aUmax,const gp_XYZ & aNorm)32     void IGESGeom_BSplineCurve::Init
33   (const Standard_Integer anIndex,
34    const Standard_Integer aDegree, const Standard_Boolean aPlanar,
35    const Standard_Boolean aClosed, const Standard_Boolean aPolynom,
36    const Standard_Boolean aPeriodic,
37    const Handle(TColStd_HArray1OfReal)& allKnots,
38    const Handle(TColStd_HArray1OfReal)& allWeights,
39    const Handle(TColgp_HArray1OfXYZ)& allPoles,
40    const Standard_Real aUmin, const Standard_Real aUmax,
41    const gp_XYZ& aNorm)
42 {
43   if (!allPoles.IsNull())
44   {
45     if (allKnots->Lower() != -aDegree
46      || allKnots->Upper() != anIndex + 1
47      || allPoles->Lower() != 0)
48     {
49       throw Standard_DimensionMismatch ("IGESGeom_BSplineCurve : Init");
50     }
51     if (!allWeights.IsNull())
52     {
53       if (allPoles->Length() != allWeights->Length()
54        || allWeights->Upper() !=  anIndex
55        || allWeights->Lower() != 0)
56       {
57         throw Standard_DimensionMismatch ("IGESGeom_BSplineCurve : Init");
58       }
59     }
60   }
61 
62   theIndex     = anIndex;
63   theDegree    = aDegree;
64   isPlanar     = aPlanar;
65   isClosed     = aClosed;
66   isPolynomial = aPolynom;
67   isPeriodic   = aPeriodic;
68   theKnots     = allKnots;
69   theWeights   = allWeights;
70   thePoles     = allPoles;
71   theUmin      = aUmin;
72   theUmax      = aUmax;
73   theNorm      = aNorm;
74   InitTypeAndForm(126,FormNumber());
75 // FormNumber  precises the shape  0-5
76 }
77 
SetFormNumber(const Standard_Integer form)78     void  IGESGeom_BSplineCurve::SetFormNumber (const Standard_Integer form)
79 {
80   if (form < 0 || form > 5) throw Standard_OutOfRange("IGESGeom_BSplineCurve : SetFormNumber");
81   InitTypeAndForm(126,form);
82 }
83 
UpperIndex() const84     Standard_Integer IGESGeom_BSplineCurve::UpperIndex () const
85 {
86   return theIndex;
87 }
88 
Degree() const89     Standard_Integer IGESGeom_BSplineCurve::Degree () const
90 {
91   return theDegree;
92 }
93 
IsPlanar() const94     Standard_Boolean IGESGeom_BSplineCurve::IsPlanar () const
95 {
96   return isPlanar;
97 }
98 
IsClosed() const99     Standard_Boolean IGESGeom_BSplineCurve::IsClosed () const
100 {
101   return isClosed;
102 }
103 
IsPolynomial(const Standard_Boolean flag) const104     Standard_Boolean IGESGeom_BSplineCurve::IsPolynomial
105   (const Standard_Boolean flag) const
106 {
107   if (flag || theWeights.IsNull()) return isPolynomial;
108   Standard_Integer i, i1 = theWeights->Lower(), i2 = theWeights->Upper();
109   Standard_Real w0 = theWeights->Value(i1);
110   for (i = i1+1; i <= i2; i ++)
111     if (Abs (theWeights->Value(i) - w0) > 1.e-10) return Standard_False;
112   return Standard_True;
113 }
114 
IsPeriodic() const115     Standard_Boolean IGESGeom_BSplineCurve::IsPeriodic () const
116 {
117   return isPeriodic;
118 }
119 
NbKnots() const120     Standard_Integer IGESGeom_BSplineCurve::NbKnots () const
121 {
122   return (theKnots.IsNull() ? 0 : theKnots->Length());
123 }
124 
Knot(const Standard_Integer anIndex) const125     Standard_Real IGESGeom_BSplineCurve::Knot
126   (const Standard_Integer anIndex) const
127 {
128   return theKnots->Value(anIndex);
129 }
130 
NbPoles() const131     Standard_Integer IGESGeom_BSplineCurve::NbPoles () const
132 {
133   return (thePoles.IsNull() ? 0 : thePoles->Length());
134 }
135 
Weight(const Standard_Integer anIndex) const136     Standard_Real IGESGeom_BSplineCurve::Weight
137   (const Standard_Integer anIndex) const
138 {
139   return theWeights->Value(anIndex);
140 }
141 
Pole(const Standard_Integer anIndex) const142     gp_Pnt IGESGeom_BSplineCurve::Pole (const Standard_Integer anIndex) const
143 {
144   gp_XYZ tempXYZ = thePoles->Value(anIndex);
145   gp_Pnt Pole(tempXYZ);
146   return Pole;
147 }
148 
TransformedPole(const Standard_Integer anIndex) const149     gp_Pnt IGESGeom_BSplineCurve::TransformedPole
150   (const Standard_Integer anIndex) const
151 {
152   gp_XYZ tempXYZ = thePoles->Value(anIndex);
153   if (HasTransf()) Location().Transforms(tempXYZ);
154   gp_Pnt Pole(tempXYZ);
155   return Pole;
156 }
157 
UMin() const158     Standard_Real IGESGeom_BSplineCurve::UMin () const
159 {
160   return theUmin;
161 }
162 
UMax() const163     Standard_Real IGESGeom_BSplineCurve::UMax () const
164 {
165   return theUmax;
166 }
167 
Normal() const168     gp_XYZ IGESGeom_BSplineCurve::Normal () const
169 {
170   return theNorm;
171 }
172