Commit cbef0231 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Added optional JSON-Serialization of materials if QJson is available.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17986 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bc56a1ec
......@@ -59,6 +59,12 @@ set(INCLUDE_DIRS ${OPENMESH_INCLUDE_DIRS}
set(ADDITIONAL_LINK_LIBRARIES "" )
find_package (QJson)
if (QJSON_FOUND)
LIST(APPEND INCLUDE_DIRS ${QJSON_INCLUDE_DIR})
LIST(APPEND ADDITIONAL_LINK_LIBRARIES ${QJSON_LIBRARY})
endif ()
# use Qwt6 for QT5
if (NOT FORCE_QT4 AND QT5_FOUND)
find_package(Qwt6)
......
......@@ -58,6 +58,11 @@
#include <cstdio>
#ifdef ENABLE_QJSON
#include <QJson/Serializer>
#include <QJson/Parser>
#endif
//== NAMESPACES ===============================================================
namespace ACG {
......@@ -77,6 +82,7 @@ static inline Vec4f vl2col(const QVariantList &vl) {
}
QString Material::serializeToJson() const {
#ifdef ENABLE_QJSON
QVariantMap matMap;
matMap["baseColor"] = col2vl(baseColor_);
......@@ -99,19 +105,21 @@ QString Material::serializeToJson() const {
matMap["backfaceCulling"] = backfaceCulling_;
matMap["multiSampling"] = multiSampling_;
//QJson::Serializer serializer;
//QByteArray bytes = serializer.serialize(matMap);
//return QString::fromUtf8(bytes.constData(), bytes.size());
QJson::Serializer serializer;
QByteArray bytes = serializer.serialize(matMap);
return QString::fromUtf8(bytes.constData(), bytes.size());
#else
return QString("<No suitable serializer at the moment. Sorry.>");
#endif
}
void Material::deserializeFromJson(const QString &json) {
//QJson::Parser parser;
//bool ok;
//QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
//if (!ok) return;
QVariantMap matMap;
#ifdef ENABLE_QJSON
QJson::Parser parser;
bool ok;
QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
if (!ok) return;
//QVariantMap matMap;
if (matMap.contains("baseColor")) baseColor_ = vl2col(matMap["baseColor"].toList());
if (matMap.contains("ambientColor")) ambientColor_ = vl2col(matMap["ambientColor"].toList());
......@@ -132,6 +140,7 @@ void Material::deserializeFromJson(const QString &json) {
if (matMap.contains("colorMaterial")) colorMaterial_ = matMap["colorMaterial"].toBool();
if (matMap.contains("backfaceCulling")) backfaceCulling_ = matMap["backfaceCulling"].toBool();
if (matMap.contains("multiSampling")) multiSampling_ = matMap["multiSampling"].toBool();
#endif
}
MaterialNode::MaterialNode( BaseNode* _parent,
......
......@@ -66,7 +66,6 @@ namespace SceneGraph {
//== CLASS DEFINITION =========================================================
/** \class Material
Class to store the properties of a material.
......@@ -77,6 +76,14 @@ class ACGDLLEXPORT Material {
friend class MaterialNode;
public:
enum ClassProperties {
#ifdef ENABLE_QJSON
CP_JSON_SERIALIZABLE = 1
#else
CP_JSON_SERIALIZABLE = 0
#endif
};
/// Default constructor
Material() :
baseColor_(GLState::default_base_color),
......
# - Try to find OpenVolumeMesh
# Once done this will define
#
# QJSON_FOUND - system has QJSON
# QJSON_INCLUDE_DIR - the QJSON include directory
# QJSON_LIBRARY - Link these to use QJSON
# QJSON_LIBRARY_DIR - Library DIR of QJSON
#
IF (QJSON_INCLUDE_DIRS)
# Already in cache, be silent
SET(QJSON_FIND_QUIETLY TRUE)
ENDIF (QJSON_INCLUDE_DIRS)
FIND_PATH(QJSON_INCLUDE_DIR QJson/Serializer
PATHS /usr/local/include
/usr/include
/usr/local/OpenVolumeMesh/include
"${CMAKE_SOURCE_DIR}/libs_required/qjson/include"
"C:\\Program Files\\QJson\\include"
)
IF (QJSON_INCLUDE_DIR )
SET(QJSON_FOUND TRUE)
ADD_DEFINITIONS(-DENABLE_QJSON)
IF (WIN32)
IF(EXISTS "${QJSON_INCLUDE_DIR}/../lib")
SET(QJSON_LIBRARY_DIR "${QJSON_INCLUDE_DIR}/../lib")
ENDIF()
ELSE (WIN32)
IF(EXISTS "${QJSON_INCLUDE_DIR}/../lib/QJson")
SET(QJSON_LIBRARY_DIR "${QJSON_INCLUDE_DIR}/../lib/QJson")
ENDIF()
ENDIF (WIN32)
SET(QJSON_LIBRARY "QJson")
ELSE (QJSON_INCLUDE_DIR)
SET(QJSON_FOUND FALSE )
ENDIF (QJSON_INCLUDE_DIR )
Supports Markdown
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