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 B-spline curve by references to another features
25 from salome.shaper import model
28 from GeomDataAPI import *
29 from ModelAPI import *
30 from SketchAPI import *
32 __updated__ = "2020-01-31"
34 class TestMacroBSpline(unittest.TestCase):
37 self.myDocument = model.moduleDocument()
38 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
39 self.myPoint = self.mySketch.addPoint(50., 50.)
40 self.myLine = self.mySketch.addLine(30., -1., 70., 19.)
42 self.myPoles = [[GeomAPI_Pnt2d(50., 50.), self.myPoint.coordinates()],
43 GeomAPI_Pnt2d(70., 70.),
45 [GeomAPI_Pnt2d(50., 10.), self.myLine.result()],
46 GeomAPI_Pnt2d(20., 10.)
55 self.myNbCoincidences = 0
61 model.testNbSubFeatures(self.mySketch, "SketchPoint", self.myNbPoints)
62 model.testNbSubFeatures(self.mySketch, "SketchLine", self.myNbLines)
63 model.testNbSubFeatures(self.mySketch, "SketchBSpline", self.myNbSplines)
64 model.testNbSubFeatures(self.mySketch, "SketchBSplinePeriodic", self.myNbSplinesP)
65 model.testNbSubFeatures(self.mySketch, "SketchMacroBSpline", 0)
66 model.testNbSubFeatures(self.mySketch, "SketchMacroBSplinePeriodic", 0)
67 model.testNbSubFeatures(self.mySketch, "SketchConstraintCoincidence", self.myNbCoincidences)
68 model.testNbSubFeatures(self.mySketch, "SketchConstraintCoincidenceInternal", self.myNbInternal)
72 self.assertEqual(model.dof(self.mySketch), self.myDOF)
75 def test_bspline_non_periodic(self):
76 """ Test 1. Create B-spline curve by poles and references to other shapes
78 self.mySpline = self.mySketch.addSpline(poles = self.myPoles)
79 self.myDOF += len(self.myPoles) * 2 - 3
81 self.myNbPoints += len(self.myPoles)
82 self.myNbLines += len(self.myPoles) - 1
83 self.myNbCoincidences += 2
84 self.myNbInternal += len(self.myPoles) * 3 - 2
87 assert(self.mySpline.feature())
88 assert(self.mySpline.feature().error() == "")
89 assert(self.mySpline.degree().value() == self.myDegree)
91 def test_bspline_periodic(self):
92 """ Test 2. Create periodic B-spline curve by poles and references to other shapes
94 self.mySpline = self.mySketch.addSpline(poles = self.myPoles, periodic = True)
95 self.myDOF += len(self.myPoles) * 2 - 3
96 self.myNbSplinesP += 1
97 self.myNbPoints += len(self.myPoles)
98 self.myNbLines += len(self.myPoles)
99 self.myNbCoincidences += 2
100 self.myNbInternal += len(self.myPoles) * 3
103 assert(self.mySpline.feature())
104 assert(self.mySpline.feature().error() == "")
105 assert(self.mySpline.degree().value() == self.myDegree)
107 def test_bspline_lowlevel(self):
108 """ Test 3. Create macro B-spline on low-level to test attributeRefAttrList
111 session = ModelAPI_Session.get()
112 sketch = featureToCompositeFeature(self.mySketch.feature())
113 session.startOperation()
114 bspline = sketch.addFeature("SketchMacroBSpline")
115 poles = geomDataAPI_Point2DArray(bspline.attribute("poles"))
116 weights = bspline.data().realArray("weights")
117 polesRef = bspline.data().refattrlist("poles_ref")
118 bspline.boolean("need_control_poly").setValue(False)
120 poles.setSize(3); weights.setSize(3)
121 poles.setPnt(0, GeomAPI_Pnt2d(50., 50.)); weights.setValue(0, 1.0); polesRef.append(self.myPoint.coordinates())
122 poles.setPnt(1, GeomAPI_Pnt2d(50., 10.)); weights.setValue(1, 1.0); polesRef.append(self.myLine.defaultResult())
123 poles.setPnt(2, GeomAPI_Pnt2d(20., 10.)); weights.setValue(2, 1.0); polesRef.append(None)
125 assert(polesRef.isInList(self.myPoint.coordinates()))
126 assert(not polesRef.isInList(self.myLine.startPoint()))
127 assert(polesRef.isInList(self.myLine.defaultResult()))
128 assert(not polesRef.isInList(self.myPoint.defaultResult()))
130 assert(polesRef.isAttribute(0))
131 assert(not polesRef.isAttribute(1))
132 assert(not polesRef.isAttribute(2))
133 assert(not polesRef.isAttribute(3))
135 assert(polesRef.attribute(0) is not None)
136 assert(polesRef.attribute(1) is None)
137 assert(polesRef.attribute(2) is None)
138 assert(polesRef.attribute(3) is None)
139 assert(polesRef.object(0) is not None)
140 assert(polesRef.object(1) is not None)
141 assert(polesRef.object(2) is None)
142 assert(polesRef.object(3) is None)
144 polesRef.remove(self.myPoint.coordinates())
145 polesRef.remove(self.myLine.defaultResult())
146 assert(polesRef.size() == 1)
147 polesRef.removeLast()
149 polesRef.append(self.myPoint.coordinates())
150 polesRef.append(None)
151 polesRef.append(self.myLine.defaultResult())
152 polesRef.removeLast()
153 polesRef.append(self.myLine.defaultResult())
155 session.finishOperation()
158 self.myNbSplines += 1
160 if __name__ == "__main__":
161 test_program = unittest.main(exit=False)
162 assert test_program.result.wasSuccessful(), "Test failed"
163 assert model.checkPythonDump()