Salome HOME
3314ec49e8ffe3d417231ae8069423a20df1294d
[modules/shaper.git] / src / ConnectorAPI / Test / TestImportSTL.py
1 # Copyright (C) 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 import os
21 from salome.shaper import model
22
23 import salome
24 salome.standalone()
25 salome.salome_init(1)
26
27 data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
28
29 def testImportSTL():
30     model.begin()
31     partSet = model.moduleDocument()
32
33     ### Create Part
34     Part_1 = model.addPart(partSet)
35     Part_1_doc = Part_1.document()
36
37     ### Create Import
38     Import_1 = model.addImport(Part_1_doc, os.path.join(data_dir, "cube_ascii.stl"))
39     model.do()
40     Import_1.setName("cube_ascii")
41     Import_1.result().setName("cube_ascii")
42     BoundingBox_1 = model.getBoundingBox(Part_1_doc, model.selection("SOLID", "cube_ascii"))
43
44     Import_2 = model.addImport(Part_1_doc, os.path.join(data_dir, "cube_binary.stl"))
45     model.do()
46     Import_2.setName("cube_binary")
47     Import_2.result().setName("cube_binary")
48
49     model.end()
50
51     #=============================================================================
52     # Tests :
53     #=============================================================================
54     # ASCII STL file :
55     model.checkResult(Import_1, model, 1, [0], [1], [12], [36], [72])
56     r=Import_1.defaultResult()
57     s=r.shape()
58     dim=s.computeSize()
59     dim=dim[1:]
60     dx=abs(dim[3]-dim[0])
61     dy=abs(dim[4]-dim[1])
62     dz=abs(dim[5]-dim[2])
63     tol=1e-06
64     assert(abs(dx-14) <= tol)
65     assert(abs(dy-8) <= tol)
66     assert(abs(dz-5) <= tol)
67     model.testResultsVolumes(Import_1, [560.0000222], theNbSignificantDigits = 7)
68
69     # Binary STL file :
70     model.checkResult(Import_2, model, 1, [0], [1], [12], [36], [72])
71     r=Import_2.defaultResult()
72     s=r.shape()
73     dim=s.computeSize()
74     dim=dim[1:]
75     dx=abs(dim[3]-dim[0])
76     dy=abs(dim[4]-dim[1])
77     dz=abs(dim[5]-dim[2])
78     assert(abs(dx-10) <= tol)
79     assert(abs(dy-10) <= tol)
80     assert(abs(dz-10) <= tol)
81     model.testResultsVolumes(Import_2, [1000], theNbSignificantDigits = 7)
82
83
84 if __name__ == '__main__':
85     testImportSTL()