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";
39 /// The active document becomes another one
40 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
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";
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";
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";
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";
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";
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";
71 /// Event ID that informs that some object has changed the stability
72 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
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";
77 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
78 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
81 /// Creates an empty message
82 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
83 /// The virtual destructor
84 virtual ~ModelAPI_ObjectUpdatedMessage();
87 /// Returns the feature that has been updated
88 virtual const std::set<ObjectPtr>& objects() const = 0;
90 //! Creates a new empty group (to store it in the loop before flush)
91 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
93 //! Allows to join the given message with the current one
94 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
97 /// Message that feature was deleted (used for Object Browser update)
98 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
101 /// Creates an empty message
102 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
103 /// The virtual destructor
104 virtual ~ModelAPI_ObjectDeletedMessage();
107 /// Returns the document that has been updated
108 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
110 /// Returns the groups where the objects were deleted
111 virtual const std::set<std::string>& groups() const = 0;
113 /// Creates the new empty message of this kind
114 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
116 /// Returns the identifier of the kind of a message
117 virtual const Events_ID messageId() = 0;
119 /// Appenad to this message the given one.
120 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
123 /// Message that order changed (used for Object Browser update)
124 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
127 /// Creates a message:
128 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
129 /// The virtual destructor
130 virtual ~ModelAPI_OrderUpdatedMessage();
133 /// Returns the document that has been updated
134 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
136 /// Returns the identifier of the kind of a message
137 virtual const Events_ID messageId() = 0;
140 /// Allows to create ModelAPI messages
141 class MODELAPI_EXPORT ModelAPI_EventCreator
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;
153 /// returns the creator instance
154 static const ModelAPI_EventCreator* get();
156 /// sets the creator instance
157 static void set(const ModelAPI_EventCreator* theCreator);
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
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();
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);
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;
186 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
188 std::map<std::string, bool> myFeatureState;
191 /// Message that document (Part, PartSet) was created
192 class ModelAPI_DocumentCreatedMessage : public Events_Message
194 DocumentPtr myDocument;
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()
204 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
205 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
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);
214 /// Message that attribute text should be evaluated in the attribute value
215 class ModelAPI_AttributeEvalMessage : public Events_Message
217 AttributePtr myAttribute;
220 /// Static. Returns EventID of the message.
221 MODELAPI_EXPORT static Events_ID& eventId()
223 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
224 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
228 /// Useful method that creates and sends the AttributeEvalMessage event
229 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
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);
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();
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);
249 /// Message that the object is renamed
250 class ModelAPI_ObjectRenamedMessage : public Events_Message
253 std::string myOldName;
254 std::string myNewName;
257 /// Static. Returns EventID of the message.
258 MODELAPI_EXPORT static Events_ID& eventId()
260 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
261 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
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);
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();
276 /// Returns an object
277 MODELAPI_EXPORT ObjectPtr object() const;
279 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
280 /// Returns an old name
281 MODELAPI_EXPORT std::string oldName() const;
283 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
284 /// Returns a new name
285 MODELAPI_EXPORT std::string newName() const;
287 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
290 /// Message that the parameter should be replaced with its value
291 class ModelAPI_ReplaceParameterMessage : public Events_Message
296 /// Static. Returns EventID of the message.
297 MODELAPI_EXPORT static Events_ID& eventId()
299 static const char * MY_EVENT_ID("ReplaceParameter");
300 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
304 /// Useful method that creates and sends the AttributeEvalMessage event
305 MODELAPI_EXPORT static void send(ObjectPtr theObject,
306 const void* theSender);
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();
313 /// Returns an object
314 MODELAPI_EXPORT ObjectPtr object() const;
316 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
319 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
320 class ModelAPI_SolverFailedMessage : public Events_Message
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();
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;
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; }
339 std::set<ObjectPtr> myObjects;