]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_XAOImport.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[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 <TopoDS_Shape.hxx>
10
11 #include <XAO_XaoExporter.hxx>
12 #include <XAO_BrepGeometry.hxx>
13
14 //=============================================================================
15 /*!
16  *
17  */
18 //=============================================================================
19 std::shared_ptr<GeomAPI_Shape> XAOImport(const std::string& theFileName,
20                                          std::string& theError,
21                                          XAO::Xao* theXao)
22 {
23   #ifdef _DEBUG
24   std::cout << "Import XAO from file " << theFileName << std::endl;
25   #endif
26   if (theFileName.empty() || !theXao) {
27     theError = "An invalid argument.";
28     return std::shared_ptr<GeomAPI_Shape>();
29   }
30
31   TopoDS_Shape aShape;
32   try {
33     if (XAO::XaoExporter::readFromFile(theFileName, theXao)) {
34       XAO::Geometry* aGeometry = theXao->getGeometry();
35       XAO::Format aFormat = aGeometry->getFormat();
36       if (aFormat == XAO::BREP) {
37         if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
38           aShape = aBrepGeometry->getTopoDS_Shape();
39       } else {
40         theError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
41         aShape.Nullify();
42       }
43     } else {
44       theError = "XAO object was not read successful";
45       aShape.Nullify();
46     }
47   } catch (XAO::XAO_Exception& e) {
48     theError = e.what();
49     aShape.Nullify();
50   }
51
52   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
53   aGeomShape->setImpl(new TopoDS_Shape(aShape));
54   return aGeomShape;
55 }