]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue when the SHAPER module data model was not correctly initialized...
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Jun 2020 13:43:17 +0000 (16:43 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 11 Jun 2020 13:43:17 +0000 (16:43 +0300)
src/InitializationPlugin/InitializationPlugin_EvalListener.cpp
src/Model/Model_Document.cpp
src/Model/Model_Session.cpp
src/PartSet/PartSet_Module.cpp
src/SHAPERGUI/SHAPERGUI.cpp
src/SHAPERGUI/SHAPERGUI_DataModel.h
src/XGUI/XGUI_DataModel.cpp

index e9024634939e4ea59a9bf846ded1bc1b158d9aa6..6e5e7d29c10a3589d4ba72945f7e90f75dcdca96 100644 (file)
@@ -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\")");
 }
index 5a9c7b4c454f92e438817408840e306e2a9c7fa5..6893930feef6bfad68286a496580eba73aae3c27 100644 (file)
@@ -1150,6 +1150,8 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre
 {
   std::shared_ptr<Model_Session> aSession =
     std::dynamic_pointer_cast<Model_Session>(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;
index de686eebce3042c127d3d637b6c0ea52371abc1c..01d35426856e2e5f9c58f95dd05a5f1924f9d5bc 100644 (file)
@@ -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<Events_Message> aMsg(new Events_Message(aDocChangeEvent));
   Events_Loop::loop()->send(aMsg);
   Events_Loop::loop()->flush(aDocChangeEvent);
@@ -251,6 +252,12 @@ std::shared_ptr<ModelAPI_Document> 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<Events_Message> 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<ModelAPI_Document> 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;
 }
 
index 536c95cf49affbd057d3c124d38e30aeb6cf8d2b..7ea68ddfd93f482889bd67beb730e0dcb5413a3e 100644 (file)
@@ -1530,6 +1530,9 @@ if (aObjIndex.isValid()) { \
 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& 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<Events_Message>& 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
index 764583f675451551b59f710d96d746b48c593df4..ef41f900c7500750a6998e5155444019e8f002ea 100644 (file)
@@ -74,6 +74,8 @@
 #include <QMenu>
 #include <QToolBar>
 
+#include <ModelAPI_Session.h>
+
 #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<SHAPERGUI_DataModel*>(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);
 }
index 8c206de6b99150fd818d59dc9ed3b408c3ef67ed..3c062fb5ddbdfa1c4921fcf8d2e8d113e792352b 100644 (file)
@@ -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
index e3a1fb6329fa7cfba576d745e4f3be364f562103..5b15106a862a75750621e20f2f9ee48795a77a06 100644 (file)
@@ -201,10 +201,12 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& 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)) {