Salome HOME
Issue #20641: Tests for implemented features
[modules/shaper.git] / src / ExchangePlugin / Test / TestImportImage_1.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(sys.argv[0]), "data")
27
28 model.begin()
29 partSet = model.moduleDocument()
30
31 ### Create Part
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34
35 ### Create ImportImage
36 ImportImage_1 = model.addImportImage(Part_1_doc, os.path.join(data_dir, "1.jpg"))
37 model.do()
38 ImportImage_1.setName("drawing")
39 ImportImage_1.result().setName("drawing")
40
41 ### Create Translation
42 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("FACE", "drawing")], startPoint = model.selection("VERTEX", "[drawing/Shape_1]e[drawing/Shape_4]e"), endPoint = model.selection("VERTEX", "PartSet/Origin"), keepSubResults = True)
43
44 ### Create Scale
45 Scale_1 = model.addScale(Part_1_doc, [model.selection("FACE", "drawing")] , model.selection("VERTEX", "PartSet/Origin"), 0.5, keepSubResults = True)
46
47 model.end()
48
49 #=============================================================================
50 # Tests :
51 #=============================================================================
52 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
53 r=Scale_1.defaultResult()
54 s=r.shape()
55 dim=s.computeSize()
56 dim=dim[1:]
57 dx=abs(dim[3]-dim[0])
58 dy=abs(dim[4]-dim[1])
59 dz=abs(dim[5]-dim[2])
60 tol=1e-06
61 assert(abs(dx-400) <= tol)
62 assert(abs(dy-258.5) <= tol)
63 assert(abs(dz-0) <= tol)
64
65 #=============================================================================
66 # Change the image :
67 #=============================================================================
68 model.begin()
69 ImportImage_1.setFilePath(os.path.join(data_dir, "2.png"))
70 ImportImage_1.execute()
71 ImportImage_1.result().setName("drawing")
72 Scale_1.setScaleFactor(0.7)
73 Scale_1.execute()
74 model.do()
75 model.end()
76 salome.sg.UpdateView()
77
78 #=============================================================================
79 # Tests :
80 #=============================================================================
81 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
82 r=Scale_1.defaultResult()
83 s=r.shape()
84 dim=s.computeSize()
85 dim=dim[1:]
86 dx=abs(dim[3]-dim[0])
87 dy=abs(dim[4]-dim[1])
88 dz=abs(dim[5]-dim[2])
89 tol=1e-06
90 assert(abs(dx-448) <= tol)
91 assert(abs(dy-296.8) <= tol)
92 assert(abs(dz-0) <= tol)
93
94
95 # Close SALOME GUI
96 import salome_utils
97 import subprocess
98 port = salome_utils.getPortNumber()
99 proc = subprocess.Popen(["killSalomeWithPort.py", "{}".format(port)])