Salome HOME
Issue #904 - Fatal error aftre delete sketch from dataset used in extrusion in part
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STEPImport.cpp
index 8ed138604b6ebfea7cf7d14f52b1fbe35e2feb3c..6c251b4299173ca40b57d8ae618712bbb87e9cf6 100644 (file)
@@ -1,5 +1,9 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
+// File:    GEOMALGOAPI_STEPImport.cpp
+// Created: Dec 24, 2014
+// Author:  Sergey BELASH
+
 #include <GeomAlgoAPI_STEPImport.h>
 
 #include <TDF_ChildIDIterator.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+
 
 #include <TColStd_SequenceOfAsciiString.hxx>
 
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
-namespace STEPImport {
 //=============================================================================
 /*!
  *  GetShape()
@@ -364,10 +369,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,
-                     const TDF_Label&               theShapeLabel)
+std::shared_ptr<GeomAPI_Shape> STEPImport(const std::string& theFileName,
+                                          const std::string& theFormatName,
+                                          std::string& theError)
 {
   TopoDS_Shape aResShape;
 
@@ -388,7 +392,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) {
 
@@ -411,7 +415,9 @@ TopoDS_Shape Import (const TCollection_AsciiString& 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 == "")
@@ -480,7 +486,9 @@ TopoDS_Shape Import (const TCollection_AsciiString& 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.";
@@ -493,7 +501,7 @@ TopoDS_Shape Import (const TCollection_AsciiString& 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;
 }
-
-} // namespace STEPImport