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_Feature>& theReordered) const
32 std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
33 new Model_OrderUpdatedMessage(theReordered));
34 Events_Loop::loop()->send(aMsg, true);
37 Model_EventCreator::Model_EventCreator()
39 ModelAPI_EventCreator::set(this);
42 /////////////////////// UPDATED MESSAGE /////////////////////////////
43 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
44 const Events_ID& theEvent)
45 : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
48 myObjects.insert(theObject);
52 const std::set<ObjectPtr>& Model_ObjectUpdatedMessage::objects() const
57 std::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
59 ObjectPtr anEmptyObject;
60 return std::shared_ptr<Model_ObjectUpdatedMessage>(
61 new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
64 void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
66 std::shared_ptr<Model_ObjectUpdatedMessage> aJoined =
67 std::dynamic_pointer_cast<Model_ObjectUpdatedMessage>(theJoined);
68 std::set<ObjectPtr>::iterator aFIter = aJoined->myObjects.begin();
69 for (; aFIter != aJoined->myObjects.end(); aFIter++) {
70 myObjects.insert(*aFIter);
74 /////////////////////// DELETED MESSAGE /////////////////////////////
75 Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
76 const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
77 : ModelAPI_ObjectDeletedMessage(messageId(), 0),
80 if (!theGroup.empty())
81 myGroups.insert(theGroup);
84 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
86 return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
89 const Events_ID Model_ObjectDeletedMessage::messageId()
91 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
95 void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
97 std::shared_ptr<Model_ObjectDeletedMessage> aJoined =
98 std::dynamic_pointer_cast<Model_ObjectDeletedMessage>(theJoined);
99 std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
100 for (; aGIter != aJoined->myGroups.end(); aGIter++) {
101 myGroups.insert(*aGIter);
105 /////////////////////// REORDERED MESSAGE /////////////////////////////
106 Model_OrderUpdatedMessage::Model_OrderUpdatedMessage(
107 FeaturePtr theReordered, const void* theSender)
108 : ModelAPI_OrderUpdatedMessage(messageId(), theSender),
109 myReordered(theReordered)
113 const Events_ID Model_OrderUpdatedMessage::messageId()
115 static Events_ID MY_ID = Events_Loop::eventByName(EVENT_ORDER_UPDATED);