Salome HOME
Simplified calculation of fly out distance and creation of constraints limited only...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Events.h
4 // Created:     10 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef MODELAPI_EVENTS_H_
8 #define MODELAPI_EVENTS_H_
9
10 #include <ModelAPI.h>
11 #include <ModelAPI_Object.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <Events_MessageGroup.h>
15 #include <Events_Loop.h>
16
17 #include <memory>
18 #include <string>
19 #include <set>
20 #include <map>
21
22
23 class ModelAPI_Document;
24
25 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
26 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
27 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
28 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
29 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
30 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
31 /// Event ID that name of feature is changed (comes with Model_ObjectRenamedMessage)
32 static const char * EVENT_OBJECT_RENAMED = "ObjectRenamed";
33 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
34 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
35 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
36 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
37 /// Event ID that error state or error message was updated for the object
38 static const char * EVENT_OBJECT_ERROR_CHANGED = "ObjectsErrorChanged";
39 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
40 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
41 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
42 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
43 //
44 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
45
46 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
47 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
48
49
50 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
51 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
52
53 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
54 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
55
56 /// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
57 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
58
59 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
60 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
61 {
62  protected:
63   /// Creates an empty message
64   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
65   /// The virtual destructor
66   virtual ~ModelAPI_ObjectUpdatedMessage();
67
68  public:
69   /// Returns the feature that has been updated
70   virtual const std::set<ObjectPtr>& objects() const = 0;
71
72   //! Creates a new empty group (to store it in the loop before flush)
73   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
74
75   //! Allows to join the given message with the current one
76   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
77 };
78
79 /// Message that feature was deleted (used for Object Browser update)
80 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
81 {
82 protected:
83   /// Creates an empty message
84   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
85   /// The virtual destructor
86   virtual ~ModelAPI_ObjectDeletedMessage();
87
88 public:
89   /// Returns the document that has been updated
90   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
91
92   /// Returns the groups where the objects were deleted
93   virtual const std::set<std::string>& groups() const = 0;
94
95   /// Creates the new empty message of this kind
96   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
97
98   /// Returns the identifier of the kind of a message
99   virtual const Events_ID messageId() = 0;
100
101   /// Appenad to this message the given one.
102   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
103 };
104
105 /// Message that order changed (used for Object Browser update)
106 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
107 {
108 protected:
109   /// Creates an empty message
110   ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
111   /// The virtual destructor
112   virtual ~ModelAPI_OrderUpdatedMessage();
113
114 public:
115   /// Returns the document that has been updated
116   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
117
118   /// Returns the groups where the objects were reordered
119   virtual const std::string& group() const = 0;
120
121   /// Returns the identifier of the kind of a message
122   virtual const Events_ID messageId() = 0;
123 };
124
125 /// Allows to create ModelAPI messages
126 class MODELAPI_EXPORT ModelAPI_EventCreator
127 {
128 public:
129   /// creates created, updated or moved messages and sends to the loop
130   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
131                            const bool isGroupped = true) const = 0;
132   /// creates deleted message and sends to the loop
133   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
134                            const std::string& theGroup) const = 0;
135   /// creates reordered message and sends to the loop
136   virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
137                              const std::string& theGroup) const = 0;
138
139   /// returns the creator instance
140   static const ModelAPI_EventCreator* get();
141
142   /// sets the creator instance
143   static void set(const ModelAPI_EventCreator* theCreator);
144 };
145
146 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
147 /// Contains the state information about the feature: is it enabled or disabled.
148 class ModelAPI_FeatureStateMessage : public Events_Message
149 {
150 public:
151   /// Creates an empty message
152   MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
153   /// The virtual destructor
154   MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
155
156   /// Returns the feature this message is related to
157   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
158   /// Stores the feature this message is related to
159   MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
160   // For response
161   /// Returns true if feature has specific state
162   MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
163   /// Returns true if feature is enabled
164   MODELAPI_EXPORT bool state(const  std::string& theFeatureId, bool theDefault = false) const;
165   /// Stores the feature state
166   MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
167   /// Returns all feature IDs with states
168   MODELAPI_EXPORT std::list<std::string> features() const;
169
170  private:
171   /// For Request
172   std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
173   /// For response
174   std::map<std::string, bool> myFeatureState;
175 };
176
177 /// Message that document (Part, PartSet) was created
178 class ModelAPI_DocumentCreatedMessage : public Events_Message
179 {
180   DocumentPtr myDocument;
181
182  public:
183   /// Creates an empty message
184   MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
185   /// The virtual destructor
186   MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
187   /// Static. Returns EventID of the message.
188   MODELAPI_EXPORT static Events_ID eventId()
189   {
190     static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
191     return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
192   }
193
194   /// Returns a document stored in the message
195   MODELAPI_EXPORT DocumentPtr document() const;
196   /// Sets a document to the message
197   MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
198 };
199
200 /// Message that attribute text should be evaluated in the attribute value
201 class ModelAPI_AttributeEvalMessage : public Events_Message
202 {
203   AttributePtr myAttribute;
204
205  public:
206   /// Static. Returns EventID of the message.
207   MODELAPI_EXPORT static Events_ID& eventId()
208   {
209     static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
210     static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
211     return anId;
212   }
213
214   /// Useful method that creates and sends the AttributeEvalMessage event
215   MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
216   {
217     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
218       std::shared_ptr<ModelAPI_AttributeEvalMessage>(
219       new ModelAPI_AttributeEvalMessage(eventId(), theSender));
220     aMessage->setAttribute(theAttribute);
221     Events_Loop::loop()->send(aMessage);
222   }
223
224   /// Creates an empty message
225   MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
226   /// The virtual destructor
227   MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
228
229   /// Returns a document stored in the message
230   MODELAPI_EXPORT AttributePtr attribute() const;
231   /// Sets an attribute to the message
232   MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
233 };
234
235 /// Message that the object is renamed
236 class ModelAPI_ObjectRenamedMessage : public Events_Message
237 {
238   ObjectPtr myObject;
239   std::string myOldName;
240   std::string myNewName;
241
242  public:
243   /// Static. Returns EventID of the message.
244   MODELAPI_EXPORT static Events_ID& eventId()
245   {
246     static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
247     static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
248     return anId;
249   }
250
251   /// Useful method that creates and sends the AttributeEvalMessage event
252   MODELAPI_EXPORT static void send(ObjectPtr theObject,
253                                    const std::string& theOldName,
254                                    const std::string& theNewName,
255                                    const void* theSender);
256
257   /// Creates an empty message
258   MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
259   /// The virtual destructor
260   MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
261
262   /// Returns an object
263   MODELAPI_EXPORT ObjectPtr object() const;
264   /// Sets an object
265   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
266   /// Returns an old name
267   MODELAPI_EXPORT std::string oldName() const;
268   /// Sets an old name
269   MODELAPI_EXPORT void setOldName(const std::string& theOldName);
270   /// Returns a new name
271   MODELAPI_EXPORT std::string newName() const;
272   /// Sets a new name
273   MODELAPI_EXPORT void setNewName(const std::string& theNewName);
274 };
275
276 #endif