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 visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
38 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
39 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
40 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
42 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
44 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
45 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
48 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
49 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
51 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
52 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
54 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
55 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
57 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
58 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
59 /// Event ID that the problem in solver disappeared
60 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
62 /// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
63 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
65 /// Event ID that informs that some object has changed the stability
66 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
68 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
69 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
72 /// Creates an empty message
73 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
74 /// The virtual destructor
75 virtual ~ModelAPI_ObjectUpdatedMessage();
78 /// Returns the feature that has been updated
79 virtual const std::set<ObjectPtr>& objects() const = 0;
81 //! Creates a new empty group (to store it in the loop before flush)
82 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
84 //! Allows to join the given message with the current one
85 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
88 /// Message that feature was deleted (used for Object Browser update)
89 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
92 /// Creates an empty message
93 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
94 /// The virtual destructor
95 virtual ~ModelAPI_ObjectDeletedMessage();
98 /// Returns the document that has been updated
99 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
101 /// Returns the groups where the objects were deleted
102 virtual const std::set<std::string>& groups() const = 0;
104 /// Creates the new empty message of this kind
105 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
107 /// Returns the identifier of the kind of a message
108 virtual const Events_ID messageId() = 0;
110 /// Appenad to this message the given one.
111 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
114 /// Message that order changed (used for Object Browser update)
115 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
118 /// Creates an empty message
119 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
120 /// The virtual destructor
121 virtual ~ModelAPI_OrderUpdatedMessage();
124 /// Returns the document that has been updated
125 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
127 /// Returns the groups where the objects were reordered
128 virtual const std::string& group() const = 0;
130 /// Returns the identifier of the kind of a message
131 virtual const Events_ID messageId() = 0;
134 /// Allows to create ModelAPI messages
135 class MODELAPI_EXPORT ModelAPI_EventCreator
138 /// creates created, updated or moved messages and sends to the loop
139 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
140 const bool isGroupped = true) const = 0;
141 /// creates deleted message and sends to the loop
142 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
143 const std::string& theGroup) const = 0;
144 /// creates reordered message and sends to the loop
145 virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
146 const std::string& theGroup) const = 0;
148 /// returns the creator instance
149 static const ModelAPI_EventCreator* get();
151 /// sets the creator instance
152 static void set(const ModelAPI_EventCreator* theCreator);
155 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
156 /// Contains the state information about the feature: is it enabled or disabled.
157 class ModelAPI_FeatureStateMessage : public Events_Message
160 /// Creates an empty message
161 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
162 /// The virtual destructor
163 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
165 /// Returns the feature this message is related to
166 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
167 /// Stores the feature this message is related to
168 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
170 /// Returns true if feature has specific state
171 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
172 /// Returns true if feature is enabled
173 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
174 /// Stores the feature state
175 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
176 /// Returns all feature IDs with states
177 MODELAPI_EXPORT std::list<std::string> features() const;
181 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
183 std::map<std::string, bool> myFeatureState;
186 /// Message that document (Part, PartSet) was created
187 class ModelAPI_DocumentCreatedMessage : public Events_Message
189 DocumentPtr myDocument;
192 /// Creates an empty message
193 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
194 /// The virtual destructor
195 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
196 /// Static. Returns EventID of the message.
197 MODELAPI_EXPORT static Events_ID eventId()
199 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
200 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
203 /// Returns a document stored in the message
204 MODELAPI_EXPORT DocumentPtr document() const;
205 /// Sets a document to the message
206 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
209 /// Message that attribute text should be evaluated in the attribute value
210 class ModelAPI_AttributeEvalMessage : public Events_Message
212 AttributePtr myAttribute;
215 /// Static. Returns EventID of the message.
216 MODELAPI_EXPORT static Events_ID& eventId()
218 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
219 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
223 /// Useful method that creates and sends the AttributeEvalMessage event
224 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
226 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
227 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
228 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
229 aMessage->setAttribute(theAttribute);
230 Events_Loop::loop()->send(aMessage);
233 /// Creates an empty message
234 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
235 /// The virtual destructor
236 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
238 /// Returns a document stored in the message
239 MODELAPI_EXPORT AttributePtr attribute() const;
240 /// Sets an attribute to the message
241 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
244 /// Message that the object is renamed
245 class ModelAPI_ObjectRenamedMessage : public Events_Message
248 std::string myOldName;
249 std::string myNewName;
252 /// Static. Returns EventID of the message.
253 MODELAPI_EXPORT static Events_ID& eventId()
255 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
256 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
260 /// Useful method that creates and sends the AttributeEvalMessage event
261 MODELAPI_EXPORT static void send(ObjectPtr theObject,
262 const std::string& theOldName,
263 const std::string& theNewName,
264 const void* theSender);
266 /// Creates an empty message
267 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
268 /// The virtual destructor
269 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
271 /// Returns an object
272 MODELAPI_EXPORT ObjectPtr object() const;
274 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
275 /// Returns an old name
276 MODELAPI_EXPORT std::string oldName() const;
278 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
279 /// Returns a new name
280 MODELAPI_EXPORT std::string newName() const;
282 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
285 /// Message that the parameter should be replaced with its value
286 class ModelAPI_ReplaceParameterMessage : public Events_Message
291 /// Static. Returns EventID of the message.
292 MODELAPI_EXPORT static Events_ID& eventId()
294 static const char * MY_EVENT_ID("ReplaceParameter");
295 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
299 /// Useful method that creates and sends the AttributeEvalMessage event
300 MODELAPI_EXPORT static void send(ObjectPtr theObject,
301 const void* theSender);
303 /// Creates an empty message
304 MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
305 /// The virtual destructor
306 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
308 /// Returns an object
309 MODELAPI_EXPORT ObjectPtr object() const;
311 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
314 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
315 class ModelAPI_SolverFailedMessage : public Events_Message
318 /// Creates an message
319 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
320 /// Default destructor
321 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
323 /// Sets list of conflicting constraints
324 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
325 /// Returns list of conflicting constraints
326 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
328 /// Sets degrees of freedom
329 void dof(const int theDOF) { myDOF = theDOF; }
330 /// Returns degrees of freedom
331 const int& dof() const { return myDOF; }
334 std::set<ObjectPtr> myObjects;