Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PYTHON_PLUGIN
[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_H_
6 #define ModelAPI_Events_H_
7
8 #include <ModelAPI.h>
9 #include <Events_MessageGroup.h>
10 #include <memory>
11 #include <string>
12 #include <set>
13
14 #include "ModelAPI_Object.h"
15
16 class ModelAPI_Document;
17
18 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
19 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
20 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
21 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
22 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
23 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
24 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
25 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
26 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
27 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
28 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
29 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
30 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
31 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
32 /// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
33 static const char * EVENT_OBJECT_TOSHOW = "ObjectShow";
34 /// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
35 static const char * EVENT_OBJECT_TOHIDE = "ObjectHide";
36
37 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
38 class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
39 {
40  protected:
41   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0)
42       : Events_MessageGroup(theID, theSender)
43   {
44   }
45
46  public:
47   /// Returns the feature that has been updated
48   virtual const std::set<ObjectPtr>& objects() const = 0;
49
50   //! Creates a new empty group (to store it in the loop before flush)
51   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
52
53   //! Allows to join the given message with the current one
54   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
55 };
56
57 /// Message that feature was deleted (used for Object Browser update)
58 class ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
59 {
60  protected:
61   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0)
62       : Events_MessageGroup(theID, theSender)
63   {
64   }
65
66  public:
67   /// Returns the feature that has been updated
68   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
69
70   /// Returns the group where the feature was deleted
71   virtual const std::set<std::string>& groups() const = 0;
72
73   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
74
75   virtual const Events_ID messageId() = 0;
76
77   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
78 };
79
80 /// Allows to create ModelAPI messages
81 class MODELAPI_EXPORT ModelAPI_EventCreator
82 {
83  public:
84   /// creates created, updated or moved messages and sends to the loop
85   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
86                            const bool isGroupped = true) const = 0;
87   /// creates deleted message and sends to the loop
88   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
89                            const std::string& theGroup) const = 0;
90
91   /// returns the creator instance
92   static const ModelAPI_EventCreator* get();
93
94   /// sets the creator instance
95   static void set(const ModelAPI_EventCreator* theCreator);
96 };
97
98 #endif