Skip to content

Commit

Permalink
highlighting of selected Constraint
Browse files Browse the repository at this point in the history
Signed-off-by: kantundpeterpan <[email protected]>
  • Loading branch information
kantundpeterpan authored and ghutchis committed Mar 11, 2022
1 parent ac57f1f commit e02b969
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 160 deletions.
1 change: 1 addition & 0 deletions avogadro/qtplugins/constraints/.#constraintsdialog.cpp
29 changes: 15 additions & 14 deletions avogadro/qtplugins/constraints/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Avogadro {
c_model = model;
ConstraintType = type;

//adjusting for 0 indexing
a = a-1;
b = b-1;
c = c-1;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -164,4 +165,4 @@ namespace Avogadro {
return ConstraintJ;
}
} //namespace QtPlugins
} //namespace Avogadroe
} //namespace Avogadro
46 changes: 9 additions & 37 deletions avogadro/qtplugins/constraints/constraint.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <QtCore>
#include <QJsonObject>
#include <QList>
//#include <avogadro/core/atom.h>

#include <avogadro/qtgui/molecule.h>
#include "constraintsmodel.h"

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -54,17 +47,10 @@ namespace Avogadro {
~Constraint();

void SetConstraintType(int ConstraintType);
// void SetAtomId(QList<int> 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;
Expand All @@ -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<Index> Atoms;
double ConstraintValue;

QList<Index> Atoms;
ConstraintsModel* c_model = nullptr;
};
}
Expand Down
55 changes: 51 additions & 4 deletions avogadro/qtplugins/constraints/constraintsdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "constraintsdialog.h"
#include "ui_constraintsdialog.h"

#include <QPushButton>
#include <QButtonGroup>
#include <QDebug>
#include <QTextStream>

using Avogadro::QtGui::Molecule;

//#include <QFileDialog>
//#include <QFile>
//#include <QString>
//#include <QMessageBox>
//#include <string>

namespace Avogadro {
// namespace QtGui{
// class Molecule;
// }
namespace QtPlugins {
ConstraintsDialog::ConstraintsDialog(ConstraintsExtension* plugin,
QWidget* parent_,
Expand All @@ -28,19 +28,64 @@ 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()
{
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()
Expand All @@ -58,13 +103,15 @@ namespace Avogadro {

void ConstraintsDialog::addConstraint()
{
//Parsing user inptu
int type = ui->comboType->currentIndex();
double value = ui->editValue->value();
int AtomIdA = ui->editA->value();
int AtomIdB = ui->editB->value();
int AtomIdC = ui->editC->value();
int AtomIdD = ui->editD->value();

//adding the constraint to the molecule's CosntraintsModel
m_plugin->m_molecule->constraints->addConstraint(type,
AtomIdA,
AtomIdB,
Expand Down
3 changes: 3 additions & 0 deletions avogadro/qtplugins/constraints/constraintsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};
}
}
Expand Down
Loading

0 comments on commit e02b969

Please sign in to comment.