1 # Copyright (C) 2021 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from salome.shaper import model
26 data_dir = os.path.join(os.path.dirname(inspect.getfile(lambda: None)), "data")
28 from tempfile import TemporaryDirectory
29 tmp_dir = TemporaryDirectory()
30 img_file = os.path.join(tmp_dir.name, "1.jpg")
32 from shutil import copyfile
33 copyfile(os.path.join(data_dir, "1.jpg"), img_file)
37 partSet = model.moduleDocument()
40 Part_1 = model.addPart(partSet)
41 Part_1_doc = Part_1.document()
43 ### Create ImportImage
44 ImportImage_1 = model.addImportImage(Part_1_doc, img_file)
46 ImportImage_1.setName("drawing")
47 ImportImage_1.result().setName("drawing")
49 ### Create Translation
50 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)
53 Scale_1 = model.addScale(Part_1_doc, [model.selection("FACE", "drawing")] , model.selection("VERTEX", "PartSet/Origin"), 0.5, keepSubResults = True)
57 #=============================================================================
59 #=============================================================================
60 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
61 r=Scale_1.defaultResult()
69 assert(abs(dx-400) <= tol)
70 assert(abs(dy-258.5) <= tol)
71 assert(abs(dz-0) <= tol)
73 #=============================================================================
75 #=============================================================================
76 os.rename(img_file, os.path.join(tmp_dir.name, "1_new.jpg"))
79 Scale_1.setScaleFactor(0.7)
84 #=============================================================================
86 #=============================================================================
87 model.checkResult(Scale_1, model, 1, [0], [0], [1], [4], [8])
88 r=Scale_1.defaultResult()
96 assert(abs(dx-560) <= tol)
97 assert(abs(dy-361.9) <= tol)
98 assert(abs(dz-0) <= tol)
104 port = salome_utils.getPortNumber()
105 proc = subprocess.Popen(["killSalomeWithPort.py", "{}".format(port)])