Created
June 27, 2018 18:46
-
-
Save ghutchis/debb02a623d49e5cc835ac4e6c9a9dfa to your computer and use it in GitHub Desktop.
Broken ResetView for Avo2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | |
avogadro_plugin(ResetView | |
"Manipulate the view camera." | |
ExtensionPlugin | |
resetview.h | |
ResetView | |
"resetview.cpp" | |
"" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
This source file is part of the Avogadro project. | |
Copyright 2017, Geoffrey R. Hutchison | |
This source code is released under the New BSD License, (the "License"). | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
******************************************************************************/ | |
#include "resetview.h" | |
#include <avogadro/rendering/camera.h> | |
#include <avogadro/qtgui/molecule.h> | |
#include <QtWidgets/QAction> | |
namespace Avogadro { | |
namespace QtPlugins { | |
ResetView::ResetView(QObject *parent_) : | |
Avogadro::QtGui::ExtensionPlugin(parent_), | |
m_centerAction(new QAction(tr("Center"), this)), | |
m_viewToAxesAction(new QAction(tr("Align View to Axes"), this)) | |
{ | |
connect(m_centerAction, SIGNAL(triggered()), SLOT(centerView())); | |
connect(m_viewToAxesAction, SIGNAL(triggered()), SLOT(alignToAxes())); | |
} | |
ResetView::~ResetView() | |
{ | |
} | |
QList<QAction *> ResetView::actions() const | |
{ | |
QList<QAction *> result; | |
return result << m_centerAction << m_viewToAxesAction; | |
} | |
QStringList ResetView::menuPath(QAction *) const | |
{ | |
return QStringList() << tr("&View"); | |
} | |
void ResetView::setMolecule(QtGui::Molecule *mol) | |
{ | |
m_molecule = mol; | |
} | |
void ResetView::setCamera(Rendering::Camera *camera) | |
{ | |
m_camera = camera; | |
} | |
void ResetView::centerView() | |
{ | |
if (!m_molecule || m_camera) | |
return; | |
// Check for 3D coordinates - it's useless to consider the camera otherwise | |
if (m_molecule->atomPositions3d().size() != m_molecule->atomCount()) | |
return; | |
// no need to animate when there are no atoms | |
if(m_molecule->atomCount() == 0) { | |
m_camera->translate( Eigen::Vector3d( 0.0, 0.0, -20.0 ) ); | |
return; | |
} | |
Matrix3d linearGoal; | |
linearGoal.row(2) = d->glWidget->normalVector(); | |
linearGoal.row(0) = linearGoal.row(2).unitOrthogonal(); | |
linearGoal.row(1) = linearGoal.row(2).cross(linearGoal.row(0)); | |
// calculate the translation matrix | |
Transform3d goal(linearGoal); | |
goal.pretranslate(- 3.0 * (d->glWidget->radius() + CAMERA_NEAR_DISTANCE) * Vector3d::UnitZ()); | |
m_camera->setModelView(goal); | |
return; | |
} | |
void ResetView::alignToAxes() | |
{ | |
if (!m_molecule || m_camera) | |
return; | |
// Check for 3D coordinates - it's useless to consider the camera otherwise | |
if (m_molecule->atomPositions3d().size() != m_molecule->atomCount()) | |
return; | |
} | |
} // namespace QtPlugins | |
} // namespace Avogadro |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
This source file is part of the Avogadro project. | |
Copyright 2017, Geoffrey R. Hutchison | |
This source code is released under the New BSD License, (the "License"). | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
******************************************************************************/ | |
#ifndef AVOGADRO_QTPLUGINS_RESETVIEW_H | |
#define AVOGADRO_QTPLUGINS_RESETVIEW_H | |
#include <avogadro/qtgui/extensionplugin.h> | |
#include <avogadro/core/avogadrocore.h> | |
#include <Eigen/Geometry> | |
#include <QtCore/QTimer> | |
namespace Avogadro { | |
namespace QtPlugins { | |
/** | |
* @brief The ResetView class adjusts the camera/view | |
*/ | |
class ResetView : public QtGui::ExtensionPlugin | |
{ | |
Q_OBJECT | |
public: | |
explicit ResetView(QObject *parent_ = 0); | |
~ResetView() override; | |
QString name() const override { return tr("ResetView"); } | |
QString description() const override | |
{ | |
return tr("Adjust the camera and view"); | |
} | |
QList<QAction *> actions() const override; | |
QStringList menuPath(QAction *action) const override; | |
public slots: | |
void setMolecule(QtGui::Molecule *mol) override; | |
void setCamera(Rendering::Camera *camera) override; | |
void centerView(); | |
void alignToAxes(); | |
private: | |
QtGui::Molecule *m_molecule; | |
Rendering::Camera *m_camera; | |
QAction *m_centerAction; | |
QAction *m_viewToAxesAction; | |
QTimer *m_timer; | |
Eigen::Quaterniond startOrientation, endOrientation; | |
Eigen::Vector3d deltaTrans, startTrans; | |
double rotationAcceleration; | |
long rotationStart; | |
int rotationTime; | |
int currentTime; | |
}; | |
} // namespace QtPlugins | |
} // namespace Avogadro | |
#endif // AVOGADRO_QTPLUGINS_RESETVIEW_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment