Salome HOME
Merge branch 'SALOME-8.2.0_porting'
[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_Feature>& theReordered) const;
28
29   /// must be one per application, the constructor for internal usage only
30   Model_EventCreator();
31 };
32
33 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
34 class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
35 {
36   std::set<ObjectPtr> myObjects;  ///< which feature is changed
37
38   /// Sender is not important, all information is located in the feature.
39   /// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
40   Model_ObjectUpdatedMessage(const ObjectPtr& theObject, const Events_ID& theEvent);
41
42   friend class Model_EventCreator;
43  public:
44
45   /// Returns the feature that has been updated
46   virtual const std::set<ObjectPtr>& objects() const;
47
48   //! Creates a new empty group (to store it in the loop before flush)
49   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
50
51   //! Allows to join the given message with the current one
52   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
53 };
54
55 /// Message that feature was deleted (used for Object Browser update)
56 class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
57 {
58   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
59   std::set<std::string> myGroups;  ///< group identifiers that contained the deleted feature
60
61   /// Use ModelAPI for creation of this event.
62   Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
63                              const std::string& theGroup);
64
65   friend class Model_EventCreator;
66  public:
67   /// Returns the document that has been updated
68   virtual std::shared_ptr<ModelAPI_Document> document() const
69   {
70     return myDoc;
71   }
72
73   /// Returns the group where the objects were deleted
74   virtual const std::set<std::string>& groups() const
75   {
76     return myGroups;
77   }
78
79   /// Returns the new empty message of this type
80   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
81
82   /// Returns the identifier of this message
83   virtual const Events_ID messageId();
84
85   /// Appends to this message the given one
86   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
87 };
88
89 /// Message that feature was deleted (used for Object Browser update)
90 class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
91 {
92   std::shared_ptr<ModelAPI_Feature> myReordered;  ///< the feature that was moved
93
94   /// Use ModelAPI for creation of this event.
95   Model_OrderUpdatedMessage(FeaturePtr theReordered,
96                             const void* theSender = 0);
97
98   friend class Model_EventCreator;
99  public:
100   /// Returns the document that has been updated
101   virtual std::shared_ptr<ModelAPI_Feature> reordered()
102   {
103     return myReordered;
104   }
105
106   /// Returns the identifier of this message
107   virtual const Events_ID messageId();
108 };
109
110 #endif