diff --git a/applications/mne_scan/mne_scan/main.cpp b/applications/mne_scan/mne_scan/main.cpp index 89461d06455..a28fa17d30e 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 @@ -163,9 +164,8 @@ int main(int argc, char *argv[]) QCoreApplication::setApplicationName(CInfo::AppNameShort()); QCoreApplication::setOrganizationDomain("www.mne-cpp.org"); - SCMEASLIB::MeasurementTypes::registerTypes(); - - MainWindow mainWin; + //MainWindow mainWin; + ScanCore scanCore; QSurfaceFormat fmt; fmt.setSamples(10); diff --git a/applications/mne_scan/mne_scan/mainwindow.cpp b/applications/mne_scan/mne_scan/mainwindow.cpp index 1300ba0cfd1..ac2c834544a 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: @@ -57,6 +58,7 @@ #include #include "mainwindow.h" +#include "scancore.h" #include "startupwidget.h" #include "plugingui.h" #include "info.h" @@ -95,18 +97,17 @@ 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)) , 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") +, m_pScanCore(core) { printf( "%s - Version %s\n", CInfo::AppNameShort().toUtf8().constData(), @@ -122,11 +123,6 @@ MainWindow::MainWindow(QWidget *parent) initSplashScreen(); - setupPlugins(); - 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..."; @@ -159,9 +155,11 @@ 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; } //============================================================================================================= @@ -180,6 +178,8 @@ void MainWindow::setupUI() createLogDockWindow(); initStatusBar(); + + 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); @@ -912,13 +912,13 @@ 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); - 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 345e57dedac..bff503a08b4 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: @@ -91,6 +92,10 @@ namespace DISPLIB class QuickControlView; } +namespace MNESCAN { + class ScanCore; +} + //============================================================================================================= // DEFINE NAMESPACE MNESCAN //============================================================================================================= @@ -125,9 +130,11 @@ 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); + MainWindow(ScanCore& core); //========================================================================================================= /** @@ -166,7 +173,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 +202,8 @@ class MainWindow : public QMainWindow /** * Init an setup the plugins. */ - void setupPlugins(); + void setupPlugins(std::shared_ptr, + std::shared_ptr); //========================================================================================================= /** @@ -438,14 +448,16 @@ 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. */ 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/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..af131cbf5fd --- /dev/null +++ b/applications/mne_scan/mne_scan/scancore.cpp @@ -0,0 +1,116 @@ +//============================================================================================================= +/** + * @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 +//============================================================================================================= + +#include "scancore.h" +#include "mainwindow.h" + +#include + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +namespace MNESCAN { + +//============================================================================================================= +// CONST +//============================================================================================================= + +const QString pluginDir = "/mne_scan_plugins"; /**< holds path to plugins.*/ + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +ScanCore::ScanCore(QObject *parent) +: QObject(parent) +, m_bGuiMode(true) +{ + registerQtMetaTypes(); + + initPlugins(); + if(m_bGuiMode){ + initGUI(); //plugins must be initialized before GUI + } +} + +//============================================================================================================= + +void ScanCore::registerQtMetaTypes() +{ + SCMEASLIB::MeasurementTypes::registerTypes(); +} + +//============================================================================================================= + +void ScanCore::initPlugins() +{ + m_pPluginManager = std::make_shared(); + m_pPluginManager->loadPlugins(qApp->applicationDirPath() + pluginDir); + m_pPluginSceneManager = std::make_shared(); +} + +//============================================================================================================= + +void ScanCore::initGUI() +{ + m_pMainWindow = std::make_unique(*this); + m_pMainWindow->setupPlugins(m_pPluginManager, m_pPluginSceneManager); + m_pMainWindow->setupUI(); +} + +//============================================================================================================= + +bool ScanCore::startMeasurement() +{ + if(!m_pPluginSceneManager->startPlugins()) { + m_pPluginSceneManager->stopPlugins(); + return false; + } + return true; +} + +//============================================================================================================= + +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 new file mode 100644 index 00000000000..32d1432c038 --- /dev/null +++ b/applications/mne_scan/mne_scan/scancore.h @@ -0,0 +1,113 @@ +//============================================================================================================= +/** + * @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 + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "mainwindow.h" + +#include +#include + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// NAMESPACE +//============================================================================================================= + +namespace MNESCAN +{ + +//============================================================================================================= + +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: + //========================================================================================================= + /** + * 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(); + + 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 */ + +}; +}//namespace +#endif // SCANCORE_H