Skip to content

Commit

Permalink
Now track our Simulation Support plugin (#1630).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Apr 30, 2018
1 parent 3d2728f commit 073babe
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ set(SOURCES
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
src/plugins/preferencesinterface.cpp
src/plugins/simulationinterface.cpp
src/plugins/solverinterface.cpp
src/plugins/viewinterface.cpp
src/plugins/windowinterface.cpp
Expand Down Expand Up @@ -655,6 +656,7 @@ if(WIN32)
src/plugins/plugininfo.cpp
src/plugins/plugininterface.cpp
src/plugins/pluginmanager.cpp
src/plugins/simulationinterface.cpp
src/plugins/solverinterface.cpp

src/windows/main.cpp
Expand Down
1 change: 1 addition & 0 deletions src/plugins/miscellaneous/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_plugin(Core
../../plugininterface.cpp
../../pluginmanager.cpp
../../preferencesinterface.cpp
../../simulationinterface.cpp
../../solverinterface.cpp
../../viewinterface.cpp
../../windowinterface.cpp
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "filemanager.h"
#include "guiinterface.h"
#include "interfaces.h"
#include "simulationinterface.h"
#include "tabbarwidget.h"
#include "usermessagewidget.h"
#include "viewinterface.h"
Expand Down Expand Up @@ -576,7 +577,9 @@ void CentralWidget::saveSettings(QSettings *pSettings) const

void CentralWidget::settingsLoaded(const Plugins &pLoadedPlugins)
{
// Determine which loaded plugins support a given interface
// Determine which loaded plugins support a given interface, as well as
// retrieve the simulation interface of our Simulation Support plugin,
// should it be loaded

foreach (Plugin *plugin, pLoadedPlugins) {
if (qobject_cast<FileHandlingInterface *>(plugin->instance()))
Expand All @@ -590,6 +593,9 @@ void CentralWidget::settingsLoaded(const Plugins &pLoadedPlugins)

if (qobject_cast<ViewInterface *>(plugin->instance()))
mLoadedViewPlugins << plugin;

if (!plugin->name().compare(SimulationSupportPluginName))
mSimulationInterface = qobject_cast<SimulationInterface *>(plugin->instance());
}

// Update our state now that our plugins are fully ready
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/miscellaneous/Core/src/centralwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace OpenCOR {
//==============================================================================

class Plugin;
class SimulationInterface;

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

Expand Down Expand Up @@ -144,6 +145,8 @@ class CentralWidget : public Widget
Plugins mLoadedGuiPlugins;
Plugins mLoadedViewPlugins;

SimulationInterface *mSimulationInterface;

TabBarWidget *mModeTabs;
TabBarWidget *mFileTabs;

Expand Down
4 changes: 4 additions & 0 deletions src/plugins/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CLI_VERSION
#include "preferencesinterface.h"
#endif
#include "simulationinterface.h"
#include "solverinterface.h"
#ifndef CLI_VERSION
#include "viewinterface.h"
Expand Down Expand Up @@ -128,6 +129,7 @@ Plugin::Plugin(const QString &pFileName, PluginInfo *pInfo,
CliInterface *cliInterface = qobject_cast<CliInterface *>(mInstance);
CoreInterface *coreInterface = qobject_cast<CoreInterface *>(mInstance);
PluginInterface *pluginInterface = qobject_cast<PluginInterface *>(mInstance);
SimulationInterface *simulationInterface = qobject_cast<SimulationInterface *>(mInstance);

if ( ( cliInterface
&& (interfaceVersion(pFileName, "cliInterfaceVersion") != cliInterfaceVersion()))
Expand All @@ -151,6 +153,8 @@ Plugin::Plugin(const QString &pFileName, PluginInfo *pInfo,
|| ( qobject_cast<PreferencesInterface *>(mInstance)
&& (interfaceVersion(pFileName, "preferencesInterfaceVersion") != preferencesInterfaceVersion()))
#endif
|| ( simulationInterface
&& (interfaceVersion(pFileName, "simulationInterfaceVersion") != simulationInterfaceVersion()))
|| ( qobject_cast<SolverInterface *>(mInstance)
&& (interfaceVersion(pFileName, "solverInterfaceVersion") != solverInterfaceVersion()))
#ifndef CLI_VERSION
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ static const auto SettingsPlugins = QStringLiteral("Plugins");

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

static const auto CorePluginName = QStringLiteral("Core");
static const auto CorePluginName = QStringLiteral("Core");
static const auto SimulationSupportPluginName = QStringLiteral("SimulationSupport");

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

Expand Down
14 changes: 13 additions & 1 deletion src/plugins/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ PluginManager::PluginManager(bool pGuiMode) :
mGuiMode(pGuiMode),
mPlugins(Plugins()),
mLoadedPlugins(Plugins()),
mCorePlugin(0)
mCorePlugin(0),
mSimulationSupportPlugin(0)
{
// Retrieve OpenCOR's plugins directory
// Note #1: the plugin's directory is retrieved in main()...
Expand Down Expand Up @@ -183,6 +184,8 @@ PluginManager::PluginManager(bool pGuiMode) :

if (!pluginName.compare(CorePluginName))
mCorePlugin = plugin;
else if (!pluginName.compare(SimulationSupportPluginName))
mSimulationSupportPlugin = plugin;
}
}
}
Expand Down Expand Up @@ -275,6 +278,15 @@ Plugin * PluginManager::corePlugin() const

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

Plugin * PluginManager::simulationSupportPlugin() const
{
// Return our Simulation Support plugin

return mSimulationSupportPlugin;
}

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

} // namespace OpenCOR

//==============================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PluginManager : public QObject

Plugin * plugin(const QString &pName) const;
Plugin * corePlugin() const;
Plugin * simulationSupportPlugin() const;

private:
bool mGuiMode;
Expand All @@ -71,6 +72,7 @@ class PluginManager : public QObject
Plugins mLoadedPlugins;

Plugin *mCorePlugin;
Plugin *mSimulationSupportPlugin;
};

//==============================================================================
Expand Down
45 changes: 45 additions & 0 deletions src/plugins/simulationinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

//==============================================================================
// Simulation interface
//==============================================================================

#include "simulationinterface.h"

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

namespace OpenCOR {

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

extern "C" Q_DECL_EXPORT int simulationInterfaceVersion()
{
// Version of the simulation interface

return 1;
}

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

} // namespace OpenCOR

//==============================================================================
// End of file
//==============================================================================
58 changes: 58 additions & 0 deletions src/plugins/simulationinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

//==============================================================================
// Simulation interface
//==============================================================================

#pragma once

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

#include "plugin.h"

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

namespace OpenCOR {

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

extern "C" Q_DECL_EXPORT int simulationInterfaceVersion();

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

class SimulationInterface
{
public:
#define INTERFACE_DEFINITION
#include "simulationinterface.inl"
#undef INTERFACE_DEFINITION
};

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

} // namespace OpenCOR

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

Q_DECLARE_INTERFACE(OpenCOR::SimulationInterface, "OpenCOR::SimulationInterface")

//==============================================================================
// End of file
//==============================================================================
42 changes: 42 additions & 0 deletions src/plugins/simulationinterface.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

//==============================================================================
// Simulation interface
//==============================================================================

#ifdef INTERFACE_DEFINITION
#define PURE = 0
#else
#define PURE
#endif

// Note: make sure to update simulationInterfaceVersion() whenever you
// update this interface...

virtual void save(const QString &pFileName) PURE;
virtual void reload(const QString &pFileName) PURE;
virtual void rename(const QString &pOldFileName,
const QString &pNewFileName) PURE;

#undef PURE

//==============================================================================
// End of file
//==============================================================================
1 change: 1 addition & 0 deletions src/plugins/support/SimulationSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_plugin(SimulationSupport
../../filehandlinginterface.cpp
../../i18ninterface.cpp
../../plugininfo.cpp
../../simulationinterface.cpp
../../solverinterface.cpp

src/simulation.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,39 @@ void SimulationSupportPlugin::retranslateUi()
// multilingual...
}

//==============================================================================
// Simulation interface
//==============================================================================

void SimulationSupportPlugin::save(const QString &pFileName)
{
// The given file has been saved, so let our simulation manager know about
// it

SimulationManager::instance()->save(pFileName);
}

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

void SimulationSupportPlugin::reload(const QString &pFileName)
{
// The given file has been reloaded, so let our simulation manager know
// about it

SimulationManager::instance()->reload(pFileName);
}

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

void SimulationSupportPlugin::rename(const QString &pOldFileName,
const QString &pNewFileName)
{
// The given file has been renamed, so let our simulation manager know
// about it

SimulationManager::instance()->rename(pOldFileName, pNewFileName);
}

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

} // namespace SimulationSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "filehandlinginterface.h"
#include "i18ninterface.h"
#include "plugininfo.h"
#include "simulationinterface.h"

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

Expand All @@ -41,18 +42,20 @@ PLUGININFO_FUNC SimulationSupportPluginInfo();
//==============================================================================

class SimulationSupportPlugin : public QObject, public FileHandlingInterface,
public I18nInterface
public I18nInterface, public SimulationInterface
{
Q_OBJECT

Q_PLUGIN_METADATA(IID "OpenCOR.SimulationSupportPlugin" FILE "simulationsupportplugin.json")

Q_INTERFACES(OpenCOR::FileHandlingInterface)
Q_INTERFACES(OpenCOR::I18nInterface)
Q_INTERFACES(OpenCOR::SimulationInterface)

public:
#include "filehandlinginterface.inl"
#include "i18ninterface.inl"
#include "simulationinterface.inl"
};

//==============================================================================
Expand Down

0 comments on commit 073babe

Please sign in to comment.