Salome HOME
Issue #608: Usage of OCCT in interface -- Remove OCCT from *Import interfaces
authorspo <sergey.pokhodenko@opencascade.com>
Mon, 29 Jun 2015 09:25:41 +0000 (12:25 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Mon, 29 Jun 2015 10:08:56 +0000 (13:08 +0300)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h
src/GeomAlgoAPI/GeomAlgoAPI_Tools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Tools.h

index b10ae4cf1453d2700ba5e19d9ce9f070b345816c..1716adb37e54150fb7e59e74c704f895024d5fe1 100644 (file)
@@ -5,11 +5,14 @@
 // 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>
@@ -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<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
index 32cb7c95a67c461068f2ff681051729acfac2513..9cb93117d5ad0257f466f52546b217db38cd8f8b 100644 (file)
  *
  */
 //=============================================================================
-//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
index 6afbdf0cad1d1c830fe72af945630c70723455a9..93fce71fd4d4ff9b85d04dfeabf6d13d901e509e 100644 (file)
 
 #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_ */
index 8e20cb32aec65b37fb6cbe8b2551efb1605bdeaa..b15b0d19e63504d4b020190d94298d1531b657b7 100644 (file)
  *
  */
 //=============================================================================
-//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
index 9bdb3ad84515fdd4abfd2ded6c9818a603edba97..f2a3e2dc7324a25b202a23231dd1d6dfc41bae85 100644 (file)
 
 #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_ */
index 4bc7f2f6488b334be9f229440f06679317eb8700..bb304eea928e9b7f379b39d732c6be64978d0fdf 100644 (file)
@@ -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) {
 
index 5955ddbf11a13792b62f84379e769d476fd06cda..6f3506248dd1d8a84753f8cc9e35a1dd5ea5b66d 100644 (file)
 
 #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_ */
index 50a3907eb6067d327193f0947b73be880e651bfe..5632155e953e3565fc9f7de2db8f5b41b00bd97a 100644 (file)
@@ -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 <clocale>
 
+#include <TCollection_AsciiString.hxx>
+#include <OSD_Path.hxx>
+
 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();
+}
index 2f1e0eb9291432c8f08c2578f45a667fe122d230..3524e188e933547ac7db8acb7e060287c1a23702 100644 (file)
@@ -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_ */