Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6'
[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_H_
6 #define Model_Events_H_
7
8 #include <Model.h>
9 #include <ModelAPI_Events.h>
10
11 #include <memory>
12
13 /// Allovs to create ModelAPI messages
14 class Model_EventCreator : public ModelAPI_EventCreator
15 {
16  public:
17   /// creates created, updated or moved messages and sends to the loop
18   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
19                            const bool isGroupped = true) const;
20   /// creates deleted message and sends to the loop
21   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
22                            const std::string& theGroup) const;
23
24   /// must be one per application, the constructor for internal usage only
25   Model_EventCreator();
26 };
27
28 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
29 class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
30 {
31   std::set<ObjectPtr> myObjects;  ///< which feature is changed
32
33   /// Sender is not important, all information is located in the feature.
34   /// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
35   Model_ObjectUpdatedMessage(const ObjectPtr& theObject, const Events_ID& theEvent);
36
37   friend class Model_EventCreator;
38  public:
39
40   /// Returns the feature that has been updated
41   virtual const std::set<ObjectPtr>& objects() const;
42
43   //! Creates a new empty group (to store it in the loop before flush)
44   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
45
46   //! Allows to join the given message with the current one
47   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
48 };
49
50 /// Message that feature was deleted (used for Object Browser update)
51 class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
52 {
53   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
54   std::set<std::string> myGroups;  ///< group identifiers that contained the deleted feature
55
56   /// Use ModelAPI for creation of this event.
57   Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
58                              const std::string& theGroup);
59
60   friend class Model_EventCreator;
61  public:
62   /// Returns the feature that has been updated
63   virtual std::shared_ptr<ModelAPI_Document> document() const
64   {
65     return myDoc;
66   }
67
68   /// Returns the group where the feature was deleted
69   virtual const std::set<std::string>& groups() const
70   {
71     return myGroups;
72   }
73
74   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
75
76   virtual const Events_ID messageId();
77
78   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
79 };
80
81 #endif