]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Events.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[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_Feature>& theReordered) const
31 {
32   std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
33     new Model_OrderUpdatedMessage(theReordered));
34   Events_Loop::loop()->send(aMsg, true);
35 }
36
37 Model_EventCreator::Model_EventCreator()
38 {
39   ModelAPI_EventCreator::set(this);
40 }
41
42 /////////////////////// UPDATED MESSAGE /////////////////////////////
43 Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(const ObjectPtr& theObject,
44                                                        const Events_ID& theEvent)
45     : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
46 {
47   if (theObject) {
48     myObjects.insert(theObject);
49   }
50 }
51
52 const std::set<ObjectPtr>& Model_ObjectUpdatedMessage::objects() const
53 {
54   return myObjects;
55 }
56
57 std::shared_ptr<Events_MessageGroup> Model_ObjectUpdatedMessage::newEmpty()
58 {
59   ObjectPtr anEmptyObject;
60   return std::shared_ptr<Model_ObjectUpdatedMessage>(
61     new Model_ObjectUpdatedMessage(anEmptyObject, eventID()));
62 }
63
64 void Model_ObjectUpdatedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
65 {
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);
71   }
72 }
73
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),
78       myDoc(theDoc)
79 {
80   if (!theGroup.empty())
81     myGroups.insert(theGroup);
82 }
83
84 std::shared_ptr<Events_MessageGroup> Model_ObjectDeletedMessage::newEmpty()
85 {
86   return std::shared_ptr<Model_ObjectDeletedMessage>(new Model_ObjectDeletedMessage(myDoc, ""));
87 }
88
89 const Events_ID Model_ObjectDeletedMessage::messageId()
90 {
91   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
92   return MY_ID;
93 }
94
95 void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>& theJoined)
96 {
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);
102   }
103 }
104
105 /////////////////////// REORDERED MESSAGE /////////////////////////////
106 Model_OrderUpdatedMessage::Model_OrderUpdatedMessage(
107     FeaturePtr theReordered, const void* theSender)
108     : ModelAPI_OrderUpdatedMessage(messageId(), theSender),
109     myReordered(theReordered)
110 {
111 }
112
113 const Events_ID Model_OrderUpdatedMessage::messageId()
114 {
115   static Events_ID MY_ID = Events_Loop::eventByName(EVENT_ORDER_UPDATED);
116   return MY_ID;
117 }