]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Initial solution Treads_control_development
authorvsv <vsv@opencascade.com>
Tue, 16 Oct 2018 08:54:21 +0000 (11:54 +0300)
committervsv <vsv@opencascade.com>
Tue, 16 Oct 2018 08:54:21 +0000 (11:54 +0300)
25 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_EventsListener.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_EventsListener.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_IconFactory.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_WorkController.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WorkController.h [new file with mode: 0644]
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_CustomPrs.h
src/PartSet/PartSet_IconFactory.cpp
src/PartSet/PartSet_IconFactory.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_DataModel.h
src/XGUI/XGUI_MenuMgr.cpp
src/XGUI/XGUI_MenuMgr.h
src/XGUI/XGUI_WorkshopListener.cpp
src/XGUI/XGUI_WorkshopListener.h

index ee79fe18606b89c6063ec90cd8f5c6b678aee875..6e84c8363ab7ff4a6d1a6440bb3615b11de66dcb 100644 (file)
@@ -104,6 +104,8 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetRadiobox.h
   ModuleBase_WidgetPointInput.h
   ModuleBase_ITreeNode.h
+  ModuleBase_WorkController.h
+  ModuleBase_EventsListener.h
 )
 
 SET(PROJECT_MOC_HEADERS
@@ -153,6 +155,9 @@ SET(PROJECT_MOC_HEADERS
   ModuleBase_WidgetNameEdit.h
   ModuleBase_WidgetRadiobox.h
   ModuleBase_WidgetPointInput.h
+  ModuleBase_WorkController.h
+  ModuleBase_EventsListener.h
+  ModuleBase_IconFactory.h
 )
 
 SET(PROJECT_SOURCES
@@ -221,6 +226,8 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetNameEdit.cpp
   ModuleBase_WidgetRadiobox.cpp
   ModuleBase_WidgetPointInput.cpp
+  ModuleBase_WorkController.cpp
+  ModuleBase_EventsListener.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/ModuleBase/ModuleBase_EventsListener.cpp b/src/ModuleBase/ModuleBase_EventsListener.cpp
new file mode 100644 (file)
index 0000000..7553d14
--- /dev/null
@@ -0,0 +1,99 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "ModuleBase_EventsListener.h"
+#include "ModuleBase_Events.h"
+
+#include <ModelAPI_Events.h>
+
+#include <Events_Loop.h>
+#include <Events_InfoMessage.h>
+#include <Events_LongOp.h>
+#include <Config_FeatureMessage.h>
+
+
+
+static ModuleBase_EventsListener* MYListener = NULL;
+
+//Q_DECLARE_METATYPE(EventMsgPtr)
+//qRegisterMetaType<std::shared_ptr<Events_Message>>();
+//qRegisterMetaType<std::shared_ptr<Events_Message>>("std::shared_ptr<Events_Message>");
+
+
+ModuleBase_EventsListener::ModuleBase_EventsListener()
+  : QThread()
+{
+  //Initialize event listening
+  Events_Loop* aLoop = Events_Loop::loop();
+  aLoop->registerListener(this, Events_InfoMessage::errorID());  //!< Listening application errors.
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  aLoop->registerListener(this, Events_LongOp::eventID());
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
+
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION));
+
+  aLoop->registerListener(this, Events_Loop::eventByName("FinishOperation"));
+  aLoop->registerListener(this, Events_Loop::eventByName("AbortOperation"));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_STATE_RESPONSE));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION));
+}
+
+
+
+ModuleBase_EventsListener* ModuleBase_EventsListener::instance()
+{
+  if (!MYListener) {
+    MYListener = new ModuleBase_EventsListener();
+    MYListener->start();
+  }
+  return MYListener;
+}
+
+void ModuleBase_EventsListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  ModuleBase_Event* aEvnt = new ModuleBase_Event(theMessage);
+  myMutex.lock();
+  myMessages.append(aEvnt);
+  myMutex.unlock();
+}
+
+void ModuleBase_EventsListener::run()
+{
+  while (1) {
+    while (myMessages.size()) {
+      myMutex.lock();
+      ModuleBase_Event* aMsg = myMessages.first();
+      myMessages.removeFirst();
+      myMutex.unlock();
+      emit hasEvent(aMsg);
+      //aMsg->deleteLater();
+    }
+    msleep(10);
+  }
+}
diff --git a/src/ModuleBase/ModuleBase_EventsListener.h b/src/ModuleBase/ModuleBase_EventsListener.h
new file mode 100644 (file)
index 0000000..31349bf
--- /dev/null
@@ -0,0 +1,77 @@
+#pragma once
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef ModuleBase_EventsListener_H
+#define ModuleBase_EventsListener_H
+
+#include "ModuleBase.h"
+
+#include <Events_Listener.h>
+#include <Events_Message.h>
+
+#include <QThread>
+#include <QList>
+#include <QMutex>
+
+
+class MODULEBASE_EXPORT ModuleBase_Event: public QObject
+{
+  Q_OBJECT
+public:
+  ModuleBase_Event() {}
+
+  ModuleBase_Event(const std::shared_ptr<Events_Message>& theMsg) : myMsg(theMsg) {}
+
+  void setMessage(const std::shared_ptr<Events_Message>& theMsg) {
+    myMsg = theMsg;
+  }
+
+  std::shared_ptr<Events_Message> message() const { return myMsg; }
+
+private:
+  std::shared_ptr<Events_Message> myMsg;
+};
+
+
+class MODULEBASE_EXPORT ModuleBase_EventsListener : public QThread, public Events_Listener
+{
+  Q_OBJECT
+public:
+  static ModuleBase_EventsListener* instance();
+
+  //! Redefinition of Events_Listener method
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+signals:
+  void hasEvent(ModuleBase_Event* theMsg);
+
+protected:
+  virtual void run();
+
+private:
+  ModuleBase_EventsListener();
+
+private:
+  QList<ModuleBase_Event*> myMessages;
+  QMutex myMutex;
+};
+
+#endif
\ No newline at end of file
index b20fb23c0a55846a8fe187756733552a4ddb760c..0976114baaf1f7571134bbdf5fe5bb71ad6b0fbd 100644 (file)
 #include <QPixmap>
 #include <QIcon>
 #include <QImage>
