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 groups where the objects were deleted
132 virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
135 /// Creates the new empty message of this kind
136 virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
138 /// Returns the identifier of the kind of a message
139 virtual const Events_ID messageId() = 0;
141 /// Appenad to this message the given one.
142 virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
145 /// Message that order changed (used for Object Browser update)
146 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
149 /// Creates a message:
150 ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
151 /// The virtual destructor
152 virtual ~ModelAPI_OrderUpdatedMessage();
155 /// Returns the document that has been updated
156 virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
158 /// Returns the identifier of the kind of a message
159 virtual const Events_ID messageId() = 0;
162 /// Allows to create ModelAPI messages
163 class MODELAPI_EXPORT ModelAPI_EventCreator
166 /// creates created, updated or moved messages and sends to the loop
167 virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
168 const bool isGroupped = true) const = 0;
169 /// creates deleted message and sends to the loop
170 virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
171 const std::string& theGroup) const = 0;
172 /// creates reordered message and sends to the loop
173 virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
175 /// returns the creator instance
176 static const ModelAPI_EventCreator* get();
178 /// sets the creator instance
179 static void set(const ModelAPI_EventCreator* theCreator);
182 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
183 /// Contains the state information about the feature: is it enabled or disabled.
184 class ModelAPI_FeatureStateMessage : public Events_Message
187 /// Creates an empty message
188 MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
189 /// The virtual destructor
190 MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
192 /// Returns the feature this message is related to
193 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
194 /// Stores the feature this message is related to
195 MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
197 /// Returns true if feature has specific state
198 MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
199 /// Returns true if feature is enabled
200 MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
201 /// Stores the feature state
202 MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
203 /// Returns all feature IDs with states
204 MODELAPI_EXPORT std::list<std::string> features() const;
208 std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
210 std::map<std::string, bool> myFeatureState;
213 /// Message that document (Part, PartSet) was created
214 class ModelAPI_DocumentCreatedMessage : public Events_Message
216 DocumentPtr myDocument;
219 /// Creates an empty message
220 MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
221 /// The virtual destructor
222 MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
223 /// Static. Returns EventID of the message.
224 MODELAPI_EXPORT static Events_ID eventId()
226 static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
227 return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
230 /// Returns a document stored in the message
231 MODELAPI_EXPORT DocumentPtr document() const;
232 /// Sets a document to the message
233 MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
236 /// Message that attribute text should be evaluated in the attribute value
237 class ModelAPI_AttributeEvalMessage : public Events_Message
239 AttributePtr myAttribute;
242 /// Static. Returns EventID of the message.
243 MODELAPI_EXPORT static Events_ID& eventId()
245 static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
246 static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
250 /// Useful method that creates and sends the AttributeEvalMessage event
251 MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
253 std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
254 std::shared_ptr<ModelAPI_AttributeEvalMessage>(
255 new ModelAPI_AttributeEvalMessage(eventId(), theSender));
256 aMessage->setAttribute(theAttribute);
257 Events_Loop::loop()->send(aMessage);
260 /// Creates an empty message
261 MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
262 /// The virtual destructor
263 MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
265 /// Returns a document stored in the message
266 MODELAPI_EXPORT AttributePtr attribute() const;
267 /// Sets an attribute to the message
268 MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
271 /// Message that parameter feature expression should be evaluated: value and error producing
272 class ModelAPI_ParameterEvalMessage : public Events_Message
274 FeaturePtr myParam; ///< parameters that should be evaluated
275 bool myIsProcessed; ///< true if results were set
276 /// result of processing, list of parameters in expression found
277 std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
278 double myResult; ///< result of processing, the computed value of the expression
279 std::string myError; ///< error of processing, empty if there is no error
282 /// Static. Returns EventID of the message.
283 MODELAPI_EXPORT static Events_ID& eventId()
285 static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
286 static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
290 /// Useful method that creates and sends the event.
291 /// Returns the message, processed, with the resulting fields filled.
292 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
293 send(FeaturePtr theParameter, const void* theSender)
295 std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
296 std::shared_ptr<ModelAPI_ParameterEvalMessage>(
297 new ModelAPI_ParameterEvalMessage(eventId(), theSender));
298 aMessage->setParameter(theParameter);
299 Events_Loop::loop()->send(aMessage);
303 /// Creates an empty message
304 MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
305 /// The virtual destructor
306 MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
308 /// Returns a parameter stored in the message
309 MODELAPI_EXPORT FeaturePtr parameter() const;
310 /// Sets a parameter to the message
311 MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
312 /// Sets the results of processing
313 MODELAPI_EXPORT void setResults(
314 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
315 const double theResult, const std::string& theError);
316 /// Returns true if the expression is processed
317 MODELAPI_EXPORT bool isProcessed();
318 /// Returns the results of processing: list of parameters found in the expression
319 MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
320 /// Returns the expression result
321 MODELAPI_EXPORT const double& result() const;
322 /// Returns the interpreter error (empty if no error)
323 MODELAPI_EXPORT const std::string& error() const;
327 /// Message to ask compute the positions of parameters in the expression
328 class ModelAPI_ComputePositionsMessage : public Events_Message
330 std::string myExpression; ///< the expression string
331 std::string myParamName; ///< name of the parameter to be searched
332 std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
335 /// Static. Returns EventID of the message.
336 MODELAPI_EXPORT static Events_ID& eventId()
338 static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
339 static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
343 /// Useful method that creates and sends the AttributeEvalMessage event
344 /// Returns the message, processed, with the resulting fields filled
345 MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
346 send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
348 std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
349 std::shared_ptr<ModelAPI_ComputePositionsMessage>(
350 new ModelAPI_ComputePositionsMessage(eventId(), theSender));
351 aMessage->set(theExpression, theParameter);
352 Events_Loop::loop()->send(aMessage);
356 /// Creates an empty message
357 MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
358 const Events_ID theID, const void* theSender = 0);
359 /// The virtual destructor
360 MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
362 /// Returns an expression stored in the message
363 MODELAPI_EXPORT const std::string& expression() const;
364 /// Returns a parameter name stored in the message
365 MODELAPI_EXPORT const std::string& parameter() const;
366 /// Sets an expression and parameter needed for computation
367 MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
368 /// Sets the results of processing
369 MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
370 /// Returns the results of processing: position start and end indices
371 MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
374 /// Message that the object is renamed
375 class ModelAPI_ObjectRenamedMessage : public Events_Message
378 std::string myOldName;
379 std::string myNewName;
382 /// Static. Returns EventID of the message.
383 MODELAPI_EXPORT static Events_ID& eventId()
385 static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
386 static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
390 /// Useful method that creates and sends the AttributeEvalMessage event
391 MODELAPI_EXPORT static void send(ObjectPtr theObject,
392 const std::string& theOldName,
393 const std::string& theNewName,
394 const void* theSender);
396 /// Creates an empty message
397 MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
398 /// The virtual destructor
399 MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
401 /// Returns an object
402 MODELAPI_EXPORT ObjectPtr object() const;
404 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
405 /// Returns an old name
406 MODELAPI_EXPORT std::string oldName() const;
408 MODELAPI_EXPORT void setOldName(const std::string& theOldName);
409 /// Returns a new name
410 MODELAPI_EXPORT std::string newName() const;
412 MODELAPI_EXPORT void setNewName(const std::string& theNewName);
415 /// Message that the parameter should be replaced with its value
416 class ModelAPI_ReplaceParameterMessage : public Events_Message
421 /// Static. Returns EventID of the message.
422 MODELAPI_EXPORT static Events_ID& eventId()
424 static const char * MY_EVENT_ID("ReplaceParameter");
425 static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
429 /// Useful method that creates and sends the AttributeEvalMessage event
430 MODELAPI_EXPORT static void send(ObjectPtr theObject,
431 const void* theSender);
433 /// Creates an empty message
435 ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
436 /// The virtual destructor
437 MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
439 /// Returns an object
440 MODELAPI_EXPORT ObjectPtr object() const;
442 MODELAPI_EXPORT void setObject(ObjectPtr theObject);
445 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
446 class ModelAPI_SolverFailedMessage : public Events_Message
449 /// Creates an message
450 MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
451 /// Default destructor
452 MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
454 /// Sets list of conflicting constraints
455 MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
456 /// Returns list of conflicting constraints
457 MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
459 /// Sets degrees of freedom
460 void dof(const int theDOF) { myDOF = theDOF; }
461 /// Returns degrees of freedom
462 const int& dof() const { return myDOF; }
465 std::set<ObjectPtr> myObjects;
469 /// Message sent when feature or attrubute has been moved.
470 /// Stores the moving object/attribute, original and new positions of mouse.
471 class ModelAPI_ObjectMovedMessage : public Events_Message
473 ObjectPtr myMovedObject;
474 AttributePtr myMovedAttribute;
476 std::shared_ptr<GeomAPI_Pnt2d> myOriginalPosition;
477 std::shared_ptr<GeomAPI_Pnt2d> myCurrentPosition;
480 MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0);
482 /// Set object which is being moved (if the message already contains attribute it will be cleared)
483 MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject);
484 /// Set attribute which is being moved (if the message already contains object it will be cleared)
485 MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute);
487 /// Return moved object
488 ObjectPtr movedObject() const
489 { return myMovedObject; }
490 /// Return moved attribute
491 AttributePtr movedAttribute() const
492 { return myMovedAttribute; }
494 /// Set original mouse position
495 MODELAPI_EXPORT void setOriginalPosition(double theX, double theY);
496 /// Set original mouse position
497 MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
498 /// Return original mouse position
499 const std::shared_ptr<GeomAPI_Pnt2d>& originalPosition() const
500 { return myOriginalPosition; }
502 /// Set current mouse position
503 MODELAPI_EXPORT void setCurrentPosition(double theX, double theY);
504 /// Set current mouse position
505 MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
506 /// Return current mouse position
507 const std::shared_ptr<GeomAPI_Pnt2d>& currentPosition() const
508 { return myCurrentPosition; }