]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Events.h
Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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 <Events_MessageGroup.h>
14
15 #include <memory>
16 #include <string>
17 #include <set>
18 #include <map>
19
20
21 class ModelAPI_Document;
22
23 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
24 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
25 /// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
26 static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
27 /// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
28 static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
29 /// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
30 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
31 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
32 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
33 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
34 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
35 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
36 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
37 /// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
38 static const char * EVENT_OBJECT_TOSHOW = "ObjectShow";
39 /// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
40 static const char * EVENT_OBJECT_TOHIDE = "ObjectHide";
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 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
48 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
49 {
50  protected:
51   ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0);
52   virtual ~ModelAPI_ObjectUpdatedMessage();
53
54  public:
55   /// Returns the feature that has been updated
56   virtual const std::set<ObjectPtr>& objects() const = 0;
57
58   //! Creates a new empty group (to store it in the loop before flush)
59   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
60
61   //! Allows to join the given message with the current one
62   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
63 };
64
65 /// Message that feature was deleted (used for Object Browser update)
66 class MODELAPI_EXPORT ModelAPI_ObjectDeletedMessage : public Events_MessageGroup
67 {
68  protected:
69   ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0);
70   virtual ~ModelAPI_ObjectDeletedMessage();
71
72  public:
73   /// Returns the feature that has been updated
74   virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
75
76   /// Returns the group where the feature was deleted
77   virtual const std::set<std::string>& groups() const = 0;
78
79   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
80
81   virtual const Events_ID messageId() = 0;
82
83   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
84 };
85
86 /// Allows to create ModelAPI messages
87 class MODELAPI_EXPORT ModelAPI_EventCreator
88 {
89  public:
90   /// creates created, updated or moved messages and sends to the loop
91   virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
92                            const bool isGroupped = true) const = 0;
93   /// creates deleted message and sends to the loop
94   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
95                            const std::string& theGroup) const = 0;
96
97   /// returns the creator instance
98   static const ModelAPI_EventCreator* get();
99
100   /// sets the creator instance
101   static void set(const ModelAPI_EventCreator* theCreator);
102 };
103
104 // TODO(sbh): Move this message into a separate package, like "GuiAPI"
105 class ModelAPI_FeatureStateMessage : public Events_Message
106 {
107  public:
108   MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
109   MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
110
111   // For request
112   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
113   MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
114   // For response
115   MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
116   MODELAPI_EXPORT bool state(const  std::string& theFeatureId, bool theDefault = false) const;
117   MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
118   MODELAPI_EXPORT std::list<std::string> features() const;
119
120  private:
121   // For Request
122   std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
123   // For response
124   std::map<std::string, bool> myFeatureState;
125 };
126
127 #endif