Salome HOME
36a8208560d7b5fe0eac770092968271f04888eb
[modules/shaper.git] / test.API / SHAPER / Primitives / TestSphere.py
1 # Copyright (C) 2017-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 from salome.shaper import model
20
21 model.begin()
22 partSet = model.moduleDocument()
23 Part_1 = model.addPart(partSet)
24 Part_1_doc = Part_1.document()
25
26 # Init
27 Point_1 = model.addPoint(Part_1_doc, 10, 10, 10).result()
28 Point_2 = model.selection("VERTEX", "pnt")
29
30 # Parameters
31 model.addParameter(Part_1_doc, "r", "5")
32
33 # Tests
34 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10)
35 Sphere_2 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 0)
36 Sphere_3 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), -5)
37 Sphere_4 = model.addSphere(Part_1_doc, Point_1, 10)
38 Sphere_5 = model.addSphere(Part_1_doc, Point_2, 10)
39 Sphere_6 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), "r")
40
41 Sphere_7 = model.addSphere(Part_1_doc, 10)
42 Sphere_7.setCenterPoint(Point_1)
43
44 Sphere_8 = model.addSphere(Part_1_doc,10,40,0,180,0,180)
45 Sphere_9 = model.addSphere(Part_1_doc,40,10,0,180,0,180)
46
47 model.do()
48 model.end()
49
50 # Checks
51 from GeomAPI import GeomAPI_Shape
52
53 model.testNbResults(Sphere_1, 1)
54 model.testNbSubResults(Sphere_1, [0])
55 model.testNbSubShapes(Sphere_1, GeomAPI_Shape.SOLID, [1])
56 model.testNbSubShapes(Sphere_1, GeomAPI_Shape.FACE, [1])
57 model.testHaveNamingFaces(Sphere_1, model, Part_1_doc)
58
59 model.testNbResults(Sphere_4, 1)
60 model.testNbSubResults(Sphere_4, [0])
61 model.testNbSubShapes(Sphere_4, GeomAPI_Shape.SOLID, [1])
62 model.testNbSubShapes(Sphere_4, GeomAPI_Shape.FACE, [1])
63 model.testHaveNamingFaces(Sphere_4, model, Part_1_doc)
64
65 model.testNbResults(Sphere_6, 1)
66 model.testNbSubResults(Sphere_6, [0])
67 model.testNbSubShapes(Sphere_6, GeomAPI_Shape.SOLID, [1])
68 model.testNbSubShapes(Sphere_6, GeomAPI_Shape.FACE, [1])
69 model.testHaveNamingFaces(Sphere_6, model, Part_1_doc)
70
71 model.testNbResults(Sphere_7, 1)
72 model.testNbSubResults(Sphere_7, [0])
73 model.testNbSubShapes(Sphere_7, GeomAPI_Shape.SOLID, [1])
74 model.testNbSubShapes(Sphere_7, GeomAPI_Shape.FACE, [1])
75 model.testHaveNamingFaces(Sphere_7, model, Part_1_doc)
76
77 model.testNbResults(Sphere_8, 1)
78 model.testNbSubResults(Sphere_8, [0])
79 model.testNbSubShapes(Sphere_8, GeomAPI_Shape.SOLID, [1])
80 model.testNbSubShapes(Sphere_8, GeomAPI_Shape.FACE, [4])
81 model.testHaveNamingFaces(Sphere_8, model, Part_1_doc)
82
83 model.testNbResults(Sphere_2, 0)
84 assert(Sphere_2.feature().error() == "Sphere builder :: radius is negative or null.")
85
86 model.testNbResults(Sphere_3, 0)
87 assert(Sphere_3.feature().error() == "Sphere builder :: radius is negative or null.")
88
89 model.testNbResults(Sphere_5, 0)
90 assert(Sphere_5.feature().error() == "Attribute \"center_point\" is not initialized.")
91
92 model.testNbResults(Sphere_9, 0)
93 assert(Sphere_9.feature().error() == "Sphere builder :: RMin is larger than RMax.")