From 4000c4428dcbd19ac8af272ddfd3bae203c87586 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 11 Jun 2020 16:43:17 +0300 Subject: [PATCH] Fix for the issue when the SHAPER module data model was not correctly initialized after a first activation/deactivation, close study and load script. --- .../InitializationPlugin_EvalListener.cpp | 2 +- src/Model/Model_Document.cpp | 2 + src/Model/Model_Session.cpp | 12 ++++- src/PartSet/PartSet_Module.cpp | 49 ++++++++++--------- src/SHAPERGUI/SHAPERGUI.cpp | 12 ++++- src/SHAPERGUI/SHAPERGUI_DataModel.h | 2 +- src/XGUI/XGUI_DataModel.cpp | 10 ++-- 7 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index e90246349..6e5e7d29c 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -222,5 +222,5 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( void InitializationPlugin_EvalListener::initDataModel() { - myInterp->runString("salome_iapp.load_module(\"Shaper\")"); + myInterp->runString("salome_iapp.register_module_in_study(\"Shaper\")"); } diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 5a9c7b4c4..6893930fe 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1150,6 +1150,8 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre { std::shared_ptr aSession = std::dynamic_pointer_cast(ModelAPI_Session::get()); + if (!aSession->hasModuleDocument() || !myObjs) + return FeaturePtr(); // this may be on close of the document FeaturePtr aFeature = aSession->createFeature(theID, this); if (!aFeature) return aFeature; diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index de686eebc..01d354268 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -73,6 +73,7 @@ void Model_Session::closeAll() { Model_Application::getApplication()->deleteAllDocuments(); static const Events_ID aDocChangeEvent = Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED); + myCurrentDoc = NULL; static std::shared_ptr aMsg(new Events_Message(aDocChangeEvent)); Events_Loop::loop()->send(aMsg); Events_Loop::loop()->flush(aDocChangeEvent); @@ -251,6 +252,12 @@ std::shared_ptr Model_Session::moduleDocument() anApp->createDocument(0); // 0 is a root ID // creation of the root document is always outside of the transaction, so, avoid checking it setCheckTransactions(true); + if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) { + myCurrentDoc = moduleDocument(); + static std::shared_ptr aMsg( + new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED))); + Events_Loop::loop()->send(aMsg); + } } return anApp->rootDocument(); } @@ -268,8 +275,9 @@ bool Model_Session::hasModuleDocument() std::shared_ptr Model_Session::activeDocument() { - if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) - myCurrentDoc = moduleDocument(); + if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id())) { + return moduleDocument(); + } return myCurrentDoc; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 536c95cf4..7ea68ddfd 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1530,6 +1530,9 @@ if (aObjIndex.isValid()) { \ void PartSet_Module::processEvent(const std::shared_ptr& theMessage) { if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { + SessionPtr aMgr = ModelAPI_Session::get(); + if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation + return; // Do not change activation of parts if an operation active static QStringList aAllowActivationList; if (aAllowActivationList.isEmpty()) @@ -1541,32 +1544,34 @@ void PartSet_Module::processEvent(const std::shared_ptr& theMess (!aAllowActivationList.contains(myWorkshop->currentOperation()->id()))) return; XGUI_Workshop* aWorkshop = getWorkshop(); - XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView(); - QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel(); - QPalette aPalet = aLabel->palette(); + bool needUpdate = false; + XGUI_DataTree* aTreeView; + if (aWorkshop->objectBrowser()) { + aTreeView = aWorkshop->objectBrowser()->treeView(); + QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel(); + QPalette aPalet = aLabel->palette(); - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aActiveDoc = aMgr->activeDocument(); + DocumentPtr aActiveDoc = aMgr->activeDocument(); - // Clear active part index if there is no Part documents - // It could be not null if document was closed and opened a new - // without closeDocument call - if (aMgr->allOpenedDocuments().size() <= 1) - myActivePartIndex = QModelIndex(); + // Clear active part index if there is no Part documents + // It could be not null if document was closed and opened a new + // without closeDocument call + if (aMgr->allOpenedDocuments().size() <= 1) + myActivePartIndex = QModelIndex(); - XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel(); - QModelIndex aOldActive = myActivePartIndex; - myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0); - bool needUpdate = false; - if (myActivePartIndex.isValid()) { - needUpdate = aTreeView->isExpanded(myActivePartIndex); - if (!needUpdate) - aTreeView->setExpanded(myActivePartIndex, true); - } - if ((aOldActive != myActivePartIndex) && (aOldActive.isValid())) - aTreeView->setExpanded(aOldActive, false); + XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel(); + QModelIndex aOldActive = myActivePartIndex; + myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0); + if (myActivePartIndex.isValid()) { + needUpdate = aTreeView->isExpanded(myActivePartIndex); + if (!needUpdate) + aTreeView->setExpanded(myActivePartIndex, true); + } + if ((aOldActive != myActivePartIndex) && (aOldActive.isValid())) + aTreeView->setExpanded(aOldActive, false); - aLabel->setPalette(aPalet); + aLabel->setPalette(aPalet); + } aWorkshop->updateCommandStatus(); // Update displayed objects in order to update active color diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 764583f67..ef41f900c 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -74,6 +74,8 @@ #include #include +#include + #if OCC_VERSION_HEX < 0x070400 #define SALOME_PATCH_FOR_CTRL_WHEEL #endif @@ -274,6 +276,14 @@ void SHAPERGUI::viewManagers(QStringList& theList) const //****************************************************** bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { + ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet + + // this must be done in the initialization and in activation (on the second activation initialization + // in not called, so SComponent must be added anyway + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); + + bool isDone = LightApp_Module::activateModule(theStudy); loadToolbarsConfig(); @@ -1235,6 +1245,6 @@ void SHAPERGUI::resetToolbars() void SHAPERGUI::publishToStudy() { - if (isActiveModule()) + if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) myWorkshop->module()->launchOperation("PublishToStudy", false); } diff --git a/src/SHAPERGUI/SHAPERGUI_DataModel.h b/src/SHAPERGUI/SHAPERGUI_DataModel.h index 8c206de6b..3c062fb5d 100644 --- a/src/SHAPERGUI/SHAPERGUI_DataModel.h +++ b/src/SHAPERGUI/SHAPERGUI_DataModel.h @@ -70,7 +70,7 @@ class SHAPERGUI_EXPORT SHAPERGUI_DataModel : public LightApp_DataModel /// Creates a module root object if it has not been created yet /// and append it to the active study. It is necessary for correct persistent /// of the model. - void initRootObject(); + virtual void initRootObject() override; /// Update data object /// \param theObj an data object diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index e3a1fb632..5b15106a8 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -201,10 +201,12 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { - DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); - ModuleBase_ITreeNode* aRoot = myRoot->findRoot(aDoc); - if (aRoot) { - updateSubTree(aRoot); + if (ModelAPI_Session::get()->hasModuleDocument()) { + DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); + ModuleBase_ITreeNode* aRoot = myRoot->findRoot(aDoc); + if (aRoot) { + updateSubTree(aRoot); + } } } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { -- 2.39.2