Skip to content

Commit

Permalink
Merge pull request #1374 from ghutchis/fill-unit-cell
Browse files Browse the repository at this point in the history
Add initial crystal and space group commands, including fillUnitCell
  • Loading branch information
ghutchis authored Oct 16, 2023
2 parents a1fa3ab + 60f8b77 commit fd05cc6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
24 changes: 23 additions & 1 deletion avogadro/qtplugins/crystal/crystal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ void Crystal::importCrystalClipboard()
}
}

void Crystal::registerCommands()
{
emit registerCommand("wrapUnitCell", tr("Wrap atoms into the unit cell."));
emit registerCommand("standardCrystalOrientation",
tr("Rotate the unit cell to the standard orientation."));
}

bool Crystal::handleCommand(const QString& command, const QVariantMap& options)
{
if (m_molecule == nullptr)
return false; // No molecule to handle the command.

if (command == "wrapUnitCell") {
wrapAtomsToCell();
return true;
} else if (command == "standardCrystalOrientation") {
standardOrientation();
return true;
}
return false;
}

void Crystal::editUnitCell()
{
if (!m_unitCellDialog) {
Expand Down Expand Up @@ -233,4 +255,4 @@ void Crystal::wrapAtomsToCell()
m_molecule->undoMolecule()->wrapAtomsToCell();
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
5 changes: 5 additions & 0 deletions avogadro/qtplugins/crystal/crystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Crystal : public Avogadro::QtGui::ExtensionPlugin
QList<QAction*> actions() const override;
QStringList menuPath(QAction*) const override;

bool handleCommand(const QString& command,
const QVariantMap& options) override;

void registerCommands() override;

public slots:
void setMolecule(QtGui::Molecule* mol) override;

Expand Down
25 changes: 23 additions & 2 deletions avogadro/qtplugins/spacegroup/spacegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <avogadro/qtgui/molecule.h>
#include <avogadro/qtgui/rwmolecule.h>

#include <QtWidgets/QAbstractItemView>
#include <QAction>
#include <QDebug>
#include <QtWidgets/QAbstractItemView>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QInputDialog>
Expand Down Expand Up @@ -104,6 +105,26 @@ QStringList SpaceGroup::menuPath(QAction*) const
return QStringList() << tr("&Crystal") << tr("Space Group");
}

void SpaceGroup::registerCommands()
{
emit registerCommand(
"fillUnitCell",
tr("Fill symmetric atoms based on the crystal space group."));
}

bool SpaceGroup::handleCommand(const QString& command,
const QVariantMap& options)
{
if (m_molecule == nullptr)
return false; // No molecule to handle the command.

if (command == "fillUnitCell") {
fillUnitCell();
return true;
}
return false;
}

void SpaceGroup::setMolecule(QtGui::Molecule* mol)
{
if (m_molecule == mol)
Expand Down Expand Up @@ -370,4 +391,4 @@ unsigned short SpaceGroup::selectSpaceGroup()
return view->currentIndex().row() + 1;
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
5 changes: 5 additions & 0 deletions avogadro/qtplugins/spacegroup/spacegroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class SpaceGroup : public Avogadro::QtGui::ExtensionPlugin
QList<QAction*> actions() const;
QStringList menuPath(QAction*) const;

bool handleCommand(const QString& command,
const QVariantMap& options) override;

void registerCommands() override;

public slots:
void setMolecule(QtGui::Molecule* mol);

Expand Down

0 comments on commit fd05cc6

Please sign in to comment.