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<FeaturePtr > aFeatures = aUpdMsg->features();
45 std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
46 for (; anIt != aLast; anIt++) {
47 FeaturePtr aFeature = *anIt;
48 if (myModule->workshop()->displayer()->isVisible(aFeature) ||
49 aType == EVENT_FEATURE_CREATED) {
50 myModule->visualizePreview(aFeature, true, false);
51 //if (aType == EVENT_FEATURE_CREATED)
52 myModule->activateFeature(aFeature, true);
55 myModule->workshop()->displayer()->updateViewer();
57 if (aType == EVENT_FEATURE_DELETED)
59 const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
60 boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
62 std::set<std::string> aGroups = aDelMsg->groups();
63 std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
64 for (; anIt != aLast; anIt++) {
65 std::string aGroup = *anIt;
66 if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group
67 myModule->workshop()->displayer()->eraseDeletedFeatures();
68 myModule->updateCurrentPreview(aGroup);