Salome HOME
af058cc9143ee558ce2130566c14cc33a8c53545
[modules/shaper.git] / src / SketchPlugin / Test / TestRemoveBSplinePeriodic.py
1 # Copyright (C) 2019-2023  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21     Test removing peridoc B-spline curve and its construstion elements
22 """
23
24 from salome.shaper import model
25 from ModelAPI import *
26
27 def assertNbSubs(theSketch, theNbPoints, theNbLines, theNbSplines, theNbInternalConstraints):
28     model.testNbSubFeatures(theSketch, "SketchPoint", theNbPoints)
29     model.testNbSubFeatures(theSketch, "SketchLine", theNbLines)
30     model.testNbSubFeatures(theSketch, "SketchBSplinePeriodic", theNbSplines)
31     model.testNbSubFeatures(theSketch, "SketchConstraintCoincidenceInternal", theNbInternalConstraints)
32
33 model.begin()
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, periodic = True)
40 controlPoles = SketchBSpline_1.controlPoles(auxiliary = [0, 1, 2, 3, 4])
41 controlLines = SketchBSpline_1.controlPolygon(auxiliary = [0, 1, 2, 3, 4])
42 model.do()
43 model.end()
44
45 DEFAULT_DOF = len(SketchBSpline_1_poles) * 2
46 DEFAULT_POINTS = len(SketchBSpline_1_poles)
47 DEFAULT_LINES = len(SketchBSpline_1_poles)
48 DEFAULT_BSPLINES = 1
49 DEAFULT_INTERNALS = len(controlPoles) + len(controlLines) * 2
50
51 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
52 assert(model.dof(Sketch_1) == DEFAULT_DOF)
53
54 # Test 1. Remove auxiliary points one by one.
55 for pnt in controlPoles:
56     model.begin()
57     removeFeaturesAndReferences(FeatureSet([pnt.feature()]))
58     model.end()
59
60     assertNbSubs(Sketch_1, DEFAULT_POINTS - 1, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 1)
61     assert(model.dof(Sketch_1) == DEFAULT_DOF)
62     model.undo()
63     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
64     assert(model.dof(Sketch_1) == DEFAULT_DOF)
65
66 # Test 2. Remove auxiliary lines one by one.
67 for ln in controlLines:
68     model.begin()
69     removeFeaturesAndReferences(FeatureSet([ln.feature()]))
70     model.end()
71
72     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES - 1, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 2)
73     assert(model.dof(Sketch_1) == DEFAULT_DOF)
74     model.undo()
75     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
76     assert(model.dof(Sketch_1) == DEFAULT_DOF)
77
78 # Test 3. Remove the B-spline curve.
79 model.begin()
80 removeFeaturesAndReferences(FeatureSet([SketchBSpline_1.feature()]))
81 model.end()
82
83 assertNbSubs(Sketch_1, 0, 0, 0, 0)
84 assert(model.dof(Sketch_1) == 0)
85 model.undo()
86 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_BSPLINES, DEAFULT_INTERNALS)
87 assert(model.dof(Sketch_1) == DEFAULT_DOF)
88
89 # Test 4. Remove some construction elements, make non-auxiliary a couple of the rest and check the dumping.
90 model.begin()
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, periodic = True)
95 controlPoles2 = SketchBSpline_2.controlPoles(auxiliary = [0, 1, 2, 3, 4])
96 controlLines2 = SketchBSpline_2.controlPolygon(auxiliary = [0, 1, 2, 3, 4])
97 model.do()
98 model.end()
99
100 model.begin()
101 controlPoles2[1].setAuxiliary(False)
102 controlLines2[2].setAuxiliary(False)
103 removeFeaturesAndReferences(FeatureSet([controlPoles2[2].feature(), controlLines2[0].feature()]))
104 model.end()
105
106 assertNbSubs(Sketch_2, DEFAULT_POINTS - 1, DEFAULT_LINES - 1, DEFAULT_BSPLINES, DEAFULT_INTERNALS - 3)
107
108 assert(model.checkPythonDump())