+#include <QObject>
 
 /**\class ModuleBase_IconFactory
  * \ingroup GUI
  * \brief This is a class which provides icons of objects for object browser 
  */
-class MODULEBASE_EXPORT ModuleBase_IconFactory
+class MODULEBASE_EXPORT ModuleBase_IconFactory: public QObject
 {
+  Q_OBJECT
 public:
   /// Returns icons factory instance
   static ModuleBase_IconFactory* get();
index 91be0c34cb2221b98cd5ea8aab98fcd1509288ea..e08e5cf5a959224f143d56f72ba93470e5d3feda 100644 (file)
 #include <QDebug>
 #endif
 
+
+void ModuleBase_FinishOperation::work()
+{
+  SessionPtr aMgr = ModelAPI_Session::get();
+  aMgr->finishOperation();
+  thread()->quit();
+}
+
+
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
     : QObject(theParent),
       myIsModified(false),
@@ -137,10 +146,14 @@ bool ModuleBase_Operation::commit()
     if (aPanel)
       aPanel->onAcceptData();
 
-    SessionPtr aMgr = ModelAPI_Session::get();
 
     commitOperation();
+
+    SessionPtr aMgr = ModelAPI_Session::get();
     aMgr->finishOperation();
+    //ModuleBase_FinishOperation* aFinish = new ModuleBase_FinishOperation();
+    //ModuleBase_WorkController aController(aFinish);
+    //aController.perform();
 
     stopOperation();
     emit stopped();
index 4ea8c6c4493267c41597323cf0d420e1b80768ba..c81b70b8c4e527193cb48e53f4b5cd18422c0180 100644 (file)
@@ -22,6 +22,7 @@
 #define ModuleBase_Operation_H
 
 #include <ModuleBase.h>
+#include <ModuleBase_WorkController.h>
 
 #include <QObject>
 #include <QString>
@@ -33,6 +34,16 @@ class ModuleBase_IPropertyPanel;
 
 class QKeyEvent;
 
+
+
+class ModuleBase_FinishOperation : public ModuleBase_IWorker
+{
+  Q_OBJECT
+public slots:
+  virtual void work();
+};
+
+
 /*!
  * \class ModuleBase_Operation
  * \ingroup GUI
index 04edf79576b5a8e6df3fc796d0b954c6b096f3a9..5daa0c28a9dd162a4823a145fd4ec1f2c40ad922 100755 (executable)
@@ -353,10 +353,13 @@ bool ModuleBase_OperationFeature::commit()
     myFeature->setStable(true);
 
     SessionPtr aMgr = ModelAPI_Session::get();
-    /// Set current feature and remeber old current feature
+    // Set current feature and remeber old current feature
 
     commitOperation();
     aMgr->finishOperation();
+    //ModuleBase_FinishOperation* aFinish = new ModuleBase_FinishOperation();
+    //ModuleBase_WorkController aController(aFinish);
+    //aController.perform();
 
     stopOperation();
     emit stopped();
diff --git a/src/ModuleBase/ModuleBase_WorkController.cpp b/src/ModuleBase/ModuleBase_WorkController.cpp
new file mode 100644 (file)
index 0000000..233d883
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "ModuleBase_WorkController.h"
+#include <QApplication>
+
+ModuleBase_WorkController::ModuleBase_WorkController(ModuleBase_IWorker* theWorker)
+  : QObject(),
+  myWorker(theWorker)
+{
+}
+
+
+ModuleBase_WorkController::~ModuleBase_WorkController()
+{
+  while (myThread.isRunning())
+    myThread.wait(1);
+}
+
+void ModuleBase_WorkController::perform()
+{
+  myWorker->moveToThread(&myThread);
+  connect(&myThread, SIGNAL(finished()), myWorker, SLOT(deleteLater()));
+  connect(&myThread, SIGNAL(started()), myWorker, SLOT(work()));
+  myThread.start();
+}
diff --git a/src/ModuleBase/ModuleBase_WorkController.h b/src/ModuleBase/ModuleBase_WorkController.h
new file mode 100644 (file)
index 0000000..d6abe30
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef ModuleBase_WorkController_H
+#define ModuleBase_WorkController_H
+
+#include "ModuleBase.h"
+
+#include <QObject>
+#include <QThread>
+
+
+class MODULEBASE_EXPORT ModuleBase_IWorker: public QObject
+{
+  Q_OBJECT
+public slots:
+  virtual void work() {}
+};
+
+
+class MODULEBASE_EXPORT ModuleBase_WorkController: public QObject
+{
+  Q_OBJECT
+public:
+  ModuleBase_WorkController(ModuleBase_IWorker* theWorker);
+
+  ~ModuleBase_WorkController();
+
+  void perform();
+
+private:
+  ModuleBase_IWorker* myWorker;
+  QThread myThread;
+};
+
+#endif
\ No newline at end of file
index 0defdd96f8c6bd0952d9ee41db67119299f063e9..a4026816429d34d6e93af712249ea630592618a1 100644 (file)
@@ -77,6 +77,8 @@ SET(PROJECT_MOC_HEADERS
     PartSet_WidgetSketchCreator.h
     PartSet_WidgetSketchLabel.h
     PartSet_ExternalPointsMgr.h
+    PartSet_IconFactory.h
+       PartSet_CustomPrs.h
 )
 
 SET(PROJECT_SOURCES
index 1780f0d44f6299d88775afb1130ad0c0aea10cf0..bcce8d242509c9f8ef536d05388450a68984c72b 100755 (executable)
 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
   : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false)
 {
-  Events_Loop* aLoop = Events_Loop::loop();
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION));
+  //Events_Loop* aLoop = Events_Loop::loop();
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION));
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
 
   initPresentation(ModuleBase_IModule::CustomizeArguments);
   initPresentation(ModuleBase_IModule::CustomizeResults);
@@ -229,9 +232,10 @@ void PartSet_CustomPrs::clearPrs()
   clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
 }
 
-void PartSet_CustomPrs::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void PartSet_CustomPrs::processEvent(ModuleBase_Event* theMessage)
 {
-  if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+  if (aMsg->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))
     myPresentationIsEmpty = true; /// store state to analize it after display/erase is finished
 }
 
index 65c3bdf0916fbd86840153a34b4974861e27b991..2b743168f7fa1af2d95d4d6d27e73e2d54110f80 100755 (executable)
@@ -26,6 +26,8 @@
 #include "PartSet_OperationPrs.h"
 
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_EventsListener.h>
+
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Feature.h>
@@ -43,8 +45,9 @@ class XGUI_Workshop;
  * This is the module custom presentation, which manage an AIS presentation, that can be filled
  * by a feature and visualized in the viewer additionally to usual workshop objects.
 */
-class PartSet_CustomPrs : public Events_Listener
+class PartSet_CustomPrs : public QObject //Events_Listener
 {
+  Q_OBJECT
 public:
   /// Returns yellow color
   static const std::string OPERATION_PARAMETER_COLOR() { return "255, 255, 0"; }
@@ -99,8 +102,9 @@ public:
   /// it caused erroneus case because the presentation has linkage to the previous context.
   void clearPrs();
 
+private slots:
   //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  virtual void processEvent(ModuleBase_Event* theMessage);
 
 private:
   /// Creates the AIS operation presentation
index 42b3d4d62f6f65b516232f300dbc7f603d3ba098..e899a979e765c82b977020a637afb5f4657fc82f 100644 (file)
@@ -35,8 +35,11 @@ QMap<QString, QString> PartSet_IconFactory::myIcons;
 
 PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
 {
-  Events_Loop::loop()->registerListener(this,
-    Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+  //Events_Loop::loop()->registerListener(this,
+  //  Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
 }
 
 
@@ -127,12 +130,13 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
   return anIcon;
 }
 
-void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void PartSet_IconFactory::processEvent(ModuleBase_Event* theMessage)
 {
-  if (theMessage->eventID() ==
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+  if (aMsg->eventID() ==
       Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
-       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
+       std::dynamic_pointer_cast<Config_FeatureMessage>(aMsg);
     if (!aFeatureMsg->isInternal()) {
       ActionInfo aFeatureInfo;
       aFeatureInfo.initFrom(aFeatureMsg);
index 092754e28e0ba0551b46aead6ecb4b268da741df..3e4df3ba82a8baee66dbde1528a35a97eb28ae08 100644 (file)
@@ -23,7 +23,9 @@
 
 #include "PartSet.h"
 #include <ModuleBase_IconFactory.h>
-#include <Events_Listener.h>
+#include <ModuleBase_EventsListener.h>
+//#include <Events_Listener.h>
+#include <Events_Message.h>
 
 #include <QMap>
 
  * \brief This is a class is redefined in order to provide
  * icons of objects for object browser specific for PartSetModule
  */
-class PARTSET_EXPORT PartSet_IconFactory : public ModuleBase_IconFactory, public Events_Listener
+class PARTSET_EXPORT PartSet_IconFactory : public ModuleBase_IconFactory
+  //, public Events_Listener
 {
+  Q_OBJECT
 public:
   /// Constructor
   PartSet_IconFactory();
@@ -45,7 +49,12 @@ public:
 
   /// Event Listener method
   /// \param theMessage an event message
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  //virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+private slots:
+  /// Event Listener method
+  /// \param theMessage an event message
+  virtual void processEvent(ModuleBase_Event* theMessage);
 
 private:
   static QMap<QString, QString> myIcons;
index aa7b4e383f47e0d4298d138e4c26fb6407b0a877..4b2816010f42a45478ec0fd0a17c2438152cafc2 100755 (executable)
@@ -176,8 +176,11 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
 
-  Events_Loop* aLoop = Events_Loop::loop();
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  //Events_Loop* aLoop = Events_Loop::loop();
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
 
   registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
   registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
@@ -1289,8 +1292,8 @@ void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
 
-    Events_Loop* aLoop = Events_Loop::loop();
-    aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+    //Events_Loop* aLoop = Events_Loop::loop();
+    //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   }
 }
 
@@ -1422,9 +1425,11 @@ if (aObjIndex.isValid()) { \
 }
 
 //******************************************************
-void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void PartSet_Module::processEvent(ModuleBase_Event* theMessage)
 {
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+
+  if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
     // Do not change activation of parts if an operation active
     static QStringList aAllowActivationList;
     if (aAllowActivationList.isEmpty())
@@ -1479,9 +1484,9 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     if (needUpdate) {
       aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
     }
-  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+  } else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
 
     ObjectPtr aConstrObj;
index 3979a599bc8fa0273d067dd3b37a561fac44d009..633106a700baa3759c9ab5c83509a8f50366b2c3 100755 (executable)
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Definitions.h>
+#include <ModuleBase_EventsListener.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_CompositeFeature.h>
 
-#include <Events_Listener.h>
+//#include <Events_Listener.h>
 
 //#include <StdSelect_FaceFilter.hxx>
 #include <TopoDS_Shape.hxx>
@@ -67,7 +68,7 @@ class QAction;
 * \ingroup Modules
 * Implementation of Partset module
 */
-class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
+class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule//, public Events_Listener
 {
 Q_OBJECT
 
@@ -280,7 +281,7 @@ public:
 
   /// Event Listener method
   /// \param theMessage an event message
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  // virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
   /// Set the object with the object results are customized
   /// \param theFeature a feature
@@ -436,6 +437,10 @@ protected slots:
   /// \param theIndex the current choice index
   void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
 
+  /// Event Listener method
+  /// \param theMessage an event message
+  virtual void processEvent(ModuleBase_Event* theMessage);
+
 protected:
   /// Appends specific selection modes for the module to the list of types
   /// \param theModes a selection modes to be extended
index 6c7d19fe42269755d4b8fe789f044beb3c55d42b..05c48bae51faee8fa3e1272cbfcd5f2ec06321aa 100644 (file)
@@ -91,6 +91,7 @@ SET(PROJECT_MOC_HEADERS
     XGUI_Workshop.h
     XGUI_WorkshopListener.h
        XGUI_InspectionPanel.h
+       XGUI_MenuMgr.h
 )
 
 # sources / moc wrappings
index 0d7a57d33a3d337f815ac27dc47066eaf13d84ea..29b1282ec93da5b3842dcbe30ae2088c2a3b8e70 100644 (file)
@@ -62,10 +62,9 @@ XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
   myShortcuts << QKeySequence::Close;
 
   //Initialize event listening
-  Events_Loop* aLoop = Events_Loop::loop();
-  static Events_ID aStateResponseEventId =
-      Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
-  aLoop->registerListener(this, aStateResponseEventId, NULL, true);
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
 }
 
 XGUI_ActionsMgr::~XGUI_ActionsMgr()
@@ -211,13 +210,15 @@ QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
   return aResult;
 }
 
-void XGUI_ActionsMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void XGUI_ActionsMgr::processEvent(ModuleBase_Event* theMessage)
 {
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+
   const Events_ID kResponseEvent =
       Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
-  if (theMessage->eventID() == kResponseEvent) {
+  if (aMsg->eventID() == kResponseEvent) {
     std::shared_ptr<ModelAPI_FeatureStateMessage> aStateMessage =
-        std::dynamic_pointer_cast<ModelAPI_FeatureStateMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_FeatureStateMessage>(aMsg);
     if (!aStateMessage.get())
       return;
     std::list<std::string> aFeaturesList = aStateMessage->features();
@@ -230,11 +231,6 @@ void XGUI_ActionsMgr::processEvent(const std::shared_ptr<Events_Message>& theMes
       }
       setActionEnabled(anActionId, aStateMessage->state(*it, theDefaultState));
     }
-  } else if (theMessage.get()) {
-    #ifdef _DEBUG
-    std::cout << "XGUI_ActionsMgr::processEvent: unhandled message caught: " << std::endl
-              << theMessage->eventID().eventText() << std::endl;
-    #endif
   }
 }
 
index 3773ae9bac0b423261ac87ee44d34cca0b47fa55..3048d146e7819e0fcb37be5b02b24248adc74329 100644 (file)
 
 #include "XGUI.h"
 
-#include <Events_Listener.h>
 #include <ModelAPI_Feature.h>
 
 #include <ModuleBase_ActionInfo.h>
+#include <ModuleBase_EventsListener.h>
 
 #include <QObject>
 #include <QMap>
@@ -42,7 +42,7 @@ class QAction;
 /// class XGUI_ActionsMgr
 /// \ingroup GUI
 /// A class for management of actions (features) activation/deactivation
-class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
+class XGUI_EXPORT XGUI_ActionsMgr : public QObject//, public Events_Listener
 {
   Q_OBJECT
 
@@ -88,9 +88,6 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
   /// \param theKeySequence - string that contain a key sequence to register
   QKeySequence registerShortcut(const QString& theKeySequence);
 
-  /// Redefinition of Events_Listener method
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
-
   /// Return property panel's action like ok, cancel, help.
   /// If there is no such action, it will be created.
   QAction* operationStateAction(OperationStateActionId theId);
@@ -102,6 +99,10 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
   /// if it was registered in the manager
   ActionInfo actionInfoById(const QString& theId);
 
+private slots:
+  /// Redefinition of Events_Listener method
+  virtual void processEvent(ModuleBase_Event* theMessage);
+
  private:
   /// Update workbench actions according to OperationMgr state:
   /// No active operations: all actions but nested are available
index 45354a917da4d425f7fd9600eb4ab2d3f2e8ba36..825c7368035709cce5a88079ffc3ab7d07d9581a 100644 (file)
@@ -42,13 +42,16 @@ XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParen
   XGUI_ObjectsBrowser* aOB = qobject_cast<XGUI_ObjectsBrowser*>(theParent);
   myWorkshop = aOB->workshop();
 
-  Events_Loop* aLoop = Events_Loop::loop();
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
+  //Events_Loop* aLoop = Events_Loop::loop();
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_ORDER_UPDATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
 XGUI_DataModel::~XGUI_DataModel()
@@ -57,11 +60,13 @@ XGUI_DataModel::~XGUI_DataModel()
 }
 
 //******************************************************
-void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void XGUI_DataModel::processEvent(ModuleBase_Event* theMessage)
 {
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+
+  if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
     QObjectPtrList aCreated;
     std::set<ObjectPtr>::const_iterator aIt;
@@ -82,9 +87,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       dataChanged(aParentIndex1, aParentIndex2);
     }
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
-      std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(aMsg);
     const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>& aMsgGroups =
       aUpdMsg->groups();
     std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string>>::const_iterator aIt;
@@ -92,9 +97,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       QTreeNodesList aList = myRoot->objectsDeleted(aIt->first, aIt->second.c_str());
     rebuildDataTree();
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
 
     QObjectPtrList aCreated;
@@ -142,9 +147,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       }
     }
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
     std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
-      std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(aMsg);
     if (aUpdMsg->reordered().get()) {
       DocumentPtr aDoc = aUpdMsg->reordered()->document();
       std::string aGroup = aUpdMsg->reordered()->group();
@@ -155,16 +160,16 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
       }
     }
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
     DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
     ModuleBase_ITreeNode* aRoot = myRoot->findRoot(aDoc);
     if (aRoot) {
       updateSubTree(aRoot);
     }
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
 
     QObjectPtrList aCreated;
index 929f3afb3467d003abc59f63f8dd1f0819923c53..5f17a04cd0d1bcba57706452e72f4d701c19f1ca 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "XGUI.h"
 #include <ModuleBase_Definitions.h>
+#include <ModuleBase_EventsListener.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Document.h>
 #include <Events_Listener.h>
@@ -44,7 +45,7 @@ class ModuleBase_ITreeNode;
  * - An index which contains internal pointer as ModelAPI_Document is 
  *   a folder which belongs to this document
  */
-class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener
+class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel//, public Events_Listener
 {
 Q_OBJECT
 public:
@@ -62,7 +63,7 @@ public:
 
   /// Event Listener method
   /// \param theMessage an event message
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  //virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
   //! Returns an object by the given Model index.
   //! Returns 0 if the given index is not index of an object
@@ -162,6 +163,11 @@ signals:
   /// Signal about tree had been rebuilt
   void treeRebuilt();
 
+private slots:
+  /// Event Listener method
+  /// \param theMessage an event message
+  void processEvent(ModuleBase_Event* theMessage);
+
 private:
   enum VisibilityState {
     NoneState,
@@ -176,69 +182,9 @@ private:
 
   void updateSubTree(ModuleBase_ITreeNode* theParent);
 
-  /// Find a root index which contains objects of the given document
-  /// \param theDoc the document object
-  //QModelIndex findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn = 1) const;
-
-  /// Returns number of folders in document.
-  /// Considered folders which has to be shown only if they are not empty.
-  /// \param theDoc document which has to be checked. If 0 then Root document will be considered
-  //int foldersCount(ModelAPI_Document* theDoc = 0) const;
-
-  /// Retrurns indexes of folders which can not be shown because they are empty
-  /// \param theDoc document which has to be checked. If 0 then Root document will be considered
-  //QIntList missedFolderIndexes(ModelAPI_Document* theDoc = 0) const;
-
-  /// Returns Id (row) of a folder taking into consideration
-  /// folders which can not be shown non empty
-  /// \param theType Type of the folder
-  /// \param theDoc a document which contains this folder
-  //int folderId(std::string theType, ModelAPI_Document* theDoc = 0) const;
-
-  /// Removes a row from branch of tree
-  /// \param theStart - start row to update indexes
-  /// \param theSize - number of indexes in the folder
-  /// \param theParent - index of parent folder
-  //void rebuildBranch(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
-
-  /// Returns list of folders types which can not be shown empty
-  /// \param fromRoot - root document flag
-  //QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const;
-
-  //int getNumberOfFolderItems(const ModelAPI_Folder* theFolder) const;
-  //ObjectPtr getObjectInFolder(const ModelAPI_Folder* theFolder, int theId) const;
-
-  //VisibilityState getVisibilityState(const QModelIndex& theIndex) const;
-
-  //void addShownFolder(DocumentPtr theDoc, QString theFolder)
-  //{
-  //  if (!myShownFolders.contains(theDoc)) {
-  //    myShownFolders[theDoc] = QStringList();
-  //  }
-  //  myShownFolders[theDoc].append(theFolder);
-  //}
-
-  //void removeShownFolder(DocumentPtr theDoc, QString theFolder)
-  //{
-  //  if (myShownFolders.contains(theDoc)) {
-  //    myShownFolders[theDoc].removeAll(theFolder);
-  //    if (myShownFolders[theDoc].isEmpty())
-  //      myShownFolders.remove(theDoc);
-  //  }
-  //}
-
-  //bool hasShownFolder(DocumentPtr theDoc, QString theFolder) const
-  //{
-  //  if (myShownFolders.contains(theDoc))
-  //    return myShownFolders[theDoc].contains(theFolder);
-  //  return false;
-  //}
-
-  //Config_DataModelReader* myXMLReader;
 
   XGUI_Workshop* myWorkshop;
   QMap<DocumentPtr, QStringList> myShownFolders;
-  //bool myIsEventsProcessingBlocked;
 
   ModuleBase_ITreeNode* myRoot;
 };
index 577685a87a0a792cc83dca533665432292f7e2bf..6116b3dd1131fd76c824ac3de6df7c118a073144 100755 (executable)
 XGUI_MenuMgr::XGUI_MenuMgr(XGUI_Workshop* theWorkshop)
 : myWorkshop(theWorkshop)
 {
-  Events_Loop* aLoop = Events_Loop::loop();
-
-  aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
 }
 
-void XGUI_MenuMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void XGUI_MenuMgr::processEvent(ModuleBase_Event* theMessage)
 {
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+
   //A message to start feature creation received.
-  if (theMessage->eventID() ==
+  if (aMsg->eventID() ==
       Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
-       std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
+       std::dynamic_pointer_cast<Config_FeatureMessage>(aMsg);
     if (!aFeatureMsg->isInternal()) {
       addFeature(aFeatureMsg);
     }
index d122d8b53d1cabe8c69c436116cf7d92764adab2..6a23999e2c4e2cbc49dae9598643d08810a5cbdd 100755 (executable)
 
 #include "XGUI.h"
 
-#include <Events_Listener.h>
+#include <ModuleBase_EventsListener.h>
 
 #include <string>
 #include <list>
 #include <memory>
+#include <QObject>
 
 class XGUI_MenuWorkbench;
 class XGUI_Workshop;
@@ -41,20 +42,22 @@ class QAction;
 * in XML file. It listens the read feature of XML and fills internal structure of menu workbenches
 * and groups of feature. After, it creates menues and tools in the module.
 */
-class XGUI_MenuMgr : public Events_Listener
+class XGUI_EXPORT XGUI_MenuMgr : public QObject //Events_Listener
 {
+  Q_OBJECT
  public:
   /// Constructor
   /// \param theWorkshop the current workshop
-  XGUI_EXPORT XGUI_MenuMgr(XGUI_Workshop* theWorkshop);
-  XGUI_EXPORT virtual ~XGUI_MenuMgr() {}
+  XGUI_MenuMgr(XGUI_Workshop* theWorkshop);
+  virtual ~XGUI_MenuMgr() {}
 
   /// Creates feature actions
-  XGUI_EXPORT void createFeatureActions();
+  void createFeatureActions();
 
+public slots:
   /// Redefinition of Events_Listener method
   /// \param theMessage a message
-  XGUI_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  void processEvent(ModuleBase_Event* theMessage);
 
 protected:
   /// Process event "Add a feature"
index f7720512d9fc73e38d1df1ff9d9458ab63063735..1366e99bbd602def9e70ee66f75a17d7c17e7997 100755 (executable)
@@ -97,42 +97,47 @@ XGUI_WorkshopListener::~XGUI_WorkshopListener(void)
 //******************************************************
 void XGUI_WorkshopListener::initializeEventListening()
 {
+  ModuleBase_EventsListener* aListener = ModuleBase_EventsListener::instance();
+  connect(aListener, SIGNAL(hasEvent(ModuleBase_Event*)),
+    SLOT(processEvent(ModuleBase_Event*)), Qt::QueuedConnection);
   //Initialize event listening
-  Events_Loop* aLoop = Events_Loop::loop();
-  aLoop->registerListener(this, Events_InfoMessage::errorID());  //!< Listening application errors.
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  aLoop->registerListener(this, Events_LongOp::eventID());
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
-
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION));
-
-  aLoop->registerListener(this, Events_Loop::eventByName("FinishOperation"));
-  aLoop->registerListener(this, Events_Loop::eventByName("AbortOperation"));
+  //Events_Loop* aLoop = Events_Loop::loop();
+  //aLoop->registerListener(this, Events_InfoMessage::errorID());  //!< Listening application errors.
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  //aLoop->registerListener(this, Events_LongOp::eventID());
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
+
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
+  //aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION));
+
+  //aLoop->registerListener(this, Events_Loop::eventByName("FinishOperation"));
+  //aLoop->registerListener(this, Events_Loop::eventByName("AbortOperation"));
 }
 
 //******************************************************
-void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+void XGUI_WorkshopListener::processEvent(ModuleBase_Event* theMessage)
 {
+  std::shared_ptr<Events_Message> aMsg = theMessage->message();
+
   if (QApplication::instance() &&
       QApplication::instance()->thread() != QThread::currentThread()) {
     #ifdef _DEBUG
     std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
     #endif
     SessionPtr aMgr = ModelAPI_Session::get();
-    PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
+    PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(aMsg);
     QApplication::postEvent(this, aPostponeEvent);
     return;
   }
 
   // Process creation of Part
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+  if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     onFeatureCreatedMsg(aUpdMsg);
     if (myUpdatePrefs) {
       XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector();
@@ -141,19 +146,19 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
       myUpdatePrefs = false;
     }
   }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
     myUpdatePrefs = true;
   }
   // Redisplay feature
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     onFeatureRedisplayMsg(aUpdMsg);
-  } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)) {
+  } else if (aMsg->eventID() == Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     onFeatureEmptyPresentationMsg(aUpdMsg);
-  } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION)) {
+  } else if (aMsg->eventID() == Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION)) {
     ModuleBase_ModelWidget* aWidget = workshop()->propertyPanel()->activeWidget();
     if (aWidget) {
       ModuleBase_WidgetSelector* aWidgetSelector =
@@ -161,33 +166,33 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
       if (aWidgetSelector)
         workshop()->selector()->setSelected(aWidgetSelector->getAttributeSelection());
     }
-  } else if (theMessage->eventID() == Events_Loop::eventByName("FinishOperation")/* ||
+  } else if (aMsg->eventID() == Events_Loop::eventByName("FinishOperation")/* ||
              theMessage->eventID() == Events_Loop::eventByName("AbortOperation")*/)
     workshop()->facesPanel()->reset(false); // do not flush redisplay, it is flushed after event
 
   //Update property panel on corresponding message. If there is no current operation (no
   //property panel), or received message has different feature to the current - do nothing.
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
+  else if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(aMsg);
     onFeatureUpdatedMsg(anUpdateMsg);
