Salome HOME
Added unit-tests for SHAPERSTUDY and SMESH check
[modules/shaper.git] / src / ConnectorAPI / Test / TestExportToGEOM.py
index 0403f1e9ee713944d7b1cd3dd9ee0eb01253a263..9efb1bba0a526c85d90f73b3132ba9a7a79c792d 100644 (file)
@@ -1,22 +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<mailto:webmaster.salome@opencascade.com>
-##
+# Copyright (C) 2014-2019  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
+#
 
 import salome
 from salome.shaper import model
@@ -26,8 +25,8 @@ from salome.geom import geomBuilder
 import os
 import tempfile
 
-salome.salome_init(0,1)
-geompy = geomBuilder.New(salome.myStudy)
+salome.salome_init(1)
+geompy = geomBuilder.New()
 
 ## Get the last object published in the GEOM section of the object browser
 def getLastGEOMShape():
@@ -60,6 +59,9 @@ def dumpShaper(fileName):
   dump=model.moduleDocument().addFeature("Dump")
   dump.string("file_path").setValue(fileName)
   dump.string("file_format").setValue("py")
+  dump.boolean("topological_naming").setValue(True)
+  dump.boolean("geometric_selection").setValue(False)
+  dump.boolean("weak_naming").setValue(False)
   model.do()
   model.end()
   pass
@@ -85,13 +87,13 @@ def testSeveralExportsToGEOM():
   Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
   Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
   Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), -10)
-  Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Box_2_1")])
-  Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Partition_1_1_1/Modified_Face_2_2"), model.selection("FACE", "Box_2_1/Top")])
+  Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Box_2_1")])
+  Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Box_2_1/Top")])
   model.do()
-  model.end()
 
   # First export to GEOM
   model.exportToGEOM(Part_1_doc)
+  model.end()
 
   # Check that the GEOM object has 1 compsolid and 2 solids
   geomObject_1 = getLastGEOMShape()
@@ -103,15 +105,18 @@ def testSeveralExportsToGEOM():
   assert geompy.NumberOfFaces(geomGroup_1) == 2
 
   # Add a third box
+  model.begin()
   Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
   Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 20)
+  model.do()
 
   # Second export to GEOM
   model.exportToGEOM(Part_1_doc)
+  model.end()
 
-  # Check that the GEOM object has 3 solids
+  # Check that the last exported GEOM object is 1 solids
   geomObject_2 = getLastGEOMShape()
-  assert geompy.NumberOfSolids(geomObject_2) == 3
+  assert geompy.NumberOfSolids(geomObject_2) == 1
 
   # Dump the salome study (only CORBA modules, SHAPER dump is not in it)
   tempdir = tempfile.gettempdir()
@@ -124,10 +129,10 @@ def testSeveralExportsToGEOM():
   dumpShaper(dumpFileShaper)
 
   # Load SHAPER dump
-  execfile(dumpFileShaper)
+  exec(compile(open(dumpFileShaper).read(), dumpFileShaper, 'exec'))
 
   # Load GEOM dump
-  execfile(dumpFileGeom)
+  exec(compile(open(dumpFileGeom).read(), dumpFileGeom, 'exec'))
 
   # Clean files
   files = [dumpFileGeom, dumpFileShaper]
@@ -139,4 +144,4 @@ def testSeveralExportsToGEOM():
 
 
 if __name__ == '__main__':
-  testSeveralExportsToGEOM()
\ No newline at end of file
+  testSeveralExportsToGEOM()