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>
14 #include <SketchPlugin_Sketch.h>
22 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
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));
31 PartSet_Listener::~PartSet_Listener()
35 //******************************************************
36 void PartSet_Listener::processEvent(const Events_Message* theMessage)
38 QString aType = QString(theMessage->eventID().eventText());
39 if (aType == EVENT_FEATURE_UPDATED ||
40 aType == EVENT_FEATURE_CREATED)
42 const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>
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);
56 myModule->workshop()->displayer()->updateViewer();
58 if (aType == EVENT_FEATURE_DELETED)
60 const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
61 boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
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);