From: cg246364 Date: Tue, 15 Dec 2020 12:58:09 +0000 (+0100) Subject: Fixed issue #20475 X-Git-Tag: V9_7_0a1~67^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=11b409dbd9619352ea7fb5732aba991e6c65aef8;p=modules%2Fshaper.git Fixed issue #20475 --- diff --git a/src/ConnectorAPI/Test/TestImportSTEP.py b/src/ConnectorAPI/Test/TestImportSTEP.py index 84b6d90ce..c3a80f8a0 100644 --- a/src/ConnectorAPI/Test/TestImportSTEP.py +++ b/src/ConnectorAPI/Test/TestImportSTEP.py @@ -31,14 +31,10 @@ 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 * @@ -46,7 +42,6 @@ from GeomAlgoAPI import * __updated__ = "2015-05-22" salome.salome_init(1) -geompy = geomBuilder.New() #========================================================================= # Help functions @@ -115,10 +110,4 @@ def testImportSTEP(): if __name__ == '__main__': with TemporaryDirectory() as tmp_dir: - #========================================================================= - # Export a shape into STL - #========================================================================= testImportSTEP() - #========================================================================= - # End of test - #========================================================================= diff --git a/src/ExchangePlugin/ExchangePlugin_Import.h b/src/ExchangePlugin/ExchangePlugin_Import.h index 994b3c8be..eeac51794 100644 --- a/src/ExchangePlugin/ExchangePlugin_Import.h +++ b/src/ExchangePlugin/ExchangePlugin_Import.h @@ -123,10 +123,6 @@ class ExchangePlugin_Import : public ModelAPI_Feature /// \param theID identifier of changed attribute EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// Called to update part - EXCHANGEPLUGIN_EXPORT - void updatePart(AttributeStringArrayPtr& thePartsAttr, AttributeIntegerPtr& theTargetAttr); - /// Computes or recomputes the results EXCHANGEPLUGIN_EXPORT virtual void execute(); @@ -135,6 +131,11 @@ class ExchangePlugin_Import : public ModelAPI_Feature /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false. EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; } + + private: + /// Called to update part + EXCHANGEPLUGIN_EXPORT + void updatePart(AttributeStringArrayPtr& thePartsAttr, AttributeIntegerPtr& theTargetAttr); }; #endif /* IMPORT_IMPORTFEATURE_H_ */ diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index dc3542679..24c821f1c 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -63,8 +63,6 @@ #include -#include -#include ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature() @@ -154,7 +152,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) std::string anError; std::shared_ptr aGeomShape; - std::map< std::wstring, std::list> theMaterialShape; + std::map> theMaterialShape; std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); data()->setName(Locale::Convert::toWString(anObjectName)); @@ -171,31 +169,22 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) bool anScalInterUnits = boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value(); - try{ + // Process groups/fields + std::shared_ptr aRefListOfGroups = + std::dynamic_pointer_cast(data()->attribute(FEATURES_ID())); - aResult->clearShapeNameAndColor(); - // Process groups/fields - std::shared_ptr aRefListOfGroups = - std::dynamic_pointer_cast(data()->attribute(FEATURES_ID())); - - // Remove previous groups/fields stored in RefList - std::list anGroupList = aRefListOfGroups->list(); - std::list::iterator anGroupIt = anGroupList.begin(); - for (; anGroupIt != anGroupList.end(); ++anGroupIt) { - std::shared_ptr aFeature = ModelAPI_Feature::feature(*anGroupIt); - if (aFeature) + // Remove previous groups/fields stored in RefList + std::list anGroupList = aRefListOfGroups->list(); + std::list::iterator anGroupIt = anGroupList.begin(); + for (; anGroupIt != anGroupList.end(); ++anGroupIt) { + std::shared_ptr aFeature = ModelAPI_Feature::feature(*anGroupIt); + if (aFeature) document()->removeFeature(aFeature); - } - - aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits, - anMaterialsGroupSelected, anColorGroupSelected, - theMaterialShape,anError); - - } - catch (OSD_Exception& e) { - //Try to load STEP file without colors... - aGeomShape = STEPImport(theFileName, anExtension,anScalInterUnits,anError); } + + aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits, + anMaterialsGroupSelected, anColorGroupSelected, + theMaterialShape, anError); } else if (anExtension == "IGES" || anExtension == "IGS") { aGeomShape = IGESImport(theFileName, anExtension, anError); } else { @@ -224,6 +213,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) } setResult(aResult); + aResult->clearShapeNameAndColor(); } @@ -232,13 +222,13 @@ void ExchangePlugin_ImportFeature::setColorGroups( { std::vector aColor; int anIndice = 1; - std::list< std::vector > aColorsRead; + std::list> aColorsRead; ModelAPI_Tools::getColor(theResultBody, aColor); if (!aColor.empty() ){ std::wstringstream aColorName; aColorName <selectionList("group_list"); ModelAPI_Tools::getColor(theResultBody, aColor); - if (!aColor.empty() ){ - if (aColor == theColor ) { + if (!aColor.empty()){ + if (aColor == theColor) { GeomShapePtr aShape = theResultBody->shape(); - aSelectionList->setSelectionType(aShape->shapeTypeStr() ); + aSelectionList->setSelectionType(aShape->shapeTypeStr()); aSelectionList->append(theResultBody,aShape); } } @@ -290,9 +280,9 @@ void ExchangePlugin_ImportFeature::setColorGroup( ModelAPI_Tools::getColor(*aRes, aColor); GeomShapePtr aShape = (*aRes)->shape(); - if (!aColor.empty() ){ - if (aRes->get() && aColor == theColor ) { - aSelectionList->setSelectionType(aShape->shapeTypeStr() ); + if (!aColor.empty()){ + if (aRes->get() && aColor == theColor) { + aSelectionList->setSelectionType(aShape->shapeTypeStr()); aSelectionList->append(theResultBody,aShape); } } @@ -304,7 +294,7 @@ void ExchangePlugin_ImportFeature::setColorGroup( ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor); - if (aSelectionList->size() == 0 ){ + if (aSelectionList->size() == 0) { document()->removeFeature(aGroupFeature); } } @@ -314,7 +304,7 @@ void ExchangePlugin_ImportFeature::setMaterielGroup( std::map< std::wstring,std::list>& theMaterialShape) { std::map< std::wstring, std::list>::iterator anIt; - for( anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) { + for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) { std::shared_ptr aGroupFeature = addFeature("Group"); // group name @@ -322,19 +312,18 @@ void ExchangePlugin_ImportFeature::setMaterielGroup( // fill selection AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); - GeomShapePtr aShape = theResultBody->shape(); std::list allRes; ModelAPI_Tools::allSubs(theResultBody, allRes); - for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) { + for (std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) { GeomShapePtr aShape = (*aRes)->shape(); - for(std::list::iterator aResMat = anIt->second.begin(); + for (std::list::iterator aResMat = anIt->second.begin(); aResMat != anIt->second.end(); ++aResMat) { if (aRes->get() && ((*aRes)->data()->name() == (*aResMat))) { aSelectionList->append(theResultBody,aShape); - aSelectionList->setSelectionType(aShape->shapeTypeStr() ); + aSelectionList->setSelectionType(aShape->shapeTypeStr()); break; } } diff --git a/src/ExchangePlugin/ExchangePlugin_msg_fr.ts b/src/ExchangePlugin/ExchangePlugin_msg_fr.ts index 72f1663ec..2774f3d59 100644 --- a/src/ExchangePlugin/ExchangePlugin_msg_fr.ts +++ b/src/ExchangePlugin/ExchangePlugin_msg_fr.ts @@ -296,12 +296,12 @@ Create groups from - créer des groupes à partir + Créer des groupes à partir - Materials - Matériels - + Materials + Matériels + Import:file_path @@ -318,24 +318,25 @@ - Import:step_scale_inter_units - - Scale to International System of Units - Mettre àl'échelle du système international d'unités - + Import:step_scale_inter_units + + Scale to International System of Units + Mettre à l'échelle du système international d'unités + - Import:step_materials - - Materials - Matériels - + + Import:step_materials + + Materials + Matériels + - Import:step_materials - - Colors - Couleurs - + Import:step_colors + + Colors + Couleurs + ImportMacro @@ -347,11 +348,11 @@ Import a file Importer un fichier - - + Create groups from - créer des groupes à partir + Créer des groupes à partir + ImportMacro:target_part @@ -370,21 +371,22 @@ ImportMacro:step_scale_inter_units Scale to International System of Units - Mettre àl'échelle du système international d'unités + Mettre à l'échelle du système international d'unités - Import:step_materials - - Materials - Matériels - + + ImportMacro:step_materials + + Materials + Matériels + - Import:step_materials - - Colors - Couleurs - + ImportMacro:step_colors + + Colors + Couleurs + ImportMacro:file_path @@ -394,13 +396,12 @@ - ImportMacro:step_file_path - - Import file - Importer un fichier - - - + ImportMacro:step_file_path + + Import file + Importer un fichier + + ImportMacro:file_path:ExchangePlugin_ImportFormat diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 7e557e32d..68818b783 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -59,6 +59,46 @@ #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +#include + +//================================================================================================= +bool readUnits(const STEPControl_Reader& aReader, + const bool theScalInterUnits, + std::string& theError) +{ + // Regard or not the model units + if (!theScalInterUnits) { + // set UnitFlag to units from file + TColStd_SequenceOfAsciiString anUnitLengthNames; + TColStd_SequenceOfAsciiString anUnitAngleNames; + TColStd_SequenceOfAsciiString anUnitSolidAngleNames; + aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); + if (anUnitLengthNames.Length() > 0) { + TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); + if (aLenUnits == "millimetre") + Interface_Static::SetCVal("xstep.cascade.unit", "MM"); + else if (aLenUnits == "centimetre") + Interface_Static::SetCVal("xstep.cascade.unit", "CM"); + else if (aLenUnits == "metre" || aLenUnits.IsEmpty()) + Interface_Static::SetCVal("xstep.cascade.unit", "M"); + else if (aLenUnits == "INCH") + Interface_Static::SetCVal("xstep.cascade.unit", "INCH"); + else { + theError = "The file contains not supported units."; + return false; + } + // TODO (for other units than mm, cm, m or inch) + //else if (aLenUnits == "") + // Interface_Static::SetCVal("xstep.cascade.unit", "???"); + } + } + else { + //cout<<"need re-scale a model"< STEPImport(const std::string& theFileName, IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str()); if (status == IFSelect_RetDone) { - // Regard or not the model units - if (!theScalInterUnits) { - // set UnitFlag to units from file - TColStd_SequenceOfAsciiString anUnitLengthNames; - TColStd_SequenceOfAsciiString anUnitAngleNames; - TColStd_SequenceOfAsciiString anUnitSolidAngleNames; - aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); - if (anUnitLengthNames.Length() > 0) { - TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); - if (aLenUnits == "millimetre") - Interface_Static::SetCVal("xstep.cascade.unit", "MM"); - else if (aLenUnits == "centimetre") - Interface_Static::SetCVal("xstep.cascade.unit", "CM"); - else if (aLenUnits == "metre" || aLenUnits.IsEmpty()) - Interface_Static::SetCVal("xstep.cascade.unit", "M"); - else if (aLenUnits == "INCH") - Interface_Static::SetCVal("xstep.cascade.unit", "INCH"); - else { - theError = "The file contains not supported units."; - std::shared_ptr aGeomShape(new GeomAPI_Shape); - aGeomShape->setImpl(new TopoDS_Shape(aResShape)); - return aGeomShape; - } - // TODO (for other units than mm, cm, m or inch) - //else if (aLenUnits == "") - // Interface_Static::SetCVal("xstep.cascade.unit", "???"); - } - } - else { - //cout<<"need re-scale a model"< aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape()); + return aGeomShape; } Standard_Boolean failsonly = Standard_False; @@ -209,75 +221,51 @@ GeomShapePtr STEPImportAttributs(const std::string& theFileName, std::string& theError) { - STEPControl_Reader aReader; - std::shared_ptr aGeomShape(new GeomAPI_Shape); - - Interface_Static::SetCVal("xstep.cascade.unit","M"); - Interface_Static::SetIVal("read.step.ideas", 1); - Interface_Static::SetIVal("read.step.nonmanifold", 1); - try { - OCC_CATCH_SIGNALS; + STEPControl_Reader aReader; + std::shared_ptr aGeomShape(new GeomAPI_Shape); - IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str()); + Interface_Static::SetCVal("xstep.cascade.unit","M"); + Interface_Static::SetIVal("read.step.ideas", 1); + Interface_Static::SetIVal("read.step.nonmanifold", 1); - if (status == IFSelect_RetDone) { + try { + OCC_CATCH_SIGNALS; - // Regard or not the model units - if (!theScalInterUnits) { - // set UnitFlag to units from file - TColStd_SequenceOfAsciiString anUnitLengthNames; - TColStd_SequenceOfAsciiString anUnitAngleNames; - TColStd_SequenceOfAsciiString anUnitSolidAngleNames; - aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); - if (anUnitLengthNames.Length() > 0) { - TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); - if (aLenUnits == "millimetre") - Interface_Static::SetCVal("xstep.cascade.unit", "MM"); - else if (aLenUnits == "centimetre") - Interface_Static::SetCVal("xstep.cascade.unit", "CM"); - else if (aLenUnits == "metre" || aLenUnits.IsEmpty()) - Interface_Static::SetCVal("xstep.cascade.unit", "M"); - else if (aLenUnits == "INCH") - Interface_Static::SetCVal("xstep.cascade.unit", "INCH"); - else { - theError = "The file contains not supported units."; - aGeomShape->setImpl(new TopoDS_Shape()); - return aGeomShape; - } - // TODO (for other units than mm, cm, m or inch) - //else if (aLenUnits == "") - // Interface_Static::SetCVal("xstep.cascade.unit", "???"); + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str()); + + if (status == IFSelect_RetDone) { + // Regard or not the model units + if( !readUnits(aReader,theScalInterUnits,theError)) { + aGeomShape->setImpl(new TopoDS_Shape()); + return aGeomShape; } } - else { - //cout<<"need re-scale a model"<setImpl(new TopoDS_Shape()); + return aGeomShape; } - } - catch (Standard_Failure const& anException) { - theError = anException.GetMessageString(); - aGeomShape->setImpl(new TopoDS_Shape()); - return aGeomShape; - } - STEPCAFControl_Reader aCafreader; - aCafreader.SetColorMode(true); - aCafreader.SetNameMode(true); - aCafreader.SetMatMode(true); + STEPCAFControl_Reader aCafreader; + aCafreader.SetColorMode(true); + aCafreader.SetNameMode(true); + aCafreader.SetMatMode(true); - if(aCafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) { - theError = "Wrong format of the imported file. Can't import file."; - std::shared_ptr aGeomShape(new GeomAPI_Shape); - aGeomShape->setImpl(new TopoDS_Shape()); - return aGeomShape; - } + if (aCafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) { + theError = "Wrong format of the imported file. Can't import file."; + std::shared_ptr aGeomShape(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape()); + return aGeomShape; + } - return readAttributes(aCafreader, - theResultBody, - theMaterials, - theMaterialShape, - theError); + return readAttributes(aCafreader, + theResultBody, + theMaterials, + theMaterialShape, + theError); + } catch (OSD_Exception& e) { + //Try to load STEP file without colors... + return STEPImport(theFileName,"",theScalInterUnits,theError); + } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index 807d4f86d..b77defd14 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -329,12 +329,12 @@ void storeMaterial( std::shared_ptr theResultBody, Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti); Handle(StepBasic_ProductDefinition) aProdDef; - if (aPDS.IsNull() == Standard_False) { + if (!aPDS.IsNull()) { // Product Definition Shape ==> Product Definition aProdDef = aPDS->Definition().ProductDefinition(); } - if (aProdDef.IsNull() == Standard_False) { + if (!aProdDef.IsNull()) { // Product Definition ==> Property Definition const Interface_Graph &aGraph = theTP->Graph(); Interface_EntityIterator aSubs = aGraph.Sharings(aProdDef); @@ -344,7 +344,7 @@ void storeMaterial( std::shared_ptr theResultBody, Handle(StepRepr_PropertyDefinition) aPropD = Handle(StepRepr_PropertyDefinition)::DownCast(aSubs.Value()); - if (aPropD.IsNull() == Standard_False) { + if (!aPropD.IsNull()) { // Property Definition ==> Representation. Interface_EntityIterator aSubs1 = aGraph.Sharings(aPropD); @@ -353,11 +353,11 @@ void storeMaterial( std::shared_ptr theResultBody, Handle(StepRepr_PropertyDefinitionRepresentation):: DownCast(aSubs1.Value()); - if (aPDR.IsNull() == Standard_False) { + if (!aPDR.IsNull()) { // Property Definition ==> Material Name. Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation(); - if (aRepr.IsNull() == Standard_False) { + if (!aRepr.IsNull()) { Standard_Integer anIr; for(anIr = 1; anIr <= aRepr->NbItems(); anIr++) { @@ -365,10 +365,10 @@ void storeMaterial( std::shared_ptr theResultBody, Handle(StepRepr_DescriptiveRepresentationItem) aDRI = Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI); - if (aDRI.IsNull() == Standard_False) { + if (!aDRI.IsNull()) { // Get shape from Product Definition Handle(TCollection_HAsciiString) aMatName = aDRI->Name(); - if (aMatName.IsNull() == Standard_False) { + if (!aMatName.IsNull()) { TCollection_ExtendedString aMatNameExt (aMatName->ToCString()); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 8d943e9c8..68b34a177 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -117,6 +117,7 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES Config GeomAPI + Locale ) SET(CMAKE_SWIG_FLAGS -threads -w325,321,362,383,302,403,451,473) ADD_DEFINITIONS(-DMODELAPI_EXPORTS) @@ -130,11 +131,6 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/Locale - ${OpenCASCADE_INCLUDE_DIR} - ${OpenCASCADE_DataExchange_LIBRARIES} - ${OpenCASCADE_ModelingAlgorithms_LIBRARIES} - ${OpenCASCADE_ApplicationFramework_LIBRARIES} - )