X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FTest%2FTestExport.py;h=6af4500ff968700bb4a7df881c74e204a249d709;hb=c726762e267b69c5764914db39c14353283c657f;hp=750bde940a656b69913d64a44a4da3056f202276;hpb=28f1e6c675511ef49f268b816a4c2dab94fa9ad2;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/Test/TestExport.py b/src/ExchangePlugin/Test/TestExport.py index 750bde940..6af4500ff 100644 --- a/src/ExchangePlugin/Test/TestExport.py +++ b/src/ExchangePlugin/Test/TestExport.py @@ -1,3 +1,23 @@ +## 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 +## + """ TestExport.py Unit test of ExchangePlugin_TestExport class @@ -7,14 +27,14 @@ #========================================================================= import os import math +from tempfile import TemporaryDirectory from ModelAPI import * -from GeomDataAPI import * -from GeomAlgoAPI import * -from GeomAPI import * from TestImport import testImport +from salome.shaper import model + __updated__ = "2015-05-22" aSession = ModelAPI_Session.get() @@ -30,69 +50,151 @@ def removeFile(theFileName): #========================================================================= # Common test function #========================================================================= -def testExport(theType, theFormat, theFile, theVolume, theDelta): - # Import a reference part - aSession.startOperation() +def testExport(theType, theFormat, theFile, theVolume, theDelta, theErrorExpected = False): + # Import a reference part + aSession.startOperation("Add part") aPartFeature = aSession.moduleDocument().addFeature("Part") aSession.finishOperation() aPart = aSession.activeDocument() - - aSession.startOperation() + + aSession.startOperation("Import screw") anImportFeature = aPart.addFeature("Import") - anImportFeature.string("import_file_selector").setValue("Data/screw.step") - anImportFeature.execute() + aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "screw.step") + anImportFeature.string("file_path").setValue(aShapePath) aSession.finishOperation() - + removeFile(theFile) # Export a part - aSession.startOperation() - aFeatureKind = "Export" - anExportFeature = aPart.addFeature(aFeatureKind) - assert anExportFeature, "{0}: Can not create a feature {1}".format(theType, aFeatureKind) - - aFormatAttrName = "export_file_format" - aFormatAttr = anExportFeature.string(aFormatAttrName) - assert aFormatAttr, "{0}: Can not receive string field {1}".format(theType, aFormatAttrName) - aFormatAttr.setValue(theFormat) - - aFileAttrName = "export_file_selector" - aFileAttr = anExportFeature.string(aFileAttrName) - assert aFileAttr, "{0}: Can not receive string field {1}".format(theType, aFileAttrName) - aFileAttr.setValue(theFile) - - aSelectionListAttrName = "selection_list" - aSelectionListAttr = anExportFeature.selectionList(aSelectionListAttrName) - assert aSelectionListAttr, "{0}: Can not receive selection list field {1}".format(theType, aSelectionListAttrName) + aSession.startOperation("Export part") + anExportFeature = aPart.addFeature("Export") + anExportFeature.string("file_format").setValue(theFormat) + print("theFile=",theFile) + anExportFeature.string("file_path").setValue(theFile) + anExportFeature.string("ExportType").setValue("Regular") + aSelectionListAttr = anExportFeature.selectionList("selection_list") aSelectionListAttr.setSelectionType("solids") aSelectionListAttr.append(anImportFeature.firstResult(), anImportFeature.firstResult().shape()) - - anExportFeature.execute() aSession.finishOperation() - - assert os.path.exists(theFile), "{0}: Can not find exported file {1}".format(theType, theFile) - - # Test exported file by importing - testImport(theType, theFile, theVolume, theDelta) + + if theErrorExpected: + assert anExportFeature.error() != "" + aPart.removeFeature(anExportFeature) + else: + assert os.path.exists(theFile) + + # Test exported file by importing + testImport(theType, theFile, theVolume, theDelta) + +def testExportXAO(theFile, theEmptyFormat = False): + type = "XAO" + format = "XAO" + if theEmptyFormat: + type = "Regular" + format = "" + + # Import a reference part + aSession.startOperation("Add part") + aPartFeature = aSession.moduleDocument().addFeature("Part") + aSession.finishOperation() + aPart = aSession.activeDocument() + + aSession.startOperation("Import Box_1") + anImportFeature = aPart.addFeature("Import") + aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Brep", "box1.brep") + anImportFeature.string("file_path").setValue(aShapePath) + aSession.finishOperation() + + # Create groups + aSession.startOperation("First group") + aGroupFeature = aSession.activeDocument().addFeature("Group") + aGroupFeature.data().setName("boite_1") + aSelectionListAttr = aGroupFeature.selectionList("group_list") + aSelectionListAttr.setSelectionType("solid") + aSelectionListAttr.append(anImportFeature.lastResult(), None) + aSession.finishOperation() + + aSession.startOperation("Second Group") + aGroupFeature = aSession.activeDocument().addFeature("Group") + aGroupFeature.data().setName("") + aSelectionListAttr = aGroupFeature.selectionList("group_list") + aSelectionListAttr.setSelectionType("face") + aSelectionListAttr.append("box1_1/Shape_1") + aSelectionListAttr.append("box1_1/Shape_2") + aSession.finishOperation() + + aSession.startOperation("Create a field") + aField = aSession.activeDocument().addFeature("Field") + aSelectionListAttr = aField.selectionList("selected") + aSelectionListAttr.setSelectionType("face") + aSelectionListAttr.append("box1_1/Shape_1") + aSelectionListAttr.append("box1_1/Shape_2") + aComponentNames = aField.stringArray("components_names") + aComponentNames.setSize(2) # two components + aComponentNames.setValue(0, "temperatue") + aComponentNames.setValue(1, "porosity") + aStamps = aField.intArray("stamps") + aStamps.setSize(1) # one step + aStamps.setValue(0, 10) + aTables = aField.tables("values") + aTables.setType(2) # double + aTables.setSize(1 + 2, 2, 1) # default row + number of selected, number of compoents, number of steps (tables) + aTables.setValue(1., 0, 0, 0) # value, index of selection, index of component, index of step + aTables.setValue(2., 1, 0, 0) + aTables.setValue(3., 2, 0, 0) + aTables.setValue(4., 0, 1, 0) + aTables.setValue(5., 1, 1, 0) + aTables.setValue(6., 2, 1, 0) + aSession.finishOperation() + + # Export + aSession.startOperation("Export to XAO") + anExportFeature = aPart.addFeature("Export") + anExportFeature.string("xao_file_path").setValue(theFile) + anExportFeature.string("file_format").setValue(type) + anExportFeature.string("ExportType").setValue(type) + anExportFeature.string("xao_author").setValue("me") + anExportFeature.string("xao_geometry_name").setValue("mygeom") + aSession.finishOperation() + + # Check exported file + aRefPath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Xao", "box2.xao") + import filecmp + assert filecmp.cmp(theFile, aRefPath) if __name__ == '__main__': -#========================================================================= -# Export a shape into BREP -#========================================================================= - aRealVolume = 3.78827059338e-06 - testExport("BREP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brep"), aRealVolume, 10 ** -17) - testExport("BRP", "BREP", os.path.join(os.getcwd(), "Data", "screw_export.brp"), aRealVolume, 10 ** -17) -#========================================================================= -# Export a shape into STEP -#========================================================================= - testExport("STEP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.step"), 3.7882546512e-06, 10 ** -17) - testExport("STP", "STEP", os.path.join(os.getcwd(), "Data", "screw_export.stp"), 3.7882546512e-06, 10 ** -17) -#========================================================================= -# Export a shape into IGES -#========================================================================= - testExport("IGES-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.iges"), 1.98291079746e-06, 10 ** -17) - testExport("IGS-5.1", "IGES-5.1", os.path.join(os.getcwd(), "Data", "screw_export-5.1.igs"), 1.98291079746e-06, 10 ** -17) - testExport("IGES-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.iges"), 3.78827060085e-06, 10 ** -17) - testExport("IGS-5.3", "IGES-5.3", os.path.join(os.getcwd(), "Data", "screw_export-5.3.igs"), 3.78827060085e-06, 10 ** -17) -#========================================================================= -# End of test -#========================================================================= + with TemporaryDirectory() as tmp_dir: + #========================================================================= + # Export a shape into BREP + #========================================================================= + aRealVolume = 3.78827401738e-06 + testExport("BREP", "BREP", os.path.join(tmp_dir, "screw_export.brep"), aRealVolume, 10 ** -17) + testExport("BRP", "BREP", os.path.join(tmp_dir, "screw_export.brp"), aRealVolume, 10 ** -17) + testExport("Regular", "", os.path.join(tmp_dir, "screw_export.brep"), aRealVolume, 10 ** -17) + #========================================================================= + # Export a shape into STEP + #========================================================================= + testExport("STEP", "STEP", os.path.join(tmp_dir, "screw_export.step"), 3.78825807533e-06, 10 ** -17) + testExport("STP", "STEP", os.path.join(tmp_dir, "screw_export.stp"), 3.78825807533e-06, 10 ** -17) + testExport("Regular", "", os.path.join(tmp_dir, "screw_export.step"), 3.78825807533e-06, 10 ** -17) + #========================================================================= + # Export a shape into IGES + #========================================================================= + testExport("IGES-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17) + testExport("IGS-5.1", "IGES-5.1", os.path.join(tmp_dir, "screw_export-5.1.igs"), 3.78829613776e-06, 10 ** -17) + testExport("Regular", "", os.path.join(tmp_dir, "screw_export-5.1.iges"), 3.78829613776e-06, 10 ** -17) + testExport("IGES-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.iges"), 3.78827401651e-06, 10 ** -17) + testExport("IGS-5.3", "IGES-5.3", os.path.join(tmp_dir, "screw_export-5.3.igs"), 3.78827401651e-06, 10 ** -17) + #========================================================================= + # Export a shape into XAO + #========================================================================= + testExportXAO(os.path.join(tmp_dir, "export.xao")) + testExportXAO(os.path.join(tmp_dir, "export.xao"), True) + #========================================================================= + # Check error when export to unsupported format + #========================================================================= + testExport("Regular", "", os.path.join(tmp_dir, "screw_export.dwg"), 3.78825807533e-06, 10 ** -17, True) + #========================================================================= + # End of test + #========================================================================= + + assert(model.checkPythonDump())