Salome HOME
Make import XAO with groups
[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                                          const std::string&,
23                                          std::string& theError,
24                                          XAO::Xao* theXao)
25 {
26   assert(theXao);
27
28   #ifdef _DEBUG
29   std::cout << "Import XAO from file " << theFileName << std::endl;
30   #endif
31   TopoDS_Shape aShape;
32   try {
33 //    XAO::Xao aXao;
34     if (XAO::XaoExporter::readFromFile(theFileName, theXao/*&aXao*/)) {
35       XAO::Geometry* aGeometry = /*aXao*/theXao->getGeometry();
36       XAO::Format aFormat = aGeometry->getFormat();
37       if (aFormat == XAO::BREP) {
38         if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
39           aShape = aBrepGeometry->getTopoDS_Shape();
40       } else {
41         theError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
42         aShape.Nullify();
43       }
44     } else {
45       theError = "XAO object was not read successful";
46       aShape.Nullify();
47     }
48   } catch (XAO::XAO_Exception& e) {
49     theError = e.what();
50     aShape.Nullify();
51   }
52
53   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
54   aGeomShape->setImpl(new TopoDS_Shape(aShape));
55   return aGeomShape;
56 }