Salome HOME
Ability for plugins to manage state (on/off) of their features added
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModelAPI_Events.cpp
5  *
6  *  Created on: Dec 8, 2014
7  *      Author: sbh
8  */
9
10 #include <ModelAPI.h>
11 #include <ModelAPI_Events.h>
12
13 ModelAPI_ObjectUpdatedMessage::ModelAPI_ObjectUpdatedMessage(const Events_ID theID,
14                                                              const void* theSender)
15     : Events_MessageGroup(theID, theSender)
16 {
17
18 }
19
20 ModelAPI_ObjectUpdatedMessage::~ModelAPI_ObjectUpdatedMessage()
21 {
22
23 }
24
25 ModelAPI_ObjectDeletedMessage::ModelAPI_ObjectDeletedMessage(const Events_ID theID,
26                                                              const void* theSender)
27     : Events_MessageGroup(theID, theSender)
28 {
29
30 }
31
32 ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
33 {
34
35 }
36
37 ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
38                                                            const void* theSender)
39  : Events_Message(theID, theSender)
40 {
41   myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
42 }
43
44 ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
45 {
46
47 }
48
49 std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
50 {
51   return myCurrentFeature;
52 }
53
54 void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
55 {
56   myCurrentFeature = theFeature;
57 }
58
59 bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
60 {
61   return myFeatureState.find(theKey) != myFeatureState.end();
62 }
63
64 bool ModelAPI_FeatureStateMessage::state(const  std::string& theFeatureId, bool theDefault) const
65 {
66   if(hasState(theFeatureId)) {
67     return myFeatureState.at(theFeatureId);
68   }
69   return theDefault;
70 }
71
72 void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
73 {
74   myFeatureState[theFeatureId] = theValue;
75 }
76
77 std::list<std::string> ModelAPI_FeatureStateMessage::features() const
78 {
79   std::list<std::string> result;
80   std::map<std::string, bool>::const_iterator it = myFeatureState.begin();
81   for( ; it != myFeatureState.end(); ++it) {
82     result.push_back(it->first);
83   }
84   return result;
85 }
86