X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Dump.cpp;h=aaee3f0034519034e97a43b25cbd67f1f66feeda;hb=88ee9b2b81cf93a6324336b57e30cc8a3a487499;hp=dc74c54c4d184b11cf1bf8e797dfe5c6f4419890;hpb=9fc847fd03b8e9b615c6ecc7aa655aae9167cc68;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Dump.cpp b/src/ExchangePlugin/ExchangePlugin_Dump.cpp index dc74c54c4..aaee3f003 100644 --- a/src/ExchangePlugin/ExchangePlugin_Dump.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Dump.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -25,11 +24,32 @@ #include #include #include +#include #include #include +#include + +#ifdef EXCHANGEPLUGIN_DUMP_NAMING +static const bool THE_DUMP_NAMING = true; +#else +static const bool THE_DUMP_NAMING = false; +#endif + +#ifdef EXCHANGEPLUGIN_DUMP_GEO +static const bool THE_DUMP_GEO = true; +#else +static const bool THE_DUMP_GEO = false; +#endif + +#ifdef EXCHANGEPLUGIN_DUMP_WEAK +static const bool THE_DUMP_WEAK = true; +#else +static const bool THE_DUMP_WEAK = false; +#endif + ExchangePlugin_Dump::ExchangePlugin_Dump() { @@ -44,8 +64,21 @@ void ExchangePlugin_Dump::initAttributes() data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(TOPOLOGICAL_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId()); data()->addAttribute(GEOMETRIC_DUMP_ID(), ModelAPI_AttributeBoolean::typeId()); - boolean(GEOMETRIC_DUMP_ID())->setValue(false); + data()->addAttribute(WEAK_NAMING_DUMP_ID(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(EXPORT_VARIABLES_ID(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(DUMP_DIR_ID(), ModelAPI_AttributeString::typeId()); + + // default values + boolean(TOPOLOGICAL_NAMING_DUMP_ID())->setValue(THE_DUMP_NAMING); + boolean(GEOMETRIC_DUMP_ID())->setValue(THE_DUMP_GEO); + boolean(WEAK_NAMING_DUMP_ID())->setValue(THE_DUMP_WEAK); + boolean(EXPORT_VARIABLES_ID())->setValue(false); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DUMP_DIR_ID()); } void ExchangePlugin_Dump::execute() @@ -64,10 +97,6 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName) // load DumpAssistant from Python side Config_ModuleReader::loadScript("salome.shaper.model.dump"); - ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance(); - aDumper->clear(); - aDumper->setSelectionByGeometry(boolean(GEOMETRIC_DUMP_ID())->value()); - DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument(); int aFeaturesNb = aDoc->size(ModelAPI_Feature::group()); @@ -86,8 +115,8 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName) FeaturePtr aLastFeature = ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1)); if(anActiveDoc->currentFeature(true) != aLastFeature) { - setError("Dump cannot be done. Please move the history line to the end before dumping."); - return; + setError("Dump cannot be done. Please move the history line to the end before dumping."); + return; } } @@ -105,6 +134,59 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName) } } - if (!aDumper || !aDumper->process(aDoc, theFileName)) + // process selected types of the dump + ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance(); + if (!aDumper) setError("An error occured while dumping to " + theFileName); + + static const int THE_TYPES_SIZE = 3; + bool aTypes[THE_TYPES_SIZE] = { + boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value(), + boolean(GEOMETRIC_DUMP_ID())->value(), + boolean(WEAK_NAMING_DUMP_ID())->value() + }; + int aNbSelectedTypes = 0; + for (int i = 0; i < THE_TYPES_SIZE; ++i) + if (aTypes[i]) + ++aNbSelectedTypes; + + if (boolean(TOPOLOGICAL_NAMING_DUMP_ID())->value()) { + ModelHighAPI_Dumper::DumpStoragePtr aTopoNameStorage(new ModelHighAPI_Dumper::DumpStorage); + aDumper->addCustomStorage(aTopoNameStorage); + } + if (boolean(GEOMETRIC_DUMP_ID())->value()) { + ModelHighAPI_Dumper::DumpStoragePtr aGeomSelectionStorage( + new ModelHighAPI_Dumper::DumpStorageGeom); + if (aNbSelectedTypes > 1) + aGeomSelectionStorage->setFilenameSuffix("_geo"); + aDumper->addCustomStorage(aGeomSelectionStorage); + } + if (boolean(WEAK_NAMING_DUMP_ID())->value()) { + ModelHighAPI_Dumper::DumpStoragePtr aWeakNamingStorage( + new ModelHighAPI_Dumper::DumpStorageWeak); + if (aNbSelectedTypes > 1) + aWeakNamingStorage->setFilenameSuffix("_weak"); + aDumper->addCustomStorage(aWeakNamingStorage); + } + + // pass dump directory to the dumper + AttributeStringPtr aDumpDirAttr = + this->string(ExchangePlugin_Dump::DUMP_DIR_ID()); + std::string aDumpDir; + if (aDumpDirAttr.get() && aDumpDirAttr->isInitialized()) + aDumpDir = aDumpDirAttr->value(); + else + aDumpDir = GeomAlgoAPI_Tools::File_Tools::path(theFileName); + aDumper->setDumpDir(aDumpDir); + + if (!aDumper->process(aDoc, theFileName)) { + setError("An error occurred while dumping to " + theFileName); + } else { + if (boolean(EXPORT_VARIABLES_ID())->value()) { + aDumper->exportVariables(); + } + } + // clear cashed data after export variables was performed + aDumper->clearCustomStorage(); + }