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 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
54 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
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";
59 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
60 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
63 /// Creates an empty message
64 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
65 /// The virtual destructor
66 virtual ~ModelAPI_ObjectUpdatedMessage();
69 /// Returns the feature that has been updated
70 virtual const std::set<ObjectPtr>& objects() const = 0;
72 //! Creates a new empty group (to store it in the loop before flush)
73 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
75 //! Allows to join the given message with the current one
76 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
79 /// Message that feature was deleted (used for Object Browser update)
80 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
83 /// Creates an empty message
84 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
85 /// The virtual destructor
86 virtual ~ModelAPI_ObjectDeletedMessage();
89 /// Returns the document that has been updated
90 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
92 /// Returns the groups where the objects were deleted
93 virtual const std::set<std::string>& groups() const = 0;
95 /// Creates the new empty message of this kind
96 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
98 /// Returns the identifier of the kind of a message
99 virtual const Events_ID messageId() = 0;
101 /// Appenad to this message the given one.
102 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
105 /// Message that order changed (used for Object Browser update)
106 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
109 /// Creates an empty message
110 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
111 /// The virtual destructor
112 virtual ~ModelAPI_OrderUpdatedMessage();
115 /// Returns the document that has been updated
116 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
118 /// Returns the groups where the objects were reordered
119 virtual const std::string& group() const = 0;
121 /// Returns the identifier of the kind of a message
122 virtual const Events_ID messageId() = 0;
125 /// Allows to create ModelAPI messages
126 class MODELAPI_EXPORT ModelAPI_EventCreator
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;
139 /// returns the creator instance
140 static const ModelAPI_EventCreator* get();
142 /// sets the creator instance
143 static void set(const ModelAPI_EventCreator* theCreator);
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
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();
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);
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;
172 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
174 std::map<std::string, bool> myFeatureState;
177 /// Message that document (Part, PartSet) was created
178 class ModelAPI_DocumentCreatedMessage : public Events_Message
180 DocumentPtr myDocument;
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()
190 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
191 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
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);
200 /// Message that attribute text should be evaluated in the attribute value
201 class ModelAPI_AttributeEvalMessage : public Events_Message
203 AttributePtr myAttribute;
206 /// Static. Returns EventID of the message.
207 MODELAPI_EXPORT static Events_ID& eventId()
209 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
210 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
214 /// Useful method that creates and sends the AttributeEvalMessage event
215 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
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);
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();
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);
235 /// Message that the object is renamed
236 class ModelAPI_ObjectRenamedMessage : public Events_Message
239 std::string myOldName;
240 std::string myNewName;
243 /// Static. Returns EventID of the message.
244 MODELAPI_EXPORT static Events_ID& eventId()
246 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
247 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
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);
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();
262 /// Returns an object
263 MODELAPI_EXPORT ObjectPtr object() const;
265 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
266 /// Returns an old name
267 MODELAPI_EXPORT std::string oldName() const;
269 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
270 /// Returns a new name
271 MODELAPI_EXPORT std::string newName() const;
273 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
276 /// Message that the parameter should be replaced with its value
277 class ModelAPI_ReplaceParameterMessage : public Events_Message
282 /// Static. Returns EventID of the message.
283 MODELAPI_EXPORT static Events_ID& eventId()
285 static const char * MY_EVENT_ID("ReplaceParameter");
286 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
290 /// Useful method that creates and sends the AttributeEvalMessage event
291 MODELAPI_EXPORT static void send(ObjectPtr theObject,
292 const void* theSender);
294 /// Creates an empty message
295 MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
296 /// The virtual destructor
297 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
299 /// Returns an object
300 MODELAPI_EXPORT ObjectPtr object() const;
302 MODELAPI_EXPORT void setObject(ObjectPtr theObject);