From 2dd4d315bde6af849d68f1d3cd190ac3ec219527 Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 29 Jun 2015 12:25:41 +0300 Subject: [PATCH] Issue #608: Usage of OCCT in interface -- Remove OCCT from *Import interfaces --- .../ExchangePlugin_ImportFeature.cpp | 37 +++++++++---------- src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp | 13 +++---- src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h | 12 +++--- src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp | 13 +++---- src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h | 12 +++--- src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp | 8 ++-- src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h | 20 ++++------ src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp | 35 +++++++++++++++--- src/GeomAlgoAPI/GeomAlgoAPI_Tools.h | 23 +++++++++--- 9 files changed, 98 insertions(+), 75 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index b10ae4cf1..1716adb37 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -5,11 +5,14 @@ // Author: Sergey BELASH #include + #include -#include #include +#include +#include #include + #include #include @@ -18,10 +21,8 @@ #include #include #include -#include -#include + #include -#include #include #include @@ -72,34 +73,30 @@ void ExchangePlugin_ImportFeature::execute() 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 anExtension = aPath.Extension(); - // ".brep" -> "BREP", TCollection_AsciiString are numbered from 1 - anExtension = anExtension.SubString(2, anExtension.Length()); - anExtension.UpperCase(); + // ".brep" -> "BREP" + std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName); // Perform the import - TCollection_AsciiString anError; + std::string anError; TopoDS_Shape aShape; if (anExtension == "BREP" || anExtension == "BRP") { - aShape = BREPImport::Import(aFileName, anExtension, anError); + aShape = BREPImport::Import(theFileName, anExtension, anError); } else if (anExtension == "STEP" || anExtension == "STP") { - aShape = STEPImport::Import(aFileName, anExtension, anError); + aShape = STEPImport::Import(theFileName, anExtension, anError); } else if (anExtension == "IGES" || anExtension == "IGS") { - aShape = IGESImport::Import(aFileName, anExtension, anError); + aShape = IGESImport::Import(theFileName, anExtension, anError); } // Check if shape is valid if ( aShape.IsNull() ) { - const static std::string aShapeError = - "An error occurred while importing " + theFileName + ": " + anError.ToCString(); - setError(aShapeError); - return false; - } + const static std::string aShapeError = + "An error occurred while importing " + theFileName + ": " + anError; + setError(aShapeError); + return false; + } // Pass the results into the model - std::string anObjectName = aPath.Name().ToCString(); + std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); data()->setName(anObjectName); std::shared_ptr aResultBody = document()->createBody(data()); std::shared_ptr aGeomShape(new GeomAPI_Shape); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp index 32cb7c95a..9cb93117d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp @@ -10,23 +10,22 @@ * */ //============================================================================= -//extern "C" { namespace BREPImport { -TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString&, - TCollection_AsciiString& theError) + +TopoDS_Shape Import(const std::string& theFileName, + const std::string&, + std::string& theError) { #ifdef _DEBUG std::cout << "Import BREP from file " << theFileName << std::endl; #endif TopoDS_Shape aShape; BRep_Builder aBuilder; - BRepTools::Read(aShape, theFileName.ToCString(), aBuilder); + BRepTools::Read(aShape, theFileName.c_str(), aBuilder); if (aShape.IsNull()) { theError = "BREP Import failed"; } return aShape; } -} -//} +} // namespace BREPImport diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h index 6afbdf0ca..93fce71fd 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h @@ -12,18 +12,18 @@ #include -#include +#include + #include -#include namespace BREPImport { /// Implementation of the import BREP files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError); +TopoDS_Shape Import(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); -} +} // namespace BREPImport #endif /* GEOMALGOAPI_BREPIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp index 8e20cb32a..b15b0d19e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp @@ -11,11 +11,11 @@ * */ //============================================================================= -//extern "C" { namespace IGESImport { -TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString&, - TCollection_AsciiString& theError) + +TopoDS_Shape Import(const std::string& theFileName, + const std::string&, + std::string& theError) { #ifdef _DEBUG std::cout << "Import IGES from file " << theFileName << std::endl; @@ -23,7 +23,7 @@ TopoDS_Shape Import(const TCollection_AsciiString& theFileName, TopoDS_Shape aResShape; IGESControl_Reader aReader; try { - IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.ToCString() ); + IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.c_str() ); if (status == IFSelect_RetDone) { #ifdef _DEBUG @@ -67,5 +67,4 @@ TopoDS_Shape Import(const TCollection_AsciiString& theFileName, return aResShape; } -} -//} +} // namespace IGESImport diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h index 9bdb3ad84..f2a3e2dc7 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h @@ -12,18 +12,18 @@ #include -#include +#include + #include -#include namespace IGESImport { /// Implementation of the import IGES files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError); +TopoDS_Shape Import(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); -} +} // namespace IGESImport #endif /* GEOMALGOAPI_IGESIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp index 4bc7f2f64..bb304eea9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp @@ -364,9 +364,9 @@ Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFil return aValue; } -TopoDS_Shape Import (const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError) +TopoDS_Shape Import (const std::string& theFileName, + const std::string& theFormatName, + std::string& theError) { TopoDS_Shape aResShape; @@ -387,7 +387,7 @@ TopoDS_Shape Import (const TCollection_AsciiString& theFileName, try { OCC_CATCH_SIGNALS; - IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str()); if (status == IFSelect_RetDone) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h index 5955ddbf1..6f3506248 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h @@ -12,24 +12,18 @@ #include -#include -#include +#include + #include -#include namespace STEPImport { -/// Implementation of the import parameter from the STEP file -GEOMALGOAPI_EXPORT -Handle(TCollection_HAsciiString) GetValue(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theParameterName, - TCollection_AsciiString& theError); - /// Implementation of the import STEP files algorithms GEOMALGOAPI_EXPORT -TopoDS_Shape Import(const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& theFormatName, - TCollection_AsciiString& theError); -} +TopoDS_Shape Import(const std::string& theFileName, + const std::string& theFormatName, + std::string& theError); + +} // namespace STEPImport #endif /* GEOMALGOAPI_STEPIMPORT_H_ */ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp index 50a3907eb..5632155e9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp @@ -1,14 +1,16 @@ -/* - * GeomAlgoAPI_Tools.cpp - * - * Created on: May 18, 2015 - * Author: spo - */ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Tools.cpp +// Created: May 18, 2015 +// Author: Sergey POKHODENKO #include "GeomAlgoAPI_Tools.h" #include +#include +#include + using namespace GeomAlgoAPI_Tools; Localizer::Localizer() @@ -21,3 +23,24 @@ Localizer::~Localizer() { std::setlocale(LC_NUMERIC, myCurLocale.c_str()); } + + +std::string File_Tools::extension(const std::string& theFileName) +{ + // retrieve the file and plugin library names + TCollection_AsciiString aFileName(theFileName.c_str()); + OSD_Path aPath(aFileName); + TCollection_AsciiString anExtension = aPath.Extension(); + // TCollection_AsciiString are numbered from 1 + anExtension = anExtension.SubString(2, anExtension.Length()); + anExtension.UpperCase(); + return anExtension.ToCString(); +} + +std::string File_Tools::name(const std::string& theFileName) +{ + // retrieve the file and plugin library names + TCollection_AsciiString aFileName(theFileName.c_str()); + OSD_Path aPath(aFileName); + return aPath.Name().ToCString(); +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h index 2f1e0eb92..3524e188e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tools.h @@ -1,9 +1,8 @@ -/* - * GeomAlgoAPI_Tools.h - * - * Created on: May 18, 2015 - * Author: spo - */ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Tools.h +// Created: May 18, 2015 +// Author: Sergey POKHODENKO #ifndef GEOMALGOAPI_TOOLS_H_ #define GEOMALGOAPI_TOOLS_H_ @@ -23,6 +22,18 @@ private: std::string myCurLocale; }; +class File_Tools { +public: + /** + * Returns an extension of theFileName + */ + static std::string extension(const std::string& theFileName); + /** + * Returns a name of theFileName + */ + static std::string name(const std::string& theFileName); +}; + } // GeomAlgoAPI_Tools #endif /* GEOMALGOAPI_TOOLS_H_ */ -- 2.39.2