Salome HOME
Sources formated according to the codeing standards
[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(const ObjectPtr& theObject, const Events_ID& theEvent,
13                                      const bool isGroupped) const
14 {
15   Model_ObjectUpdatedMessage aMsg(theObject, theEvent);
16   Events_Loop::loop()->send(aMsg, isGroupped);
17 }
18
19 void Model_EventCreator::sendDeleted(const boost::shared_ptr<ModelAPI_Document>& theDoc,
20                                      const std::string& theGroup) const
21 {
22   Model_ObjectDeletedMessage 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_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
33                                                        const Events_ID& theEvent)
34     : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
35 {
36   if (theObject)
37     myObjects.insert(theObject);
38 }
39
40 std::set<ObjectPtr> Model_ObjectUpdatedMessage::objects() const
41 {
42   return myObjects;
43 }
44
45 Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty()
46 {
47   ObjectPtr anEmptyObject;
48   return new Model_ObjectUpdatedMessage(anEmptyObject, eventID());
49 }
50
51 void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined)
52 {
53   Model_ObjectUpdatedMessage* aJoined = dynamic_cast<Model_ObjectUpdatedMessage*>(&theJoined);
54   std::set<ObjectPtr>::iterator aFIter = aJoined->myObjects.begin();
55   for (; aFIter != aJoined->myObjects.end(); aFIter++) {
56     myObjects.insert(*aFIter);
57   }
58 }
59
60 /////////////////////// DELETED MESSAGE /////////////////////////////
61 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
62     const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
63     : ModelAPI_ObjectDeletedMessage(messageId(), 0),
64       myDoc(theDoc)
65 {
66   if (!theGroup.empty())
67     myGroups.insert(theGroup);
68 }
69
70 Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty()
71 {
72   return new Model_ObjectDeletedMessage(myDoc, "");
73 }
74
75 const Events_ID Model_ObjectDeletedMessage::messageId()
76 {
77   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
78   return MY_ID;
79 }
80
81 void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined)
82 {
83   Model_ObjectDeletedMessage* aJoined = dynamic_cast<Model_ObjectDeletedMessage*>(&theJoined);
84   std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
85   for (; aGIter != aJoined->myGroups.end(); aGIter++) {
86     myGroups.insert(*aGIter);
87   }
88 }