From ef666fb72e87ffe6f6c6fd063a1e74e97477bce6 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Tue, 30 Jun 2020 17:03:38 +0200 Subject: [PATCH 01/12] QtGui::Molecule modified Signed-off-by: Heiner Atze Signed-off-by: Geoff Hutchison --- avogadro/qtgui/molecule.cpp | 12 +- avogadro/qtgui/molecule.h | 8 + avogadro/qtplugins/CMakeLists.txt | 3 + avogadro/qtplugins/constraints/CMakeLists.txt | 23 ++ avogadro/qtplugins/constraints/constraint.cpp | 48 ++++ avogadro/qtplugins/constraints/constraint.h | 30 +++ .../constraints/constraintsdialog.cpp | 63 +++++ .../qtplugins/constraints/constraintsdialog.h | 42 ++++ .../constraints/constraintsdialog.ui | 225 +++++++++++++++++ .../constraints/constraintsdialog_small.ui | 205 +++++++++++++++ .../constraints/constraintsextension.cpp | 83 +++++++ .../constraints/constraintsextension.h | 46 ++++ .../constraints/constraintsmodel.cpp | 234 ++++++++++++++++++ .../qtplugins/constraints/constraintsmodel.h | 73 ++++++ .../constraints/orig/constraintsdialog.ui | 225 +++++++++++++++++ .../orig/constraintsdialog_orig.cpp | 27 ++ .../constraints/orig/constraintsdialog_orig.h | 29 +++ .../orig/constraintsdialog_orig.ui | 225 +++++++++++++++++ 18 files changed, 1595 insertions(+), 6 deletions(-) create mode 100644 avogadro/qtplugins/constraints/CMakeLists.txt create mode 100644 avogadro/qtplugins/constraints/constraint.cpp create mode 100644 avogadro/qtplugins/constraints/constraint.h create mode 100644 avogadro/qtplugins/constraints/constraintsdialog.cpp create mode 100644 avogadro/qtplugins/constraints/constraintsdialog.h create mode 100644 avogadro/qtplugins/constraints/constraintsdialog.ui create mode 100644 avogadro/qtplugins/constraints/constraintsdialog_small.ui create mode 100644 avogadro/qtplugins/constraints/constraintsextension.cpp create mode 100644 avogadro/qtplugins/constraints/constraintsextension.h create mode 100644 avogadro/qtplugins/constraints/constraintsmodel.cpp create mode 100644 avogadro/qtplugins/constraints/constraintsmodel.h create mode 100644 avogadro/qtplugins/constraints/orig/constraintsdialog.ui create mode 100644 avogadro/qtplugins/constraints/orig/constraintsdialog_orig.cpp create mode 100644 avogadro/qtplugins/constraints/orig/constraintsdialog_orig.h create mode 100644 avogadro/qtplugins/constraints/orig/constraintsdialog_orig.ui diff --git a/avogadro/qtgui/molecule.cpp b/avogadro/qtgui/molecule.cpp index 11659915e6..d3de762f09 100644 --- a/avogadro/qtgui/molecule.cpp +++ b/avogadro/qtgui/molecule.cpp @@ -14,15 +14,15 @@ namespace 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 @@ -34,7 +34,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++) @@ -205,8 +205,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 23cdb82b82..01e919bb9a 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 7642f69d1a..eebe7a57c9 100644 --- a/avogadro/qtplugins/CMakeLists.txt +++ b/avogadro/qtplugins/CMakeLists.txt @@ -174,6 +174,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..459899ba5d --- /dev/null +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -0,0 +1,48 @@ +#include "constraint.h" + +namespace Avogadro { + namespace QtPlugins { + Constraint::Constraint(int type, int a, int b, int c, int d, double value) + { + ConstraintType = type; + AtomIdA = a; + AtomIdB = b; + AtomIdC = c; + AtomIdD = 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; + } + int Constraint::GetConstraintAtomA() const + { + return AtomIdA; + } + int Constraint::GetConstraintAtomB() const + { + return AtomIdB; + } + int Constraint::GetConstraintAtomC() const + { + return AtomIdC; + } + int Constraint::GetConstraintAtomD() const + { + return AtomIdD; + } + } +} diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h new file mode 100644 index 0000000000..d1391e2e4d --- /dev/null +++ b/avogadro/qtplugins/constraints/constraint.h @@ -0,0 +1,30 @@ +#include + +namespace Avogadro { + namespace QtPlugins { + class Constraint + { + public: + explicit Constraint(int ConstraintType, int AtomIdA, int AtomIdB, int AtomIdC, int AtomIdD, double ConstraintValue); + ~Constraint(); + + void SetConstraintType(int ConstraintType); + // void SetAtomId(QList atom_ids); + void SetValue(double Value); + + int GetConstraintType() const; + double GetConstraintValue() const; + int GetConstraintAtomA() const; + int GetConstraintAtomB() const; + int GetConstraintAtomC() const; + int GetConstraintAtomD() const; + + int ConstraintType; + int AtomIdA; + int AtomIdB; + int AtomIdC; + int AtomIdD; + float ConstraintValue; + }; + } +} diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp new file mode 100644 index 0000000000..228788e305 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -0,0 +1,63 @@ +#include "constraintsdialog.h" +#include "ui_constraintsdialog.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace Avogadro { + namespace QtPlugins { + ConstraintsDialog::ConstraintsDialog(QWidget* parent_, Qt::WindowFlags f) : QDialog(parent_,f), ui(new Ui::ConstraintsDialog)//, m_constraints(new QtPlugins::ConstraintsModel) + { + 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() )); + } + ConstraintsDialog::~ConstraintsDialog() + { + delete ui; + } + void ConstraintsDialog::setModel(ConstraintsModel *model) + { + m_constraints = model; // new QtPlugins::ConstraintsModel(); + ui->ConstraintsTableView->setModel(m_constraints); + } + void ConstraintsDialog::acceptConstraints() + { + hide(); + } + void ConstraintsDialog::deleteConstraint() + { + m_constraints->deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); + } + void ConstraintsDialog::addConstraint() + { + 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(); + + m_constraints->addConstraint(type, + AtomIdA, + AtomIdB, + AtomIdC, + AtomIdD, + value); + } + void ConstraintsDialog::deleteAllConstraints() + { + m_constraints->clear(); + this->update(); + } + } +} diff --git a/avogadro/qtplugins/constraints/constraintsdialog.h b/avogadro/qtplugins/constraints/constraintsdialog.h new file mode 100644 index 0000000000..0b14ebaafd --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -0,0 +1,42 @@ +#ifndef AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#define AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#include "constraintsmodel.h" +#include +#include +#include +#include +#include +#include +#include + +namespace Avogadro { + namespace QtPlugins { + namespace Ui { + class ConstraintsDialog; + } + class ConstraintsDialog : public QDialog + { + Q_OBJECT + + public: + explicit ConstraintsDialog(QWidget* parent_=0, Qt::WindowFlags f = 0); + ~ConstraintsDialog() override; + void setModel(ConstraintsModel *model); + //void setMolecule(Molecule* m_molecule); + + public slots: + void acceptConstraints(); + void addConstraint(); + void deleteConstraint(); + void deleteAllConstraints(); + /* + void comboTypeChanged(int); + */ + private: + Ui::ConstraintsDialog* ui; + ConstraintsModel *m_constraints; + //Molecule* m_molecule; + }; + } +} +#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..42a3c2186d --- /dev/null +++ b/avogadro/qtplugins/constraints/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/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..b285ea100d --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -0,0 +1,83 @@ +#include "constraintsextension.h" +#include "constraintsdialog.h" +#include "constraintsmodel.h" + +#include +#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(qobject_cast(parent())); + + } + + ConstraintsExtension::~ConstraintsExtension(){} + + QList ConstraintsExtension::actions() const{ + return m_actions; + } + + QStringList ConstraintsExtension::menuPath(QAction*) const{ + return QStringList() << tr("&Extensions"); + } + + + void ConstraintsExtension::onDialog() + {/* + if (!dialog) + { + dialog = new ConstraintsDialog(qobject_cast(parent())); + }*/ + dialog->show(); + //ConstraintsDialog dlg(qobject_cast(parent())); + //dlg.show(); + /* + QMessageBox::critical(qobject_cast(parent()), tr("Error"), + tr("I could open you"), + QMessageBox::Ok); + */ + /* + ConstraintsDialog dlg; + dlg.whow(); + */ + + //ConstraintsDialog::whow(qobject_cast(parent())); + + /* + QTextStream out(stdout); + + ConstraintsDialog dlg(qobject_cast(parent())); + QString test = dlg.whow(); + out << test; + */ + + } + + + void ConstraintsExtension::setMolecule(QtGui::Molecule* mol) + { + if (mol != m_molecule) + m_molecule = mol; + if (!m_molecule->constraints) + m_molecule->constraints = new ConstraintsModel(); + dialog->setModel(m_molecule->constraints); + // update dialog with constraint info (if any) from mol object + } + + 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..c924d0d29e --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsextension.h @@ -0,0 +1,46 @@ +#ifndef AVOGADRO_QTPLUGINS_CONSTRAINTS_H +#define AVOGADRO_QTPLUGINS_CONSTRAINTS_H + +#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; + }; + } +} + +#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..fba05b5ad8 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -0,0 +1,234 @@ +/********************************************************************** + constraintsmodel.cpp - Model to hold constraints + + Copyright (C) 2007 by Tim Vandermeersch + + This file is part of the Avogadro molecular editor project. + For more information, see + + Some code is based on Open Babel + For more information, see + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + ***********************************************************************/ + +#include "constraintsmodel.h" + +/* +#include +#include +#include +#include +*/ +#include +#include + +using namespace std; +//using namespace OpenBabel; + +namespace Avogadro +{ + namespace QtPlugins{ + + int ConstraintsModel::rowCount(const QModelIndex &) const + { + return m_constraints.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() >= m_constraints.size()) + return QVariant(); + + if (role == Qt::DisplayRole) + switch (index.column()) { + case 0: + if (m_constraints[index.row()].GetConstraintType() == 0) + return QString("Ignore Atom"); + else if (m_constraints[index.row()].GetConstraintType() == 1) + return QString("Fix Atom"); + else if (m_constraints[index.row()].GetConstraintType() == 2) + return QString("Fix Atom X"); + else if (m_constraints[index.row()].GetConstraintType() == 3) + return QString("Fix Atom Y"); + else if (m_constraints[index.row()].GetConstraintType() == 4) + return QString("Fix Atom Z"); + else if (m_constraints[index.row()].GetConstraintType() == 5) + return QString("Distance"); + else if (m_constraints[index.row()].GetConstraintType() == 6) + return QString("Angle"); + else if (m_constraints[index.row()].GetConstraintType() == 7) + return QString("Torsion angle"); + break; + case 1: + return m_constraints[index.row()].GetConstraintValue(); + break; + case 2: + return m_constraints[index.row()].GetConstraintAtomA(); + break; + case 3: + return m_constraints[index.row()].GetConstraintAtomB(); + break; + case 4: + return m_constraints[index.row()].GetConstraintAtomC(); + break; + case 5: + return m_constraints[index.row()].GetConstraintAtomD(); + 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(), m_constraints.size(), m_constraints.size()); + m_constraints << Constraint(type, a, b, c, d, value); + endInsertRows(); + } + /* + void ConstraintsModel::addIgnore(int index) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddIgnore(index); + endInsertRows(); + } + + void ConstraintsModel::addAtomConstraint(int index) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddAtomConstraint(index); + endInsertRows(); + } + + void ConstraintsModel::addAtomXConstraint(int index) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddAtomXConstraint(index); + endInsertRows(); + } + + void ConstraintsModel::addAtomYConstraint(int index) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddAtomYConstraint(index); + endInsertRows(); + } + + void ConstraintsModel::addAtomZConstraint(int index) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddAtomZConstraint(index); + endInsertRows(); + } + + void ConstraintsModel::addDistanceConstraint(int a, int b, double length) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddDistanceConstraint(a, b, length); + endInsertRows(); + } + + void ConstraintsModel::addAngleConstraint(int a, int b, int c, double angle) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddAngleConstraint(a, b, c, angle); + endInsertRows(); + } + + void ConstraintsModel::addTorsionConstraint(int a, int b, int c, int d, double torsion) + { + beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); + m_constraints.AddTorsionConstraint(a, b, c, d, torsion); + endInsertRows(); + } + */ + void ConstraintsModel::clear() + { + qDebug() << "ConstraintsModel::clear()" << endl; + if (m_constraints.size()) { + beginRemoveRows(QModelIndex(), 0, m_constraints.size() - 1); + m_constraints.clear(); + endRemoveRows(); + } + } + + void ConstraintsModel::deleteConstraint(int index) + { + qDebug() << "ConstraintsModel::deleteConstraint(" << index << ")" << endl; + if (m_constraints.size() && (index >= 0)) { + beginRemoveRows(QModelIndex(), index, index); + m_constraints.removeAt(index); + endRemoveRows(); + } + } + /* + // remove all constraints in which the atom occurs + void ConstraintsModel::primitiveRemoved(Primitive *primitive) + { + qDebug() << "ConstraintsModel::primitiveRemoved(...)" << endl; + if (primitive->type() == Primitive::AtomType) { + int index = static_cast(primitive)->index() + 1; + for (int i = 0; i < m_constraints.Size(); ++i) { + if ( (m_constraints.GetConstraintAtomA(i) == index) || + (m_constraints.GetConstraintAtomB(i) == index) || + (m_constraints.GetConstraintAtomC(i) == index) || + (m_constraints.GetConstraintAtomD(i) == index) ) { + + beginRemoveRows(QModelIndex(), i, i); + m_constraints.DeleteConstraint(i); + endRemoveRows(); + i--; // this index will be replaced with a new, we want to check this aswell + } + } + } + }*/ + } +} // end namespace Avogadro + diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h new file mode 100644 index 0000000000..1cab541436 --- /dev/null +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -0,0 +1,73 @@ +/********************************************************************** + constraintsmodel.h - Model to hold constraints + + Copyright (C) 2007 by Tim Vandermeersch + + This file is part of the Avogadro molecular editor project. + For more information, see + + Some code is based on Open Babel + For more information, see + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + ***********************************************************************/ + +#ifndef CONSTRAINTSMODEL_H +#define CONSTRAINTSMODEL_H + +#include +#include +#include +#include +#include "constraint.h" +#ifndef BUFF_SIZE +#define BUFF_SIZE 256 +#endif + +namespace Avogadro { + namespace QtPlugins { + class ConstraintsModel : public QAbstractTableModel + + { + Q_OBJECT + /* + public slots: + void primitiveRemoved(Primitive *primitive); + */ + public: + ConstraintsModel() : QAbstractTableModel() {} + + 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); + + /* + void addIgnore(int index); + void addAtomConstraint(int index); + void addAtomXConstraint(int index); + void addAtomYConstraint(int index); + void addAtomZConstraint(int index); + void addDistanceConstraint(int a, int b, double length); + void addAngleConstraint(int a, int b, int c, double angle); + void addTorsionConstraint(int a, int b, int c, int d, double torsion); + */ + QList m_constraints; + + }; //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 + + + + + + + + + + + + + From ca801a203500d996099fce2b93c50557e53bdb6a Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Fri, 3 Jul 2020 15:44:51 +0200 Subject: [PATCH 02/12] some cleanup Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/.#constraint.h | 1 + .../constraints/.#constraintsdialog.cpp | 1 + .../constraints/.#constraintsdialog.h | 1 + .../constraints/constraintsdialog.cpp | 27 +++-- .../qtplugins/constraints/constraintsdialog.h | 11 +- .../constraints/constraintsextension.cpp | 31 +---- .../constraints/constraintsextension.h | 2 + .../constraints/constraintsmodel.cpp | 114 +++++------------- .../qtplugins/constraints/constraintsmodel.h | 2 +- 9 files changed, 62 insertions(+), 128 deletions(-) create mode 120000 avogadro/qtplugins/constraints/.#constraint.h create mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.cpp create mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.h diff --git a/avogadro/qtplugins/constraints/.#constraint.h b/avogadro/qtplugins/constraints/.#constraint.h new file mode 120000 index 0000000000..ec856af392 --- /dev/null +++ b/avogadro/qtplugins/constraints/.#constraint.h @@ -0,0 +1 @@ +kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp new file mode 120000 index 0000000000..ec856af392 --- /dev/null +++ b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp @@ -0,0 +1 @@ +kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.h b/avogadro/qtplugins/constraints/.#constraintsdialog.h new file mode 120000 index 0000000000..ec856af392 --- /dev/null +++ b/avogadro/qtplugins/constraints/.#constraintsdialog.h @@ -0,0 +1 @@ +kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index 228788e305..f475bac412 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -13,7 +13,12 @@ namespace Avogadro { namespace QtPlugins { - ConstraintsDialog::ConstraintsDialog(QWidget* parent_, Qt::WindowFlags f) : QDialog(parent_,f), ui(new Ui::ConstraintsDialog)//, m_constraints(new QtPlugins::ConstraintsModel) + 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() )); @@ -27,8 +32,8 @@ namespace Avogadro { } void ConstraintsDialog::setModel(ConstraintsModel *model) { - m_constraints = model; // new QtPlugins::ConstraintsModel(); - ui->ConstraintsTableView->setModel(m_constraints); + // m_constraints = model; // this should be plugin->m_molecule->constraints; + ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); } void ConstraintsDialog::acceptConstraints() { @@ -36,7 +41,7 @@ namespace Avogadro { } void ConstraintsDialog::deleteConstraint() { - m_constraints->deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); + m_plugin->m_molecule->constraints->deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); } void ConstraintsDialog::addConstraint() { @@ -47,16 +52,16 @@ namespace Avogadro { int AtomIdC = ui->editC->value(); int AtomIdD = ui->editD->value(); - m_constraints->addConstraint(type, - AtomIdA, - AtomIdB, - AtomIdC, - AtomIdD, - value); + m_plugin->m_molecule->constraints->addConstraint(type, + AtomIdA, + AtomIdB, + AtomIdC, + AtomIdD, + value); } void ConstraintsDialog::deleteAllConstraints() { - m_constraints->clear(); + m_plugin->m_molecule->constraints->clear(); this->update(); } } diff --git a/avogadro/qtplugins/constraints/constraintsdialog.h b/avogadro/qtplugins/constraints/constraintsdialog.h index 0b14ebaafd..f33e9a3383 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.h +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -1,5 +1,6 @@ #ifndef AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H #define AVOGADRO_QTPLUGINS_CONSTRAINTSDIALOG_H +#include "constraintsextension.h" #include "constraintsmodel.h" #include #include @@ -14,15 +15,17 @@ namespace Avogadro { namespace Ui { class ConstraintsDialog; } + // class ConstraintsExtension; class ConstraintsDialog : public QDialog { Q_OBJECT public: - explicit ConstraintsDialog(QWidget* parent_=0, Qt::WindowFlags f = 0); + explicit ConstraintsDialog(ConstraintsExtension* plugin , + QWidget* parent_=0, + Qt::WindowFlags f = 0); ~ConstraintsDialog() override; void setModel(ConstraintsModel *model); - //void setMolecule(Molecule* m_molecule); public slots: void acceptConstraints(); @@ -32,9 +35,11 @@ namespace Avogadro { /* void comboTypeChanged(int); */ + private: Ui::ConstraintsDialog* ui; - ConstraintsModel *m_constraints; + ConstraintsExtension* m_plugin; + // ConstraintsModel *m_constraints; //Molecule* m_molecule; }; } diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index b285ea100d..fa1d547bec 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -19,7 +19,8 @@ namespace Avogadro { connect(action, SIGNAL(triggered()), SLOT(onDialog())); m_actions.push_back(action); - dialog = new ConstraintsDialog(qobject_cast(parent())); + dialog = new ConstraintsDialog(this, + qobject_cast(parent())); } @@ -35,33 +36,8 @@ namespace Avogadro { void ConstraintsExtension::onDialog() - {/* - if (!dialog) - { - dialog = new ConstraintsDialog(qobject_cast(parent())); - }*/ + { dialog->show(); - //ConstraintsDialog dlg(qobject_cast(parent())); - //dlg.show(); - /* - QMessageBox::critical(qobject_cast(parent()), tr("Error"), - tr("I could open you"), - QMessageBox::Ok); - */ - /* - ConstraintsDialog dlg; - dlg.whow(); - */ - - //ConstraintsDialog::whow(qobject_cast(parent())); - - /* - QTextStream out(stdout); - - ConstraintsDialog dlg(qobject_cast(parent())); - QString test = dlg.whow(); - out << test; - */ } @@ -73,7 +49,6 @@ namespace Avogadro { if (!m_molecule->constraints) m_molecule->constraints = new ConstraintsModel(); dialog->setModel(m_molecule->constraints); - // update dialog with constraint info (if any) from mol object } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ diff --git a/avogadro/qtplugins/constraints/constraintsextension.h b/avogadro/qtplugins/constraints/constraintsextension.h index c924d0d29e..6c0a2b3007 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.h +++ b/avogadro/qtplugins/constraints/constraintsextension.h @@ -39,6 +39,8 @@ namespace Avogadro { QList m_actions; QtGui::Molecule* m_molecule = nullptr; ConstraintsDialog* dialog = nullptr; + + friend class ConstraintsDialog; }; } } diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index fba05b5ad8..cd30b10abd 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -39,7 +39,7 @@ namespace Avogadro int ConstraintsModel::rowCount(const QModelIndex &) const { - return m_constraints.size(); + return ConstraintsList.size(); } int ConstraintsModel::columnCount(const QModelIndex &) const @@ -52,43 +52,43 @@ namespace Avogadro if (!index.isValid()) return QVariant(); - if (index.row() >= m_constraints.size()) + if (index.row() >= ConstraintsList.size()) return QVariant(); if (role == Qt::DisplayRole) switch (index.column()) { case 0: - if (m_constraints[index.row()].GetConstraintType() == 0) + if (ConstraintsList[index.row()].GetConstraintType() == 0) return QString("Ignore Atom"); - else if (m_constraints[index.row()].GetConstraintType() == 1) + else if (ConstraintsList[index.row()].GetConstraintType() == 1) return QString("Fix Atom"); - else if (m_constraints[index.row()].GetConstraintType() == 2) + else if (ConstraintsList[index.row()].GetConstraintType() == 2) return QString("Fix Atom X"); - else if (m_constraints[index.row()].GetConstraintType() == 3) + else if (ConstraintsList[index.row()].GetConstraintType() == 3) return QString("Fix Atom Y"); - else if (m_constraints[index.row()].GetConstraintType() == 4) + else if (ConstraintsList[index.row()].GetConstraintType() == 4) return QString("Fix Atom Z"); - else if (m_constraints[index.row()].GetConstraintType() == 5) + else if (ConstraintsList[index.row()].GetConstraintType() == 5) return QString("Distance"); - else if (m_constraints[index.row()].GetConstraintType() == 6) + else if (ConstraintsList[index.row()].GetConstraintType() == 6) return QString("Angle"); - else if (m_constraints[index.row()].GetConstraintType() == 7) + else if (ConstraintsList[index.row()].GetConstraintType() == 7) return QString("Torsion angle"); break; case 1: - return m_constraints[index.row()].GetConstraintValue(); + return ConstraintsList[index.row()].GetConstraintValue(); break; case 2: - return m_constraints[index.row()].GetConstraintAtomA(); + return ConstraintsList[index.row()].GetConstraintAtomA(); break; case 3: - return m_constraints[index.row()].GetConstraintAtomB(); + return ConstraintsList[index.row()].GetConstraintAtomB(); break; case 4: - return m_constraints[index.row()].GetConstraintAtomC(); + return ConstraintsList[index.row()].GetConstraintAtomC(); break; case 5: - return m_constraints[index.row()].GetConstraintAtomD(); + return ConstraintsList[index.row()].GetConstraintAtomD(); break; } @@ -128,73 +128,17 @@ namespace Avogadro void ConstraintsModel::addConstraint(int type, int a, int b, int c, int d, double value) { - beginInsertRows(QModelIndex(), m_constraints.size(), m_constraints.size()); - m_constraints << Constraint(type, a, b, c, d, value); + beginInsertRows(QModelIndex(), ConstraintsList.size(), ConstraintsList.size()); + ConstraintsList << Constraint(type, a, b, c, d, value); endInsertRows(); } - /* - void ConstraintsModel::addIgnore(int index) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddIgnore(index); - endInsertRows(); - } - - void ConstraintsModel::addAtomConstraint(int index) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddAtomConstraint(index); - endInsertRows(); - } - - void ConstraintsModel::addAtomXConstraint(int index) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddAtomXConstraint(index); - endInsertRows(); - } - - void ConstraintsModel::addAtomYConstraint(int index) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddAtomYConstraint(index); - endInsertRows(); - } - - void ConstraintsModel::addAtomZConstraint(int index) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddAtomZConstraint(index); - endInsertRows(); - } - - void ConstraintsModel::addDistanceConstraint(int a, int b, double length) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddDistanceConstraint(a, b, length); - endInsertRows(); - } - - void ConstraintsModel::addAngleConstraint(int a, int b, int c, double angle) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddAngleConstraint(a, b, c, angle); - endInsertRows(); - } - - void ConstraintsModel::addTorsionConstraint(int a, int b, int c, int d, double torsion) - { - beginInsertRows(QModelIndex(), m_constraints.Size(), m_constraints.Size()); - m_constraints.AddTorsionConstraint(a, b, c, d, torsion); - endInsertRows(); - } - */ + void ConstraintsModel::clear() { qDebug() << "ConstraintsModel::clear()" << endl; - if (m_constraints.size()) { - beginRemoveRows(QModelIndex(), 0, m_constraints.size() - 1); - m_constraints.clear(); + if (ConstraintsList.size()) { + beginRemoveRows(QModelIndex(), 0, ConstraintsList.size() - 1); + ConstraintsList.clear(); endRemoveRows(); } } @@ -202,9 +146,9 @@ namespace Avogadro void ConstraintsModel::deleteConstraint(int index) { qDebug() << "ConstraintsModel::deleteConstraint(" << index << ")" << endl; - if (m_constraints.size() && (index >= 0)) { + if (ConstraintsList.size() && (index >= 0)) { beginRemoveRows(QModelIndex(), index, index); - m_constraints.removeAt(index); + ConstraintsList.removeAt(index); endRemoveRows(); } } @@ -215,14 +159,14 @@ namespace Avogadro qDebug() << "ConstraintsModel::primitiveRemoved(...)" << endl; if (primitive->type() == Primitive::AtomType) { int index = static_cast(primitive)->index() + 1; - for (int i = 0; i < m_constraints.Size(); ++i) { - if ( (m_constraints.GetConstraintAtomA(i) == index) || - (m_constraints.GetConstraintAtomB(i) == index) || - (m_constraints.GetConstraintAtomC(i) == index) || - (m_constraints.GetConstraintAtomD(i) == index) ) { + for (int i = 0; i < ConstraintsList.Size(); ++i) { + if ( (ConstraintsList.GetConstraintAtomA(i) == index) || + (ConstraintsList.GetConstraintAtomB(i) == index) || + (ConstraintsList.GetConstraintAtomC(i) == index) || + (ConstraintsList.GetConstraintAtomD(i) == index) ) { beginRemoveRows(QModelIndex(), i, i); - m_constraints.DeleteConstraint(i); + ConstraintsList.DeleteConstraint(i); endRemoveRows(); i--; // this index will be replaced with a new, we want to check this aswell } diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index 1cab541436..50a485ec33 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -64,7 +64,7 @@ namespace Avogadro { void addAngleConstraint(int a, int b, int c, double angle); void addTorsionConstraint(int a, int b, int c, int d, double torsion); */ - QList m_constraints; + QList ConstraintsList; }; //ConstraintsModel } // QtPlugins From dbc1506cfbecbb8bf325b35dad20f9b20810d30e Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Fri, 3 Jul 2020 15:52:30 +0200 Subject: [PATCH 03/12] more cleanup Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/.#constraintsdialog.cpp | 1 - avogadro/qtplugins/constraints/.#constraintsdialog.h | 1 - avogadro/qtplugins/constraints/constraintsdialog.cpp | 3 +-- avogadro/qtplugins/constraints/constraintsdialog.h | 8 +------- 4 files changed, 2 insertions(+), 11 deletions(-) delete mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.cpp delete mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.h diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp deleted file mode 120000 index ec856af392..0000000000 --- a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp +++ /dev/null @@ -1 +0,0 @@ -kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.h b/avogadro/qtplugins/constraints/.#constraintsdialog.h deleted file mode 120000 index ec856af392..0000000000 --- a/avogadro/qtplugins/constraints/.#constraintsdialog.h +++ /dev/null @@ -1 +0,0 @@ -kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index f475bac412..f299760501 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -30,9 +30,8 @@ namespace Avogadro { { delete ui; } - void ConstraintsDialog::setModel(ConstraintsModel *model) + void ConstraintsDialog::setModel() { - // m_constraints = model; // this should be plugin->m_molecule->constraints; ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); } void ConstraintsDialog::acceptConstraints() diff --git a/avogadro/qtplugins/constraints/constraintsdialog.h b/avogadro/qtplugins/constraints/constraintsdialog.h index f33e9a3383..45491ff32a 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.h +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -15,7 +15,6 @@ namespace Avogadro { namespace Ui { class ConstraintsDialog; } - // class ConstraintsExtension; class ConstraintsDialog : public QDialog { Q_OBJECT @@ -25,22 +24,17 @@ namespace Avogadro { QWidget* parent_=0, Qt::WindowFlags f = 0); ~ConstraintsDialog() override; - void setModel(ConstraintsModel *model); + void setModel(); public slots: void acceptConstraints(); void addConstraint(); void deleteConstraint(); void deleteAllConstraints(); - /* - void comboTypeChanged(int); - */ private: Ui::ConstraintsDialog* ui; ConstraintsExtension* m_plugin; - // ConstraintsModel *m_constraints; - //Molecule* m_molecule; }; } } From dfabe13a73e43984f37a7be203fc220fdf8633d1 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Fri, 3 Jul 2020 15:54:52 +0200 Subject: [PATCH 04/12] still cleanup Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/constraintsextension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index fa1d547bec..16f1781a28 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -48,7 +48,7 @@ namespace Avogadro { m_molecule = mol; if (!m_molecule->constraints) m_molecule->constraints = new ConstraintsModel(); - dialog->setModel(m_molecule->constraints); + dialog->setModel(); } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ From a0f3f1bb1a77a483b58438bfe625d58dbd847201 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Fri, 3 Jul 2020 17:11:09 +0200 Subject: [PATCH 05/12] added Json Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- ...{.#constraint.h => .#constraintsmodel.cpp} | 0 avogadro/qtplugins/constraints/constraint.cpp | 31 ++++++++++++++ avogadro/qtplugins/constraints/constraint.h | 40 ++++++++++++++++++- .../constraints/constraintsmodel.cpp | 22 ++++++++++ .../qtplugins/constraints/constraintsmodel.h | 7 ++++ 5 files changed, 98 insertions(+), 2 deletions(-) rename avogadro/qtplugins/constraints/{.#constraint.h => .#constraintsmodel.cpp} (100%) diff --git a/avogadro/qtplugins/constraints/.#constraint.h b/avogadro/qtplugins/constraints/.#constraintsmodel.cpp similarity index 100% rename from avogadro/qtplugins/constraints/.#constraint.h rename to avogadro/qtplugins/constraints/.#constraintsmodel.cpp diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index 459899ba5d..f67ed6b878 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -12,6 +12,7 @@ namespace Avogadro { ConstraintValue = value; } Constraint::~Constraint(){} + void Constraint::SetConstraintType(int type) { ConstraintType = type; @@ -44,5 +45,35 @@ namespace Avogadro { { return AtomIdD; } + QJsonObject Constraint::toJson() + { + QJsonObject ConstraintJ; + ConstraintJ["type"] = GetConstraintType(); + ConstraintJ["value"] = GetConstraintValue(); + + QJsonArray ConstraintAtoms; + + switch (GetConstraintType()) + { + case 0 ... 4: + ConstraintAtoms << GetConstraintAtomA(); + break; + case 5: + ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB(); + break; + case 6: + ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB() + << GetConstraintAtomC(); + break; + case 7: + ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB() + << GetConstraintAtomC() << GetConstraintAtomD(); + break; + } + + ConstraintJ.insert("atoms", ConstraintAtoms); + + return ConstraintJ; + } } } diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h index d1391e2e4d..4a762c2ad5 100644 --- a/avogadro/qtplugins/constraints/constraint.h +++ b/avogadro/qtplugins/constraints/constraint.h @@ -1,11 +1,45 @@ #include +#include namespace Avogadro { namespace QtPlugins { class Constraint { public: - explicit Constraint(int ConstraintType, int AtomIdA, int AtomIdB, int AtomIdC, int AtomIdD, double ConstraintValue); + /* + Implementation of very simple class for the represenation of constraints. + + At the moment it stores rather naively just some numbers. 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 angle + + This constraint representation has to be translated when passing it to whatever + Optimizing/MD/QM code. + + A more sophisticated way would probably be to store pointers to the respective + atoms of the molecule and extend the Atom class by something like : + + void Atom::setConstrained() + bool Atom::isConstrained() + + This would enable easy updating of the constraints upon changing the Molecule. + + + */ + explicit Constraint(int ConstraintType, + int AtomIdA, + int AtomIdB, + int AtomIdC, + int AtomIdD, + double ConstraintValue); ~Constraint(); void SetConstraintType(int ConstraintType); @@ -19,12 +53,14 @@ namespace Avogadro { int GetConstraintAtomC() const; int GetConstraintAtomD() const; + QJsonObject toJson(); + int ConstraintType; int AtomIdA; int AtomIdB; int AtomIdC; int AtomIdD; - float ConstraintValue; + double ConstraintValue; }; } } diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index cd30b10abd..29adc70369 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -29,6 +29,7 @@ */ #include #include +#include using namespace std; //using namespace OpenBabel; @@ -152,6 +153,27 @@ namespace Avogadro 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()); + } + } + + + QJsonDocument json_doc(ConstraintsMJ); + QString json_string = json_doc.toJson(); + + qDebug() << json_string << endl; + + return ConstraintsMJ; + } /* // remove all constraints in which the atom occurs void ConstraintsModel::primitiveRemoved(Primitive *primitive) diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index 50a485ec33..950f529d3a 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "constraint.h" #ifndef BUFF_SIZE #define BUFF_SIZE 256 @@ -54,6 +56,10 @@ namespace Avogadro { void addConstraint(int type, int a, int b, int c, int d, double value); void deleteConstraint(int index); + QJsonObject toJson(); + + + /* void addIgnore(int index); void addAtomConstraint(int index); @@ -64,6 +70,7 @@ namespace Avogadro { void addAngleConstraint(int a, int b, int c, double angle); void addTorsionConstraint(int a, int b, int c, int d, double torsion); */ + QList ConstraintsList; }; //ConstraintsModel From f123c1c563872b3e9e197e2534c091b5731ef6ae Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Fri, 3 Jul 2020 17:52:04 +0200 Subject: [PATCH 06/12] cleanup Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- .../constraints/.#constraintsmodel.cpp | 1 - .../constraints/constraintsmodel.cpp | 33 ++----------------- 2 files changed, 3 insertions(+), 31 deletions(-) delete mode 120000 avogadro/qtplugins/constraints/.#constraintsmodel.cpp diff --git a/avogadro/qtplugins/constraints/.#constraintsmodel.cpp b/avogadro/qtplugins/constraints/.#constraintsmodel.cpp deleted file mode 120000 index ec856af392..0000000000 --- a/avogadro/qtplugins/constraints/.#constraintsmodel.cpp +++ /dev/null @@ -1 +0,0 @@ -kantundpeterpan@haina-Ubs19.20331:1593701498 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index 29adc70369..35b90a5bb4 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -20,13 +20,6 @@ ***********************************************************************/ #include "constraintsmodel.h" - -/* -#include -#include -#include -#include -*/ #include #include #include @@ -158,6 +151,7 @@ namespace Avogadro { QJsonObject ConstraintsMJ; ConstraintsMJ["total"] = ConstraintsList.size(); + if(ConstraintsList.size()) { for(int i = 0; i < ConstraintsList.size(); i++) @@ -166,35 +160,14 @@ namespace Avogadro } } - + /* QJsonDocument json_doc(ConstraintsMJ); QString json_string = json_doc.toJson(); qDebug() << json_string << endl; - + */ return ConstraintsMJ; } - /* - // remove all constraints in which the atom occurs - void ConstraintsModel::primitiveRemoved(Primitive *primitive) - { - qDebug() << "ConstraintsModel::primitiveRemoved(...)" << endl; - if (primitive->type() == Primitive::AtomType) { - int index = static_cast(primitive)->index() + 1; - for (int i = 0; i < ConstraintsList.Size(); ++i) { - if ( (ConstraintsList.GetConstraintAtomA(i) == index) || - (ConstraintsList.GetConstraintAtomB(i) == index) || - (ConstraintsList.GetConstraintAtomC(i) == index) || - (ConstraintsList.GetConstraintAtomD(i) == index) ) { - - beginRemoveRows(QModelIndex(), i, i); - ConstraintsList.DeleteConstraint(i); - endRemoveRows(); - i--; // this index will be replaced with a new, we want to check this aswell - } - } - } - }*/ } } // end namespace Avogadro From 424d1c8f4bb96ca53e0ecb43d52de9c7b348b1b1 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Sun, 5 Jul 2020 15:48:53 +0200 Subject: [PATCH 07/12] cleanup include statements Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/constraint.cpp | 14 ++++++-- avogadro/qtplugins/constraints/constraint.h | 8 ++--- .../constraints/constraintsdialog.cpp | 25 ++++++++++---- .../qtplugins/constraints/constraintsdialog.h | 1 - .../constraints/constraintsextension.cpp | 7 ++-- .../constraints/constraintsextension.h | 1 + .../qtplugins/constraints/constraintsmodel.h | 34 ------------------- 7 files changed, 40 insertions(+), 50 deletions(-) diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index f67ed6b878..a91ab2353c 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -2,6 +2,7 @@ namespace Avogadro { namespace QtPlugins { + Constraint::Constraint(int type, int a, int b, int c, int d, double value) { ConstraintType = type; @@ -11,40 +12,49 @@ namespace Avogadro { AtomIdD = 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; } + int Constraint::GetConstraintAtomA() const { return AtomIdA; } + int Constraint::GetConstraintAtomB() const { return AtomIdB; } + int Constraint::GetConstraintAtomC() const { return AtomIdC; } + int Constraint::GetConstraintAtomD() const { return AtomIdD; } + QJsonObject Constraint::toJson() { QJsonObject ConstraintJ; @@ -75,5 +85,5 @@ namespace Avogadro { return ConstraintJ; } - } -} + } //namespace QtPlugins +} //namespace Avogadroe diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h index 4a762c2ad5..657278041d 100644 --- a/avogadro/qtplugins/constraints/constraint.h +++ b/avogadro/qtplugins/constraints/constraint.h @@ -21,17 +21,17 @@ namespace Avogadro { 6: Angle 7: Torsion angle - This constraint representation has to be translated when passing it to whatever - Optimizing/MD/QM code. - A more sophisticated way would probably be to store pointers to the respective atoms of the molecule and extend the Atom class by something like : void Atom::setConstrained() bool Atom::isConstrained() - This would enable easy updating of the constraints upon changing the Molecule. + Connecting the appropriate signals would enable easy updating of the constraints + upon changing the Molecule. + This constraint representation has to be translated when passing it to whatever + Optimizing/MD/QM code. */ explicit Constraint(int ConstraintType, diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index f299760501..691196d564 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -5,13 +5,16 @@ #include #include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include namespace Avogadro { + // namespace QtGui{ + // class Molecule; + // } namespace QtPlugins { ConstraintsDialog::ConstraintsDialog(ConstraintsExtension* plugin, QWidget* parent_, @@ -26,22 +29,30 @@ namespace Avogadro { connect( ui->ConstraintsDelete, SIGNAL( clicked() ), this, SLOT( deleteConstraint() )); connect( ui->ConstraintsDeleteAll, SIGNAL( clicked() ), this, SLOT( deleteAllConstraints() )); } + ConstraintsDialog::~ConstraintsDialog() { delete ui; } + void ConstraintsDialog::setModel() { ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); } + void ConstraintsDialog::acceptConstraints() { hide(); } + void ConstraintsDialog::deleteConstraint() { - m_plugin->m_molecule->constraints->deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); + m_plugin-> + m_molecule-> + constraints-> + deleteConstraint(ui->ConstraintsTableView->currentIndex().row()); } + void ConstraintsDialog::addConstraint() { int type = ui->comboType->currentIndex(); @@ -58,10 +69,12 @@ namespace Avogadro { 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 index 45491ff32a..43397a7abd 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.h +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace Avogadro { diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index 16f1781a28..99ccf5b03d 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -3,12 +3,13 @@ #include "constraintsmodel.h" #include -#include -#include -#include + +//#include +//#include #include #include + namespace Avogadro { namespace QtPlugins { ConstraintsExtension::ConstraintsExtension(QObject* p) : ExtensionPlugin(p) diff --git a/avogadro/qtplugins/constraints/constraintsextension.h b/avogadro/qtplugins/constraints/constraintsextension.h index 6c0a2b3007..98c89c9343 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.h +++ b/avogadro/qtplugins/constraints/constraintsextension.h @@ -1,6 +1,7 @@ #ifndef AVOGADRO_QTPLUGINS_CONSTRAINTS_H #define AVOGADRO_QTPLUGINS_CONSTRAINTS_H +#include #include #include diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index 950f529d3a..b236aaa626 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -1,24 +1,3 @@ -/********************************************************************** - constraintsmodel.h - Model to hold constraints - - Copyright (C) 2007 by Tim Vandermeersch - - This file is part of the Avogadro molecular editor project. - For more information, see - - Some code is based on Open Babel - For more information, see - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - ***********************************************************************/ - #ifndef CONSTRAINTSMODEL_H #define CONSTRAINTSMODEL_H @@ -58,19 +37,6 @@ namespace Avogadro { QJsonObject toJson(); - - - /* - void addIgnore(int index); - void addAtomConstraint(int index); - void addAtomXConstraint(int index); - void addAtomYConstraint(int index); - void addAtomZConstraint(int index); - void addDistanceConstraint(int a, int b, double length); - void addAngleConstraint(int a, int b, int c, double angle); - void addTorsionConstraint(int a, int b, int c, int d, double torsion); - */ - QList ConstraintsList; }; //ConstraintsModel From 91c636996de952f87858f36b60e872b1f2d0012c Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Sun, 5 Jul 2020 20:47:05 +0200 Subject: [PATCH 08/12] rewrite Constraint, is now directly linked to Atoms Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/constraint.cpp | 111 +++++++++++++++--- avogadro/qtplugins/constraints/constraint.h | 34 +++++- .../constraints/constraintsextension.cpp | 3 +- .../constraints/constraintsmodel.cpp | 48 +++++++- .../qtplugins/constraints/constraintsmodel.h | 10 +- 5 files changed, 178 insertions(+), 28 deletions(-) diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index a91ab2353c..c730743cf6 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -3,14 +3,53 @@ namespace Avogadro { namespace QtPlugins { - Constraint::Constraint(int type, int a, int b, int c, int d, double value) + Constraint::Constraint(int type, + int a, + int b, + int c, + int d, + double value, + ConstraintsModel* model) { + c_model = model; ConstraintType = type; - AtomIdA = a; - AtomIdB = b; - AtomIdC = c; - AtomIdD = d; + + switch (ConstraintType) + { + case 0 ... 4: + // AtomA = &(c_model->c_molecule->atom(a)); + Atoms << c_model->c_molecule->atom(a); + break; + + case 5: + // AtomA = + Atoms << c_model->c_molecule->atom(a); + //AtomB = + Atoms << c_model->c_molecule->atom(b); + break; + + case 6: + //AtomA = + Atoms << c_model->c_molecule->atom(a); + //AtomB = + Atoms << c_model->c_molecule->atom(b); + //AtomC = + Atoms << c_model->c_molecule->atom(c); + break; + + case 7: + //AtomA = + Atoms << c_model->c_molecule->atom(a); + //AtomB = + Atoms << c_model->c_molecule->atom(b); + //AtomC = + Atoms << c_model->c_molecule->atom(c); + //AtomD = + Atoms << c_model->c_molecule->atom(d); + } + ConstraintValue = value; + } Constraint::~Constraint(){} @@ -35,24 +74,54 @@ namespace Avogadro { return ConstraintValue; } - int Constraint::GetConstraintAtomA() const + const Core::Atom* Constraint::GetConstraintAtomA() const { - return AtomIdA; + if (Atoms.size() >= 1) + { + const Core::Atom* a; + a = &Atoms[0]; + return a; + } + else + { + return nullptr; + } } - int Constraint::GetConstraintAtomB() const + const Core::Atom* Constraint::GetConstraintAtomB() const { - return AtomIdB; + if (Atoms.size() >= 2) + { + return &Atoms[1]; + } + else + { + return nullptr; + } } - int Constraint::GetConstraintAtomC() const + const Core::Atom* Constraint::GetConstraintAtomC() const { - return AtomIdC; + if (Atoms.size() >= 3) + { + return &Atoms[2]; + } + else + { + return nullptr; + } } - int Constraint::GetConstraintAtomD() const + const Core::Atom* Constraint::GetConstraintAtomD() const { - return AtomIdD; + if (Atoms.size() >= 4) + { + return &Atoms[3]; + } + else + { + return nullptr; + } } QJsonObject Constraint::toJson() @@ -66,18 +135,22 @@ namespace Avogadro { switch (GetConstraintType()) { case 0 ... 4: - ConstraintAtoms << GetConstraintAtomA(); + ConstraintAtoms << static_cast(GetConstraintAtomA()->index()); break; case 5: - ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB(); + ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) + << static_cast(GetConstraintAtomB()->index()); break; case 6: - ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB() - << GetConstraintAtomC(); + ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) + << static_cast(GetConstraintAtomB()->index()) + << static_cast(GetConstraintAtomC()->index()); break; case 7: - ConstraintAtoms << GetConstraintAtomA() << GetConstraintAtomB() - << GetConstraintAtomC() << GetConstraintAtomD(); + ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) + << static_cast(GetConstraintAtomB()->index()) + << static_cast(GetConstraintAtomC()->index()) + << static_cast(GetConstraintAtomD()->index()); break; } diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h index 657278041d..b03e86ab3c 100644 --- a/avogadro/qtplugins/constraints/constraint.h +++ b/avogadro/qtplugins/constraints/constraint.h @@ -1,7 +1,17 @@ #include #include +#include +//#include +#include +#include "constraintsmodel.h" + +#ifndef CONSTRAINT_H +#define CONSTRAINT_H namespace Avogadro { + namespace Core{ + class Atom; + } namespace QtPlugins { class Constraint { @@ -39,7 +49,8 @@ namespace Avogadro { int AtomIdB, int AtomIdC, int AtomIdD, - double ConstraintValue); + double ConstraintValue, + ConstraintsModel* model); ~Constraint(); void SetConstraintType(int ConstraintType); @@ -48,19 +59,40 @@ namespace Avogadro { int GetConstraintType() const; double GetConstraintValue() const; + /* int GetConstraintAtomA() const; int GetConstraintAtomB() const; int GetConstraintAtomC() const; int GetConstraintAtomD() const; + */ + + const Core::Atom* GetConstraintAtomA() const; + const Core::Atom* GetConstraintAtomB() const; + const Core::Atom* GetConstraintAtomC() const; + const Core::Atom* GetConstraintAtomD() const; QJsonObject toJson(); int ConstraintType; + /* int AtomIdA; int AtomIdB; int AtomIdC; int AtomIdD; + */ + + /* + Core::Atom* AtomA = nullptr; + Core::Atom* AtomB = nullptr; + Core::Atom* AtomC = nullptr; + Core::Atom* AtomD = nullptr; + */ + + QList Atoms; double ConstraintValue; + + ConstraintsModel* c_model = nullptr; }; } } +#endif diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index 99ccf5b03d..52d43c8fc4 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -48,8 +48,9 @@ namespace Avogadro { if (mol != m_molecule) m_molecule = mol; if (!m_molecule->constraints) - m_molecule->constraints = new ConstraintsModel(); + m_molecule->constraints = new ConstraintsModel(m_molecule); dialog->setModel(); + connect(m_molecule, SIGNAL( emitChanged(Molecule::Atoms)), dialog, SLOT (update())); } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index 35b90a5bb4..0b1587b6c9 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -24,8 +24,8 @@ #include #include + using namespace std; -//using namespace OpenBabel; namespace Avogadro { @@ -73,16 +73,52 @@ namespace Avogadro return ConstraintsList[index.row()].GetConstraintValue(); break; case 2: - return ConstraintsList[index.row()].GetConstraintAtomA(); + if (ConstraintsList[index.row()].GetConstraintAtomA()) + { + QVariant v; + v.setValue(ConstraintsList[index.row()].GetConstraintAtomA()->index()); + return v; + } + else + { + return "NA"; + } break; case 3: - return ConstraintsList[index.row()].GetConstraintAtomB(); + if (ConstraintsList[index.row()].GetConstraintAtomB()) + { + QVariant v; + v.setValue(ConstraintsList[index.row()].GetConstraintAtomB()->index()); + return v; + } + else + { + return "NA"; + } break; case 4: - return ConstraintsList[index.row()].GetConstraintAtomC(); + if (ConstraintsList[index.row()].GetConstraintAtomC()) + { + QVariant v; + v.setValue(ConstraintsList[index.row()].GetConstraintAtomC()->index()); + return v; + } + else + { + return "NA"; + } break; case 5: - return ConstraintsList[index.row()].GetConstraintAtomD(); + if (ConstraintsList[index.row()].GetConstraintAtomD()) + { + QVariant v; + v.setValue(ConstraintsList[index.row()].GetConstraintAtomD()->index()); + return v; + } + else + { + return "NA"; + } break; } @@ -123,7 +159,7 @@ namespace Avogadro 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); + ConstraintsList << Constraint(type, a, b, c, d, value, this); endInsertRows(); } diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index b236aaa626..f69910d100 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -7,7 +7,10 @@ #include #include #include + +#include #include "constraint.h" + #ifndef BUFF_SIZE #define BUFF_SIZE 256 #endif @@ -23,7 +26,10 @@ namespace Avogadro { void primitiveRemoved(Primitive *primitive); */ public: - ConstraintsModel() : QAbstractTableModel() {} + ConstraintsModel(QtGui::Molecule* molecule) + : QAbstractTableModel() + , c_molecule(molecule) + {} int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -38,6 +44,8 @@ namespace Avogadro { QJsonObject toJson(); QList ConstraintsList; + // reference to associated molecule + QtGui::Molecule* c_molecule = nullptr; }; //ConstraintsModel } // QtPlugins From feb7c4f6ca1c99b8b4c95aa4bdb815939421f8c4 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Sun, 5 Jul 2020 23:20:26 +0200 Subject: [PATCH 09/12] linked to atoms via uniqueIDs, automatic update of dialog Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/constraint.cpp | 93 ++++++++++--------- avogadro/qtplugins/constraints/constraint.h | 10 +- .../constraints/constraintsdialog.cpp | 3 + .../constraints/constraintsextension.cpp | 2 +- .../constraints/constraintsmodel.cpp | 13 ++- .../qtplugins/constraints/constraintsmodel.h | 6 +- 6 files changed, 72 insertions(+), 55 deletions(-) diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index c730743cf6..1906893374 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -14,38 +14,45 @@ namespace Avogadro { c_model = model; ConstraintType = type; + a = a-1; + b = b-1; + c = c-1; + d = d-1; + + // store unique AtomIds + switch (ConstraintType) { case 0 ... 4: - // AtomA = &(c_model->c_molecule->atom(a)); - Atoms << c_model->c_molecule->atom(a); + // AtomA + Atoms << c_model->c_molecule->atomUniqueId(a); break; case 5: - // AtomA = - Atoms << c_model->c_molecule->atom(a); - //AtomB = - Atoms << c_model->c_molecule->atom(b); + // AtomUniqueIdA = + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomUniqueIdB = + Atoms << c_model->c_molecule->atomUniqueId(b); break; case 6: - //AtomA = - Atoms << c_model->c_molecule->atom(a); - //AtomB = - Atoms << c_model->c_molecule->atom(b); - //AtomC = - Atoms << c_model->c_molecule->atom(c); + //AtomUniqueIdA = + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomUniqueIdB = + Atoms << c_model->c_molecule->atomUniqueId(b); + //AtomUniqueIdC = + Atoms << c_model->c_molecule->atomUniqueId(c); break; case 7: - //AtomA = - Atoms << c_model->c_molecule->atom(a); - //AtomB = - Atoms << c_model->c_molecule->atom(b); - //AtomC = - Atoms << c_model->c_molecule->atom(c); - //AtomD = - Atoms << c_model->c_molecule->atom(d); + //AtomUniqueIdA = + Atoms << c_model->c_molecule->atomUniqueId(a); + //AtomUniqueIdB = + Atoms << c_model->c_molecule->atomUniqueId(b); + //AtomUniqueIdC = + Atoms << c_model->c_molecule->atomUniqueId(c); + //AtomUniqueIdD = + Atoms << c_model->c_molecule->atomUniqueId(d); } ConstraintValue = value; @@ -74,53 +81,51 @@ namespace Avogadro { return ConstraintValue; } - const Core::Atom* Constraint::GetConstraintAtomA() const + const Index Constraint::GetConstraintAtomA() const { if (Atoms.size() >= 1) { - const Core::Atom* a; - a = &Atoms[0]; - return a; + return c_model->c_molecule->atomByUniqueId(Atoms[0]).index()+1; } else { - return nullptr; + return 0; } } - const Core::Atom* Constraint::GetConstraintAtomB() const + const Index Constraint::GetConstraintAtomB() const { if (Atoms.size() >= 2) { - return &Atoms[1]; + return c_model->c_molecule->atomByUniqueId(Atoms[1]).index()+1; } else { - return nullptr; + return 0; } } - const Core::Atom* Constraint::GetConstraintAtomC() const + const Index Constraint::GetConstraintAtomC() const { if (Atoms.size() >= 3) { - return &Atoms[2]; + return c_model->c_molecule->atomByUniqueId(Atoms[2]).index()+1; } else { - return nullptr; + return 0; } } - const Core::Atom* Constraint::GetConstraintAtomD() const + const Index Constraint::GetConstraintAtomD() const { if (Atoms.size() >= 4) { - return &Atoms[3]; + return c_model->c_molecule->atomByUniqueId(Atoms[3]).index()+1; } else { - return nullptr; + return 0; } } @@ -135,22 +140,22 @@ namespace Avogadro { switch (GetConstraintType()) { case 0 ... 4: - ConstraintAtoms << static_cast(GetConstraintAtomA()->index()); + ConstraintAtoms << static_cast(GetConstraintAtomA()); break; case 5: - ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) - << static_cast(GetConstraintAtomB()->index()); + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()); break; case 6: - ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) - << static_cast(GetConstraintAtomB()->index()) - << static_cast(GetConstraintAtomC()->index()); + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()) + << static_cast(GetConstraintAtomC()); break; case 7: - ConstraintAtoms << static_cast(GetConstraintAtomA()->index()) - << static_cast(GetConstraintAtomB()->index()) - << static_cast(GetConstraintAtomC()->index()) - << static_cast(GetConstraintAtomD()->index()); + ConstraintAtoms << static_cast(GetConstraintAtomA()) + << static_cast(GetConstraintAtomB()) + << static_cast(GetConstraintAtomC()) + << static_cast(GetConstraintAtomD()); break; } diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h index b03e86ab3c..3f822134a1 100644 --- a/avogadro/qtplugins/constraints/constraint.h +++ b/avogadro/qtplugins/constraints/constraint.h @@ -66,10 +66,10 @@ namespace Avogadro { int GetConstraintAtomD() const; */ - const Core::Atom* GetConstraintAtomA() const; - const Core::Atom* GetConstraintAtomB() const; - const Core::Atom* GetConstraintAtomC() const; - const Core::Atom* GetConstraintAtomD() const; + const Index GetConstraintAtomA() const; + const Index GetConstraintAtomB() const; + const Index GetConstraintAtomC() const; + const Index GetConstraintAtomD() const; QJsonObject toJson(); @@ -88,7 +88,7 @@ namespace Avogadro { Core::Atom* AtomD = nullptr; */ - QList Atoms; + QList Atoms; double ConstraintValue; ConstraintsModel* c_model = nullptr; diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index 691196d564..2d2dd5e71c 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -28,6 +28,7 @@ namespace Avogadro { connect( ui->ConstraintsAdd, SIGNAL( clicked() ), this, SLOT( addConstraint() )); connect( ui->ConstraintsDelete, SIGNAL( clicked() ), this, SLOT( deleteConstraint() )); connect( ui->ConstraintsDeleteAll, SIGNAL( clicked() ), this, SLOT( deleteAllConstraints() )); + } ConstraintsDialog::~ConstraintsDialog() @@ -38,6 +39,8 @@ namespace Avogadro { void ConstraintsDialog::setModel() { ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); + connect( m_plugin->m_molecule, SIGNAL( changed(unsigned int)), + m_plugin->m_molecule->constraints, SLOT (emitDataChanged())); } void ConstraintsDialog::acceptConstraints() diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index 52d43c8fc4..67a326dba6 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -50,7 +50,7 @@ namespace Avogadro { if (!m_molecule->constraints) m_molecule->constraints = new ConstraintsModel(m_molecule); dialog->setModel(); - connect(m_molecule, SIGNAL( emitChanged(Molecule::Atoms)), dialog, SLOT (update())); + } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index 0b1587b6c9..9697a78a22 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -30,6 +30,11 @@ using namespace std; namespace Avogadro { namespace QtPlugins{ + + void ConstraintsModel::emitDataChanged() + { + emit dataChanged(QModelIndex(), QModelIndex()); + } int ConstraintsModel::rowCount(const QModelIndex &) const { @@ -76,7 +81,7 @@ namespace Avogadro if (ConstraintsList[index.row()].GetConstraintAtomA()) { QVariant v; - v.setValue(ConstraintsList[index.row()].GetConstraintAtomA()->index()); + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomA())); return v; } else @@ -88,7 +93,7 @@ namespace Avogadro if (ConstraintsList[index.row()].GetConstraintAtomB()) { QVariant v; - v.setValue(ConstraintsList[index.row()].GetConstraintAtomB()->index()); + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomB())); return v; } else @@ -100,7 +105,7 @@ namespace Avogadro if (ConstraintsList[index.row()].GetConstraintAtomC()) { QVariant v; - v.setValue(ConstraintsList[index.row()].GetConstraintAtomC()->index()); + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomC())); return v; } else @@ -112,7 +117,7 @@ namespace Avogadro if (ConstraintsList[index.row()].GetConstraintAtomD()) { QVariant v; - v.setValue(ConstraintsList[index.row()].GetConstraintAtomD()->index()); + v.setValue(static_cast(ConstraintsList[index.row()].GetConstraintAtomD())); return v; } else diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index f69910d100..97bfeea852 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -43,11 +43,15 @@ namespace Avogadro { QJsonObject toJson(); + QList ConstraintsList; // reference to associated molecule QtGui::Molecule* c_molecule = nullptr; - }; //ConstraintsModel + public slots: + void emitDataChanged(); + +}; //ConstraintsModel } // QtPlugins } // end namespace Avogadro From 8be3045768faf5b5736571df6ab59cd9a9e2f32b Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Mon, 6 Jul 2020 01:25:32 +0200 Subject: [PATCH 10/12] highlighting of selected Constraint Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- .../constraints/.#constraintsdialog.cpp | 1 + avogadro/qtplugins/constraints/constraint.cpp | 29 ++-- avogadro/qtplugins/constraints/constraint.h | 46 ++---- .../constraints/constraintsdialog.cpp | 55 +++++++- .../qtplugins/constraints/constraintsdialog.h | 3 + .../constraints/constraintsdialog.ui | 133 +++++++++--------- .../constraints/constraintsextension.cpp | 12 +- .../constraints/constraintsmodel.cpp | 27 ---- .../qtplugins/constraints/constraintsmodel.h | 8 +- 9 files changed, 154 insertions(+), 160 deletions(-) create mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.cpp diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp new file mode 120000 index 0000000000..a0ca7487e7 --- /dev/null +++ b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp @@ -0,0 +1 @@ +kantundpeterpan@haina-Ubs19.5479:1593976063 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index 1906893374..379bc6e24c 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -14,6 +14,7 @@ namespace Avogadro { c_model = model; ConstraintType = type; + //adjusting for 0 indexing a = a-1; b = b-1; c = c-1; @@ -29,29 +30,29 @@ namespace Avogadro { break; case 5: - // AtomUniqueIdA = + //AtomA Atoms << c_model->c_molecule->atomUniqueId(a); - //AtomUniqueIdB = + //AtomB Atoms << c_model->c_molecule->atomUniqueId(b); break; case 6: - //AtomUniqueIdA = + //AtomA Atoms << c_model->c_molecule->atomUniqueId(a); - //AtomUniqueIdB = + //AtomB Atoms << c_model->c_molecule->atomUniqueId(b); - //AtomUniqueIdC = + //AtomC Atoms << c_model->c_molecule->atomUniqueId(c); break; case 7: - //AtomUniqueIdA = + //AtomA Atoms << c_model->c_molecule->atomUniqueId(a); - //AtomUniqueIdB = + //AtomB Atoms << c_model->c_molecule->atomUniqueId(b); - //AtomUniqueIdC = + //AtomC Atoms << c_model->c_molecule->atomUniqueId(c); - //AtomUniqueIdD = + //AtomD Atoms << c_model->c_molecule->atomUniqueId(d); } @@ -83,7 +84,7 @@ namespace Avogadro { const Index Constraint::GetConstraintAtomA() const { - if (Atoms.size() >= 1) + if (Atoms.size() >= 1) //returned for all constraint types { return c_model->c_molecule->atomByUniqueId(Atoms[0]).index()+1; } @@ -95,7 +96,7 @@ namespace Avogadro { const Index Constraint::GetConstraintAtomB() const { - if (Atoms.size() >= 2) + if (Atoms.size() >= 2) //distance, angle and torsion constraints { return c_model->c_molecule->atomByUniqueId(Atoms[1]).index()+1; } @@ -107,7 +108,7 @@ namespace Avogadro { const Index Constraint::GetConstraintAtomC() const { - if (Atoms.size() >= 3) + if (Atoms.size() >= 3) //angle and torsion constraints { return c_model->c_molecule->atomByUniqueId(Atoms[2]).index()+1; } @@ -119,7 +120,7 @@ namespace Avogadro { const Index Constraint::GetConstraintAtomD() const { - if (Atoms.size() >= 4) + if (Atoms.size() >= 4) //torsion constraints only { return c_model->c_molecule->atomByUniqueId(Atoms[3]).index()+1; } @@ -164,4 +165,4 @@ namespace Avogadro { return ConstraintJ; } } //namespace QtPlugins -} //namespace Avogadroe +} //namespace Avogadro diff --git a/avogadro/qtplugins/constraints/constraint.h b/avogadro/qtplugins/constraints/constraint.h index 3f822134a1..966058b0ad 100644 --- a/avogadro/qtplugins/constraints/constraint.h +++ b/avogadro/qtplugins/constraints/constraint.h @@ -1,7 +1,7 @@ #include #include #include -//#include + #include #include "constraintsmodel.h" @@ -17,10 +17,9 @@ namespace Avogadro { { public: /* - Implementation of very simple class for the represenation of constraints. + Implementation of simple class for the represenation of constraints. - At the moment it stores rather naively just some numbers. The ConstraintType - has the following mapping (reflected in the ConstraintDialog combobox): + The ConstraintType has the following mapping (reflected in the ConstraintDialog combobox): 0: Ignore Atom 1: Fix Atom @@ -29,19 +28,13 @@ namespace Avogadro { 4: Fix Atom Z 5: Distance 6: Angle - 7: Torsion angle - - A more sophisticated way would probably be to store pointers to the respective - atoms of the molecule and extend the Atom class by something like : - - void Atom::setConstrained() - bool Atom::isConstrained() + 7: Torsion - Connecting the appropriate signals would enable easy updating of the constraints - upon changing the Molecule. + 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 when passing it to whatever - Optimizing/MD/QM code. + This constraint representation has to be translated into package specific instructions when + passing it to whatever Optimizing/MD/QM code. */ explicit Constraint(int ConstraintType, @@ -54,17 +47,10 @@ namespace Avogadro { ~Constraint(); void SetConstraintType(int ConstraintType); - // void SetAtomId(QList atom_ids); void SetValue(double Value); int GetConstraintType() const; double GetConstraintValue() const; - /* - int GetConstraintAtomA() const; - int GetConstraintAtomB() const; - int GetConstraintAtomC() const; - int GetConstraintAtomD() const; - */ const Index GetConstraintAtomA() const; const Index GetConstraintAtomB() const; @@ -74,23 +60,9 @@ namespace Avogadro { QJsonObject toJson(); int ConstraintType; - /* - int AtomIdA; - int AtomIdB; - int AtomIdC; - int AtomIdD; - */ - - /* - Core::Atom* AtomA = nullptr; - Core::Atom* AtomB = nullptr; - Core::Atom* AtomC = nullptr; - Core::Atom* AtomD = nullptr; - */ - - QList Atoms; double ConstraintValue; + QList Atoms; ConstraintsModel* c_model = nullptr; }; } diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index 2d2dd5e71c..94440e856d 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -1,10 +1,13 @@ #include "constraintsdialog.h" #include "ui_constraintsdialog.h" + #include #include #include #include +using Avogadro::QtGui::Molecule; + //#include //#include //#include @@ -12,9 +15,6 @@ //#include namespace Avogadro { - // namespace QtGui{ - // class Molecule; - // } namespace QtPlugins { ConstraintsDialog::ConstraintsDialog(ConstraintsExtension* plugin, QWidget* parent_, @@ -28,7 +28,8 @@ namespace Avogadro { 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() @@ -36,11 +37,55 @@ namespace Avogadro { 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); + } + // get currently selected constraint + QModelIndex idx = ui->ConstraintsTableView->selectionModel()->currentIndex(); + // extract 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"; + } + m_plugin->m_molecule->emitChanged(Molecule::Atoms); + } + } + void ConstraintsDialog::setModel() { ui->ConstraintsTableView->setModel(m_plugin->m_molecule->constraints); connect( m_plugin->m_molecule, SIGNAL( changed(unsigned int)), m_plugin->m_molecule->constraints, SLOT (emitDataChanged())); + /* + connect( ui->ConstraintsTableView, SIGNAL( selectionChanged(const QItemSelection &selected, + const QItemSelection &deselected)), + this, SLOT(highlightSelected())); + */ } void ConstraintsDialog::acceptConstraints() @@ -58,6 +103,7 @@ namespace Avogadro { void ConstraintsDialog::addConstraint() { + //Parsing user inptu int type = ui->comboType->currentIndex(); double value = ui->editValue->value(); int AtomIdA = ui->editA->value(); @@ -65,6 +111,7 @@ namespace Avogadro { 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, diff --git a/avogadro/qtplugins/constraints/constraintsdialog.h b/avogadro/qtplugins/constraints/constraintsdialog.h index 43397a7abd..560663bfae 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.h +++ b/avogadro/qtplugins/constraints/constraintsdialog.h @@ -30,10 +30,13 @@ namespace Avogadro { void addConstraint(); void deleteConstraint(); void deleteAllConstraints(); + void highlightSelected(); + void connectHighlight(int state); private: Ui::ConstraintsDialog* ui; ConstraintsExtension* m_plugin; + }; } } diff --git a/avogadro/qtplugins/constraints/constraintsdialog.ui b/avogadro/qtplugins/constraints/constraintsdialog.ui index 42a3c2186d..ee526432cb 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.ui +++ b/avogadro/qtplugins/constraints/constraintsdialog.ui @@ -1,122 +1,123 @@ - + + Avogadro::QtPlugins::ConstraintsDialog - - + + 0 0 - 750 + 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 @@ -127,39 +128,39 @@ - - + + Options - + - + - - + + false - + Save - - + + false - + Load - + Qt::Horizontal - + 40 20 @@ -168,47 +169,41 @@ - - - + + + Highlight selected Constraint + + + + + + + 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 index 67a326dba6..6f4af1aa3d 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -46,11 +46,15 @@ namespace Avogadro { void ConstraintsExtension::setMolecule(QtGui::Molecule* mol) { if (mol != m_molecule) - m_molecule = mol; + { + m_molecule = mol; + dialog->setModel(); + dialog->connectHighlight(0); + } if (!m_molecule->constraints) - m_molecule->constraints = new ConstraintsModel(m_molecule); - dialog->setModel(); - + { + m_molecule->constraints = new ConstraintsModel(m_molecule); + } } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ diff --git a/avogadro/qtplugins/constraints/constraintsmodel.cpp b/avogadro/qtplugins/constraints/constraintsmodel.cpp index 9697a78a22..f1a7fe78e3 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.cpp +++ b/avogadro/qtplugins/constraints/constraintsmodel.cpp @@ -1,24 +1,3 @@ -/********************************************************************** - constraintsmodel.cpp - Model to hold constraints - - Copyright (C) 2007 by Tim Vandermeersch - - This file is part of the Avogadro molecular editor project. - For more information, see - - Some code is based on Open Babel - For more information, see - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - ***********************************************************************/ - #include "constraintsmodel.h" #include #include @@ -200,13 +179,7 @@ namespace Avogadro ConstraintsMJ.insert(QString::number(i), ConstraintsList[i].toJson()); } } - - /* - QJsonDocument json_doc(ConstraintsMJ); - QString json_string = json_doc.toJson(); - qDebug() << json_string << endl; - */ return ConstraintsMJ; } } diff --git a/avogadro/qtplugins/constraints/constraintsmodel.h b/avogadro/qtplugins/constraints/constraintsmodel.h index 97bfeea852..b2d12cba31 100644 --- a/avogadro/qtplugins/constraints/constraintsmodel.h +++ b/avogadro/qtplugins/constraints/constraintsmodel.h @@ -11,9 +11,6 @@ #include #include "constraint.h" -#ifndef BUFF_SIZE -#define BUFF_SIZE 256 -#endif namespace Avogadro { namespace QtPlugins { @@ -45,13 +42,14 @@ namespace Avogadro { QList ConstraintsList; - // reference to associated molecule + + // pointer to the associated molecule QtGui::Molecule* c_molecule = nullptr; public slots: void emitDataChanged(); -}; //ConstraintsModel + }; //ConstraintsModel } // QtPlugins } // end namespace Avogadro From 33e9693f8274434785b2b256d4a4b16a352231b3 Mon Sep 17 00:00:00 2001 From: kantundpeterpan Date: Mon, 6 Jul 2020 12:31:00 +0200 Subject: [PATCH 11/12] updated automatic update of constraints Signed-off-by: kantundpeterpan Signed-off-by: Geoff Hutchison --- .../constraints/.#constraintsdialog.cpp | 1 - .../constraints/constraintsdialog.cpp | 32 +++++++++---------- .../constraints/constraintsextension.cpp | 5 +-- 3 files changed, 19 insertions(+), 19 deletions(-) delete mode 120000 avogadro/qtplugins/constraints/.#constraintsdialog.cpp diff --git a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp b/avogadro/qtplugins/constraints/.#constraintsdialog.cpp deleted file mode 120000 index a0ca7487e7..0000000000 --- a/avogadro/qtplugins/constraints/.#constraintsdialog.cpp +++ /dev/null @@ -1 +0,0 @@ -kantundpeterpan@haina-Ubs19.5479:1593976063 \ No newline at end of file diff --git a/avogadro/qtplugins/constraints/constraintsdialog.cpp b/avogadro/qtplugins/constraints/constraintsdialog.cpp index 94440e856d..442de90781 100644 --- a/avogadro/qtplugins/constraints/constraintsdialog.cpp +++ b/avogadro/qtplugins/constraints/constraintsdialog.cpp @@ -61,31 +61,31 @@ namespace Avogadro { { m_plugin->m_molecule->atom(i).setSelected(false); } - // get currently selected constraint - QModelIndex idx = ui->ConstraintsTableView->selectionModel()->currentIndex(); - // extract 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++) + if (m_plugin->m_molecule->constraints->ConstraintsList.size()>0) { - // get atom by uniqueID and set selected - m_plugin->m_molecule->atomByUniqueId(c->Atoms[i]).setSelected(true); - qDebug() << "Set selected"; + // 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); } - 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())); - /* - connect( ui->ConstraintsTableView, SIGNAL( selectionChanged(const QItemSelection &selected, - const QItemSelection &deselected)), - this, SLOT(highlightSelected())); - */ } void ConstraintsDialog::acceptConstraints() @@ -123,7 +123,7 @@ namespace Avogadro { void ConstraintsDialog::deleteAllConstraints() { m_plugin->m_molecule->constraints->clear(); - this->update(); + // this->update(); } } diff --git a/avogadro/qtplugins/constraints/constraintsextension.cpp b/avogadro/qtplugins/constraints/constraintsextension.cpp index 6f4af1aa3d..dac9ff068f 100644 --- a/avogadro/qtplugins/constraints/constraintsextension.cpp +++ b/avogadro/qtplugins/constraints/constraintsextension.cpp @@ -48,13 +48,14 @@ namespace Avogadro { if (mol != m_molecule) { m_molecule = mol; - dialog->setModel(); - dialog->connectHighlight(0); + // dialog->connectHighlight(0); } + if (!m_molecule->constraints) { m_molecule->constraints = new ConstraintsModel(m_molecule); } + dialog->setModel(); } bool ConstraintsExtension::readMolecule(QtGui::Molecule& mol){ From a6317b03992bd1193c5877390fa4d65f21329407 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 22 Mar 2022 22:46:37 -0400 Subject: [PATCH 12/12] Fix syntax error with case statement on VC++ Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/constraints/constraint.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/avogadro/qtplugins/constraints/constraint.cpp b/avogadro/qtplugins/constraints/constraint.cpp index 379bc6e24c..3676361004 100644 --- a/avogadro/qtplugins/constraints/constraint.cpp +++ b/avogadro/qtplugins/constraints/constraint.cpp @@ -24,7 +24,11 @@ namespace Avogadro { switch (ConstraintType) { - case 0 ... 4: + case 0: + case 1: + case 2: + case 3: + case 4: // AtomA Atoms << c_model->c_molecule->atomUniqueId(a); break; @@ -140,7 +144,11 @@ namespace Avogadro { switch (GetConstraintType()) { - case 0 ... 4: + case 0: + case 1: + case 2: + case 3: + case 4: ConstraintAtoms << static_cast(GetConstraintAtomA()); break; case 5: