Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestGeometryCalculation.py
1 # Copyright (C) 2014-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       Unit test of ...
22 """
23 #=========================================================================
24 # Initialization of the test
25 #=========================================================================
26
27 import salome
28
29 import os
30 import math
31
32 from ModelAPI import *
33 from salome.shaper import model
34
35
36
37 __updated__ = "2020-11-12"
38
39
40 #=========================================================================
41 # test Geometry calculation
42 #=========================================================================
43 def test_Geometry_Calculation():
44
45     model.begin()
46     file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep")
47     partSet = model.moduleDocument()
48     Part_1 = model.addPart(partSet)
49     Part_1_doc = Part_1.document()
50     Import_1 = model.addImport(Part_1_doc,file_path)
51     model.do()
52
53     myDelta = 1e-6
54     Props = model.getGeometryCalculation(Part_1_doc,model.selection("SOLID", "box1_1"))
55
56     print(" Geometry calculation:")
57     print(" Wires length: ", Props[0])
58     print(" Surface area: ", Props[1])
59     print(" Volume      : ", Props[2])
60
61     aReflength = 2400
62     aReslength = Props[0]
63     assert (math.fabs(aReslength - aReflength) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aReflength, aReslength)
64
65     aRefSurface = 240000
66     aResSurface = Props[1]
67     assert (math.fabs(aResSurface - aRefSurface) < myDelta), "The surface is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
68
69     aRefVolume = 8000000
70     aResVolume = Props[2]
71     assert (math.fabs(aResVolume - aRefVolume) < myDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefVolume, aResVolume)
72
73
74 if __name__ == '__main__':
75
76     test_Geometry_Calculation()
77
78     #=========================================================================
79     # End of test
80     #=========================================================================