Salome HOME
Issue #608: Usage of OCCT in interface -- Remove OCCT from *Export/Import interfaces...
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 30 Jun 2015 08:48:49 +0000 (11:48 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 30 Jun 2015 08:49:15 +0000 (11:49 +0300)
14 files changed:
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BREPExport.h
src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_BREPImport.h
src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_IGESExport.h
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_IGESImport.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPExport.h
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImport.h

index f4e87b76ef0c6378491cc4d1b31e9a68162190c2..882a14a00092a431b9e0fa0967d548048bfa63de 100644 (file)
@@ -116,15 +116,13 @@ bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
 
   // Perform the export
   std::string anError;
-
-  TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
   bool aResult = false;
   if (aFormatName == "BREP") {
-    aResult = BREPExport(theFileName, aFormatName, aShape, anError);
+    aResult = BREPExport(theFileName, aFormatName, theShape, anError);
   } else if (aFormatName == "STEP") {
-    aResult = STEPExport(theFileName, aFormatName, aShape, anError);
+    aResult = STEPExport(theFileName, aFormatName, theShape, anError);
   } else if (aFormatName.substr(0, 4) == "IGES") {
-    aResult = IGESExport(theFileName, aFormatName, aShape, anError);
+    aResult = IGESExport(theFileName, aFormatName, theShape, anError);
   } else {
     anError = "Unsupported format " + aFormatName;
   }
index adc678657a778b0a92b77a9510d30607aab369f1..bcf06561e071f8887904c11d188fb1356df31700 100644 (file)
@@ -79,16 +79,16 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   // Perform the import
   std::string anError;
 
-  TopoDS_Shape aShape;
+  std::shared_ptr<GeomAPI_Shape> aGeomShape;
   if (anExtension == "BREP" || anExtension == "BRP") {
-    aShape = BREPImport(theFileName, anExtension, anError);
+    aGeomShape = BREPImport(theFileName, anExtension, anError);
   } else if (anExtension == "STEP" || anExtension == "STP") {
-    aShape = STEPImport(theFileName, anExtension, anError);
+    aGeomShape = STEPImport(theFileName, anExtension, anError);
   } else if (anExtension == "IGES" || anExtension == "IGS") {
-    aShape = IGESImport(theFileName, anExtension, anError);
+    aGeomShape = IGESImport(theFileName, anExtension, anError);
   }
    // Check if shape is valid
-  if ( aShape.IsNull() ) {
+  if ( aGeomShape->isNull() ) {
     const static std::string aShapeError =
       "An error occurred while importing " + theFileName + ": " + anError;
     setError(aShapeError);
@@ -99,8 +99,6 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   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);
-  aGeomShape->setImpl(new TopoDS_Shape(aShape));
 
   //LoadNamingDS of the imported shape
   loadNamingDS(aGeomShape, aResultBody);
index d85ae6b4f74de282aad96e9a93839936f1872a80..a9c4fffd2ca63d6727c7213e83297202760e6ff4 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "GeomAlgoAPI_Tools.h"
 
+#include <TopoDS_Shape.hxx>
+
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
 //=============================================================================
 bool BREPExport(const std::string& theFileName,
                 const std::string&,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError)
 {
   #ifdef _DEBUG
   std::cout << "Export BREP into file " << theFileName << std::endl;
   #endif
 
+  if (!theShape.get()) {
+    theError = "BREP Export failed: An invalid argument";
+    return false;
+  }
+
   // Set "C" numeric locale to save numbers correctly
   GeomAlgoAPI_Tools::Localizer loc;
 
-  if (!BRepTools::Write(theShape, theFileName.c_str())) {
+  if (!BRepTools::Write(theShape->impl<TopoDS_Shape>(), theFileName.c_str())) {
     theError = "BREP Export failed";
     return false;
   }
index de545479e6ba8af584f728a8c8d74ccd2d57b64b..79f3d99b68ea0edb0193c3e413b083cc17e45587 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the export BREP files algorithms
 GEOMALGOAPI_EXPORT
 bool BREPExport(const std::string& theFileName,
                 const std::string& theFormatName,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError);
 
 #endif /* GEOMALGOAPI_BREPEXPORT_H_ */
index 4dc8769bd91214c85a73fd1dbb09f6cc744c791d..e067acc9e94b3d09067a197063934ac7bebac752 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <GeomAlgoAPI_BREPImport.h>
 
+#include <TopoDS_Shape.hxx>
+
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 
@@ -14,9 +16,9 @@
  *
  */
 //=============================================================================
-TopoDS_Shape BREPImport(const std::string& theFileName,
-                        const std::string&,
-                        std::string& theError)
+std::shared_ptr<GeomAPI_Shape> BREPImport(const std::string& theFileName,
+                                          const std::string&,
+                                          std::string& theError)
 {
   #ifdef _DEBUG
   std::cout << "Import BREP from file " << theFileName << std::endl;
@@ -27,5 +29,8 @@ TopoDS_Shape BREPImport(const std::string& theFileName,
   if (aShape.IsNull()) {
     theError = "BREP Import failed";
   }
-  return aShape;
+
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+  aGeomShape->setImpl(new TopoDS_Shape(aShape));
+  return aGeomShape;
 }
index 18ac9ffd750565623095494544fcee0e12aae529..a8a5c582f9b591f6474d53340758141399c57fa6 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the import BREP files algorithms
 GEOMALGOAPI_EXPORT
-TopoDS_Shape BREPImport(const std::string& theFileName,
-                        const std::string& theFormatName,
-                        std::string& theError);
+std::shared_ptr<GeomAPI_Shape> BREPImport(const std::string& theFileName,
+                                          const std::string& theFormatName,
+                                          std::string& theError);
 
 #endif /* GEOMALGOAPI_BREPIMPORT_H_ */
index 0479b0a4fda61bea081300fa556df98eed714ebb..b91780545377145b6981fc355948d0aa128f4aab 100644 (file)
@@ -80,9 +80,18 @@ int KindOfBRep (const TopoDS_Shape& theShape)
 //=============================================================================
 bool IGESExport(const std::string& theFileName,
                 const std::string& theFormatName,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError)
 {
+  #ifdef _DEBUG
+  std::cout << "Export IGES into file " << theFileName << std::endl;
+  #endif
+
+  if (!theShape.get()) {
+    theError = "IGES Export failed: An invalid argument";
+    return false;
+  }
+
   // theFormatName expected "IGES-5.1", "IGES-5.3"...
   TCollection_AsciiString aFormatName(theFormatName.c_str());
   TCollection_AsciiString aVersion = aFormatName.Token("-", 2);
@@ -97,14 +106,10 @@ bool IGESExport(const std::string& theFileName,
   if( aVersion.IsEqual( "5.3" ) )
     aBrepMode = 1;
 
-  #ifdef _DEBUG
-  std::cout << "Export IGES into file " << theFileName << std::endl;
-  #endif
-
   // Mantis issue 0021350: check being exported shape, as some stand-alone
   // entities (edges, wires and vertices) cannot be saved in BRepMode
   if( aBrepMode == 1 ) {
-    int aKind = KindOfBRep( theShape );
+    int aKind = KindOfBRep( theShape->impl<TopoDS_Shape>() );
     if( aKind == -1 ) {
       theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
       return false;
@@ -127,7 +132,7 @@ bool IGESExport(const std::string& theFileName,
   Interface_Static::SetCVal( "write.precision.mode", "Max" );
 
   // perform shape writing
-  if( ICW.AddShape( theShape ) ) {
+  if( ICW.AddShape( theShape->impl<TopoDS_Shape>() ) ) {
     ICW.ComputeModel();
     return ICW.Write(theFileName.c_str());
   }
index f701723428a3c28606b29460711c8ad4cce340fb..62781d9ea4ee346b8f64c9fc40f9cca6bcd17c4f 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the export IGES files algorithms
 GEOMALGOAPI_EXPORT
 bool IGESExport(const std::string& theFileName,
                 const std::string& theFormatName,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError);
 
 #endif /* GEOMALGOAPI_IGESEXPORT_H_ */
index 910be52e81a8a110b53c959a45c572faf8e21087..79830e43f221a0ec7b79b3de7f4699ba767ad515 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <GeomAlgoAPI_IGESImport.h>
 
+#include <TopoDS_Shape.hxx>
+
 // OOCT includes
 #include <IGESControl_Reader.hxx>
 #include <IGESData_IGESModel.hxx>
  *
  */
 //=============================================================================
-TopoDS_Shape IGESImport(const std::string& theFileName,
-                        const std::string&,
-                        std::string& theError)
+std::shared_ptr<GeomAPI_Shape> IGESImport(const std::string& theFileName,
+                                          const std::string&,
+                                          std::string& theError)
 {
   #ifdef _DEBUG
   std::cout << "Import IGES from file " << theFileName << std::endl;
   #endif
-  TopoDS_Shape aResShape;
+  TopoDS_Shape aShape;
   IGESControl_Reader aReader;
   try {
     IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.c_str() );
@@ -37,7 +39,7 @@ TopoDS_Shape IGESImport(const std::string& theFileName,
       #ifdef _DEBUG
       std::cout << "ImportIGES : count of shapes produced = " << aReader.NbShapes() << std::endl;
       #endif
-      aResShape = aReader.OneShape();
+      aShape = aReader.OneShape();
     }
     else {
       switch (status) {
@@ -57,14 +59,16 @@ TopoDS_Shape IGESImport(const std::string& theFileName,
           theError = "Wrong format of the imported file. Can't import file.";
           break;
       }
-      aResShape.Nullify();
+      aShape.Nullify();
     }
   }
   catch( Standard_Failure ) {
     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     theError = aFail->GetMessageString();
-    aResShape.Nullify();
+    aShape.Nullify();
   }
 
-  return aResShape;
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+  aGeomShape->setImpl(new TopoDS_Shape(aShape));
+  return aGeomShape;
 }
index b7a63865d8b94b8ba2885def2cc762e6f2a3db90..37ab90aa7d19069600f733000542ea3b9d74ac21 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the import IGES files algorithms
 GEOMALGOAPI_EXPORT
-TopoDS_Shape IGESImport(const std::string& theFileName,
-                        const std::string& theFormatName,
-                        std::string& theError);
+std::shared_ptr<GeomAPI_Shape> IGESImport(const std::string& theFileName,
+                                          const std::string& theFormatName,
+                                          std::string& theError);
 
 #endif /* GEOMALGOAPI_IGESIMPORT_H_ */
index fbf7f718b07c97704454c54c6998fd57674f5893..c9e9830c1829b293d7b67beac4db593e9b902fa8 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "GeomAlgoAPI_Tools.h"
 
+#include <TopoDS_Shape.hxx>
+
 // OOCT includes
 #include <IFSelect_ReturnStatus.hxx>
 #include <STEPControl_Writer.hxx>
 
 bool STEPExport(const std::string& theFileName,
                 const std::string& theFormatName,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError)
 {
   #ifdef _DEBUG
   std::cout << "Export STEP into file " << theFileName << std::endl;
   #endif
 
+  if (!theShape.get()) {
+    theError = "STEP Export failed: An invalid argument";
+    return false;
+  }
+
   try
   {
     // Set "C" numeric locale to save numbers correctly
@@ -33,10 +40,10 @@ bool STEPExport(const std::string& theFileName,
     Interface_Static::SetCVal("xstep.cascade.unit","M");
     Interface_Static::SetCVal("write.step.unit", "M");
     Interface_Static::SetIVal("write.step.nonmanifold", 1);
-    status = aWriter.Transfer( theShape, STEPControl_AsIs );
+    status = aWriter.Transfer(theShape->impl<TopoDS_Shape>(), STEPControl_AsIs);
     //VRV: OCC 4.0 migration
     if( status == IFSelect_RetDone )
-      status = aWriter.Write( theFileName.c_str() );
+      status = aWriter.Write(theFileName.c_str());
 
     // Return previous locale
     if( status == IFSelect_RetDone )
index 2011617af76b05b67995d6a047abf1fce0a339c2..5376a050b1c43092d50f99d4106bd9bc2509e1e1 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the export STEP files algorithms
 GEOMALGOAPI_EXPORT
 bool STEPExport(const std::string& theFileName,
                 const std::string& theFormatName,
-                const TopoDS_Shape& theShape,
+                const std::shared_ptr<GeomAPI_Shape>& theShape,
                 std::string& theError);
 
 #endif /* GEOMALGOAPI_STEPEXPORT_H_ */
index 432cd1d5939c9cace45f3aa45a27f8f39280a2cc..6c251b4299173ca40b57d8ae618712bbb87e9cf6 100644 (file)
@@ -41,6 +41,8 @@
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+
 
 #include <TColStd_SequenceOfAsciiString.hxx>
 
@@ -367,9 +369,9 @@ Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFil
   return aValue;
 }
 
-TopoDS_Shape STEPImport(const std::string& theFileName,
-                        const std::string& theFormatName,
-                        std::string& theError)
+std::shared_ptr<GeomAPI_Shape> STEPImport(const std::string& theFileName,
+                                          const std::string& theFormatName,
+                                          std::string& theError)
 {
   TopoDS_Shape aResShape;
 
@@ -413,7 +415,9 @@ TopoDS_Shape STEPImport(const std::string& theFileName,
             Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
           else {
             theError = "The file contains not supported units.";
-            return aResShape;
+            std::shared_ptr<GeomAPI_Shape> 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 == "")
@@ -482,7 +486,9 @@ TopoDS_Shape STEPImport(const std::string& theFileName,
       if ( !TopExp_Explorer( aResShape, TopAbs_VERTEX ).More() )
       {
         theError = "No geometrical data in the imported file.";
-        return TopoDS_Shape();
+        std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+        aGeomShape->setImpl(new TopoDS_Shape());
+        return aGeomShape;
       }
     } else {
       theError = "Wrong format of the imported file. Can't import file.";
@@ -495,5 +501,7 @@ TopoDS_Shape STEPImport(const std::string& theFileName,
     aResShape.Nullify();
   }
   // Return previous locale
-  return aResShape;
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+  aGeomShape->setImpl(new TopoDS_Shape(aResShape));
+  return aGeomShape;
 }
index 0a50607980e7864e544e5bd2063786af950f0e6d..b206962cbcabd70ea31ad4a1a1397ccccb5fd1e7 100644 (file)
 
 #include <string>
 
-#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
 
 /// Implementation of the import STEP files algorithms
 GEOMALGOAPI_EXPORT
-TopoDS_Shape STEPImport(const std::string& theFileName,
-                        const std::string& theFormatName,
-                        std::string& theError);
+std::shared_ptr<GeomAPI_Shape> STEPImport(const std::string& theFileName,
+                                          const std::string& theFormatName,
+                                          std::string& theError);
 
 #endif /* GEOMALGOAPI_STEPIMPORT_H_ */