]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Events.cpp
Salome HOME
Issue #1315 Middle point constraint problem
[modules/shaper.git] / src / Model / Model_Events.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Events.cxx
4 // Created:     10 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_Events.h>
8 #include <Events_Loop.h>
9
10 /// Alone instance of the creator per application
11 Model_EventCreator MY_CREATOR;
12
13 /////////////////////// CREATOR /////////////////////////////
14 void Model_EventCreator::sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
15                                      const bool isGroupped) const
16 {
17   std::shared_ptr<Model_ObjectUpdatedMessage> aMsg(
18     new Model_ObjectUpdatedMessage(theObject, theEvent));
19   Events_Loop::loop()->send(aMsg, isGroupped);
20 }
21
22 void Model_EventCreator::sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
23                                      const std::string& theGroup) const
24 {
25   std::shared_ptr<Model_ObjectDeletedMessage> aMsg(
26     new Model_ObjectDeletedMessage(theDoc, theGroup));
27   Events_Loop::loop()->send(aMsg, true);
28 }
29
30 void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
31                                        const std::string& theGroup) const
32 {
33   std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
34     new Model_OrderUpdatedMessage(theDoc, theGroup));
35   Events_Loop::loop()->send(aMsg, true);
36 }
37
38 Model_EventCreator::Model_EventCreator()
39 {
40   ModelAPI_EventCreator::set(this);
41 }
42
43 /////////////////////// UPDATED MESSAGE /////////////////////////////
44 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
45                                                        const Events_ID& theEvent)
46     : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
47 {
48   if (theObject) {
49     myObjects.insert(theObject);
50   }
51 }
52
53 const std::set<ObjectPtr>& Model_ObjectUpdatedMessage::objects() const
54 {
55   return myObjects;
56 }
57
58 std::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
59 {
60   ObjectPtr anEmptyObject;
61   return std::shared_ptr<Model_ObjectUpdatedMessage>(
62     new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
63 }
64
65 void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
66 {
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);
72   }
73 }
74
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),
79       myDoc(theDoc)
80 {
81   if (!theGroup.empty())
82     myGroups.insert(theGroup);
83 }
84
85 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
86 {
87   return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
88 }
89
90 const Events_ID Model_ObjectDeletedMessage::messageId()
91 {
92   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
93   return MY_ID;
94 }
95
96 void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
97 {
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);
103   }
104 }
105
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)
111 {
112 }
113
114 const Events_ID Model_OrderUpdatedMessage::messageId()
115 {
116   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_ORDER_UPDATED);
117   return MY_ID;
118 }