1 # Copyright (C) 2020 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 periodic B-spline curve
25 from salome.shaper import model
28 from SketchAPI import *
30 __updated__ = "2020-01-24"
32 class TestBSplinePeriodic(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, "SketchBSplinePeriodic", 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, periodic = True)
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, periodic = True)
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, periodic = True)
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], periodic = True)
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 = [(-10, 0), (-20, 20), (0, 10), (20, 20),
111 (10, 0), (20, -20), (0, -10), (-20, -20)
113 self.mySpline = self.mySketch.addSpline(degree = self.myDegree,
114 poles = self.myPolesCoordinates,
115 weights = [1, 1, 1, 1, 1, 1, 1, 1],
116 knots = [0, 1, 2, 3, 4, 5, 6, 7, 8],
117 multiplicities = [1, 1, 1, 1, 1, 1, 1, 1, 1],
119 self.myDOF += len(self.myPolesCoordinates) * 2
120 self.myNbSplines += 1
123 assert(self.mySpline.feature())
124 assert(self.mySpline.feature().error() == "")
125 assert(self.mySpline.degree().value() == self.myDegree)
127 def test_bspline_linear(self):
128 """ Test 6. Create B-spline curve by 2 poles
131 self.mySpline = self.mySketch.addSpline(poles = self.myPoles[:2], periodic = True)
133 self.myNbSplines += 1
136 assert(self.mySpline.feature())
137 assert(self.mySpline.feature().error() == "")
138 assert(self.mySpline.degree().value() == self.myDegree)
140 def test_bspline_parabola(self):
141 """ Test 7. Create B-spline curve by 3 poles
144 self.mySpline = self.mySketch.addSpline(poles = self.myPoles[:3], periodic = True)
146 self.myNbSplines += 1
149 assert(self.mySpline.feature())
150 assert(self.mySpline.feature().error() == "")
151 assert(self.mySpline.degree().value() == self.myDegree)
153 def test_bspline_with_poles(self):
154 """ Test 8. Create B-spline curve and points coincident with its poles
156 self.mySpline = self.mySketch.addSpline(poles = self.myPoles, periodic = True)
157 self.mySpline.controlPoles(regular = [0, 2], auxiliary = [1, 3])
158 self.myDOF += len(self.myPoles) * 2
159 self.myNbSplines += 1
163 assert(self.mySpline.feature())
164 assert(self.mySpline.feature().error() == "")
165 assert(self.mySpline.degree().value() == self.myDegree)
167 def test_bspline_with_polygon(self):
168 """ Test 9. Create B-spline curve and its control polygon
170 self.mySpline = self.mySketch.addSpline(poles = self.myPoles, periodic = True)
171 self.mySpline.controlPolygon(regular = [0, 2], auxiliary = [1, 3])
172 self.myDOF += len(self.myPoles) * 2
173 self.myNbSplines += 1
177 assert(self.mySpline.feature())
178 assert(self.mySpline.feature().error() == "")
179 assert(self.mySpline.degree().value() == self.myDegree)
181 if __name__ == "__main__":
182 test_program = unittest.main(exit=False)
183 assert test_program.result.wasSuccessful(), "Test failed"
184 assert model.checkPythonDump()