| 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_SVG_H |
| 7 |
#define AVOGADRO_QTPLUGINS_SVG_H |
| 8 |
|
| 9 |
#include <Eigen/Geometry> |
| 10 |
#include <QPainter> |
| 11 |
#include <avogadro/core/vector.h> |
| 12 |
#include <avogadro/qtgui/extensionplugin.h> |
| 13 |
#include <avogadro/qtgui/molecule.h> |
| 14 |
#include <map> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace Avogadro { |
| 18 |
namespace QtPlugins { |
| 19 |
typedef Avogadro::Core::Array<Avogadro::Core::Bond> NeighborListType; |
| 20 |
|
| 21 |
class SVG : public Avogadro::QtGui::ExtensionPlugin |
| 22 |
{ |
| 23 |
Q_OBJECT |
| 24 |
public: |
| 25 |
explicit SVG(QObject* parent_ = nullptr); |
| 26 |
~SVG() override; |
| 27 |
QString name() const override { return tr("SVG"); } |
| 28 |
|
| 29 |
QString description() const override |
| 30 |
{ |
| 31 |
return tr("Render the scene in a SVG file."); |
| 32 |
} |
| 33 |
|
| 34 |
QList<QAction*> actions() const override; |
| 35 |
|
| 36 |
QStringList menuPath(QAction* action) const override; |
| 37 |
|
| 38 |
public slots: |
| 39 |
void setMolecule(QtGui::Molecule* mol) override; |
| 40 |
void setScene(Rendering::Scene* scene) override; |
| 41 |
void setCamera(Rendering::Camera* camera) override; |
| 42 |
|
| 43 |
private slots: |
| 44 |
void render(); |
| 45 |
|
| 46 |
private: |
| 47 |
struct SVGAtom |
| 48 |
{ |
| 49 |
Eigen::Vector3f pos_model, pos_view, pos_image; |
| 50 |
unsigned int radius; |
| 51 |
unsigned int id; |
| 52 |
|
| 53 |
SVGAtom(Vector3f m, Vector3f v, unsigned int i, unsigned int bonds) |
| 54 |
: pos_model(m), pos_view(v), id(i) |
| 55 |
{ |
| 56 |
radius = (bonds <= 0 ? 1 : bonds); |
| 57 |
} |
| 58 |
}; |
| 59 |
QtGui::Molecule* m_molecule; |
| 60 |
Rendering::Scene* m_scene; |
| 61 |
Rendering::Camera* m_camera; |
| 62 |
|
| 63 |
QAction* m_action; |
| 64 |
int m_width, m_height; |
| 65 |
Eigen::Vector3f m_min, m_max; |
| 66 |
std::vector<SVGAtom> m_atoms; |
| 67 |
std::vector<Eigen::Vector4f> m_frustrum; |
| 68 |
std::map<unsigned int, unsigned int> m_idToindex; |
| 69 |
|
| 70 |
static const float DEFAULT_RADIUS, DEFAULT_PEN_WIDTH_MOL, |
| 71 |
DEFAULT_PEN_WIDTH_BOND, DEFAULT_OFF_SET_PARALEL, DEFAULT_IMAGE_PADDING; |
| 72 |
static const Vector3ub DEFAULT_BOND_COLOR; |
| 73 |
|
| 74 |
float m_radius, m_penWidthMol, m_penWidthBond, m_offSetParalel, |
| 75 |
m_ImagePadding; |
| 76 |
Vector3ub m_BondColor; |
| 77 |
void paintSVG(QPainter& painter); |
| 78 |
void paintCore(QPainter& painter, const SVGAtom& atom); |
| 79 |
void paintBonds(QPainter& painter, const SVGAtom& atom, unsigned int i, |
| 80 |
const NeighborListType& bonds); |
| 81 |
|
| 82 |
bool defaultChecks(); |
| 83 |
void setOptions(); |
| 84 |
void getPositions(); |
| 85 |
void calculateCamera(); |
| 86 |
bool frustrumCulling(const SVGAtom& atom); |
| 87 |
Eigen::Vector3f posToSVGImage(const SVGAtom& atom); |
| 88 |
}; |
| 89 |
} // namespace QtPlugins |
| 90 |
} // namespace Avogadro |
| 91 |
#endif // AVOGADRO_QTPLUGINS_SVG_H |