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 for adding a pole to already created B-spline curve
24 from salome.shaper import model
30 def assertSubFeatures(theSketch, theNbPoints, theNbLines, theNbSplines, theNbSplinesP, theNbCoincidences, theNbInternal):
31 model.testNbSubFeatures(theSketch, "SketchPoint", theNbPoints)
32 model.testNbSubFeatures(theSketch, "SketchLine", theNbLines)
33 model.testNbSubFeatures(theSketch, "SketchBSpline", theNbSplines)
34 model.testNbSubFeatures(theSketch, "SketchBSplinePeriodic", theNbSplinesP)
35 model.testNbSubFeatures(theSketch, "SketchConstraintCoincidence", theNbCoincidences)
36 model.testNbSubFeatures(theSketch, "SketchConstraintCoincidenceInternal", theNbInternal)
38 def assertPoles(thePoles, theReference):
39 assert(thePoles.size() == len(theReference))
40 for ind in range(0, len(theReference)):
41 pole = thePoles.pnt(ind)
42 ref = GeomAPI_Pnt2d(theReference[ind][0], theReference[ind][1])
43 assert(model.distancePointPoint(pole, ref) < TOLERANCE), "Index = {}, pole = ({}, {}), refdata = ({}, {})".format(ind, pole.x(), pole.y(), ref.x(), ref.y())
47 partSet = model.moduleDocument()
48 Part_1 = model.addPart(partSet)
49 Part_1_doc = Part_1.document()
50 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
52 SketchBSpline_1_poles = [(-25, 5), (-15, 35), (15, 35), (28, 5)]
53 SketchBSpline_1 = Sketch_1.addSpline(poles = SketchBSpline_1_poles)
54 [SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4] = SketchBSpline_1.controlPoles(auxiliary = [0, 1, 2, 3])
55 [SketchLine_1, SketchLine_2, SketchLine_3] = SketchBSpline_1.controlPolygon(auxiliary = [0, 1, 2])
57 SketchBSplinePeriodic_1_poles = [(-20, -10), (20, -40), (20, -10), (-20, -40)]
58 SketchBSplinePeriodic_1 = Sketch_1.addSpline(poles = SketchBSplinePeriodic_1_poles, periodic = True)
59 [SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchPoint_8] = SketchBSplinePeriodic_1.controlPoles(auxiliary = [0, 1, 2, 3])
60 [SketchLine_4, SketchLine_5, SketchLine_6, SketchLine_7] = SketchBSplinePeriodic_1.controlPolygon(auxiliary = [0, 1, 2, 3])
63 # check original values
70 assertSubFeatures(Sketch_1, NBPOINTS, NBLINES, NBSPLINES, NBSPLINESPERIODIC, NBCOINCIDENCES, NBINTERNAL)
71 assertPoles(SketchBSpline_1.poles(), SketchBSpline_1_poles)
72 assertPoles(SketchBSplinePeriodic_1.poles(), SketchBSplinePeriodic_1_poles)
74 # add poles to non-periodic B-spline
76 while ind < len(SketchBSpline_1_poles):
77 x = random.uniform(-25, 25)
78 y = random.uniform(5, 40)
79 SketchBSpline_1.insertPole(ind, GeomAPI_Pnt2d(x, y))
80 if ind + 1 < len(SketchBSpline_1_poles):
81 SketchBSpline_1_poles.insert(ind + 1, (x, y))
83 SketchBSpline_1_poles.insert(len(SketchBSpline_1_poles) - 1, (x, y))
90 assertSubFeatures(Sketch_1, NBPOINTS, NBLINES, NBSPLINES, NBSPLINESPERIODIC, NBCOINCIDENCES, NBINTERNAL)
91 assertPoles(SketchBSpline_1.poles(), SketchBSpline_1_poles)
93 # add poles to periodic B-spline
95 while ind < len(SketchBSplinePeriodic_1_poles):
96 x = random.uniform(-25, 25)
97 y = random.uniform(-45, -5)
98 SketchBSplinePeriodic_1.insertPole(ind, GeomAPI_Pnt2d(x, y))
99 SketchBSplinePeriodic_1_poles.insert(ind + 1, (x, y))
106 assertSubFeatures(Sketch_1, NBPOINTS, NBLINES, NBSPLINES, NBSPLINESPERIODIC, NBCOINCIDENCES, NBINTERNAL)
107 assertPoles(SketchBSplinePeriodic_1.poles(), SketchBSplinePeriodic_1_poles)
111 # check error on incorrect action
113 assert(not SketchBSpline_1.feature().customAction("wrong_action"))
116 #assert(model.checkPythonDump())