1 // File: Model_Events.cxx
2 // Created: 10 Apr 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_Events.h>
6 #include <Events_Loop.h>
8 /// Alone instance of the creator per application
9 Model_EventCreator MY_CREATOR;
11 /////////////////////// CREATOR /////////////////////////////
12 void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
13 const bool isGroupped) const
15 std::shared_ptr<Model_ObjectUpdatedMessage> aMsg(
16 new Model_ObjectUpdatedMessage(theObject, theEvent));
17 Events_Loop::loop()->send(aMsg, isGroupped);
20 void Model_EventCreator::sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
21 const std::string& theGroup) const
23 std::shared_ptr<Model_ObjectDeletedMessage> aMsg(
24 new Model_ObjectDeletedMessage(theDoc, theGroup));
25 Events_Loop::loop()->send(aMsg, true);
28 Model_EventCreator::Model_EventCreator()
30 ModelAPI_EventCreator::set(this);
33 /////////////////////// UPDATED MESSAGE /////////////////////////////
34 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
35 const Events_ID& theEvent)
36 : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
39 myObjects.insert(theObject);
43 const std::set<ObjectPtr>& Model_ObjectUpdatedMessage::objects() const
48 std::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
50 ObjectPtr anEmptyObject;
51 return std::shared_ptr<Model_ObjectUpdatedMessage>(
52 new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
55 void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
57 std::shared_ptr<Model_ObjectUpdatedMessage> aJoined =
58 std::dynamic_pointer_cast<Model_ObjectUpdatedMessage>(theJoined);
59 std::set<ObjectPtr>::iterator aFIter = aJoined->myObjects.begin();
60 for (; aFIter != aJoined->myObjects.end(); aFIter++) {
61 myObjects.insert(*aFIter);
65 /////////////////////// DELETED MESSAGE /////////////////////////////
66 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
67 const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
68 : ModelAPI_ObjectDeletedMessage(messageId(), 0),
71 if (!theGroup.empty())
72 myGroups.insert(theGroup);
75 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
77 return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
80 const Events_ID Model_ObjectDeletedMessage::messageId()
82 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
86 void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
88 std::shared_ptr<Model_ObjectDeletedMessage> aJoined =
89 std::dynamic_pointer_cast<Model_ObjectDeletedMessage>(theJoined);
90 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
91 for (; aGIter != aJoined->myGroups.end(); aGIter++) {
92 myGroups.insert(*aGIter);