Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / PartSet / PartSet_Listener.cpp
index e27fb725d7a4707081cc54b0dd01545387299931..f94e6c24f45d7f0b1ac7e90db35ee94e807899e7 100644 (file)
@@ -7,9 +7,12 @@
 #include <PartSet_Module.h>
 
 #include <XGUI_Displayer.h>
+#include <XGUI_Workshop.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
+
+#include <SketchPlugin_Sketch.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -21,9 +24,9 @@ PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
 : myModule(theModule)
 {
   Events_Loop* aLoop = Events_Loop::loop();
-  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));
+  aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_UPDATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 }
 
 PartSet_Listener::~PartSet_Listener()
@@ -34,36 +37,39 @@ PartSet_Listener::~PartSet_Listener()
 void PartSet_Listener::processEvent(const Events_Message* theMessage)
 {
   QString aType = QString(theMessage->eventID().eventText());
-  if (aType == EVENT_FEATURE_UPDATED ||
-      aType == EVENT_FEATURE_CREATED)
+  if (aType == EVENT_OBJECT_UPDATED ||
+      aType == EVENT_OBJECT_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();
+    const ModelAPI_ObjectUpdatedMessage* aUpdMsg = 
+      dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+    std::set<ObjectPtr > aFeatures = aUpdMsg->features();
+    std::set<ObjectPtr >::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);
-        //if (aType == EVENT_FEATURE_CREATED)
+      ObjectPtr aObject = *anIt;
+      FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+      if (aFeature) {
+        if (myModule->workshop()->displayer()->isVisible(aFeature->firstResult()) ||
+            aType == EVENT_OBJECT_CREATED) {
+          myModule->visualizePreview(aFeature->firstResult(), true, false);
+          //if (aType == EVENT_OBJECT_CREATED)
           myModule->activateFeature(aFeature, true);
+        }
       }
     }
     myModule->workshop()->displayer()->updateViewer();
   }
-  if (aType == EVENT_FEATURE_DELETED)
+  if (aType == EVENT_OBJECT_DELETED)
   {
-    const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
+    const ModelAPI_ObjectDeletedMessage* aDelMsg = 
+      dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(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();
+      if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group
+        myModule->workshop()->displayer()->eraseDeletedResults();
         myModule->updateCurrentPreview(aGroup);
       }
     }