From: mpv Date: Fri, 4 Sep 2015 15:51:53 +0000 (+0300) Subject: Created a new event that features were reordered due to the "move to end" action X-Git-Tag: V_1.4.0_beta4~111 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a0a094f0e94be8b4fd7b733e2f6e028b06f0517;p=modules%2Fshaper.git Created a new event that features were reordered due to the "move to end" action --- diff --git a/src/Model/Model_Events.cpp b/src/Model/Model_Events.cpp index 13c4d2568..fb5b650d1 100644 --- a/src/Model/Model_Events.cpp +++ b/src/Model/Model_Events.cpp @@ -27,6 +27,14 @@ void Model_EventCreator::sendDeleted(const std::shared_ptr& t Events_Loop::loop()->send(aMsg, true); } +void Model_EventCreator::sendReordered(const std::shared_ptr& theDoc, + const std::string& theGroup) const +{ + std::shared_ptr aMsg( + new Model_OrderUpdatedMessage(theDoc, theGroup)); + Events_Loop::loop()->send(aMsg, true); +} + Model_EventCreator::Model_EventCreator() { ModelAPI_EventCreator::set(this); @@ -94,3 +102,34 @@ void Model_ObjectDeletedMessage::Join(const std::shared_ptr myGroups.insert(*aGIter); } } + +/////////////////////// REORDERED MESSAGE ///////////////////////////// +Model_OrderUpdatedMessage::Model_OrderUpdatedMessage( + const std::shared_ptr& theDoc, const std::string& theGroup) + : ModelAPI_OrderUpdatedMessage(messageId(), 0), + myDoc(theDoc) +{ + if (!theGroup.empty()) + myGroups.insert(theGroup); +} + +std::shared_ptr Model_OrderUpdatedMessage::newEmpty() +{ + return std::shared_ptr(new Model_OrderUpdatedMessage(myDoc, "")); +} + +const Events_ID Model_OrderUpdatedMessage::messageId() +{ + static Events_ID MY_ID = Events_Loop::eventByName(EVENT_ORDER_UPDATED); + return MY_ID; +} + +void Model_OrderUpdatedMessage::Join(const std::shared_ptr& theJoined) +{ + 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); + } +} diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index d52e7f8ca..7b5ffdce1 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -23,6 +23,10 @@ class Model_EventCreator : public ModelAPI_EventCreator virtual void sendDeleted(const std::shared_ptr& theDoc, const std::string& theGroup) const; + /// creates reordered message and sends to the loop + virtual void sendReordered(const std::shared_ptr& theDoc, + const std::string& theGroup) const; + /// must be one per application, the constructor for internal usage only Model_EventCreator(); }; @@ -61,13 +65,47 @@ class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage friend class Model_EventCreator; public: - /// Returns the feature that has been updated + /// 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 + { + return myGroups; + } + + /// Returns the new empty message of this type + virtual std::shared_ptr newEmpty(); + + /// Returns the identifier of this message + virtual const Events_ID messageId(); + + /// Appends to this message the given one + virtual void Join(const std::shared_ptr& theJoined); +}; + +/// Message that feature was deleted (used for Object Browser update) +class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage +{ + std::shared_ptr myDoc; ///< document owner of the feature + std::set myGroups; ///< group identifiers that contained the deleted feature + + /// Use ModelAPI for creation of this event. + Model_OrderUpdatedMessage(const std::shared_ptr& theDoc, + const std::string& theGroup); + + 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 feature was deleted + /// Returns the group where the objects were reordered virtual const std::set& groups() const { return myGroups; diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 8c65194fd..0a86b587d 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -301,6 +301,7 @@ void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis) theMoved->data()->setUpdateID(0); static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(theMoved, EVENT_UPD); + ModelAPI_EventCreator::get()->sendReordered(theMoved->document(), theMoved->groupName()); } void Model_Objects::clearHistory(ObjectPtr theObj) diff --git a/src/ModelAPI/ModelAPI_Events.cpp b/src/ModelAPI/ModelAPI_Events.cpp index 2260ce1fb..06068c8b6 100644 --- a/src/ModelAPI/ModelAPI_Events.cpp +++ b/src/ModelAPI/ModelAPI_Events.cpp @@ -34,6 +34,18 @@ ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage() } +ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID, + const void* theSender) + : Events_MessageGroup(theID, theSender) +{ + +} + +ModelAPI_OrderUpdatedMessage::~ModelAPI_OrderUpdatedMessage() +{ + +} + ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender) : Events_Message(theID, theSender) diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 545a34768..ae84e6cbc 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -51,6 +51,9 @@ static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked"; static const char * EVENT_SOLVER_FAILED = "SolverFailed"; static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired"; +/// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature) +static const char * EVENT_ORDER_UPDATED = "OrderUpdated"; + /// Message that feature was changed (used for Object Browser update): moved, updated and deleted class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup { @@ -81,10 +84,36 @@ protected: virtual ~ModelAPI_ObjectDeletedMessage(); public: - /// Returns the feature that has been updated + /// 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; + + /// Creates the new empty message of this kind + virtual std::shared_ptr newEmpty() = 0; + + /// Returns the identifier of the kind of a message + virtual const Events_ID messageId() = 0; + + /// Appenad to this message the given one. + virtual void Join(const std::shared_ptr& theJoined) = 0; +}; + +/// Message that order changed (used for Object Browser update) +class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_MessageGroup +{ +protected: + /// Creates an empty message + ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0); + /// The virtual destructor + virtual ~ModelAPI_OrderUpdatedMessage(); + +public: + /// Returns the document that has been updated virtual std::shared_ptr document() const = 0; - /// Returns the group where the feature was deleted + /// Returns the groups where the objects were reordered virtual const std::set& groups() const = 0; /// Creates the new empty message of this kind @@ -107,6 +136,9 @@ public: /// creates deleted message and sends to the loop virtual void sendDeleted(const std::shared_ptr& theDoc, const std::string& theGroup) const = 0; + /// creates reordered message and sends to the loop + virtual void sendReordered(const std::shared_ptr& theDoc, + const std::string& theGroup) const = 0; /// returns the creator instance static const ModelAPI_EventCreator* get();