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_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, 'Box10x10x10' )
56 geompy.addToStudyInFather( Box_1, Group_1, 'GroupTopFace' )
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 with tempfile.TemporaryDirectory() as tmpdirname:
63 tmpfilename = os.path.join(tmpdirname, "Box.xao")
64 exported = geompy.ExportXAO(Box_1, [Group_1], [], "XAO", tmpfilename, "")
65 file_stats = os.stat(tmpfilename)
66 assert(len(Export_buff) == file_stats.st_size)
71 partSet = model.moduleDocument()
72 Part_1 = model.addPart(partSet)
73 Part_1_doc = Part_1.document()
75 Import_1 = model.addImportXAOMem(Part_1_doc, Export_buff)
79 assert(Import_1.feature().error() == "")
80 model.testNbResults(Import_1, 1)
81 model.testNbSubResults(Import_1, [0])
82 model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [1])
83 model.testNbSubShapes(Import_1, GeomAPI_Shape.FACE, [6])
84 model.testNbSubShapes(Import_1, GeomAPI_Shape.EDGE, [24])
85 model.testNbSubShapes(Import_1, GeomAPI_Shape.VERTEX, [48])
86 model.testResultsVolumes(Import_1, [1000])
87 model.testResultsAreas(Import_1, [600])
89 assert(Import_1.name() == "Box10x10x10")
90 assert(Import_1.result().name() == "Box10x10x10_1")
91 assert(Import_1.subFeature(0).name() == "GroupTopFace")
92 assert(Import_1.subFeature(0).result().name() == "GroupTopFace")
95 assert(Part_1_doc.size("Groups") == 1)
96 res1 = objectToResult(Part_1_doc.object("Groups", 0))
97 assert(res1 is not None)
98 res1It = GeomAPI_ShapeExplorer(res1.shape(), GeomAPI_Shape.FACE)
100 shape1 = res1It.current()
102 assert(not res1It.more())
103 p1 = res1.shape().middlePoint()
105 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)
108 def testImportXAOMem_EmptyName():
111 Box_1 = geompy.MakeBoxDXDYDZ(10, 10, 10)
112 Group_1 = geompy.CreateGroup(Box_1, geompy.ShapeType["FACE"])
113 geompy.UnionIDs(Group_1, [33])
114 # here we do not add box to study to check special case of empty shape name in XAO
116 Export_buff = geompy.ExportXAOMem(Box_1, [Group_1], [], "XAO")
120 partSet = model.moduleDocument()
121 Part_1 = model.addPart(partSet)
122 Part_1_doc = Part_1.document()
124 Import_1 = model.addImportXAOMem(Part_1_doc, Export_buff)
128 assert(Import_1.feature().error() == "")
129 model.testNbResults(Import_1, 1)
131 assert(Import_1.name() == "ImportXAOMem")
132 assert(Import_1.result().name() == "ImportXAOMem_1")
133 assert(Import_1.subFeature(0).name() == "Group_1")
134 assert(Import_1.subFeature(0).result().name() == "Group_1")
136 if __name__ == '__main__':
137 #=========================================================================
138 # Import a shape from XAO memory buffer
139 #=========================================================================
141 testImportXAOMem_EmptyName()
142 #=========================================================================
144 #=========================================================================