Skip to content

Commit

Permalink
Removed some more functions and members from plugin interfaces that d…
Browse files Browse the repository at this point in the history
…uplicated those in BasePluginInterface. Added BasePluginInterface::enabled_ member and access. Disabled plugins are now no longer registered by PluginStore.
  • Loading branch information
trisyoungs committed Mar 15, 2017
1 parent 8820293 commit 76b5e52
Show file tree
Hide file tree
Showing 85 changed files with 332 additions and 60 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ src/plugins/io_vfield/Makefile
src/plugins/io_xyz/Makefile
src/plugins/method_mopac71/Makefile
src/plugins/method_mopac71/mopac7.1/Makefile
src/plugins/tool_rings/Makefile
src/plugins/tool_test/Makefile
src/sg/Makefile
src/templates/Makefile
Expand Down
9 changes: 9 additions & 0 deletions src/main/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ bool Aten::registerPlugin(QObject* plugin, QString filename)
FilePluginInterface* filePlugin = qobject_cast<FilePluginInterface*>(plugin);
if (filePlugin)
{
// If the plugin is disabled, don't register it
if (!filePlugin->enabled()) return true;

filePlugin->setPluginFilename(filename);
filePlugin->setPluginStore(&pluginStore_);
pluginStore_.registerFilePlugin(filePlugin);
Expand All @@ -43,6 +46,9 @@ bool Aten::registerPlugin(QObject* plugin, QString filename)
MethodPluginInterface* methodPlugin = qobject_cast<MethodPluginInterface*>(plugin);
if (methodPlugin)
{
// If the plugin is disabled, don't register it
if (!methodPlugin->enabled()) return true;

methodPlugin->setPluginFilename(filename);
methodPlugin->setPluginStore(&pluginStore_);
pluginStore_.registerMethodPlugin(methodPlugin);
Expand All @@ -53,6 +59,9 @@ bool Aten::registerPlugin(QObject* plugin, QString filename)
ToolPluginInterface* toolPlugin = qobject_cast<ToolPluginInterface*>(plugin);
if (toolPlugin)
{
// If the plugin is disabled, don't register it
if (!toolPlugin->enabled()) return true;

toolPlugin->setPluginFilename(filename);
toolPlugin->setPluginStore(&pluginStore_);
pluginStore_.registerToolPlugin(toolPlugin);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ add_subdirectory(io_sybylmol2)
add_subdirectory(io_vfield)
add_subdirectory(io_xyz)
add_subdirectory(method_mopac71)
add_subdirectory(tool_rings)
add_subdirectory(tool_test)
2 changes: 1 addition & 1 deletion src/plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SUBDIRS = interfaces
SUBDIRS += io_akf io_chemshell io_cif io_cube io_dlpoly io_dlputils io_epsr io_ff io_gamessus io_gromacs io_mdlmol io_mopac io_msi io_pdb io_rmcprofile io_sybylmol2 io_vfield io_xyz
#SUBDIRS += io_csd io_espresso io_gaussian io_siesta
SUBDIRS += method_mopac71
SUBDIRS += tool_test
SUBDIRS += tool_rings tool_test

noinst_LTLIBRARIES = libplugins.la

Expand Down
16 changes: 7 additions & 9 deletions src/plugins/interfaces/baseplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
#define ATEN_BASEPLUGININTERFACE_H

#include "plugins/plugintypes.h"
#include "model/model.h"
#include "ff/forcefield.h"
#include "base/grid.h"
#include "base/kvmap.h"
#include "base/messenger.h"
#include "templates/list.h"
#include <QStringList>

Expand Down Expand Up @@ -76,6 +74,8 @@ class BasePluginInterface : public ListItem<BasePluginInterface>
virtual QString description() const = 0;
// Return nickname of plugin
virtual QString nickname() const = 0;
// Return whether plugin is enabled
virtual bool enabled() const = 0;


/*
Expand All @@ -97,15 +97,13 @@ class BasePluginInterface : public ListItem<BasePluginInterface>
// Options specific to this plugin
KVMap pluginOptions_;

protected:
public:
// Return conversion of supplied QString to bool
bool toBool(QString string)
static bool toBool(QString string)
{
if ((string.toInt() == 1) || (string.toLower() == "false")) return false;
return true;
if ((string.toInt() == 1) || (string.toLower() == "true") || (string.toLower() == "on")) return true;
return false;
}

public:
// Set plugin option
bool setOption(QString optionName, QString optionValue)
{
Expand Down
37 changes: 2 additions & 35 deletions src/plugins/interfaces/fileplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "base/messenger.h"
#include "base/fileparser.h"
#include "base/namespace.h"
#include "base/grid.h"
#include "ff/forcefield.h"
#include "templates/reflist.h"
#include <QStringList>
#include <QtPlugin>
Expand Down Expand Up @@ -617,8 +619,6 @@ class FilePluginInterface : public BasePluginInterface
protected:
// Standard options
FilePluginStandardImportOptions standardOptions_;
// Options specific to this plugin
KVMap pluginOptions_;

public:
// Return whether the plugin has import options
Expand All @@ -644,39 +644,6 @@ class FilePluginInterface : public BasePluginInterface
{
return standardOptions_;
}
// Set plugin option
bool setOption(QString optionName, QString optionValue)
{
// Search for this option in pluginOptions_
KVPair* pair = pluginOptions_.search(optionName);
if (pair) pair->setValue(optionValue);
else
{
Messenger::error("Option '" + optionName + "' is not recognised by this plugin.");
Messenger::error("Available options are: " + pluginOptions_.keys());
return false;
}
return true;
}
// Set plugin options
bool setOptions(KVMap options)
{
bool result = true;
for (KVPair* pair = options.pairs(); pair != NULL; pair = pair->next) if (!setOption(pair->key(), pair->value())) result = false;

return result;
}
// Return options specific to this plugin (read-only)
const KVMap& pluginOptions()
{
return pluginOptions_;
}
// Return conversion of supplied QString to bool
static bool toBool(QString string)
{
if ((string.toInt() == 1) || (string.toLower() == "true") || (string.toLower() == "on")) return true;
return false;
}
};

ATEN_END_NAMESPACE
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/interfaces/methodplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ class MethodPluginInterface : public BasePluginInterface
/*
* Options
*/
protected:
// Options specific to this plugin
KVMap pluginOptions_;

public:
// Return whether the plugin has options
virtual bool hasOptions() = 0;
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/interfaces/toolplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ class ToolPluginInterface : public BasePluginInterface
* Tool Definition
*/
protected:
// Options specific to this plugin
KVMap pluginOptions_;
// Dialog for tool (if there is one)
QDialog* dialog_;

Expand All @@ -121,8 +119,6 @@ class ToolPluginInterface : public BasePluginInterface
virtual QIcon buttonIcon() const = 0;
// Return group name for tool (used to group similar tools together)
virtual QString groupName() const = 0;
// Return whether the tool is enabled (appears in the GUI)
virtual bool isEnabled() const = 0;
// Return whether the tool has a dialog
virtual bool hasDialog() const = 0;
// Show the dialog for the tool
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_akf/akf.hui
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class AKFModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_akf/akf_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ QString AKFModelPlugin::nickname() const
return QString("akf");
}

// Return whether the plugin is enabled
bool AKFModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString AKFModelPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_chemshell/chemshell.hui
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class ChemShellModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_chemshell/chemshell_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ QString ChemShellModelPlugin::nickname() const
return QString("chemshell");
}

// Return whether the plugin is enabled
bool ChemShellModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString ChemShellModelPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_cif/cif.hui
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CIFModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_cif/cif_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ QString CIFModelPlugin::nickname() const
return QString("cif");
}

