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