Commit a4f44f26 authored by Jan Möbius's avatar Jan Möbius

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20846 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin (DIRS
INSTALLDATA Icons
)
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 18129 $ *
* $LastChangedBy: moebius $ *
* $Date: 2014-02-05 10:25:53 +0100 (Mi, 05 Feb 2014) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS DeserializeScreenshotMetadataPlugin - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "DeserializeScreenshotMetadataPlugin.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/RPCWrappers.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
//== IMPLEMENTATION ==========================================================
DeserializeScreenshotMetadataPlugin::DeserializeScreenshotMetadataPlugin() :
toolbar(0),
restoreAction(0),
restore_from_screenshot_dlg(0) {
}
void DeserializeScreenshotMetadataPlugin::initializePlugin() {
}
void DeserializeScreenshotMetadataPlugin::pluginsInitialized() {
toolbar = new QToolBar(tr("Restore from Screenshot"));
restoreAction = new QAction(tr("Restore Scene From Screenshot"), toolbar);
restoreAction->setIcon(
QIcon(OpenFlipper::Options::iconDirStr() +
OpenFlipper::Options::dirSeparator() +
"restore_from_screenshot.png"));
toolbar->addAction(restoreAction);
emit addToolbar(toolbar);
connect(restoreAction, SIGNAL(triggered(bool)), this,
SLOT(slot_restore_from_screenshot()));
}
void DeserializeScreenshotMetadataPlugin::slot_do_restore_from_screenshot() {
if (!restore_from_screenshot_dlg) return;
const QString restoreFileName =
restore_from_screenshot_dlg->getRestoreFileName();
QImage img(restoreFileName);
if (img.isNull()) {
QMessageBox::warning(0, tr("Unable to load image"),
tr("Unable to load image. "
"Unrecognized format or file not existent."),
QMessageBox::Ok);
return;
}
/*
* Deserialize View
*/
if (restore_from_screenshot_dlg->restore_viewer_cb->isChecked()) {
QString view = img.text("View");
if (!view.isEmpty()) {
RPC::callFunction("core", "setViewAndWindowGeometry", view);
}
}
/*
* Deserialize Materials
*/
if (restore_from_screenshot_dlg->restore_materials_cb->isChecked()) {
QString materials_json =
QString::fromUtf8("{") + img.text("Mesh Materials") +
QString::fromUtf8("}");
QVariantMap materials = ACG::json_to_variant_map(materials_json);
QMap<QString, ACG::SceneGraph::Material*> objname_to_material;
for (PluginFunctions::ObjectIterator
o_it(PluginFunctions::ALL_OBJECTS, DATA_ALL);
o_it != PluginFunctions::objectsEnd(); ++o_it) {
if (!o_it->materialNode()) continue;
objname_to_material[o_it->name()] = &o_it->materialNode()->material();
}
for (QVariantMap::const_iterator it = materials.begin();
it != materials.end(); ++it) {
if (objname_to_material.contains(it.key())) {
objname_to_material[it.key()]->deserializeFromVariantMap(
it.value().toMap());
}
}
}
/*
* Notify core.
*/
if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
QStringList textKeys = img.textKeys();
QVector<QPair<QString, QString> > metadata;
metadata.reserve(textKeys.size());
for (QStringList::iterator it = textKeys.begin();
it != textKeys.end(); ++it) {
metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
}
emit metadataDeserialized(metadata);
}
}
void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
if (!restore_from_screenshot_dlg) {
restore_from_screenshot_dlg = new RestoreFromScreenshotDlg();
connect(restore_from_screenshot_dlg->restore_pb,
SIGNAL(clicked()),
this,
SLOT(slot_do_restore_from_screenshot()));
}
restore_from_screenshot_dlg->show();
restore_from_screenshot_dlg->raise();
}
void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
QString key, QString value) {
}
void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
QString object_name, QString value) {
}
#if QT_VERSION >= 0x050000
void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
QString object_name, QJsonDocument value) {
}
#endif
//-----------------------------------------------------------------------------
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(DeserializeScreenshotMetadataPlugin, DeserializeScreenshotMetadataPlugin);
#endif
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 18129 $ *
* $LastChangedBy: moebius $ *
* $Date: 2014-02-05 10:25:53 +0100 (Mi, 05 Feb 2014) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS DeserializeScreenshotMetadataPlugin
//
//=============================================================================
#ifndef DESERIALIZESCREENSHOTMETADATAPLUGIN_HH
#define DESERIALIZESCREENSHOTMETADATAPLUGIN_HH
//== INCLUDES =================================================================
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/MetadataInterface.hh>
#include <ACG/QtWidgets/QtExaminerViewer.hh>
#include "RestoreFromScreenshotDlg.hh"
//== CLASS DEFINITION =========================================================
class DeserializeScreenshotMetadataPlugin: public QObject,
BaseInterface,
ToolbarInterface,
MetadataInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(MetadataInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-DeserializeScreenshotMetadataPlugin")
#endif
signals:
void updateView();
void updatedObject(int /*_identifier*/, const UpdateType /*_type*/);
// ToolboxInterface
void addToolbar(QToolBar* _toolbar);
// MetadataInterface
void metadataDeserialized(
const QVector<QPair<QString, QString> > &data);
private slots:
// initialization functions
void initializePlugin();
void pluginsInitialized();
void slot_restore_from_screenshot();
void slot_do_restore_from_screenshot();
void slotGenericMetadataDeserialized(QString key, QString value);
void slotObjectMetadataDeserialized(QString object_name, QString value);
#if QT_VERSION >= 0x050000
void slotObjectMetadataDeserializedJson(
QString object_name, QJsonDocument value);
#endif
public:
DeserializeScreenshotMetadataPlugin();
~DeserializeScreenshotMetadataPlugin() { }
QString name() {
return (QString("DeserializeScreenshotMetadata"));
}
QString description() {
return (QString("Deserializes meta data from viewer snapshots."));
}
private:
QToolBar *toolbar;
QAction *restoreAction;
RestoreFromScreenshotDlg *restore_from_screenshot_dlg;
};
//=============================================================================
#endif // DESERIALIZESCREENSHOTMETADATAPLUGIN_HH defined
//=============================================================================
/*
* RestoreFromScreenshotDlg.hh
*
* Created on: Jan 7, 2014
* Author: ebke
*/
#ifndef RESTOREFROMSCREENSHOTDLG_HH_
#define RESTOREFROMSCREENSHOTDLG_HH_
#include "ui_RestoreFromScreenshotDlg.hh"
class RestoreFromScreenshotDlg : public QDialog,
public Ui::RestoreFromScreenshotDlg {
Q_OBJECT
public:
RestoreFromScreenshotDlg(QWidget * parent = 0) :
QDialog(parent) {
setupUi(this);
}
QString getRestoreFileName() {
return restore_file_picker->currentFileName();
}
};
#endif /* RESTOREFROMSCREENSHOTDLG_HH_ */
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RestoreFromScreenshotDlg</class>
<widget class="QWidget" name="RestoreFromScreenshotDlg">
<property name="minimumSize">
<size>
<width>512</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Restore Scene from Screen Shot</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/Plugin-DeserializeScreenshotMetadata/Icons/restore_from_screenshot.png</normaloff>:/Plugin-DeserializeScreenshotMetadata/Icons/restore_from_screenshot.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,1,0">
<item>
<widget class="FilePicker" name="restore_file_picker" native="true">
<property name="recent_files_ini_key" stdset="0">
<string notr="true">Plugin-DeserializeScreenshotMetadata/RecentRestoreFiles</string>
</property>
<property name="dialog_title" stdset="0">
<string>Restore From</string>
</property>
<property name="file_filter" stdset="0">
<string>PNG Files (*.png)</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="restore_viewer_cb">
<property name="text">
<string>Restore Window and Viewer Size</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="restore_materials_cb">
<property name="text">
<string>Restore Materials</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="restore_objectmd_cb">
<property name="text">
<string>Process Plugin Meta Data</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/Plugin-DeserializeScreenshotMetadata/Icons/restore_from_screenshot.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancel_pb">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="restore_pb">
<property name="text">
<string>Restore</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FilePicker</class>
<extends>QWidget</extends>
<header location="global">OpenFlipper/widgets/filePicker/FilePicker.hh</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections>
<connection>
<sender>cancel_pb</sender>
<signal>clicked()</signal>
<receiver>RestoreFromScreenshotDlg</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>418</x>
<y>244</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>74</y>
</hint>
</hints>
</connection>
<connection>
<sender>restore_pb</sender>
<signal>clicked()</signal>
<receiver>RestoreFromScreenshotDlg</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>501</x>
<y>245</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>74</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<RCC>
<qresource prefix="Plugin-DeserializeScreenshotMetadata">
<file>Icons/restore_from_screenshot.png</file>
</qresource>
</RCC>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment