Salome HOME
fb94001b86aa83d13717f28861f40b63181da385
[modules/shaper.git] / src / Model / Model_Events.cpp
1 // File:        Model_Events.cxx
2 // Created:     10 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <Model_Events.h>
6 #include <Events_Loop.h>
7
8 /// Alone instance of the creator per application
9 Model_EventCreator MY_CREATOR;
10
11 /////////////////////// CREATOR /////////////////////////////
12 void Model_EventCreator::sendUpdated(
13   const FeaturePtr& theFeature, const Events_ID& theEvent, const bool isGroupped) const
14 {
15   Model_FeatureUpdatedMessage aMsg(theFeature, theEvent);
16   Events_Loop::loop()->send(aMsg, isGroupped);
17 }
18
19 void Model_EventCreator::sendDeleted(
20   const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const
21 {
22   Model_FeatureDeletedMessage aMsg(theDoc, theGroup);
23   Events_Loop::loop()->send(aMsg, true);
24 }
25
26 Model_EventCreator::Model_EventCreator()
27 {
28   ModelAPI_EventCreator::set(this);
29 }
30
31 /////////////////////// UPDATED MESSAGE /////////////////////////////
32 Model_FeatureUpdatedMessage::Model_FeatureUpdatedMessage(
33   const FeaturePtr& theFeature,
34   const Events_ID& theEvent) : ModelAPI_FeatureUpdatedMessage(theEvent, 0)
35 {
36   if (theFeature) myFeatures.insert(theFeature);
37 }
38
39 std::set<FeaturePtr> Model_FeatureUpdatedMessage::features() const 
40 {
41   return myFeatures;
42 }
43
44 Events_MessageGroup* Model_FeatureUpdatedMessage::newEmpty() 
45 {
46   FeaturePtr anEmptyFeature;
47   return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
48 }
49
50 void Model_FeatureUpdatedMessage::Join(Events_MessageGroup& theJoined) 
51 {
52   Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
53   std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
54   for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
55     myFeatures.insert(*aFIter);
56   }
57 }
58
59 /////////////////////// DELETED MESSAGE /////////////////////////////
60 Model_FeatureDeletedMessage::Model_FeatureDeletedMessage(
61   const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
62   : ModelAPI_FeatureDeletedMessage(messageId(), 0), myDoc(theDoc)
63 {
64   if (!theGroup.empty())
65     myGroups.insert(theGroup);
66 }
67
68 Events_MessageGroup* Model_FeatureDeletedMessage::newEmpty() 
69 {
70   return new Model_FeatureDeletedMessage(myDoc, "");
71 }
72
73 const Events_ID Model_FeatureDeletedMessage::messageId()
74 {
75   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
76   return MY_ID;
77 }
78
79 void Model_FeatureDeletedMessage::Join(Events_MessageGroup& theJoined)
80 {
81   Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
82   std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
83   for(; aGIter != aJoined->myGroups.end(); aGIter++) {
84     myGroups.insert(*aGIter);
85   }
86 }