summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Render/Q3DSGraphObjectTranslator.cpp
blob: f4bdd1936b4e1ad6f7da0c2489f31d1d33c5b3ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "Q3DSGraphObjectTranslator.h"
#include "Q3DSTranslation.h"
#include "Q3DSStringTable.h"

#include "Qt3DSString.h"
#include "IDocumentReader.h"

namespace Q3DStudio
{

QMap<Q3DSGraphObject *, Q3DSGraphObjectTranslator *> Q3DSGraphObjectTranslator::s_translatorMap;

Q3DSGraphObjectTranslator::Q3DSGraphObjectTranslator(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
                                                     Q3DSGraphObject &inObj)
    : m_graphObject(&inObj)
    , m_instanceHandle(inInstance)
    , m_dirtyIndex(std::numeric_limits<unsigned int>::max())
{
    s_translatorMap.insert(m_graphObject, this);
}

Q3DSGraphObjectTranslator::~Q3DSGraphObjectTranslator()
{
    s_translatorMap.remove(m_graphObject);
}

void Q3DSGraphObjectTranslator::pushTranslation(Q3DSTranslation &translation)
{
    QString theId = translation.reader().GetFileId(instanceHandle());
    if (theId.size() && theId != graphObject().id()) {
        QByteArray data = theId.toLatin1();
        translation.presentation()->registerObject(data, &graphObject());
    }
    setDirty(false);
}

bool Q3DSGraphObjectTranslator::updateProperty(Q3DSTranslation &context,
                                               qt3dsdm::Qt3DSDMInstanceHandle instance,
                                               qt3dsdm::Qt3DSDMPropertyHandle property,
                                               qt3dsdm::SValue &value,
                                               const QString &name)
{
    Q_UNUSED(context)
    Q_UNUSED(instance)
    Q_UNUSED(property)
    Q3DSPropertyChangeList changeList;
    if (name == QLatin1String("name"))
        changeList.append(m_graphObject->setName(value.toQVariant().toString()));
    else if (name == QLatin1String("starttime"))
        changeList.append(m_graphObject->setStartTime(value.getData<qint32>()));
    else if (name == QLatin1String("endtime"))
        changeList.append(m_graphObject->setEndTime(value.getData<qint32>()));
    if (changeList.count())
        m_graphObject->notifyPropertyChanges(changeList);
    return changeList.count() > 0;
}

void Q3DSGraphObjectTranslator::copyProperties(Q3DSGraphObject *target, bool ignoreReferenced)
{
    Q_UNUSED(ignoreReferenced);
    Q3DSPropertyChangeList changeList;
    changeList.append(target->setName(graphObject().name()));
    changeList.append(target->setStartTime(graphObject().startTime()));
    changeList.append(target->setEndTime(graphObject().endTime()));
    target->notifyPropertyChanges(changeList);
}

Q3DSGraphObjectTranslator *Q3DSGraphObjectTranslator::translatorForObject(Q3DSGraphObject *object)
{
    return s_translatorMap.value(object, nullptr);
}

Q3DSGraphObjectTranslator *Q3DSGraphObjectTranslator::parent() const
{
    return translatorForObject(m_graphObject->parent());
}

void Q3DSGraphObjectTranslator::releaseGraphObjectsRecursive(Q3DSTranslation &inContext)
{
    const Q3DStudio::CGraph &graph = inContext.assetGraph();
    int childCount = graph.GetChildCount(instanceHandle());
    for (int idx = 0; idx < childCount; ++idx) {
        qt3dsdm::Qt3DSDMInstanceHandle childInstance = graph.GetChild(instanceHandle(), idx);
        Q3DSGraphObjectTranslator *child = inContext.getOrCreateTranslator(childInstance);
        child->releaseGraphObjectsRecursive(inContext);
        inContext.releaseTranslator(child);
    }
}

void Q3DSAliasedTranslator::pushTranslation(Q3DSTranslation &translation)
{
    // copy object values from the referenced graph object
    Q3DSGraphObjectTranslator *reference = translation.getOrCreateTranslator(instanceHandle());

    reference->copyProperties(&graphObject(), true);

    setDirty(false);
}

}