From a0237cd83a6f8dd9b8f415fc8efce9928d37661a Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Mon, 22 Jun 2020 13:38:11 +0300 Subject: [PATCH] Task #3223: Improve Python dump readability Fix the wrong script generation if a group contains filters. --- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 10 ++++++++++ src/ModelHighAPI/ModelHighAPI_Dumper.h | 4 ++++ src/PythonAPI/model/dump/DumpAssistant.py | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 5352af497..cf359fc65 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -1060,6 +1060,16 @@ bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) cons return fabs(anAttribute->value()) < 1.e-12; } +bool ModelHighAPI_Dumper::dumpCommentBeforeFeature(const FeaturePtr& theFeature) const +{ + // currently, the comment should not be dumped only before the filters + FiltersFeaturePtr aFilters = std::dynamic_pointer_cast(theFeature); + if (aFilters) + return false; + // all other features should be commented before the dump + return true; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar) { *myDumpStorage << theChar; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 8f480c0f1..aceab1465 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -356,6 +356,10 @@ public: MODELHIGHAPI_EXPORT virtual void exportVariable( const std::string& theEntry, const std::string& theVarName) const {} + /// Returns \c true if the special comment line to improve the readability + /// should be printed before the feature of the given kind. + MODELHIGHAPI_EXPORT bool dumpCommentBeforeFeature(const FeaturePtr& theFeature) const; + protected: /// Dump "setName" command if last entity had user-defined name MODELHIGHAPI_EXPORT void dumpEntitySetName(); diff --git a/src/PythonAPI/model/dump/DumpAssistant.py b/src/PythonAPI/model/dump/DumpAssistant.py index 08007616d..1f254a5a9 100644 --- a/src/PythonAPI/model/dump/DumpAssistant.py +++ b/src/PythonAPI/model/dump/DumpAssistant.py @@ -67,8 +67,9 @@ class DumpAssistant(ModelHighAPI.ModelHighAPI_Dumper): if theForce or theFeature.isInHistory() or aFeatureKind=="Export" or aFeatureKind=="RemoveResults": aDumper = self.myFeatures[aFeatureKind](theFeature) # Dump comment for the operation before the dumping of the feature to improve the readability of a script. - self.__print__("\n### Create " + theFeature.getKind()) - self.newline() + if self.dumpCommentBeforeFeature(theFeature): + self.__print__("\n### Create " + theFeature.getKind()) + self.newline() else: self.name(theFeature) self.clearNotDumped() -- 2.39.2