Salome HOME
#Initial implementation of support of dump and save to hdf in case SHAPER module...
authormpv <mikhail.ponikarov@opencascade.com>
Mon, 8 Jun 2020 11:51:08 +0000 (14:51 +0300)
committervsr <vsr@opencascade.com>
Mon, 15 Jun 2020 16:48:39 +0000 (19:48 +0300)
bos #19209 EDF 21531 - General problem of dumping a 9.4.0 study

14 files changed:
src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py
src/ConnectorPlugin/ConnectorPlugin_msg_fr.ts
src/InitializationPlugin/InitializationPlugin_EvalListener.cpp
src/InitializationPlugin/InitializationPlugin_EvalListener.h
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/InitializationPlugin/InitializationPlugin_PyInterp.cpp
src/InitializationPlugin/InitializationPlugin_PyInterp.h
src/Model/Model_Document.cpp
src/Model/Model_Session.cpp
src/PartSet/PartSet_Module.cpp
src/SHAPERGUI/SHAPERGUI.cpp
src/SHAPERGUI/SHAPERGUI.h
src/SHAPERGUI/SHAPERGUI_DataModel.h
src/XGUI/XGUI_DataModel.cpp

index 30be5591dba34a0696b703b035429463d7b985d6..d75dd6a52878940714aaa761e04e38c46009063a 100644 (file)
@@ -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.
index 5182d51346085b8b56db0375a77910f411a874c6..f063a15b6c2673fb93ebe284de3ff81af0d4381e 100644 (file)
@@ -23,8 +23,8 @@
       <translation>Toutes les pièces de l'assemblage ne sont pas à jour, rien n'est publié. Veuillez mettre la dernière fonctionnalité à jour.</translation>
     </message>
     <message>
-      <source>For publish to SHAPER-STUDY some Part is not activated</source>
-      <translation>Pour la publication sur SHAPER-STUDY, une pièce n'est pas activée</translation>
+      <source>To publish to SHAPER-STUDY, activate Parts in SHAPER</source>
+      <translation>Pour publier dans SHAPER-STUDY, activez les pièces dans SHAPER</translation>
     </message>
   </context>
 </TS>
index a8265d4414505b94c12678d0c01b7a6435c81c5c..6e5e7d29c10a3589d4ba72945f7e90f75dcdca96 100644 (file)
@@ -219,3 +219,8 @@ void InitializationPlugin_EvalListener::processEvaluationEvent(
                                     aCalculatedValue[1]);
   }
 }
+
+void InitializationPlugin_EvalListener::initDataModel()
+{
+  myInterp->runString("salome_iapp.register_module_in_study(\"Shaper\")");
+}
index ca381b2e45c66e1d514b06dc201424cad6854836..5b6f3d7be7cf7a5b59378166204790a5ebcbaf69 100644 (file)
@@ -45,6 +45,9 @@ class InitializationPlugin_EvalListener : public Events_Listener
   INITIALIZATIONPLUGIN_EXPORT
     virtual void processEvent(const std::shared_ptr<Events_Message>& 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<ModelAPI_Feature> theParameter,
index 872a603722251cc71ebd111f74cfa334fb052b45..6ddcc0af70d18a9cb32e276f7aaa7c40123174fe 100644 (file)
@@ -63,6 +63,8 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
     if (aDoc != ModelAPI_Session::get()->moduleDocument())
       return;
 
+    myEvalListener->initDataModel();
+
     std::list<FeaturePtr> aFeatures;
 
     // the viewer update should be blocked in order to avoid the features blinking before they are
index e64fc378841c9c4e1aa34033a005c33ca5c29320..0e07f96967e4d972b16ac40f379422cc40ea219e 100644 (file)
@@ -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());
+}
index 094d4fbc9771f899b39bd88f6262f384aa8a9a9b..b34a8df82ba0b213c71c2b2f81f49722eb3579ee 100644 (file)
@@ -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();
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 efdddb88e124d6bd2f8003829b06c16361a34a9a..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
@@ -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<SHAPERGUI_DataModel*>(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<SHAPERGUI_DataModel*>(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<QDockWidget*>(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);
 }
index ee3d34a8a9ecd3d4e562fb807732ccc99ff9a40d..864cc4c9010580332924bf88c39233b8faabd867 100644 (file)
@@ -241,6 +241,9 @@ private slots:
   void saveToolbarsConfig();
   void loadToolbarsConfig();
 
+
+  void hideInternalWindows();
+
   /// List of registered nested actions
   QStringList myNestedActionsList;
 
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)) {