summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/TimelineTranslationManager.cpp
blob: c03867a79abe360d2b987f4060bb3aaa4907fa76 (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
129
130
/****************************************************************************
**
** Copyright (C) 2008 NVIDIA Corporation.
** Copyright (C) 2017 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 "TimelineTranslationManager.h"
#include "SlideTimelineItemBinding.h"
#include "GroupTimelineItemBinding.h"
#include "BehaviorTimelineItemBinding.h"
#include "MaterialTimelineItemBinding.h"
#include "ImageTimelineItemBinding.h"
#include "PathAnchorPointTimelineItemBinding.h"
#include "PathTimelineItemBinding.h"
#include "LayerTimelineItemBinding.h"
#include "Qt3DSDMStudioSystem.h"
#include "StudioObjectTypes.h"
#include "StudioApp.h"
#include "Core.h"
#include "Doc.h"
#include "ClientDataModelBridge.h"

using namespace qt3dsdm;

CTimelineTranslationManager::CTimelineTranslationManager()
{
}

CTimelineTranslationManager::~CTimelineTranslationManager()
{
    // clean up all bindings
    Clear();
}

ITimelineItemBinding *CTimelineTranslationManager::GetOrCreate(Qt3DSDMInstanceHandle inInstance)
{
    ITimelineItemBinding *theBinding = GetBinding(inInstance);
    if (!theBinding) {
        Qt3DSDMTimelineItemBinding *theReturn = nullptr;

        EStudioObjectType objType = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem()
                                    ->GetClientDataModelBridge()->GetObjectType(inInstance);

        if (objType & OBJTYPE_IS_MATERIAL) {
            theReturn = new CMaterialTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_IMAGE) {
            theReturn = new CImageTimelineItemBinding(this, inInstance);
        } else if (objType & (OBJTYPE_GROUP | OBJTYPE_COMPONENT)) {
            theReturn = new CGroupTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_BEHAVIOR) {
            theReturn = new CBehaviorTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_SLIDE) {
            theReturn = new CSlideTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_PATHANCHORPOINT) {
            theReturn = new CPathAnchorPointTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_PATH) {
            theReturn = new CPathTimelineItemBinding(this, inInstance);
        } else if (objType == OBJTYPE_LAYER) {
            theReturn = new CLayerTimelineItemBinding(this, inInstance);
        } else if (objType & (OBJTYPE_MODEL | OBJTYPE_TEXT | OBJTYPE_CAMERA | OBJTYPE_EFFECT
                              | OBJTYPE_LIGHT | OBJTYPE_RENDERPLUGIN | OBJTYPE_ALIAS
                              | OBJTYPE_SUBPATH))
            theReturn = new Qt3DSDMTimelineItemBinding(this, inInstance);
        else {
            // Add support for additional DataModel types here.
            Q_ASSERT(0);
        }

        m_InstanceBindingMap.insert({theReturn->GetInstanceHandle(), theReturn});
        theBinding = theReturn;
    }

    return theBinding;
}

/**
 * Clear all bindings, typically when a presentation is closed.
 */
void CTimelineTranslationManager::Clear()
{
    // clean up all bindings
    m_InstanceBindingMap.clear();
}

/**
 * @return the Binding object that corresponds to this instance.
 */
Qt3DSDMTimelineItemBinding *
CTimelineTranslationManager::GetBinding(Qt3DSDMInstanceHandle inHandle) const
{
    auto it = m_InstanceBindingMap.find(inHandle);
    if (it != m_InstanceBindingMap.end())
        return it->second;

    return nullptr;
}

CDoc *CTimelineTranslationManager::GetDoc() const
{
    return dynamic_cast<CDoc *>(g_StudioApp.GetCore()->GetDoc());
}

CStudioSystem *CTimelineTranslationManager::GetStudioSystem() const
{
    return GetDoc()->GetStudioSystem();
}