Salome HOME
Implementation of mechanism of grouping of messages
[modules/shaper.git] / src / PartSet / PartSet_Listener.cpp
index a9c1eb2cb68dbe3e401a5fe2a5e04c845200de14..355142a31449d3cf0eff57d1dad009b7f04e57f9 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <PartSet_Module.h>
 
+#include <XGUI_Displayer.h>
+
 #include <Events_Loop.h>
 #include <Model_Events.h>
 
@@ -19,8 +21,9 @@ PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
 : myModule(theModule)
 {
   Events_Loop* aLoop = Events_Loop::loop();
-  Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
-  aLoop->registerListener(this, aFeatureUpdatedId);
+  aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
 }
 
 PartSet_Listener::~PartSet_Listener()
@@ -30,10 +33,38 @@ PartSet_Listener::~PartSet_Listener()
 //******************************************************
 void PartSet_Listener::processEvent(const Events_Message* theMessage)
 {
-  if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED)
+  QString aType = QString(theMessage->eventID().eventText());
+  if (aType == EVENT_FEATURE_UPDATED ||
+      aType == EVENT_FEATURE_CREATED)
+  {
+    const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>
+                                                                                    (theMessage);
+    std::set<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aUpdMsg->features();
+    std::set<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
+                                                                   aLast = aFeatures.end();
+    for (; anIt != aLast; anIt++) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
+      if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
+          aType == EVENT_FEATURE_CREATED) {
+        myModule->visualizePreview(aFeature, true, false);
+        myModule->activateFeature(aFeature, true);
+      }
+    }
+    myModule->workshop()->displayer()->UpdateViewer();
+  }
+  if (aType == EVENT_FEATURE_DELETED)
   {
-    const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-    boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
-    myModule->visualizePreview(aFeature, true);
+    const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
+    boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
+
+    std::set<std::string> aGroups = aDelMsg->groups();
+    std::set<std::string>::const_iterator anIt = aGroups.begin(), aLast = aGroups.end();
+    for (; anIt != aLast; anIt++) {
+      std::string aGroup = *anIt;
+      if (aGroup.compare("Sketch") == 0) { // Update only Sketch group
+        myModule->workshop()->displayer()->EraseDeletedFeatures();
+        myModule->updateCurrentPreview(aGroup);
+      }
+    }
   }
 }