1 # Copyright (C) 2019-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 removing B-spline curve and its construstion elements
24 from salome.shaper import model
25 from ModelAPI import *
27 def assertNbSubs(theSketch, theNbPoints, theNbLines, theNbSplines, theNbInternalConstraints):
28 model.testNbSubFeatures(theSketch, "SketchPoint", theNbPoints)
29 model.testNbSubFeatures(theSketch, "SketchLine", theNbLines)
30 model.testNbSubFeatures(theSketch, "SketchBSpline", theNbSplines)
31 model.testNbSubFeatures(theSketch, "SketchConstraintCoincidenceInternal", theNbInternalConstraints)
34 partSet = model.moduleDocument()
35 Part_1 = model.addPart(partSet)
36 Part_1_doc = Part_1.document()
37 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
38 SketchBSpline_1_poles = [(-30, -10), (-15, 20), (0, -10), (15, 20), (30, -10)]
39 SketchBSpline_1 = Sketch_1.addSpline(poles = SketchBSpline_1_poles)
40 controlPoles = SketchBSpline_1.controlPoles(auxiliary = [0, 1, 2, 3, 4])
41 controlLines = SketchBSpline_1.controlPolygon(auxiliary = [0, 1, 2, 3])
45 DEFAULT_DOF = len(SketchBSpline_1_poles) * 2
46 DEFAULT_POINTS = len(SketchBSpline_1_poles)
47 DEFAULT_LINES = len(SketchBSpline_1_poles) - 1
49 DEAFULT_INTERNALS = len(controlPoles) + len(controlLines) * 2
51 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
52 assert(model.dof(Sketch_1) == DEFAULT_DOF)
54 # Test 1. Remove auxiliary points one by one.
55 for pnt in controlPoles:
57 removeFeaturesAndReferences(FeatureSet([pnt.feature()]))
60 assertNbSubs(Sketch_1, DEFAULT_POINTS - 1, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 1)
61 assert(model.dof(Sketch_1) == DEFAULT_DOF)
63 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
64 assert(model.dof(Sketch_1) == DEFAULT_DOF)
66 # Test 2. Remove auxiliary lines one by one.
67 for ln in controlLines:
69 removeFeaturesAndReferences(FeatureSet([ln.feature()]))
72 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES - 1, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 2)
73 assert(model.dof(Sketch_1) == DEFAULT_DOF)
75 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
76 assert(model.dof(Sketch_1) == DEFAULT_DOF)
78 # Test 3. Remove the B-spline curve.
80 removeFeaturesAndReferences(FeatureSet([SketchBSpline_1.feature()]))
83 assertNbSubs(Sketch_1, 0, 0, 0, 0)
84 assert(model.dof(Sketch_1) == 0)
86 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
87 assert(model.dof(Sketch_1) == DEFAULT_DOF)
89 # Test 4. Remove some construction elements, make non-auxiliary a couple of the rest and check the dumping.
91 partSet = model.moduleDocument()
92 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
93 SketchBSpline_2_poles = [(-30, -10), (-15, -40), (0, -10), (15, -40), (30, -10)]
94 SketchBSpline_2 = Sketch_2.addSpline(poles = SketchBSpline_2_poles)
95 controlPoles2 = SketchBSpline_2.controlPoles(auxiliary = [0, 1, 2, 3, 4])
96 controlLines2 = SketchBSpline_2.controlPolygon(auxiliary = [0, 1, 2, 3])
101 controlPoles2[1].setAuxiliary(False)
102 controlLines2[2].setAuxiliary(False)
103 removeFeaturesAndReferences(FeatureSet([controlPoles2[2].feature(), controlLines2[0].feature()]))
106 assertNbSubs(Sketch_2, DEFAULT_POINTS - 1, DEFAULT_LINES - 1, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 3)
108 assert(model.checkPythonDump())