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 rectreated (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";
83 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
84 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
85 /// Event ID that the problem in solver disappeared
86 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
88 /// Event Id that sketch has DoF = 0
89 static const char * EVENT_SKETCH_FULLY_CONSTRAINED = "SketchFullyConstrainted";
90 /// Event Id that sketch has DoF > 0
91 static const char * EVENT_SKETCH_UNDER_CONSTRAINED = "SketchUnderConstrainted";
92 /// Event Id that sketch has DoF < 0
93 static const char * EVENT_SKETCH_OVER_CONSTRAINED = "SketchOverConstrainted";
95 /// Event ID that informs that some object has changed the stability
96 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
98 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
99 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
101 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
102 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
105 /// Creates an empty message
106 ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
107 /// The virtual destructor
108 virtual ~ModelAPI_ObjectUpdatedMessage();
111 /// Returns the feature that has been updated
112 virtual const std::set<ObjectPtr>& objects() const = 0;
114 //! Creates a new empty group (to store it in the loop before flush)
115 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
117 //! Allows to join the given message with the current one
118 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
121 /// Message that feature was deleted (used for Object Browser update)
122 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
125 /// Creates an empty message
126 ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
127 /// The virtual destructor
128 virtual ~ModelAPI_ObjectDeletedMessage();
131 /// Returns the document that has been updated
132 virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
134 /// Returns the groups where the objects were deleted
135 virtual const std::set<std::string>& groups() const = 0;
137 /// Creates the new empty message of this kind
138 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
140 /// Returns the identifier of the kind of a message
141 virtual const Events_ID messageId() = 0;
143 /// Appenad to this message the given one.
144 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
147 /// Message that order changed (used for Object Browser update)
148 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
151 /// Creates a message:
152 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
153 /// The virtual destructor
154 virtual ~ModelAPI_OrderUpdatedMessage();
157 /// Returns the document that has been updated
158 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
160 /// Returns the identifier of the kind of a message
161 virtual const Events_ID messageId() = 0;
164 /// Allows to create ModelAPI messages
165 class MODELAPI_EXPORT ModelAPI_EventCreator
168 /// creates created, updated or moved messages and sends to the loop
169 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
170 const bool isGroupped = true) const = 0;
171 /// creates deleted message and sends to the loop
172 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
173 const std::string& theGroup) const = 0;
174 /// creates reordered message and sends to the loop
175 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
177 /// returns the creator instance
178 static const ModelAPI_EventCreator* get();
180 /// sets the creator instance
181 static void set(const ModelAPI_EventCreator* theCreator);
184 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
185 /// Contains the state information about the feature: is it enabled or disabled.
186 class ModelAPI_FeatureStateMessage : public Events_Message
189 /// Creates an empty message
190 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
191 /// The virtual destructor
192 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
194 /// Returns the feature this message is related to
195 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
196 /// Stores the feature this message is related to
197 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
199 /// Returns true if feature has specific state
200 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
201 /// Returns true if feature is enabled
202 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
203 /// Stores the feature state
204 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
205 /// Returns all feature IDs with states
206 MODELAPI_EXPORT std::list<std::string> features() const;
210 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
212 std::map<std::string, bool> myFeatureState;
215 /// Message that document (Part, PartSet) was created
216 class ModelAPI_DocumentCreatedMessage : public Events_Message
218 DocumentPtr myDocument;
221 /// Creates an empty message
222 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
223 /// The virtual destructor
224 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
225 /// Static. Returns EventID of the message.
226 MODELAPI_EXPORT static Events_ID eventId()
228 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
229 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
232 /// Returns a document stored in the message
233 MODELAPI_EXPORT DocumentPtr document() const;
234 /// Sets a document to the message
235 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
238 /// Message that attribute text should be evaluated in the attribute value
239 class ModelAPI_AttributeEvalMessage : public Events_Message
241 AttributePtr myAttribute;
244 /// Static. Returns EventID of the message.
245 MODELAPI_EXPORT static Events_ID& eventId()
247 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
248 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
252 /// Useful method that creates and sends the AttributeEvalMessage event
253 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
255 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
256 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
257 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
258 aMessage->setAttribute(theAttribute);
259 Events_Loop::loop()->send(aMessage);
262 /// Creates an empty message
263 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
264 /// The virtual destructor
265 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
267 /// Returns a document stored in the message
268 MODELAPI_EXPORT AttributePtr attribute() const;
269 /// Sets an attribute to the message
270 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
273 /// Message that parameter feature expression should be evaluated: value and error producing
274 class ModelAPI_ParameterEvalMessage : public Events_Message
276 FeaturePtr myParam; ///< parameters that should be evaluated
277 bool myIsProcessed; ///< true if results were set
278 /// result of processing, list of parameters in expression found
279 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
280 double myResult; ///< result of processing, the computed value of the expression
281 std::string myError; ///< error of processing, empty if there is no error
284 /// Static. Returns EventID of the message.
285 MODELAPI_EXPORT static Events_ID& eventId()
287 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
288 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
292 /// Useful method that creates and sends the event.
293 /// Returns the message, processed, with the resulting fields filled.
294 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
295 send(FeaturePtr theParameter, const void* theSender)
297 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
298 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
299 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
300 aMessage->setParameter(theParameter);
301 Events_Loop::loop()->send(aMessage);
305 /// Creates an empty message
306 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
307 /// The virtual destructor
308 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
310 /// Returns a parameter stored in the message
311 MODELAPI_EXPORT FeaturePtr parameter() const;
312 /// Sets a parameter to the message
313 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
314 /// Sets the results of processing
315 MODELAPI_EXPORT void setResults(
316 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
317 const double theResult, const std::string& theError);
318 /// Returns true if the expression is processed
319 MODELAPI_EXPORT bool isProcessed();
320 /// Returns the results of processing: list of parameters found in the expression
321 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
322 /// Returns the expression result
323 MODELAPI_EXPORT const double& result() const;
324 /// Returns the interpreter error (empty if no error)
325 MODELAPI_EXPORT const std::string& error() const;
329 /// Message to ask compute the positions of parameters in the expression
330 class ModelAPI_ComputePositionsMessage : public Events_Message
332 std::string myExpression; ///< the expression string
333 std::string myParamName; ///< name of the parameter to be searched
334 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
337 /// Static. Returns EventID of the message.
338 MODELAPI_EXPORT static Events_ID& eventId()
340 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
341 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
345 /// Useful method that creates and sends the AttributeEvalMessage event
346 /// Returns the message, processed, with the resulting fields filled
347 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
348 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
350 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
351 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
352 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
353 aMessage->set(theExpression, theParameter);
354 Events_Loop::loop()->send(aMessage);
358 /// Creates an empty message
359 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
360 const Events_ID theID, const void* theSender = 0);
361 /// The virtual destructor
362 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
364 /// Returns an expression stored in the message
365 MODELAPI_EXPORT const std::string& expression() const;
366 /// Returns a parameter name stored in the message
367 MODELAPI_EXPORT const std::string& parameter() const;
368 /// Sets an expression and parameter needed for computation
369 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
370 /// Sets the results of processing
371 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
372 /// Returns the results of processing: position start and end indices
373 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
376 /// Message that the object is renamed
377 class ModelAPI_ObjectRenamedMessage : public Events_Message
380 std::string myOldName;
381 std::string myNewName;
384 /// Static. Returns EventID of the message.
385 MODELAPI_EXPORT static Events_ID& eventId()
387 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
388 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
392 /// Useful method that creates and sends the AttributeEvalMessage event
393 MODELAPI_EXPORT static void send(ObjectPtr theObject,
394 const std::string& theOldName,
395 const std::string& theNewName,
396 const void* theSender);
398 /// Creates an empty message
399 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
400 /// The virtual destructor
401 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
403 /// Returns an object
404 MODELAPI_EXPORT ObjectPtr object() const;
406 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
407 /// Returns an old name
408 MODELAPI_EXPORT std::string oldName() const;
410 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
411 /// Returns a new name
412 MODELAPI_EXPORT std::string newName() const;
414 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
417 /// Message that the parameter should be replaced with its value
418 class ModelAPI_ReplaceParameterMessage : public Events_Message
423 /// Static. Returns EventID of the message.
424 MODELAPI_EXPORT static Events_ID& eventId()
426 static const char * MY_EVENT_ID("ReplaceParameter");
427 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
431 /// Useful method that creates and sends the AttributeEvalMessage event
432 MODELAPI_EXPORT static void send(ObjectPtr theObject,
433 const void* theSender);
435 /// Creates an empty message
437 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
438 /// The virtual destructor
439 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
441 /// Returns an object
442 MODELAPI_EXPORT ObjectPtr object() const;
444 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
447 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
448 class ModelAPI_SolverFailedMessage : public Events_Message
451 /// Creates an message
452 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
453 /// Default destructor
454 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
456 /// Sets list of conflicting constraints
457 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
458 /// Returns list of conflicting constraints
459 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
461 /// Sets degrees of freedom
462 void dof(const int theDOF) { myDOF = theDOF; }
463 /// Returns degrees of freedom
464 const int& dof() const { return myDOF; }
467 std::set<ObjectPtr> myObjects;
471 /// Message sent when feature or attrubute has been moved.
472 /// Stores the moving object/attribute, original and new positions of mouse.
473 class ModelAPI_ObjectMovedMessage : public Events_Message
475 ObjectPtr myMovedObject;
476 AttributePtr myMovedAttribute;
478 std::shared_ptr<GeomAPI_Pnt2d> myOriginalPosition;
479 std::shared_ptr<GeomAPI_Pnt2d> myCurrentPosition;
482 MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0);
484 /// Set object which is being moved (if the message already contains attribute it will be cleared)
485 MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject);
486 /// Set attribute which is being moved (if the message already contains object it will be cleared)
487 MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute);
489 /// Return moved object
490 ObjectPtr movedObject() const
491 { return myMovedObject; }
492 /// Return moved attribute
493 AttributePtr movedAttribute() const
494 { return myMovedAttribute; }
496 /// Set original mouse position
497 MODELAPI_EXPORT void setOriginalPosition(double theX, double theY);
498 /// Set original mouse position
499 MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
500 /// Return original mouse position
501 const std::shared_ptr<GeomAPI_Pnt2d>& originalPosition() const
502 { return myOriginalPosition; }
504 /// Set current mouse position
505 MODELAPI_EXPORT void setCurrentPosition(double theX, double theY);
506 /// Set current mouse position
507 MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
508 /// Return current mouse position
509 const std::shared_ptr<GeomAPI_Pnt2d>& currentPosition() const
510 { return myCurrentPosition; }