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,
43 /// so, tree must be fully rectreated (movement of feature)
44 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
45 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
46 static const char * EVENT_UPDATE_SELECTION = "UpdateSelection";
48 /// Request for the enabled/disabled actions behavior for some specific features
49 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
50 /// Reply for the enabled/disabled actions behavior for some specific features
51 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
53 /// To block the viewer updates
54 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
55 /// To unblock the viewer updates
56 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
58 /// To inform that there is an empty presentation in the viewer
59 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
60 /// To inform that there is an empty operation for presentation in the viewer
61 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
63 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
64 /// To preview the current feature in the viewer (to compute the result)
65 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
67 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
68 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
69 /// Event ID that the problem in solver disappeared
70 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
72 /// Event ID that informs that some object has changed the stability
73 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
75 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
76 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
78 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
79 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
82 /// Creates an empty message
83 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
84 /// The virtual destructor
85 virtual ~ModelAPI_ObjectUpdatedMessage();
88 /// Returns the feature that has been updated
89 virtual const std::set<ObjectPtr>& objects() const = 0;
91 //! Creates a new empty group (to store it in the loop before flush)
92 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
94 //! Allows to join the given message with the current one
95 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
98 /// Message that feature was deleted (used for Object Browser update)
99 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
102 /// Creates an empty message
103 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
104 /// The virtual destructor
105 virtual ~ModelAPI_ObjectDeletedMessage();
108 /// Returns the document that has been updated
109 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
111 /// Returns the groups where the objects were deleted
112 virtual const std::set<std::string>& groups() const = 0;
114 /// Creates the new empty message of this kind
115 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
117 /// Returns the identifier of the kind of a message
118 virtual const Events_ID messageId() = 0;
120 /// Appenad to this message the given one.
121 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
124 /// Message that order changed (used for Object Browser update)
125 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
128 /// Creates a message:
129 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
130 /// The virtual destructor
131 virtual ~ModelAPI_OrderUpdatedMessage();
134 /// Returns the document that has been updated
135 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
137 /// Returns the identifier of the kind of a message
138 virtual const Events_ID messageId() = 0;
141 /// Allows to create ModelAPI messages
142 class MODELAPI_EXPORT ModelAPI_EventCreator
145 /// creates created, updated or moved messages and sends to the loop
146 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
147 const bool isGroupped = true) const = 0;
148 /// creates deleted message and sends to the loop
149 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
150 const std::string& theGroup) const = 0;
151 /// creates reordered message and sends to the loop
152 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
154 /// returns the creator instance
155 static const ModelAPI_EventCreator* get();
157 /// sets the creator instance
158 static void set(const ModelAPI_EventCreator* theCreator);
161 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
162 /// Contains the state information about the feature: is it enabled or disabled.
163 class ModelAPI_FeatureStateMessage : public Events_Message
166 /// Creates an empty message
167 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
168 /// The virtual destructor
169 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
171 /// Returns the feature this message is related to
172 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
173 /// Stores the feature this message is related to
174 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
176 /// Returns true if feature has specific state
177 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
178 /// Returns true if feature is enabled
179 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
180 /// Stores the feature state
181 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
182 /// Returns all feature IDs with states
183 MODELAPI_EXPORT std::list<std::string> features() const;
187 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
189 std::map<std::string, bool> myFeatureState;
192 /// Message that document (Part, PartSet) was created
193 class ModelAPI_DocumentCreatedMessage : public Events_Message
195 DocumentPtr myDocument;
198 /// Creates an empty message
199 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
200 /// The virtual destructor
201 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
202 /// Static. Returns EventID of the message.
203 MODELAPI_EXPORT static Events_ID eventId()
205 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
206 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
209 /// Returns a document stored in the message
210 MODELAPI_EXPORT DocumentPtr document() const;
211 /// Sets a document to the message
212 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
215 /// Message that attribute text should be evaluated in the attribute value
216 class ModelAPI_AttributeEvalMessage : public Events_Message
218 AttributePtr myAttribute;
221 /// Static. Returns EventID of the message.
222 MODELAPI_EXPORT static Events_ID& eventId()
224 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
225 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
229 /// Useful method that creates and sends the AttributeEvalMessage event
230 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
232 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
233 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
234 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
235 aMessage->setAttribute(theAttribute);
236 Events_Loop::loop()->send(aMessage);
239 /// Creates an empty message
240 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
241 /// The virtual destructor
242 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
244 /// Returns a document stored in the message
245 MODELAPI_EXPORT AttributePtr attribute() const;
246 /// Sets an attribute to the message
247 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
250 /// Message that the object is renamed
251 class ModelAPI_ObjectRenamedMessage : public Events_Message
254 std::string myOldName;
255 std::string myNewName;
258 /// Static. Returns EventID of the message.
259 MODELAPI_EXPORT static Events_ID& eventId()
261 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
262 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
266 /// Useful method that creates and sends the AttributeEvalMessage event
267 MODELAPI_EXPORT static void send(ObjectPtr theObject,
268 const std::string& theOldName,
269 const std::string& theNewName,
270 const void* theSender);
272 /// Creates an empty message
273 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
274 /// The virtual destructor
275 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
277 /// Returns an object
278 MODELAPI_EXPORT ObjectPtr object() const;
280 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
281 /// Returns an old name
282 MODELAPI_EXPORT std::string oldName() const;
284 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
285 /// Returns a new name
286 MODELAPI_EXPORT std::string newName() const;
288 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
291 /// Message that the parameter should be replaced with its value
292 class ModelAPI_ReplaceParameterMessage : public Events_Message
297 /// Static. Returns EventID of the message.
298 MODELAPI_EXPORT static Events_ID& eventId()
300 static const char * MY_EVENT_ID("ReplaceParameter");
301 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
305 /// Useful method that creates and sends the AttributeEvalMessage event
306 MODELAPI_EXPORT static void send(ObjectPtr theObject,
307 const void* theSender);
309 /// Creates an empty message
311 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
312 /// The virtual destructor
313 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
315 /// Returns an object
316 MODELAPI_EXPORT ObjectPtr object() const;
318 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
321 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
322 class ModelAPI_SolverFailedMessage : public Events_Message
325 /// Creates an message
326 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
327 /// Default destructor
328 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
330 /// Sets list of conflicting constraints
331 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
332 /// Returns list of conflicting constraints
333 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
335 /// Sets degrees of freedom
336 void dof(const int theDOF) { myDOF = theDOF; }
337 /// Returns degrees of freedom
338 const int& dof() const { return myDOF; }
341 std::set<ObjectPtr> myObjects;