Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / PartSet / PartSet_Listener.cpp
1 // File:        PartSet_Listener.h
2 // Created:     28 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_Listener.h>
6
7 #include <PartSet_Module.h>
8
9 #include <XGUI_Displayer.h>
10
11 #include <Events_Loop.h>
12 #include <Model_Events.h>
13
14 #ifdef _DEBUG
15 #include <QDebug>
16 #endif
17
18 using namespace std;
19
20 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
21 : myModule(theModule)
22 {
23   Events_Loop* aLoop = Events_Loop::loop();
24   aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
25   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
26   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
27 }
28
29 PartSet_Listener::~PartSet_Listener()
30 {
31 }
32
33 //******************************************************
34 void PartSet_Listener::processEvent(const Events_Message* theMessage)
35 {
36   QString aType = QString(theMessage->eventID().eventText());
37   if (aType == EVENT_FEATURE_UPDATED ||
38       aType == EVENT_FEATURE_CREATED)
39   {
40     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
41     boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
42     if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
43         aType == EVENT_FEATURE_CREATED) {
44       myModule->visualizePreview(aFeature, true, false);
45       myModule->activateFeature(aFeature, true);
46       myModule->workshop()->displayer()->UpdateViewer();
47     }
48   }
49   if (aType == EVENT_FEATURE_DELETED)
50   {
51     const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
52     boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
53
54     std::string aGroup = aDelMsg->group();
55     if (aDelMsg->group().compare("Sketch") == 0) { // Update only Sketch group
56       myModule->workshop()->displayer()->EraseDeletedFeatures();
57       myModule->updateCurrentPreview(aGroup);
58     }
59   }
60 }