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 plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
38 static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
40 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
42 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
43 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
46 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
47 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
49 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
50 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
52 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
53 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
55 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
56 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
57 /// Event ID that the problem in solver disappeared
58 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
60 /// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
61 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
63 /// Event ID that informs that some object has changed the stability
64 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
66 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
67 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
70 /// Creates an empty message
71 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
72 /// The virtual destructor
73 virtual ~ModelAPI_ObjectUpdatedMessage();
76 /// Returns the feature that has been updated
77 virtual const std::set<ObjectPtr>& objects() const = 0;
79 //! Creates a new empty group (to store it in the loop before flush)
80 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
82 //! Allows to join the given message with the current one
83 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
86 /// Message that feature was deleted (used for Object Browser update)
87 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
90 /// Creates an empty message
91 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
92 /// The virtual destructor
93 virtual ~ModelAPI_ObjectDeletedMessage();
96 /// Returns the document that has been updated
97 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
99 /// Returns the groups where the objects were deleted
100 virtual const std::set<std::string>& groups() const = 0;
102 /// Creates the new empty message of this kind
103 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
105 /// Returns the identifier of the kind of a message
106 virtual const Events_ID messageId() = 0;
108 /// Appenad to this message the given one.
109 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
112 /// Message that order changed (used for Object Browser update)
113 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
116 /// Creates a message:
117 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
118 /// The virtual destructor
119 virtual ~ModelAPI_OrderUpdatedMessage();
122 /// Returns the document that has been updated
123 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
125 /// Returns the identifier of the kind of a message
126 virtual const Events_ID messageId() = 0;
129 /// Allows to create ModelAPI messages
130 class MODELAPI_EXPORT ModelAPI_EventCreator
133 /// creates created, updated or moved messages and sends to the loop
134 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
135 const bool isGroupped = true) const = 0;
136 /// creates deleted message and sends to the loop
137 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
138 const std::string& theGroup) const = 0;
139 /// creates reordered message and sends to the loop
140 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
142 /// returns the creator instance
143 static const ModelAPI_EventCreator* get();
145 /// sets the creator instance
146 static void set(const ModelAPI_EventCreator* theCreator);
149 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
150 /// Contains the state information about the feature: is it enabled or disabled.
151 class ModelAPI_FeatureStateMessage : public Events_Message
154 /// Creates an empty message
155 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
156 /// The virtual destructor
157 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
159 /// Returns the feature this message is related to
160 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
161 /// Stores the feature this message is related to
162 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
164 /// Returns true if feature has specific state
165 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
166 /// Returns true if feature is enabled
167 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
168 /// Stores the feature state
169 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
170 /// Returns all feature IDs with states
171 MODELAPI_EXPORT std::list<std::string> features() const;
175 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
177 std::map<std::string, bool> myFeatureState;
180 /// Message that document (Part, PartSet) was created
181 class ModelAPI_DocumentCreatedMessage : public Events_Message
183 DocumentPtr myDocument;
186 /// Creates an empty message
187 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
188 /// The virtual destructor
189 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
190 /// Static. Returns EventID of the message.
191 MODELAPI_EXPORT static Events_ID eventId()
193 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
194 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
197 /// Returns a document stored in the message
198 MODELAPI_EXPORT DocumentPtr document() const;
199 /// Sets a document to the message
200 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
203 /// Message that attribute text should be evaluated in the attribute value
204 class ModelAPI_AttributeEvalMessage : public Events_Message
206 AttributePtr myAttribute;
209 /// Static. Returns EventID of the message.
210 MODELAPI_EXPORT static Events_ID& eventId()
212 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
213 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
217 /// Useful method that creates and sends the AttributeEvalMessage event
218 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
220 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
221 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
222 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
223 aMessage->setAttribute(theAttribute);
224 Events_Loop::loop()->send(aMessage);
227 /// Creates an empty message
228 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
229 /// The virtual destructor
230 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
232 /// Returns a document stored in the message
233 MODELAPI_EXPORT AttributePtr attribute() const;
234 /// Sets an attribute to the message
235 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
238 /// Message that the object is renamed
239 class ModelAPI_ObjectRenamedMessage : public Events_Message
242 std::string myOldName;
243 std::string myNewName;
246 /// Static. Returns EventID of the message.
247 MODELAPI_EXPORT static Events_ID& eventId()
249 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
250 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
254 /// Useful method that creates and sends the AttributeEvalMessage event
255 MODELAPI_EXPORT static void send(ObjectPtr theObject,
256 const std::string& theOldName,
257 const std::string& theNewName,
258 const void* theSender);
260 /// Creates an empty message
261 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
262 /// The virtual destructor
263 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
265 /// Returns an object
266 MODELAPI_EXPORT ObjectPtr object() const;
268 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
269 /// Returns an old name
270 MODELAPI_EXPORT std::string oldName() const;
272 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
273 /// Returns a new name
274 MODELAPI_EXPORT std::string newName() const;
276 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
279 /// Message that the parameter should be replaced with its value
280 class ModelAPI_ReplaceParameterMessage : public Events_Message
285 /// Static. Returns EventID of the message.
286 MODELAPI_EXPORT static Events_ID& eventId()
288 static const char * MY_EVENT_ID("ReplaceParameter");
289 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
293 /// Useful method that creates and sends the AttributeEvalMessage event
294 MODELAPI_EXPORT static void send(ObjectPtr theObject,
295 const void* theSender);
297 /// Creates an empty message
298 MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
299 /// The virtual destructor
300 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
302 /// Returns an object
303 MODELAPI_EXPORT ObjectPtr object() const;
305 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
308 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
309 class ModelAPI_SolverFailedMessage : public Events_Message
312 /// Creates an message
313 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
314 /// Default destructor
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;
322 /// Sets degrees of freedom
323 void dof(const int theDOF) { myDOF = theDOF; }
324 /// Returns degrees of freedom
325 const int& dof() const { return myDOF; }
328 std::set<ObjectPtr> myObjects;