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>
9 #include <PartSet_OperationSketch.h>
10 #include <PartSet_OperationFeatureCreate.h>
12 #include <XGUI_Displayer.h>
13 #include <XGUI_Workshop.h>
14 #include <XGUI_OperationMgr.h>
16 #include <ModuleBase_Operation.h>
18 #include <Events_Loop.h>
19 #include <ModelAPI_Events.h>
20 #include <ModelAPI_Feature.h>
28 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
31 Events_Loop* aLoop = Events_Loop::loop();
32 aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY));
33 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
34 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
37 PartSet_Listener::~PartSet_Listener()
41 //******************************************************
42 void PartSet_Listener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
44 ModuleBase_Operation* anOperation = myModule->xWorkshop()->operationMgr()->currentOperation();
45 PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
49 XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
50 QString aType = QString(theMessage->eventID().eventText());
51 if (aType == EVENT_OBJECT_CREATED) {
52 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
53 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
54 std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
56 PartSet_OperationSketch* aSketchOp =
57 dynamic_cast<PartSet_OperationSketch*>(myModule->xWorkshop()->operationMgr()->currentOperation());
59 std::set<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
60 for (; anIt != aLast; anIt++) {
61 ObjectPtr aObj = (*anIt);
62 // If current operation is Sketch then there is no active sketching operation
63 // and possible the object was created by Redo operation
65 XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
66 // Very possible it is not displayed
67 aDisplayer->display(aObj, false);
70 } else if (aType == EVENT_OBJECT_TO_REDISPLAY) {
71 PartSet_OperationFeatureCreate* aCreationOp =
72 dynamic_cast<PartSet_OperationFeatureCreate*>
73 (myModule->xWorkshop()->operationMgr()->currentOperation());
75 // Deactivate currently creating objects for selection
76 XGUI_Displayer* aDisplayer = myModule->xWorkshop()->displayer();
77 FeaturePtr aFeature = aCreationOp->feature();
78 const std::list<ResultPtr>& aResults = aFeature->results();
79 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
80 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
82 std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
83 std::set<ObjectPtr>::const_iterator aObjIt, aNoObj = aFeatures.cend();
84 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
85 for (; anIt != aLast; anIt++) {
86 aObjIt = aFeatures.find(*anIt);
87 if (aObjIt != aNoObj) {
88 aDisplayer->deactivate(*aObjIt);
92 } else if (aType == EVENT_OBJECT_DELETED) {
93 std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
94 std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
95 std::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
97 std::set<std::string> aGroups = aDelMsg->groups();
98 std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
99 for (; anIt != aLast; anIt++) {
100 std::string aGroup = *anIt;
101 if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group
102 myModule->xWorkshop()->displayer()->eraseDeletedResults();
103 myModule->updateCurrentPreview(aGroup);