we cannot cleanly restart with a new plugin through loading. must relaunch.
This commit is contained in:
@ -228,7 +228,10 @@ bool LammpsWrapper::has_plugin() const
|
|||||||
|
|
||||||
bool LammpsWrapper::load_lib(const char *libfile)
|
bool LammpsWrapper::load_lib(const char *libfile)
|
||||||
{
|
{
|
||||||
if (plugin_handle) liblammpsplugin_release((liblammpsplugin_t *)plugin_handle);
|
if (plugin_handle) {
|
||||||
|
close();
|
||||||
|
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) {
|
if (((liblammpsplugin_t *)plugin_handle)->abiversion != LAMMPSPLUGIN_ABI_VERSION) {
|
||||||
|
|||||||
@ -44,10 +44,20 @@
|
|||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#define execv(exe, args) _execv(exe, args)
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
Preferences::Preferences(LammpsWrapper *_lammps, QWidget *parent) :
|
Preferences::Preferences(LammpsWrapper *_lammps, QWidget *parent) :
|
||||||
QDialog(parent), tabWidget(new QTabWidget),
|
QDialog(parent), tabWidget(new QTabWidget),
|
||||||
buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)),
|
buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)),
|
||||||
settings(new QSettings), lammps(_lammps)
|
settings(new QSettings), lammps(_lammps), need_relaunch(false)
|
||||||
{
|
{
|
||||||
tabWidget->addTab(new GeneralTab(settings, lammps), "&General Settings");
|
tabWidget->addTab(new GeneralTab(settings, lammps), "&General Settings");
|
||||||
tabWidget->addTab(new AcceleratorTab(settings, lammps), "&Accelerators");
|
tabWidget->addTab(new AcceleratorTab(settings, lammps), "&Accelerators");
|
||||||
@ -141,6 +151,16 @@ void Preferences::accept()
|
|||||||
if (box) settings->setValue("viewlog", box->isChecked());
|
if (box) settings->setValue("viewlog", box->isChecked());
|
||||||
box = tabWidget->findChild<QCheckBox *>("viewchart");
|
box = tabWidget->findChild<QCheckBox *>("viewchart");
|
||||||
if (box) settings->setValue("viewchart", box->isChecked());
|
if (box) settings->setValue("viewchart", box->isChecked());
|
||||||
|
|
||||||
|
if (need_relaunch) {
|
||||||
|
QMessageBox msg(QMessageBox::Information, QString("Relaunching LAMMPS-GUI"),
|
||||||
|
QString("LAMMPS library plugin path was changed.\n"
|
||||||
|
"LAMMPS-GUI must be relaunched."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
msg.exec();
|
||||||
|
execv(QCoreApplication::applicationFilePath().toStdString().c_str(), nullptr);
|
||||||
|
fprintf(stderr, "after relaunch\n");
|
||||||
|
}
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,16 +278,11 @@ void GeneralTab::pluginpath()
|
|||||||
QFileDialog::getOpenFileName(this, "Select Shared LAMMPS Library to Load", field->text(),
|
QFileDialog::getOpenFileName(this, "Select Shared LAMMPS Library to Load", field->text(),
|
||||||
"Shared Objects (*.so *.dll *.dylib)");
|
"Shared Objects (*.so *.dll *.dylib)");
|
||||||
if (!pluginfile.isEmpty() && pluginfile.contains("liblammps", Qt::CaseSensitive)) {
|
if (!pluginfile.isEmpty() && pluginfile.contains("liblammps", Qt::CaseSensitive)) {
|
||||||
if (lammps->load_lib(pluginfile.toStdString().c_str())) {
|
auto canonical = QFileInfo(pluginfile).canonicalFilePath();
|
||||||
auto canonical = QFileInfo(pluginfile).canonicalFilePath();
|
field->setText(pluginfile);
|
||||||
field->setText(pluginfile);
|
settings->setValue("plugin_path", canonical);
|
||||||
settings->setValue("plugin_path", canonical);
|
// ugly hack
|
||||||
} else {
|
qobject_cast<Preferences *>(parent()->parent()->parent())->need_relaunch = true;
|
||||||
// plugin did not load cannot continue
|
|
||||||
settings->remove("plugin_path");
|
|
||||||
QMessageBox::critical(this, "Error", "Cannot open LAMMPS shared library file");
|
|
||||||
QCoreApplication::quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool need_relaunch;
|
||||||
private:
|
private:
|
||||||
QTabWidget *tabWidget;
|
QTabWidget *tabWidget;
|
||||||
QDialogButtonBox *buttonBox;
|
QDialogButtonBox *buttonBox;
|
||||||
|
|||||||
Reference in New Issue
Block a user