Salome HOME
9b6d6782bf60ede73675e62c595a5ba367e8ba6c
[modules/shaper.git] / src / SketchPlugin / Test / TestRemoveEllipse.py
1 # Copyright (C) 2019-2021  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 ellipse and its construstion elements
22 """
23
24 from salome.shaper import model
25 from ModelAPI import *
26
27 def assertNbSubs(theSketch, theNbPoints, theNbLines, theNbEllipses, theNbInternalConstraints):
28     model.testNbSubFeatures(theSketch, "SketchPoint", theNbPoints)
29     model.testNbSubFeatures(theSketch, "SketchLine", theNbLines)
30     model.testNbSubFeatures(theSketch, "SketchEllipse", theNbEllipses)
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 SketchEllipse_1 = Sketch_1.addEllipse(40, 30, 70, 40, 20)
39 [Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd, MajorAxisLine, MinorAxisLine] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
40 model.do()
41 model.end()
42
43 DEFAULT_DOF = 5
44 DEFAULT_POINTS = 7
45 DEFAULT_LINES = 2
46 DEFAULT_ELLIPSES = 1
47 DEAFULT_INTERNALS = 11
48
49 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
50 assert(model.dof(Sketch_1) == DEFAULT_DOF)
51
52 # Test 1. Remove auxiliary points one by one.
53 points = [Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd]
54 for pnt in points:
55     model.begin()
56     removeFeaturesAndReferences(FeatureSet([pnt.feature()]))
57     model.end()
58
59     assertNbSubs(Sketch_1, DEFAULT_POINTS - 1, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 1)
60     assert(model.dof(Sketch_1) == DEFAULT_DOF)
61     model.undo()
62     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
63     assert(model.dof(Sketch_1) == DEFAULT_DOF)
64
65 # Test 2. Remove auxiliary axes one by one.
66 lines = [MajorAxisLine, MinorAxisLine]
67 for ln in lines:
68     model.begin()
69     removeFeaturesAndReferences(FeatureSet([ln.feature()]))
70     model.end()
71
72     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 2)
73     assert(model.dof(Sketch_1) == DEFAULT_DOF)
74     model.undo()
75     assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
76     assert(model.dof(Sketch_1) == DEFAULT_DOF)
77
78 # Test 3.  Remove the ellipse.
79 model.begin()
80 removeFeaturesAndReferences(FeatureSet([SketchEllipse_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_ELLIPSES, 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 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
92 SketchEllipse_2 = Sketch_2.addEllipse(40, -30, 70, 0, 10)
93 [Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd, MajorAxisLine, MinorAxisLine] = SketchEllipse_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
94 model.do()
95 model.end()
96
97 model.begin()
98 removeFeaturesAndReferences(FeatureSet([MajorAxisLine.feature(), Focus2.feature()]))
99 Focus1.setAuxiliary(False)
100 MinorAxisEnd.setAuxiliary(False)
101 model.end()
102
103 assertNbSubs(Sketch_2, DEFAULT_POINTS - 1, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 3)
104 assert(model.dof(Sketch_2) == DEFAULT_DOF)
105
106 assert(model.checkPythonDump())