From: Alexey Kondratyev Date: Mon, 18 Oct 2021 08:12:43 +0000 (+0300) Subject: bos #26446 Customize study opening; bos #26447 Customize script execution X-Git-Tag: V9_9_0a1~18^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50c0ccb84aa5d196a71a8edac332cfcc21bb5462;p=modules%2Fshaper.git bos #26446 Customize study opening; bos #26447 Customize script execution * Add tab "General" in Preferences window. * Add algorithm to update displaying elements depending of settings. * Update opening file algorithm to activating parts depending of settings. * Update activating part algorithm to display elements depending of settings. * Update activating part algorithm to display elements depending of sub elements. * Update the documentation. --- diff --git a/doc/gui/General/Introduction.rst b/doc/gui/General/Introduction.rst index 35e17284c..3cb1c45b2 100644 --- a/doc/gui/General/Introduction.rst +++ b/doc/gui/General/Introduction.rst @@ -451,6 +451,7 @@ To call **Preferences** dialog box: SHAPER preferences contains the following tabs: +- :ref:`general_preferences`; - :ref:`visualization_preferences`; - :ref:`plugins_preferences`; - :ref:`shortcuts_preferences`; @@ -458,10 +459,43 @@ SHAPER preferences contains the following tabs: - :ref:`sketch_preferences`. - :ref:`viewer_preferences`. -Visualization tab is activated by default when **Preferences** dialog box is opened in the active SHAPER module. +General tab is activated by default when **Preferences** dialog box is opened in the active SHAPER module. Other tabs are activated by click on tab header. +.. _general_preferences: + +General tab +^^^^^^^^^^^ + +This tab defines what parts to be activated and what elements to be visible after opening a study or a script. + +.. figure:: /images/general_preferences.png + :align: center + + **Preferences**: General tab + +**Input fields**: + +- **Activate** relates to activation of part when opening a HDF document. Its could be one of the following: + + - "Last part" - activate last part in the document (**default value**); + - "All parts" - activate all parts within the document; + - "No activation" - do not activate any part. + +- **Display** in "Opening a study". It specifies the shapes, which should be visualized when activating a part. It could be one of the following: + + - "As stored in HDF" - display only the shapes visible before the document is saved (**default value**); + - "Last item in each folder" - show only the last result in each folder of the part: Constructions, Results, Groups, Fields; + - "All items" - show all shapes from each folder; + - "No visualization" - do not display any shape. + +- **Display** in "Launching a python script". It specifies the shapes, which should be visualized when loading a script using "File -> Load Script..." menu. It could be one of the following: + + - "Last item in each folder" - show only the last result in each folder of the part: Constructions, Results, Groups, Fields; + - "All items" - show all shapes from each folder(**default value**); + - "No visualization" - do not display any shape. + .. _visualization_preferences: Visualization tab diff --git a/doc/gui/images/general_preferences.png b/doc/gui/images/general_preferences.png new file mode 100644 index 000000000..e7eee1721 Binary files /dev/null and b/doc/gui/images/general_preferences.png differ diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 2d7a4917f..07adac9db 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -58,6 +58,7 @@ SET(PROJECT_LIBRARIES Locale ModelAPI ModelGeomAlgo + ModuleBase ) ADD_DEFINITIONS(-DMODELHIGHAPI_EXPORTS -DWNT) @@ -87,6 +88,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Locale ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/ModelGeomAlgo + ${PROJECT_SOURCE_DIR}/src/ModuleBase ${PROJECT_SOURCE_DIR}/src/PartSetPlugin ${OpenCASCADE_INCLUDE_DIR} ) diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index 82423fb0b..bd87cd0e4 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -82,7 +82,7 @@ void ModelHighAPI_Interface::execute(bool isForce) Events_Loop* aLoop = Events_Loop::loop(); aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); } diff --git a/src/ModelHighAPI/ModelHighAPI_Services.cpp b/src/ModelHighAPI/ModelHighAPI_Services.cpp index 09dea983c..763798c8b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Services.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Services.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -106,8 +108,9 @@ void begin() aNbTransactions = aNbUndo; ++aTransactionID; } + static std::string anOperationPrefix(ModuleBase_Tools::translate("", "Operation").toStdString()); std::ostringstream aTransactionName; - aTransactionName << "Operation_" << aTransactionID; + aTransactionName << anOperationPrefix << "_" << aTransactionID; ModelAPI_Session::get()->startOperation(aTransactionName.str()); } diff --git a/src/ModuleBase/ModuleBase_Preferences.cpp b/src/ModuleBase/ModuleBase_Preferences.cpp index c651c7d46..229603f83 100644 --- a/src/ModuleBase/ModuleBase_Preferences.cpp +++ b/src/ModuleBase/ModuleBase_Preferences.cpp @@ -35,6 +35,7 @@ const QString ModuleBase_Preferences::VIEWER_SECTION = "Viewer"; const QString ModuleBase_Preferences::MENU_SECTION = "Menu"; +const QString ModuleBase_Preferences::GENERAL_SECTION = "General"; SUIT_ResourceMgr* ModuleBase_Preferences::myResourceMgr = 0; @@ -115,6 +116,7 @@ void ModuleBase_Preferences::loadCustomProps() void ModuleBase_Preferences::createEditContent(ModuleBase_IPrefMgr* thePref, int thePage) { thePref->prefMgr()->setItemIcon(thePage, QIcon(":pictures/module.png")); + createGeneralTab(thePref, thePage); createCustomPage(thePref, thePage); } @@ -150,6 +152,64 @@ void ModuleBase_Preferences::resetConfigPropPreferences(SUIT_PreferenceMgr* theP } } +void ModuleBase_Preferences::createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId) +{ + int generalTab = thePref->addPreference(QObject::tr("General"), thePageId, + SUIT_PreferenceMgr::Auto, QString(), QString()); + thePref->setItemProperty("columns", 2, generalTab); + + QStringList actItemList; + actItemList << QObject::tr("Last part") + << QObject::tr("All parts") + << QObject::tr("No activation"); + + QList actIdList; + actIdList << 0 << 1 << 2; + + // Group related to opening a study + int group = thePref->addPreference(QObject::tr("Opening a study"), generalTab, + SUIT_PreferenceMgr::Auto, QString(), QString()); + + int actId = thePref->addPreference(QObject::tr("Activate"), group, SUIT_PreferenceMgr::Selector, + ModuleBase_Preferences::GENERAL_SECTION, + "part_activation_study"); + thePref->setItemProperty("strings", actItemList, actId); + thePref->setItemProperty("indexes", actIdList, actId); + + QStringList visuItemList; + visuItemList << QObject::tr("As stored in HDF") + << QObject::tr("Last item in each folder") + << QObject::tr("All items") + << QObject::tr("No visualization"); + + QList visuIdList; + visuIdList << 0 << 1 << 2 << 3; + + int visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector, + ModuleBase_Preferences::GENERAL_SECTION, + "part_visualization_study"); + thePref->setItemProperty("strings", visuItemList, visuId); + thePref->setItemProperty("indexes", visuIdList, visuId); + + // Group related to running a python script + group = thePref->addPreference(QObject::tr("Launching a python script"), generalTab, + SUIT_PreferenceMgr::Auto, QString(), QString()); + + visuItemList.clear(); + visuItemList << QObject::tr("Last item in each folder") + << QObject::tr("All items") + << QObject::tr("No visualization"); + + visuIdList.clear(); + visuIdList << 0 << 1 << 2; + + visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector, + ModuleBase_Preferences::GENERAL_SECTION, + "part_visualization_script"); + thePref->setItemProperty("strings", visuItemList, visuId); + thePref->setItemProperty("indexes", visuIdList, visuId); +} + void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId) { SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); diff --git a/src/ModuleBase/ModuleBase_Preferences.h b/src/ModuleBase/ModuleBase_Preferences.h index 985262569..65b2a2d7a 100644 --- a/src/ModuleBase/ModuleBase_Preferences.h +++ b/src/ModuleBase/ModuleBase_Preferences.h @@ -47,6 +47,9 @@ class MODULEBASE_EXPORT ModuleBase_Preferences /// Name of preferences of menu section static const QString MENU_SECTION; + /// Name of preferences of general section + static const QString GENERAL_SECTION; + /// Shows a dialog box to edit preferences /// \param theModified a list of modified preferences static bool editPreferences(ModuleBase_Prefs& theModified); @@ -83,6 +86,9 @@ private: /// Set default values to the Config_PropManager properties static void resetConfig(); + /// Creates a content for General tab, which defines behavior of loading parts and displaying shapes + static void createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId); + /// Creates content of preferences editing widget static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId); diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index b014d60de..1b5bfc9a3 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +55,12 @@ #include +#ifdef HAVE_SALOME +#include +#include +#include +#endif + #include #include #include @@ -108,6 +116,51 @@ namespace ModuleBase_Tools { //****************************************************************** + //! Waits for REDISPLAY message and set the Visible flag to the entities + //! according to Preferences choice. + class ModuleBase_RedisplayListener : public Events_Listener + { + public: + static std::shared_ptr instance() + { + static std::shared_ptr + anInstance(new ModuleBase_RedisplayListener); + return anInstance; + } + + void processEvent(const std::shared_ptr& theMessage) + { + if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)) + { +#if HAVE_SALOME + // If the python script is being loaded now, the preferences should be used + // to display the required object + SUIT_Application * app = SUIT_Session::session()->activeApplication(); + QVariant aVar = app->property("IsLoadedScript"); + if (!aVar.isNull() && aVar.toBool()) { + DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); + int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); + if (aSize > 0) { + ObjectPtr anPartObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1); + ResultPartPtr aPart = std::dynamic_pointer_cast(anPartObject); + ModuleBase_Tools::setDisplaying(aPart, true); + } + } +#endif + } + } + + private: + ModuleBase_RedisplayListener() + { + Events_Loop::loop()->registerListener(this, + Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + }; + + static std::shared_ptr + RL = ModuleBase_RedisplayListener::instance(); + //****************************************************************** void adjustMargins(QWidget* theWidget) @@ -1342,6 +1395,46 @@ qreal currentPixelRatio() } +// Set displaying status to every element on group +static void setDisplayingByLoop(DocumentPtr theDoc, int theSize, + std::string theGroup, bool theDisplayFromScript) +{ + int aDisplayingId = -1; + if (theDisplayFromScript) { + aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General", + "part_visualization_script", -1); + // Increase ID to prevert using "As stored in HDF" + ++aDisplayingId; + } + else { + aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General", + "part_visualization_study", -1); + + // if chosen "As stored in HDF" then don't change displaying + if (aDisplayingId == 0) + 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); +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index a68f2ee9e..cae27a1d9 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -406,6 +406,11 @@ std::wstring MODULEBASE_EXPORT generateName(const AttributePtr& theAttribute, /// Returns pixel ratio of a screen where main window is displayed qreal MODULEBASE_EXPORT currentPixelRatio(); + +/// Set displaying status for elements from part depending on the settings +/// \param thePart a pointer of part +void MODULEBASE_EXPORT setDisplaying(std::shared_ptr thePart, + bool theDisplayFromScript = false); } #endif diff --git a/src/ModuleBase/ModuleBase_msg_fr.ts b/src/ModuleBase/ModuleBase_msg_fr.ts index 050f6abb6..39de141b1 100644 --- a/src/ModuleBase/ModuleBase_msg_fr.ts +++ b/src/ModuleBase/ModuleBase_msg_fr.ts @@ -278,13 +278,61 @@ Replace Remplacer - - Trihedron arrows constant size - Flèche trièdre de taille constante - + + Trihedron arrows constant size + Flèche trièdre de taille constante + Keep trihedron arrows view size constant Maintenir la taille de la vue des flèches trièdres constante + + General + Général + + + Opening a study + Ouverture d'une étude + + + Launching a python script + Lancement d'un script python + + + Activate + Activation + + + Display + Visualisation + + + Last part + Dernière pièce + + + All parts + Toutes les pièces + + + No activation + Aucune + + + As stored in HDF + Comme dans le HDF + + + Last item in each folder + Le dernier élément de chaque dossier + + + All items + Tous les éléments + + + No visualization + Aucune visualisation + diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index ce5f478a3..b0cf3a6dc 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -495,15 +496,20 @@ void PartSet_MenuMgr::onActivatePart(bool) void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const { bool isFirstLoad = !thePart->partDoc().get(); + ModuleBase_Tools::blockUpdateViewer(true); thePart->activate(); if (isFirstLoad) { XGUI_Workshop* aWorkshop = myModule->getWorkshop(); XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser(); + ModuleBase_Tools::setDisplaying(thePart); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + aObjBrowser->onSelectionChanged(); DocumentPtr aDoc = thePart->partDoc(); std::list aStates; aDoc->restoreNodesState(aStates); aObjBrowser->setStateForDoc(aDoc, aStates); } + ModuleBase_Tools::blockUpdateViewer(false); } void PartSet_MenuMgr::onActivateAllParts() diff --git a/src/SHAPERGUI/resources/LightApp.xml.in b/src/SHAPERGUI/resources/LightApp.xml.in index 33908724f..0a0028ab8 100644 --- a/src/SHAPERGUI/resources/LightApp.xml.in +++ b/src/SHAPERGUI/resources/LightApp.xml.in @@ -22,6 +22,12 @@ +
+ + + + +
diff --git a/src/XGUI/SHAPER.xml b/src/XGUI/SHAPER.xml index 879498824..94ff4fcc6 100644 --- a/src/XGUI/SHAPER.xml +++ b/src/XGUI/SHAPER.xml @@ -4,6 +4,12 @@
+
+ + + + +
diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4342023ae..f95053cbd 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1067,6 +1067,37 @@ void XGUI_Workshop::openFile(const QString& theDirectory) } #endif + int anActivationId = + ModuleBase_Preferences::resourceMgr()->integerValue("General", "part_activation_study", -1); + int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); + + if (anActivationId == 0 && aSize > 0) { + ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1); + ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); + if (aPart.get()) { + aPart->activate(); + ModuleBase_Tools::setDisplaying(aPart); + } + } + else if (anActivationId == 1) { + for (int anIndex = 0; anIndex < aSize; ++anIndex) { + ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), anIndex); + ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); + if (aPart.get()) { + aPart->activate(); + ModuleBase_Tools::setDisplaying(aPart); + + if (anIndex < aSize - 1) { + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->startOperation("Activation"); + aMgr->setActiveDocument(aMgr->moduleDocument()); + aMgr->finishOperation(); + updateCommandStatus(); + viewer()->update(); + } + } + } + } QApplication::restoreOverrideCursor(); } diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index b1092af83..34b87d99a 100644 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -50,6 +50,11 @@ #include #include +#ifdef HAVE_SALOME +#include +#include +#endif + #include "XGUI_ActionsMgr.h" #include "XGUI_Displayer.h" #include "XGUI_ErrorMgr.h" @@ -57,7 +62,6 @@ #include "XGUI_OperationMgr.h" #include "XGUI_ModuleConnector.h" #include "XGUI_PropertyPanel.h" - #include "XGUI_QtEvents.h" #include "XGUI_SalomeConnector.h" #include "XGUI_SelectionMgr.h" @@ -373,6 +377,7 @@ void XGUI_WorkshopListener:: } } } + // this processing should be moved in another place in order to do not cause problems in // flush messages chain //if (aHiddenObjects.size() > 0) @@ -392,6 +397,10 @@ void XGUI_WorkshopListener:: void XGUI_WorkshopListener:: onFeatureCreatedMsg(const std::shared_ptr& theMsg) { + SUIT_Application * app = SUIT_Session::session()->activeApplication(); + + QVariant aVar = app->property("IsLoadedScript"); + std::set anObjects = theMsg->objects(); std::set::const_iterator aIt; #ifdef DEBUG_FEATURE_CREATED @@ -406,46 +415,32 @@ void XGUI_WorkshopListener:: //bool aHasPart = false; bool aDisplayed = false; - for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) { - ObjectPtr anObject = *aIt; + if (aVar.isNull() || !aVar.toBool()) { + for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) { + ObjectPtr anObject = *aIt; #ifdef DEBUG_RESULT_COMPSOLID - ResultPtr aRes = std::dynamic_pointer_cast(anObject); - if (aRes.get()) { - ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast(aRes); - if (aCompSolidRes.get()) { - qDebug(QString("COMPSOLID, numberOfSubs = %1") - .arg(aCompSolidRes->numberOfSubs()).toStdString().c_str()); + ResultPtr aRes = std::dynamic_pointer_cast(anObject); + if (aRes.get()) { + ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast(aRes); + if (aCompSolidRes.get()) { + qDebug(QString("COMPSOLID, numberOfSubs = %1") + .arg(aCompSolidRes->numberOfSubs()).toStdString().c_str()); + } + if (ModelAPI_Tools::compSolidOwner(aRes)) + qDebug("COMPSOLID sub-object"); } - if (ModelAPI_Tools::compSolidOwner(aRes)) - qDebug("COMPSOLID sub-object"); - } #endif - // the validity of the data should be checked here in order to avoid display of the objects, - // which were created, then deleted, but flush for the creation event happens after that - // we should not display disabled objects - bool aHide = !anObject->data()->isValid() || - anObject->isDisabled() || - !anObject->isDisplayed(); - if (!aHide) { // check that this is not hidden result - ResultPtr aRes = std::dynamic_pointer_cast(anObject); - aHide = aRes && aRes->isConcealed(); - // Hide the presentation with an empty shape. But isDisplayed state of the object should not - // be changed to the object becomes visible when the shape becomes not empty - if (!aHide && aRes.get()) - aHide = !aRes->shape().get() || aRes->shape()->isNull(); - } - if (!aHide) { - // setDisplayed has to be called in order to synchronize internal state of the object - // with list of displayed objects - if (myWorkshop->module()->canDisplayObject(anObject)) { - anObject->setDisplayed(true); - aDisplayed = displayObject(anObject); - } else - anObject->setDisplayed(false); + + ResultBodyPtr aRes = std::dynamic_pointer_cast(anObject); + + if (aRes.get() && aRes->numberOfSubs() > 0) + for (int anIndex = 0; anIndex < aRes->numberOfSubs(); ++anIndex) + setDisplayed(aRes->subResult(anIndex), aDisplayed); + else + setDisplayed(anObject, aDisplayed); } } - MAYBE_UNUSED bool isCustomized = customizeFeature(anObjects, aDisplayed); //if (myObjectBrowser) @@ -558,3 +553,32 @@ XGUI_Workshop* XGUI_WorkshopListener::workshop() const { return myWorkshop; } + + +void XGUI_WorkshopListener::setDisplayed(ObjectPtr theObject, bool& theDisplayed) +{ + // the validity of the data should be checked here in order to avoid display of the objects, + // which were created, then deleted, but flush for the creation event happens after that + // we should not display disabled objects + bool aHide = !theObject->data()->isValid() || + theObject->isDisabled() || + !theObject->isDisplayed(); + if (!aHide) { // check that this is not hidden result + ResultPtr aRes = std::dynamic_pointer_cast(theObject); + aHide = aRes && aRes->isConcealed(); + // Hide the presentation with an empty shape. But isDisplayed state of the object should not + // be changed to the object becomes visible when the shape becomes not empty + if (!aHide && aRes.get()) + aHide = !aRes->shape().get() || aRes->shape()->isNull(); + } + if (!aHide) { + // setDisplayed has to be called in order to synchronize internal state of the object + // with list of displayed objects + if (myWorkshop->module()->canDisplayObject(theObject)) { + theObject->setDisplayed(true); + theDisplayed = displayObject(theObject); + } + else + theObject->setDisplayed(false); + } +} diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index d8827d57b..dcedeb713 100644 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -103,6 +103,9 @@ protected: XGUI_Workshop* workshop() const; private: + + void setDisplayed(ObjectPtr theObject, bool& theDisplayed); + XGUI_Workshop* myWorkshop; // the current workshop bool myUpdatePrefs;