1 # Copyright (C) 2022-2024 CEA, EDF, OPEN CASCADE
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
22 Unit test of ExchangePlugin_ExportFeature class
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
37 from ModelAPI import *
38 from GeomAlgoAPI import *
39 from salome.shaper import model
42 from salome.geom import geomBuilder
43 geompy = geomBuilder.New()
45 #=========================================================================
46 # test Export XAO to memory buffer (bytes array)
47 #=========================================================================
48 def testExportXAOMem():
51 partSet = model.moduleDocument()
52 Part_1 = model.addPart(partSet)
53 Part_1_doc = Part_1.document()
54 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
55 Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Top")])
56 Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
59 # Export to memory buffer (bytes array)
60 Export_buff1 = model.exportToXAOMem(Part_1_doc, model.selection("SOLID", "Box_1_1"), 'XAO')
61 Export_buff2 = model.exportToXAOMem(Part_1_doc, model.selection("SOLID", "Box_2_1"), 'XAO')
65 # export to XAO file and compare size of file and size of buffer
66 #assert(len(Export_buff1) == 4392)
67 #assert(len(Export_buff2) == 4287)
68 with tempfile.TemporaryDirectory() as tmpdirname:
69 tmpfilename = os.path.join(tmpdirname, "Box.xao")
70 Export_1 = model.exportToXAO(Part_1_doc, tmpfilename, model.selection("SOLID", "Box_1_1"), 'XAO')
71 file_stats = os.stat(tmpfilename)
72 assert(len(Export_buff1) == file_stats.st_size)
74 Export_2 = model.exportToXAO(Part_1_doc, tmpfilename, model.selection("SOLID", "Box_2_1"), 'XAO')
75 file_stats = os.stat(tmpfilename)
76 assert(len(Export_buff2) == file_stats.st_size)
80 (imported1, b1, [], [Group_1], []) = geompy.ImportXAOMem(Export_buff1, theName="Box1")
81 (imported2, b2, [], [] , []) = geompy.ImportXAOMem(Export_buff2, theName="Box2")
85 Props = geompy.BasicProperties(b1)
88 assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
90 Props = geompy.BasicProperties(Group_1)
93 assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
96 Props = geompy.BasicProperties(b2)
99 assert (math.fabs(Props[1] - aSurface) < aTol), "The surface is wrong: expected = {0}, real = {1}".format(aSurface, Props[1])
101 if __name__ == '__main__':
102 #=========================================================================
103 # Export a shape into XAO memory buffer
104 #=========================================================================
106 #=========================================================================
108 #=========================================================================