From 5bcf4556c81dd473e2d041c87d489034518fb59b Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 23 Jul 2018 17:18:20 +0300 Subject: [PATCH] Fix for delete message bug with pairs document and group --- src/Model/Model_Events.cpp | 28 ++++++++++++++++------- src/Model/Model_Events.h | 13 ++++------- src/Model/Model_Session.cpp | 10 ++++++-- src/ModelAPI/ModelAPI_Events.h | 6 ++--- src/SketchSolver/SketchSolver_Manager.cpp | 9 ++++---- src/XGUI/XGUI_DataModel.cpp | 8 +++---- 6 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/Model/Model_Events.cpp b/src/Model/Model_Events.cpp index 30d6e70a4..e113d3ae7 100644 --- a/src/Model/Model_Events.cpp +++ b/src/Model/Model_Events.cpp @@ -88,16 +88,18 @@ void Model_ObjectUpdatedMessage::Join(const std::shared_ptr /////////////////////// DELETED MESSAGE ///////////////////////////// Model_ObjectDeletedMessage::Model_ObjectDeletedMessage( const std::shared_ptr& 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::string>(theDoc, theGroup)); + } } std::shared_ptr Model_ObjectDeletedMessage::newEmpty() { - return std::shared_ptr(new Model_ObjectDeletedMessage(myDoc, "")); + static const std::shared_ptr anEmpty; + return std::shared_ptr(new Model_ObjectDeletedMessage(anEmpty, "")); } const Events_ID Model_ObjectDeletedMessage::messageId() @@ -110,9 +112,19 @@ void Model_ObjectDeletedMessage::Join(const std::shared_ptr { std::shared_ptr aJoined = std::dynamic_pointer_cast(theJoined); - std::set::iterator aGIter = aJoined->myGroups.begin(); - for (; aGIter != aJoined->myGroups.end(); aGIter++) { - myGroups.insert(*aGIter); + + const std::list, std::string>>& aJGroups = + aJoined->groups(); + + std::list, std::string>>::iterator aGIter; + std::list, 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); } } diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index c7a46b120..c0ed01254 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -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 myDoc; ///< document owner of the feature - std::set myGroups; ///< group identifiers that contained the deleted feature + ///< group identifiers that contained the deleted feature and document where they are deleted + std::list, std::string> > myGroups; /// Use ModelAPI for creation of this event. Model_ObjectDeletedMessage(const std::shared_ptr& 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 document() const - { - return myDoc; - } - /// Returns the group where the objects were deleted - virtual const std::set& groups() const + virtual const std::list, std::string> >& + groups() const { return myGroups; } diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 8a0b7b89f..c0dde0f28 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -504,8 +504,14 @@ void Model_Session::processEvent(const std::shared_ptr& theMessa if (theMessage->eventID() == kDeletedEvent) { std::shared_ptr aDeleted = std::dynamic_pointer_cast(theMessage); - if (aDeleted && - aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end()) + + std::list, 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; diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index a7718d1de..aa957fb72 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -128,11 +128,9 @@ protected: virtual ~ModelAPI_ObjectDeletedMessage(); public: - /// Returns the document that has been updated - virtual std::shared_ptr document() const = 0; - /// Returns the groups where the objects were deleted - virtual const std::set& groups() const = 0; + virtual const std::list, std::string> >& + groups() const = 0; /// Creates the new empty message of this kind virtual std::shared_ptr newEmpty() = 0; diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 8f30aa70d..8e976d02b 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -163,14 +163,15 @@ void SketchSolver_Manager::processEvent( } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = std::dynamic_pointer_cast(theMessage); - const std::set& aFeatureGroups = aDeleteMsg->groups(); + const std::list, 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::const_iterator aFGrIter; + std::list, 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()) { diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index e28d26a55..d677b8d94 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -81,11 +81,11 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aUpdMsg = std::dynamic_pointer_cast(theMessage); - DocumentPtr aDoc = aUpdMsg->document(); - std::set aMsgGroups = aUpdMsg->groups(); - std::set::const_iterator aIt; + const std::list, std::string>>& aMsgGroups = + aUpdMsg->groups(); + std::list, 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)) { -- 2.30.2