Skip to content

Commit

Permalink
Merge pull request #1376 from ghutchis/reset-view-command
Browse files Browse the repository at this point in the history
Add alignView script command (e.g., for screenshots)
  • Loading branch information
ghutchis authored Oct 17, 2023
2 parents 575bee9 + 4177564 commit aa47ffc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
27 changes: 23 additions & 4 deletions avogadro/qtplugins/resetview/resetview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include <avogadro/qtopengl/glwidget.h>
#include <avogadro/rendering/camera.h>

#include <QTimer>
#include <QAction>
#include <QDebug>
#include <QOpenGLWidget>
#include <QTimer>

#include <limits>

Expand Down Expand Up @@ -46,6 +47,24 @@ ResetView::ResetView(QObject* parent_)

ResetView::~ResetView() {}

void ResetView::registerCommands()
{
emit registerCommand("alignView", tr("Align view to axes."));
}

bool ResetView::handleCommand(const QString& command,
const QVariantMap& options)
{
if (m_molecule == nullptr || m_camera == nullptr)
return false; // Nothing to do

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

QList<QAction*> ResetView::actions() const
{
QList<QAction*> result;
Expand Down Expand Up @@ -185,13 +204,13 @@ inline void getOBB(const Array<Vector3>& mols, Vector3d& centroid,
{
centroid = Vector3::Zero();

for (const auto & mol : mols)
for (const auto& mol : mols)
centroid += mol;

centroid /= (double)mols.size();
Matrix3d covariance = Matrix3::Zero();

for (const auto & mol : mols) {
for (const auto& mol : mols) {
Vector3d adjusted = mol - centroid;
covariance += adjusted * adjusted.transpose();
}
Expand Down Expand Up @@ -254,4 +273,4 @@ void ResetView::alignToAxes()
animationCameraDefault();
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
5 changes: 5 additions & 0 deletions avogadro/qtplugins/resetview/resetview.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ResetView : 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;
void setCamera(Rendering::Camera* camera) override;
Expand Down

0 comments on commit aa47ffc

Please sign in to comment.