]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Events.h
Salome HOME
Moved the model messages from Model to ModelAPI and removed dependencies on Model
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.h
1 // File:        ModelAPI_Events.h
2 // Created:     10 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Events_HeaderFile
6 #define ModelAPI_Events_HeaderFile
7
8 #include <ModelAPI.h>
9 #include <Events_MessageGroup.h>
10 #include <boost/shared_ptr.hpp>
11 #include <string>
12 #include <set>
13
14 #include "ModelAPI_Feature.h"
15
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 ModelAPI_FeatureUpdatedMessage : public Events_MessageGroup {
29 protected:
30   ModelAPI_FeatureUpdatedMessage(const Events_ID theID, const void* theSender = 0)
31     : Events_MessageGroup(theID, theSender) {}
32
33 public:
34   /// Returns the feature that has been updated
35   virtual std::set<FeaturePtr> features() const = 0;
36
37   //! Creates a new empty group (to store it in the loop before flush)
38   virtual Events_MessageGroup* newEmpty() = 0;
39
40   //! Allows to join the given message with the current one
41   virtual void Join(Events_MessageGroup& theJoined) = 0;
42 };
43
44 /// Message that feature was deleted (used for Object Browser update)
45 class ModelAPI_FeatureDeletedMessage : public Events_MessageGroup {
46 protected:
47   ModelAPI_FeatureDeletedMessage(const Events_ID theID, const void* theSender = 0)
48     : Events_MessageGroup(theID, theSender) {}
49
50 public:
51   /// Returns the feature that has been updated
52   virtual boost::shared_ptr<ModelAPI_Document> document() const = 0;
53
54   /// Returns the group where the feature was deleted
55   virtual const std::set<std::string >& groups() const = 0;
56
57   virtual Events_MessageGroup* newEmpty() = 0;
58
59   virtual const Events_ID messageId() = 0;
60
61   virtual void Join(Events_MessageGroup& theJoined) = 0;
62 };
63
64 /// Allows to create ModelAPI messages
65 class MODELAPI_EXPORT ModelAPI_EventCreator {
66 public:
67   /// creates created, updated or moved messages and sends to the loop
68   virtual void sendUpdated(const FeaturePtr& theFeature, const Events_ID& theEvent,
69                            const bool isGroupped = true) const = 0;
70   /// creates deleted message and sends to the loop
71   virtual void sendDeleted(
72     const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const = 0;
73
74   /// returns the creator instance
75   static const ModelAPI_EventCreator* get();
76   
77   /// sets the creator instance
78   static void set(const ModelAPI_EventCreator* theCreator);
79 };
80
81 #endif