Salome HOME
#1330 Multiply selection when Create fillet using Shift button
[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 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
54 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
55 /// Event ID that the problem in solver disappeared
56 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
57
58 /// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
59 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
60
61 /// Event ID that informs that some object has changed the stability
62 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
63
64 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
65 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
66 {
67  protected:
68   /// Creates an empty message
69   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
70   /// The virtual destructor
71   virtual ~ModelAPI_ObjectUpdatedMessage();
72
73  public:
74   /// Returns the feature that has been updated
75   virtual const std::set<ObjectPtr>& objects() const = 0;
76
77   //! Creates a new empty group (to store it in the loop before flush)
78   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
79
80   //! Allows to join the given message with the current one
81   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
82 };
83
84 /// Message that feature was deleted (used for Object Browser update)
85 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
86 {
87 protected:
88   /// Creates an empty message
89   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
90   /// The virtual destructor
91   virtual ~ModelAPI_ObjectDeletedMessage();
92
93 public:
94   /// Returns the document that has been updated
95   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
96
97   /// Returns the groups where the objects were deleted
98   virtual const std::set<std::string>& groups() const = 0;
99
100   /// Creates the new empty message of this kind
101   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
102
103   /// Returns the identifier of the kind of a message
104   virtual const Events_ID messageId() = 0;
105
106   /// Appenad to this message the given one.
107   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
108 };
109
110 /// Message that order changed (used for Object Browser update)
111 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
112 {
113 protected:
114   /// Creates an empty message
115   ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
116   /// The virtual destructor
117   virtual ~ModelAPI_OrderUpdatedMessage();
118
119 public:
120   /// Returns the document that has been updated
121   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
122
123   /// Returns the groups where the objects were reordered
124   virtual const std::string& group() const = 0;
125
126   /// Returns the identifier of the kind of a message
127   virtual const Events_ID messageId() = 0;
128 };
129
130 /// Allows to create ModelAPI messages
131 class MODELAPI_EXPORT ModelAPI_EventCreator
132 {
133 public:
134   /// creates created, updated or moved messages and sends to the loop
135   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
136                            const bool isGroupped = true) const = 0;
137   /// creates deleted message and sends to the loop
138   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
139                            const std::string& theGroup) const = 0;
140   /// creates reordered message and sends to the loop
141   virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
142                              const std::string& theGroup) const = 0;
143
144   /// returns the creator instance
145   static const ModelAPI_EventCreator* get();
146
147   /// sets the creator instance
148   static void set(const ModelAPI_EventCreator* theCreator);
149 };
150
151 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
152 /// Contains the state information about the feature: is it enabled or disabled.
153 class ModelAPI_FeatureStateMessage : public Events_Message
154 {
155 public:
156   /// Creates an empty message
157   MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
158   /// The virtual destructor
159   MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
160
161   /// Returns the feature this message is related to
162   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
163   /// Stores the feature this message is related to
164   MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
165   // For response
166   /// Returns true if feature has specific state
167   MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
168   /// Returns true if feature is enabled
169   MODELAPI_EXPORT bool state(const  std::string& theFeatureId, bool theDefault = false) const;
170   /// Stores the feature state
171   MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
172   /// Returns all feature IDs with states
173   MODELAPI_EXPORT std::list<std::string> features() const;
174
175  private:
176   /// For Request
177   std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
178   /// For response
179   std::map<std::string, bool> myFeatureState;
180 };
181
182 /// Message that document (Part, PartSet) was created
183 class ModelAPI_DocumentCreatedMessage : public Events_Message
184 {
185   DocumentPtr myDocument;
186
187  public:
188   /// Creates an empty message
189   MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
190   /// The virtual destructor
191   MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
192   /// Static. Returns EventID of the message.
193   MODELAPI_EXPORT static Events_ID eventId()
194   {
195     static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
196     return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
197   }
198
199   /// Returns a document stored in the message
200   MODELAPI_EXPORT DocumentPtr document() const;
201   /// Sets a document to the message
202   MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
203 };
204
205 /// Message that attribute text should be evaluated in the attribute value
206 class ModelAPI_AttributeEvalMessage : public Events_Message
207 {
208   AttributePtr myAttribute;
209
210  public:
211   /// Static. Returns EventID of the message.
212   MODELAPI_EXPORT static Events_ID& eventId()
213   {
214     static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
215     static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
216     return anId;
217   }
218
219   /// Useful method that creates and sends the AttributeEvalMessage event
220   MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
221   {
222     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
223       std::shared_ptr<ModelAPI_AttributeEvalMessage>(
224       new ModelAPI_AttributeEvalMessage(eventId(), theSender));
225     aMessage->setAttribute(theAttribute);
226     Events_Loop::loop()->send(aMessage);
227   }
228
229   /// Creates an empty message
230   MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
231   /// The virtual destructor
232   MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
233
234   /// Returns a document stored in the message
235   MODELAPI_EXPORT AttributePtr attribute() const;
236   /// Sets an attribute to the message
237   MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
238 };
239
240 /// Message that the object is renamed
241 class ModelAPI_ObjectRenamedMessage : public Events_Message
242 {
243   ObjectPtr myObject;
244   std::string myOldName;
245   std::string myNewName;
246
247  public:
248   /// Static. Returns EventID of the message.
249   MODELAPI_EXPORT static Events_ID& eventId()
250   {
251     static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
252     static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
253     return anId;
254   }
255
256   /// Useful method that creates and sends the AttributeEvalMessage event
257   MODELAPI_EXPORT static void send(ObjectPtr theObject,
258                                    const std::string& theOldName,
259                                    const std::string& theNewName,
260                                    const void* theSender);
261
262   /// Creates an empty message
263   MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
264   /// The virtual destructor
265   MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
266
267   /// Returns an object
268   MODELAPI_EXPORT ObjectPtr object() const;
269   /// Sets an object
270   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
271   /// Returns an old name
272   MODELAPI_EXPORT std::string oldName() const;
273   /// Sets an old name
274   MODELAPI_EXPORT void setOldName(const std::string& theOldName);
275   /// Returns a new name
276   MODELAPI_EXPORT std::string newName() const;
277   /// Sets a new name
278   MODELAPI_EXPORT void setNewName(const std::string& theNewName);
279 };
280
281 /// Message that the parameter should be replaced with its value
282 class ModelAPI_ReplaceParameterMessage : public Events_Message
283 {
284   ObjectPtr myObject;
285
286  public:
287   /// Static. Returns EventID of the message.
288   MODELAPI_EXPORT static Events_ID& eventId()
289   {
290     static const char * MY_EVENT_ID("ReplaceParameter");
291     static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
292     return anId;
293   }
294
295   /// Useful method that creates and sends the AttributeEvalMessage event
296   MODELAPI_EXPORT static void send(ObjectPtr theObject,
297                                    const void* theSender);
298
299   /// Creates an empty message
300   MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
301   /// The virtual destructor
302   MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
303
304   /// Returns an object
305   MODELAPI_EXPORT ObjectPtr object() const;
306   /// Sets an object
307   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
308 };
309
310
311 class ModelAPI_SolverFailedMessage : public Events_Message
312 {
313 public:
314   MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
315   MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
316
317   /// Sets list of conflicting constraints
318   MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
319   /// Returns list of conflicting constraints
320   MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
321
322 private:
323   std::set<ObjectPtr> myObjects;
324 };
325
326 #endif