From d8ca5075e675454605c6c17e61b5e5b88a4851c9 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Mon, 24 Jan 2022 16:04:50 -0500 Subject: [PATCH 1/8] ENH: add scancore class --- applications/mne_scan/mne_scan/mne_scan.pro | 2 ++ applications/mne_scan/mne_scan/scancore.cpp | 6 +++++ applications/mne_scan/mne_scan/scancore.h | 28 +++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 applications/mne_scan/mne_scan/scancore.cpp create mode 100644 applications/mne_scan/mne_scan/scancore.h diff --git a/applications/mne_scan/mne_scan/mne_scan.pro b/applications/mne_scan/mne_scan/mne_scan.pro index 3ebc58c0b63..1474289ae63 100755 --- a/applications/mne_scan/mne_scan/mne_scan.pro +++ b/applications/mne_scan/mne_scan/mne_scan.pro @@ -144,6 +144,7 @@ CONFIG(debug, debug|release) { SOURCES += \ main.cpp \ mainsplashscreencloser.cpp \ + scancore.cpp \ startupwidget.cpp \ mainsplashscreen.cpp \ pluginscene.cpp \ @@ -155,6 +156,7 @@ SOURCES += \ HEADERS += \ info.h \ mainsplashscreencloser.h \ + scancore.h \ startupwidget.h \ mainsplashscreen.h \ pluginscene.h \ diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp new file mode 100644 index 00000000000..12f3c1b9053 --- /dev/null +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -0,0 +1,6 @@ +#include "scancore.h" + +ScanCore::ScanCore(QObject *parent) : QObject(parent) +{ + +} diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h new file mode 100644 index 00000000000..8be498d5529 --- /dev/null +++ b/applications/mne_scan/mne_scan/scancore.h @@ -0,0 +1,28 @@ +#ifndef SCANCORE_H +#define SCANCORE_H + +#include +#include + +#include "mainwindow.h" +#include "scShared/Management/pluginmanager.h" + +namespace MNESCAN +{ + +class ScanCore : public QObject +{ + Q_OBJECT +public: + explicit ScanCore(QObject *parent = nullptr); + +private: + void loadPlugins(); + + void loadGui(); + + std::unique_ptr p_MainWindow; + std::shared_ptr p_PluginManager; +}; +}//namespace +#endif // SCANCORE_H From 8103e3798114cfc73385dd786098bf390e56732d Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Thu, 27 Jan 2022 17:56:36 -0500 Subject: [PATCH 2/8] MAINT: migrating functions --- applications/mne_scan/mne_scan/main.cpp | 2 + applications/mne_scan/mne_scan/scancore.cpp | 59 ++++++++++++++++++++- applications/mne_scan/mne_scan/scancore.h | 11 ++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/applications/mne_scan/mne_scan/main.cpp b/applications/mne_scan/mne_scan/main.cpp index 89461d06455..ea71ada6038 100644 --- a/applications/mne_scan/mne_scan/main.cpp +++ b/applications/mne_scan/mne_scan/main.cpp @@ -39,6 +39,7 @@ #include "mainsplashscreen.h" #include "mainwindow.h" +#include "scancore.h" #include #include @@ -166,6 +167,7 @@ int main(int argc, char *argv[]) SCMEASLIB::MeasurementTypes::registerTypes(); MainWindow mainWin; + ScanCore scanCore; QSurfaceFormat fmt; fmt.setSamples(10); diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 12f3c1b9053..b1914fcfb18 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -1,6 +1,63 @@ +//============================================================================================================= +// INCLUDES +//============================================================================================================= + #include "scancore.h" -ScanCore::ScanCore(QObject *parent) : QObject(parent) +#include + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +namespace MNESCAN { + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +ScanCore::ScanCore(QObject *parent) +: QObject(parent) +{ + registerMetatypes(); + + initPluginManager(); + initMainWindow(); +} + +//============================================================================================================= + +void ScanCore::registerMetatypes() +{ + SCMEASLIB::MeasurementTypes::registerTypes(); +} + +//============================================================================================================= + +void ScanCore::initPluginManager() +{ + m_pPluginManager = std::make_shared(); +} + +//============================================================================================================= + +void ScanCore::initMainWindow() +{ + m_pMainWindow = std::make_unique(); +} + +//============================================================================================================= + +void ScanCore::startMeasurement() { } + +//============================================================================================================= + +void ScanCore::stopMeasurement() +{ + +} + +} //namespace diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h index 8be498d5529..bf4213c91b3 100644 --- a/applications/mne_scan/mne_scan/scancore.h +++ b/applications/mne_scan/mne_scan/scancore.h @@ -17,12 +17,15 @@ class ScanCore : public QObject explicit ScanCore(QObject *parent = nullptr); private: - void loadPlugins(); - void loadGui(); + void registerMetatypes(); + void initPluginManager(); + void initMainWindow(); - std::unique_ptr p_MainWindow; - std::shared_ptr p_PluginManager; + std::unique_ptr m_pMainWindow; + std::shared_ptr m_pPluginManager; + + bool m_bIsRunning; }; }//namespace #endif // SCANCORE_H From c3f8dd93deec136163f225c42168a7b7d5437800 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 11:07:10 -0500 Subject: [PATCH 3/8] MAINT: init plugins from core, pass to window gui --- applications/mne_scan/mne_scan/mainwindow.cpp | 10 +-- applications/mne_scan/mne_scan/mainwindow.h | 15 +++-- applications/mne_scan/mne_scan/scancore.cpp | 35 +++++++++++ applications/mne_scan/mne_scan/scancore.h | 61 +++++++++++++++++-- 4 files changed, 107 insertions(+), 14 deletions(-) diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index 1300ba0cfd1..19e16ad41ea 100644 --- a/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/applications/mne_scan/mne_scan/mainwindow.cpp @@ -102,8 +102,6 @@ MainWindow::MainWindow(QWidget *parent) , m_pStartUpWidget(new StartUpWidget(this)) , m_eLogLevelCurrent(_LogLvMax) , m_pTime(new QTime(0, 0)) -, m_pPluginManager(new SCSHAREDLIB::PluginManager(this)) -, m_pPluginSceneManager(new SCSHAREDLIB::PluginSceneManager(this)) , m_pDisplayManager(new SCSHAREDLIB::DisplayManager(this)) , m_sSettingsPath("MNESCAN/MainWindow") , m_sCurrentStyle("default") @@ -159,9 +157,12 @@ MainWindow::~MainWindow() //============================================================================================================= -void MainWindow::setupPlugins() +void MainWindow::setupPlugins(std::shared_ptr pPluginManager, + std::shared_ptr pPluginSceneManager) { - m_pPluginManager->loadPlugins(qApp->applicationDirPath()+pluginDir); + m_pPluginManager = pPluginManager; + m_pPluginSceneManager = pPluginSceneManager; + createPluginDockWindow(); } //============================================================================================================= @@ -176,7 +177,6 @@ void MainWindow::setupUI() createActions(); createMenus(); createToolBars(); - createPluginDockWindow(); createLogDockWindow(); initStatusBar(); diff --git a/applications/mne_scan/mne_scan/mainwindow.h b/applications/mne_scan/mne_scan/mainwindow.h index 345e57dedac..bbda3cd897c 100644 --- a/applications/mne_scan/mne_scan/mainwindow.h +++ b/applications/mne_scan/mne_scan/mainwindow.h @@ -125,7 +125,9 @@ class MainWindow : public QMainWindow /** * Constructs a MainWindow which is a child of parent. * - * @param[in] parent pointer to parent widget; If parent is Q_NULLPTR, the new MainWindow becomes a window. If parent is another widget, MainWindow becomes a child window inside parent. MainWindow is deleted when its parent is deleted. + * @param[in] parent pointer to parent widget; If parent is Q_NULLPTR, the new MainWindow becomes + * a window. If parent is another widget, MainWindow becomes a child window inside + * parent. MainWindow is deleted when its parent is deleted. */ MainWindow(QWidget *parent = Q_NULLPTR); @@ -166,7 +168,9 @@ class MainWindow : public QMainWindow * @param[in] lgknd message kind; Message is formated depending on its kind. * @param[in] lglvl message level; Message is displayed depending on its level. */ - void writeToLog(const QString& logMsg, LogKind lgknd = _LogKndMessage, LogLevel lglvl = _LogLvNormal); + void writeToLog(const QString& logMsg, + LogKind lgknd = _LogKndMessage, + LogLevel lglvl = _LogLvNormal); //========================================================================================================= /** @@ -193,7 +197,8 @@ class MainWindow : public QMainWindow /** * Init an setup the plugins. */ - void setupPlugins(); + void setupPlugins(std::shared_ptr, + std::shared_ptr); //========================================================================================================= /** @@ -438,8 +443,8 @@ class MainWindow : public QMainWindow QSharedPointer m_pTimer; /**< timer of the main application*/ QSharedPointer m_pTime; /**< Holds current time output, updated with timeout of timer.*/ - QSharedPointer m_pPluginManager; /**< Holds log dock widget.*/ - QSharedPointer m_pPluginSceneManager; /**< Plugin scene manager which manages the plugin graph. */ + std::shared_ptr m_pPluginManager; /**< Holds log dock widget.*/ + std::shared_ptr m_pPluginSceneManager; /**< Plugin scene manager which manages the plugin graph. */ QSharedPointer m_pAboutWindow; /**< Holds the widget containing the about information.*/ QSharedPointer m_pDisplayManager; /**< display manager. */ diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index b1914fcfb18..8888eefc9cd 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -1,3 +1,37 @@ +//============================================================================================================= +/** + * @file scancore.cpp + * @author Gabriel Motta ; + * @since 0.1.9 + * @date January, 2022 + * + * @section LICENSE + * + * Copyright (C) 2022, Gabriel Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Definition of the ScanCore class. + * + */ + //============================================================================================================= // INCLUDES //============================================================================================================= @@ -44,6 +78,7 @@ void ScanCore::initPluginManager() void ScanCore::initMainWindow() { m_pMainWindow = std::make_unique(); + m_pMainWindow->setupPlugins(m_pPluginManager, m_pPluginSceneManager); } //============================================================================================================= diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h index bf4213c91b3..8b3475cc0ae 100644 --- a/applications/mne_scan/mne_scan/scancore.h +++ b/applications/mne_scan/mne_scan/scancore.h @@ -1,29 +1,82 @@ +//============================================================================================================= +/** + * @file scancore.h + * @author Gabriel Motta ; + * @since 0.1.9 + * @date January, 2022 + * + * @section LICENSE + * + * Copyright (C) 2022, Gabriel Motta. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * @brief Declaration of the ScanCore class. + * + */ + #ifndef SCANCORE_H #define SCANCORE_H -#include -#include +//============================================================================================================= +// INCLUDES +//============================================================================================================= #include "mainwindow.h" -#include "scShared/Management/pluginmanager.h" + +#include +#include + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// NAMESPACE +//============================================================================================================= namespace MNESCAN { + class ScanCore : public QObject { Q_OBJECT public: explicit ScanCore(QObject *parent = nullptr); -private: + void startMeasurement(); + void stopMeasurement(); +private: void registerMetatypes(); void initPluginManager(); void initMainWindow(); std::unique_ptr m_pMainWindow; std::shared_ptr m_pPluginManager; + std::shared_ptr m_pPluginSceneManager; bool m_bIsRunning; }; From 31910ce2d1902e04e204dee929224e1572c57f4f Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 12:02:10 -0500 Subject: [PATCH 4/8] MAINT: Loading plugins correctly. --- applications/mne_scan/mne_scan/main.cpp | 2 +- applications/mne_scan/mne_scan/mainwindow.cpp | 10 +++++----- applications/mne_scan/mne_scan/mainwindow.h | 5 +++-- applications/mne_scan/mne_scan/scancore.cpp | 7 +++++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/applications/mne_scan/mne_scan/main.cpp b/applications/mne_scan/mne_scan/main.cpp index ea71ada6038..31a9843e0c5 100644 --- a/applications/mne_scan/mne_scan/main.cpp +++ b/applications/mne_scan/mne_scan/main.cpp @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) SCMEASLIB::MeasurementTypes::registerTypes(); - MainWindow mainWin; + //MainWindow mainWin; ScanCore scanCore; QSurfaceFormat fmt; diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index 19e16ad41ea..459066a6de3 100644 --- a/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/applications/mne_scan/mne_scan/mainwindow.cpp @@ -2,13 +2,14 @@ /** * @file mainwindow.cpp * @author Christoph Dinh ; - * Lorenz Esch + * Lorenz Esch ; + * Gabriel B Motta * @since 0.1.0 * @date February, 2013 * * @section LICENSE * - * Copyright (C) 2013, Christoph Dinh, Lorenz Esch. All rights reserved. + * Copyright (C) 2013, Christoph Dinh, Lorenz Esch, Gabriel B Motta. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that * the following conditions are met: @@ -120,7 +121,6 @@ MainWindow::MainWindow(QWidget *parent) initSplashScreen(); - setupPlugins(); setupUI(); loadSettings(); @@ -271,7 +271,7 @@ void MainWindow::initSplashScreen(bool bShowSplashScreen) m_pSplashScreen = MainSplashScreen::SPtr::create(splashPixMap, Qt::WindowFlags() | Qt::WindowStaysOnTopHint ); if(m_pSplashScreen && m_pPluginManager) { - QObject::connect(m_pPluginManager.data(), &PluginManager::pluginLoaded, + QObject::connect(m_pPluginManager.get(), &PluginManager::pluginLoaded, m_pSplashScreen.data(), &MainSplashScreen::showMessage); } @@ -692,7 +692,7 @@ void MainWindow::createPluginDockWindow() m_pPluginGuiDockWidget = new QDockWidget(tr("Plugins"), this); m_pPluginGuiDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - m_pPluginGui = new PluginGui(m_pPluginManager.data(), m_pPluginSceneManager.data()); + m_pPluginGui = new PluginGui(m_pPluginManager.get(), m_pPluginSceneManager.get()); m_pPluginGui->setParent(m_pPluginGuiDockWidget); m_pPluginGuiDockWidget->setWidget(m_pPluginGui); diff --git a/applications/mne_scan/mne_scan/mainwindow.h b/applications/mne_scan/mne_scan/mainwindow.h index bbda3cd897c..b81158454c8 100644 --- a/applications/mne_scan/mne_scan/mainwindow.h +++ b/applications/mne_scan/mne_scan/mainwindow.h @@ -2,13 +2,14 @@ /** * @file mainwindow.h * @author Christoph Dinh ; - * Lorenz Esch + * Lorenz Esch ; + * Gabriel B Motta * @since 0.1.0 * @date February, 2013 * * @section LICENSE * - * Copyright (C) 2013, Christoph Dinh, Lorenz Esch. All rights reserved. + * Copyright (C) 2013, Christoph Dinh, Lorenz Esch, Gabriel B Motta. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that * the following conditions are met: diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 8888eefc9cd..0792ec70f5b 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -46,6 +46,12 @@ namespace MNESCAN { +//============================================================================================================= +// CONST +//============================================================================================================= + +const QString pluginDir = "/mne_scan_plugins"; /**< holds path to plugins.*/ + //============================================================================================================= // DEFINE MEMBER METHODS //============================================================================================================= @@ -71,6 +77,7 @@ void ScanCore::registerMetatypes() void ScanCore::initPluginManager() { m_pPluginManager = std::make_shared(); + m_pPluginManager->loadPlugins(qApp->applicationDirPath() + pluginDir); } //============================================================================================================= From d687c9b12b2405037e229a873cf7463a72b124ac Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 14:16:53 -0500 Subject: [PATCH 5/8] MAINT: starting/stopping plugins --- applications/mne_scan/mne_scan/mainwindow.cpp | 6 +++--- applications/mne_scan/mne_scan/mainwindow.h | 6 ++++++ applications/mne_scan/mne_scan/scancore.cpp | 14 ++++++++++---- applications/mne_scan/mne_scan/scancore.h | 12 ++++++++---- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index 459066a6de3..ec81f5f9bd9 100644 --- a/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/applications/mne_scan/mne_scan/mainwindow.cpp @@ -58,6 +58,7 @@ #include #include "mainwindow.h" +#include "scancore.h" #include "startupwidget.h" #include "plugingui.h" #include "info.h" @@ -916,9 +917,8 @@ void MainWindow::startMeasurement() writeToLog(tr("Starting real-time measurement..."), _LogKndMessage, _LogLvMin); - if(!m_pPluginSceneManager->startPlugins()) { + if(!m_pScanCore->startMeasurement()) { QMessageBox::information(0, tr("MNE Scan - Start"), QString(QObject::tr("Not able to start all plugins!")), QMessageBox::Ok); - m_pPluginSceneManager->stopPlugins(); return; } @@ -944,7 +944,7 @@ void MainWindow::stopMeasurement() writeToLog(tr("Stopping real-time measurement..."), _LogKndMessage, _LogLvMin); //Stop all plugins - m_pPluginSceneManager->stopPlugins(); + m_pScanCore->stopMeasurement(); m_pDisplayManager->clean(); // Hide and clear QuickControlView diff --git a/applications/mne_scan/mne_scan/mainwindow.h b/applications/mne_scan/mne_scan/mainwindow.h index b81158454c8..b973023da77 100644 --- a/applications/mne_scan/mne_scan/mainwindow.h +++ b/applications/mne_scan/mne_scan/mainwindow.h @@ -92,6 +92,10 @@ namespace DISPLIB class QuickControlView; } +namespace MNESCAN { + class ScanCore; +} + //============================================================================================================= // DEFINE NAMESPACE MNESCAN //============================================================================================================= @@ -452,6 +456,8 @@ class MainWindow : public QMainWindow QString m_sSettingsPath; /**< The settings path to store the GUI settings to. */ QString m_sCurrentStyle; /**< The currently selected style (dark mode, default mode). */ + MNESCAN::ScanCore* m_pScanCore; /**< The core of mnescan */ + signals: //========================================================================================================= /** diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 0792ec70f5b..2802fc92542 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -37,6 +37,7 @@ //============================================================================================================= #include "scancore.h" +#include "mainwindow.h" #include @@ -90,16 +91,21 @@ void ScanCore::initMainWindow() //============================================================================================================= -void ScanCore::startMeasurement() +bool ScanCore::startMeasurement() { - + if(!m_pPluginSceneManager->startPlugins()) { + m_pPluginSceneManager->stopPlugins(); + return false; + } + return true; } //============================================================================================================= -void ScanCore::stopMeasurement() +bool ScanCore::stopMeasurement() { - + m_pPluginSceneManager->stopPlugins(); + return true; } } //namespace diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h index 8b3475cc0ae..6f59f4cc5ca 100644 --- a/applications/mne_scan/mne_scan/scancore.h +++ b/applications/mne_scan/mne_scan/scancore.h @@ -39,8 +39,6 @@ // INCLUDES //============================================================================================================= -#include "mainwindow.h" - #include #include @@ -59,15 +57,21 @@ namespace MNESCAN { +//============================================================================================================= +// FORWARD DECLARATION +//============================================================================================================= +class MainWindow; + +//============================================================================================================= class ScanCore : public QObject { Q_OBJECT public: explicit ScanCore(QObject *parent = nullptr); - void startMeasurement(); - void stopMeasurement(); + bool startMeasurement(); + bool stopMeasurement(); private: void registerMetatypes(); From 929f89daee0fcc67e49b9f1c8f1eb392a17ec7cd Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 15:30:27 -0500 Subject: [PATCH 6/8] MAINT: debugging uninitialized values and passing core to window --- applications/mne_scan/mne_scan/mainwindow.cpp | 14 +++++++------- applications/mne_scan/mne_scan/mainwindow.h | 2 +- applications/mne_scan/mne_scan/scancore.cpp | 16 +++++++++++----- applications/mne_scan/mne_scan/scancore.h | 12 +++++------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index ec81f5f9bd9..c073e004d31 100644 --- a/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/applications/mne_scan/mne_scan/mainwindow.cpp @@ -97,8 +97,8 @@ constexpr unsigned long waitUntilHidingSplashScreen(1); /**< Seconds to wait // DEFINE MEMBER METHODS //============================================================================================================= -MainWindow::MainWindow(QWidget *parent) -: QMainWindow(parent) +MainWindow::MainWindow(ScanCore *core) +: QMainWindow(nullptr) , m_bIsRunning(false) , m_iTimeoutMSec(1000) , m_pStartUpWidget(new StartUpWidget(this)) @@ -107,6 +107,7 @@ MainWindow::MainWindow(QWidget *parent) , m_pDisplayManager(new SCSHAREDLIB::DisplayManager(this)) , m_sSettingsPath("MNESCAN/MainWindow") , m_sCurrentStyle("default") +, m_pScanCore(core) { printf( "%s - Version %s\n", CInfo::AppNameShort().toUtf8().constData(), @@ -122,10 +123,6 @@ MainWindow::MainWindow(QWidget *parent) initSplashScreen(); - setupUI(); - - loadSettings(); - //Load application icon for linux builds only, mac and win executables have built in icons from .pro file #ifdef __linux__ qInfo() << "Loading icon..."; @@ -163,7 +160,6 @@ void MainWindow::setupPlugins(std::shared_ptr pPlugi { m_pPluginManager = pPluginManager; m_pPluginSceneManager = pPluginSceneManager; - createPluginDockWindow(); } //============================================================================================================= @@ -178,9 +174,12 @@ void MainWindow::setupUI() createActions(); createMenus(); createToolBars(); + createPluginDockWindow(); createLogDockWindow(); initStatusBar(); + + loadSettings(); } //============================================================================================================= @@ -913,6 +912,7 @@ void MainWindow::writeToLog(const QString& logMsg, void MainWindow::startMeasurement() { // Save pipeline before starting just in case a crash occurs + std::cout << "Hey!\n"; m_pPluginGui->saveConfig(QStandardPaths::writableLocation(QStandardPaths::DataLocation),"default.xml"); writeToLog(tr("Starting real-time measurement..."), _LogKndMessage, _LogLvMin); diff --git a/applications/mne_scan/mne_scan/mainwindow.h b/applications/mne_scan/mne_scan/mainwindow.h index b973023da77..9a549d1b4d3 100644 --- a/applications/mne_scan/mne_scan/mainwindow.h +++ b/applications/mne_scan/mne_scan/mainwindow.h @@ -134,7 +134,7 @@ class MainWindow : public QMainWindow * a window. If parent is another widget, MainWindow becomes a child window inside * parent. MainWindow is deleted when its parent is deleted. */ - MainWindow(QWidget *parent = Q_NULLPTR); + MainWindow(ScanCore* core); //========================================================================================================= /** diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 2802fc92542..1f32efd31eb 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -59,11 +59,15 @@ const QString pluginDir = "/mne_scan_plugins"; /**< holds path to plugi ScanCore::ScanCore(QObject *parent) : QObject(parent) +, m_bGuiMode(true) { registerMetatypes(); - initPluginManager(); - initMainWindow(); + initPlugins(); + + if(m_bGuiMode){ + initGUI(); + } } //============================================================================================================= @@ -75,18 +79,20 @@ void ScanCore::registerMetatypes() //============================================================================================================= -void ScanCore::initPluginManager() +void ScanCore::initPlugins() { m_pPluginManager = std::make_shared(); m_pPluginManager->loadPlugins(qApp->applicationDirPath() + pluginDir); + m_pPluginSceneManager = std::make_shared(); } //============================================================================================================= -void ScanCore::initMainWindow() +void ScanCore::initGUI() { - m_pMainWindow = std::make_unique(); + m_pMainWindow = std::make_unique(this); m_pMainWindow->setupPlugins(m_pPluginManager, m_pPluginSceneManager); + m_pMainWindow->setupUI(); } //============================================================================================================= diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h index 6f59f4cc5ca..ca57df36b33 100644 --- a/applications/mne_scan/mne_scan/scancore.h +++ b/applications/mne_scan/mne_scan/scancore.h @@ -39,6 +39,8 @@ // INCLUDES //============================================================================================================= +#include "mainwindow.h" + #include #include @@ -57,13 +59,8 @@ namespace MNESCAN { -//============================================================================================================= -// FORWARD DECLARATION //============================================================================================================= -class MainWindow; - -//============================================================================================================= class ScanCore : public QObject { Q_OBJECT @@ -75,14 +72,15 @@ class ScanCore : public QObject private: void registerMetatypes(); - void initPluginManager(); - void initMainWindow(); + void initPlugins(); + void initGUI(); std::unique_ptr m_pMainWindow; std::shared_ptr m_pPluginManager; std::shared_ptr m_pPluginSceneManager; bool m_bIsRunning; + bool m_bGuiMode; }; }//namespace #endif // SCANCORE_H From b1370f2d653efd9d1450231ea6faaf20a24b86b3 Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 17:31:47 -0500 Subject: [PATCH 7/8] MAINT: prefer references to pointers --- applications/mne_scan/mne_scan/mainwindow.cpp | 6 +++--- applications/mne_scan/mne_scan/mainwindow.h | 4 ++-- applications/mne_scan/mne_scan/scancore.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index c073e004d31..ac2c834544a 100644 --- a/applications/mne_scan/mne_scan/mainwindow.cpp +++ b/applications/mne_scan/mne_scan/mainwindow.cpp @@ -97,7 +97,7 @@ constexpr unsigned long waitUntilHidingSplashScreen(1); /**< Seconds to wait // DEFINE MEMBER METHODS //============================================================================================================= -MainWindow::MainWindow(ScanCore *core) +MainWindow::MainWindow(ScanCore& core) : QMainWindow(nullptr) , m_bIsRunning(false) , m_iTimeoutMSec(1000) @@ -917,7 +917,7 @@ void MainWindow::startMeasurement() writeToLog(tr("Starting real-time measurement..."), _LogKndMessage, _LogLvMin); - if(!m_pScanCore->startMeasurement()) { + if(!m_pScanCore.startMeasurement()) { QMessageBox::information(0, tr("MNE Scan - Start"), QString(QObject::tr("Not able to start all plugins!")), QMessageBox::Ok); return; } @@ -944,7 +944,7 @@ void MainWindow::stopMeasurement() writeToLog(tr("Stopping real-time measurement..."), _LogKndMessage, _LogLvMin); //Stop all plugins - m_pScanCore->stopMeasurement(); + m_pScanCore.stopMeasurement(); m_pDisplayManager->clean(); // Hide and clear QuickControlView diff --git a/applications/mne_scan/mne_scan/mainwindow.h b/applications/mne_scan/mne_scan/mainwindow.h index 9a549d1b4d3..bff503a08b4 100644 --- a/applications/mne_scan/mne_scan/mainwindow.h +++ b/applications/mne_scan/mne_scan/mainwindow.h @@ -134,7 +134,7 @@ class MainWindow : public QMainWindow * a window. If parent is another widget, MainWindow becomes a child window inside * parent. MainWindow is deleted when its parent is deleted. */ - MainWindow(ScanCore* core); + MainWindow(ScanCore& core); //========================================================================================================= /** @@ -456,7 +456,7 @@ class MainWindow : public QMainWindow QString m_sSettingsPath; /**< The settings path to store the GUI settings to. */ QString m_sCurrentStyle; /**< The currently selected style (dark mode, default mode). */ - MNESCAN::ScanCore* m_pScanCore; /**< The core of mnescan */ + MNESCAN::ScanCore& m_pScanCore; /**< The core of mnescan */ signals: //========================================================================================================= diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 1f32efd31eb..9f0e8466c7c 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -90,7 +90,7 @@ void ScanCore::initPlugins() void ScanCore::initGUI() { - m_pMainWindow = std::make_unique(this); + m_pMainWindow = std::make_unique(*this); m_pMainWindow->setupPlugins(m_pPluginManager, m_pPluginSceneManager); m_pMainWindow->setupUI(); } From 9c0b186fca9f6da22aa6a8bbadfb8d347d177cda Mon Sep 17 00:00:00 2001 From: Gabriel B Motta Date: Fri, 28 Jan 2022 17:53:27 -0500 Subject: [PATCH 8/8] DOC, MAINT: add documentation for functions. Remove unused vars, change names. --- applications/mne_scan/mne_scan/main.cpp | 2 -- applications/mne_scan/mne_scan/scancore.cpp | 7 ++-- applications/mne_scan/mne_scan/scancore.h | 39 +++++++++++++++++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/applications/mne_scan/mne_scan/main.cpp b/applications/mne_scan/mne_scan/main.cpp index 31a9843e0c5..a28fa17d30e 100644 --- a/applications/mne_scan/mne_scan/main.cpp +++ b/applications/mne_scan/mne_scan/main.cpp @@ -164,8 +164,6 @@ int main(int argc, char *argv[]) QCoreApplication::setApplicationName(CInfo::AppNameShort()); QCoreApplication::setOrganizationDomain("www.mne-cpp.org"); - SCMEASLIB::MeasurementTypes::registerTypes(); - //MainWindow mainWin; ScanCore scanCore; diff --git a/applications/mne_scan/mne_scan/scancore.cpp b/applications/mne_scan/mne_scan/scancore.cpp index 9f0e8466c7c..af131cbf5fd 100644 --- a/applications/mne_scan/mne_scan/scancore.cpp +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -61,18 +61,17 @@ ScanCore::ScanCore(QObject *parent) : QObject(parent) , m_bGuiMode(true) { - registerMetatypes(); + registerQtMetaTypes(); initPlugins(); - if(m_bGuiMode){ - initGUI(); + initGUI(); //plugins must be initialized before GUI } } //============================================================================================================= -void ScanCore::registerMetatypes() +void ScanCore::registerQtMetaTypes() { SCMEASLIB::MeasurementTypes::registerTypes(); } diff --git a/applications/mne_scan/mne_scan/scancore.h b/applications/mne_scan/mne_scan/scancore.h index ca57df36b33..32d1432c038 100644 --- a/applications/mne_scan/mne_scan/scancore.h +++ b/applications/mne_scan/mne_scan/scancore.h @@ -65,22 +65,49 @@ class ScanCore : public QObject { Q_OBJECT public: + //========================================================================================================= + /** + * Constructs a ScanCore object. Main object that controls MNE Scan. + */ explicit ScanCore(QObject *parent = nullptr); + //========================================================================================================= + /** + * Attempts to start current workflow. Returns wheteher successful. + */ bool startMeasurement(); + + //========================================================================================================= + /** + * Attempts to stop current workflow. Returns wheteher successful. + */ bool stopMeasurement(); private: - void registerMetatypes(); + //========================================================================================================= + /** + * Registers types with Qt for use in QVariant and signals/slots. + */ + void registerQtMetaTypes(); + + //========================================================================================================= + /** + * Inititlaizes plguins management classes and loads plugins. + */ void initPlugins(); + + //========================================================================================================= + /** + * Initializes GUI elements. + */ void initGUI(); - std::unique_ptr m_pMainWindow; - std::shared_ptr m_pPluginManager; - std::shared_ptr m_pPluginSceneManager; + bool m_bGuiMode; /**< Whether to use a GUI. */ + std::unique_ptr m_pMainWindow; /**< GUI main window. */ + + std::shared_ptr m_pPluginManager; /**< Loads and holds plugins. */ + std::shared_ptr m_pPluginSceneManager; /**< Stores selected and running plugins */ - bool m_bIsRunning; - bool m_bGuiMode; }; }//namespace #endif // SCANCORE_H