Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_XAOExport.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <GeomAlgoAPI_XAOExport.h>
22
23 #include "GeomAlgoAPI_Tools.h"
24
25 #include <TopoDS_Shape.hxx>
26
27 #include <XAO_XaoExporter.hxx>
28 #include <XAO_BrepGeometry.hxx>
29
30 //=============================================================================
31 bool SetShapeToXAO(const std::shared_ptr<GeomAPI_Shape>& theShape,
32                    XAO::Xao* theXao,
33                    std::string& theError)
34 {
35   if (!theShape.get() || !theXao) {
36     theError = "An invalid argument.";
37     return false;
38   }
39
40   TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
41   try {
42     XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
43     theXao->setGeometry(aGeometry);
44     aGeometry->setTopoDS_Shape(aShape);
45   } catch (XAO::XAO_Exception& e) {
46     theError = e.what();
47     return false;
48   }
49   return true;
50 }
51
52 //=============================================================================
53 /*!
54  *
55  */
56 //=============================================================================
57 bool XAOExport(const std::string& theFileName,
58                XAO::Xao* theXao,
59                std::string& theError)
60 {
61   #ifdef _DEBUG
62   std::cout << "Export XAO into file " << theFileName << std::endl;
63   #endif
64
65   if (theFileName.empty() || !theXao) {
66     theError = "An invalid argument.";
67     return false;
68   }
69
70   try {
71     XAO::XaoExporter::saveToFile(theXao, theFileName);
72   } catch (XAO::XAO_Exception& e) {
73     theError = e.what();
74     return false;
75   }
76   return true;
77 }