| 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 |
#include "force.h" |
| 7 |
|
| 8 |
#include <avogadro/core/elements.h> |
| 9 |
#include <avogadro/qtgui/molecule.h> |
| 10 |
#include <avogadro/rendering/arrowgeometry.h> |
| 11 |
#include <avogadro/rendering/geometrynode.h> |
| 12 |
#include <avogadro/rendering/groupnode.h> |
| 13 |
|
| 14 |
#include <QtWidgets/QCheckBox> |
| 15 |
#include <QtWidgets/QDoubleSpinBox> |
| 16 |
#include <QtWidgets/QHBoxLayout> |
| 17 |
#include <QtWidgets/QLabel> |
| 18 |
#include <QtWidgets/QVBoxLayout> |
| 19 |
#include <QtWidgets/QWidget> |
| 20 |
|
| 21 |
namespace Avogadro::QtPlugins { |
| 22 |
|
| 23 |
using QtGui::Molecule; |
| 24 |
using Rendering::ArrowGeometry; |
| 25 |
using Rendering::GeometryNode; |
| 26 |
using Rendering::GroupNode; |
| 27 |
|
| 28 |
Force::Force(QObject* p) : ScenePlugin(p) |
| 29 |
{ |
| 30 |
m_layerManager = QtGui::PluginLayerManager(m_name); |
| 31 |
} |
| 32 |
|
| 33 |
Force::~Force() {} |
| 34 |
|
| 35 |
void Force::process(const QtGui::Molecule& molecule, Rendering::GroupNode& node) |
| 36 |
{ |
| 37 |
auto* geometry = new GeometryNode; |
| 38 |
node.addChild(geometry); |
| 39 |
|
| 40 |
auto* arrows = new ArrowGeometry; |
| 41 |
arrows->identifier().molecule = &molecule; |
| 42 |
geometry->addDrawable(arrows); |
| 43 |
for (Index i = 0; i < molecule.atomCount(); ++i) { |
| 44 |
if (!m_layerManager.atomEnabled(i)) |
| 45 |
continue; // ignore hidden atoms |
| 46 |
|
| 47 |
Core::Atom atom1 = molecule.atom(i); |
| 48 |
Vector3f pos1 = atom1.position3d().cast<float>(); |
| 49 |
Vector3f forceVector = atom1.forceVector().cast<float>(); |
| 50 |
arrows->addSingleArrow(pos1, pos1 + forceVector); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
} // namespace Avogadro::QtPlugins |