diff --git a/avogadro/qtgui/molecule.cpp b/avogadro/qtgui/molecule.cpp index b6a9563654..41c6bee3a6 100644 --- a/avogadro/qtgui/molecule.cpp +++ b/avogadro/qtgui/molecule.cpp @@ -13,15 +13,15 @@ namespace Avogadro::QtGui { using std::swap; Molecule::Molecule(QObject* parent_) - : QObject(parent_), - m_undoMolecule(new RWMolecule(*this, this)), Core::Molecule() + : QObject(parent_), Core::Molecule(), + m_undoMolecule(new RWMolecule(*this, this)), constraints() { m_undoMolecule->setInteractive(true); } Molecule::Molecule(const Molecule& other) : QObject(), Core::Molecule(other), - m_undoMolecule(new RWMolecule(*this, this)) + m_undoMolecule(new RWMolecule(*this, this)), constraints() { m_undoMolecule->setInteractive(true); // Now assign the unique ids @@ -33,7 +33,7 @@ Molecule::Molecule(const Molecule& other) } Molecule::Molecule(const Core::Molecule& other) - : QObject(), Core::Molecule(other) + : QObject(), Core::Molecule(other), constraints() { // Now assign the unique ids for (Index i = 0; i < atomCount(); i++) @@ -204,8 +204,8 @@ void Molecule::swapAtom(Index a, Index b) Core::Molecule::swapAtom(a, b); } -Molecule::BondType Molecule::addBond(Index a, Index b, - unsigned char order, Index uniqueId) +Molecule::BondType Molecule::addBond(Index a, Index b, unsigned char order, + Index uniqueId) { if (uniqueId >= static_cast(m_bondUniqueIds.size()) || m_bondUniqueIds[uniqueId] != MaxIndex) { diff --git a/avogadro/qtgui/molecule.h b/avogadro/qtgui/molecule.h index 9eb86ff981..d0e5fb89e5 100644 --- a/avogadro/qtgui/molecule.h +++ b/avogadro/qtgui/molecule.h @@ -18,6 +18,11 @@ #include namespace Avogadro { + +namespace QtPlugins { + class ConstraintsModel; +} + namespace QtGui { class Mesh; @@ -33,6 +38,9 @@ class AVOGADROQTGUI_EXPORT Molecule : public QObject, public Core::Molecule Q_OBJECT public: + + QtPlugins::ConstraintsModel* constraints; + /** Typedef for Atom class. */ typedef Core::Molecule::AtomType AtomType; diff --git a/avogadro/qtplugins/CMakeLists.txt b/avogadro/qtplugins/CMakeLists.txt index f36c852048..fda86967c4 100644 --- a/avogadro/qtplugins/CMakeLists.txt +++ b/avogadro/qtplugins/CMakeLists.txt @@ -186,6 +186,9 @@ if(BUILD_GPL_PLUGINS) add_subdirectory(qtaim) endif() +#kantundpeterpan +add_subdirectory(constraints) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${original_library_output_dir}") # Add all of the static plugins to the initialization file. diff --git a/avogadro/qtplugins/constraints/CMakeLists.txt b/avogadro/qtplugins/constraints/CMakeLists.txt new file mode 100644 index 0000000000..4c86e2c525 --- /dev/null +++ b/avogadro/qtplugins/constraints/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories("${AvogadroLibs_SOURCE_DIR}/thirdparty") + +set(constraints + constraintsextension.cpp + constraintsdialog.cpp + constraintsmodel.cpp + constraint.cpp +) + +set(constraints_uis + constraintsdialog.ui +) + +avogadro_plugin(ConstraintsExtension + "Constraints extension" + ExtensionPlugin + constraintsextension.h + ConstraintsExtension + "${constraints}" + "${constraints_uis}" +) + +target_link_libraries(ConstraintsExtension) diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp new file mode 100644 index 0000000000..3676361004 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -0,0 +1,176 @@ +#include "constraint.h" + +namespace Avogadro { + namespace QtPlugins { + + Constraint::Constraint(int type, + int a, + int b, + int c, + int d, + double value, + ConstraintsModel* model) + { + c_model = model; + ConstraintType = type; + + //adjusting for 0 indexing + a = a-1; + b = b-1; + c = c-1; + d = d-1; + + // store unique AtomIds + + switch (ConstraintType) + { + case 0: + case 1: + case 2: + case 3: + case 4: + // AtomA + Atoms << c_model->c_molecule->atomUniqueId(a); + break; + + case 5: + //AtomA + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomB + Atoms << c_model->c_molecule->atomUniqueId(b); + break; + + case 6: + //AtomA + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomB + Atoms << c_model->c_molecule->atomUniqueId(b); + //AtomC + Atoms << c_model->c_molecule->atomUniqueId(c); + break; + + case 7: + //AtomA + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomB + Atoms << c_model->c_molecule->atomUniqueId(b); + //AtomC + Atoms << c_model->c_molecule->atomUniqueId(c); + //AtomD + Atoms << c_model->c_molecule->atomUniqueId(d); + } + + ConstraintValue = value; + + } + + Constraint::~Constraint(){} + + void Constraint::SetConstraintType(int type) + { + ConstraintType = type; + } + + void Constraint::SetValue(double Value) + { + ConstraintValue = Value; + } + + int Constraint::GetConstraintType() const + { + return ConstraintType; + } + + double Constraint::GetConstraintValue() const + { + return ConstraintValue; + } + + const Index Constraint::GetConstraintAtomA() const + { + if (Atoms.size() >= 1) //returned for all constraint types + { + return c_model->c_molecule->atomByUniqueId(Atoms[0]).index()+1; + } + else + { + return 0; + } + } + + const Index Constraint::GetConstraintAtomB() const + { + if (Atoms.size() >= 2) //distance, angle and torsion constraints + { + return c_model->c_molecule->atomByUniqueId(Atoms[1]).index()+1; + } + else + { + return 0; + } + } + + const Index Constraint::GetConstraintAtomC() const + { + if (Atoms.size() >= 3) //angle and torsion constraints + { + return c_model->c_molecule->atomByUniqueId(Atoms[2]).index()+1; + } + else + { + return 0; + } + } + + const Index Constraint::GetConstraintAtomD() const + { + if (Atoms.size() >= 4) //torsion constraints only + { + return c_model->c_molecule->atomByUniqueId(Atoms[3]).index()+1; + } + else + { + return 0; + } + } + + QJsonObject Constraint::toJson() + { + QJsonObject ConstraintJ; + ConstraintJ["type"] = GetConstraintType(); + ConstraintJ["value"] = GetConstraintValue(); + + QJsonArray ConstraintAtoms; + + switch (GetConstraintType()) + { + case 0: + case 1: + case 2: + case 3: + case 4: + ConstraintAtoms << static_cast(GetConstraintAtomA()); + break; + case 5: + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()); + break; + case 6: + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()) + << static_cast(GetConstraintAtomC()); + break; + case 7: + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()) + << static_cast(GetConstraintAtomC()) + << static_cast(GetConstraintAtomD()); + break; + } + + ConstraintJ.insert("atoms", ConstraintAtoms); + + return ConstraintJ; + } + } //namespace QtPlugins +} //namespace Avogadro diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h new file mode 100644 index 0000000000..966058b0ad --- /dev/null +++ b/avogadro/qtplugins/constraints/constraint.h @@ -0,0 +1,70 @@ +#include +#include +#include + +#include +#include "constraintsmodel.h" + +#ifndef CONSTRAINT_H +#define CONSTRAINT_H + +namespace Avogadro { + namespace Core{ + class Atom; + } + namespace QtPlugins { + class Constraint + { + public: + /* + Implementation of simple class for the represenation of constraints. + + The ConstraintType has the following mapping (reflected in the ConstraintDialog combobox): + + 0: Ignore Atom + 1: Fix Atom + 2: Fix Atom X + 3: Fix Atom Y + 4: Fix Atom Z + 5: Distance + 6: Angle + 7: Torsion + + This implementation makes use of the UniqueID that is assigned to each Atom upon creation, + which can be used to unambigously retrieve the current index of the Atom in molecule. + + This constraint representation has to be translated into package specific instructions when + passing it to whatever Optimizing/MD/QM code. + + */ + explicit Constraint(int ConstraintType, + int AtomIdA, + int AtomIdB, + int AtomIdC, + int AtomIdD, + double ConstraintValue, + ConstraintsModel* model); + ~Constraint(); + + void SetConstraintType(int ConstraintType); + void SetValue(double Value); + + int GetConstraintType() const; + double GetConstraintValue() const; + + const Index GetConstraintAtomA() const; + const Index GetConstraintAtomB() const; + const Index GetConstraintAtomC() const; + const Index GetConstraintAtomD() const; + + QJsonObject toJson(); + + int ConstraintType; + double ConstraintValue; + + QList Atoms; + ConstraintsModel* c_model = nullptr; + }; + } +} +#endif diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp new file mode 100644 index 0000000000..442de90781 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -0,0 +1,130 @@ +#include "constraintsdialog.h" +#include "ui_constraintsdialog.h" + +#include +#include +#include +#include + +using Avogadro::QtGui::Molecule; + +//#include +//#include +//#include +//#include +//#include + +namespace Avogadro { + namespace QtPlugins { + ConstraintsDialog::ConstraintsDialog(ConstraintsExtension* plugin, + QWidget* parent_, + Qt::WindowFlags f) + : QDialog(parent_,f) + , m_plugin(plugin) + , ui(new Ui::ConstraintsDialog) + { + ui->setupUi(this); + connect( ui->ConstraintsOK, SIGNAL( clicked() ), this, SLOT( acceptConstraints() )); + connect( ui->ConstraintsAdd, SIGNAL( clicked() ), this, SLOT( addConstraint() )); + connect( ui->ConstraintsDelete, SIGNAL( clicked() ), this, SLOT( deleteConstraint() )); + connect( ui->ConstraintsDeleteAll, SIGNAL( clicked() ), this, SLOT( deleteAllConstraints() )); + // connect( ui->HighlightButton, SIGNAL( clicked() ), this, SLOT( highlightSelected())); + connect( ui->checkHighlight, SIGNAL( stateChanged(int)), this, SLOT( connectHighlight(int))); + } + + ConstraintsDialog::~ConstraintsDialog() + { + delete ui; + } + + void ConstraintsDialog::connectHighlight(int state) + { + if (state) + { + connect(ui->ConstraintsTableView->selectionModel(), + SIGNAL( selectionChanged(QItemSelection, QItemSelection)), + this, SLOT (highlightSelected())); + } + else + { + disconnect(ui->ConstraintsTableView->selectionModel(), + SIGNAL( selectionChanged(QItemSelection, QItemSelection)), + this, SLOT (highlightSelected())); + } + } + + void ConstraintsDialog::highlightSelected() + {// check if highlighting requestd + if (ui->checkHighlight->checkState()) + {//clear all previous selections + for (int i = 0; i < m_plugin->m_molecule->atomCount(); ++i) + { + m_plugin->m_molecule->atom(i).setSelected(false); + } + if (m_plugin->m_molecule->constraints->ConstraintsList.size()>0) + { + // get currently selected constraint + QModelIndex idx = ui->ConstraintsTableView->selectionModel()->currentIndex(); + // extract selected constraint from ConstraintModel + QtPlugins::Constraint* c = &m_plugin->m_molecule->constraints->ConstraintsList[idx.row()]; + // iterate over involved uniqueAtomIDs + for (int i = 0; i < c->Atoms.size(); i++) + { + // get atom by uniqueID and set selected + m_plugin->m_molecule->atomByUniqueId(c->Atoms[i]).setSelected(true); + qDebug() << "Set selected"; + } + //emit molecule changes + m_plugin->m_molecule->emitChanged(Molecule::Atoms); + } + } + } + + void ConstraintsDialog::setModel() + { + ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); + connectHighlight(ui->checkHighlight->checkState()); + connect( m_plugin->m_molecule, SIGNAL( changed(unsigned int)), + m_plugin->m_molecule->constraints, SLOT (emitDataChanged())); + } + + void ConstraintsDialog::acceptConstraints() + { + hide(); + } + + void ConstraintsDialog::deleteConstraint() + { + m_plugin-> + m_molecule-> + constraints-> + deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); + } + + void ConstraintsDialog::addConstraint() + { + //Parsing user inptu + int type = ui->comboType->currentIndex(); + double value = ui->editValue->value(); + int AtomIdA = ui->editA->value(); + int AtomIdB = ui->editB->value(); + int AtomIdC = ui->editC->value(); + int AtomIdD = ui->editD->value(); + + //adding the constraint to the molecule's CosntraintsModel + m_plugin->m_molecule->constraints->addConstraint(type, + AtomIdA, + AtomIdB, + AtomIdC, + AtomIdD, + value); + } + + void ConstraintsDialog::deleteAllConstraints() + { + m_plugin->m_molecule->constraints->clear(); + // this->update(); + } + + } +} diff --git a/avogadro/qtplugins/constraints/constraintsdialog.h b/avogadro/qtplugins/constraints/constraintsdialog.h new file mode 100644 index 0000000000..560663bfae --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -0,0 +1,43 @@ +#ifndef AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#define AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#include "constraintsextension.h" +#include "constraintsmodel.h" +#include +#include +#include +#include +#include +#include + +namespace Avogadro { + namespace QtPlugins { + namespace Ui { + class ConstraintsDialog; + } + class ConstraintsDialog : public QDialog + { + Q_OBJECT + + public: + explicit ConstraintsDialog(ConstraintsExtension* plugin , + QWidget* parent_=0, + Qt::WindowFlags f = 0); + ~ConstraintsDialog() override; + void setModel(); + + public slots: + void acceptConstraints(); + void addConstraint(); + void deleteConstraint(); + void deleteAllConstraints(); + void highlightSelected(); + void connectHighlight(int state); + + private: + Ui::ConstraintsDialog* ui; + ConstraintsExtension* m_plugin; + + }; + } +} +#endif //AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H diff --git a/avogadro/qtplugins/constraints/constraintsdialog.ui b/avogadro/qtplugins/constraints/constraintsdialog.ui new file mode 100644 index 0000000000..ee526432cb --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog.ui @@ -0,0 +1,220 @@ + + + Avogadro::QtPlugins::ConstraintsDialog + + + + 0 + 0 + 798 + 357 + + + + Constraints + + + + + + QAbstractItemView::SelectRows + + + + + + + Add Constraints + + + + + + + + + 40 + 16777215 + + + + Type + + + + + + + + Ignore Atom + + + + + Fix Atom + + + + + Fix Atom X + + + + + Fix Atom Y + + + + + Fix Atom Z + + + + + Distance + + + + + Angle + + + + + Torsion angle + + + + + + + + Constraint Value + + + + + + + + + + Atom Indices + + + + + + + + + + + + + + + + + + + Add + + + + + + + + + + + + Options + + + + + + + + false + + + Save + + + + + + + false + + + Load + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Highlight selected Constraint + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Delete Selected + + + + + + + Delete All + + + + + + + OK + + + + + + + + + + + + + diff --git a/avogadro/qtplugins/constraints/constraintsdialog_small.ui b/avogadro/qtplugins/constraints/constraintsdialog_small.ui new file mode 100644 index 0000000000..cefe05bdb8 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog_small.ui @@ -0,0 +1,205 @@ + + Avogadro::QtPlugins::ConstraintsDialog + + + + 0 + 0 + 750 + 357 + + + + Constraints + + + + + + QAbstractItemView::SelectRows + + + + + + + Add Constraints + + + + + + + + + 40 + 16777215 + + + + Type + + + + + + + + Fix Atom + + + + + Distance + + + + + Angle + + + + + Torsion angle + + + + + + + + Constraint Value + + + + + + + + + + Atom Indices + + + + + + + + + + + + + + + + + + + Add + + + + + + + + + + + + Options + + + + + + + + false + + + Save + + + + + + + false + + + Load + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Delete Selected + + + + + + + Delete All + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + + + + + + + diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp new file mode 100644 index 0000000000..dac9ff068f --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -0,0 +1,65 @@ +#include "constraintsextension.h" +#include "constraintsdialog.h" +#include "constraintsmodel.h" + +#include + +//#include +//#include + +#include +#include + +namespace Avogadro { + namespace QtPlugins { + ConstraintsExtension::ConstraintsExtension(QObject* p) : ExtensionPlugin(p) + { + QAction* action = new QAction(this); + action->setEnabled(true); + action->setText(tr("Constraints")); + connect(action, SIGNAL(triggered()), SLOT(onDialog())); + m_actions.push_back(action); + + dialog = new ConstraintsDialog(this, + qobject_cast(parent())); + + } + + ConstraintsExtension::~ConstraintsExtension(){} + + QList ConstraintsExtension::actions() const{ + return m_actions; + } + + QStringList ConstraintsExtension::menuPath(QAction*) const{ + return QStringList() << tr("&Extensions"); + } + + + void ConstraintsExtension::onDialog() + { + dialog->show(); + + } + + + void ConstraintsExtension::setMolecule(QtGui::Molecule* mol) + { + if (mol != m_molecule) + { + m_molecule = mol; + // dialog->connectHighlight(0); + } + + if (!m_molecule->constraints) + { + m_molecule->constraints = new ConstraintsModel(m_molecule); + } + dialog->setModel(); + } + + bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ + return true; + } + } +} diff --git a/avogadro/qtplugins/constraints/constraintsextension.h b/avogadro/qtplugins/constraints/constraintsextension.h new file mode 100644 index 0000000000..98c89c9343 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsextension.h @@ -0,0 +1,49 @@ +#ifndef AVOGADRO_QTPLUGINS_CONSTRAINTS_H +#define AVOGADRO_QTPLUGINS_CONSTRAINTS_H + +#include +#include +#include + +class QAction; + +namespace Avogadro { + namespace QtPlugins { + class ConstraintsDialog; + + class ConstraintsExtension : public QtGui::ExtensionPlugin + { + Q_OBJECT + + public: + explicit ConstraintsExtension(QObject* parent=0); + ~ConstraintsExtension() override; + + QString name() const override { return tr("Constraints");} + + QString description() const override { + return tr("Set Constraints for MM and QM optimizations"); + } + + QList actions() const override; + + QStringList menuPath(QAction*) const override; + + void setMolecule(QtGui::Molecule* mol) override; + + bool readMolecule(QtGui::Molecule& mol) override; + + private slots: + void onDialog(); + + private: + QList m_actions; + QtGui::Molecule* m_molecule = nullptr; + ConstraintsDialog* dialog = nullptr; + + friend class ConstraintsDialog; + }; + } +} + +#endif // AVOGADRO_QTPLUGINS_CONSTRAINTS_H diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp new file mode 100644 index 0000000000..f1a7fe78e3 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -0,0 +1,187 @@ +#include "constraintsmodel.h" +#include +#include +#include + + +using namespace std; + +namespace Avogadro +{ + namespace QtPlugins{ + + void ConstraintsModel::emitDataChanged() + { + emit dataChanged(QModelIndex(), QModelIndex()); + } + + int ConstraintsModel::rowCount(const QModelIndex &) const + { + return ConstraintsList.size(); + } + + int ConstraintsModel::columnCount(const QModelIndex &) const + { + return 6; + } + + QVariant ConstraintsModel::data(const QModelIndex &index, int role) const + { + if (!index.isValid()) + return QVariant(); + + if (index.row() >= ConstraintsList.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + switch (index.column()) { + case 0: + if (ConstraintsList[index.row()].GetConstraintType() == 0) + return QString("Ignore Atom"); + else if (ConstraintsList[index.row()].GetConstraintType() == 1) + return QString("Fix Atom"); + else if (ConstraintsList[index.row()].GetConstraintType() == 2) + return QString("Fix Atom X"); + else if (ConstraintsList[index.row()].GetConstraintType() == 3) + return QString("Fix Atom Y"); + else if (ConstraintsList[index.row()].GetConstraintType() == 4) + return QString("Fix Atom Z"); + else if (ConstraintsList[index.row()].GetConstraintType() == 5) + return QString("Distance"); + else if (ConstraintsList[index.row()].GetConstraintType() == 6) + return QString("Angle"); + else if (ConstraintsList[index.row()].GetConstraintType() == 7) + return QString("Torsion angle"); + break; + case 1: + return ConstraintsList[index.row()].GetConstraintValue(); + break; + case 2: + if (ConstraintsList[index.row()].GetConstraintAtomA()) + { + QVariant v; + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomA())); + return v; + } + else + { + return "NA"; + } + break; + case 3: + if (ConstraintsList[index.row()].GetConstraintAtomB()) + { + QVariant v; + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomB())); + return v; + } + else + { + return "NA"; + } + break; + case 4: + if (ConstraintsList[index.row()].GetConstraintAtomC()) + { + QVariant v; + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomC())); + return v; + } + else + { + return "NA"; + } + break; + case 5: + if (ConstraintsList[index.row()].GetConstraintAtomD()) + { + QVariant v; + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomD())); + return v; + } + else + { + return "NA"; + } + break; + } + + return QVariant(); + } + + QVariant ConstraintsModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("Type"); + break; + case 1: + return QString("Value"); + break; + case 2: + return QString("Atom idx 1"); + break; + case 3: + return QString("Atom idx 2"); + break; + case 4: + return QString("Atom idx 3"); + break; + case 5: + return QString("Atom idx 4"); + break; + } + } + + return QString("Constraint %1").arg(section + 1); + } + + void ConstraintsModel::addConstraint(int type, int a, int b, int c, int d, double value) + { + beginInsertRows(QModelIndex(), ConstraintsList.size(), ConstraintsList.size()); + ConstraintsList << Constraint(type, a, b, c, d, value, this); + endInsertRows(); + } + + void ConstraintsModel::clear() + { + qDebug() << "ConstraintsModel::clear()" << endl; + if (ConstraintsList.size()) { + beginRemoveRows(QModelIndex(), 0, ConstraintsList.size() - 1); + ConstraintsList.clear(); + endRemoveRows(); + } + } + + void ConstraintsModel::deleteConstraint(int index) + { + qDebug() << "ConstraintsModel::deleteConstraint(" << index << ")" << endl; + if (ConstraintsList.size() && (index >= 0)) { + beginRemoveRows(QModelIndex(), index, index); + ConstraintsList.removeAt(index); + endRemoveRows(); + } + } + + QJsonObject ConstraintsModel::toJson() + { + QJsonObject ConstraintsMJ; + ConstraintsMJ["total"] = ConstraintsList.size(); + + if(ConstraintsList.size()) + { + for(int i = 0; i < ConstraintsList.size(); i++) + { + ConstraintsMJ.insert(QString::number(i), ConstraintsList[i].toJson()); + } + } + + return ConstraintsMJ; + } + } +} // end namespace Avogadro + diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h new file mode 100644 index 0000000000..b2d12cba31 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -0,0 +1,56 @@ +#ifndef CONSTRAINTSMODEL_H +#define CONSTRAINTSMODEL_H + +#include +#include +#include +#include +#include +#include + +#include +#include "constraint.h" + + +namespace Avogadro { + namespace QtPlugins { + class ConstraintsModel : public QAbstractTableModel + + { + Q_OBJECT + /* + public slots: + void primitiveRemoved(Primitive *primitive); + */ + public: + ConstraintsModel(QtGui::Molecule* molecule) + : QAbstractTableModel() + , c_molecule(molecule) + {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + void clear(); + void addConstraint(int type, int a, int b, int c, int d, double value); + void deleteConstraint(int index); + + QJsonObject toJson(); + + + QList ConstraintsList; + + // pointer to the associated molecule + QtGui::Molecule* c_molecule = nullptr; + + public slots: + void emitDataChanged(); + + }; //ConstraintsModel + } // QtPlugins +} // end namespace Avogadro + +#endif diff --git a/avogadro/qtplugins/constraints/orig/constraintsdialog.ui b/avogadro/qtplugins/constraints/orig/constraintsdialog.ui new file mode 100644 index 0000000000..42a3c2186d --- /dev/null +++ b/avogadro/qtplugins/constraints/orig/constraintsdialog.ui @@ -0,0 +1,225 @@ + + Avogadro::QtPlugins::ConstraintsDialog + + + + 0 + 0 + 750 + 357 + + + + Constraints + + + + + + QAbstractItemView::SelectRows + + + + + + + Add Constraints + + + + + + + + + 40 + 16777215 + + + + Type + + + + + + + + Ignore Atom + + + + + Fix Atom + + + + + Fix Atom X + + + + + Fix Atom Y + + + + + Fix Atom Z + + + + + Distance + + + + + Angle + + + + + Torsion angle + + + + + + + + Constraint Value + + + + + + + + + + Atom Indices + + + + + + + + + + + + + + + + + + + Add + + + + + + + + + + + + Options + + + + + + + + false + + + Save + + + + + + + false + + + Load + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Delete Selected + + + + + + + Delete All + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + + + + + + + diff --git a/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.cpp b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.cpp new file mode 100644 index 0000000000..7827c28b81 --- /dev/null +++ b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.cpp @@ -0,0 +1,27 @@ +#include "constraintsdialog.h" +#include "ui_constraintsdialog.h" +#include +#include +#include + +#include +#include + +#include + +namespace Avogadro { + namespace QtPlugins { + ConstraintsDialog::ConstraintsDialog(QWidget* parent_) : QDialog(parent_), ui(new Ui::ConstraintsDialog) + { + ui->setupUi(this); + } + ConstraintsDialog::~ConstraintsDialog() + { + delete ui; + } + void ConstraintsDialog::whow() + { + this->show(); + } + } +} diff --git a/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.h b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.h new file mode 100644 index 0000000000..db4c31c1e1 --- /dev/null +++ b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.h @@ -0,0 +1,29 @@ +#ifndef AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#define AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H + +#include +#include +#include +#include + +namespace Avogadro { + namespace QtPlugins { + namespace Ui { + class ConstraintsDialog; + } + class ConstraintsDialog : public QDialog + { + Q_OBJECT + + public: + explicit ConstraintsDialog(QWidget* parent_=0); + ~ConstraintsDialog() override; + + void whow(); + + private: + Ui::ConstraintsDialog* ui; + }; + } +} +#endif //AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H diff --git a/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.ui b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.ui new file mode 100644 index 0000000000..42a3c2186d --- /dev/null +++ b/avogadro/qtplugins/constraints/orig/constraintsdialog_orig.ui @@ -0,0 +1,225 @@ + + Avogadro::QtPlugins::ConstraintsDialog + + + + 0 + 0 + 750 + 357 + + + + Constraints + + + + + + QAbstractItemView::SelectRows + + + + + + + Add Constraints + + + + + + + + + 40 + 16777215 + + + + Type + + + + + + + + Ignore Atom + + + + + Fix Atom + + + + + Fix Atom X + + + + + Fix Atom Y + + + + + Fix Atom Z + + + + + Distance + + + + + Angle + + + + + Torsion angle + + + + + + + + Constraint Value + + + + + + + + + + Atom Indices + + + + + + + + + + + + + + + + + + + Add + + + + + + + + + + + + Options + + + + + + + + false + + + Save + + + + + + + false + + + Load + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Delete Selected + + + + + + + Delete All + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + + + + + + +