Salome HOME
Improve XAO import: group_list
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_XAOImport.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    GEOMALGOAPI_XAOImport.cpp
4 // Created: Nov 25, 2015
5 // Author:  Sergey POKHODENKO
6
7 #include <GeomAlgoAPI_XAOImport.h>
8
9 #include <cassert>
10
11 #include <TopoDS_Shape.hxx>
12
13 #include <XAO_XaoExporter.hxx>
14 #include <XAO_BrepGeometry.hxx>
15
16 //=============================================================================
17 /*!
18  *
19  */
20 //=============================================================================
21 std::shared_ptr<GeomAPI_Shape> XAOImport(const std::string& theFileName,
22                                          std::string& theError,
23                                          XAO::Xao* theXao)
24 {
25   assert(theXao);
26
27   #ifdef _DEBUG
28   std::cout << "Import XAO from file " << theFileName << std::endl;
29   #endif
30   TopoDS_Shape aShape;
31   try {
32     if (XAO::XaoExporter::readFromFile(theFileName, theXao)) {
33       XAO::Geometry* aGeometry = theXao->getGeometry();
34       XAO::Format aFormat = aGeometry->getFormat();
35       if (aFormat == XAO::BREP) {
36         if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
37           aShape = aBrepGeometry->getTopoDS_Shape();
38       } else {
39         theError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
40         aShape.Nullify();
41       }
42     } else {
43       theError = "XAO object was not read successful";
44       aShape.Nullify();
45     }
46   } catch (XAO::XAO_Exception& e) {
47     theError = e.what();
48     aShape.Nullify();
49   }
50
51   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
52   aGeomShape->setImpl(new TopoDS_Shape(aShape));
53   return aGeomShape;
54 }