From: Jérôme Date: Tue, 10 Nov 2020 15:20:22 +0000 (+0100) Subject: fix issues #20296 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=77ec1e64c1e419a02fbf46ff452ef6b5d623d09d;p=modules%2Fshaper.git fix issues #20296 --- diff --git a/src/ExchangeAPI/ExchangeAPI_Import.cpp b/src/ExchangeAPI/ExchangeAPI_Import.cpp index 13af1b262..550d3384e 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Import.cpp @@ -72,23 +72,25 @@ void ExchangeAPI_Import::setParameters(const std::string & theFilePath, const bool theColor) { fillAttribute(theFilePath, mystepfilePath); - fillAttribute("STEP", feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); - fillAttribute(theScalInterUnits, - feature()->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())); - fillAttribute(theMaterials, - feature()->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())); - fillAttribute(theColor, - feature()->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())); + fillAttribute("STEP", myimporttype); + fillAttribute(theScalInterUnits, myscalinterunits); + fillAttribute(theMaterials,mymaterials); + fillAttribute(theColor,mycolors); execute(); } //-------------------------------------------------------------------------------------- void ExchangeAPI_Import::setFilePath(const std::string & theFilePath) { - fillAttribute(theFilePath, myfilePath); + std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFilePath); - fillAttribute(anExtension, feature()->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID())); - execute(); + if (anExtension == "STEP" || anExtension == "STP") { + setParameters(theFilePath,true,false,false); + }else{ + fillAttribute(theFilePath, myfilePath); + fillAttribute(anExtension, myimporttype); + execute(); + } } //-------------------------------------------------------------------------------------- diff --git a/src/ExchangeAPI/ExchangeAPI_Import.h b/src/ExchangeAPI/ExchangeAPI_Import.h index 90562443a..9cb21b70c 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.h +++ b/src/ExchangeAPI/ExchangeAPI_Import.h @@ -62,7 +62,7 @@ public: INTERFACE_6(ExchangePlugin_ImportFeature::ID(), filePath, ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString, /** File path */, - stepimporttype, ExchangePlugin_ImportFeature::IMPORT_TYPE_ID(), + importtype, ExchangePlugin_ImportFeature::IMPORT_TYPE_ID(), ModelAPI_AttributeString, /**import type */, stepfilePath, ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID(), ModelAPI_AttributeString, /**step File path */, diff --git a/src/ExchangePlugin/Test/TestImportSTEP.py b/src/ExchangePlugin/Test/TestImportSTEP.py new file mode 100644 index 000000000..f58393477 --- /dev/null +++ b/src/ExchangePlugin/Test/TestImportSTEP.py @@ -0,0 +1,124 @@ +# 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 +# + +""" + TestImportStep.py + Unit test of ExchangePlugin_ImportFeature class for STEP +""" +#========================================================================= +# 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 GeomAPI import GeomAPI_Shape + +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 Import STEP +#========================================================================= +def testImportSTEP(): + + model.begin() + partSet = model.moduleDocument() + Part_1 = model.addPart(partSet) + Part_1_doc = Part_1.document() + aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "black_and_white.step") + print("aShapePath=",aShapePath) + Import_1 = model.addImportStep(Part_1_doc,aShapePath, True, True, True) + + model.do() + + # Check results + Import_1_Feature = Import_1.feature() + assert Import_1_Feature.error() == '' + assert Import_1_Feature.name() == "black_and_white" + assert len(Import_1_Feature.results()) == 1 + model.testNbSubShapes(Import_1, GeomAPI_Shape.SOLID, [2]) + + aCompositeFeature = featureToCompositeFeature(Import_1_Feature) + assert aCompositeFeature.numberOfSubs(False) == 4 + + aFeature1 = aCompositeFeature.subFeature(0, False) + assert aFeature1.getKind() == "Group" + assert aFeature1.name() == "Color_1" + + aSelectionList = aFeature1.selectionList("group_list") + assert aSelectionList.size() == 1 + + aFeature1 = aCompositeFeature.subFeature(1, False) + assert aFeature1.getKind() == "Group" + assert aFeature1.name() == "Color_2" + + aSelectionList = aFeature1.selectionList("group_list") + assert aSelectionList.size() == 1 + + aFeature1 = aCompositeFeature.subFeature(2, False) + assert aFeature1.getKind() == "Group" + assert aFeature1.name() == "Material_black" + + aSelectionList = aFeature1.selectionList("group_list") + assert aSelectionList.size() == 1 + + + aFeature1 = aCompositeFeature.subFeature(3, False) + assert aFeature1.getKind() == "Group" + assert aFeature1.name() == "Material_white" + + aSelectionList = aFeature1.selectionList("group_list") + assert aSelectionList.size() == 1 + + model.end() + +if __name__ == '__main__': + with TemporaryDirectory() as tmp_dir: + #========================================================================= + # Export a shape into STL + #========================================================================= + testImportSTEP() + #========================================================================= + # End of test + #========================================================================= diff --git a/src/ExchangePlugin/doc/examples/importStep.py b/src/ExchangePlugin/doc/examples/importStep.py index f6a81281a..54efab493 100644 --- a/src/ExchangePlugin/doc/examples/importStep.py +++ b/src/ExchangePlugin/doc/examples/importStep.py @@ -1,10 +1,11 @@ from salome.shaper import model +import os model.begin() +file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Step","black_and_white.step") partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() -Import_1 = model.addImportStep(Part_1_doc, - "/SOURCES/SAMPLES/Shapes/Step/black_and_white.step", True, True, True) +Import_1 = model.addImportStep(Part_1_doc,file_path, True, True, True) model.do() model.end() diff --git a/src/ExchangePlugin/doc/importFeature.rst b/src/ExchangePlugin/doc/importFeature.rst index c27faab76..33706fb40 100644 --- a/src/ExchangePlugin/doc/importFeature.rst +++ b/src/ExchangePlugin/doc/importFeature.rst @@ -131,9 +131,9 @@ The **Import to** combobox provides the list of destinations (one of existing Pa :param part: The current part object :param string: A file name string. - :param scalInterUnits: True if scale to UIS - :param materials: True to create groups from materials - :param colors: True to create groups from colors + :param boolean: True if scale to UIS + :param boolean: True to create groups from materials + :param boolean: True to create groups from colors Result """"""