summaryrefslogtreecommitdiffstats
path: root/src/dm/systems/StudioAnimationSystem.h
blob: e6fdf75523310aad5b13ddeaad69ea9ef606a61e (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
/****************************************************************************
**
** Copyright (C) 1993-2009 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$
**
****************************************************************************/
#pragma once
#ifndef STUDIOANIMATIONSYSTEMIMPLH
#define STUDIOANIMATIONSYSTEMIMPLH

#include "Qt3DSDMAnimation.h"
#include "Qt3DSDMSlides.h"
#include "Qt3DSDMSlideCore.h"
#include "Qt3DSDMSlideGraphCore.h"
#include "Qt3DSDMTransactions.h"
#include "Qt3DSDMDataCore.h"
#include "Qt3DSDMSignals.h"

namespace qt3dsdm {

typedef std::pair<Qt3DSDMAnimationHandle, float> TAnimationFloatPair;
typedef std::vector<TAnimationFloatPair> TAnimationFloatPairList;

class CStudioAnimationSystem : public IStudioAnimationSystem,
                               public ITransactionProducer
{
    Q_DISABLE_COPY(CStudioAnimationSystem)

    TPropertySystemPtr m_PropertySystem;
    TSlideSystemPtr m_SlideSystem;
    TSlideCorePtr m_SlideCore;
    TSlideGraphCorePtr m_SlideGraphCore;
    TAnimationCorePtr m_AnimationCore;
    TRefreshCallbackFunc m_refreshCallback = nullptr;

    bool m_AutoKeyframe;
    // When a property has an animation associated with it, then writes
    // do not go all the way down to the db.  They stay on this object.
    TAnimationFloatPairList m_AnimationFloatPairs;
    bool m_SmoothInterpolation;

    TAnimationKeyframesPairList m_DeletedAnimationData; // list to store deanimated animation &
                                                        // keyframe data. This will be use if user
                                                        // wants to animate the same property again

    TTransactionConsumerPtr m_Consumer;

    std::vector<std::shared_ptr<ISignalConnection>> m_Connections;

public:
    CStudioAnimationSystem(TPropertySystemPtr inPropertySystem, TSlideSystemPtr inSlideSystem,
                           TSlideCorePtr inSlideCore, TSlideGraphCorePtr inSlideGraphCore,
                           TAnimationCorePtr inAnimationCore);

    void ClearTemporaryAnimationValues();
    void ClearTemporaryAnimationValues(Qt3DSDMAnimationHandle inAnimation);

    void SetPropertySystem(TPropertySystemPtr inPropertySystem)
    {
        m_PropertySystem = inPropertySystem;
    } // HACK: TODO: We should really consider having all the subsytem know everyone else without
      // passing in so many things in the constructor

    //====================================================================
    // IStudioAnimationSystem implementation
    //====================================================================
    void SetAutoKeyframe(bool inAutoKeyframe) override;
    bool GetAutoKeyframe() const override;
    void Animate(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty) override;
    void Deanimate(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty) override;
    void KeyframeProperty(Qt3DSDMInstanceHandle inInstance, Qt3DSDMPropertyHandle inProperty,
                                  bool inDoDiffValue) override;
    void SetOrCreateKeyframe(Qt3DSDMInstanceHandle inInstance,
                                     Qt3DSDMPropertyHandle inProperty, float inTimeInSeconds,
                                     SGetOrSetKeyframeInfo *inKeyframeInfo, size_t inNumInfos) override;
    Qt3DSDMAnimationHandle GetControllingAnimation(Qt3DSDMInstanceHandle inInstance,
                                                          Qt3DSDMPropertyHandle inProperty,
                                                          size_t inIndex) const override;
    bool IsPropertyAnimatable(Qt3DSDMInstanceHandle inInstance,
                                      Qt3DSDMPropertyHandle inProperty) const override;
    bool IsPropertyAnimated(Qt3DSDMInstanceHandle inInstance,
                                    Qt3DSDMPropertyHandle inProperty) const override;
    void SetInterpolation(bool inSmooth) override { m_SmoothInterpolation = inSmooth; }

    bool GetAnimatedInstancePropertyValue(Qt3DSDMSlideHandle inSlide,
                                                  Qt3DSDMInstanceHandle inInstance,
                                                  Qt3DSDMPropertyHandle inProperty,
                                                  SValue &outValue) const override;
    bool SetAnimatedInstancePropertyValue(Qt3DSDMSlideHandle inSlide,
                                                  Qt3DSDMInstanceHandle inInstance,
                                                  Qt3DSDMPropertyHandle inProperty,
                                                  const SValue &inValue) override;
    //====================================================================

    void SetConsumer(TTransactionConsumerPtr inConsumer) override;

    void setRefreshCallback(TRefreshCallbackFunc func) override;

private:
    void OnAnimationDeleted(Qt3DSDMAnimationHandle inAnimation);

    Qt3DSDMSlideHandle GetApplicableGraphAndSlide(Qt3DSDMInstanceHandle inInstance,
                                                 Qt3DSDMPropertyHandle inProperty,
                                                 const SValue &inValue);

    void OverrideChannelIfAnimated(Qt3DSDMSlideHandle inSlide, Qt3DSDMInstanceHandle inInstance,
                                   Qt3DSDMPropertyHandle inProperty, size_t inIndex, float inSeconds,
                                   bool &ioAnimated, SValue &outValue) const;
};
}

#endif