]> SALOME platform Git repositories - modules/shaper.git/blob - src/ExchangeAPI/ExchangeAPI_Export.cpp
Salome HOME
Add command "Rename" to a folder context menu
[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 =
88                 aBase->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value();
89     theDumper << "exportToXAO(" << aDocName << ", '" << tmpXAOFile << "'" ;
90     std::string theAuthor = aBase->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
91     if (! theAuthor.empty())
92       theDumper << ", '" << theAuthor << "'";
93     std::string theGeometryName =
94                 aBase->string(ExchangePlugin_ExportFeature::XAO_GEOMETRY_NAME_ID())->value();
95     if (! theGeometryName.empty())
96       theDumper << ", '" << theGeometryName << "'";
97     theDumper << ")" << std::endl;
98   }
99   else {
100       theDumper << "exportToFile(" << aDocName << ", " <<
101           aBase->string(ExchangePlugin_ExportFeature::FILE_PATH_ID()) << ", " <<
102           aBase->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()) ;
103       std::string theFileFormat =
104                   aBase->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())->value();
105       if (! theFileFormat.empty())
106         theDumper << ", '" << theFileFormat << "'";
107       theDumper << ")" << std::endl;
108   }
109 }
110
111 ExportPtr exportToFile(const std::shared_ptr<ModelAPI_Document> & thePart,
112                   const std::string & theFilePath,
113                   const std::list<ModelHighAPI_Selection> & theSelectionList,
114                   const std::string & theFileFormat)
115 {
116   apply(); // finish previous operation to make sure all previous operations are done
117   std::shared_ptr<ModelAPI_Feature> aFeature =
118     thePart->addFeature(ExchangePlugin_ExportFeature::ID());
119   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theSelectionList, theFileFormat));
120 }
121
122 ExportPtr exportToXAO(const std::shared_ptr<ModelAPI_Document> & thePart,
123                  const std::string & theFilePath,
124                  const std::string & theAuthor,
125                  const std::string & theGeometryName)
126 {
127   apply(); // finish previous operation to make sure all previous operations are done
128   std::shared_ptr<ModelAPI_Feature> aFeature =
129     thePart->addFeature(ExchangePlugin_ExportFeature::ID());
130   return ExportPtr(new ExchangeAPI_Export(aFeature, theFilePath, theAuthor, theGeometryName));
131 }
132
133 //--------------------------------------------------------------------------------------