From 60f8b77c979e40d486510c87e935bbec45bc3df4 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Mon, 16 Oct 2023 13:34:22 -0400 Subject: [PATCH] Add initial crystal and space group commands, including fillUnitCell Signed-off-by: Geoff Hutchison --- avogadro/qtplugins/crystal/crystal.cpp | 24 ++++++++++++++++++- avogadro/qtplugins/crystal/crystal.h | 5 ++++ avogadro/qtplugins/spacegroup/spacegroup.cpp | 25 ++++++++++++++++++-- avogadro/qtplugins/spacegroup/spacegroup.h | 5 ++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/avogadro/qtplugins/crystal/crystal.cpp b/avogadro/qtplugins/crystal/crystal.cpp index 04d25f1bb4..6ecd3db438 100644 --- a/avogadro/qtplugins/crystal/crystal.cpp +++ b/avogadro/qtplugins/crystal/crystal.cpp @@ -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) { @@ -233,4 +255,4 @@ void Crystal::wrapAtomsToCell() m_molecule->undoMolecule()->wrapAtomsToCell(); } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/crystal/crystal.h b/avogadro/qtplugins/crystal/crystal.h index 972ab72ca9..048c7cccf2 100644 --- a/avogadro/qtplugins/crystal/crystal.h +++ b/avogadro/qtplugins/crystal/crystal.h @@ -27,6 +27,11 @@ class Crystal : public Avogadro::QtGui::ExtensionPlugin QList 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; diff --git a/avogadro/qtplugins/spacegroup/spacegroup.cpp b/avogadro/qtplugins/spacegroup/spacegroup.cpp index 8a2f3d3e11..f50fa34bf0 100644 --- a/avogadro/qtplugins/spacegroup/spacegroup.cpp +++ b/avogadro/qtplugins/spacegroup/spacegroup.cpp @@ -13,8 +13,9 @@ #include #include -#include #include +#include +#include #include #include #include @@ -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) @@ -370,4 +391,4 @@ unsigned short SpaceGroup::selectSpaceGroup() return view->currentIndex().row() + 1; } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/spacegroup/spacegroup.h b/avogadro/qtplugins/spacegroup/spacegroup.h index 1875c10ea5..4c3d6a776c 100644 --- a/avogadro/qtplugins/spacegroup/spacegroup.h +++ b/avogadro/qtplugins/spacegroup/spacegroup.h @@ -26,6 +26,11 @@ class SpaceGroup : public Avogadro::QtGui::ExtensionPlugin QList 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);