From 02f05f9a36e033a4d52bab90d0917d9679683c0f Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 8 Jun 2020 14:51:08 +0300 Subject: [PATCH] #Initial implementation of support of dump and save to hdf in case SHAPER module was not activated, but script is loaded. bos #19209 EDF 21531 - General problem of dumping a 9.4.0 study --- .../ConnectorPlugin_PublishToStudyFeature.py | 2 +- src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts | 4 +- .../InitializationPlugin_EvalListener.cpp | 5 ++ .../InitializationPlugin_EvalListener.h | 3 ++ .../InitializationPlugin_Plugin.cpp | 2 + .../InitializationPlugin_PyInterp.cpp | 6 +++ .../InitializationPlugin_PyInterp.h | 3 ++ src/Model/Model_Document.cpp | 2 + src/Model/Model_Session.cpp | 12 ++++- src/PartSet/PartSet_Module.cpp | 49 ++++++++++-------- src/SHAPERGUI/SHAPERGUI.cpp | 51 +++++++++++++------ src/SHAPERGUI/SHAPERGUI.h | 3 ++ src/SHAPERGUI/SHAPERGUI_DataModel.h | 2 +- src/XGUI/XGUI_DataModel.cpp | 10 ++-- 14 files changed, 106 insertions(+), 48 deletions(-) diff --git a/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py b/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py index 30be5591d..d75dd6a52 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py @@ -83,7 +83,7 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature): aPartRes = ModelAPI.modelAPI_ResultPart(ModelAPI.modelAPI_Result(aPartObject)) aPartDoc = aPartRes.partDoc() if aPartDoc is None and aPartObject is not None: - EventsAPI.Events_InfoMessage("PublishToStudy", "For publish to SHAPER-STUDY some Part is not activated", self).send() + EventsAPI.Events_InfoMessage("PublishToStudy", "To publish to SHAPER-STUDY, activate Parts in SHAPER", self).send() break aPartFeatureId = aPartSet.feature(aPartRes).data().featureId() # Collects all features of exported results to find results of the same features and extend id. diff --git a/src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts b/src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts index 5182d5134..f063a15b6 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts +++ b/src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts @@ -23,8 +23,8 @@ Toutes les pièces de l'assemblage ne sont pas à jour, rien n'est publié. Veuillez mettre la dernière fonctionnalité à jour. - For publish to SHAPER-STUDY some Part is not activated - Pour la publication sur SHAPER-STUDY, une pièce n'est pas activée + To publish to SHAPER-STUDY, activate Parts in SHAPER + Pour publier dans SHAPER-STUDY, activez les pièces dans SHAPER diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index a8265d441..6e5e7d29c 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -219,3 +219,8 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( aCalculatedValue[1]); } } + +void InitializationPlugin_EvalListener::initDataModel() +{ + myInterp->runString("salome_iapp.register_module_in_study(\"Shaper\")"); +} diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.h b/src/InitializationPlugin/InitializationPlugin_EvalListener.h index ca381b2e4..5b6f3d7be 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.h +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.h @@ -45,6 +45,9 @@ class InitializationPlugin_EvalListener : public Events_Listener INITIALIZATIONPLUGIN_EXPORT virtual void processEvent(const std::shared_ptr& theMessage); + // performs the python call to initialize high level data model on internal data model creation + void initDataModel(); + protected: /// Evaluates theExpression and returns its value. double evaluate(std::shared_ptr theParameter, diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index 872a60372..6ddcc0af7 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -63,6 +63,8 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrmoduleDocument()) return; + myEvalListener->initDataModel(); + std::list aFeatures; // the viewer update should be blocked in order to avoid the features blinking before they are diff --git a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp index e64fc3788..0e07f9696 100644 --- a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp +++ b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp @@ -255,3 +255,9 @@ void InitializationPlugin_PyInterp::closeContext() Py_XDECREF(_local_context); PyInterp_Interp::closeContext(); } + +bool InitializationPlugin_PyInterp::runString(std::string theString) +{ + PyLockWrapper lck; // Acquire GIL until the end of the method + return PyRun_SimpleString(theString.c_str()); +} diff --git a/src/InitializationPlugin/InitializationPlugin_PyInterp.h b/src/InitializationPlugin/InitializationPlugin_PyInterp.h index 094d4fbc9..b34a8df82 100644 --- a/src/InitializationPlugin/InitializationPlugin_PyInterp.h +++ b/src/InitializationPlugin/InitializationPlugin_PyInterp.h @@ -50,6 +50,9 @@ class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_PyInterp : public PyInter /// Evaluates theExpression and returns its value. double evaluate(const std::string& theExpression, std::string& theError); + /// Runs the string command in the python interpreter. Returns true if no error is in result. + bool runString(std::string theString); + protected: /// Returns error message. std::string errorMessage(); 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 efdddb88e..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 @@ -205,6 +207,13 @@ void SHAPERGUI::initialize(CAM_Application* theApp) #endif createMenu(aId, aEditMenu); + if (!myInspectionPanel) { + myInspectionPanel = myWorkshop->inspectionPanel(); + connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)), + this, SLOT(onWhatIs(bool))); + } + hideInternalWindows(); + // Initialize viewer proxy if OCC viewer is already exist ViewManagerList aOCCViewManagers; application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers); @@ -224,6 +233,8 @@ void SHAPERGUI::initialize(CAM_Application* theApp) } } } + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); + aDataModel->initRootObject(); } //****************************************************** @@ -265,12 +276,17 @@ void SHAPERGUI::viewManagers(QStringList& theList) const //****************************************************** bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { - bool isDone = LightApp_Module::activateModule(theStudy); - loadToolbarsConfig(); + 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(); + if (isDone) { setMenuShown(true); setToolShown(true); @@ -284,11 +300,6 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) aObjDoc->toggleViewAction()->setVisible(true); } - if (!myInspectionPanel) { - myInspectionPanel = myWorkshop->inspectionPanel(); - connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)), - this, SLOT(onWhatIs(bool))); - } myInspectionPanel->toggleViewAction()->setVisible(true); myWorkshop->facesPanel()->toggleViewAction()->setVisible(true); @@ -387,16 +398,12 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) } //****************************************************** -bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) +void SHAPERGUI::hideInternalWindows() { - saveToolbarsConfig(); - myProxyViewer->activateViewer(false); setMenuShown(false); setToolShown(false); - myWorkshop->deactivateModule(); - QObject* aObj = myWorkshop->objectBrowser()->parent(); QDockWidget* aObjDoc = dynamic_cast(aObj); if (aObjDoc) { @@ -405,17 +412,30 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) aObjDoc->toggleViewAction()->setVisible(false); } - myIsInspectionVisible = myInspectionPanel->isVisible(); myInspectionPanel->hide(); myInspectionPanel->toggleViewAction()->setVisible(false); - myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible(); myWorkshop->facesPanel()->hide(); myWorkshop->facesPanel()->toggleViewAction()->setVisible(false); myWorkshop->propertyPanel()->hide(); myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false); + myWorkshop->hidePanel(myWorkshop->facesPanel()); +} + + +//****************************************************** +bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) +{ + saveToolbarsConfig(); + myWorkshop->deactivateModule(); + + myIsInspectionVisible = myInspectionPanel->isVisible(); + myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible(); + hideInternalWindows(); + + // the active operation should be stopped for the next activation. // There should not be active operation and visualized preview. // Abort operation should be performed before the selection's remove @@ -447,7 +467,6 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) mySelector = 0; } - myWorkshop->hidePanel(myWorkshop->facesPanel()); //myWorkshop->contextMenuMgr()->disconnectViewer(); SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); @@ -1226,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.h b/src/SHAPERGUI/SHAPERGUI.h index ee3d34a8a..864cc4c90 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -241,6 +241,9 @@ private slots: void saveToolbarsConfig(); void loadToolbarsConfig(); + + void hideInternalWindows(); + /// List of registered nested actions QStringList myNestedActionsList; 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