1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "channelmapping_p.h"
38#include <Qt3DAnimation/qchannelmapping.h>
39#include <Qt3DAnimation/private/qcallbackmapping_p.h>
40#include <Qt3DAnimation/private/qchannelmapping_p.h>
41#include <Qt3DAnimation/private/qskeletonmapping_p.h>
42#include <Qt3DAnimation/private/animationlogging_p.h>
43#include <Qt3DAnimation/private/qchannelmappingcreatedchange_p.h>
44#include <Qt3DAnimation/private/managers_p.h>
45#include <Qt3DCore/qpropertyupdatedchange.h>
46
47QT_BEGIN_NAMESPACE
48
49namespace Qt3DAnimation {
50namespace Animation {
51
52ChannelMapping::ChannelMapping()
53 : BackendNode(ReadOnly)
54 , m_channelName()
55 , m_targetId()
56 , m_type(static_cast<int>(QVariant::Invalid))
57 , m_componentCount(0)
58 , m_propertyName(nullptr)
59 , m_callback(nullptr)
60 , m_callbackFlags(0)
61 , m_skeletonId()
62 , m_mappingType(MappingType::ChannelMappingType)
63{
64}
65
66void ChannelMapping::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
67{
68 const auto createdChange = qSharedPointerCast<QChannelMappingCreatedChangeBase>(change);
69 switch (createdChange->type()) {
70 case QChannelMappingCreatedChangeBase::ChannelMapping: {
71 const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QChannelMappingData>>(change);
72 const auto &data = typedChange->data;
73 m_channelName = data.channelName;
74 m_targetId = data.targetId;
75 m_type = data.type;
76 m_componentCount = data.componentCount;
77 m_propertyName = data.propertyName;
78 m_mappingType = ChannelMappingType;
79 break;
80 }
81
82 case QChannelMappingCreatedChangeBase::SkeletonMapping: {
83 const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QSkeletonMappingData>>(change);
84 const auto &data = typedChange->data;
85 m_skeletonId = data.skeletonId;
86 m_mappingType = SkeletonMappingType;
87 break;
88 }
89
90 case QChannelMappingCreatedChangeBase::CallbackMapping: {
91 const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QCallbackMappingData>>(change);
92 const auto &data = typedChange->data;
93 m_channelName = data.channelName;
94 m_type = data.type;
95 m_callback = data.callback;
96 m_callbackFlags = data.callbackFlags;
97 m_mappingType = ChannelMappingType;
98 break;
99 }
100 }
101}
102
103void ChannelMapping::cleanup()
104{
105 setEnabled(false);
106 m_channelName.clear();
107 m_targetId = Qt3DCore::QNodeId();
108 m_type = static_cast<int>(QVariant::Invalid);
109 m_propertyName = nullptr;
110 m_componentCount = 0;
111 m_callback = nullptr;
112 m_callbackFlags = 0;
113 m_skeletonId = Qt3DCore::QNodeId();
114}
115
116void ChannelMapping::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
117{
118 switch (e->type()) {
119 case Qt3DCore::PropertyUpdated: {
120 const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
121 if (change->propertyName() == QByteArrayLiteral("channelName"))
122 m_channelName = change->value().toString();
123 else if (change->propertyName() == QByteArrayLiteral("target"))
124 m_targetId = change->value().value<Qt3DCore::QNodeId>();
125 else if (change->propertyName() == QByteArrayLiteral("type"))
126 m_type = change->value().toInt();
127 else if (change->propertyName() == QByteArrayLiteral("propertyName"))
128 m_propertyName = static_cast<const char *>(const_cast<const void *>(change->value().value<void *>()));
129 else if (change->propertyName() == QByteArrayLiteral("componentCount"))
130 m_componentCount = change->value().toInt();
131 else if (change->propertyName() == QByteArrayLiteral("callback"))
132 m_callback = static_cast<QAnimationCallback *>(change->value().value<void *>());
133 else if (change->propertyName() == QByteArrayLiteral("callbackFlags"))
134 m_callbackFlags = QAnimationCallback::Flags(change->value().toInt());
135 else if (change->propertyName() == QByteArrayLiteral("skeleton"))
136 m_skeletonId = change->value().value<Qt3DCore::QNodeId>();
137 break;
138 }
139
140 default:
141 break;
142 }
143 QBackendNode::sceneChangeEvent(e);
144}
145
146Skeleton *ChannelMapping::skeleton() const
147{
148 return m_handler->skeletonManager()->lookupResource(m_skeletonId);
149}
150
151} // namespace Animation
152} // namespace Qt3DAnimation
153
154QT_END_NAMESPACE
155