1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ExchangePlugin_ExportFeature.cpp
4 // Created: May 14, 2015
5 // Author: Sergey POKHODENKO
7 #include <ExchangePlugin_Dump.h>
9 #include <ModelAPI_AttributeString.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_ResultPart.h>
14 #include <ModelHighAPI_Dumper.h>
16 #include <Config_ModuleReader.h>
19 ExchangePlugin_Dump::ExchangePlugin_Dump()
23 ExchangePlugin_Dump::~ExchangePlugin_Dump()
27 void ExchangePlugin_Dump::initAttributes()
29 data()->addAttribute(ExchangePlugin_Dump::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
30 data()->addAttribute(ExchangePlugin_Dump::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
33 void ExchangePlugin_Dump::execute()
35 AttributeStringPtr aFilePathAttr =
36 this->string(ExchangePlugin_Dump::FILE_PATH_ID());
37 std::string aFilePath = aFilePathAttr->value();
38 if (aFilePath.empty())
44 void ExchangePlugin_Dump::dump(const std::string& theFileName)
46 // load DumpAssistant from Python side
47 Config_ModuleReader::loadScript("salome.shaper.model.dump");
49 ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
51 DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
53 int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
55 FeaturePtr aLastFeature =
56 ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
57 if(aDoc->currentFeature(true) != aLastFeature) {
58 setError("Dump cannot be done. Please move the history line to the end before dumping.");
63 DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
64 aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
66 FeaturePtr aLastFeature =
67 ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
68 if(anActiveDoc->currentFeature(true) != aLastFeature) {
69 setError("Dump cannot be done. Please move the history line to the end before dumping.");
74 std::list<FeaturePtr> aFeatures = aDoc->allFeatures();
75 for(std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
76 aFeatIt != aFeatures.end();
78 ResultPartPtr aResultPart =
79 std::dynamic_pointer_cast<ModelAPI_ResultPart>((*aFeatIt)->firstResult());
80 if(aResultPart.get()) {
81 if(!aResultPart->isActivated()) {
82 setError("Error: Not all parts are loaded. Can not dump.");
88 if (!aDumper || !aDumper->process(aDoc, theFileName))
89 setError("An error occured while dumping to " + theFileName);