| 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 "ply.h" |
| 7 |
|
| 8 |
#include <avogadro/qtgui/molecule.h> |
| 9 |
#include <avogadro/rendering/camera.h> |
| 10 |
#include <avogadro/rendering/plyvisitor.h> |
| 11 |
#include <avogadro/rendering/scene.h> |
| 12 |
|
| 13 |
#include <QtCore/QTextStream> |
| 14 |
#include <QtGui/QClipboard> |
| 15 |
#include <QtGui/QIcon> |
| 16 |
#include <QtGui/QKeySequence> |
| 17 |
#include <QAction> |
| 18 |
#include <QtWidgets/QApplication> |
| 19 |
#include <QtWidgets/QFileDialog> |
| 20 |
#include <QtWidgets/QMessageBox> |
| 21 |
|
| 22 |
#include <string> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
namespace Avogadro::QtPlugins { |
| 26 |
|
| 27 |
PLY::PLY(QObject* p) |
| 28 |
: Avogadro::QtGui::ExtensionPlugin(p), m_molecule(nullptr), m_scene(nullptr), |
| 29 |
m_camera(nullptr), m_action(new QAction(tr("PLY Render…"), this)) |
| 30 |
{ |
| 31 |
connect(m_action, SIGNAL(triggered()), SLOT(render())); |
| 32 |
} |
| 33 |
|
| 34 |
PLY::~PLY() {} |
| 35 |
|
| 36 |
QList<QAction*> PLY::actions() const |
| 37 |
{ |
| 38 |
QList<QAction*> result; |
| 39 |
return result << m_action; |
| 40 |
} |
| 41 |
|
| 42 |
QStringList PLY::menuPath(QAction*) const |
| 43 |
{ |
| 44 |
return QStringList() << tr("&File") << tr("&Export"); |
| 45 |
} |
| 46 |
|
| 47 |
void PLY::setMolecule(QtGui::Molecule* mol) |
| 48 |
{ |
| 49 |
m_molecule = mol; |
| 50 |
} |
| 51 |
|
| 52 |
void PLY::setScene(Rendering::Scene* scene) |
| 53 |
{ |
| 54 |
m_scene = scene; |
| 55 |
} |
| 56 |
|
| 57 |
void PLY::setCamera(Rendering::Camera* camera) |
| 58 |
{ |
| 59 |
m_camera = camera; |
| 60 |
} |
| 61 |
|
| 62 |
void PLY::render() |
| 63 |
{ |
| 64 |
if (!m_scene || !m_camera) |
| 65 |
return; |
| 66 |
|
| 67 |
QString filename = QFileDialog::getSaveFileName( |
| 68 |
qobject_cast<QWidget*>(parent()), tr("Save File"), QDir::homePath(), |
| 69 |
tr("PLY (*.ply);;Text file (*.txt)")); |
| 70 |
QFile file(filename); |
| 71 |
if (!file.open(QIODevice::WriteOnly)) |
| 72 |
return; |
| 73 |
|
| 74 |
QTextStream fileStream(&file); |
| 75 |
Rendering::PLYVisitor visitor(*m_camera); |
| 76 |
visitor.begin(); |
| 77 |
m_scene->rootNode().accept(visitor); |
| 78 |
fileStream << visitor.end().c_str(); |
| 79 |
|
| 80 |
file.close(); |
| 81 |
} |
| 82 |
|
| 83 |
} // namespace Avogadro::QtPlugins |