1 // File: Model_Events.h
2 // Created: 10 Apr 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef Model_Events_HeaderFile
6 #define Model_Events_HeaderFile
9 #include <Events_MessageGroup.h>
10 #include <Events_Loop.h>
11 #include <boost/shared_ptr.hpp>
15 #include "ModelAPI_Feature.h"
17 class ModelAPI_Document;
19 /// Event ID that feature is created (comes with Model_FeatureUpdatedMessage)
20 static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
21 /// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage)
22 static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
23 /// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage)
24 static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
25 /// Event ID that data of feature is updated (comes with Model_FeaturesMovedMessage)
26 static const char * EVENT_FEATURE_MOVED = "FeaturesMoved";
28 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
29 class Model_FeatureUpdatedMessage : public Events_MessageGroup {
30 std::set<FeaturePtr > myFeatures; ///< which feature is changed
32 /// sender is not important, all information is located in the feature
33 Model_FeatureUpdatedMessage(
34 const FeaturePtr& theFeature,
35 const Events_ID& theEvent) : Events_MessageGroup(theEvent, 0)
36 {if (theFeature) myFeatures.insert(theFeature);}
38 /// Returns the feature that has been updated
39 std::set<FeaturePtr > features() const {return myFeatures;}
41 //! Creates a new empty group (to store it in the loop before flush)
42 virtual Events_MessageGroup* newEmpty() {
43 FeaturePtr anEmptyFeature;
44 return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
47 //! Allows to join the given message with the current one
48 virtual void Join(Events_MessageGroup& theJoined) {
49 Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
50 std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
51 for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
52 myFeatures.insert(*aFIter);
57 /// Message that feature was deleted (used for Object Browser update)
58 class Model_FeatureDeletedMessage : public Events_MessageGroup {
59 boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
60 std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
62 /// creates a message by initialization of fields
63 // Model_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
64 // const std::string& theGroup);
66 /// Returns the ID of this message (EVENT_FEATURE_DELETED)
67 // static const Events_ID messageId();
69 /// Returns the feature that has been updated
70 boost::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
72 /// Returns the group where the feature was deleted
73 const std::set<std::string >& groups() const {return myGroups;}
75 //! Creates a new empty group (to store it in the loop before flush)
76 // virtual Events_MessageGroup* newEmpty();
78 //! Allows to join the given message with the current one
79 // virtual void Join(Events_MessageGroup& theJoined);
81 Events_MessageGroup* newEmpty() {
82 return new Model_FeatureDeletedMessage(myDoc, "");
85 Model_FeatureDeletedMessage(
86 const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
87 : Events_MessageGroup(messageId(), 0), myDoc(theDoc)
90 if (!theGroup.empty())
91 myGroups.insert(theGroup);
94 const Events_ID messageId()
96 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
100 void Join(Events_MessageGroup& theJoined)
102 Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
103 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
104 for(; aGIter != aJoined->myGroups.end(); aGIter++) {
105 myGroups.insert(*aGIter);