From e38c476552a606fe5c3fa5d5e743335f41ff576a Mon Sep 17 00:00:00 2001 From: Alexey Kondratyev Date: Wed, 19 Jan 2022 09:42:20 +0300 Subject: [PATCH] [bos #26446] Add fix to prevent endless cycle of calling function after redisplay. --- src/ModuleBase/ModuleBase_Tools.cpp | 44 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 15b389749..851ae64a4 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -1402,8 +1402,28 @@ qreal currentPixelRatio() // Set displaying status to every element on group static void setDisplayingByLoop(DocumentPtr theDoc, int theSize, - std::string theGroup, bool theDisplayFromScript) + std::string theGroup, bool theDisplayFromScript, int theDisplayingId) { + for (int anIndex = theSize - 1; anIndex >= 0; --anIndex) { + ObjectPtr anObject = theDoc->object(theGroup, anIndex); + anObject->setDisplayed((theDisplayingId == 1 && anIndex == theSize - 1) || theDisplayingId == 2); + } +} + +void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript) +{ + static bool isDoingDisplay = false; + + if (isDoingDisplay) + return; + + isDoingDisplay = true; + DocumentPtr aDoc = thePart->partDoc(); + int aConstructionSize = aDoc->size(ModelAPI_ResultConstruction::group()); + int aGroupSize = aDoc->size(ModelAPI_ResultGroup::group()); + int aFieldSize = aDoc->size(ModelAPI_ResultField::group()); + int aResultSize = aDoc->size(ModelAPI_ResultBody::group()); + int aDisplayingId = -1; if (theDisplayFromScript) { aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General", @@ -1420,24 +1440,12 @@ static void setDisplayingByLoop(DocumentPtr theDoc, int theSize, return; } - for (int anIndex = theSize - 1; anIndex >= 0; --anIndex) { - ObjectPtr anObject = theDoc->object(theGroup, anIndex); - anObject->setDisplayed((aDisplayingId == 1 && anIndex == theSize - 1) || aDisplayingId == 2); - } -} - -void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript) -{ - DocumentPtr aDoc = thePart->partDoc(); - int aConstructionSize = aDoc->size(ModelAPI_ResultConstruction::group()); - int aGroupSize = aDoc->size(ModelAPI_ResultGroup::group()); - int aFieldSize = aDoc->size(ModelAPI_ResultField::group()); - int aResultSize = aDoc->size(ModelAPI_ResultBody::group()); setDisplayingByLoop(aDoc, aConstructionSize, - ModelAPI_ResultConstruction::group(), theDisplayFromScript); - setDisplayingByLoop(aDoc, aGroupSize, ModelAPI_ResultGroup::group(), theDisplayFromScript); - setDisplayingByLoop(aDoc, aFieldSize, ModelAPI_ResultField::group(), theDisplayFromScript); - setDisplayingByLoop(aDoc, aResultSize, ModelAPI_ResultBody::group(), theDisplayFromScript); + ModelAPI_ResultConstruction::group(), theDisplayFromScript, aDisplayingId); + setDisplayingByLoop(aDoc, aGroupSize, ModelAPI_ResultGroup::group(), theDisplayFromScript, aDisplayingId); + setDisplayingByLoop(aDoc, aFieldSize, ModelAPI_ResultField::group(), theDisplayFromScript, aDisplayingId); + setDisplayingByLoop(aDoc, aResultSize, ModelAPI_ResultBody::group(), theDisplayFromScript, aDisplayingId); + isDoingDisplay = false; } } // namespace ModuleBase_Tools -- 2.39.2