From: Alexey Kondratyev Date: Mon, 18 Oct 2021 08:12:43 +0000 (+0300) Subject: bos #26446: SHAPER: customize study opening; bos #26447: SHAPER: customize script... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4c2252001dae8c524456de32578fe9fca7426780;p=modules%2Fshaper.git bos #26446: SHAPER: customize study opening; bos #26447: SHAPER: 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..359a7f5ec 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,42 @@ 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/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/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index ce5f478a3..d9e7aa8be 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(); + XGUI_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_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 6ff19daae..3314814f1 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -24,6 +24,7 @@ #include "ModuleBase_IWorkshop.h" #include "ModuleBase_Tools.h" +#include "ModuleBase_Preferences.h" #include #include @@ -36,9 +37,13 @@ #include #include #include +#include #include +#include #include +#include + #include #include @@ -401,4 +406,44 @@ void removeTemporaryFiles(const std::string& theDirectory, } } +// 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); +} + } diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 478857fb3..65d0f424d 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -135,6 +136,10 @@ std::string getTmpDirByEnv( const char* thePathEnv); /// Removes files and directory where they are located void removeTemporaryFiles(const std::string& theDirectory, const std::list& theFiles); + +/// Set displaying status for elements from part depending on the settings +/// \param thePart a pointer of part +XGUI_EXPORT void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript = false); }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4342023ae..a572b5294 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -706,6 +706,21 @@ void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const boo myDisplayer->deactivateObjects(anObjects, theUpdateViewer); } } + + 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); + XGUI_Tools::setDisplaying(aPart, true); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + } } //****************************************************** @@ -1067,6 +1082,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(); + XGUI_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(); + XGUI_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..8a3f3d181 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" @@ -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;