Salome HOME
Issue #1856: Save state of tree nodes
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 24 Nov 2016 14:45:12 +0000 (17:45 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 24 Nov 2016 14:46:10 +0000 (17:46 +0300)
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_MenuMgr.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_Workshop.cpp

index ce600a203909e271b23a8f3f7d436059cbcdc6ef..54ada4890bdad4daf3994ef2eb1f2c7aaa13a493 100644 (file)
 #include <XGUI_Displayer.h>
 #include <XGUI_DataModel.h>
 #include <XGUI_OperationMgr.h>
+#include <XGUI_ObjectsBrowser.h>
 
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
-#include <ModelAPI_ResultPart.h>
 #include <ModelAPI_ResultParameter.h>
 
 #include <QMainWindow>
@@ -457,9 +457,24 @@ void PartSet_MenuMgr::onActivatePart(bool)
         aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
       }
     }
-    if (aPart.get())
-      aPart->activate();
+    if (aPart.get()) {
+      activatePart(aPart);
       myModule->workshop()->updateCommandStatus();
+    }
+  }
+}
+
+void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const
+{
+  bool isFirstLoad = !thePart->partDoc().get();
+  thePart->activate();
+  if (isFirstLoad) {
+    XGUI_Workshop* aWorkshop = myModule->getWorkshop();
+    XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser();
+    DocumentPtr aDoc = thePart->partDoc();
+    std::list<bool> aStates;
+    aDoc->restoreNodesState(aStates);
+    aObjBrowser->setStateForDoc(aDoc, aStates);
   }
 }
 
@@ -475,7 +490,8 @@ void PartSet_MenuMgr::activatePartSet() const
   SessionPtr aMgr = ModelAPI_Session::get();
   bool isNewTransaction = !aMgr->isOperation();
   // activation may cause changes in current features in document, so it must be in transaction
-  if (isNewTransaction) aMgr->startOperation("Activation");
+  if (isNewTransaction) 
+    aMgr->startOperation("Activation");
   aMgr->setActiveDocument(aMgr->moduleDocument());
   if (isNewTransaction) aMgr->finishOperation();
 
index 5061b1fec3fdaf0f9f3d59b94b30b49834a76ace..454c0acf82391a9155ecfc8c6577a85b994294c4 100644 (file)
@@ -8,6 +8,7 @@
 #define PartSet_MenuMgr_H
 
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <QObject>
 #include <QMap>
@@ -56,6 +57,9 @@ public:
   /// Returns list of granted operation indices
   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
 
+  /// Activates a Part document
+  void activatePart(ResultPartPtr thePart) const;
+
 public slots:
   /// Processes the context menu action click
   /// \param isChecked a state of toggle if the action is checkable
index 921205e7317f9e032403272fbb910bb8f6489487..8d004cdedcb75fc2980512ef5675f858a5b8b0a4 100755 (executable)
@@ -1308,7 +1308,7 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
     if (aPart->partDoc() == aMgr->activeDocument()) {
       myMenuMgr->activatePartSet();
     } else {
-      aPart->activate();
+      myMenuMgr->activatePart(aPart);
     }
   }
 }
index aeae3414671177d6ca1ac61738b66172ce09be08..06fdf458c2017b925abb7b68151da9b3c9fee982 100755 (executable)
@@ -324,6 +324,9 @@ public:
   /// \return theAttribute
   virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
 
+  /// Returns the workshop
+  XGUI_Workshop* getWorkshop() const;
+
 public slots:
   /// Redefines the parent method in order to customize the next case:
   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
@@ -404,9 +407,6 @@ protected:
   //! Delete features
   virtual bool deleteObjects();
 
-  /// Returns the workshop
-  XGUI_Workshop* getWorkshop() const;
-
   void setDefaultConstraintShown();
 
 private:
index 4512cf1feea0b1ade3e5fa919b5b8561ebb20cd1..eb40a0a9c6f949bbde3ccd9938636c7ab46a5171 100644 (file)
@@ -536,3 +536,34 @@ void XGUI_ObjectsBrowser::onAfterModelReset()
     myTreeView->setExpanded(aIndex, true);
   }
 }
+
+std::list<bool> XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const
+{
+  std::list<bool> aStates;
+  XGUI_DataModel* aModel = dataModel();
+  QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
+  int aNbChild = aModel->rowCount(aRootIdx);
+  for (int i = 0; i < aNbChild; i++) {
+    QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
+    aStates.push_back(myTreeView->isExpanded(aIdx));
+  }
+  return aStates;
+}
+
+void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates)
+{
+  if (theStates.size() == 0)
+    return;
+  XGUI_DataModel* aModel = dataModel();
+  QModelIndex aRootIdx = aModel->documentRootIndex(theDoc);
+  int aNbChild = aModel->rowCount(aRootIdx);
+
+  std::list<bool>::const_iterator aIt;
+  int i = 0;
+  for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) {
+    if (i >= aNbChild )
+      break;
+    QModelIndex aIdx = aModel->index(i, 0, aRootIdx);
+    myTreeView->setExpanded(aIdx, (*aIt));
+  }
+}
index 2b9ab1803390bbcaa8125ede8ffdeae784958ab6..416088e32dd325f57a09c77c75e7a8dd99bd1ec6 100644 (file)
@@ -185,6 +185,16 @@ Q_OBJECT
   /// \param theReader the reader object
   void setXMLReader(Config_DataModelReader* theReader);
 
+  /// Returns list of folders opened state for the given document
+  /// \param theDoc the document
+  /// \return list of booleans with state expanded or not
+  std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
+
+  /// Set folders opened state for the given document
+  /// \param theDoc the document
+  /// \param theStates list of booleans with state expanded or not
+  void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
+
 public slots:
   //! Called on Edit command request
   void onEditItem();
index 64954b4ece3f59c3a945676e3bc608d09974108a..f569608b99fc1fb527bdc102603055bdb6707681 100755 (executable)
@@ -698,7 +698,16 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>&
 {
   QApplication::restoreOverrideCursor();
   SessionPtr aMgr = ModelAPI_Session::get();
+
+  std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
+  std::list<DocumentPtr>::const_iterator aIt;
+  for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
+    std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
+    (*aIt)->storeNodesState(aState);
+  }
+
   aMgr->save(theName.toLatin1().constData(), theFileNames);
+
   QApplication::restoreOverrideCursor();
 }
 
@@ -765,6 +774,13 @@ void XGUI_Workshop::openDirectory(const QString& theDirectory)
   aSession->closeAll();
   aSession->load(myCurrentDir.toLatin1().constData());
   myObjectBrowser->rebuildDataTree();
+
+  // Open first level of data tree
+  DocumentPtr aRootDoc = aSession->moduleDocument();
+  std::list<bool> aStates;
+  aRootDoc->restoreNodesState(aStates);
+  myObjectBrowser->setStateForDoc(aRootDoc, aStates);
+
   updateCommandStatus();
 #ifndef HAVE_SALOME
   myMainWindow->setCurrentDir(myCurrentDir, true);