Salome HOME
Issue #79 Move Events messages to boost pointers: XGUI, PartSet
[modules/shaper.git] / src / PartSet / PartSet_Listener.cpp
index 1f3505ee771821645ce24f312f47364718f4e481..be392c0097207ca07c38d6ac1f2fa3f302bf005e 100644 (file)
@@ -5,11 +5,16 @@
 #include <PartSet_Listener.h>
 
 #include <PartSet_Module.h>
+#include <PartSet_OperationSketchBase.h>
 
 #include <XGUI_Displayer.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_OperationMgr.h>
+
+#include <ModuleBase_Operation.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <SketchPlugin_Sketch.h>
 
 using namespace std;
 
 PartSet_Listener::PartSet_Listener(PartSet_Module* theModule)
-: myModule(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_TO_REDISPLAY));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 }
 
 PartSet_Listener::~PartSet_Listener()
@@ -33,38 +38,38 @@ PartSet_Listener::~PartSet_Listener()
 }
 
 //******************************************************
-void PartSet_Listener::processEvent(const Events_Message* theMessage)
+void PartSet_Listener::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
 {
+  ModuleBase_Operation* anOperation = myModule->workshop()->operationMgr()->currentOperation();
+  PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (!aSketchOp)
+    return;
+
+  XGUI_Displayer* aDisplayer = myModule->workshop()->displayer();
   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<FeaturePtr > aFeatures = aUpdMsg->features();
-    std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+  if (aType == EVENT_OBJECT_CREATED) {
+    boost::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+        boost::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+    std::set<ObjectPtr> aFeatures = aUpdMsg->objects();
+    std::set<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
     for (; anIt != aLast; anIt++) {
-      FeaturePtr aFeature = *anIt;
-      if (myModule->workshop()->displayer()->isVisible(aFeature) ||
-          aType == EVENT_FEATURE_CREATED) {
-        myModule->visualizePreview(aFeature, true, false);
-        //if (aType == EVENT_FEATURE_CREATED)
-          myModule->activateFeature(aFeature, true);
-      }
+      aDisplayer->deactivate(*anIt);
+      FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+      if (aFeature)
+        myModule->activateFeature(aFeature, false);
     }
-    myModule->workshop()->displayer()->updateViewer();
-  }
-  if (aType == EVENT_FEATURE_DELETED)
-  {
-    const Model_FeatureDeletedMessage* aDelMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
+
+  } else if (aType == EVENT_OBJECT_DELETED) {
+    boost::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
+        boost::dynamic_pointer_cast<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_KIND) == 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);
       }
     }