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(
13 const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped) const
15 Model_ObjectUpdatedMessage aMsg(theObject, theEvent);
16 Events_Loop::loop()->send(aMsg, isGroupped);
19 void Model_EventCreator::sendDeleted(
20 const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const
22 Model_ObjectDeletedMessage aMsg(theDoc, theGroup);
23 Events_Loop::loop()->send(aMsg, true);
26 Model_EventCreator::Model_EventCreator()
28 ModelAPI_EventCreator::set(this);
31 /////////////////////// UPDATED MESSAGE /////////////////////////////
32 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(
33 const ObjectPtr& theObject,
34 const Events_ID& theEvent) : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
36 if (theObject) myObjects.insert(theObject);
39 std::set<ObjectPtr> Model_ObjectUpdatedMessage::objects() const
44 Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty()
46 ObjectPtr anEmptyObject;
47 return new Model_ObjectUpdatedMessage(anEmptyObject, eventID());
50 void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined)
52 Model_ObjectUpdatedMessage* aJoined = dynamic_cast<Model_ObjectUpdatedMessage*>(&theJoined);
53 std::set<ObjectPtr >::iterator aFIter = aJoined->myObjects.begin();
54 for(; aFIter != aJoined->myObjects.end(); aFIter++) {
55 myObjects.insert(*aFIter);
59 /////////////////////// DELETED MESSAGE /////////////////////////////
60 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
61 const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
62 : ModelAPI_ObjectDeletedMessage(messageId(), 0), myDoc(theDoc)
64 if (!theGroup.empty())
65 myGroups.insert(theGroup);
68 Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty()
70 return new Model_ObjectDeletedMessage(myDoc, "");
73 const Events_ID Model_ObjectDeletedMessage::messageId()
75 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
79 void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined)
81 Model_ObjectDeletedMessage* aJoined = dynamic_cast<Model_ObjectDeletedMessage*>(&theJoined);
82 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
83 for(; aGIter != aJoined->myGroups.end(); aGIter++) {
84 myGroups.insert(*aGIter);