1 // File: PartSet_Listener.h
2 // Created: 28 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <PartSet_Listener.h>
7 #include <PartSet_Module.h>
8 #include <PartSet_OperationSketchBase.h>
10 #include <XGUI_Displayer.h>
11 #include <XGUI_Workshop.h>
12 #include <XGUI_OperationMgr.h>
14 #include <ModuleBase_Operation.h>
16 #include <Events_Loop.h>
17 #include <ModelAPI_Events.h>
19 #include <SketchPlugin_Sketch.h>
27 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
30 Events_Loop* aLoop = Events_Loop::loop();
31 //aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY));
32 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
33 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
36 PartSet_Listener::~PartSet_Listener()
40 //******************************************************
41 void PartSet_Listener::processEvent(const Events_Message* theMessage)
43 ModuleBase_Operation* anOperation = myModule->workshop()->operationMgr()->currentOperation();
44 PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
48 XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
49 QString aType = QString(theMessage->eventID().eventText());
50 if (aType == EVENT_OBJECT_CREATED) {
51 const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
52 dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
53 std::set<ObjectPtr > aFeatures = aUpdMsg->objects();
54 std::set<ObjectPtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
55 for (; anIt != aLast; anIt++) {
56 aDisplayer->deactivate(*anIt);
57 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
59 myModule->activateFeature(aFeature, false);
62 } else 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);