1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <ExchangePlugin_Dump.h>
22 #include <ModelAPI_AttributeBoolean.h>
23 #include <ModelAPI_AttributeString.h>
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_ResultPart.h>
28 #include <ModelHighAPI_Dumper.h>
30 #include <Config_ModuleReader.h>
33 ExchangePlugin_Dump::ExchangePlugin_Dump()
37 ExchangePlugin_Dump::~ExchangePlugin_Dump()
41 void ExchangePlugin_Dump::initAttributes()
43 data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
44 data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
46 data()->addAttribute(TOPOLOGICAL_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
47 data()->addAttribute(GEOMETRIC_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
48 data()->addAttribute(WEAK_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
50 data()->addAttribute(EXPORT_VARIABLES_ID(), ModelAPI_AttributeBoolean::typeId());
53 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->setValue(true);
54 boolean(GEOMETRIC_DUMP_ID())->setValue(true);
55 boolean(WEAK_NAMING_DUMP_ID())->setValue(false);
56 boolean(EXPORT_VARIABLES_ID())->setValue(false);
59 void ExchangePlugin_Dump::execute()
61 AttributeStringPtr aFilePathAttr =
62 this->string(ExchangePlugin_Dump::FILE_PATH_ID());
63 std::string aFilePath = aFilePathAttr->value();
64 if (aFilePath.empty())
70 void ExchangePlugin_Dump::dump(const std::string& theFileName)
72 // load DumpAssistant from Python side
73 Config_ModuleReader::loadScript("salome.shaper.model.dump");
75 DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
77 int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
79 FeaturePtr aLastFeature =
80 ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
81 if(aDoc->currentFeature(true) != aLastFeature) {
82 setError("Dump cannot be done. Please move the history line to the end before dumping.");
87 DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
88 aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
90 FeaturePtr aLastFeature =
91 ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
92 if(anActiveDoc->currentFeature(true) != aLastFeature) {
93 setError("Dump cannot be done. Please move the history line to the end before dumping.");
98 std::list<FeaturePtr> aFeatures = aDoc->allFeatures();
99 for(std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
100 aFeatIt != aFeatures.end();
102 ResultPartPtr aResultPart =
103 std::dynamic_pointer_cast<ModelAPI_ResultPart>((*aFeatIt)->firstResult());
104 if(aResultPart.get()) {
105 if(!aResultPart->isActivated()) {
106 setError("Error: Not all parts are loaded. Can not dump.");
112 // process selected types of the dump
113 ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
115 setError("An error occured while dumping to " + theFileName);
117 static const int THE_TYPES_SIZE = 3;
118 bool aTypes[THE_TYPES_SIZE] = {
119 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value(),
120 boolean(GEOMETRIC_DUMP_ID())->value(),
121 boolean(WEAK_NAMING_DUMP_ID())->value()
123 int aNbSelectedTypes = 0;
124 for (int i = 0; i < THE_TYPES_SIZE; ++i)
128 if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) {
129 ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage);
130 aDumper->addCustomStorage(aTopoNameStorage);
132 if (boolean(GEOMETRIC_DUMP_ID())->value()) {
133 ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage(
134 new ModelHighAPI_Dumper::DumpStorageGeom);
135 if (aNbSelectedTypes > 1)
136 aGeomSelectionStorage->setFilenameSuffix("_geo");
137 aDumper->addCustomStorage(aGeomSelectionStorage);
139 if (boolean(WEAK_NAMING_DUMP_ID())->value()) {
140 ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage(
141 new ModelHighAPI_Dumper::DumpStorageWeak);
142 if (aNbSelectedTypes > 1)
143 aWeakNamingStorage->setFilenameSuffix("_weak");
144 aDumper->addCustomStorage(aWeakNamingStorage);
147 if (!aDumper->process(aDoc, theFileName)) {
148 setError("An error occurred while dumping to " + theFileName);
150 if (boolean(EXPORT_VARIABLES_ID())->value()) {
151 aDumper->exportVariables();
154 // clear cashed data after export variables was performed
155 aDumper->clearCustomStorage();