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 class ModelAPI_Feature;
16 class ModelAPI_Document;
18 /// Event ID that feature is created (comes with Model_FeatureUpdatedMessage)
19 static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
20 /// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage)
21 static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
22 /// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage)
23 static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
24 /// Event ID that data of feature is updated (comes with Model_FeaturesMovedMessage)
25 static const char * EVENT_FEATURE_MOVED = "FeaturesMoved";
27 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
28 class Model_FeatureUpdatedMessage : public Events_MessageGroup {
29 std::set<boost::shared_ptr<ModelAPI_Feature> > myFeatures; ///< which feature is changed
31 /// sender is not important, all information is located in the feature
32 Model_FeatureUpdatedMessage(
33 const boost::shared_ptr<ModelAPI_Feature>& theFeature,
34 const Events_ID& theEvent) : Events_MessageGroup(theEvent, 0)
35 {if (theFeature) myFeatures.insert(theFeature);}
37 /// Returns the feature that has been updated
38 std::set<boost::shared_ptr<ModelAPI_Feature> > features() const {return myFeatures;}
40 //! Creates a new empty group (to store it in the loop before flush)
41 virtual Events_MessageGroup* newEmpty() {
42 boost::shared_ptr<ModelAPI_Feature> anEmptyFeature;
43 return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
46 //! Allows to join the given message with the current one
47 virtual void Join(Events_MessageGroup& theJoined) {
48 Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
49 std::set<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = aJoined->myFeatures.begin();
50 for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
51 myFeatures.insert(*aFIter);
56 /// Message that feature was deleted (used for Object Browser update)
57 class Model_FeatureDeletedMessage : public Events_MessageGroup {
58 boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
59 std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
61 /// creates a message by initialization of fields
62 // Model_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
63 // const std::string& theGroup);
65 /// Returns the ID of this message (EVENT_FEATURE_DELETED)
66 // static const Events_ID messageId();
68 /// Returns the feature that has been updated
69 boost::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
71 /// Returns the group where the feature was deleted
72 const std::set<std::string >& groups() const {return myGroups;}
74 //! Creates a new empty group (to store it in the loop before flush)
75 // virtual Events_MessageGroup* newEmpty();
77 //! Allows to join the given message with the current one
78 // virtual void Join(Events_MessageGroup& theJoined);
80 Events_MessageGroup* newEmpty() {
81 return new Model_FeatureDeletedMessage(myDoc, "");
84 Model_FeatureDeletedMessage(
85 const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
86 : Events_MessageGroup(messageId(), 0), myDoc(theDoc)
89 if (!theGroup.empty())
90 myGroups.insert(theGroup);
93 const Events_ID messageId()
95 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
99 void Join(Events_MessageGroup& theJoined)
101 Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
102 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
103 for(; aGIter != aJoined->myGroups.end(); aGIter++) {
104 myGroups.insert(*aGIter);