1 # Copyright (C) 2019 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 ellipse and its construstion elements
24 from salome.shaper import model
25 from ModelAPI import *
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)
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")
47 DEAFULT_INTERNALS = 11
49 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
50 assert(model.dof(Sketch_1) == DEFAULT_DOF)
52 # Test 1. Remove auxiliary points one by one.
53 points = [Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd]
56 removeFeaturesAndReferences(FeatureSet([pnt.feature()]))
59 assertNbSubs(Sketch_1, DEFAULT_POINTS - 1, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 1)
60 assert(model.dof(Sketch_1) == DEFAULT_DOF)
62 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
63 assert(model.dof(Sketch_1) == DEFAULT_DOF)
65 # Test 2. Remove auxiliary axes one by one.
66 lines = [MajorAxisLine, MinorAxisLine]
69 removeFeaturesAndReferences(FeatureSet([ln.feature()]))
72 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 2)
73 assert(model.dof(Sketch_1) == DEFAULT_DOF)
75 assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS)
76 assert(model.dof(Sketch_1) == DEFAULT_DOF)
78 # Test 3. Remove the ellipse.
80 removeFeaturesAndReferences(FeatureSet([SketchEllipse_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_ELLIPSES, 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 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")
98 removeFeaturesAndReferences(FeatureSet([MajorAxisLine.feature(), Focus2.feature()]))
99 Focus1.setAuxiliary(False)
100 MinorAxisEnd.setAuxiliary(False)
103 assertNbSubs(Sketch_2, DEFAULT_POINTS - 1, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 3)
104 assert(model.dof(Sketch_2) == DEFAULT_DOF)
106 assert(model.checkPythonDump())