X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FTest%2FTestImport.py;h=56d89bf8804436bfd12343102219ee2f1256bd65;hb=241b1234365e3f65b9b84c7c8eccf072be54b68c;hp=f51836649fcd953054236a76f9e62c509773a56e;hpb=9b61e5ee5eafe9d6948d9a78667efa2abec132c3;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/Test/TestImport.py b/src/ExchangePlugin/Test/TestImport.py index f51836649..56d89bf88 100644 --- a/src/ExchangePlugin/Test/TestImport.py +++ b/src/ExchangePlugin/Test/TestImport.py @@ -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 -## +# Copyright (C) 2014-2023 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 +# """ TestImport.py @@ -44,7 +43,7 @@ def getShapePath(path): shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes") return os.path.join(shapes_dir, path) -def testImport(theType, theFile, theVolume, theDelta, theErrorExpected = False): +def testImport(theType, theFile, theVolume, theArea, theDelta, theErrorExpected = False): # Create a part for import aSession.startOperation("Create part for import") aPartFeature = aSession.moduleDocument().addFeature("Part") @@ -55,10 +54,23 @@ def testImport(theType, theFile, theVolume, theDelta, theErrorExpected = False): aFeatureKind = "Import" anImportFeature = aPart.addFeature(aFeatureKind) assert anImportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind) + if theType == "STP" or theType == "STEP": + aFieldName = "step_file_path" + file = anImportFeature.string(aFieldName) + assert file, "{0}: Can not receive string field {1}".format(theType, aFieldName) + file.setValue(theFile) + aFieldName = "step_scale_inter_units" + units = anImportFeature.boolean(aFieldName) + assert units, "{0}: Can not receive string field {1}".format(theType, aFieldName) + units.setValue(True) aFieldName = "file_path" file = anImportFeature.string(aFieldName) assert file, "{0}: Can not receive string field {1}".format(theType, aFieldName) file.setValue(theFile) + aFieldName = "ImportType" + type = anImportFeature.string(aFieldName) + assert type, "{0}: Can not receive string field {1}".format(theType, aFieldName) + type.setValue(theType) aSession.finishOperation() if theErrorExpected: @@ -76,6 +88,10 @@ def testImport(theType, theFile, theVolume, theDelta, theErrorExpected = False): aRefVolume = theVolume aResVolume = GeomAlgoAPI_ShapeTools.volume(aShape) assert (math.fabs(aResVolume - aRefVolume) < theDelta), "{0}: The volume is wrong: expected = {1}, real = {2}".format(theType, aRefVolume, aResVolume) + # Check shape area + aRefArea = theArea + aResArea = GeomAlgoAPI_ShapeTools.area(aShape) + assert (math.fabs(aResArea - aRefArea) < theDelta), "{0}: The area is wrong: expected = {1}, real = {2}".format(theType, aRefArea, aResArea) def testImportXAO(): # Create a part for import @@ -87,6 +103,9 @@ def testImportXAO(): aSession.startOperation("Import XAO") anImportFeature = aPart.addFeature("Import") anImportFeature.string("file_path").setValue(getShapePath("Xao/box1.xao")) + aFieldName = "ImportType" + type = anImportFeature.string(aFieldName) + type.setValue("XAO") aSession.finishOperation() # Check results @@ -134,41 +153,43 @@ if __name__ == '__main__': # Create a shape imported from BREP #========================================================================= shape_path = getShapePath("Brep/solid.brep") - testImport("BREP", shape_path, 259982.297176, 10 ** -5) + testImport("BREP", shape_path, 259982.297176, 39481.415022205365, 10 ** -5) shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "solid.brp")) - testImport("BRP", shape_path, 259982.297176, 10 ** -5) + testImport("BRP", shape_path, 259982.297176, 39481.415022205365, 10 ** -5) + shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "pièce.brep")) + testImport("BREP", shape_path, 259982.297176, 39481.415022205365, 10 ** -5) #========================================================================= # Create a shape imported from STEP #========================================================================= shape_path = getShapePath("Step/screw.step") - testImport("STP", shape_path, 3.78827401738e-06, 10 ** -17) + testImport("STEP", shape_path, 3.78827401738e-06, 0.0019293313778547085, 10 ** -17) shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "screw.stp")) - testImport("STEP", shape_path, 3.78827401738e-06, 10 ** -17) + testImport("STEP", shape_path, 3.78827401738e-06, 0.0019293313778547085, 10 ** -17) #========================================================================= # Create a shape imported from IGES #========================================================================= shape_path = getShapePath("Iges/bearing.igs") - testImport("IGES", shape_path, 6.86970803067e-14, 10 ** -25) + testImport("IGS", shape_path, 0.0, 1.3407098545036494e-08, 10 ** -25) shape_path = shutil.copyfile(shape_path, os.path.join(tmp_dir, "bearing.iges")) - testImport("IGS", shape_path, 6.86970803067e-14, 10 ** -25) + testImport("IGES", shape_path, 0.0, 1.3407098545036494e-08, 10 ** -25) #========================================================================= # Create a shape imported from XAO #========================================================================= testImportXAO() - #========================================================================= - # Check import errors - #========================================================================= - testImport("BREP", "", 0, 10 ** -25, True) - shape_path = getShapePath("Brep/solid.dwg") - testImport("BREP", shape_path, 0, 10 ** -25, True) - shape_path = getShapePath("Xao/wrong_file.xao") - testImport("XAO", shape_path, 0, 10 ** -25, True) - #========================================================================= # End of test #========================================================================= from salome.shaper import model assert(model.checkPythonDump()) + + #========================================================================= + # Check import errors + #========================================================================= + testImport("BREP", "", 0, 0, 10 ** -25, True) + shape_path = getShapePath("Brep/solid.dwg") + testImport("BREP", shape_path, 0, 0, 10 ** -25, True) + shape_path = getShapePath("Xao/wrong_file.xao") + testImport("XAO", shape_path, 0, 0, 10 ** -25, True)