Salome HOME
It replaces using of direct value "Sketch" to SKETCH_KIND, which is defined in the...
[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 #include <SketchPlugin_Sketch.h>
15
16 #ifdef _DEBUG
17 #include <QDebug>
18 #endif
19
20 using namespace std;
21
22 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
23 : myModule(theModule)
24 {
25   Events_Loop* aLoop = Events_Loop::loop();
26   aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
27   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
28   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
29 }
30
31 PartSet_Listener::~PartSet_Listener()
32 {
33 }
34
35 //******************************************************
36 void PartSet_Listener::processEvent(const Events_Message* theMessage)
37 {
38   QString aType = QString(theMessage->eventID().eventText());
39   if (aType == EVENT_FEATURE_UPDATED ||
40       aType == EVENT_FEATURE_CREATED)
41   {
42     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>
43                                                                                     (theMessage);
44     std::set<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aUpdMsg->features();
45     std::set<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
46                                                                    aLast = aFeatures.end();
47     for (; anIt != aLast; anIt++) {
48       boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
49       if (myModule->workshop()->displayer()->isVisible(aFeature) ||
50           aType == EVENT_FEATURE_CREATED) {
51         myModule->visualizePreview(aFeature, true, false);
52         //if (aType == EVENT_FEATURE_CREATED)
53           myModule->activateFeature(aFeature, true);
54       }
55     }
56     myModule->workshop()->displayer()->updateViewer();
57   }
58   if (aType == EVENT_FEATURE_DELETED)
59   {
60     const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
61     boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
62
63     std::set<std::string> aGroups = aDelMsg->groups();
64     std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
65     for (; anIt != aLast; anIt++) {
66       std::string aGroup = *anIt;
67       if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group
68         myModule->workshop()->displayer()->eraseDeletedFeatures();
69         myModule->updateCurrentPreview(aGroup);
70       }
71     }
72   }
73 }