Salome HOME
Fix for delete message bug with pairs document and group
authorvsv <vsv@opencascade.com>
Mon, 23 Jul 2018 14:18:20 +0000 (17:18 +0300)
committervsv <vsv@opencascade.com>
Mon, 23 Jul 2018 14:18:20 +0000 (17:18 +0300)
src/Model/Model_Events.cpp
src/Model/Model_Events.h
src/Model/Model_Session.cpp
src/ModelAPI/ModelAPI_Events.h
src/SketchSolver/SketchSolver_Manager.cpp
src/XGUI/XGUI_DataModel.cpp

index 30d6e70a4321301f96d804b55120fcf018f7909d..e113d3ae7f73b1cbcd66bce97a8dc37b41ff8172 100644 (file)
@@ -88,16 +88,18 @@ void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>
 /////////////////////// DELETED MESSAGE /////////////////////////////
 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
     const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
-    : ModelAPI_ObjectDeletedMessage(messageId(), 0),
-      myDoc(theDoc)
+    : ModelAPI_ObjectDeletedMessage(messageId(), 0)
 {
-  if (!theGroup.empty())
-    myGroups.insert(theGroup);
+  if (!theGroup.empty()) {
+    myGroups.push_back(
+      std::pair<std::shared_ptr<ModelAPI_Document>, std::string>(theDoc, theGroup));
+  }
 }
 
 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
 {
-  return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
+  static const std::shared_ptr<ModelAPI_Document> anEmpty;
+  return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(anEmpty, ""));
 }
 
 const Events_ID Model_ObjectDeletedMessage::messageId()
@@ -110,9 +112,19 @@ void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>
 {
   std::shared_ptr<Model_ObjectDeletedMessage> aJoined =
     std::dynamic_pointer_cast<Model_ObjectDeletedMessage>(theJoined);
-  std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
-  for (; aGIter != aJoined->myGroups.end(); aGIter++) {
-    myGroups.insert(*aGIter);
+
+  const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aJGroups =
+    aJoined->groups();
+
+  std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::iterator aGIter;
+  std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aJIter;
+  for (aJIter = aJGroups.cbegin(); aJIter != aJGroups.cend(); aJIter++) {
+    for (aGIter = myGroups.begin(); aGIter != myGroups.end(); aGIter++) {
+      if (aGIter->first == aJIter->first && aGIter->second == aJIter->second)
+        break; // exists, so no need to insert
+    }
+    if (aGIter == myGroups.end())
+      myGroups.push_back(*aJIter);
   }
 }
 
index c7a46b12027854aec49f74304c4ab1eca9fdac4b..c0ed012542e2d581b7ad723f2d70aa8ef789b500 100644 (file)
@@ -69,8 +69,8 @@ class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
 /// Message that feature was deleted (used for Object Browser update)
 class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
 {
-  std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
-  std::set<std::string> myGroups;  ///< group identifiers that contained the deleted feature
+  ///< group identifiers that contained the deleted feature and document where they are deleted
+  std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> > myGroups;
 
   /// Use ModelAPI for creation of this event.
   Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
@@ -78,14 +78,9 @@ class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
 
   friend class Model_EventCreator;
  public:
-  /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const
-  {
-    return myDoc;
-  }
-
   /// Returns the group where the objects were deleted
-  virtual const std::set<std::string>& groups() const
+  virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
+    groups() const
   {
     return myGroups;
   }
index 8a0b7b89f6d10bb8ee6cc6360eb848b3d39ea837..c0dde0f287ea7bea7ff7f529b0ed201c658cd845 100644 (file)
@@ -504,8 +504,14 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
     if (theMessage->eventID() == kDeletedEvent) {
       std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
-      if (aDeleted &&
-          aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end())
+
+      std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator
+        aGIter = aDeleted->groups().cbegin();
+      for (; aGIter != aDeleted->groups().cend(); aGIter++) {
+        if (aGIter->second == ModelAPI_ResultPart::group())
+          break;
+      }
+      if (aGIter != aDeleted->groups().cend())
       {
          // check that the current feature of the session is still the active Part (even disabled)
         bool aFound = false;
index a7718d1de11721eaa0106e359d2666d62bc4b776..aa957fb723caabfbb3c68e86ba37be75159fdc57 100644 (file)
@@ -128,11 +128,9 @@ protected:
   virtual ~ModelAPI_ObjectDeletedMessage();
 
 public:
-  /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
-
   /// Returns the groups where the objects were deleted
-  virtual const std::set<std::string>& groups() const = 0;
+  virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
+    groups() const = 0;
 
   /// Creates the new empty message of this kind
   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
index 8f30aa70d255071eba9bcd450e63cf7cc9886df0..8e976d02b9dd8d370fc3f515ddd47be4e2c30900 100644 (file)
@@ -163,14 +163,15 @@ void SketchSolver_Manager::processEvent(
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
       std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
-    const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
+    const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aFeatureGroups =
+      aDeleteMsg->groups();
 
     // Find SketchPlugin_Sketch::ID() in groups.
     // The constraint groups should be updated when an object removed from Sketch
-    std::set<std::string>::const_iterator aFGrIter;
+    std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aFGrIter;
     for (aFGrIter = aFeatureGroups.begin(); aFGrIter != aFeatureGroups.end(); aFGrIter++)
-      if (aFGrIter->compare(ModelAPI_ResultConstruction::group()) == 0 ||
-          aFGrIter->compare(ModelAPI_Feature::group()) == 0)
+      if (aFGrIter->second == ModelAPI_ResultConstruction::group() ||
+        aFGrIter->second == ModelAPI_Feature::group())
         break;
 
     if (aFGrIter != aFeatureGroups.end()) {
index e28d26a55a55ce80552d16fdedbd6aaea1a02973..d677b8d9409f1aa3f4b45495c28ee408b9d92a4b 100644 (file)
@@ -81,11 +81,11 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
       std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
           std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
-      DocumentPtr aDoc = aUpdMsg->document();
-      std::set<std::string> aMsgGroups = aUpdMsg->groups();
-      std::set<std::string>::const_iterator aIt;
+      const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aMsgGroups =
+        aUpdMsg->groups();
+      std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aIt;
       for (aIt = aMsgGroups.cbegin(); aIt != aMsgGroups.cend(); aIt++)
-        QTreeNodesList aList = myRoot->objectsDeleted(aDoc, (*aIt).c_str());
+        QTreeNodesList aList = myRoot->objectsDeleted(aIt->first, aIt->second.c_str());
       rebuildDataTree();
   }
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {