X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConnectorAPI%2FTest%2FTestExportToGEOMAllGroupsAndFields.py;h=ef0971c7fb42a036024169cbb7bfe68a4523b6d3;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=114ca9f617447c8e9090d71043642f894104ce25;hpb=e9e3cd25ca7f0887caf63f4eb1c240849cf7c2a0;p=modules%2Fshaper.git diff --git a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py index 114ca9f61..ef0971c7f 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py +++ b/src/ConnectorAPI/Test/TestExportToGEOMAllGroupsAndFields.py @@ -1,23 +1,21 @@ -## Copyright (C) 2014-2017 CEA/DEN, EDF R&D -## -## This library is free software; you can redistribute it and/or -## modify it under the terms of the GNU Lesser General Public -## License as published by the Free Software Foundation; either -## version 2.1 of the License, or (at your option) any later version. -## -## This library is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## Lesser General Public License for more details. -## -## You should have received a copy of the GNU Lesser General Public -## License along with this library; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## -## See http:##www.salome-platform.org/ or -## email : webmaster.salome@opencascade.com -## -# -*- coding: utf-8 -*- +# Copyright (C) 2014-2024 CEA, EDF +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# import os import tempfile @@ -25,6 +23,7 @@ import tempfile import sys import salome +salome.standalone() salome.salome_init() theStudy = salome.myStudy @@ -64,17 +63,13 @@ def dumpShaper(fileName): dump=model.moduleDocument().addFeature("Dump") dump.string("file_path").setValue(fileName) dump.string("file_format").setValue("py") - dump.string("selection_type").setValue("topological_naming") + dump.boolean("topological_naming").setValue(True) + dump.boolean("geometric_selection").setValue(False) + dump.boolean("weak_naming").setValue(False) model.do() model.end() pass -def getTmpFileName(ext): - tempdir = tempfile.gettempdir() - tmp_file = tempfile.NamedTemporaryFile(suffix=".%s"%ext, prefix='shaper_', dir=tempdir, delete=False) - tmp_filename = tmp_file.name - return tmp_filename - def testGroupsAndFieldsExportToGEOM(): model.begin() partSet = model.moduleDocument() @@ -116,8 +111,8 @@ def testGroupsAndFieldsExportToGEOM(): Field_4 = model.addField(Part_1_doc, 1, "DOUBLE", 1, ["Comp 1"], Field_4_objects) Field_4.result().setName("Field_vertices") Field_4.addStep(0, 0, [[0], [1], [1], [1], [1], [1], [1], [1], [1], [2], [2], [2], [2], [3], [3], [3], [3]]) - model.exportToGEOM(Part_1_doc) model.do() + model.exportToGEOM(Part_1_doc) model.end() # check the groups content by the coordinates of a point on its sub-shapes @@ -129,80 +124,77 @@ def checkGroupByCoords(group, coords, tolerance=1e-7): ## Check the result imported in GEOM def checkResultInGEOM(): - geomObject_1 = getLastGEOMShape() + geomObject_1 = getLastGEOMShape() # the second, translation result group_1_GEOM = getSubObject(geomObject_1, 1) assert group_1_GEOM.GetName() == 'faces_top' - assert geompy.NumberOfFaces(group_1_GEOM) == 3 + assert geompy.NumberOfFaces(group_1_GEOM) == 1 # 2 faces are in the first result, only one here # coordinates of the barycenters of the faces of Group_1 - coords_1 = [[-5, 5, 10], [10, 10, 20], [25, 5, 10]] + coords_1 = [[25, 5, 10]] checkGroupByCoords(group_1_GEOM, coords_1) group_2_GEOM = getSubObject(geomObject_1, 2) assert group_2_GEOM.GetName() == 'edges_x' - assert geompy.NumberOfEdges(group_2_GEOM) == 3 + assert geompy.NumberOfEdges(group_2_GEOM) == 1 # 2 edges are in the first result, only one here # coordinates of the barycenters of the edges of Group_2 - coords_2 = [[-5, 0, 0], [10, 0, 0], [25, 0, 0]] + coords_2 = [[25, 0, 0]] checkGroupByCoords(group_2_GEOM, coords_2) group_3_GEOM = getSubObject(geomObject_1, 3) assert group_3_GEOM.GetName() == 'vertices_bottom' - assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 8 + assert geompy.NumberOfSubShapes(group_3_GEOM, geompy.ShapeType["VERTEX"]) == 3 # 3 of 8 # coordinates of the points of of Group_3 - coords_3 = [[-10, 0, 0], [-10, 10, 0], [0, 10, 0], [0, 20, 0], [20, 20, 0], [20, 10, 0], [30, 10, 0], [30, 0, 0]] + coords_3 = [[20, 10, 0], [30, 10, 0], [30, 0, 0]] checkGroupByCoords(group_3_GEOM, coords_3) group_4_GEOM = getSubObject(geomObject_1, 4) assert group_4_GEOM.GetName() == 'solids_small' - assert geompy.NumberOfSolids(group_4_GEOM) == 2 + assert geompy.NumberOfSolids(group_4_GEOM) == 1 # 1 of 2 # coordinates of the barycenters of the solids of Group_4 - coords_4 = [[-5, 5, 5], [25, 5, 5]] + coords_4 = [[25, 5, 5]] checkGroupByCoords(group_4_GEOM, coords_4) field_1_GEOM = getSubObject(geomObject_1, 5) assert field_1_GEOM.GetName() == 'Field_solids' - assert field_1_GEOM.GetStep(0).GetValues() == [1.0, 2.0, 3.0] + assert field_1_GEOM.GetStep(1).GetValues() == [3.0] field_2_GEOM = getSubObject(geomObject_1, 6) assert field_2_GEOM.GetName() == 'Field_faces' - assert field_2_GEOM.GetStep(0).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0] + assert field_2_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 2.0] field_3_GEOM = getSubObject(geomObject_1, 7) assert field_3_GEOM.GetName() == 'Field_edges' - assert field_3_GEOM.GetStep(0).GetValues() == [2.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0] + assert field_3_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0] field_4_GEOM = getSubObject(geomObject_1, 8) assert field_4_GEOM.GetName() == 'Field_vertices' - assert field_4_GEOM.GetStep(0).GetValues() == [2.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0, 3.0, 0.0, 3.0, 1.0, 0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0] + assert field_4_GEOM.GetStep(1).GetValues() == [0.0, 0.0, 0.0, 1.0, 3.0, 1.0, 3.0, 1.0] pass def checkDump(): # Dump the salome study (only CORBA modules, SHAPER dump is not in it) - tempdir = tempfile.gettempdir() - dumpFileGeomBase = "dump_test_geom" - dumpFileGeom = os.path.join(tempdir, "%s.py"%dumpFileGeomBase) - salome.myStudy.DumpStudy(tempdir, dumpFileGeomBase, True, False) - - # Dump SHAPER - dumpFileShaper = os.path.join(tempdir, "dump_test_shaper.py") - dumpShaper(dumpFileShaper) + with tempfile.TemporaryDirectory() as tempdir: + dumpFileGeomBase = "dump_test_geom" + dumpFileGeom = os.path.join(tempdir, "%s.py"%dumpFileGeomBase) + salome.myStudy.DumpStudy(tempdir, dumpFileGeomBase, True, False) - # Load SHAPER dump - exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec')) + # Dump SHAPER + dumpFileShaper = os.path.join(tempdir, "dump_test_shaper.py") + dumpShaper(dumpFileShaper) - # Load GEOM dump - exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec')) + # Load SHAPER dump + exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec')) - # Clean files - files = [dumpFileGeom, dumpFileShaper] - for f in files: - os.remove(f) + # Load GEOM dump + exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec')) + # Clean files + files = [dumpFileGeom, dumpFileShaper] pass if __name__ == '__main__':