1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
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 //--------------------------------------------------------------------------------------
30 ExchangeAPI_Export::ExchangeAPI_Export(const std::shared_ptr<ModelAPI_Feature>& theFeature)
31 : ModelHighAPI_Interface(theFeature)
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)
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()));
51 apply(); // finish operation to make sure the export is done on the current state of the history
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)
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()));
68 apply(); // finish operation to make sure the export is done on the current state of the history
71 ExchangeAPI_Export::~ExchangeAPI_Export()
76 void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const
79 FeaturePtr aBase = feature();
80 const std::string& aDocName = theDumper.name(aBase->document());
82 theDumper << aBase << " = model.";
84 std::string exportType = aBase->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())->value();
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;
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;
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)
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));
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)
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));
133 //--------------------------------------------------------------------------------------