Salome HOME
Fix the problem of the sketch plane update
[modules/shaper.git] / src / Model / Model_Events.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef Model_Events_H_
22 #define Model_Events_H_
23
24 #include <Model.h>
25 #include <ModelAPI_Events.h>
26
27 #include <memory>
28
29 /// Allovs to create ModelAPI messages
30 class Model_EventCreator : public ModelAPI_EventCreator
31 {
32  public:
33   /// creates created, updated or moved messages and sends to the loop
34   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
35                            const bool isGroupped = true) const;
36   /// creates deleted message and sends to the loop
37   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
38                            const std::string& theGroup) const;
39
40   /// creates reordered message and sends to the loop
41   virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const;
42
43   /// must be one per application, the constructor for internal usage only
44   Model_EventCreator();
45 };
46
47 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
48 class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
49 {
50   std::set<ObjectPtr> myObjects;  ///< which feature is changed
51
52   /// Sender is not important, all information is located in the feature.
53   /// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
54   Model_ObjectUpdatedMessage(const ObjectPtr& theObject, const Events_ID& theEvent);
55
56   friend class Model_EventCreator;
57  public:
58
59   /// Returns the feature that has been updated
60   virtual const std::set<ObjectPtr>& objects() const;
61
62   //! Creates a new empty group (to store it in the loop before flush)
63   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
64
65   //! Allows to join the given message with the current one
66   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
67 };
68
69 /// Message that feature was deleted (used for Object Browser update)
70 class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
71 {
72   ///< group identifiers that contained the deleted feature and document where they are deleted
73   std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> > myGroups;
74
75   /// Use ModelAPI for creation of this event.
76   Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
77                              const std::string& theGroup);
78
79   friend class Model_EventCreator;
80  public:
81   /// Returns the group where the objects were deleted
82   virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
83     groups() const
84   {
85     return myGroups;
86   }
87
88   /// Returns the new empty message of this type
89   virtual std::shared_ptr<Events_MessageGroup> newEmpty();
90
91   /// Returns the identifier of this message
92   virtual const Events_ID messageId();
93
94   /// Appends to this message the given one
95   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
96 };
97
98 /// Message that feature was deleted (used for Object Browser update)
99 class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
100 {
101   std::shared_ptr<ModelAPI_Feature> myReordered;  ///< the feature that was moved
102
103   /// Use ModelAPI for creation of this event.
104   Model_OrderUpdatedMessage(FeaturePtr theReordered,
105                             const void* theSender = 0);
106
107   friend class Model_EventCreator;
108  public:
109   /// Returns the document that has been updated
110   virtual std::shared_ptr<ModelAPI_Feature> reordered()
111   {
112     return myReordered;
113   }
114
115   /// Returns the identifier of this message
116   virtual const Events_ID messageId();
117 };
118
119 #endif