Skip to content

Commit

Permalink
Merge 9c0b186 into 8de6344
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbmotta authored Jan 28, 2022
2 parents 8de6344 + 9c0b186 commit 351ed3a
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 29 deletions.
6 changes: 3 additions & 3 deletions applications/mne_scan/mne_scan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "mainsplashscreen.h"
#include "mainwindow.h"
#include "scancore.h"

#include <scMeas/measurementtypes.h>
#include <scMeas/realtimemultisamplearray.h>
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions applications/mne_scan/mne_scan/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/**
* @file mainwindow.cpp
* @author Christoph Dinh <chdinh@nmr.mgh.harvard.edu>;
* Lorenz Esch <lesch@mgh.harvard.edu>
* Lorenz Esch <lesch@mgh.harvard.edu>;
* Gabriel B Motta <gbmotta@mgh.harvard.edu>
* @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:
Expand Down Expand Up @@ -57,6 +58,7 @@
#include <utils/buildinfo.h>

#include "mainwindow.h"
#include "scancore.h"
#include "startupwidget.h"
#include "plugingui.h"
#include "info.h"
Expand Down Expand Up @@ -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(),
Expand All @@ -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...";
Expand Down Expand Up @@ -159,9 +155,11 @@ MainWindow::~MainWindow()

//=============================================================================================================

void MainWindow::setupPlugins()
void MainWindow::setupPlugins(std::shared_ptr<SCSHAREDLIB::PluginManager> pPluginManager,
std::shared_ptr<SCSHAREDLIB::PluginSceneManager> pPluginSceneManager)
{
m_pPluginManager->loadPlugins(qApp->applicationDirPath()+pluginDir);
m_pPluginManager = pPluginManager;
m_pPluginSceneManager = pPluginSceneManager;
}

//=============================================================================================================
Expand All @@ -180,6 +178,8 @@ void MainWindow::setupUI()
createLogDockWindow();

initStatusBar();

loadSettings();
}

//=============================================================================================================
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down
28 changes: 20 additions & 8 deletions applications/mne_scan/mne_scan/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/**
* @file mainwindow.h
* @author Christoph Dinh <chdinh@nmr.mgh.harvard.edu>;
* Lorenz Esch <lesch@mgh.harvard.edu>
* Lorenz Esch <lesch@mgh.harvard.edu>;
* Gabriel B Motta <gbmotta@mgh.harvard.edu>
* @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:
Expand Down Expand Up @@ -91,6 +92,10 @@ namespace DISPLIB
class QuickControlView;
}

namespace MNESCAN {
class ScanCore;
}

//=============================================================================================================
// DEFINE NAMESPACE MNESCAN
//=============================================================================================================
Expand Down Expand Up @@ -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);

//=========================================================================================================
/**
Expand Down Expand Up @@ -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);

//=========================================================================================================
/**
Expand All @@ -193,7 +202,8 @@ class MainWindow : public QMainWindow
/**
* Init an setup the plugins.
*/
void setupPlugins();
void setupPlugins(std::shared_ptr<SCSHAREDLIB::PluginManager>,
std::shared_ptr<SCSHAREDLIB::PluginSceneManager>);

//=========================================================================================================
/**
Expand Down Expand Up @@ -438,14 +448,16 @@ class MainWindow : public QMainWindow

QSharedPointer<QTimer> m_pTimer; /**< timer of the main application*/
QSharedPointer<QTime> m_pTime; /**< Holds current time output, updated with timeout of timer.*/
QSharedPointer<SCSHAREDLIB::PluginManager> m_pPluginManager; /**< Holds log dock widget.*/
QSharedPointer<SCSHAREDLIB::PluginSceneManager> m_pPluginSceneManager; /**< Plugin scene manager which manages the plugin graph. */
std::shared_ptr<SCSHAREDLIB::PluginManager> m_pPluginManager; /**< Holds log dock widget.*/
std::shared_ptr<SCSHAREDLIB::PluginSceneManager> m_pPluginSceneManager; /**< Plugin scene manager which manages the plugin graph. */
QSharedPointer<QWidget> m_pAboutWindow; /**< Holds the widget containing the about information.*/
QSharedPointer<SCSHAREDLIB::DisplayManager> 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:
//=========================================================================================================
/**
Expand Down
2 changes: 2 additions & 0 deletions applications/mne_scan/mne_scan/mne_scan.pro
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ CONFIG(debug, debug|release) {
SOURCES += \
main.cpp \
mainsplashscreencloser.cpp \
scancore.cpp \
startupwidget.cpp \
mainsplashscreen.cpp \
pluginscene.cpp \
Expand All @@ -155,6 +156,7 @@ SOURCES += \
HEADERS += \
info.h \
mainsplashscreencloser.h \
scancore.h \
startupwidget.h \
mainsplashscreen.h \
pluginscene.h \
Expand Down
116 changes: 116 additions & 0 deletions applications/mne_scan/mne_scan/scancore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//=============================================================================================================
/**
* @file scancore.cpp
* @author Gabriel Motta <gbmotta@mgh.harvard.edu>;
* @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 <scMeas/measurementtypes.h>

//=============================================================================================================
// 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<SCSHAREDLIB::PluginManager>();
m_pPluginManager->loadPlugins(qApp->applicationDirPath() + pluginDir);
m_pPluginSceneManager = std::make_shared<SCSHAREDLIB::PluginSceneManager>();
}

//=============================================================================================================

void ScanCore::initGUI()
{
m_pMainWindow = std::make_unique<MainWindow>(*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
Loading

0 comments on commit 351ed3a

Please sign in to comment.