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>
10 #include <XGUI_Workshop.h>
12 #include <Events_Loop.h>
13 #include <ModelAPI_Events.h>
15 #include <SketchPlugin_Sketch.h>
23 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
26 Events_Loop* aLoop = Events_Loop::loop();
27 aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
28 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
29 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
32 PartSet_Listener::~PartSet_Listener()
36 //******************************************************
37 void PartSet_Listener::processEvent(const Events_Message* theMessage)
39 QString aType = QString(theMessage->eventID().eventText());
40 if (aType == EVENT_FEATURE_UPDATED ||
41 aType == EVENT_FEATURE_CREATED)
43 const ModelAPI_FeatureUpdatedMessage* aUpdMsg =
44 dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
45 std::set<FeaturePtr > aFeatures = aUpdMsg->features();
46 std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
47 for (; anIt != aLast; anIt++) {
48 FeaturePtr 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 ModelAPI_FeatureDeletedMessage* aDelMsg =
61 dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
62 boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
64 std::set<std::string> aGroups = aDelMsg->groups();
65 std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
66 for (; anIt != aLast; anIt++) {
67 std::string aGroup = *anIt;
68 if (aGroup.compare(SKETCH_KIND) == 0) { // Update only Sketch group
69 myModule->workshop()->displayer()->eraseDeletedFeatures();
70 myModule->updateCurrentPreview(aGroup);