1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Events.cxx
4 // Created: 10 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_Events.h>
8 #include <Events_Loop.h>
10 /// Alone instance of the creator per application
11 Model_EventCreator MY_CREATOR;
13 /////////////////////// CREATOR /////////////////////////////
14 void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
15 const bool isGroupped) const
17 std::shared_ptr<Model_ObjectUpdatedMessage> aMsg(
18 new Model_ObjectUpdatedMessage(theObject, theEvent));
19 Events_Loop::loop()->send(aMsg, isGroupped);
22 void Model_EventCreator::sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
23 const std::string& theGroup) const
25 std::shared_ptr<Model_ObjectDeletedMessage> aMsg(
26 new Model_ObjectDeletedMessage(theDoc, theGroup));
27 Events_Loop::loop()->send(aMsg, true);
30 void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
31 const std::string& theGroup) const
33 std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
34 new Model_OrderUpdatedMessage(theDoc, theGroup));
35 Events_Loop::loop()->send(aMsg, true);
38 Model_EventCreator::Model_EventCreator()
40 ModelAPI_EventCreator::set(this);
43 /////////////////////// UPDATED MESSAGE /////////////////////////////
44 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
45 const Events_ID& theEvent)
46 : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
49 myObjects.insert(theObject);
53 const std::set<ObjectPtr>& Model_ObjectUpdatedMessage::objects() const
58 std::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
60 ObjectPtr anEmptyObject;
61 return std::shared_ptr<Model_ObjectUpdatedMessage>(
62 new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
65 void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
67 std::shared_ptr<Model_ObjectUpdatedMessage> aJoined =
68 std::dynamic_pointer_cast<Model_ObjectUpdatedMessage>(theJoined);
69 std::set<ObjectPtr>::iterator aFIter = aJoined->myObjects.begin();
70 for (; aFIter != aJoined->myObjects.end(); aFIter++) {
71 myObjects.insert(*aFIter);
75 /////////////////////// DELETED MESSAGE /////////////////////////////
76 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
77 const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
78 : ModelAPI_ObjectDeletedMessage(messageId(), 0),
81 if (!theGroup.empty())
82 myGroups.insert(theGroup);
85 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
87 return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
90 const Events_ID Model_ObjectDeletedMessage::messageId()
92 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
96 void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
98 std::shared_ptr<Model_ObjectDeletedMessage> aJoined =
99 std::dynamic_pointer_cast<Model_ObjectDeletedMessage>(theJoined);
100 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
101 for (; aGIter != aJoined->myGroups.end(); aGIter++) {
102 myGroups.insert(*aGIter);
106 /////////////////////// REORDERED MESSAGE /////////////////////////////
107 Model_OrderUpdatedMessage::Model_OrderUpdatedMessage(
108 const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
109 : ModelAPI_OrderUpdatedMessage(messageId(), 0),
110 myDoc(theDoc), myGroup(theGroup)
114 const Events_ID Model_OrderUpdatedMessage::messageId()
116 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_ORDER_UPDATED);