1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "channelmapping_p.h" |
5 | #include <Qt3DAnimation/qchannelmapping.h> |
6 | #include <Qt3DAnimation/qskeletonmapping.h> |
7 | #include <Qt3DAnimation/qcallbackmapping.h> |
8 | #include <Qt3DAnimation/private/qcallbackmapping_p.h> |
9 | #include <Qt3DAnimation/private/qchannelmapping_p.h> |
10 | #include <Qt3DAnimation/private/qskeletonmapping_p.h> |
11 | #include <Qt3DAnimation/private/animationlogging_p.h> |
12 | #include <Qt3DAnimation/private/managers_p.h> |
13 | #include <Qt3DCore/qabstractskeleton.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | namespace Qt3DAnimation { |
18 | namespace Animation { |
19 | |
20 | ChannelMapping::ChannelMapping() |
21 | : BackendNode(ReadOnly) |
22 | , m_channelName() |
23 | , m_targetId() |
24 | , m_type(static_cast<int>(QMetaType::UnknownType)) |
25 | , m_componentCount(0) |
26 | , m_propertyName(nullptr) |
27 | , m_callback(nullptr) |
28 | , m_skeletonId() |
29 | , m_mappingType(MappingType::ChannelMappingType) |
30 | { |
31 | } |
32 | |
33 | void ChannelMapping::cleanup() |
34 | { |
35 | setEnabled(false); |
36 | m_channelName.clear(); |
37 | m_targetId = Qt3DCore::QNodeId(); |
38 | m_type = static_cast<int>(QMetaType::UnknownType); |
39 | m_propertyName = nullptr; |
40 | m_componentCount = 0; |
41 | m_callback = nullptr; |
42 | m_callbackFlags = {}; |
43 | m_skeletonId = Qt3DCore::QNodeId(); |
44 | } |
45 | |
46 | void ChannelMapping::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
47 | { |
48 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
49 | const QAbstractChannelMapping *node = qobject_cast<const QAbstractChannelMapping *>(object: frontEnd); |
50 | if (!node) |
51 | return; |
52 | |
53 | const QChannelMapping *channelMapping = qobject_cast<const QChannelMapping *>(object: frontEnd); |
54 | if (channelMapping) { |
55 | m_mappingType = ChannelMappingType; |
56 | m_channelName = channelMapping->channelName(); |
57 | m_targetId = Qt3DCore::qIdForNode(node: channelMapping->target()); |
58 | |
59 | QChannelMappingPrivate *d = static_cast<QChannelMappingPrivate *>(Qt3DCore::QNodePrivate::get(q: const_cast<QChannelMapping *>(channelMapping))); |
60 | m_type = d->m_type; |
61 | m_propertyName = d->m_propertyName; |
62 | m_componentCount = d->m_componentCount; |
63 | } |
64 | |
65 | const QSkeletonMapping *skeletonMapping = qobject_cast<const QSkeletonMapping *>(object: frontEnd); |
66 | if (skeletonMapping) { |
67 | m_mappingType = SkeletonMappingType; |
68 | m_skeletonId = Qt3DCore::qIdForNode(node: skeletonMapping->skeleton()); |
69 | } |
70 | |
71 | const QCallbackMapping *callbackMapping = qobject_cast<const QCallbackMapping *>(object: frontEnd); |
72 | if (callbackMapping) { |
73 | m_mappingType = ChannelMappingType; |
74 | m_channelName = callbackMapping->channelName(); |
75 | |
76 | const QCallbackMappingPrivate *d = static_cast<const QCallbackMappingPrivate *>(Qt3DCore::QNodePrivate::get(q: callbackMapping)); |
77 | m_type = d->m_type; |
78 | m_callback = d->m_callback; |
79 | m_callbackFlags = d->m_callbackFlags; |
80 | } |
81 | } |
82 | |
83 | Skeleton *ChannelMapping::skeleton() const |
84 | { |
85 | return m_handler->skeletonManager()->lookupResource(id: m_skeletonId); |
86 | } |
87 | |
88 | } // namespace Animation |
89 | } // namespace Qt3DAnimation |
90 | |
91 | QT_END_NAMESPACE |
92 | |