Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / ExchangePlugin / ExchangePlugin_Dump.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    ExchangePlugin_ExportFeature.cpp
4 // Created: May 14, 2015
5 // Author:  Sergey POKHODENKO
6
7 #include <ExchangePlugin_Dump.h>
8
9 #include <ModelAPI_AttributeString.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Session.h>
12
13 #include <ModelHighAPI_Dumper.h>
14
15 #include <Config_ModuleReader.h>
16
17
18 ExchangePlugin_Dump::ExchangePlugin_Dump()
19 {
20 }
21
22 ExchangePlugin_Dump::~ExchangePlugin_Dump()
23 {
24 }
25
26 void ExchangePlugin_Dump::initAttributes()
27 {
28   data()->addAttribute(ExchangePlugin_Dump::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
29   data()->addAttribute(ExchangePlugin_Dump::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
30 }
31
32 void ExchangePlugin_Dump::execute()
33 {
34   AttributeStringPtr aFilePathAttr =
35       this->string(ExchangePlugin_Dump::FILE_PATH_ID());
36   std::string aFilePath = aFilePathAttr->value();
37   if (aFilePath.empty())
38     return;
39
40   dump(aFilePath);
41 }
42
43 void ExchangePlugin_Dump::dump(const std::string& theFileName)
44 {
45   // load DumpAssistant from Python side
46   Config_ModuleReader::loadScript("model.dump");
47
48   ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
49   aDumper->clear();
50   DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
51   if (!aDumper || !aDumper->process(aDoc, theFileName))
52     setError("An error occured while dumping to " + theFileName);
53 }