// Return whether the plugin is enabled
bool CIFModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString CIFModelPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_csd/csd.hui
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CSDModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_csd/csd_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ QString CSDModelPlugin::nickname() const
return QString("csd");
}

// Return whether the plugin is enabled
bool CSDModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString CSDModelPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_cube/cube.hui
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CUBEModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_cube/cube_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ QString CUBEModelPlugin::nickname() const
return QString("cube");
}

// Return whether the plugin is enabled
bool CUBEModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString CUBEModelPlugin::description() const
{
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/io_dlpoly/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool DLPOLYPluginCommon::readCONFIGModel ( FilePluginInterface* plugin, FilePars
} while ( (!parser.eofOrBlank()) );

// Shift atoms by half-cell
bool shift = FilePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
bool shift = BasePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
if (shift && targetModel->isPeriodic())
{
targetModel->selectAll(true);
Expand Down Expand Up @@ -211,8 +211,8 @@ bool DLPOLYPluginCommon::writeCONFIGModel (FilePluginInterface* plugin, FilePars

// Write atom information
int k=1;
bool useTypeNames = FilePluginInterface::toBool(plugin->pluginOptions().value("useTypeNames"));
bool shift = (FilePluginInterface::toBool(plugin->pluginOptions().value("shiftCell")) && sourceModel->isPeriodic());
bool useTypeNames = BasePluginInterface::toBool(plugin->pluginOptions().value("useTypeNames"));
bool shift = (BasePluginInterface::toBool(plugin->pluginOptions().value("shiftCell")) && sourceModel->isPeriodic());
Vec3<double> r;

for ( Atom* i = sourceModel->atoms(); i != NULL; i = i->next ) {
Expand Down Expand Up @@ -385,7 +385,7 @@ bool DLPOLYPluginCommon::readUnformattedFrame(FilePluginInterface* plugin, FileP
// Create atoms - if we read in atom information in the header we will have the names and masses
// If these arrays are empty, use the parent model. If it doesn't contain enough atoms, create a dummy atom
Atom* i = targetModel->parent()->atoms(), *j;
bool shiftCell = FilePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
bool shiftCell = BasePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
Vec3<double> r;
for (int n = 0; n<nAtoms; ++n)
{
Expand Down Expand Up @@ -612,7 +612,7 @@ bool DLPOLYPluginCommon::readDEFECTSModel ( FilePluginInterface* plugin, FilePar
if (nDef>0){

if (nInter>0){
int readInter=FilePluginInterface::toBool(plugin->pluginOptions().value("interstitial"));
int readInter=BasePluginInterface::toBool(plugin->pluginOptions().value("interstitial"));
if (readInter){
do {
if ( !parser.parseLine() ) {
Expand All @@ -635,7 +635,7 @@ bool DLPOLYPluginCommon::readDEFECTSModel ( FilePluginInterface* plugin, FilePar
}

if (nVac>0) {
int readVac=FilePluginInterface::toBool(plugin->pluginOptions().value("vacancy"));
int readVac=BasePluginInterface::toBool(plugin->pluginOptions().value("vacancy"));
if (readVac){
do {
if ( !parser.parseLine() ) {
Expand All @@ -658,7 +658,7 @@ bool DLPOLYPluginCommon::readDEFECTSModel ( FilePluginInterface* plugin, FilePar
}

// Shift atoms by half-cell
bool shift = FilePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
bool shift = BasePluginInterface::toBool(plugin->pluginOptions().value("shiftCell"));
if (shift && targetModel->isPeriodic())
{
targetModel->selectAll(true);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_dlpoly/defects4.hui
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class DLP4DefectsPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_dlpoly/defects4_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ QString DLP4DefectsPlugin::nickname() const
return QString("dlpoly4def");
}

// Return whether the plugin is enabled
bool DLP4DefectsPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString DLP4DefectsPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_dlpoly/dlp2.hui
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class DLP2ModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/io_dlpoly/dlp2_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ QString DLP2ModelPlugin::nickname() const
return QString ( "dlpoly2" );
}

// Return whether the plugin is enabled
bool DLP2ModelPlugin::enabled() const
{
return true;
}

// Description (long name) of plugin
QString DLP2ModelPlugin::description() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/io_dlpoly/dlp4.hui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class DLP4ModelPlugin : public QObject, public FilePluginInterface
QString name() const;
// Return nickname of plugin
QString nickname() const;
// Return whether plugin is enabled
bool enabled() const;
// Return description (long name) of plugin
QString description() const;
// Return related file extensions
Expand Down
Loading

0 comments on commit 76b5e52

Please sign in to comment.