summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Qt3DStudio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp
blob: 79d5da54c7d389278aaf83d8c021ade600ff31b7 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/****************************************************************************
**
** 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 "Qt3DSCommonPrecompile.h"
#include "LayerTimelineItemBinding.h"
#include "TimelineTranslationManager.h"
#include "ImageTimelineItemBinding.h"
#include "EmptyTimelineTimebar.h"

// Data model specific
#include "IDoc.h"
#include "ClientDataModelBridge.h"
#include "DropSource.h"
#include "Doc.h"

#include "Qt3DSDMHandles.h"
#include "Qt3DSDMStudioSystem.h"

#include "Qt3DSDMMetaData.h"
#include "Qt3DSDMDataCore.h"
#include "StudioFullSystem.h"
#include "StudioCoreSystem.h"
#include "Qt3DSDMSlides.h"

using namespace qt3dsdm;

namespace {

bool ImageSlotIsFilled(qt3dsdm::IPropertySystem *inPropertySystem, Qt3DSDMInstanceHandle inInstance,
                       const TCharStr &inStr)
{
    Qt3DSDMPropertyHandle theProperty =
        inPropertySystem->GetAggregateInstancePropertyByName(inInstance, inStr);
    SValue theValue;
    inPropertySystem->GetInstancePropertyValue(inInstance, theProperty, theValue);

    SLong4 theLong4 = qt3dsdm::get<SLong4>(theValue);
    bool theReturn = theLong4.m_Longs[0] != 0 || theLong4.m_Longs[1] != 0
        || theLong4.m_Longs[2] != 0 || theLong4.m_Longs[3] != 0;

    return theReturn;
}
}

CLayerTimelineItemBinding::CLayerTimelineItemBinding(CTimelineTranslationManager *inMgr,
                                                     qt3dsdm::Qt3DSDMInstanceHandle inDataHandle)
    : Qt3DSDMTimelineItemBinding(inMgr, inDataHandle)
{
    qt3dsdm::IPropertySystem *thePropertySystem = m_TransMgr->GetStudioSystem()->GetPropertySystem();
    TPropertyHandleList theProperties;
    thePropertySystem->GetAggregateInstanceProperties(inDataHandle, theProperties);

    size_t thePropertyCount = theProperties.size();
    for (size_t thePropertyIndex = 0; thePropertyIndex < thePropertyCount; ++thePropertyIndex) {
        Qt3DSDMPropertyHandle theProperty = theProperties[thePropertyIndex];

        AdditionalMetaDataType::Value theAdditionalMetaDataType =
            thePropertySystem->GetAdditionalMetaDataType(inDataHandle, theProperty);

        if (theAdditionalMetaDataType == AdditionalMetaDataType::Image) {
            TCharStr theName(thePropertySystem->GetName(theProperty));
            TCharStr theFormalName(thePropertySystem->GetFormalName(inDataHandle, theProperty));
            TNameFormalNamePair thePair =
                std::make_tuple(theName, theFormalName, theProperty);
            m_ImageNameFormalNamePairs.push_back(thePair);
        }
    }
}

CLayerTimelineItemBinding::~CLayerTimelineItemBinding()
{
}

EStudioObjectType CLayerTimelineItemBinding::GetObjectType() const
{
    return OBJTYPE_LAYER;
}

ITimelineItemBinding *CLayerTimelineItemBinding::GetChild(long inIndex)
{
    qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
    if (theInstance.Valid()) {
        Q3DStudio::CGraphIterator theChildren;
        Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide();
        GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(),
                                     theChildren, theActiveSlide);
        theChildren += inIndex;
        return GetOrCreateBinding(theChildren.GetCurrent());
    }
    return nullptr;
}

QList<ITimelineItemBinding *> CLayerTimelineItemBinding::GetChildren()
{
    QList<ITimelineItemBinding *> retlist;
    qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
    if (theInstance.Valid()) {
        Q3DStudio::CGraphIterator theChildren;
        Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide();
        GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(),
                                     theChildren, theActiveSlide);
        int childCount = int(theChildren.GetCount());
        retlist.reserve(childCount);
        for (int i = 0; i < childCount; ++i) {
            retlist.append(GetOrCreateBinding(theChildren.GetCurrent()));
            ++theChildren;
        }
    }

    return retlist;
}

void CLayerTimelineItemBinding::OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance)
{
    using namespace qt3dsdm;
    CClientDataModelBridge *theBridge = m_TransMgr->GetStudioSystem()->GetClientDataModelBridge();
    // This is handled via the OnPropertyChanged call below
    if (theBridge->IsImageInstance(inInstance))
        return;
    else
        Qt3DSDMTimelineItemBinding::OnAddChild(inInstance);
}

void CLayerTimelineItemBinding::OnPropertyChanged(Qt3DSDMPropertyHandle inPropertyHandle)
{
    Qt3DSDMTimelineItemBinding::OnPropertyChanged(inPropertyHandle);
}

qt3dsdm::Qt3DSDMInstanceHandle
CLayerTimelineItemBinding::GetImage(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle)
{
    qt3dsdm::IPropertySystem *thePropertySystem = m_TransMgr->GetStudioSystem()->GetPropertySystem();
    SValue theImageValue;
    thePropertySystem->GetInstancePropertyValue(m_DataHandle, inPropertyHandle, theImageValue);
    SLong4 theImageLong4 = qt3dsdm::get<SLong4>(theImageValue);
    return m_TransMgr->GetStudioSystem()->GetClientDataModelBridge()->GetImageInstanceByGUID(
        theImageLong4);
}

ITimelineItemBinding *
CLayerTimelineItemBinding::GetOrCreateImageBinding(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle,
                                                   const wchar_t *inName)
{
    qt3dsdm::Qt3DSDMInstanceHandle theImageInstance = GetImage(inPropertyHandle);
    if (!theImageInstance.Valid())
        return nullptr;
    ITimelineItemBinding *theImageTimelineRow = m_TransMgr->GetBinding(theImageInstance);
    if (!theImageTimelineRow) // create
    {
        theImageTimelineRow = m_TransMgr->GetOrCreate(theImageInstance);
        // Set the name, by spec: the nice name.
        theImageTimelineRow->GetTimelineItem()->SetName(inName);
        CImageTimelineItemBinding *theImageBinding =
            dynamic_cast<CImageTimelineItemBinding *>(theImageTimelineRow);
        if (theImageBinding)
            theImageBinding->SetPropertyHandle(inPropertyHandle);
    }
    return theImageTimelineRow;
}

ITimelineItemBinding *CLayerTimelineItemBinding::GetOrCreateBinding(Qt3DSDMInstanceHandle instance)
{
    if (instance.Valid()) {
        qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
        qt3dsdm::IPropertySystem *thePropertySystem =
                m_TransMgr->GetStudioSystem()->GetPropertySystem();
        std::shared_ptr<IDataCore> theDataCore =
            m_TransMgr->GetStudioSystem()->GetFullSystem()->GetCoreSystem()->GetDataCore();
        ISlideSystem *theSlideSystem = m_TransMgr->GetStudioSystem()->GetSlideSystem();
        ISlideCore *theSlideCore = m_TransMgr->GetStudioSystem()->GetSlideCore();

        size_t theSlotCursor = (size_t)-1;
        {
            qt3dsdm::IPropertySystem *thePropertySystem =
                m_TransMgr->GetStudioSystem()->GetPropertySystem();
            qt3dsdm::SLong4 theGuid;
            {
                Qt3DSDMPropertyHandle theTypeProperty =
                    thePropertySystem->GetAggregateInstancePropertyByName(instance, L"id");
                SValue theIdValue;
                thePropertySystem->GetInstancePropertyValue(instance, theTypeProperty, theIdValue);
                theGuid = qt3dsdm::get<qt3dsdm::SLong4>(theIdValue);
            }
            for (size_t theSlotIndex = 0, theSlotCount = m_ImageNameFormalNamePairs.size();
                 theSlotIndex < theSlotCount; ++theSlotIndex) {
                bool theIsMatch = false;
                qt3dsdm::Qt3DSDMPropertyHandle theProperty =
                    std::get<2>(m_ImageNameFormalNamePairs[theSlotIndex]);
                SValue theValue;
                const Qt3DSDMPropertyDefinition &theDefinition(
                    theDataCore->GetProperty(theProperty));
                if (theDefinition.m_Type == DataModelDataType::Long4) {
                    SValue theDCValue;
                    if (theDataCore->GetInstancePropertyValue(theInstance, theProperty,
                                                              theDCValue)) {
                        SLong4 thePropGuid = get<SLong4>(theDCValue);
                        if (thePropGuid == theGuid)
                            theIsMatch = true;
                    }
                    Qt3DSDMSlideHandle theSlide =
                        theSlideSystem->GetAssociatedSlide(instance);
                    Qt3DSDMSlideHandle theMasterSlide = theSlideSystem->GetMasterSlide(theSlide);
                    if (theIsMatch == false && theSlide.Valid()
                        && theSlideCore->GetSpecificInstancePropertyValue(
                               theSlide, theInstance, theProperty, theValue)) {
                        SLong4 thePropGuid = get<SLong4>(theValue);
                        if (thePropGuid == theGuid)
                            theIsMatch = true;
                    }
                }
                if (theIsMatch) {
                    theSlotCursor = theSlotIndex;
                    break;
                }
            }
        }
        if (theSlotCursor != (size_t)-1) {
            Qt3DSDMPropertyHandle theImageProperty =
                thePropertySystem->GetAggregateInstancePropertyByName(
                    m_DataHandle, std::get<0>(m_ImageNameFormalNamePairs[theSlotCursor]));
            return GetOrCreateImageBinding(
                theImageProperty,
                std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str());
        } else
            return m_TransMgr->GetOrCreate(instance);
    }
    return nullptr;
}