| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "openmminput.h" |
| 7 |
|
| 8 |
#include "openmminputdialog.h" |
| 9 |
|
| 10 |
#include <avogadro/io/fileformat.h> |
| 11 |
#include <avogadro/qtgui/fileformatdialog.h> |
| 12 |
#include <avogadro/qtgui/molecule.h> |
| 13 |
|
| 14 |
#include <QtCore/QDebug> |
| 15 |
|
| 16 |
#include <QAction> |
| 17 |
#include <QtWidgets/QMessageBox> |
| 18 |
|
| 19 |
namespace Avogadro { |
| 20 |
namespace Core { |
| 21 |
class Molecule; |
| 22 |
} |
| 23 |
namespace QtPlugins { |
| 24 |
|
| 25 |
OpenMMInput::OpenMMInput(QObject* parent_) |
| 26 |
: ExtensionPlugin(parent_), m_action(new QAction(this)), m_molecule(nullptr), |
| 27 |
m_dialog(nullptr), m_outputFormat(nullptr) |
| 28 |
{ |
| 29 |
m_action->setEnabled(true); |
| 30 |
m_action->setText(tr("&OpenMM Script…")); |
| 31 |
connect(m_action, SIGNAL(triggered()), SLOT(menuActivated())); |
| 32 |
} |
| 33 |
|
| 34 |
OpenMMInput::~OpenMMInput() {} |
| 35 |
|
| 36 |
QList<QAction*> OpenMMInput::actions() const |
| 37 |
{ |
| 38 |
QList<QAction*> actions_; |
| 39 |
actions_.append(m_action); |
| 40 |
return actions_; |
| 41 |
} |
| 42 |
|
| 43 |
QStringList OpenMMInput::menuPath(QAction*) const |
| 44 |
{ |
| 45 |
QStringList path; |
| 46 |
path << tr("&Input"); |
| 47 |
return path; |
| 48 |
} |
| 49 |
|
| 50 |
void OpenMMInput::setMolecule(QtGui::Molecule* mol) |
| 51 |
{ |
| 52 |
if (m_dialog) |
| 53 |
m_dialog->setMolecule(mol); |
| 54 |
m_molecule = mol; |
| 55 |
} |
| 56 |
|
| 57 |
bool OpenMMInput::readMolecule(QtGui::Molecule& mol) |
| 58 |
{ |
| 59 |
Io::FileFormat* reader = m_outputFormat->newInstance(); |
| 60 |
bool success = reader->readFile(m_outputFileName.toStdString(), mol); |
| 61 |
if (!success) { |
| 62 |
QMessageBox::information(qobject_cast<QWidget*>(parent()), tr("Error"), |
| 63 |
tr("Error reading output file '%1':\n%2") |
| 64 |
.arg(m_outputFileName) |
| 65 |
.arg(QString::fromStdString(reader->error()))); |
| 66 |
} |
| 67 |
|
| 68 |
m_outputFormat = nullptr; |
| 69 |
m_outputFileName.clear(); |
| 70 |
|
| 71 |
return success; |
| 72 |
} |
| 73 |
|
| 74 |
void OpenMMInput::menuActivated() |
| 75 |
{ |
| 76 |
if (!m_dialog) { |
| 77 |
m_dialog = new OpenMMInputDialog(qobject_cast<QWidget*>(parent())); |
| 78 |
} |
| 79 |
m_dialog->setMolecule(m_molecule); |
| 80 |
m_dialog->show(); |
| 81 |
m_dialog->raise(); |
| 82 |
m_dialog->activateWindow(); |
| 83 |
} |
| 84 |
} // namespace QtPlugins |
| 85 |
} // namespace Avogadro |