From: vsv Date: Tue, 16 Oct 2018 08:54:21 +0000 (+0300) Subject: Initial solution X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FTreads_control_development;p=modules%2Fshaper.git Initial solution --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index ee79fe186..6e84c8363 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 index 000000000..7553d1499 --- /dev/null +++ b/src/ModuleBase/ModuleBase_EventsListener.cpp @@ -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 +// + +#include "ModuleBase_EventsListener.h" +#include "ModuleBase_Events.h" + +#include + +#include +#include +#include +#include + + + +static ModuleBase_EventsListener* MYListener = NULL; + +//Q_DECLARE_METATYPE(EventMsgPtr) +//qRegisterMetaType>(); +//qRegisterMetaType>("std::shared_ptr"); + + +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& 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 index 000000000..31349bf50 --- /dev/null +++ b/src/ModuleBase/ModuleBase_EventsListener.h @@ -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 +// + +#ifndef ModuleBase_EventsListener_H +#define ModuleBase_EventsListener_H + +#include "ModuleBase.h" + +#include +#include + +#include +#include +#include + + +class MODULEBASE_EXPORT ModuleBase_Event: public QObject +{ + Q_OBJECT +public: + ModuleBase_Event() {} + + ModuleBase_Event(const std::shared_ptr& theMsg) : myMsg(theMsg) {} + + void setMessage(const std::shared_ptr& theMsg) { + myMsg = theMsg; + } + + std::shared_ptr message() const { return myMsg; } + +private: + std::shared_ptr 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& theMessage); + +signals: + void hasEvent(ModuleBase_Event* theMsg); + +protected: + virtual void run(); + +private: + ModuleBase_EventsListener(); + +private: + QList myMessages; + QMutex myMutex; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IconFactory.h b/src/ModuleBase/ModuleBase_IconFactory.h index b20fb23c0..0976114ba 100644 --- a/src/ModuleBase/ModuleBase_IconFactory.h +++ b/src/ModuleBase/ModuleBase_IconFactory.h @@ -27,13 +27,15 @@ #include #include #include +#include /**\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(); diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 91be0c34c..e08e5cf5a 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -48,6 +48,15 @@ #include #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(); diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 4ea8c6c44..c81b70b8c 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -22,6 +22,7 @@ #define ModuleBase_Operation_H #include +#include #include #include @@ -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 diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 04edf7957..5daa0c28a 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -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 index 000000000..233d883fa --- /dev/null +++ b/src/ModuleBase/ModuleBase_WorkController.cpp @@ -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 +// + +#include "ModuleBase_WorkController.h" +#include + +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 index 000000000..d6abe302d --- /dev/null +++ b/src/ModuleBase/ModuleBase_WorkController.h @@ -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 +// + +#ifndef ModuleBase_WorkController_H +#define ModuleBase_WorkController_H + +#include "ModuleBase.h" + +#include +#include + + +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 diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 0defdd96f..a40268164 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -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 diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 1780f0d44..bcce8d242 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -44,8 +44,11 @@ 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& theMessage) +void PartSet_CustomPrs::processEvent(ModuleBase_Event* theMessage) { - if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION)) + std::shared_ptr 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 } diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index 65c3bdf09..2b743168f 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -26,6 +26,8 @@ #include "PartSet_OperationPrs.h" #include +#include + #include #include #include @@ -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& theMessage); + virtual void processEvent(ModuleBase_Event* theMessage); private: /// Creates the AIS operation presentation diff --git a/src/PartSet/PartSet_IconFactory.cpp b/src/PartSet/PartSet_IconFactory.cpp index 42b3d4d62..e899a979e 100644 --- a/src/PartSet/PartSet_IconFactory.cpp +++ b/src/PartSet/PartSet_IconFactory.cpp @@ -35,8 +35,11 @@ QMap 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& theMessage) +void PartSet_IconFactory::processEvent(ModuleBase_Event* theMessage) { - if (theMessage->eventID() == + std::shared_ptr aMsg = theMessage->message(); + if (aMsg->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) { std::shared_ptr aFeatureMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); if (!aFeatureMsg->isInternal()) { ActionInfo aFeatureInfo; aFeatureInfo.initFrom(aFeatureMsg); diff --git a/src/PartSet/PartSet_IconFactory.h b/src/PartSet/PartSet_IconFactory.h index 092754e28..3e4df3ba8 100644 --- a/src/PartSet/PartSet_IconFactory.h +++ b/src/PartSet/PartSet_IconFactory.h @@ -23,7 +23,9 @@ #include "PartSet.h" #include -#include +#include +//#include +#include #include @@ -33,8 +35,10 @@ * \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& theMessage); + //virtual void processEvent(const std::shared_ptr& theMessage); + +private slots: + /// Event Listener method + /// \param theMessage an event message + virtual void processEvent(ModuleBase_Event* theMessage); private: static QMap myIcons; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index aa7b4e383..4b2816010 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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& theMessage) +void PartSet_Module::processEvent(ModuleBase_Event* theMessage) { - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) { + std::shared_ptr 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& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); std::set aObjects = aUpdMsg->objects(); ObjectPtr aConstrObj; diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3979a599b..633106a70 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -29,11 +29,12 @@ #include #include +#include #include #include #include -#include +//#include //#include #include @@ -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& theMessage); + // virtual void processEvent(const std::shared_ptr& 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 diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 6c7d19fe4..05c48bae5 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -91,6 +91,7 @@ SET(PROJECT_MOC_HEADERS XGUI_Workshop.h XGUI_WorkshopListener.h XGUI_InspectionPanel.h + XGUI_MenuMgr.h ) # sources / moc wrappings diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 0d7a57d33..29b1282ec 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -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& theMessage) +void XGUI_ActionsMgr::processEvent(ModuleBase_Event* theMessage) { + std::shared_ptr 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 aStateMessage = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); if (!aStateMessage.get()) return; std::list aFeaturesList = aStateMessage->features(); @@ -230,11 +231,6 @@ void XGUI_ActionsMgr::processEvent(const std::shared_ptr& 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 } } diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index 3773ae9ba..3048d146e 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -23,10 +23,10 @@ #include "XGUI.h" -#include #include #include +#include #include #include @@ -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& 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 diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 45354a917..825c73680 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -42,13 +42,16 @@ XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParen XGUI_ObjectsBrowser* aOB = qobject_cast(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& theMessage) +void XGUI_DataModel::processEvent(ModuleBase_Event* theMessage) { - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { + std::shared_ptr aMsg = theMessage->message(); + + if (aMsg->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { std::shared_ptr aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); std::set aObjects = aUpdMsg->objects(); QObjectPtrList aCreated; std::set::const_iterator aIt; @@ -82,9 +87,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); const std::list, std::string>>& aMsgGroups = aUpdMsg->groups(); std::list, std::string>>::const_iterator aIt; @@ -92,9 +97,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); std::set aObjects = aUpdMsg->objects(); QObjectPtrList aCreated; @@ -142,9 +147,9 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(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& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); std::set aObjects = aUpdMsg->objects(); QObjectPtrList aCreated; diff --git a/src/XGUI/XGUI_DataModel.h b/src/XGUI/XGUI_DataModel.h index 929f3afb3..5f17a04cd 100644 --- a/src/XGUI/XGUI_DataModel.h +++ b/src/XGUI/XGUI_DataModel.h @@ -23,6 +23,7 @@ #include "XGUI.h" #include +#include #include #include #include @@ -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& theMessage); + //virtual void processEvent(const std::shared_ptr& 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 myShownFolders; - //bool myIsEventsProcessingBlocked; ModuleBase_ITreeNode* myRoot; }; diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 577685a87..6116b3dd1 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -49,18 +49,20 @@ 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& theMessage) +void XGUI_MenuMgr::processEvent(ModuleBase_Event* theMessage) { + std::shared_ptr 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 aFeatureMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); if (!aFeatureMsg->isInternal()) { addFeature(aFeatureMsg); } diff --git a/src/XGUI/XGUI_MenuMgr.h b/src/XGUI/XGUI_MenuMgr.h index d122d8b53..6a23999e2 100755 --- a/src/XGUI/XGUI_MenuMgr.h +++ b/src/XGUI/XGUI_MenuMgr.h @@ -23,11 +23,12 @@ #include "XGUI.h" -#include +#include #include #include #include +#include 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& theMessage); + void processEvent(ModuleBase_Event* theMessage); protected: /// Process event "Add a feature" diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index f7720512d..1366e99bb 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -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& theMessage) +void XGUI_WorkshopListener::processEvent(ModuleBase_Event* theMessage) { + std::shared_ptr 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); onFeatureCreatedMsg(aUpdMsg); if (myUpdatePrefs) { XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector(); @@ -141,19 +146,19 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr& 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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(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 aUpdMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(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& 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 anUpdateMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(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 anIngfoMsg = - std::dynamic_pointer_cast(theMessage); + std::dynamic_pointer_cast(aMsg); if (anIngfoMsg) { emit errorOccurred(anIngfoMsg); } @@ -460,7 +465,8 @@ bool XGUI_WorkshopListener::event(QEvent * theEvent) PostponeMessageQtEvent* aPostponedEv = dynamic_cast(theEvent); if (aPostponedEv) { std::shared_ptr aEventPtr = aPostponedEv->postponedMessage(); - processEvent(aEventPtr); + ModuleBase_Event aEv(aEventPtr); + processEvent(&aEv); return true; } return false; diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index c338535bd..9ee4b346b 100755 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -22,6 +22,7 @@ #define XGUI_WORKSHOP_LISTENER_H #include "XGUI.h" +#include #include #include @@ -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& theMessage); + //virtual void processEvent(const std::shared_ptr& theMessage); signals: /// Emitted when error in applivation happens void errorOccurred(std::shared_ptr theMsg); +private slots: + void processEvent(ModuleBase_Event* theMessage); + protected: /// Procedure to process postponed events bool event(QEvent * theEvent);