Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision: 18129 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2014-02-05 10:25:53 +0100 (Mi, 05 Feb 2014) $ *
47 * *
48 \*===========================================================================*/
49 
50 //=============================================================================
51 //
52 // CLASS DeserializeScreenshotMetadataPlugin - IMPLEMENTATION
53 //
54 //=============================================================================
55 
56 //== INCLUDES =================================================================
57 
58 #include "DeserializeScreenshotMetadataPlugin.hh"
59 
63 
64 //== IMPLEMENTATION ==========================================================
65 
66 
67 DeserializeScreenshotMetadataPlugin::DeserializeScreenshotMetadataPlugin() :
68  toolbar(0),
69  restoreAction(0),
70  restore_from_screenshot_dlg(0) {
71 }
72 
73 void DeserializeScreenshotMetadataPlugin::initializePlugin() {
74 }
75 
76 void DeserializeScreenshotMetadataPlugin::pluginsInitialized() {
77  toolbar = new QToolBar(tr("Restore from Screenshot"));
78 
79  restoreAction = new QAction(tr("Restore Scene From Screenshot"), toolbar);
80  restoreAction->setIcon(
81  QIcon(OpenFlipper::Options::iconDirStr() +
82  OpenFlipper::Options::dirSeparator() +
83  "restore_from_screenshot.png"));
84 
85  toolbar->addAction(restoreAction);
86 
87  emit addToolbar(toolbar);
88 
89  connect(restoreAction, SIGNAL(triggered(bool)), this,
90  SLOT(slot_restore_from_screenshot()));
91 }
92 
93 void DeserializeScreenshotMetadataPlugin::slot_do_restore_from_screenshot() {
94  if (!restore_from_screenshot_dlg) return;
95 
96  const QString restoreFileName =
97  restore_from_screenshot_dlg->getRestoreFileName();
98 
99  QImage img(restoreFileName);
100  if (img.isNull()) {
101  QMessageBox::warning(0, tr("Unable to load image"),
102  tr("Unable to load image. "
103  "Unrecognized format or file not existent."),
104  QMessageBox::Ok);
105  return;
106  }
107 
108  /*
109  * Deserialize View
110  */
111  if (restore_from_screenshot_dlg->restore_viewer_cb->isChecked()) {
112  QString view = img.text("View");
113  if (!view.isEmpty()) {
114  RPC::callFunction("core", "setViewAndWindowGeometry", view);
115  }
116  }
117 
118  /*
119  * Deserialize Materials
120  */
121  if (restore_from_screenshot_dlg->restore_materials_cb->isChecked()) {
122  QString materials_json =
123  QString::fromUtf8("{") + img.text("Mesh Materials") +
124  QString::fromUtf8("}");
125  QVariantMap materials = ACG::json_to_variant_map(materials_json);
126 
127  QMap<QString, ACG::SceneGraph::Material*> objname_to_material;
130  o_it != PluginFunctions::objectsEnd(); ++o_it) {
131 
132  if (!o_it->materialNode()) continue;
133 
134  objname_to_material[o_it->name()] = &o_it->materialNode()->material();
135  }
136 
137  for (QVariantMap::const_iterator it = materials.begin();
138  it != materials.end(); ++it) {
139 
140  if (objname_to_material.contains(it.key())) {
141  objname_to_material[it.key()]->deserializeFromVariantMap(
142  it.value().toMap());
143  }
144  }
145  }
146 
147  /*
148  * Notify core.
149  */
150  if (restore_from_screenshot_dlg->restore_objectmd_cb->isChecked()) {
151  QStringList textKeys = img.textKeys();
152  QVector<QPair<QString, QString> > metadata;
153  metadata.reserve(textKeys.size());
154  for (QStringList::iterator it = textKeys.begin();
155  it != textKeys.end(); ++it) {
156  metadata.push_back(QPair<QString, QString>(*it, img.text(*it)));
157  }
158  emit metadataDeserialized(metadata);
159  }
160 
161 }
162 
163 void DeserializeScreenshotMetadataPlugin::slot_restore_from_screenshot() {
164  if (!restore_from_screenshot_dlg) {
165  restore_from_screenshot_dlg = new RestoreFromScreenshotDlg();
166  connect(restore_from_screenshot_dlg->restore_pb,
167  SIGNAL(clicked()),
168  this,
169  SLOT(slot_do_restore_from_screenshot()));
170  }
171  restore_from_screenshot_dlg->show();
172  restore_from_screenshot_dlg->raise();
173 }
174 
175 void DeserializeScreenshotMetadataPlugin::slotGenericMetadataDeserialized(
176  QString key, QString value) {
177 
178 }
179 
180 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserialized(
181  QString object_name, QString value) {
182 
183 }
184 
185 #if QT_VERSION >= 0x050000
186 void DeserializeScreenshotMetadataPlugin::slotObjectMetadataDeserializedJson(
187  QString object_name, QJsonDocument value) {
188 
189 }
190 #endif
191 
192 //-----------------------------------------------------------------------------
193 
194 #if QT_VERSION < 0x050000
196 #endif
197 
const QStringList ALL_OBJECTS
Iterable object range.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
Definition: RPCWrappers.cc:63
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.