Salome HOME
Add unitary tests
authorJérôme <jerome.lucas@cesgenslab.fr>
Thu, 24 Sep 2020 08:16:11 +0000 (10:16 +0200)
committerJérôme <jerome.lucas@cesgenslab.fr>
Thu, 24 Sep 2020 08:16:11 +0000 (10:16 +0200)
src/ConnectorAPI/Test/TestExportSTL.py [new file with mode: 0644]
src/ConnectorAPI/Test/tests.set

diff --git a/src/ConnectorAPI/Test/TestExportSTL.py b/src/ConnectorAPI/Test/TestExportSTL.py
new file mode 100644 (file)
index 0000000..edc7eaf
--- /dev/null
@@ -0,0 +1,159 @@
+# Copyright (C) 2014-2020  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
+#
+
+"""
+      TestExport.py
+      Unit test of ExchangePlugin_TestExport class
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+import salome
+
+import os
+import math
+from tempfile import TemporaryDirectory
+
+import GEOM
+
+from ModelAPI import *
+
+from salome.shaper import model
+
+from salome.geom import geomBuilder
+
+from GeomAlgoAPI import *
+
+__updated__ = "2015-05-22"
+
+salome.salome_init(1)
+geompy = geomBuilder.New()
+
+#=========================================================================
+# Help functions
+#=========================================================================
+def removeFile(theFileName):
+    try: os.remove(theFileName)
+    except OSError: pass
+    assert not os.path.exists(theFileName), \
+            "Can not remove file {0}".format(theFileName)
+
+#=========================================================================
+# test Export STL 
+#=========================================================================
+def testExportSTL(theFile, theDelta, theErrorExpected = False):
+
+    model.begin()
+    partSet = model.moduleDocument()
+    Part_1 = model.addPart(partSet)
+    Part_1_doc = Part_1.document()
+    Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+    Box_2 = model.addBox(Part_1_doc, 20, 20, 20)
+    model.do()
+
+    # First export to GEOM
+    model.exportToGEOM(Part_1_doc)
+    model.end()
+
+    theSurface = 600
+
+    print("theFile=",theFile)
+
+    # deflection relative 0.0001 et Ascii 
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID","Box_1_1"),0.0001, 0.5, True,False)
+
+ #==   assert os.path.exists(theFile)
+        
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+    
+    removeFile(theFile)
+
+    theSurface =  600
+    # deflection relative 0.0001 et binaire
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, True,True)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+    
+    removeFile(theFile)
+
+    theSurface =  600
+    # deflection absolue et AScii
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False, False)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+
+    theSurface =  600
+    # deflection absolue et binaire
+    model.exportToSTL(Part_1_doc, theFile, model.selection("SOLID", "Box_1_1" ),0.0001, 0.5, False,True)
+
+    # Check results
+    test_stl_1 = geompy.ImportSTL(theFile)
+    Props = geompy.BasicProperties(test_stl_1)
+    print("\nBasic Properties:")
+    print(" Wires length: ", Props[0])
+    print(" Surface area: ", Props[1])
+    print(" Volume      : ", Props[2])
+
+    aRefSurface = theSurface
+    aResSurface = Props[1]
+    assert (math.fabs(aResSurface - aRefSurface) < theDelta), "The volume is wrong: expected = {0}, real = {1}".format(aRefSurface, aResSurface)
+
+    model.end()
+
+if __name__ == '__main__':
+    with TemporaryDirectory() as tmp_dir:
+        aRealSurface = 0.00192878
+        #=========================================================================
+        # Export a shape into STL
+        #=========================================================================
+        testExportSTL(os.path.join(tmp_dir, "export.stl"), 10 ** -5, True)
+        #=========================================================================
+        # End of test
+        #=========================================================================
index 60e932add571e24e5de7d9144d53f9fbd74c781d..31e182ca71e9349eb41828a1f98279c27f0cc16e 100644 (file)
@@ -27,4 +27,5 @@ SET(TEST_NAMES
   Test17917
   Test18887
   Test3195
+  TestExportSTL
 )