summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/uipparser/Qt3DSUIPParserActionHelper.h
blob: 3d9d44ceb0d0fbce122596cc4f56f830b456b74c (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
/****************************************************************************
**
** 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$
** 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 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** 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

//==============================================================================
//	Includes
//==============================================================================
#include "Qt3DSUIPParserImpl.h"

namespace qt3ds {
namespace runtime {
    class IParametersSystem;
}
}
//==============================================================================
//	Namespace
//==============================================================================
namespace Q3DStudio {
using qt3ds::runtime::IParametersSystem;
//==============================================================================
//	Forwards
//==============================================================================

//==============================================================================
/**
 *	@class	CUIPParserActionHelper
 *	@brief	Class for parsing UIP file - Action
 */
class CUIPParserActionHelper
{
    //==============================================================================
    //	Fields
    //==============================================================================
protected:
    CUIPParserImpl *m_UIPParser;
    CUIPParserObjectRefHelper *m_ObjRefHelper;
    IRuntimeMetaData &m_MetaData; ///< Reference to Metadata

    typedef eastl::map<eastl::string, INT32> TActionIdentifierMap; ///< Mapping of the string that
                                                                   ///uniquely identify the action
                                                                   ///to the index created
    TActionIdentifierMap m_ActionIdentifierMap;

    struct SHandlerArgumentInfo
    {
        eastl::string m_Name;
        eastl::string m_Value;

        SHandlerArgumentInfo() {}
    };
    typedef eastl::vector<SHandlerArgumentInfo> THandlerArguments; ///< List of handler arguments
    struct SActionInfo
    {
        eastl::string m_Id;

        // Where the action is added to
        eastl::string m_Owner; // Absolute path of owner object

        // Trigger object
        eastl::string m_TriggerObject; // Absolute path of trigger object
        eastl::string m_Event;

        // Target object
        eastl::string m_TargetObject; // Absolute path of target object
        eastl::string m_Handler;
        THandlerArguments m_HandlerArgs;

        SActionInfo() {}
    };
    typedef eastl::map<eastl::string, SActionInfo> TActionMap; ///< Map of action id and action info

    TActionMap m_ActionMap;

    // There are 2 tables involved:
    // 1. The Listener-To-Events tables - multimap of each listener to all events it is listening to
    // 2. The Listener-Event-To-Actions table - multimap of each listener-event pair to all actions
    // it triggers
    // note: The struct for Action is a pair of EventAction node and its owner
    struct SListenerEventNamePair
    {
        eastl::string m_Listener;
        eastl::string m_Event;

        SListenerEventNamePair(eastl::string inListener, const eastl::string &inEvent)
            : m_Listener(inListener)
            , m_Event(inEvent)
        {
        }

        bool operator<(const SListenerEventNamePair &inListenerEventPair) const
        {
            if (m_Listener == inListenerEventPair.m_Listener)
                return m_Event < inListenerEventPair.m_Event;
            return m_Listener < inListenerEventPair.m_Listener;
        }
    };

    typedef eastl::pair<eastl::string, eastl::string>
        TEventActionOwnerPair; ///< One listener(source) can listen to multiple events
    typedef eastl::multimap<eastl::string, eastl::string>
        TListenerEventsNameMap; ///< One listener(source)-event pair can trigger multiple actions
    typedef eastl::multimap<SListenerEventNamePair, TEventActionOwnerPair> TListenerEventActionsMap;

    TListenerEventsNameMap m_ListenerEventsNameMap;
    TListenerEventActionsMap m_ListenerEventActionsMap;

    //==============================================================================
    //	Methods
    //==============================================================================
public: // Construction
    CUIPParserActionHelper(CUIPParserImpl *inUIPParser, CUIPParserObjectRefHelper *inObjRefHelper,
                           IRuntimeMetaData &inMetaData);
    virtual ~CUIPParserActionHelper();

public:
    void CacheAction(qt3dsdm::IDOMReader &inReader, const char8_t *inOwnerId);
    void BuildActions(IPresentation &inPresentation);
    void GetActionSectionCount(CUIPParserImpl::SActionSectionCount &outActionCount);
    INT32 GetActionCount(const eastl::string &inActionId);
    INT32 GetActionIndex(const eastl::string &inActionId);

protected: // Action helper
    void AddListenerEventPair(eastl::string inListener, const eastl::string &inEventName);
    void CacheHandlerArguments(qt3dsdm::IDOMReader &inReader, SActionInfo &inAction);
    void BuildAction(TElement &inElement, UINT32 inEventName, IPresentation &inPresentation,
                     const eastl::string &inActionId);
    INT32 GetActionCount(const eastl::string &inActionId, INT32 &outStringAttrCount,
                         INT32 &outCustomParamCount);
    bool IsCustomHandler(const SActionInfo &inAction);
    void GetHandlerArgumentType(const SActionInfo &inAction, int inArgumentIndex,
                                ERuntimeDataModelDataType &outType,
                                ERuntimeAdditionalMetaDataType &outAdditionalType);
    void GetCustomActionParametersCount(ERuntimeDataModelDataType inDataType,
                                        ERuntimeAdditionalMetaDataType inAdditionalType,
                                        INT32 &outStringAttrCount, INT32 &outCustomParamCount);
    void ExportCustomActionParameters(IPresentation &inPresentation,
                                      IParametersSystem &inParamSystem, QT3DSI32 inParamGroup,
                                      const char *inDataValue, ERuntimeDataModelDataType inDataType,
                                      ERuntimeAdditionalMetaDataType inAdditionalType);

    inline SElement *GetElement(const eastl::string &inElementName);
};

} // namespace Q3DStudio