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 sketch has DoF = 0
74 static const char * EVENT_SKETCH_FULLY_CONSTRAINED = "SketchFullyConstrainted";
75 /// Event Id that sketch has DoF > 0
76 static const char * EVENT_SKETCH_UNDER_CONSTRAINED = "SketchUnderConstrainted";
77 /// Event Id that sketch has DoF < 0
78 static const char * EVENT_SKETCH_OVER_CONSTRAINED = "SketchOverConstrainted";
80 /// Event ID that informs that some object has changed the stability
81 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
83 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
84 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
86 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
87 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
90 /// Creates an empty message
91 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
92 /// The virtual destructor
93 virtual ~ModelAPI_ObjectUpdatedMessage();
96 /// Returns the feature that has been updated
97 virtual const std::set<ObjectPtr>& objects() const = 0;
99 //! Creates a new empty group (to store it in the loop before flush)
100 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
102 //! Allows to join the given message with the current one
103 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
106 /// Message that feature was deleted (used for Object Browser update)
107 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
110 /// Creates an empty message
111 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
112 /// The virtual destructor
113 virtual ~ModelAPI_ObjectDeletedMessage();
116 /// Returns the document that has been updated
117 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
119 /// Returns the groups where the objects were deleted
120 virtual const std::set<std::string>& groups() const = 0;
122 /// Creates the new empty message of this kind
123 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
125 /// Returns the identifier of the kind of a message
126 virtual const Events_ID messageId() = 0;
128 /// Appenad to this message the given one.
129 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
132 /// Message that order changed (used for Object Browser update)
133 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
136 /// Creates a message:
137 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
138 /// The virtual destructor
139 virtual ~ModelAPI_OrderUpdatedMessage();
142 /// Returns the document that has been updated
143 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
145 /// Returns the identifier of the kind of a message
146 virtual const Events_ID messageId() = 0;
149 /// Allows to create ModelAPI messages
150 class MODELAPI_EXPORT ModelAPI_EventCreator
153 /// creates created, updated or moved messages and sends to the loop
154 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
155 const bool isGroupped = true) const = 0;
156 /// creates deleted message and sends to the loop
157 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
158 const std::string& theGroup) const = 0;
159 /// creates reordered message and sends to the loop
160 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
162 /// returns the creator instance
163 static const ModelAPI_EventCreator* get();
165 /// sets the creator instance
166 static void set(const ModelAPI_EventCreator* theCreator);
169 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
170 /// Contains the state information about the feature: is it enabled or disabled.
171 class ModelAPI_FeatureStateMessage : public Events_Message
174 /// Creates an empty message
175 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
176 /// The virtual destructor
177 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
179 /// Returns the feature this message is related to
180 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
181 /// Stores the feature this message is related to
182 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
184 /// Returns true if feature has specific state
185 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
186 /// Returns true if feature is enabled
187 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
188 /// Stores the feature state
189 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
190 /// Returns all feature IDs with states
191 MODELAPI_EXPORT std::list<std::string> features() const;
195 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
197 std::map<std::string, bool> myFeatureState;
200 /// Message that document (Part, PartSet) was created
201 class ModelAPI_DocumentCreatedMessage : public Events_Message
203 DocumentPtr myDocument;
206 /// Creates an empty message
207 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
208 /// The virtual destructor
209 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
210 /// Static. Returns EventID of the message.
211 MODELAPI_EXPORT static Events_ID eventId()
213 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
214 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
217 /// Returns a document stored in the message
218 MODELAPI_EXPORT DocumentPtr document() const;
219 /// Sets a document to the message
220 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
223 /// Message that attribute text should be evaluated in the attribute value
224 class ModelAPI_AttributeEvalMessage : public Events_Message
226 AttributePtr myAttribute;
229 /// Static. Returns EventID of the message.
230 MODELAPI_EXPORT static Events_ID& eventId()
232 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
233 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
237 /// Useful method that creates and sends the AttributeEvalMessage event
238 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
240 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
241 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
242 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
243 aMessage->setAttribute(theAttribute);
244 Events_Loop::loop()->send(aMessage);
247 /// Creates an empty message
248 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
249 /// The virtual destructor
250 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
252 /// Returns a document stored in the message
253 MODELAPI_EXPORT AttributePtr attribute() const;
254 /// Sets an attribute to the message
255 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
258 /// Message that parameter feature expression should be evaluated: value and error producing
259 class ModelAPI_ParameterEvalMessage : public Events_Message
261 FeaturePtr myParam; ///< parameters that should be evaluated
262 bool myIsProcessed; ///< true if results were set
263 /// result of processing, list of parameters in expression found
264 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
265 double myResult; ///< result of processing, the computed value of the expression
266 std::string myError; ///< error of processing, empty if there is no error
269 /// Static. Returns EventID of the message.
270 MODELAPI_EXPORT static Events_ID& eventId()
272 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
273 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
277 /// Useful method that creates and sends the event.
278 /// Returns the message, processed, with the resulting fields filled.
279 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
280 send(FeaturePtr theParameter, const void* theSender)
282 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
283 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
284 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
285 aMessage->setParameter(theParameter);
286 Events_Loop::loop()->send(aMessage);
290 /// Creates an empty message
291 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
292 /// The virtual destructor
293 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
295 /// Returns a parameter stored in the message
296 MODELAPI_EXPORT FeaturePtr parameter() const;
297 /// Sets a parameter to the message
298 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
299 /// Sets the results of processing
300 MODELAPI_EXPORT void setResults(
301 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
302 const double theResult, const std::string& theError);
303 /// Returns true if the expression is processed
304 MODELAPI_EXPORT bool isProcessed();
305 /// Returns the results of processing: list of parameters found in the expression
306 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
307 /// Returns the expression result
308 MODELAPI_EXPORT const double& result() const;
309 /// Returns the interpreter error (empty if no error)
310 MODELAPI_EXPORT const std::string& error() const;
314 /// Message to ask compute the positions of parameters in the expression
315 class ModelAPI_ComputePositionsMessage : public Events_Message
317 std::string myExpression; ///< the expression string
318 std::string myParamName; ///< name of the parameter to be searched
319 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
322 /// Static. Returns EventID of the message.
323 MODELAPI_EXPORT static Events_ID& eventId()
325 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
326 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
330 /// Useful method that creates and sends the AttributeEvalMessage event
331 /// Returns the message, processed, with the resulting fields filled
332 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
333 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
335 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
336 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
337 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
338 aMessage->set(theExpression, theParameter);
339 Events_Loop::loop()->send(aMessage);
343 /// Creates an empty message
344 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
345 const Events_ID theID, const void* theSender = 0);
346 /// The virtual destructor
347 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
349 /// Returns an expression stored in the message
350 MODELAPI_EXPORT const std::string& expression() const;
351 /// Returns a parameter name stored in the message
352 MODELAPI_EXPORT const std::string& parameter() const;
353 /// Sets an expression and parameter needed for computation
354 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
355 /// Sets the results of processing
356 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
357 /// Returns the results of processing: position start and end indices
358 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
361 /// Message that the object is renamed
362 class ModelAPI_ObjectRenamedMessage : public Events_Message
365 std::string myOldName;
366 std::string myNewName;
369 /// Static. Returns EventID of the message.
370 MODELAPI_EXPORT static Events_ID& eventId()
372 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
373 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
377 /// Useful method that creates and sends the AttributeEvalMessage event
378 MODELAPI_EXPORT static void send(ObjectPtr theObject,
379 const std::string& theOldName,
380 const std::string& theNewName,
381 const void* theSender);
383 /// Creates an empty message
384 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
385 /// The virtual destructor
386 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
388 /// Returns an object
389 MODELAPI_EXPORT ObjectPtr object() const;
391 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
392 /// Returns an old name
393 MODELAPI_EXPORT std::string oldName() const;
395 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
396 /// Returns a new name
397 MODELAPI_EXPORT std::string newName() const;
399 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
402 /// Message that the parameter should be replaced with its value
403 class ModelAPI_ReplaceParameterMessage : public Events_Message
408 /// Static. Returns EventID of the message.
409 MODELAPI_EXPORT static Events_ID& eventId()
411 static const char * MY_EVENT_ID("ReplaceParameter");
412 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
416 /// Useful method that creates and sends the AttributeEvalMessage event
417 MODELAPI_EXPORT static void send(ObjectPtr theObject,
418 const void* theSender);
420 /// Creates an empty message
422 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
423 /// The virtual destructor
424 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
426 /// Returns an object
427 MODELAPI_EXPORT ObjectPtr object() const;
429 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
432 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
433 class ModelAPI_SolverFailedMessage : public Events_Message
436 /// Creates an message
437 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
438 /// Default destructor
439 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
441 /// Sets list of conflicting constraints
442 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
443 /// Returns list of conflicting constraints
444 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
446 /// Sets degrees of freedom
447 void dof(const int theDOF) { myDOF = theDOF; }
448 /// Returns degrees of freedom
449 const int& dof() const { return myDOF; }
452 std::set<ObjectPtr> myObjects;