Salome HOME
Implementation of mechanism of grouping of messages
[modules/shaper.git] / src / Model / Model_Events.h
1 // File:        Model_Events.h
2 // Created:     10 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Events_HeaderFile
6 #define Model_Events_HeaderFile
7
8 #include <Model.h>
9 #include <Events_MessageGroup.h>
10 #include <Events_Loop.h>
11 #include <boost/shared_ptr.hpp>
12 #include <string>
13 #include <set>
14
15 class ModelAPI_Feature;
16 class ModelAPI_Document;
17
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";
26
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
30 public:
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);}
36
37   /// Returns the feature that has been updated
38   std::set<boost::shared_ptr<ModelAPI_Feature> > features() const {return myFeatures;}
39
40   //! Creates a new empty group (to store it in the loop before flush)
41   virtual Events_MessageGroup* newEmpty();
42   //! Allows to join the given message with the current one
43   virtual void Join(Events_MessageGroup& theJoined);
44 };
45
46 /// Message that feature was deleted (used for Object Browser update)
47 class Model_FeatureDeletedMessage : public Events_MessageGroup {
48   boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
49   std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
50 public:
51   /// creates a message by initialization of fields
52   Model_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
53     const std::string& theGroup);
54
55   /// Returns the ID of this message (EVENT_FEATURE_DELETED)
56   static const Events_ID messageId();
57
58   /// Returns the feature that has been updated
59   boost::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
60
61   /// Returns the group where the feature was deleted
62   const std::set<std::string >& groups() const {return myGroups;}
63
64   //! Creates a new empty group (to store it in the loop before flush)
65   virtual Events_MessageGroup* newEmpty();
66
67   //! Allows to join the given message with the current one
68   virtual void Join(Events_MessageGroup& theJoined);
69 };
70
71 #endif