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());
51 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->setValue(true);
52 boolean(GEOMETRIC_DUMP_ID())->setValue(true);
53 boolean(WEAK_NAMING_DUMP_ID())->setValue(false);
56 void ExchangePlugin_Dump::execute()
58 AttributeStringPtr aFilePathAttr =
59 this->string(ExchangePlugin_Dump::FILE_PATH_ID());
60 std::string aFilePath = aFilePathAttr->value();
61 if (aFilePath.empty())
67 void ExchangePlugin_Dump::dump(const std::string& theFileName)
69 // load DumpAssistant from Python side
70 Config_ModuleReader::loadScript("salome.shaper.model.dump");
72 DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
74 int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
76 FeaturePtr aLastFeature =
77 ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
78 if(aDoc->currentFeature(true) != aLastFeature) {
79 setError("Dump cannot be done. Please move the history line to the end before dumping.");
84 DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
85 aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
87 FeaturePtr aLastFeature =
88 ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
89 if(anActiveDoc->currentFeature(true) != aLastFeature) {
90 setError("Dump cannot be done. Please move the history line to the end before dumping.");
95 std::list<FeaturePtr> aFeatures = aDoc->allFeatures();
96 for(std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
97 aFeatIt != aFeatures.end();
99 ResultPartPtr aResultPart =
100 std::dynamic_pointer_cast<ModelAPI_ResultPart>((*aFeatIt)->firstResult());
101 if(aResultPart.get()) {
102 if(!aResultPart->isActivated()) {
103 setError("Error: Not all parts are loaded. Can not dump.");
109 // process selected types of the dump
110 ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
112 setError("An error occured while dumping to " + theFileName);
114 static const int THE_TYPES_SIZE = 3;
115 bool aTypes[THE_TYPES_SIZE] = {
116 boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value(),
117 boolean(GEOMETRIC_DUMP_ID())->value(),
118 boolean(WEAK_NAMING_DUMP_ID())->value()
120 int aNbSelectedTypes = 0;
121 for (int i = 0; i < THE_TYPES_SIZE; ++i)
125 if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) {
126 ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage);
127 aDumper->addCustomStorage(aTopoNameStorage);
129 if (boolean(GEOMETRIC_DUMP_ID())->value()) {
130 ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage(
131 new ModelHighAPI_Dumper::DumpStorageGeom);
132 if (aNbSelectedTypes > 1)
133 aGeomSelectionStorage->setFilenameSuffix("_geo");
134 aDumper->addCustomStorage(aGeomSelectionStorage);
136 if (boolean(WEAK_NAMING_DUMP_ID())->value()) {
137 ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage(
138 new ModelHighAPI_Dumper::DumpStorageWeak);
139 if (aNbSelectedTypes > 1)
140 aWeakNamingStorage->setFilenameSuffix("_weak");
141 aDumper->addCustomStorage(aWeakNamingStorage);
144 if (!aDumper->process(aDoc, theFileName))
145 setError("An error occured while dumping to " + theFileName);