From b1d145e5b43b31355239e5b8a3a549a3c55a3309 Mon Sep 17 00:00:00 2001 From: Malte Wirkus Date: Thu, 19 Nov 2015 11:49:26 +0100 Subject: [PATCH] Allow to export currently displayed scene to osg scene file --- src/Vizkit3DWidget.cpp | 34 +++++++++++++++++++++++++++++++++- src/Vizkit3DWidget.hpp | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Vizkit3DWidget.cpp b/src/Vizkit3DWidget.cpp index b3bf0ec..a0d5c22 100644 --- a/src/Vizkit3DWidget.cpp +++ b/src/Vizkit3DWidget.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "Vizkit3DWidget.hpp" @@ -23,6 +24,7 @@ #include #include +#include #include #include @@ -234,12 +236,23 @@ Vizkit3DWidget::Vizkit3DWidget( QWidget* parent,const QString &world_name) widget->setObjectName(QString("View Widget")); splitter->addWidget(widget); + //Create Layout + QWidget* rightPaneWidget = new QWidget(parent); + QVBoxLayout* rightPaneLayout = new QVBoxLayout(); + rightPaneWidget->setLayout(rightPaneLayout); + splitter->addWidget(rightPaneWidget); + // create propertyBrowserWidget QPropertyBrowserWidget *propertyBrowserWidget = new QPropertyBrowserWidget( parent ); propertyBrowserWidget->setObjectName("PropertyBrowser"); propertyBrowserWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); propertyBrowserWidget->resize(200,600); - splitter->addWidget(propertyBrowserWidget); + rightPaneLayout->addWidget(propertyBrowserWidget); + + // create export button + QPushButton *exportButton = new QPushButton( parent ); + exportButton->setText("Export Scene"); + rightPaneLayout->addWidget(exportButton); // add config object to the property browser Vizkit3DConfig *config = new Vizkit3DConfig(this); @@ -249,6 +262,7 @@ Vizkit3DWidget::Vizkit3DWidget( QWidget* parent,const QString &world_name) connect(this, SIGNAL(addPlugins(QObject*,QObject*)), this, SLOT(addPluginIntern(QObject*,QObject*))); connect(this, SIGNAL(removePlugins(QObject*)), this, SLOT(removePluginIntern(QObject*))); connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) ); + connect(exportButton, SIGNAL(clicked()), this, SLOT(exportScene())); current_frame = QString(root->getName().c_str()); @@ -1136,3 +1150,21 @@ void Vizkit3DWidget::setCameraManipulator(CAMERA_MANIPULATORS manipulatorType, b } } +void Vizkit3DWidget::exportScene() { + QDir directory; + + QFileDialog dialog; + QString filename; + + dialog.setDirectory( directory.currentPath() ); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilter("OSG Scene files (*.osg *.osgb)"); + dialog.setDefaultSuffix("osgb"); + dialog.setWindowTitle("Export OSG scene"); + if (dialog.exec()) { + QStringList filenames = dialog.selectedFiles(); + filename = filenames.at(0); + osgDB::writeNodeFile(*root, filename.toStdString()); + } +} + diff --git a/src/Vizkit3DWidget.hpp b/src/Vizkit3DWidget.hpp index be5c3a6..9c20933 100644 --- a/src/Vizkit3DWidget.hpp +++ b/src/Vizkit3DWidget.hpp @@ -330,6 +330,13 @@ namespace vizkit3d */ void clearEnvironmentPlugin(); + /** Exports current scene to OSG scene file + * + * Opens file dialog and saves currently displayed scene to a + * OSG scene file. + */ + void exportScene(); + signals: void addPlugins(QObject* plugin,QObject* parent); void removePlugins(QObject* plugin);