Salome HOME
Implement ExportToGEOM via exportToXAO. Fix the issue #2198.
[modules/shaper.git] / src / ExchangeAPI / ExchangeAPI_Export.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 "ExchangeAPI_Export.h"
22 //--------------------------------------------------------------------------------------
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_Feature.h>
25 #include <ModelHighAPI_Tools.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Services.h>
28 //--------------------------------------------------------------------------------------
29
30 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
32 {
33   initialize();
34 }
35
36 /// Constructor with values for XAO export.
37 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
38                               const std::string & theFilePath,
39                               const std::string & theAuthor,
40                               const std::string & theGeometryName)
41 : ModelHighAPI_Interface(theFeature)
42 {
43   initialize();
44   fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID()));
45   fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID()));
46   fillAttribute(theAuthor, theFeature->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID()));
47   fillAttribute(theGeometryName,
48                 theFeature->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID()));
49   fillAttribute("XAO", theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID()));
50   execute();
51   apply(); // finish operation to make sure the export is done on the current state of the history
52 }
53
54 /// Constructor with values for export in other formats than XAO.
55 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature,
56                               const std::string & theFilePath,
57                               const std::list<ModelHighAPI_Selection> & theSelectionList,
58                               const std::string & theFileFormat)
59 : ModelHighAPI_Interface(theFeature)
60 {
61   initialize();
62   fillAttribute("Regular", theFeature->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID()));
63   fillAttribute(theFilePath, theFeature->string(ExchangePlugin_ExportFeature::FILE_PATH_ID()));
64   fillAttribute(theSelectionList,
65                 theFeature->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()));
66   fillAttribute(theFileFormat, theFeature->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID()));
67   execute();
68   apply(); // finish operation to make sure the export is done on the current state of the history
69 }
70
71 ExchangeAPI_Export::~ExchangeAPI_Export()
72 {
73 }
74
75
76 void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const
77 {
78
79   FeaturePtr aBase = feature();
80   const std::string& aDocName = theDumper.name(aBase->document());
81
82   theDumper << aBase << " = model.";
83
84   std::string exportType = aBase->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())->value();
85
86   if (exportType == "XAO") {
87     std::string tmpXAOFile = aBase->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value();
88     theDumper << "exportToXAO(" << aDocName << ", '" << tmpXAOFile << "'" ;
89     std::string theAuthor = aBase->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
90     if (not theAuthor.empty())
91       theDumper << ", '" << theAuthor << "'";
92     std::string theGeometryName = aBase->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
93     if (not theGeometryName.empty())
94       theDumper << ", '" << theGeometryName << "'";
95     theDumper << ")" << std::endl;
96   }
97   else {
98       theDumper << "exportToFile(" << aDocName << ", " <<
99           aBase->string(ExchangePlugin_ExportFeature::FILE_PATH_ID()) << ", " <<
100           aBase->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()) ;
101       std::string theFileFormat = aBase->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())->value();
102       if (not theFileFormat.empty())
103         theDumper << ", '" << theFileFormat << "'";
104       theDumper << ")" << std::endl;
105   }
106 }
107
108 ExportPtr exportToFile(const std::shared_ptr<ModelAPI_Document> & thePart,
109                   const std::string & theFilePath,
110                   const std::list<ModelHighAPI_Selection> & theSelectionList,
111                   const std::string & theFileFormat)
112 {
113   apply(); // finish previous operation to make sure all previous operations are done
114   std::shared_ptr<ModelAPI_Feature> aFeature =
115     thePart->addFeature(ExchangePlugin_ExportFeature::ID());
116   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectionList, theFileFormat));
117 }
118
119 ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
120                  const std::string & theFilePath,
121                  const std::string & theAuthor,
122                  const std::string & theGeometryName)
123 {
124   apply(); // finish previous operation to make sure all previous operations are done
125   std::shared_ptr<ModelAPI_Feature> aFeature =
126     thePart->addFeature(ExchangePlugin_ExportFeature::ID());
127   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
128 }
129
130 //--------------------------------------------------------------------------------------