| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTPLUGINS_RESETVIEW_H |
| 7 |
#define AVOGADRO_QTPLUGINS_RESETVIEW_H |
| 8 |
|
| 9 |
#include <Eigen/Geometry> |
| 10 |
#include <avogadro/qtgui/extensionplugin.h> |
| 11 |
|
| 12 |
namespace Avogadro { |
| 13 |
namespace QtPlugins { |
| 14 |
|
| 15 |
/** |
| 16 |
* @brief The ResetView class is an extension to center the camera in the best |
| 17 |
* fit panel or the default camera position |
| 18 |
*/ |
| 19 |
class ResetView : public Avogadro::QtGui::ExtensionPlugin |
| 20 |
{ |
| 21 |
Q_OBJECT |
| 22 |
public: |
| 23 |
explicit ResetView(QObject* parent_ = nullptr); |
| 24 |
~ResetView() override; |
| 25 |
|
| 26 |
QString name() const override { return tr("Reset view"); } |
| 27 |
QString description() const override |
| 28 |
{ |
| 29 |
return tr("Manipulate the view camera."); |
| 30 |
} |
| 31 |
QList<QAction*> actions() const override; |
| 32 |
QStringList menuPath(QAction*) const override; |
| 33 |
|
| 34 |
bool handleCommand(const QString& command, |
| 35 |
const QVariantMap& options) override; |
| 36 |
|
| 37 |
void registerCommands() override; |
| 38 |
|
| 39 |
public slots: |
| 40 |
void setMolecule(QtGui::Molecule* mol) override; |
| 41 |
void setCamera(Rendering::Camera* camera) override; |
| 42 |
void setActiveWidget(QWidget* widget) override; |
| 43 |
|
| 44 |
signals: |
| 45 |
void updateRequested(); |
| 46 |
|
| 47 |
private slots: |
| 48 |
void centerView(); |
| 49 |
void alignToAxes(); |
| 50 |
|
| 51 |
private: |
| 52 |
QtGui::Molecule* m_molecule; |
| 53 |
Rendering::Camera* m_camera; |
| 54 |
QAction* m_centerAction; |
| 55 |
QAction* m_viewToAxesAction; |
| 56 |
QWidget* m_glWidget; |
| 57 |
|
| 58 |
static const float DELTA_TIME; |
| 59 |
static const int TOTAL_FRAMES; |
| 60 |
|
| 61 |
bool defaultChecks(); |
| 62 |
void animationCamera(const Eigen::Affine3f& goal, bool animate = true); |
| 63 |
void animationCameraDefault(bool animate = true); |
| 64 |
float calculateOptimalOrthographicScale(const Eigen::Affine3f& viewTransform); |
| 65 |
}; |
| 66 |
|
| 67 |
} // namespace QtPlugins |
| 68 |
} // namespace Avogadro |
| 69 |
|
| 70 |
#endif |