// Author: Sergey BELASH
#include <ExchangePlugin_ImportFeature.h>
+
#include <GeomAlgoAPI_BREPImport.h>
-#include <GeomAlgoAPI_STEPImport.h>
#include <GeomAlgoAPI_IGESImport.h>
+#include <GeomAlgoAPI_STEPImport.h>
+#include <GeomAlgoAPI_Tools.h>
#include <GeomAPI_Shape.h>
+
#include <Config_Common.h>
#include <Config_PropManager.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultBody.h>
-#include <TCollection_AsciiString.hxx>
-#include <TDF_Label.hxx>
+
#include <TopoDS_Shape.hxx>
-#include <OSD_Path.hxx>
#include <algorithm>
#include <string>
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<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
*
*/
//=============================================================================
-//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
#include <GeomAlgoAPI.h>
-#include <TCollection_AsciiString.hxx>
+#include <string>
+
#include <TopoDS_Shape.hxx>
-#include <TDF_Label.hxx>
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_ */
*
*/
//=============================================================================
-//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;
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
return aResShape;
}
-}
-//}
+} // namespace IGESImport
#include <GeomAlgoAPI.h>
-#include <TCollection_AsciiString.hxx>
+#include <string>
+
#include <TopoDS_Shape.hxx>
-#include <TDF_Label.hxx>
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_ */
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;
try {
OCC_CATCH_SIGNALS;
- IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
+ IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str());
if (status == IFSelect_RetDone) {
#include <GeomAlgoAPI.h>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_HAsciiString.hxx>
+#include <string>
+
#include <TopoDS_Shape.hxx>
-#include <TDF_Label.hxx>
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_ */
-/*
- * 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 <clocale>
+#include <TCollection_AsciiString.hxx>
+#include <OSD_Path.hxx>
+
using namespace GeomAlgoAPI_Tools;
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();
+}
-/*
- * 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_
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_ */