Salome HOME
Creation of producedByFeature initial implementation neede for the issue #1306
[modules/shaper.git] / src / Model / Model_Events.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Events.h
4 // Created:     10 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_Events_H_
8 #define Model_Events_H_
9
10 #include <Model.h>
11 #include <ModelAPI_Events.h>
12
13 #include <memory>
14
15 /// Allovs to create ModelAPI messages
16 class Model_EventCreator : public ModelAPI_EventCreator
17 {
18  public:
19   /// creates created, updated or moved messages and sends to the loop
20   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
21                            const bool isGroupped = true) const;
22   /// creates deleted message and sends to the loop
23   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
24                            const std::string& theGroup) const;
25
26   /// creates reordered message and sends to the loop
27   virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
28                              const std::string& theGroup) const;
29
30   /// must be one per application, the constructor for internal usage only
31   Model_EventCreator();
32 };
33
34 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
35 class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
36 {
37   std::set<ObjectPtr> myObjects;  ///< which feature is changed
38
39   /// Sender is not important, all information is located in the feature.
40   /// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
41   Model_ObjectUpdatedMessage(const ObjectPtr& theObject, const Events_ID& theEvent);
42
43   friend class Model_EventCreator;
44  public:
45
46   /// Returns the feature that has been updated
47   virtual const std::set<ObjectPtr>& objects() const;
48
49   //! Creates a new empty group (to store it in the loop before flush)
50   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
51
52   //! Allows to join the given message with the current one
53   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
54 };
55
56 /// Message that feature was deleted (used for Object Browser update)
57 class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
58 {
59   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
60   std::set<std::string> myGroups;  ///< group identifiers that contained the deleted feature
61
62   /// Use ModelAPI for creation of this event.
63   Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
64                              const std::string& theGroup);
65
66   friend class Model_EventCreator;
67  public:
68   /// Returns the document that has been updated
69   virtual std::shared_ptr<ModelAPI_Document> document() const
70   {
71     return myDoc;
72   }
73
74   /// Returns the group where the objects were deleted
75   virtual const std::set<std::string>& groups() const
76   {
77     return myGroups;
78   }
79
80   /// Returns the new empty message of this type
81   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
82
83   /// Returns the identifier of this message
84   virtual const Events_ID messageId();
85
86   /// Appends to this message the given one
87   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
88 };
89
90 /// Message that feature was deleted (used for Object Browser update)
91 class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
92 {
93   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
94   std::string myGroup;  ///< group identifier that contained the deleted feature
95
96   /// Use ModelAPI for creation of this event.
97   Model_OrderUpdatedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
98                              const std::string& theGroup);
99
100   friend class Model_EventCreator;
101  public:
102   /// Returns the document that has been updated
103   virtual std::shared_ptr<ModelAPI_Document> document() const
104   {
105     return myDoc;
106   }
107
108   /// Returns the group where the objects were reordered
109   virtual const std::string& group() const
110   {
111     return myGroup;
112   }
113
114   /// Returns the identifier of this message
115   virtual const Events_ID messageId();
116 };
117
118 #endif