From: Sergey POKHODENKO Date: Mon, 18 May 2015 07:04:30 +0000 (+0300) Subject: Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Remove redundant code... X-Git-Tag: V_1.2.0~145^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=144fb75724b240b9a627ce7179f43e04ee90b465;p=modules%2Fshaper.git Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Remove redundant code in import/export --- diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 166bda9b6..a67b57bcc 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -89,7 +89,7 @@ void ExchangePlugin_ExportFeature::execute() AttributeSelectionListPtr aSelectionListAttr = this->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()); std::list > aShapes; - for ( int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i ) { + for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) { aShapes.push_back(aSelectionListAttr->value(i)->value()); } std::shared_ptr aShape = @@ -98,35 +98,24 @@ void ExchangePlugin_ExportFeature::execute() exportFile(aFilePath, aFormat, aShape); } -std::list ExchangePlugin_ExportFeature::getFormats() const -{ - // This value is a copy of string_list attribute of format_choice in plugin-Exchange.xml - // XPath:plugin-Exchange.xml:string(//*[@id="format_choice"]/@string_list) - std::string aFormats = "BREP STEP IGES-5.1 IGES-5.3"; - return ExchangePlugin_Tools::split(aFormats, ' '); -} - bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName, const std::string& theFormat, std::shared_ptr theShape) { // retrieve the file and plugin library names TCollection_AsciiString aFileName(theFileName.c_str()); - OSD_Path aPath(aFileName); TCollection_AsciiString aFormatName(theFormat.c_str()); // Perform the export TCollection_AsciiString anError; - TDF_Label anUnknownLabel = TDF_Label(); - TopoDS_Shape aShape(theShape->impl()); bool aResult = false; if (aFormatName == "BREP") { - aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel); + aResult = BREPExport::Export(aFileName, aFormatName, aShape, anError); } else if (aFormatName == "STEP") { - aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel); + aResult = STEPExport::Export(aFileName, aFormatName, aShape, anError); } else if (aFormatName.SubString(1, 4) == "IGES") { - aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel); + aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError); } else { anError = TCollection_AsciiString("Unsupported format ") + aFormatName; } diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h index fb45a27fc..6613f9609 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.h @@ -17,7 +17,7 @@ */ class ExchangePlugin_ExportFeature : public ModelAPI_Feature { - public: +public: inline static const std::string& ID() { static const std::string MY_EXPORT_ID("Export"); diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index f5bf2bb11..ea085c13f 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -63,11 +63,12 @@ void ExchangePlugin_ImportFeature::initAttributes() */ void ExchangePlugin_ImportFeature::execute() { - AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast( - data()->attribute(ExchangePlugin_ImportFeature::FILE_PATH_ID())); + AttributeStringPtr aFilePathAttr = + this->string(ExchangePlugin_ImportFeature::FILE_PATH_ID()); std::string aFilePath = aFilePathAttr->value(); - if(aFilePath.empty()) + if (aFilePath.empty()) return; + importFile(aFilePath); } @@ -76,26 +77,25 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName) // retrieve the file and plugin library names TCollection_AsciiString aFileName(theFileName.c_str()); OSD_Path aPath(aFileName); - TCollection_AsciiString aFormatName = aPath.Extension(); + TCollection_AsciiString anExtension = aPath.Extension(); // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1 - aFormatName = aFormatName.SubString(2, aFormatName.Length()); - aFormatName.UpperCase(); + anExtension = anExtension.SubString(2, anExtension.Length()); + anExtension.UpperCase(); // Perform the import TCollection_AsciiString anError; - TDF_Label anUnknownLabel = TDF_Label(); TopoDS_Shape aShape; - if (aFormatName == "BREP") { - aShape = BREPImport::Import(aFileName, aFormatName, anError, anUnknownLabel); - } else if (aFormatName == "STEP" || aFormatName == "STP") { - aShape = STEPImport::Import(aFileName, aFormatName, anError, anUnknownLabel); - } else if (aFormatName == "IGES") { - aShape = IGESImport::Import(aFileName, aFormatName, anError, anUnknownLabel); + if (anExtension == "BREP") { + aShape = BREPImport::Import(aFileName, anExtension, anError); + } else if (anExtension == "STEP" || anExtension == "STP") { + aShape = STEPImport::Import(aFileName, anExtension, anError); + } else if (anExtension == "IGES") { + aShape = IGESImport::Import(aFileName, anExtension, anError); } // Check if shape is valid if ( aShape.IsNull() ) { - const static std::string aShapeError = + const static std::string aShapeError = "An error occurred while importing " + theFileName + ": " + anError.ToCString(); setError(aShapeError); return false; @@ -127,8 +127,4 @@ void ExchangePlugin_ImportFeature::loadNamingDS( int aTag(1); std::string aNameMS = "Shape"; theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag); - //std::string aNameDE = "DiscEdges"; - //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag); - //std::string aNameDV = "DiscVertexes"; - //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp index 0499c7587..506a08264 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp @@ -15,7 +15,7 @@ namespace BREPExport { bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString&, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, const TDF_Label&) + TCollection_AsciiString& theError) { #ifdef _DEBUG std::cout << "Export BREP into file " << theFileName << std::endl; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h index 90496b0e4..88acbf5a1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h @@ -23,7 +23,7 @@ GEOMALGOAPI_EXPORT bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, const TDF_Label&); + TCollection_AsciiString& theError); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp index 2df29ebc0..32cb7c95a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp @@ -14,7 +14,7 @@ namespace BREPImport { TopoDS_Shape Import(const TCollection_AsciiString& theFileName, const TCollection_AsciiString&, - TCollection_AsciiString& theError, const TDF_Label&) + TCollection_AsciiString& theError) { #ifdef _DEBUG std::cout << "Import BREP from file " << theFileName << std::endl; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h index aa0c7202d..6afbdf0ca 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h @@ -22,7 +22,7 @@ namespace BREPImport { GEOMALGOAPI_EXPORT TopoDS_Shape Import(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError, const TDF_Label&); + TCollection_AsciiString& theError); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp index 425f58102..593c49670 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp @@ -83,7 +83,7 @@ namespace IGESExport { bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, const TDF_Label&) + TCollection_AsciiString& theError) { // theFormatName expected "IGES-5.1", "IGES-5.3"... TCollection_AsciiString aVersion = theFormatName.Token("-", 2); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h index e52a263e7..4f0f3cc34 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h @@ -23,7 +23,7 @@ GEOMALGOAPI_EXPORT bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, const TDF_Label&); + TCollection_AsciiString& theError); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp index 481c13521..8e20cb32a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp @@ -15,7 +15,7 @@ namespace IGESImport { TopoDS_Shape Import(const TCollection_AsciiString& theFileName, const TCollection_AsciiString&, - TCollection_AsciiString& theError, const TDF_Label&) + TCollection_AsciiString& theError) { #ifdef _DEBUG std::cout << "Import IGES from file " << theFileName << std::endl; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h index c01f7c1d5..9bdb3ad84 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h @@ -22,7 +22,7 @@ namespace IGESImport { GEOMALGOAPI_EXPORT TopoDS_Shape Import(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError, const TDF_Label&); + TCollection_AsciiString& theError); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp index 5cc71b056..734d91fb8 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp @@ -12,8 +12,7 @@ namespace STEPExport { bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, - const TDF_Label& theShapeLabel) + TCollection_AsciiString& theError) { #ifdef _DEBUG std::cout << "Export STEP into file " << theFileName.ToCString() << std::endl; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h index f0bcec172..e05a59ff1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h @@ -30,8 +30,7 @@ GEOMALGOAPI_EXPORT bool Export(const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, const TopoDS_Shape& theShape, - TCollection_AsciiString& theError, - const TDF_Label& theShapeLabel); + TCollection_AsciiString& theError); } #endif /* GEOMALGOAPI_STEPEXPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 8ed138604..4bc7f2f64 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -366,8 +366,7 @@ Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFil TopoDS_Shape Import (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError, - const TDF_Label& theShapeLabel) + TCollection_AsciiString& theError) { TopoDS_Shape aResShape; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h index dc3299669..5955ddbf1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h @@ -28,8 +28,8 @@ Handle(TCollection_HAsciiString) GetValue(const TCollection_AsciiString& theFile /// Implementation of the import STEP files algorithms GEOMALGOAPI_EXPORT TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, - const TDF_Label& theShapeLabel); + const TCollection_AsciiString& theFormatName, + TCollection_AsciiString& theError); } #endif /* GEOMALGOAPI_STEPIMPORT_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index 5da22f5eb..3292d70f2 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -146,9 +146,11 @@ QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const { SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list allValidators; std::list > allArguments; aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments); + QStringList aResult; std::list anArgumentList = allArguments.front(); std::list::const_iterator it = anArgumentList.begin();