From c501d032aa73c6b6e23822289b02863278b95db2 Mon Sep 17 00:00:00 2001 From: Tristan Youngs Date: Sun, 4 Dec 2016 15:46:01 +0000 Subject: [PATCH] Forcefields list on Forcefields panel now displays original filename as tooltip. Made Forcefield plugin-aware. Updated forcefield editor so that it doesn't allow overwriting of Forcefields in anything other than Aten's own format. --- src/ff/forcefield.cpp | 14 ++++++++++++++ src/ff/forcefield.h | 7 +++++++ src/gui/ffeditor_funcs.cpp | 22 ++++++++++++++++++++-- src/gui/mainwindow_panel_forcefields.cpp | 13 +++++++------ src/main/importexport.cpp | 2 +- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/ff/forcefield.cpp b/src/ff/forcefield.cpp index d4cad8864..de9d0a489 100644 --- a/src/ff/forcefield.cpp +++ b/src/ff/forcefield.cpp @@ -39,6 +39,8 @@ Forcefield::Forcefield() : ListItem() { // Private variables energyUnit_ = Prefs::KiloJoules; + plugin_ = NULL; + // Create _NDEF_ type common to all FFs) ForcefieldAtom* ffa = types_.add(); ffa->setParent(this); @@ -83,6 +85,18 @@ QString Forcefield::filename() return filename_; } +// Sets the plugin used to load the Forcefield +void Forcefield::setPlugin(FilePluginInterface* plugin) +{ + plugin_ = plugin; +} + +// Return the plugin used to load the Forcefield +FilePluginInterface* Forcefield::plugin() const +{ + return plugin_; +} + // Return internal energy unit of forcefield Prefs::EnergyUnit Forcefield::energyUnit() { diff --git a/src/ff/forcefield.h b/src/ff/forcefield.h index a6e915a49..ee2dc248f 100644 --- a/src/ff/forcefield.h +++ b/src/ff/forcefield.h @@ -36,6 +36,7 @@ ATEN_BEGIN_NAMESPACE class Atom; class ForcefieldAtom; class ForcefieldBound; +class FilePluginInterface; // Forcefield class Forcefield : public ListItem @@ -57,6 +58,8 @@ class Forcefield : public ListItem private: // Title of Forcefield QString name_; + // Plugin used to load / save the Forcefield (if any) + FilePluginInterface* plugin_; // Filename QString filename_; // Energy unit of the forcefield parameters @@ -71,6 +74,10 @@ class Forcefield : public ListItem void setFilename(QString filename); // Return filename QString filename(); + // Sets the plugin used to load the Forcefield + void setPlugin(FilePluginInterface* plugin); + // Return the plugin used to load the Forcefield + FilePluginInterface* plugin() const; // Return internal energy unit of forcefield Prefs::EnergyUnit energyUnit(); // Set internal energy unit of forcefield diff --git a/src/gui/ffeditor_funcs.cpp b/src/gui/ffeditor_funcs.cpp index 812834276..b8e5d8e82 100644 --- a/src/gui/ffeditor_funcs.cpp +++ b/src/gui/ffeditor_funcs.cpp @@ -28,6 +28,7 @@ #include "gui/tintegerspindelegate.hui" #include "ff/forcefield.h" #include "model/model.h" +#include "plugins/interfaces/fileplugin.h" #include "base/forcefieldatom.h" #include "base/forcefieldbound.h" #include "templates/variantpointer.h" @@ -107,6 +108,9 @@ void AtenForcefieldEditor::populate(Forcefield* ff) ui.FFEditorForcefieldLabel1->setText(ff->name()); ui.FFEditorForcefieldLabel2->setText(ff->filename()); + // Save buttons + ui.SaveButton->setEnabled(ff->plugin() && ff->plugin()->name() == "Aten Forcefield Format"); + // Types List count = 0; ui.FFEditorTypesTable->setRowCount(ff->nTypes()-1); @@ -370,8 +374,8 @@ void AtenForcefieldEditor::boundFunctionChanged(QComboBox* sender, int i, Forcef if (ffb->type() == ForcefieldBound::UreyBradleyInteraction) updateImpropersLabels(ffb); else updateTorsionsLabels(ffb); break; - default: - break; + default: + break; } } @@ -454,6 +458,8 @@ void AtenForcefieldEditor::on_FFEditorTypesTable_itemChanged(QTableWidgetItem *w case (TypeColumn::Description): ffa->setDescription(qPrintable(w->text())); break; + default: + break; } updating_ = false; } @@ -545,6 +551,8 @@ void AtenForcefieldEditor::on_FFEditorAtomsTable_itemChanged(QTableWidgetItem *w n = column - AtomColumn::Data1; ffa->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } @@ -628,6 +636,8 @@ void AtenForcefieldEditor::on_FFEditorBondsTable_itemChanged(QTableWidgetItem *w n = column - BondColumn::Data1; ffb->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } @@ -712,6 +722,8 @@ void AtenForcefieldEditor::on_FFEditorAnglesTable_itemChanged(QTableWidgetItem * n = column - AngleColumn::Data1; ffb->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } @@ -805,6 +817,8 @@ void AtenForcefieldEditor::on_FFEditorTorsionsTable_itemChanged(QTableWidgetItem n = column - TorsionColumn::Data1; ffb->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } @@ -884,6 +898,8 @@ void AtenForcefieldEditor::on_FFEditorImpropersTable_itemChanged(QTableWidgetIte n = column - TorsionColumn::Data1; ffb->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } @@ -962,6 +978,8 @@ void AtenForcefieldEditor::on_FFEditorUreyBradleysTable_itemChanged(QTableWidget n = column - AngleColumn::Data1; ffb->setParameter(n, atof(qPrintable(w->text()))); break; + default: + break; } updating_ = false; } diff --git a/src/gui/mainwindow_panel_forcefields.cpp b/src/gui/mainwindow_panel_forcefields.cpp index 5248b7c3f..2d357ebfc 100644 --- a/src/gui/mainwindow_panel_forcefields.cpp +++ b/src/gui/mainwindow_panel_forcefields.cpp @@ -22,7 +22,6 @@ #include "gui/mainwindow.h" #include "main/aten.h" #include "ff/forcefield.h" -// #include "gui/selectfilter.h" #include "gui/ffeditor.h" #include @@ -35,12 +34,14 @@ void AtenWindow::updateForcefieldsPanel(Model* sourceModel) // Forcefields list ui.ForcefieldsList->clear(); - int n = 0; - for (Forcefield* ff = aten_.forcefields(); ff != NULL; ff = ff->next) + int count = 0; + for (Forcefield* ff = aten_.forcefields(); ff != NULL; ff = ff->next, ++count) { - ui.ForcefieldsList->addItem(ff->name()); - if (ff == aten_.currentForcefield()) ui.ForcefieldsList->setCurrentRow(n); - ++n; + QListWidgetItem* item = new QListWidgetItem(ff->name()); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + item->setToolTip(QString("File: '%1'").arg(ff->filename())); + ui.ForcefieldsList->addItem(item); + if (ff == aten_.currentForcefield()) ui.ForcefieldsList->setCurrentRow(count); } ui.ForcefieldsManageRemoveButton->setEnabled(currentForcefield); ui.ForcefieldsManageEditButton->setEnabled(currentForcefield); diff --git a/src/main/importexport.cpp b/src/main/importexport.cpp index 3256dc6a8..5a3d13368 100644 --- a/src/main/importexport.cpp +++ b/src/main/importexport.cpp @@ -108,7 +108,7 @@ void Aten::processImportedObjects(FilePluginInterface* plugin, QString filename) // Set source filename and plugin interface used ff->setFilename(filename); -// ff->setPlugin(plugin); + ff->setPlugin(plugin); // Pass the model pointer to Aten ownForcefield(ff);