1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef MODELAPI_EVENTS_H_
22 #define MODELAPI_EVENTS_H_
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_Attribute.h>
28 #include <Events_MessageGroup.h>
29 #include <Events_Loop.h>
37 class ModelAPI_Document;
38 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 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
106 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
109 /// Creates an empty message
110 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
111 /// The virtual destructor
112 virtual ~ModelAPI_ObjectUpdatedMessage();
115 /// Returns the feature that has been updated
116 virtual const std::set<ObjectPtr>& objects() const = 0;
118 //! Creates a new empty group (to store it in the loop before flush)
119 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
121 //! Allows to join the given message with the current one
122 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
125 /// Message that feature was deleted (used for Object Browser update)
126 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
129 /// Creates an empty message
130 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
131 /// The virtual destructor
132 virtual ~ModelAPI_ObjectDeletedMessage();
135 /// Returns the groups where the objects were deleted
136 virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
139 /// Creates the new empty message of this kind
140 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
142 /// Returns the identifier of the kind of a message
143 virtual const Events_ID messageId() = 0;
145 /// Appends to this message the given one.
146 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
149 /// Message that order changed (used for Object Browser update)
150 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
153 /// Creates a message:
154 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
155 /// The virtual destructor
156 virtual ~ModelAPI_OrderUpdatedMessage();
159 /// Returns the document that has been updated
160 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
162 /// Returns the identifier of the kind of a message
163 virtual const Events_ID messageId() = 0;
166 /// Allows to create ModelAPI messages
167 class MODELAPI_EXPORT ModelAPI_EventCreator
170 /// creates created, updated or moved messages and sends to the loop
171 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
172 const bool isGroupped = true) const = 0;
173 /// creates created, updated or moved messages with the objects collection and sends to the loop
174 virtual void sendUpdated(const std::list<ObjectPtr>& theObjects, const Events_ID& theEvent,
175 const bool isGroupped = true) const = 0;
176 /// creates deleted message and sends to the loop
177 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
178 const std::string& theGroup) const = 0;
179 /// creates reordered message and sends to the loop
180 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
182 /// returns the creator instance
183 static const ModelAPI_EventCreator* get();
185 /// sets the creator instance
186 static void set(const ModelAPI_EventCreator* theCreator);
189 /// Contains the state information about the feature: is it enabled or disabled.
190 class ModelAPI_FeatureStateMessage : public Events_Message
193 /// Creates an empty message
194 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
195 /// The virtual destructor
196 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
198 /// Returns the feature this message is related to
199 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
200 /// Stores the feature this message is related to
201 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
203 /// Returns true if feature has specific state
204 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
205 /// Returns true if feature is enabled
206 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
207 /// Stores the feature state
208 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
209 /// Returns all feature IDs with states
210 MODELAPI_EXPORT std::list<std::string> features() const;
214 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
216 std::map<std::string, bool> myFeatureState;
219 /// Message that document (Part, PartSet) was created
220 class ModelAPI_DocumentCreatedMessage : public Events_Message
222 DocumentPtr myDocument;
225 /// Creates an empty message
226 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
227 /// The virtual destructor
228 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
229 /// Static. Returns EventID of the message.
230 MODELAPI_EXPORT static Events_ID eventId()
232 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
233 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
236 /// Returns a document stored in the message
237 MODELAPI_EXPORT DocumentPtr document() const;
238 /// Sets a document to the message
239 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
242 /// Message that attribute text should be evaluated in the attribute value
243 class ModelAPI_AttributeEvalMessage : public Events_Message
245 AttributePtr myAttribute;
248 /// Static. Returns EventID of the message.
249 MODELAPI_EXPORT static Events_ID& eventId()
251 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
252 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
256 /// Useful method that creates and sends the AttributeEvalMessage event
257 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
259 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
260 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
261 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
262 aMessage->setAttribute(theAttribute);
263 Events_Loop::loop()->send(aMessage);
266 /// Creates an empty message
267 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
268 /// The virtual destructor
269 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
271 /// Returns a document stored in the message
272 MODELAPI_EXPORT AttributePtr attribute() const;
273 /// Sets an attribute to the message
274 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
277 /// Message that parameter feature expression should be evaluated: value and error producing
278 class ModelAPI_ParameterEvalMessage : public Events_Message
280 FeaturePtr myParam; ///< parameters that should be evaluated
281 bool myIsProcessed; ///< true if results were set
282 /// result of processing, list of parameters in expression found
283 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
284 double myResult; ///< result of processing, the computed value of the expression
285 std::string myError; ///< error of processing, empty if there is no error
288 /// Static. Returns EventID of the message.
289 MODELAPI_EXPORT static Events_ID& eventId()
291 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
292 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
296 /// Useful method that creates and sends the event.
297 /// Returns the message, processed, with the resulting fields filled.
298 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
299 send(FeaturePtr theParameter, const void* theSender)
301 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
302 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
303 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
304 aMessage->setParameter(theParameter);
305 Events_Loop::loop()->send(aMessage);
309 /// Creates an empty message
310 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
311 /// The virtual destructor
312 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
314 /// Returns a parameter stored in the message
315 MODELAPI_EXPORT FeaturePtr parameter() const;
316 /// Sets a parameter to the message
317 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
318 /// Sets the results of processing
319 MODELAPI_EXPORT void setResults(
320 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
321 const double theResult, const std::string& theError);
322 /// Returns true if the expression is processed
323 MODELAPI_EXPORT bool isProcessed();
324 /// Returns the results of processing: list of parameters found in the expression
325 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
326 /// Returns the expression result
327 MODELAPI_EXPORT const double& result() const;
328 /// Returns the interpreter error (empty if no error)
329 MODELAPI_EXPORT const std::string& error() const;
333 /// Message to ask compute the positions of parameters in the expression
334 class ModelAPI_ComputePositionsMessage : public Events_Message
336 std::string myExpression; ///< the expression string
337 std::string myParamName; ///< name of the parameter to be searched
338 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
341 /// Static. Returns EventID of the message.
342 MODELAPI_EXPORT static Events_ID& eventId()
344 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
345 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
349 /// Useful method that creates and sends the AttributeEvalMessage event
350 /// Returns the message, processed, with the resulting fields filled
351 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
352 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
354 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
355 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
356 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
357 aMessage->set(theExpression, theParameter);
358 Events_Loop::loop()->send(aMessage);
362 /// Creates an empty message
363 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
364 const Events_ID theID, const void* theSender = 0);
365 /// The virtual destructor
366 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
368 /// Returns an expression stored in the message
369 MODELAPI_EXPORT const std::string& expression() const;
370 /// Returns a parameter name stored in the message
371 MODELAPI_EXPORT const std::string& parameter() const;
372 /// Sets an expression and parameter needed for computation
373 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
374 /// Sets the results of processing
375 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
376 /// Returns the results of processing: position start and end indices
377 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
380 /// Message that the object is renamed
381 class ModelAPI_ObjectRenamedMessage : public Events_Message
384 std::string myOldName;
385 std::string myNewName;
388 /// Static. Returns EventID of the message.
389 MODELAPI_EXPORT static Events_ID& eventId()
391 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
392 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
396 /// Useful method that creates and sends the AttributeEvalMessage event
397 MODELAPI_EXPORT static void send(ObjectPtr theObject,
398 const std::string& theOldName,
399 const std::string& theNewName,
400 const void* theSender);
402 /// Creates an empty message
403 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
404 /// The virtual destructor
405 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
407 /// Returns an object
408 MODELAPI_EXPORT ObjectPtr object() const;
410 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
411 /// Returns an old name
412 MODELAPI_EXPORT std::string oldName() const;
414 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
415 /// Returns a new name
416 MODELAPI_EXPORT std::string newName() const;
418 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
421 /// Message that the parameter should be replaced with its value
422 class ModelAPI_ReplaceParameterMessage : public Events_Message
427 /// Static. Returns EventID of the message.
428 MODELAPI_EXPORT static Events_ID& eventId()
430 static const char * MY_EVENT_ID("ReplaceParameter");
431 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
435 /// Useful method that creates and sends the AttributeEvalMessage event
436 MODELAPI_EXPORT static void send(ObjectPtr theObject,
437 const void* theSender);
439 /// Creates an empty message
441 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
442 /// The virtual destructor
443 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
445 /// Returns an object
446 MODELAPI_EXPORT ObjectPtr object() const;
448 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
451 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
452 class ModelAPI_SolverFailedMessage : public Events_Message
455 /// Creates an message
456 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
457 /// Default destructor
458 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
460 /// Sets list of conflicting constraints
461 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
462 /// Returns list of conflicting constraints
463 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
465 /// Sets degrees of freedom
466 void dof(const int theDOF) { myDOF = theDOF; }
467 /// Returns degrees of freedom
468 const int& dof() const { return myDOF; }
471 std::set<ObjectPtr> myObjects;
475 /// Message sent when feature or attribute has been moved.
476 /// Stores the moving object/attribute, original and new positions of mouse.
477 class ModelAPI_ObjectMovedMessage : public Events_Message
479 ObjectPtr myMovedObject;
480 AttributePtr myMovedAttribute;
482 std::shared_ptr<GeomAPI_Pnt2d> myOriginalPosition;
483 std::shared_ptr<GeomAPI_Pnt2d> myCurrentPosition;
486 MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0);
488 /// Set object which is being moved (if the message already contains attribute it will be cleared)
489 MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject);
490 /// Set attribute which is being moved (if the message already contains object it will be cleared)
491 MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute);
493 /// Return moved object
494 ObjectPtr movedObject() const
495 { return myMovedObject; }
496 /// Return moved attribute
497 AttributePtr movedAttribute() const
498 { return myMovedAttribute; }
500 /// Set original mouse position
501 MODELAPI_EXPORT void setOriginalPosition(double theX, double theY);
502 /// Set original mouse position
503 MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
504 /// Return original mouse position
505 const std::shared_ptr<GeomAPI_Pnt2d>& originalPosition() const
506 { return myOriginalPosition; }
508 /// Set current mouse position
509 MODELAPI_EXPORT void setCurrentPosition(double theX, double theY);
510 /// Set current mouse position
511 MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
512 /// Return current mouse position
513 const std::shared_ptr<GeomAPI_Pnt2d>& currentPosition() const
514 { return myCurrentPosition; }