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