1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MODELAPI_EVENTS_H_
21 #define MODELAPI_EVENTS_H_
24 #include <ModelAPI_Object.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Attribute.h>
27 #include <Events_MessageGroup.h>
28 #include <Events_Loop.h>
36 class ModelAPI_Document;
37 class ModelAPI_ResultParameter;
41 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
42 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
43 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
44 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
45 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
46 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
47 /// Event ID that name of feature is changed (comes with Model_ObjectRenamedMessage)
48 static const char * EVENT_OBJECT_RENAMED = "ObjectRenamed";
49 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
50 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
51 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
52 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
53 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
54 static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
55 /// The active document becomes another one
56 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
58 /// Event ID that order of objects in group is changed,
59 /// so, tree must be fully recreated (movement of feature)
60 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
61 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
62 static const char * EVENT_UPDATE_SELECTION = "UpdateSelection";
64 /// Request for the enabled/disabled actions behavior for some specific features
65 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
66 /// Reply for the enabled/disabled actions behavior for some specific features
67 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
69 /// To block the viewer updates
70 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
71 /// To unblock the viewer updates
72 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
74 /// To inform that there is an empty presentation in the viewer
75 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
76 /// To inform that there is an empty operation for presentation in the viewer
77 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
79 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
80 /// To preview the current feature in the viewer (to compute the result)
81 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
82 /// To block automatic recomputation of any feature (by the GUI button press)
83 static const char * EVENT_AUTOMATIC_RECOMPUTATION_DISABLE = "DisableAutomaticRecomputation";
84 /// To unblock block automatic recomputation (default state: the GUI button unpressed)
85 static const char * EVENT_AUTOMATIC_RECOMPUTATION_ENABLE = "EnableAutomaticRecomputation";
87 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
88 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
89 /// Event ID that the problem in solver disappeared
90 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
92 /// Event Id that sketch has DoF = 0
93 static const char * EVENT_SKETCH_FULLY_CONSTRAINED = "SketchFullyConstrainted";
94 /// Event Id that sketch has DoF > 0
95 static const char * EVENT_SKETCH_UNDER_CONSTRAINED = "SketchUnderConstrainted";
96 /// Event Id that sketch has DoF < 0
97 static const char * EVENT_SKETCH_OVER_CONSTRAINED = "SketchOverConstrainted";
99 /// Event ID that informs that some object has changed the stability
100 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
102 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
103 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
105 /// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
106 static const char * EVENT_GET_DOF_OBJECTS = "GetDoFObjects";
108 /// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
109 static const char * EVENT_DOF_OBJECTS = "DoFObjects";
111 /// Event ID that requests updates visual attributes for presentations
112 static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes";
114 /// Event ID that 1D-fillet failed (comes with ModelAPI_Fillet1DFailedMessage)
115 static const char * EVENT_1DFILLET_FAILED = "1DFilletFailed";
117 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
118 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
121 /// Creates an empty message
122 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
123 /// The virtual destructor
124 virtual ~ModelAPI_ObjectUpdatedMessage();
127 /// Returns the feature that has been updated
128 virtual const std::set<ObjectPtr>& objects() const = 0;
130 //! Creates a new empty group (to store it in the loop before flush)
131 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
133 //! Allows to join the given message with the current one
134 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
137 /// Message that feature was deleted (used for Object Browser update)
138 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
141 /// Creates an empty message
142 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
143 /// The virtual destructor
144 virtual ~ModelAPI_ObjectDeletedMessage();
147 /// Returns the groups where the objects were deleted
148 virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
151 /// Creates the new empty message of this kind
152 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
154 /// Returns the identifier of the kind of a message
155 virtual const Events_ID messageId() = 0;
157 /// Appends to this message the given one.
158 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
161 /// Message that order changed (used for Object Browser update)
162 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
165 /// Creates a message:
166 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
167 /// The virtual destructor
168 virtual ~ModelAPI_OrderUpdatedMessage();
171 /// Returns the document that has been updated
172 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
174 /// Returns the identifier of the kind of a message
175 virtual const Events_ID messageId() = 0;
178 /// Allows to create ModelAPI messages
179 class MODELAPI_EXPORT ModelAPI_EventCreator
182 /// creates created, updated or moved messages and sends to the loop
183 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
184 const bool isGroupped = true) const = 0;
185 /// creates created, updated or moved messages with the objects collection and sends to the loop
186 virtual void sendUpdated(const std::list<ObjectPtr>& theObjects, const Events_ID& theEvent,
187 const bool isGroupped = true) const = 0;
188 /// creates deleted message and sends to the loop
189 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
190 const std::string& theGroup) const = 0;
191 /// creates reordered message and sends to the loop
192 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
194 /// returns the creator instance
195 static const ModelAPI_EventCreator* get();
197 /// sets the creator instance
198 static void set(const ModelAPI_EventCreator* theCreator);
201 /// Contains the state information about the feature: is it enabled or disabled.
202 class ModelAPI_FeatureStateMessage : public Events_Message
205 /// Creates an empty message
206 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
207 /// The virtual destructor
208 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
210 /// Returns the feature this message is related to
211 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
212 /// Stores the feature this message is related to
213 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
215 /// Returns true if feature has specific state
216 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
217 /// Returns true if feature is enabled
218 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
219 /// Stores the feature state
220 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
221 /// Returns all feature IDs with states
222 MODELAPI_EXPORT std::list<std::string> features() const;
226 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
228 std::map<std::string, bool> myFeatureState;
231 /// Message that document (Part, PartSet) was created
232 class ModelAPI_DocumentCreatedMessage : public Events_Message
234 DocumentPtr myDocument;
237 /// Creates an empty message
238 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
239 /// The virtual destructor
240 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
241 /// Static. Returns EventID of the message.
242 MODELAPI_EXPORT static Events_ID eventId()
244 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
245 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
248 /// Returns a document stored in the message
249 MODELAPI_EXPORT DocumentPtr document() const;
250 /// Sets a document to the message
251 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
254 /// Message that attribute text should be evaluated in the attribute value
255 class ModelAPI_AttributeEvalMessage : public Events_Message
257 AttributePtr myAttribute;
260 /// Static. Returns EventID of the message.
261 MODELAPI_EXPORT static Events_ID& eventId()
263 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
264 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
268 /// Useful method that creates and sends the AttributeEvalMessage event
269 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
271 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
272 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
273 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
274 aMessage->setAttribute(theAttribute);
275 Events_Loop::loop()->send(aMessage);
278 /// Creates an empty message
279 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
280 /// The virtual destructor
281 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
283 /// Returns a document stored in the message
284 MODELAPI_EXPORT AttributePtr attribute() const;
285 /// Sets an attribute to the message
286 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
289 /// Message that parameter feature expression should be evaluated: value and error producing
290 class ModelAPI_ParameterEvalMessage : public Events_Message
292 FeaturePtr myParam; ///< parameters that should be evaluated
293 bool myIsProcessed; ///< true if results were set
294 /// result of processing, list of parameters in expression found
295 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
296 double myResult; ///< result of processing, the computed value of the expression
297 std::string myError; ///< error of processing, empty if there is no error
300 /// Static. Returns EventID of the message.
301 MODELAPI_EXPORT static Events_ID& eventId()
303 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
304 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
308 /// Useful method that creates and sends the event.
309 /// Returns the message, processed, with the resulting fields filled.
310 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
311 send(FeaturePtr theParameter, const void* theSender)
313 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
314 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
315 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
316 aMessage->setParameter(theParameter);
317 Events_Loop::loop()->send(aMessage);
321 /// Creates an empty message
322 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
323 /// The virtual destructor
324 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
326 /// Returns a parameter stored in the message
327 MODELAPI_EXPORT FeaturePtr parameter() const;
328 /// Sets a parameter to the message
329 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
330 /// Sets the results of processing
331 MODELAPI_EXPORT void setResults(
332 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
333 const double theResult, const std::string& theError);
334 /// Returns true if the expression is processed
335 MODELAPI_EXPORT bool isProcessed();
336 /// Returns the results of processing: list of parameters found in the expression
337 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
338 /// Returns the expression result
339 MODELAPI_EXPORT const double& result() const;
340 /// Returns the interpreter error (empty if no error)
341 MODELAPI_EXPORT const std::string& error() const;
345 /// Message to ask compute the positions of parameters in the expression
346 class ModelAPI_ComputePositionsMessage : public Events_Message
348 std::string myExpression; ///< the expression string
349 std::string myParamName; ///< name of the parameter to be searched
350 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
353 /// Static. Returns EventID of the message.
354 MODELAPI_EXPORT static Events_ID& eventId()
356 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
357 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
361 /// Useful method that creates and sends the AttributeEvalMessage event
362 /// Returns the message, processed, with the resulting fields filled
363 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
364 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
366 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
367 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
368 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
369 aMessage->set(theExpression, theParameter);
370 Events_Loop::loop()->send(aMessage);
374 /// Creates an empty message
375 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
376 const Events_ID theID, const void* theSender = 0);
377 /// The virtual destructor
378 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
380 /// Returns an expression stored in the message
381 MODELAPI_EXPORT const std::string& expression() const;
382 /// Returns a parameter name stored in the message
383 MODELAPI_EXPORT const std::string& parameter() const;
384 /// Sets an expression and parameter needed for computation
385 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
386 /// Sets the results of processing
387 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
388 /// Returns the results of processing: position start and end indices
389 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
392 /// Message that the object is renamed
393 class ModelAPI_ObjectRenamedMessage : public Events_Message
396 std::string myOldName;
397 std::string myNewName;
400 /// Static. Returns EventID of the message.
401 MODELAPI_EXPORT static Events_ID& eventId()
403 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
404 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
408 /// Useful method that creates and sends the AttributeEvalMessage event
409 MODELAPI_EXPORT static void send(ObjectPtr theObject,
410 const std::string& theOldName,
411 const std::string& theNewName,
412 const void* theSender);
414 /// Creates an empty message
415 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
416 /// The virtual destructor
417 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
419 /// Returns an object
420 MODELAPI_EXPORT ObjectPtr object() const;
422 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
423 /// Returns an old name
424 MODELAPI_EXPORT std::string oldName() const;
426 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
427 /// Returns a new name
428 MODELAPI_EXPORT std::string newName() const;
430 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
433 /// Message that the parameter should be replaced with its value
434 class ModelAPI_ReplaceParameterMessage : public Events_Message
439 /// Static. Returns EventID of the message.
440 MODELAPI_EXPORT static Events_ID& eventId()
442 static const char * MY_EVENT_ID("ReplaceParameter");
443 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
447 /// Useful method that creates and sends the AttributeEvalMessage event
448 MODELAPI_EXPORT static void send(ObjectPtr theObject,
449 const void* theSender);
451 /// Creates an empty message
453 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
454 /// The virtual destructor
455 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
457 /// Returns an object
458 MODELAPI_EXPORT ObjectPtr object() const;
460 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
463 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
464 class ModelAPI_SolverFailedMessage : public Events_Message
467 /// Creates an message
468 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
469 /// Default destructor
470 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
472 /// Sets list of conflicting constraints
473 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
474 /// Returns list of conflicting constraints
475 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
477 /// Sets degrees of freedom
478 void dof(const int theDOF) { myDOF = theDOF; }
479 /// Returns degrees of freedom
480 const int& dof() const { return myDOF; }
483 std::set<ObjectPtr> myObjects;
487 /// Message sent when feature or attribute has been moved.
488 /// Stores the moving object/attribute, original and new positions of mouse.
489 class ModelAPI_ObjectMovedMessage : public Events_Message
491 ObjectPtr myMovedObject;
492 AttributePtr myMovedAttribute;
493 int myMovedPointIndex;
495 std::shared_ptr<GeomAPI_Pnt2d> myOriginalPosition;
496 std::shared_ptr<GeomAPI_Pnt2d> myCurrentPosition;
499 MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0);
501 /// Set object which is being moved (if the message already contains attribute it will be cleared)
502 MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject);
503 /// Set attribute which is being moved (if the message already contains object it will be cleared)
504 /// \param[in] theMovedAttribute moved attribute
505 /// \param[in] thePointIndex index of the point if the moved attribute is an array of points
506 MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute,
507 const int thePointIndex = -1);
509 /// Return moved object
510 ObjectPtr movedObject() const
511 { return myMovedObject; }
512 /// Return moved attribute
513 AttributePtr movedAttribute() const
514 { return myMovedAttribute; }
515 /// Return index of the moved point
516 int movedPointIndex() const
517 { return myMovedPointIndex; }
519 /// Set original mouse position
520 MODELAPI_EXPORT void setOriginalPosition(double theX, double theY);
521 /// Set original mouse position
522 MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
523 /// Return original mouse position
524 const std::shared_ptr<GeomAPI_Pnt2d>& originalPosition() const
525 { return myOriginalPosition; }
527 /// Set current mouse position
528 MODELAPI_EXPORT void setCurrentPosition(double theX, double theY);
529 /// Set current mouse position
530 MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
531 /// Return current mouse position
532 const std::shared_ptr<GeomAPI_Pnt2d>& currentPosition() const
533 { return myCurrentPosition; }
536 /// Message that sends the failed vertices of 1D-fillet to highlight them in 3D viewer
537 class ModelAPI_Fillet1DFailedMessage : public Events_Message
540 /// Creates an message
541 MODELAPI_EXPORT ModelAPI_Fillet1DFailedMessage(const Events_ID theID, const void* theSender = 0);
542 /// Default destructor
543 MODELAPI_EXPORT virtual ~ModelAPI_Fillet1DFailedMessage();
544 /// Static. Returns EventID of the message.
545 MODELAPI_EXPORT static Events_ID eventId()
547 return Events_Loop::eventByName(EVENT_1DFILLET_FAILED);
550 /// Sets list of failed vertices
551 MODELAPI_EXPORT void setVertices(const std::list< std::shared_ptr<GeomAPI_Shape> >& theVertices);
552 /// Returns list of failed vertices
553 MODELAPI_EXPORT const std::list< std::shared_ptr<GeomAPI_Shape> >& vertices() const;
556 std::list< std::shared_ptr<GeomAPI_Shape> > myVertices;