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 bb304eea928e9b7f379b39d732c6be64978d0fdf..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,9 +369,9 @@ Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFil
   return aValue;
 }
 
-TopoDS_Shape Import (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;
 
@@ -410,7 +415,9 @@ TopoDS_Shape Import (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 == "")
@@ -479,7 +486,9 @@ TopoDS_Shape Import (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.";
@@ -492,7 +501,7 @@ TopoDS_Shape Import (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;
 }
-
-} // namespace STEPImport