Commit c403eb87 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Exposing material serialization in JavaScript and in the screen shot dialog.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17987 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ddbca539
...@@ -1119,4 +1119,26 @@ QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) { ...@@ -1119,4 +1119,26 @@ QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
return result; return result;
} }
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly) {
if (!ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE)
return QStringList();
QStringList result;
for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_ALL) ; o_it != objectsEnd(); ++o_it) {
if (visibleOnly && !o_it->visible()) continue;
QString materialStr(QObject::tr("<not available>"));
if (!o_it->materialNode())
materialStr = QObject::tr("<not available: materialNode == null>");
else
materialStr = o_it->materialNode()->material().serializeToJson();
if (!result.empty())
result.last().append(QString::fromUtf8(","));
result.append(QString::fromUtf8("\"%1\": %2").arg(o_it->name()).arg(materialStr));
}
return result;
}
} // End namespace PluginFunctions } // End namespace PluginFunctions
...@@ -390,6 +390,11 @@ void setDefaultViewObjectMarker (ViewObjectMarker *_marker); ...@@ -390,6 +390,11 @@ void setDefaultViewObjectMarker (ViewObjectMarker *_marker);
DLLEXPORT DLLEXPORT
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly); QStringList collectObjectComments(bool visibleOnly, bool targetedOnly);
/** Collect and return serialized materials of all meshes.
*/
DLLEXPORT
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly);
/// Get the default ViewObjectMarker /// Get the default ViewObjectMarker
DLLEXPORT DLLEXPORT
ViewObjectMarker* defaultViewObjectMarker (); ViewObjectMarker* defaultViewObjectMarker ();
......
...@@ -1667,6 +1667,14 @@ void Core::setDescriptions(){ ...@@ -1667,6 +1667,14 @@ void Core::setDescriptions(){
QString(tr("Toolbox Entry name,Widget,Icon")).split(","), QString(tr("Toolbox Entry name,Widget,Icon")).split(","),
QString(tr("Name of the new widget in the toolbox,Pointer to the new widget,Pointer to icon")).split(",")); QString(tr("Name of the new widget in the toolbox,Pointer to the new widget,Pointer to icon")).split(","));
emit setSlotDescription("serializeMaterialProperties(int)", tr("Serialize and return the material properties of the supplied object."),
QString(tr("ObjectId")).split(","),
QString(tr("ID of the object")).split(","));
emit setSlotDescription("deserializeMaterialProperties(int, QString)", tr("Deserialize the supplied material properties into the supplied object."),
QString(tr("ObjectId, SerializedProps")).split(","),
QString(tr("ID of the object,The serialized material properties.")).split(","));
emit setSlotDescription("addViewModeToolboxes(QString,QString)", tr("Set toolboxes for a viewmode (This automatically adds the view mode if it does not exist)"), emit setSlotDescription("addViewModeToolboxes(QString,QString)", tr("Set toolboxes for a viewmode (This automatically adds the view mode if it does not exist)"),
QString(tr("Name,Toolbox List")).split(","), QString(tr("Name,Toolbox List")).split(","),
QString(tr("Name of the Viewmode,seperated list of toolboxes visible in this viewmode")).split(",")); QString(tr("Name of the Viewmode,seperated list of toolboxes visible in this viewmode")).split(","));
...@@ -1729,6 +1737,44 @@ void Core::deleteObject( int _id ){ ...@@ -1729,6 +1737,44 @@ void Core::deleteObject( int _id ){
} }
void Core::deserializeMaterialProperties(int _objId, QString props) {
if ( _objId == -1 ) return;
BaseObject* object = objectRoot_->childExists(_objId);
if (!object || object == objectRoot_) {
std::cerr << "No such object." << std::endl;
return;
}
BaseObjectData* o = dynamic_cast<BaseObjectData *>(object);
if (!o || !o->materialNode()) {
std::cerr << "No suitable object found." << std::endl;
return;
}
o->materialNode()->material().deserializeFromJson(props);
}
QString Core::serializeMaterialProperties(int _objId) {
if ( _objId == -1 ) return QString();
BaseObject* object = objectRoot_->childExists(_objId);
if (!object || object == objectRoot_) {
std::cerr << "No such object." << std::endl;
return QString();
}
BaseObjectData* o = dynamic_cast<BaseObjectData *>(object);
if (!o || !o->materialNode()) {
std::cerr << "No suitable object found." << std::endl;
return QString();
}
return o->materialNode()->material().serializeToJson();
}
void Core::setObjectComment(int _id, QString key, QString comment) { void Core::setObjectComment(int _id, QString key, QString comment) {
if ( _id == -1 ) return; if ( _id == -1 ) return;
......
...@@ -941,6 +941,10 @@ private slots: ...@@ -941,6 +941,10 @@ private slots:
/// Get object id from filename /// Get object id from filename
int getObjectId(QString _filename); int getObjectId(QString _filename);
void deserializeMaterialProperties(int _objId, QString props);
QString serializeMaterialProperties(int _objId);
/** @} */ /** @} */
//=========================================================================== //===========================================================================
......
...@@ -521,6 +521,9 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -521,6 +521,9 @@ void CoreWidget::viewerSnapshotDialog() {
SnapshotDialog dialog(suggest, true, w, h, 0); SnapshotDialog dialog(suggest, true, w, h, 0);
if (!ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE)
dialog.metaData_storeMatInfo_cb->setVisible(false);
bool ok = dialog.exec(); bool ok = dialog.exec();
if (ok){ if (ok){
...@@ -543,6 +546,14 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -543,6 +546,14 @@ void CoreWidget::viewerSnapshotDialog() {
dialog.metaData_comments_targetedOnly_cb->isChecked()).join("\n"); dialog.metaData_comments_targetedOnly_cb->isChecked()).join("\n");
} }
QString materials;
if (ACG::SceneGraph::Material::CP_JSON_SERIALIZABLE &&
dialog.metaData_storeMatInfo_cb->isChecked()) {
materials = PluginFunctions::collectObjectMaterials(
dialog.metaData_comments_visibleOnly_cb->isChecked(),
dialog.metaData_comments_targetedOnly_cb->isChecked()).join("\n");
}
//now take the snapshot //now take the snapshot
switch ( baseLayout_->mode() ){ switch ( baseLayout_->mode() ){
...@@ -557,6 +568,8 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -557,6 +568,8 @@ void CoreWidget::viewerSnapshotDialog() {
if (!comments.isEmpty()) if (!comments.isEmpty())
finalImage.setText("Mesh Comments", comments); finalImage.setText("Mesh Comments", comments);
if (!materials.isEmpty())
finalImage.setText("Mesh Materials", materials);
if (dialog.metaData_storeView_cb->isChecked()) { if (dialog.metaData_storeView_cb->isChecked()) {
QSize window_size; QSize window_size;
if (isMaximized()) if (isMaximized())
......
...@@ -111,6 +111,12 @@ ...@@ -111,6 +111,12 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
...@@ -208,6 +214,12 @@ Allowed values: any number between 2 and 16.</string> ...@@ -208,6 +214,12 @@ Allowed values: any number between 2 and 16.</string>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
...@@ -279,6 +291,16 @@ Allowed values: any number between 2 and 16.</string> ...@@ -279,6 +291,16 @@ Allowed values: any number between 2 and 16.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="metaData_storeMatInfo_cb">
<property name="text">
<string>Store Material Info</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="sizePolicy"> <property name="sizePolicy">
...@@ -317,6 +339,12 @@ Allowed values: any number between 2 and 16.</string> ...@@ -317,6 +339,12 @@ Allowed values: any number between 2 and 16.</string>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
<item> <item>
...@@ -336,6 +364,12 @@ Allowed values: any number between 2 and 16.</string> ...@@ -336,6 +364,12 @@ Allowed values: any number between 2 and 16.</string>
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
......
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