1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Events.h
4 // Created: 10 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef MODELAPI_EVENTS_H_
8 #define MODELAPI_EVENTS_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>
23 class ModelAPI_Document;
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";
44 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
46 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
47 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
50 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
51 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
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";
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";
61 /// Event ID that informs that some object has changed the stability
62 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
64 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
65 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
68 /// Creates an empty message
69 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
70 /// The virtual destructor
71 virtual ~ModelAPI_ObjectUpdatedMessage();
74 /// Returns the feature that has been updated
75 virtual const std::set<ObjectPtr>& objects() const = 0;
77 //! Creates a new empty group (to store it in the loop before flush)
78 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
80 //! Allows to join the given message with the current one
81 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
84 /// Message that feature was deleted (used for Object Browser update)
85 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
88 /// Creates an empty message
89 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
90 /// The virtual destructor
91 virtual ~ModelAPI_ObjectDeletedMessage();
94 /// Returns the document that has been updated
95 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
97 /// Returns the groups where the objects were deleted
98 virtual const std::set<std::string>& groups() const = 0;
100 /// Creates the new empty message of this kind
101 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
103 /// Returns the identifier of the kind of a message
104 virtual const Events_ID messageId() = 0;
106 /// Appenad to this message the given one.
107 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
110 /// Message that order changed (used for Object Browser update)
111 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
114 /// Creates an empty message
115 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
116 /// The virtual destructor
117 virtual ~ModelAPI_OrderUpdatedMessage();
120 /// Returns the document that has been updated
121 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
123 /// Returns the groups where the objects were reordered
124 virtual const std::string& group() const = 0;
126 /// Returns the identifier of the kind of a message
127 virtual const Events_ID messageId() = 0;
130 /// Allows to create ModelAPI messages
131 class MODELAPI_EXPORT ModelAPI_EventCreator
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;
144 /// returns the creator instance
145 static const ModelAPI_EventCreator* get();
147 /// sets the creator instance
148 static void set(const ModelAPI_EventCreator* theCreator);
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
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();
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);
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;
177 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
179 std::map<std::string, bool> myFeatureState;
182 /// Message that document (Part, PartSet) was created
183 class ModelAPI_DocumentCreatedMessage : public Events_Message
185 DocumentPtr myDocument;
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()
195 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
196 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
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);
205 /// Message that attribute text should be evaluated in the attribute value
206 class ModelAPI_AttributeEvalMessage : public Events_Message
208 AttributePtr myAttribute;
211 /// Static. Returns EventID of the message.
212 MODELAPI_EXPORT static Events_ID& eventId()
214 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
215 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
219 /// Useful method that creates and sends the AttributeEvalMessage event
220 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
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);
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();
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);
240 /// Message that the object is renamed
241 class ModelAPI_ObjectRenamedMessage : public Events_Message
244 std::string myOldName;
245 std::string myNewName;
248 /// Static. Returns EventID of the message.
249 MODELAPI_EXPORT static Events_ID& eventId()
251 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
252 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
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);
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();
267 /// Returns an object
268 MODELAPI_EXPORT ObjectPtr object() const;
270 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
271 /// Returns an old name
272 MODELAPI_EXPORT std::string oldName() const;
274 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
275 /// Returns a new name
276 MODELAPI_EXPORT std::string newName() const;
278 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
281 /// Message that the parameter should be replaced with its value
282 class ModelAPI_ReplaceParameterMessage : public Events_Message
287 /// Static. Returns EventID of the message.
288 MODELAPI_EXPORT static Events_ID& eventId()
290 static const char * MY_EVENT_ID("ReplaceParameter");
291 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
295 /// Useful method that creates and sends the AttributeEvalMessage event
296 MODELAPI_EXPORT static void send(ObjectPtr theObject,
297 const void* theSender);
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();
304 /// Returns an object
305 MODELAPI_EXPORT ObjectPtr object() const;
307 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
311 class ModelAPI_SolverFailedMessage : public Events_Message
314 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
315 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
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;
323 std::set<ObjectPtr> myObjects;