Salome HOME
01a73e561b1204247c940eebc7bc4bd268ccc3ff
[modules/shaper.git] / src / ExchangePlugin / Test / TestImportImage_1.py
1 # Copyright (C) 2021-2024  CEA, EDF
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, inspect
21 from salome.shaper import model
22
23 from PyQt5.Qt import QApplication
24
25 import salome
26 salome.salome_init_without_session()
27 salome.salome_init(1)
28 if QApplication.instance() is None:
29   app = QApplication([])
30
31 data_dir = os.path.join(os.path.dirname(inspect.getfile(lambda: None)), "data")
32
33 model.begin()
34 partSet = model.moduleDocument()
35
36 ### Create Part
37 Part_1 = model.addPart(partSet)
38 Part_1_doc = Part_1.document()
39
40 ### Create ImportImage
41 ImportImage_1 = model.addImportImage(Part_1_doc, os.path.join(data_dir, "1.jpg"))
42 model.do()
43 ImportImage_1.setName("drawing")
44 ImportImage_1.result().setName("drawing")
45
46 ### Create Translation
47 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)
48
49 ### Create Scale
50 Scale_1 = model.addScale(Part_1_doc, [model.selection("FACE", "drawing")] , model.selection("VERTEX", "PartSet/Origin"), 0.5, keepSubResults = True)
51
52 model.end()
53
54 #=============================================================================
55 # Tests :
56 #=============================================================================
57 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
58 r=Scale_1.defaultResult()
59 s=r.shape()
60 dim=s.computeSize()
61 dim=dim[1:]
62 dx=abs(dim[3]-dim[0])
63 dy=abs(dim[4]-dim[1])
64 dz=abs(dim[5]-dim[2])
65 tol=1e-06
66 assert(abs(dx-400) <= tol)
67 assert(abs(dy-258.5) <= tol)
68 assert(abs(dz-0) <= tol)
69 assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
70 assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
71 assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
72
73 #=============================================================================
74 # Change the image :
75 #=============================================================================
76 model.begin()
77 ImportImage_1.setFilePath(os.path.join(data_dir, "2.png"))
78 ImportImage_1.execute()
79 ImportImage_1.result().setName("drawing")
80 Scale_1.setScaleFactor(0.7)
81 Scale_1.execute()
82 model.do()
83 model.end()
84 salome.sg.UpdateView()
85
86 #=============================================================================
87 # Tests :
88 #=============================================================================
89 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
90 r=Scale_1.defaultResult()
91 s=r.shape()
92 dim=s.computeSize()
93 dim=dim[1:]
94 dx=abs(dim[3]-dim[0])
95 dy=abs(dim[4]-dim[1])
96 dz=abs(dim[5]-dim[2])
97 tol=1e-06
98 assert(abs(dx-448) <= tol)
99 assert(abs(dy-296.8) <= tol)
100 assert(abs(dz-0) <= tol)
101 assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
102 assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
103 assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
104
105 assert(model.checkPythonDump())
106
107 # Close SALOME GUI
108 import salome_utils
109 import killSalomeWithPort
110
111 port = salome_utils.getPortNumber(False)
112 if port:
113   killSalomeWithPort.killMyPort(port)