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