-  } else if (theMessage->eventID() == Events_LongOp::eventID()) {
+  } else if (aMsg->eventID() == Events_LongOp::eventID()) {
     if (Events_LongOp::isPerformed()) {
       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     } else {
       QApplication::restoreOverrideCursor();
     }
-  } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
+  } else if (aMsg->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
     // the viewer's update context will not happens until viewer updated is emitted
       workshop()->displayer()->enableUpdateViewer(false);
-  } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
+  } else if (aMsg->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
     // the viewer's update context is unblocked, the viewer's update works
     XGUI_Displayer* aDisplayer = workshop()->displayer();
     aDisplayer->enableUpdateViewer(true);
   } else {
     //Show error dialog if error message received.
     std::shared_ptr<Events_InfoMessage> anIngfoMsg =
-      std::dynamic_pointer_cast<Events_InfoMessage>(theMessage);
+      std::dynamic_pointer_cast<Events_InfoMessage>(aMsg);
     if (anIngfoMsg) {
       emit errorOccurred(anIngfoMsg);
     }
@@ -460,7 +465,8 @@ bool XGUI_WorkshopListener::event(QEvent * theEvent)
   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
   if (aPostponedEv) {
     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
-    processEvent(aEventPtr);
+    ModuleBase_Event aEv(aEventPtr);
+    processEvent(&aEv);
     return true;
   }
   return false;
index c338535bdefd2205599700d8bd56ced599f6142e..9ee4b346be84c47dfe37023940acb6077e7c6ea4 100755 (executable)
@@ -22,6 +22,7 @@
 #define XGUI_WORKSHOP_LISTENER_H
 
 #include "XGUI.h"
+#include <ModuleBase_EventsListener.h>
 #include <Events_Listener.h>
 #include <Events_Message.h>
 
@@ -44,7 +45,7 @@ class Events_InfoMessage;
  * \ingroup GUI
  * \brief Class which process the events from the event loop.
  */
-class XGUI_EXPORT XGUI_WorkshopListener : public QObject, public Events_Listener
+class XGUI_EXPORT XGUI_WorkshopListener : public QObject//, public Events_Listener
 {
   Q_OBJECT
 public:
@@ -57,12 +58,15 @@ public:
   void initializeEventListening();
 
   //! Redefinition of Events_Listener method
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+  //virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
 signals:
   /// Emitted when error in applivation happens
   void errorOccurred(std::shared_ptr<Events_InfoMessage> theMsg);
 
+private slots:
+  void processEvent(ModuleBase_Event* theMessage);
+
 protected:
   /// Procedure to process postponed events
   bool event(QEvent * theEvent);