Salome HOME
Corrections (#20619)
[modules/shaper.git] / src / FeaturesPlugin / Test / TestBoundingBox.py
1 # Copyright (C) 2014-2020  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       Unit test of ...
22 """
23 #=========================================================================
24 # Initialization of the test
25 #=========================================================================
26
27
28 import os
29 import math
30
31 from ModelAPI import *
32 from salome.shaper import model
33
34
35 __updated__ = "2020-11-12"
36
37
38 #=========================================================================
39 # test Bounding Box  
40 #=========================================================================
41 def test_Bounding_Box():
42
43     model.begin()
44     partSet = model.moduleDocument()
45     Part_1 = model.addPart(partSet)
46     Part_1_doc = Part_1.document()
47     ### Create Cone
48     Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10)
49
50     model.do()
51     ### Create BoundingBox
52     BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "Cone_1_1"))
53     model.end()
54
55     myDelta = 1e-6
56     Props = model.getGeometryCalculation(Part_1_doc,model.selection("SOLID", "BoundingBox_1_1"))
57
58     print(" Basic Properties:")
59     print(" Wires length: ", Props[0])
60     print(" Surface area: ", Props[1])
61     print(" Volume      : ", Props[2]) 
62     
63     aReflength = 200
64     aReslength = Props[0]
65     assert (math.fabs(aReslength - aReflength) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aReflength, aReslength)
66
67     aRefSurface = 1600
68     aResSurface = Props[1]
69     assert (math.fabs(aResSurface - aRefSurface) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
70
71     aRefVolume = 4000
72     aResVolume = Props[2]
73     assert (math.fabs(aResVolume - aRefVolume) < myDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefVolume, aResVolume)
74
75     
76 if __name__ == '__main__':
77
78     test_Bounding_Box()
79         
80     #=========================================================================
81     # End of test
82     #=========================================================================