1 # Copyright (C) 2022-2023 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_ImportFeature class
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
37 from ModelAPI import *
39 from GeomAlgoAPI import *
40 from salome.shaper import model
43 from salome.geom import geomBuilder
44 geompy = geomBuilder.New()
46 #=========================================================================
47 # test Import XAO from memory buffer (bytes array)
48 #=========================================================================
49 def testImportXAOMem():
52 Box_1 = geompy.MakeBoxDXDYDZ(10, 10, 10)
53 Group_1 = geompy.CreateGroup(Box_1, geompy.ShapeType["FACE"])
54 geompy.UnionIDs(Group_1, [33])
55 geompy.addToStudy( Box_1, 'Box_1_1' )
56 geompy.addToStudyInFather( Box_1, Group_1, 'Group_1' )
58 Export_buff = geompy.ExportXAOMem(Box_1, [Group_1], [], "XAO")
61 # export to XAO file and compare size of file and size of buffer
62 #assert(len(Export_buff) == 4392)
63 with tempfile.TemporaryDirectory() as tmpdirname:
64 tmpfilename = os.path.join(tmpdirname, "Box.xao")
65 exported = geompy.ExportXAO(Box_1, [Group_1], [], "XAO", tmpfilename, "")
66 file_stats = os.stat(tmpfilename)
67 print(file_stats.st_size)
68 assert(len(Export_buff) == file_stats.st_size)
73 partSet = model.moduleDocument()
74 Part_1 = model.addPart(partSet)
75 Part_1_doc = Part_1.document()
77 Import_1 = model.addImportXAOMem(Part_1_doc, Export_buff)
79 Import_1.subFeature(0).setName("Group_1")
80 Import_1.subFeature(0).result().setName("Group_1")
81 Import_1.setName("Box_1")
82 Import_1.result().setName("Box_1_1")
87 assert(Import_1.feature().error() == "")
88 model.testNbResults(Import_1, 1)
89 model.testNbSubResults(Import_1, [0])
90 model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [1])
91 model.testNbSubShapes(Import_1, GeomAPI_Shape.FACE, [6])
92 model.testNbSubShapes(Import_1, GeomAPI_Shape.EDGE, [24])
93 model.testNbSubShapes(Import_1, GeomAPI_Shape.VERTEX, [48])
94 model.testResultsVolumes(Import_1, [1000])
95 model.testResultsAreas(Import_1, [600])
97 # check groups are the same in both parts
98 assert(Part_1_doc.size("Groups") == 1)
99 res1 = objectToResult(Part_1_doc.object("Groups", 0))
100 assert(res1 is not None)
101 res1It = GeomAPI_ShapeExplorer(res1.shape(), GeomAPI_Shape.FACE)
102 assert(res1It.more())
103 shape1 = res1It.current()
105 assert(not res1It.more())
106 p1 = res1.shape().middlePoint()
108 assert(math.fabs(p1.x() - 5) <= aTol and math.fabs(p1.y() - 5) <= aTol and math.fabs(p1.z() - 10) <= aTol), "({}, {}, {}) != ({}, {}, {})".format(p1.x(), p1.y(), p1.z(), 5, 5, 10)
110 if __name__ == '__main__':
111 #=========================================================================
112 # Import a shape from XAO memory buffer
113 #=========================================================================
115 #=========================================================================
117 #=========================================================================