1 // File: PartSet_Listener.h
2 // Created: 28 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_Listener.h>
7 #include <PartSet_Module.h>
9 #include <XGUI_Displayer.h>
11 #include <Events_Loop.h>
12 #include <Model_Events.h>
20 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
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));
29 PartSet_Listener::~PartSet_Listener()
33 //******************************************************
34 void PartSet_Listener::processEvent(const Events_Message* theMessage)
36 QString aType = QString(theMessage->eventID().eventText());
37 if (aType == EVENT_FEATURE_UPDATED ||
38 aType == EVENT_FEATURE_CREATED)
40 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>
42 std::set<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aUpdMsg->features();
43 std::set<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
44 aLast = aFeatures.end();
45 for (; anIt != aLast; anIt++) {
46 boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
47 if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
48 aType == EVENT_FEATURE_CREATED) {
49 myModule->visualizePreview(aFeature, true, false);
50 //if (aType == EVENT_FEATURE_CREATED)
51 myModule->activateFeature(aFeature, true);
54 myModule->workshop()->displayer()->UpdateViewer();
56 if (aType == EVENT_FEATURE_DELETED)
58 const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
59 boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
61 std::set<std::string> aGroups = aDelMsg->groups();
62 std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
63 for (; anIt != aLast; anIt++) {
64 std::string aGroup = *anIt;
65 if (aGroup.compare("Sketch") == 0) { // Update only Sketch group
66 myModule->workshop()->displayer()->EraseDeletedFeatures();
67 myModule->updateCurrentPreview(aGroup);