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;
24 class ModelAPI_ResultParameter;
26 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
27 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
28 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
29 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
30 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
31 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
32 /// Event ID that name of feature is changed (comes with Model_ObjectRenamedMessage)
33 static const char * EVENT_OBJECT_RENAMED = "ObjectRenamed";
34 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
35 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
36 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
37 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
38 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
39 static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
40 /// The active document becomes another one
41 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
43 /// Event ID that order of objects in group is changed,
44 /// so, tree must be fully rectreated (movement of feature)
45 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
46 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
47 static const char * EVENT_UPDATE_SELECTION = "UpdateSelection";
49 /// Request for the enabled/disabled actions behavior for some specific features
50 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
51 /// Reply for the enabled/disabled actions behavior for some specific features
52 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
54 /// To block the viewer updates
55 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
56 /// To unblock the viewer updates
57 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
59 /// To inform that there is an empty presentation in the viewer
60 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
61 /// To inform that there is an empty operation for presentation in the viewer
62 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
64 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
65 /// To preview the current feature in the viewer (to compute the result)
66 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
68 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
69 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
70 /// Event ID that the problem in solver disappeared
71 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
73 /// Event ID that informs that some object has changed the stability
74 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
76 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
77 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
79 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
80 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
83 /// Creates an empty message
84 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
85 /// The virtual destructor
86 virtual ~ModelAPI_ObjectUpdatedMessage();
89 /// Returns the feature that has been updated
90 virtual const std::set<ObjectPtr>& objects() const = 0;
92 //! Creates a new empty group (to store it in the loop before flush)
93 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
95 //! Allows to join the given message with the current one
96 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
99 /// Message that feature was deleted (used for Object Browser update)
100 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
103 /// Creates an empty message
104 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
105 /// The virtual destructor
106 virtual ~ModelAPI_ObjectDeletedMessage();
109 /// Returns the document that has been updated
110 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
112 /// Returns the groups where the objects were deleted
113 virtual const std::set<std::string>& groups() const = 0;
115 /// Creates the new empty message of this kind
116 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
118 /// Returns the identifier of the kind of a message
119 virtual const Events_ID messageId() = 0;
121 /// Appenad to this message the given one.
122 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
125 /// Message that order changed (used for Object Browser update)
126 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
129 /// Creates a message:
130 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
131 /// The virtual destructor
132 virtual ~ModelAPI_OrderUpdatedMessage();
135 /// Returns the document that has been updated
136 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
138 /// Returns the identifier of the kind of a message
139 virtual const Events_ID messageId() = 0;
142 /// Allows to create ModelAPI messages
143 class MODELAPI_EXPORT ModelAPI_EventCreator
146 /// creates created, updated or moved messages and sends to the loop
147 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
148 const bool isGroupped = true) const = 0;
149 /// creates deleted message and sends to the loop
150 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
151 const std::string& theGroup) const = 0;
152 /// creates reordered message and sends to the loop
153 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
155 /// returns the creator instance
156 static const ModelAPI_EventCreator* get();
158 /// sets the creator instance
159 static void set(const ModelAPI_EventCreator* theCreator);
162 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
163 /// Contains the state information about the feature: is it enabled or disabled.
164 class ModelAPI_FeatureStateMessage : public Events_Message
167 /// Creates an empty message
168 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
169 /// The virtual destructor
170 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
172 /// Returns the feature this message is related to
173 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
174 /// Stores the feature this message is related to
175 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
177 /// Returns true if feature has specific state
178 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
179 /// Returns true if feature is enabled
180 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
181 /// Stores the feature state
182 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
183 /// Returns all feature IDs with states
184 MODELAPI_EXPORT std::list<std::string> features() const;
188 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
190 std::map<std::string, bool> myFeatureState;
193 /// Message that document (Part, PartSet) was created
194 class ModelAPI_DocumentCreatedMessage : public Events_Message
196 DocumentPtr myDocument;
199 /// Creates an empty message
200 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
201 /// The virtual destructor
202 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
203 /// Static. Returns EventID of the message.
204 MODELAPI_EXPORT static Events_ID eventId()
206 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
207 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
210 /// Returns a document stored in the message
211 MODELAPI_EXPORT DocumentPtr document() const;
212 /// Sets a document to the message
213 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
216 /// Message that attribute text should be evaluated in the attribute value
217 class ModelAPI_AttributeEvalMessage : public Events_Message
219 AttributePtr myAttribute;
222 /// Static. Returns EventID of the message.
223 MODELAPI_EXPORT static Events_ID& eventId()
225 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
226 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
230 /// Useful method that creates and sends the AttributeEvalMessage event
231 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
233 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
234 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
235 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
236 aMessage->setAttribute(theAttribute);
237 Events_Loop::loop()->send(aMessage);
240 /// Creates an empty message
241 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
242 /// The virtual destructor
243 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
245 /// Returns a document stored in the message
246 MODELAPI_EXPORT AttributePtr attribute() const;
247 /// Sets an attribute to the message
248 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
251 /// Message that parameter feature expression should be evaluated: value and error producing
252 class ModelAPI_ParameterEvalMessage : public Events_Message
254 FeaturePtr myParam; ///< parameters that should be evaluated
255 bool myIsProcessed; ///< true if results were set
256 /// result of processing, list of parameters in expression found
257 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
258 double myResult; ///< result of processing, the computed value of the expression
259 std::string myError; ///< error of processing, empty if there is no error
262 /// Static. Returns EventID of the message.
263 MODELAPI_EXPORT static Events_ID& eventId()
265 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
266 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
270 /// Useful method that creates and sends the event.
271 /// Returns the message, processed, with the resulting fields filled.
272 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
273 send(FeaturePtr theParameter, const void* theSender)
275 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
276 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
277 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
278 aMessage->setParameter(theParameter);
279 Events_Loop::loop()->send(aMessage);
283 /// Creates an empty message
284 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
285 /// The virtual destructor
286 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
288 /// Returns a parameter stored in the message
289 MODELAPI_EXPORT FeaturePtr parameter() const;
290 /// Sets a parameter to the message
291 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
292 /// Sets the results of processing
293 MODELAPI_EXPORT void setResults(
294 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
295 const double theResult, const std::string& theError);
296 /// Returns true if the expression is processed
297 MODELAPI_EXPORT bool isProcessed();
298 /// Returns the results of processing: list of parameters found in the expression
299 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
300 /// Returns the expression result
301 MODELAPI_EXPORT const double& result() const;
302 /// Returns the interpreter error (empty if no error)
303 MODELAPI_EXPORT const std::string& error() const;
307 /// Message to ask compute the positions of parameters in the expression
308 class ModelAPI_ComputePositionsMessage : public Events_Message
310 std::string myExpression; ///< the expression string
311 std::string myParamName; ///< name of the parameter to be searched
312 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
315 /// Static. Returns EventID of the message.
316 MODELAPI_EXPORT static Events_ID& eventId()
318 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
319 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
323 /// Useful method that creates and sends the AttributeEvalMessage event
324 /// Returns the message, processed, with the resulting fields filled
325 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
326 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
328 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
329 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
330 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
331 aMessage->set(theExpression, theParameter);
332 Events_Loop::loop()->send(aMessage);
336 /// Creates an empty message
337 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
338 const Events_ID theID, const void* theSender = 0);
339 /// The virtual destructor
340 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
342 /// Returns an expression stored in the message
343 MODELAPI_EXPORT const std::string& expression() const;
344 /// Returns a parameter name stored in the message
345 MODELAPI_EXPORT const std::string& parameter() const;
346 /// Sets an expression and parameter needed for computation
347 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
348 /// Sets the results of processing
349 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
350 /// Returns the results of processing: position start and end indices
351 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
354 /// Message that the object is renamed
355 class ModelAPI_ObjectRenamedMessage : public Events_Message
358 std::string myOldName;
359 std::string myNewName;
362 /// Static. Returns EventID of the message.
363 MODELAPI_EXPORT static Events_ID& eventId()
365 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
366 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
370 /// Useful method that creates and sends the AttributeEvalMessage event
371 MODELAPI_EXPORT static void send(ObjectPtr theObject,
372 const std::string& theOldName,
373 const std::string& theNewName,
374 const void* theSender);
376 /// Creates an empty message
377 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
378 /// The virtual destructor
379 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
381 /// Returns an object
382 MODELAPI_EXPORT ObjectPtr object() const;
384 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
385 /// Returns an old name
386 MODELAPI_EXPORT std::string oldName() const;
388 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
389 /// Returns a new name
390 MODELAPI_EXPORT std::string newName() const;
392 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
395 /// Message that the parameter should be replaced with its value
396 class ModelAPI_ReplaceParameterMessage : public Events_Message
401 /// Static. Returns EventID of the message.
402 MODELAPI_EXPORT static Events_ID& eventId()
404 static const char * MY_EVENT_ID("ReplaceParameter");
405 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
409 /// Useful method that creates and sends the AttributeEvalMessage event
410 MODELAPI_EXPORT static void send(ObjectPtr theObject,
411 const void* theSender);
413 /// Creates an empty message
415 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
416 /// The virtual destructor
417 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
419 /// Returns an object
420 MODELAPI_EXPORT ObjectPtr object() const;
422 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
425 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
426 class ModelAPI_SolverFailedMessage : public Events_Message
429 /// Creates an message
430 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
431 /// Default destructor
432 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
434 /// Sets list of conflicting constraints
435 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
436 /// Returns list of conflicting constraints
437 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
439 /// Sets degrees of freedom
440 void dof(const int theDOF) { myDOF = theDOF; }
441 /// Returns degrees of freedom
442 const int& dof() const { return myDOF; }
445 std::set<ObjectPtr> myObjects;