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_OBJECT_UPDATED));
28 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
29 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_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_OBJECT_UPDATED ||
41 aType == EVENT_OBJECT_CREATED)
43 const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
44 dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
45 std::set<ObjectPtr > aFeatures = aUpdMsg->objects();
46 std::set<ObjectPtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
47 for (; anIt != aLast; anIt++) {
48 ObjectPtr aObject = *anIt;
49 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
51 if (myModule->workshop()->displayer()->isVisible(aFeature->firstResult()) ||
52 aType == EVENT_OBJECT_CREATED) {
53 myModule->visualizePreview(aFeature->firstResult(), true, false);
54 //if (aType == EVENT_OBJECT_CREATED)
55 myModule->activateFeature(aFeature, true);
59 myModule->workshop()->displayer()->updateViewer();
61 if (aType == EVENT_OBJECT_DELETED)
63 const ModelAPI_ObjectDeletedMessage* aDelMsg =
64 dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
65 boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
67 std::set<std::string> aGroups = aDelMsg->groups();
68 std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
69 for (; anIt != aLast; anIt++) {
70 std::string aGroup = *anIt;
71 if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group
72 myModule->workshop()->displayer()->eraseDeletedResults();
73 myModule->updateCurrentPreview(aGroup);