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>
32 #ifdef EXCHANGEPLUGIN_DUMP_NAMING
33 static const bool THE_DUMP_NAMING = true;
35 static const bool THE_DUMP_NAMING = false;
38 #ifdef EXCHANGEPLUGIN_DUMP_GEO
39 static const bool THE_DUMP_GEO = true;
41 static const bool THE_DUMP_GEO = false;
44 #ifdef EXCHANGEPLUGIN_DUMP_WEAK
45 static const bool THE_DUMP_WEAK = true;
47 static const bool THE_DUMP_WEAK = false;
51 ExchangePlugin_Dump::ExchangePlugin_Dump()
55 ExchangePlugin_Dump::~ExchangePlugin_Dump()
59 void ExchangePlugin_Dump::initAttributes()
61 data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
62 data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
64 data()->addAttribute(TOPOLOGICAL_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
65 data()->addAttribute(GEOMETRIC_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
66 data()->addAttribute(WEAK_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
69 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->setValue(THE_DUMP_NAMING);
70 boolean(GEOMETRIC_DUMP_ID())->setValue(THE_DUMP_GEO);
71 boolean(WEAK_NAMING_DUMP_ID())->setValue(THE_DUMP_WEAK);
74 void ExchangePlugin_Dump::execute()
76 AttributeStringPtr aFilePathAttr =
77 this->string(ExchangePlugin_Dump::FILE_PATH_ID());
78 std::string aFilePath = aFilePathAttr->value();
79 if (aFilePath.empty())
85 void ExchangePlugin_Dump::dump(const std::string& theFileName)
87 // load DumpAssistant from Python side
88 Config_ModuleReader::loadScript("salome.shaper.model.dump");
90 DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
92 int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
94 FeaturePtr aLastFeature =
95 ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
96 if(aDoc->currentFeature(true) != aLastFeature) {
97 setError("Dump cannot be done. Please move the history line to the end before dumping.");
102 DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
103 aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
104 if(aFeaturesNb > 1) {
105 FeaturePtr aLastFeature =
106 ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
107 if(anActiveDoc->currentFeature(true) != aLastFeature) {
108 setError("Dump cannot be done. Please move the history line to the end before dumping.");
113 std::list<FeaturePtr> aFeatures = aDoc->allFeatures();
114 for(std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
115 aFeatIt != aFeatures.end();
117 ResultPartPtr aResultPart =
118 std::dynamic_pointer_cast<ModelAPI_ResultPart>((*aFeatIt)->firstResult());
119 if(aResultPart.get()) {
120 if(!aResultPart->isActivated()) {
121 setError("Error: Not all parts are loaded. Can not dump.");
127 // process selected types of the dump
128 ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
130 setError("An error occured while dumping to " + theFileName);
132 static const int THE_TYPES_SIZE = 3;
133 bool aTypes[THE_TYPES_SIZE] = {
134 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value(),
135 boolean(GEOMETRIC_DUMP_ID())->value(),
136 boolean(WEAK_NAMING_DUMP_ID())->value()
138 int aNbSelectedTypes = 0;
139 for (int i = 0; i < THE_TYPES_SIZE; ++i)
143 if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) {
144 ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage);
145 aDumper->addCustomStorage(aTopoNameStorage);
147 if (boolean(GEOMETRIC_DUMP_ID())->value()) {
148 ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage(
149 new ModelHighAPI_Dumper::DumpStorageGeom);
150 if (aNbSelectedTypes > 1)
151 aGeomSelectionStorage->setFilenameSuffix("_geo");
152 aDumper->addCustomStorage(aGeomSelectionStorage);
154 if (boolean(WEAK_NAMING_DUMP_ID())->value()) {
155 ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage(
156 new ModelHighAPI_Dumper::DumpStorageWeak);
157 if (aNbSelectedTypes > 1)
158 aWeakNamingStorage->setFilenameSuffix("_weak");
159 aDumper->addCustomStorage(aWeakNamingStorage);
162 if (!aDumper->process(aDoc, theFileName))
163 setError("An error occured while dumping to " + theFileName);