Salome HOME
#Initial implementation of support of dump and save to hdf in case SHAPER module...
[modules/shaper.git] / src / XGUI / XGUI_DataModel.cpp
index 32548038ce2b4ab3cb3be13906c04d5f89a73e8c..5b15106a862a75750621e20f2f9ee48795a77a06 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 
 #include <cassert>
 
+#ifdef _MSC_VER
+#pragma warning(disable: 4100)
+#endif
+
 
 
 // Constructor *************************************************
@@ -67,6 +71,13 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
       if ((*aIt)->isInHistory())
         aCreated.append(*aIt);
+      if ((*aIt)->groupName() == ModelAPI_ResultPart::group()) {
+        emit beforeTreeRebuild();
+        myRoot->update();
+        rebuildDataTree();
+        emit treeRebuilt();
+        return;
+      }
     }
     if (aCreated.length() == 0)
       return;
@@ -78,7 +89,6 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     QModelIndex aParentIndex1, aParentIndex2;
     ObjectPtr aObj;
     bool aRebuildAll = false;
-    bool isInserted = false;
 
     foreach(ModuleBase_ITreeNode* aNode, aNodes) {
       aObj = aNode->object();
@@ -93,13 +103,10 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
         aParentIndex2 = getParentIndex(aNode, 2);
         insertRows(aRow, 1, aParentIndex1);
         dataChanged(aParentIndex1, aParentIndex2);
-        isInserted = true;
       }
     }
     if (aRebuildAll)
       rebuildDataTree();
-    else if (isInserted)
-      endInsertRows();
 
     emit treeRebuilt();
   }
@@ -194,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)) {
@@ -207,7 +216,6 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     QObjectPtrList aCreated;
     std::set<ObjectPtr>::const_iterator aIt;
-    bool aRebuildAll = false;
     for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
       ObjectPtr aObj = (*aIt);
       if (aObj->groupName() == ModelAPI_ResultField::group()) {
@@ -216,8 +224,6 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
     }
     if (aCreated.length() == 0)
       return;
-    bool isInsert = false;
-    bool isRemove = false;
     emit beforeTreeRebuild();
     foreach(ObjectPtr aObj, aCreated) {
       ModuleBase_ITreeNode* aNode = myRoot->subNode(aObj);
@@ -231,22 +237,16 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
 
         if (aNewNb > aOldNb) {
           insertRows(aOldNb - 1, aNewNb - aOldNb, aFirstIdx);
-          isInsert = true;
         }
         else if (aNewNb < aOldNb) {
           if (aNewNb)
             removeRows(aNewNb - 1, aOldNb - aNewNb, aFirstIdx);
           else if (aOldNb)
             removeRows(0, aOldNb, aFirstIdx);
-          isRemove = aNewNb || aOldNb;
         }
         dataChanged(aFirstIdx, aLastIdx);
       }
     }
-    if (isRemove)
-      endRemoveRows();
-    if (isInsert)
-      endInsertRows();
     emit treeRebuilt();
   }
 }
@@ -347,6 +347,7 @@ bool XGUI_DataModel::hasChildren(const QModelIndex& theParent) const
 bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
 {
   beginInsertRows(theParent, theRow, theRow + theCount - 1);
+  endInsertRows();
   return true;
 }
 
@@ -354,6 +355,7 @@ bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& the
 bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
 {
   beginRemoveRows(theParent, theRow, theRow + theCount - 1);
+  endRemoveRows();
   return true;
 }