Developer Documentation
DeserializeScreenshotMetadataPlugin.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43//=============================================================================
44//
45// CLASS DeserializeScreenshotMetadataPlugin - IMPLEMENTATION
46//
47//=============================================================================
48
49//== INCLUDES =================================================================
50
51#include "DeserializeScreenshotMetadataPlugin.hh"
52
56#include <ACG/Scenegraph/MaterialNode.hh>
57#include <QMessageBox>
58
59//== IMPLEMENTATION ==========================================================
60
61
62DeserializeScreenshotMetadataPlugin::DeserializeScreenshotMetadataPlugin() :
63 toolbar(0),
64 restoreAction(0),
65 restore_from_screenshot_dlg(0) {
66}
67
68void DeserializeScreenshotMetadataPlugin::initializePlugin() {
69}
70
71void DeserializeScreenshotMetadataPlugin::pluginsInitialized() {
72 toolbar = new QToolBar(tr("Restore from Screenshot"));
73
74 restoreAction = new QAction(tr("Restore Scene From Screenshot"), toolbar);
75 restoreAction->setIcon(
76 QIcon(OpenFlipper::Options::iconDirStr() +
77 OpenFlipper::Options::dirSeparator() +
78 "restore_from_screenshot.png"));
79
80 toolbar->addAction(restoreAction);
81
82 emit addToolbar(toolbar);
83
84 connect(restoreAction, SIGNAL(triggered(bool)), this,
85 SLOT(slot_restore_from_screenshot()));
86}
87
88void DeserializeScreenshotMetadataPlugin::slot_do_restore_from_screenshot() {
89 if (!restore_from_screenshot_dlg) return;
90
91 const QString restoreFileName =
92 restore_from_screenshot_dlg->getRestoreFileName();
93
94 QImage img(restoreFileName);
95 if (img.isNull()) {
96 QMessageBox::warning(0, tr("Unable to load image"),
97 tr("Unable to load image. "
98 "Unrecognized format or file not existent."),
99 QMessageBox::Ok);
100 return;
101 }
102
103 /*
104 * Deserialize View
105 */
106 if (restore_from_screenshot_dlg->restore_viewer_cb->isChecked()) {
107 QString view = img.text("View");
108 if (!view.isEmpty()) {
109 RPC::callFunction("core", "setViewAndWindowGeometry", view);
110 }
111 }
112
113 /*
114 * Deserialize Materials
115 */
116 if (restore_from_screenshot_dlg->restore_materials_cb->isChecked()) {
117 QString materials_json =
118 QString::fromUtf8("{") + img.text("Mesh Materials") +
119 QString::fromUtf8("}");
120 QVariantMap materials = ACG::json_to_variant_map(materials_json);
121
122 QMap<QString, ACG::SceneGraph::Material*> objname_to_material;
124
125 if (!o_it->materialNode()) continue;
126
127 objname_to_material[o_it->name()] = &o_it->materialNode()->material();
128 }
129
130 for (QVariantMap::const_iterator it = materials.begin();
131 it != materials.end(); ++it) {
132
133 if (objname_to_material.contains(it.key())) {
134 objname_to_material[it.key()]->deserializeFromVariantMap(
135 it.value().toMap());
136 }
137 }
138 }
139
140 /*
141 * Notify core.
142 */
143 if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
144 QStringList textKeys = img.textKeys();
145 QVector<QPair<QString, QString> > metadata;
146 metadata.reserve(textKeys.size());
147 for (QStringList::iterator it = textKeys.begin();
148 it != textKeys.end(); ++it) {
149 metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
150 }
151 emit metadataDeserialized(metadata);
152 }
153
154}
155
156void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
157 if (!restore_from_screenshot_dlg) {
158 restore_from_screenshot_dlg = new RestoreFromScreenshotDlg();
159 connect(restore_from_screenshot_dlg->restore_pb,
160 SIGNAL(clicked()),
161 this,
162 SLOT(slot_do_restore_from_screenshot()));
163 }
164 restore_from_screenshot_dlg->show();
165 restore_from_screenshot_dlg->raise();
166}
167
168void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
169 QString key, QString value) {
170
171}
172
173void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
174 QString object_name, QString value) {
175
176}
177
178void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
179 QString object_name, QJsonDocument value) {
180
181}
182
183//-----------------------------------------------------------------------------
184
185
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
const QStringList ALL_OBJECTS
Iterable object range.
void callFunction(QString _plugin, QString _functionName)
call a function in another plugin
Definition: RPCWrappers.cc:129