add setting support for selecting the LAMMPS plugin shared object
This commit is contained in:
@ -164,13 +164,15 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
dirstatus->show();
|
dirstatus->show();
|
||||||
ui->statusbar->addWidget(progress);
|
ui->statusbar->addWidget(progress);
|
||||||
|
|
||||||
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
plugin_path.clear();
|
plugin_path.clear();
|
||||||
std::string deffile = settings.value("plugin_path", "liblammps.so").toString().toStdString();
|
std::string deffile = settings.value("plugin_path", "liblammps.so").toString().toStdString();
|
||||||
for (const char *libfile : {deffile.c_str(), "./liblammps.so", "liblammps.dylib",
|
for (const char *libfile : {deffile.c_str(), "./liblammps.so", "liblammps.dylib",
|
||||||
"./liblammps.dylib", "liblammps.dll"}) {
|
"./liblammps.dylib", "liblammps.dll"}) {
|
||||||
if (lammps.load_lib(libfile)) {
|
if (lammps.load_lib(libfile)) {
|
||||||
plugin_path = libfile;
|
auto canonical = QFileInfo(libfile).canonicalFilePath();
|
||||||
settings.setValue("plugin_path", QString(libfile));
|
plugin_path = canonical.toStdString();
|
||||||
|
settings.setValue("plugin_path", canonical);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +184,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
|||||||
// QCoreApplication::quit();
|
// QCoreApplication::quit();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
open_file(filename);
|
open_file(filename);
|
||||||
|
|||||||
@ -191,7 +191,11 @@ bool LammpsWrapper::load_lib(const char *libfile)
|
|||||||
if (plugin_handle) liblammpsplugin_release((liblammpsplugin_t *)plugin_handle);
|
if (plugin_handle) liblammpsplugin_release((liblammpsplugin_t *)plugin_handle);
|
||||||
plugin_handle = liblammpsplugin_load(libfile);
|
plugin_handle = liblammpsplugin_load(libfile);
|
||||||
if (!plugin_handle) return false;
|
if (!plugin_handle) return false;
|
||||||
if (((liblammpsplugin_t *)plugin_handle)->abiversion != LAMMPSPLUGIN_ABI_VERSION) return false;
|
if (((liblammpsplugin_t *)plugin_handle)->abiversion != LAMMPSPLUGIN_ABI_VERSION) {
|
||||||
|
liblammpsplugin_release((liblammpsplugin_t *)plugin_handle);
|
||||||
|
plugin_handle = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -13,22 +13,27 @@
|
|||||||
|
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
|
||||||
|
#include "lammpswrapper.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QDir>
|
||||||
#include <QDoubleValidator>
|
#include <QDoubleValidator>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QIntValidator>
|
#include <QIntValidator>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "lammpswrapper.h"
|
|
||||||
|
|
||||||
#if defined(_OPENMP)
|
#if defined(_OPENMP)
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
@ -38,7 +43,7 @@ Preferences::Preferences(LammpsWrapper *_lammps, QWidget *parent) :
|
|||||||
buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)),
|
buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)),
|
||||||
settings(new QSettings), lammps(_lammps)
|
settings(new QSettings), lammps(_lammps)
|
||||||
{
|
{
|
||||||
tabWidget->addTab(new GeneralTab(settings), "&General Settings");
|
tabWidget->addTab(new GeneralTab(settings, lammps), "&General Settings");
|
||||||
tabWidget->addTab(new AcceleratorTab(settings, lammps), "&Accelerators");
|
tabWidget->addTab(new AcceleratorTab(settings, lammps), "&Accelerators");
|
||||||
tabWidget->addTab(new SnapshotTab(settings), "&Snapshot Image");
|
tabWidget->addTab(new SnapshotTab(settings), "&Snapshot Image");
|
||||||
|
|
||||||
@ -112,7 +117,8 @@ void Preferences::accept()
|
|||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralTab::GeneralTab(QSettings *_settings, QWidget *parent) : QWidget(parent), settings(_settings)
|
GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *parent) :
|
||||||
|
QWidget(parent), settings(_settings), lammps(_lammps)
|
||||||
{
|
{
|
||||||
auto *layout = new QVBoxLayout;
|
auto *layout = new QVBoxLayout;
|
||||||
|
|
||||||
@ -122,13 +128,66 @@ GeneralTab::GeneralTab(QSettings *_settings, QWidget *parent) : QWidget(parent),
|
|||||||
auto *cite = new QCheckBox("Include Citations");
|
auto *cite = new QCheckBox("Include Citations");
|
||||||
cite->setCheckState(settings->value("cite", "0").toInt() ? Qt::Checked : Qt::Unchecked);
|
cite->setCheckState(settings->value("cite", "0").toInt() ? Qt::Checked : Qt::Unchecked);
|
||||||
cite->setObjectName("cite");
|
cite->setObjectName("cite");
|
||||||
|
auto *tmplabel = new QLabel("Scratch Folder:");
|
||||||
|
auto *tmpedit = new QLineEdit(settings->value("tempdir", ".").toString());
|
||||||
|
auto *tmpbrowse = new QPushButton("Browse...");
|
||||||
|
auto *tmplayout = new QHBoxLayout;
|
||||||
|
tmpedit->setObjectName("tmpedit");
|
||||||
|
tmplayout->addWidget(tmplabel);
|
||||||
|
tmplayout->addWidget(tmpedit);
|
||||||
|
tmplayout->addWidget(tmpbrowse);
|
||||||
|
|
||||||
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
|
auto *pluginlabel = new QLabel("Path to LAMMPS Shared Library File:");
|
||||||
|
auto *pluginedit =
|
||||||
|
new QLineEdit(settings->value("plugin_path", "liblammpsplugin.so").toString());
|
||||||
|
auto *pluginbrowse = new QPushButton("Browse...");
|
||||||
|
auto *pluginlayout = new QHBoxLayout;
|
||||||
|
pluginedit->setObjectName("pluginedit");
|
||||||
|
pluginlayout->addWidget(pluginedit);
|
||||||
|
pluginlayout->addWidget(pluginbrowse);
|
||||||
|
|
||||||
|
connect(pluginbrowse, &QPushButton::released, this, &GeneralTab::pluginpath);
|
||||||
|
#endif
|
||||||
layout->addWidget(echo);
|
layout->addWidget(echo);
|
||||||
layout->addWidget(cite);
|
layout->addWidget(cite);
|
||||||
|
layout->addLayout(tmplayout);
|
||||||
|
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||||
|
layout->addWidget(pluginlabel);
|
||||||
|
layout->addLayout(pluginlayout);
|
||||||
|
#endif
|
||||||
layout->addStretch(1);
|
layout->addStretch(1);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralTab::newtmpfolder()
|
||||||
|
{
|
||||||
|
QLineEdit *field = findChild<QLineEdit *>("tmpedit");
|
||||||
|
QString tmpdir =
|
||||||
|
QFileDialog::getExistingDirectory(this, "Find Folder for Temporary Files", field->text());
|
||||||
|
if (!tmpdir.isEmpty()) field->setText(tmpdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeneralTab::pluginpath()
|
||||||
|
{
|
||||||
|
QLineEdit *field = findChild<QLineEdit *>("pluginedit");
|
||||||
|
QString pluginfile =
|
||||||
|
QFileDialog::getOpenFileName(this, "Select Shared LAMMPS Library to Load", field->text(),
|
||||||
|
"Shared Objects (*.so *.dll *.dylib)");
|
||||||
|
if (!pluginfile.isEmpty() && pluginfile.contains("liblammps", Qt::CaseSensitive)) {
|
||||||
|
if (lammps->load_lib(pluginfile.toStdString().c_str())) {
|
||||||
|
auto canonical = QFileInfo(pluginfile).canonicalFilePath();
|
||||||
|
field->setText(pluginfile);
|
||||||
|
settings->setValue("plugin_path", canonical);
|
||||||
|
} else {
|
||||||
|
// plugin did not load cannot continue
|
||||||
|
settings->remove("plugin_path");
|
||||||
|
QMessageBox::critical(this, "Error", "Cannot open LAMMPS shared library file");
|
||||||
|
QCoreApplication::quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AcceleratorTab::AcceleratorTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *parent) :
|
AcceleratorTab::AcceleratorTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *parent) :
|
||||||
QWidget(parent), settings(_settings), lammps(_lammps)
|
QWidget(parent), settings(_settings), lammps(_lammps)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public:
|
|||||||
explicit Preferences(LammpsWrapper *lammps, QWidget *parent = nullptr);
|
explicit Preferences(LammpsWrapper *lammps, QWidget *parent = nullptr);
|
||||||
~Preferences() override;
|
~Preferences() override;
|
||||||
|
|
||||||
protected slots:
|
private slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -44,10 +44,15 @@ class GeneralTab : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GeneralTab(QSettings *settings, QWidget *parent = nullptr);
|
explicit GeneralTab(QSettings *settings, LammpsWrapper *lammps, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void pluginpath();
|
||||||
|
void newtmpfolder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
|
LammpsWrapper *lammps;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AcceleratorTab : public QWidget {
|
class AcceleratorTab : public QWidget {
|
||||||
|
|||||||
Reference in New Issue
Block a user