1 # Copyright (C) 2020-2021 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Test creation of B-spline curve
25 from salome.shaper import model
28 from SketchAPI import *
30 __updated__ = "2020-01-17"
32 class TestBSpline(unittest.TestCase):
35 self.myDocument = model.moduleDocument()
36 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
37 self.myPoles = [GeomAPI_Pnt2d(50., 50.), GeomAPI_Pnt2d(70., 70.), GeomAPI_Pnt2d(80., 30.), GeomAPI_Pnt2d(50., 10.), GeomAPI_Pnt2d(10., -30.)]
38 self.myPolesCoordinates = [(50., 50.), (70., 70.), (80., 30.), (50., 10.), (10., -30.)]
48 model.testNbSubFeatures(self.mySketch, "SketchPoint", self.myNbPoints)
49 model.testNbSubFeatures(self.mySketch, "SketchLine", self.myNbLines)
50 model.testNbSubFeatures(self.mySketch, "SketchBSpline", self.myNbSplines)
54 self.assertEqual(model.dof(self.mySketch), self.myDOF)
57 def test_bspline_by_coordinates(self):
58 """ Test 1. Create B-spline curve by coordinates of its poles
60 self.mySpline = self.mySketch.addSpline(poles = self.myPolesCoordinates)
61 self.myDOF += len(self.myPolesCoordinates) * 2
65 assert(self.mySpline.feature())
66 assert(self.mySpline.feature().error() == "")
67 assert(self.mySpline.degree().value() == self.myDegree)
69 def test_bspline_by_poles(self):
70 """ Test 2. Create B-spline curve by poles
72 self.mySpline = self.mySketch.addSpline(poles = self.myPoles)
73 self.myDOF += len(self.myPoles) * 2
77 assert(self.mySpline.feature())
78 assert(self.mySpline.feature().error() == "")
79 assert(self.mySpline.degree().value() == self.myDegree)
81 def test_bspline_by_degree_and_poles(self):
82 """ Test 3. Create B-spline curve by poles and degree
85 self.mySpline = self.mySketch.addSpline(degree = self.myDegree, poles = self.myPoles)
86 self.myDOF += len(self.myPoles) * 2
90 assert(self.mySpline.feature())
91 assert(self.mySpline.feature().error() == "")
92 assert(self.mySpline.degree().value() == self.myDegree)
94 def test_bspline_by_poles_and_weights(self):
95 """ Test 4. Create B-spline curve by poles and weights
97 self.mySpline = self.mySketch.addSpline(poles = self.myPoles, weights = [1, 2, 3, 2, 1])
98 self.myDOF += len(self.myPoles) * 2
102 assert(self.mySpline.feature())
103 assert(self.mySpline.feature().error() == "")
104 assert(self.mySpline.degree().value() == self.myDegree)
106 def test_bspline_by_parametric(self):
107 """ Test 5. Create B-spline curve by whole set of parameters
110 self.myPolesCoordinates = [(-79.8578274581199, 75.5284518447357),
111 (-64.6205376770376, 62.7428476092882),
112 (-49.3832478959552, 49.9572433738407),
113 (-34.1459581148729, 37.1716391383932),
114 (-18.9086683337906, 24.3860349029457),
115 (-3.55842111132817, 11.5056481200973),
116 (-3.37993197286247, 11.42995541724),
117 (-3.1778022626919, 11.4565662984205),
118 (-3.02498570721059, 11.575876223351),
119 (8.46852511720001, 27.9903107977019),
120 (19.8774589601206, 44.2839569245217),
121 (31.2863928030413, 60.5776030513415),
122 (42.6953266459619, 76.8712491781612),
123 (54.1042604888826, 93.164895304981)
125 self.mySpline = self.mySketch.addSpline(degree = self.myDegree,
126 poles = self.myPolesCoordinates,
127 weights = [1, 1, 1, 1, 1, 1, 0.957903314642061, 0.95790331464206, 1, 1, 1, 1, 1, 1],
128 knots = [-494.543457494654, 500, 507.372773368102, 1501.91623086297],
129 multiplicities = [6, 4, 4, 6])
130 self.myDOF += len(self.myPolesCoordinates) * 2
131 self.myNbSplines += 1
134 assert(self.mySpline.feature())
135 assert(self.mySpline.feature().error() == "")
136 assert(self.mySpline.degree().value() == self.myDegree)
138 def test_bspline_linear(self):
139 """ Test 6. Create B-spline curve by 2 poles
142 self.mySpline = self.mySketch.addSpline(poles = self.myPoles[:2])
144 self.myNbSplines += 1
147 assert(self.mySpline.feature())
148 assert(self.mySpline.feature().error() == "")
149 assert(self.mySpline.degree().value() == self.myDegree)
151 def test_bspline_parabola(self):
152 """ Test 7. Create B-spline curve by 3 poles
155 self.mySpline = self.mySketch.addSpline(poles = self.myPoles[:3])
157 self.myNbSplines += 1
160 assert(self.mySpline.feature())
161 assert(self.mySpline.feature().error() == "")
162 assert(self.mySpline.degree().value() == self.myDegree)
164 def test_bspline_with_poles(self):
165 """ Test 8. Create B-spline curve and points coincident with its poles
167 self.mySpline = self.mySketch.addSpline(poles = self.myPoles)
168 self.mySpline.controlPoles(regular = [0, 2], auxiliary = [1, 3])
169 self.myDOF += len(self.myPoles) * 2
170 self.myNbSplines += 1
174 assert(self.mySpline.feature())
175 assert(self.mySpline.feature().error() == "")
176 assert(self.mySpline.degree().value() == self.myDegree)
178 def test_bspline_with_polygon(self):
179 """ Test 9. Create B-spline curve and its control polygon
181 self.mySpline = self.mySketch.addSpline(poles = self.myPoles)
182 self.mySpline.controlPolygon(regular = [0, 2], auxiliary = [1, 3])
183 self.myDOF += len(self.myPoles) * 2
184 self.myNbSplines += 1
188 assert(self.mySpline.feature())
189 assert(self.mySpline.feature().error() == "")
190 assert(self.mySpline.degree().value() == self.myDegree)
192 if __name__ == "__main__":
193 test_program = unittest.main(exit=False)
194 assert test_program.result.wasSuccessful(), "Test failed"
195 assert model.checkPythonDump()