Salome HOME
#1721 Selecting arcs in mirror constraint is too long and removes other edges
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Events.h
4 // Created:     10 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef MODELAPI_EVENTS_H_
8 #define MODELAPI_EVENTS_H_
9
10 #include <ModelAPI.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>
16
17 #include <memory>
18 #include <string>
19 #include <set>
20 #include <map>
21
22
23 class ModelAPI_Document;
24
25 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
26 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
27 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
28 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
29 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
30 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
31 /// Event ID that name of feature is changed (comes with Model_ObjectRenamedMessage)
32 static const char * EVENT_OBJECT_RENAMED = "ObjectRenamed";
33 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
34 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
35 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
36 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
37 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
38 static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
39 //
40 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
41
42 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
43 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
44
45
46 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
47 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
48
49 static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
50 static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
51
52 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
53 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
54
55 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
56 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
57 /// Event ID that the problem in solver disappeared
58 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
59
60 /// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
61 static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
62
63 /// Event ID that informs that some object has changed the stability
64 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
65
66 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
67 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
68 {
69  protected:
70   /// Creates an empty message
71   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
72   /// The virtual destructor
73   virtual ~ModelAPI_ObjectUpdatedMessage();
74
75  public:
76   /// Returns the feature that has been updated
77   virtual const std::set<ObjectPtr>& objects() const = 0;
78
79   //! Creates a new empty group (to store it in the loop before flush)
80   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
81
82   //! Allows to join the given message with the current one
83   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
84 };
85
86 /// Message that feature was deleted (used for Object Browser update)
87 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
88 {
89 protected:
90   /// Creates an empty message
91   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
92   /// The virtual destructor
93   virtual ~ModelAPI_ObjectDeletedMessage();
94
95 public:
96   /// Returns the document that has been updated
97   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
98
99   /// Returns the groups where the objects were deleted
100   virtual const std::set<std::string>& groups() const = 0;
101
102   /// Creates the new empty message of this kind
103   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
104
105   /// Returns the identifier of the kind of a message
106   virtual const Events_ID messageId() = 0;
107
108   /// Appenad to this message the given one.
109   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
110 };
111
112 /// Message that order changed (used for Object Browser update)
113 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
114 {
115 protected:
116   /// Creates a message: 
117   ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
118   /// The virtual destructor
119   virtual ~ModelAPI_OrderUpdatedMessage();
120
121 public:
122   /// Returns the document that has been updated
123   virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
124
125   /// Returns the identifier of the kind of a message
126   virtual const Events_ID messageId() = 0;
127 };
128
129 /// Allows to create ModelAPI messages
130 class MODELAPI_EXPORT ModelAPI_EventCreator
131 {
132 public:
133   /// creates created, updated or moved messages and sends to the loop
134   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
135                            const bool isGroupped = true) const = 0;
136   /// creates deleted message and sends to the loop
137   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
138                            const std::string& theGroup) const = 0;
139   /// creates reordered message and sends to the loop
140   virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
141
142   /// returns the creator instance
143   static const ModelAPI_EventCreator* get();
144
145   /// sets the creator instance
146   static void set(const ModelAPI_EventCreator* theCreator);
147 };
148
149 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
150 /// Contains the state information about the feature: is it enabled or disabled.
151 class ModelAPI_FeatureStateMessage : public Events_Message
152 {
153 public:
154   /// Creates an empty message
155   MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
156   /// The virtual destructor
157   MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
158
159   /// Returns the feature this message is related to
160   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
161   /// Stores the feature this message is related to
162   MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
163   // For response
164   /// Returns true if feature has specific state
165   MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
166   /// Returns true if feature is enabled
167   MODELAPI_EXPORT bool state(const  std::string& theFeatureId, bool theDefault = false) const;
168   /// Stores the feature state
169   MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
170   /// Returns all feature IDs with states
171   MODELAPI_EXPORT std::list<std::string> features() const;
172
173  private:
174   /// For Request
175   std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
176   /// For response
177   std::map<std::string, bool> myFeatureState;
178 };
179
180 /// Message that document (Part, PartSet) was created
181 class ModelAPI_DocumentCreatedMessage : public Events_Message
182 {
183   DocumentPtr myDocument;
184
185  public:
186   /// Creates an empty message
187   MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
188   /// The virtual destructor
189   MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
190   /// Static. Returns EventID of the message.
191   MODELAPI_EXPORT static Events_ID eventId()
192   {
193     static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
194     return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
195   }
196
197   /// Returns a document stored in the message
198   MODELAPI_EXPORT DocumentPtr document() const;
199   /// Sets a document to the message
200   MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
201 };
202
203 /// Message that attribute text should be evaluated in the attribute value
204 class ModelAPI_AttributeEvalMessage : public Events_Message
205 {
206   AttributePtr myAttribute;
207
208  public:
209   /// Static. Returns EventID of the message.
210   MODELAPI_EXPORT static Events_ID& eventId()
211   {
212     static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
213     static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
214     return anId;
215   }
216
217   /// Useful method that creates and sends the AttributeEvalMessage event
218   MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
219   {
220     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
221       std::shared_ptr<ModelAPI_AttributeEvalMessage>(
222       new ModelAPI_AttributeEvalMessage(eventId(), theSender));
223     aMessage->setAttribute(theAttribute);
224     Events_Loop::loop()->send(aMessage);
225   }
226
227   /// Creates an empty message
228   MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
229   /// The virtual destructor
230   MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
231
232   /// Returns a document stored in the message
233   MODELAPI_EXPORT AttributePtr attribute() const;
234   /// Sets an attribute to the message
235   MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
236 };
237
238 /// Message that the object is renamed
239 class ModelAPI_ObjectRenamedMessage : public Events_Message
240 {
241   ObjectPtr myObject;
242   std::string myOldName;
243   std::string myNewName;
244
245  public:
246   /// Static. Returns EventID of the message.
247   MODELAPI_EXPORT static Events_ID& eventId()
248   {
249     static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
250     static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
251     return anId;
252   }
253
254   /// Useful method that creates and sends the AttributeEvalMessage event
255   MODELAPI_EXPORT static void send(ObjectPtr theObject,
256                                    const std::string& theOldName,
257                                    const std::string& theNewName,
258                                    const void* theSender);
259
260   /// Creates an empty message
261   MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
262   /// The virtual destructor
263   MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
264
265   /// Returns an object
266   MODELAPI_EXPORT ObjectPtr object() const;
267   /// Sets an object
268   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
269   /// Returns an old name
270   MODELAPI_EXPORT std::string oldName() const;
271   /// Sets an old name
272   MODELAPI_EXPORT void setOldName(const std::string& theOldName);
273   /// Returns a new name
274   MODELAPI_EXPORT std::string newName() const;
275   /// Sets a new name
276   MODELAPI_EXPORT void setNewName(const std::string& theNewName);
277 };
278
279 /// Message that the parameter should be replaced with its value
280 class ModelAPI_ReplaceParameterMessage : public Events_Message
281 {
282   ObjectPtr myObject;
283
284  public:
285   /// Static. Returns EventID of the message.
286   MODELAPI_EXPORT static Events_ID& eventId()
287   {
288     static const char * MY_EVENT_ID("ReplaceParameter");
289     static Events_ID anId = Events_Loop::eventByName(MY_EVENT_ID);
290     return anId;
291   }
292
293   /// Useful method that creates and sends the AttributeEvalMessage event
294   MODELAPI_EXPORT static void send(ObjectPtr theObject,
295                                    const void* theSender);
296
297   /// Creates an empty message
298   MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
299   /// The virtual destructor
300   MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
301
302   /// Returns an object
303   MODELAPI_EXPORT ObjectPtr object() const;
304   /// Sets an object
305   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
306 };
307
308 /// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
309 class ModelAPI_SolverFailedMessage : public Events_Message
310 {
311 public:
312   /// Creates an message
313   MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
314   /// Default destructor
315   MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
316
317   /// Sets list of conflicting constraints
318   MODELAPI_EXPORT void setObjects(const std::set<ObjectPtr>& theObjects);
319   /// Returns list of conflicting constraints
320   MODELAPI_EXPORT const std::set<ObjectPtr>& objects() const;
321
322   /// Sets degrees of freedom
323   void dof(const int theDOF) { myDOF = theDOF; }
324   /// Returns degrees of freedom
325   const int& dof() const { return myDOF; }
326
327 private:
328   std::set<ObjectPtr> myObjects;
329   int myDOF;
330 };
331
332 #endif