]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Events.h
Salome HOME
Debug of naming of Boolean operation of extrusion and revolution results.
[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 visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
38 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
39 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
40 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
41 //
42 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
43
44 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
45 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
46
47
48 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
49 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
50
51 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
52 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
53
54 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
55 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
56 {
57  protected:
58   /// Creates an empty message
59   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
60   /// The virtual destructor
61   virtual ~ModelAPI_ObjectUpdatedMessage();
62
63  public:
64   /// Returns the feature that has been updated
65   virtual const std::set<ObjectPtr>& objects() const = 0;
66
67   //! Creates a new empty group (to store it in the loop before flush)
68   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
69
70   //! Allows to join the given message with the current one
71   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
72 };
73
74 /// Message that feature was deleted (used for Object Browser update)
75 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
76 {
77 protected:
78   /// Creates an empty message
79   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
80   /// The virtual destructor
81   virtual ~ModelAPI_ObjectDeletedMessage();
82
83 public:
84   /// Returns the feature that has been updated
85   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
86
87   /// Returns the group where the feature was deleted
88   virtual const std::set<std::string>& groups() const = 0;
89
90   /// Creates the new empty message of this kind
91   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
92
93   /// Returns the identifier of the kind of a message
94   virtual const Events_ID messageId() = 0;
95
96   /// Appenad to this message the given one.
97   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
98 };
99
100 /// Allows to create ModelAPI messages
101 class MODELAPI_EXPORT ModelAPI_EventCreator
102 {
103 public:
104   /// creates created, updated or moved messages and sends to the loop
105   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
106                            const bool isGroupped = true) const = 0;
107   /// creates deleted message and sends to the loop
108   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
109                            const std::string& theGroup) const = 0;
110
111   /// returns the creator instance
112   static const ModelAPI_EventCreator* get();
113
114   /// sets the creator instance
115   static void set(const ModelAPI_EventCreator* theCreator);
116 };
117
118 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
119 /// Contains the state information about the feature: is it enabled or disabled.
120 class ModelAPI_FeatureStateMessage : public Events_Message
121 {
122 public:
123   /// Creates an empty message
124   MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
125   /// The virtual destructor
126   MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
127
128   /// Returns the feature this message is related to
129   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
130   /// Stores the feature this message is related to
131   MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
132   // For response
133   /// Returns true if feature has specific state
134   MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
135   /// Returns true if feature is enabled
136   MODELAPI_EXPORT bool state(const  std::string& theFeatureId, bool theDefault = false) const;
137   /// Stores the feature state
138   MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
139   /// Returns all feature IDs with states
140   MODELAPI_EXPORT std::list<std::string> features() const;
141
142  private:
143   /// For Request
144   std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
145   /// For response
146   std::map<std::string, bool> myFeatureState;
147 };
148
149 /// Message that document (Part, PartSet) was created
150 class ModelAPI_DocumentCreatedMessage : public Events_Message
151 {
152   DocumentPtr myDocument;
153
154  public:
155   /// Creates an empty message
156   MODELAPI_EXPORT ModelAPI_DocumentCreatedMessage(const Events_ID theID, const void* theSender = 0);
157   /// The virtual destructor
158   MODELAPI_EXPORT virtual ~ModelAPI_DocumentCreatedMessage();
159   /// Static. Returns EventID of the message.
160   MODELAPI_EXPORT static Events_ID eventId()
161   {
162     static const char * MY_DOCUMENT_CREATED_EVENT_ID("DocumentCreated");
163     return Events_Loop::eventByName(MY_DOCUMENT_CREATED_EVENT_ID);
164   }
165
166   /// Returns a document stored in the message
167   MODELAPI_EXPORT DocumentPtr document() const;
168   /// Sets a document to the message
169   MODELAPI_EXPORT void setDocument(DocumentPtr theDocument);
170 };
171
172 /// Message that attribute text should be evaluated in the attribute value
173 class ModelAPI_AttributeEvalMessage : public Events_Message
174 {
175   AttributePtr myAttribute;
176
177  public:
178   /// Static. Returns EventID of the message.
179   MODELAPI_EXPORT static Events_ID& eventId()
180   {
181     static const char * MY_ATTRIBUTE_EVALUATION_EVENT_ID("AttributeEvaluationRequest");
182     static Events_ID anId = Events_Loop::eventByName(MY_ATTRIBUTE_EVALUATION_EVENT_ID);
183     return anId;
184   }
185
186   /// Useful method that creates and sends the AttributeEvalMessage event
187   MODELAPI_EXPORT static void send(AttributePtr theAttribute, const void* theSender)
188   {
189     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
190       std::shared_ptr<ModelAPI_AttributeEvalMessage>(
191       new ModelAPI_AttributeEvalMessage(eventId(), theSender));
192     aMessage->setAttribute(theAttribute);
193     Events_Loop::loop()->send(aMessage);
194   }
195
196   /// Creates an empty message
197   MODELAPI_EXPORT ModelAPI_AttributeEvalMessage(const Events_ID theID, const void* theSender = 0);
198   /// The virtual destructor
199   MODELAPI_EXPORT virtual ~ModelAPI_AttributeEvalMessage();
200
201   /// Returns a document stored in the message
202   MODELAPI_EXPORT AttributePtr attribute() const;
203   /// Sets an attribute to the message
204   MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
205 };
206
207 /// Message that the object is renamed
208 class ModelAPI_ObjectRenamedMessage : public Events_Message
209 {
210   ObjectPtr myObject;
211   std::string myOldName;
212   std::string myNewName;
213
214  public:
215   /// Static. Returns EventID of the message.
216   MODELAPI_EXPORT static Events_ID& eventId()
217   {
218     static const char * MY_OBJECT_RENAMED_EVENT_ID("ObjectRenamed");
219     static Events_ID anId = Events_Loop::eventByName(MY_OBJECT_RENAMED_EVENT_ID);
220     return anId;
221   }
222
223   /// Useful method that creates and sends the AttributeEvalMessage event
224   MODELAPI_EXPORT static void send(ObjectPtr theObject,
225                                    const std::string& theOldName,
226                                    const std::string& theNewName,
227                                    const void* theSender);
228
229   /// Creates an empty message
230   MODELAPI_EXPORT ModelAPI_ObjectRenamedMessage(const Events_ID theID, const void* theSender = 0);
231   /// The virtual destructor
232   MODELAPI_EXPORT virtual ~ModelAPI_ObjectRenamedMessage();
233
234   /// Returns an object
235   MODELAPI_EXPORT ObjectPtr object() const;
236   /// Sets an object
237   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
238   /// Returns an old name
239   MODELAPI_EXPORT std::string oldName() const;
240   /// Sets an old name
241   MODELAPI_EXPORT void setOldName(const std::string& theOldName);
242   /// Returns a new name
243   MODELAPI_EXPORT std::string newName() const;
244   /// Sets a new name
245   MODELAPI_EXPORT void setNewName(const std::string& theNewName);
246 };
247
248 #endif