summaryrefslogtreecommitdiffstats
path: root/src/dm/systems/cores/ActionCoreProducer.cpp
blob: c262c239c45ec920da6185de20c48cc3bcaf3da0 (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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/****************************************************************************
**
** 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$
**
****************************************************************************/
#include "Qt3DSDMPrefix.h"
#include "ActionCoreProducer.h"
#include "HandleSystemTransactions.h"
#include "VectorTransactions.h"
#include "SignalsImpl.h"

using namespace std;

namespace qt3dsdm {

Qt3DSDMActionHandle CActionCoreProducer::CreateAction(Qt3DSDMInstanceHandle inInstance,
                                                     Qt3DSDMSlideHandle inSlide,
                                                     Qt3DSDMInstanceHandle inOwner,
                                                     SLong4 inTriggerTargetObjects)
{
    Qt3DSDMActionHandle retval =
        m_Data->CreateAction(inInstance, inSlide, inOwner, inTriggerTargetObjects);
    CREATE_HANDLE_CREATE_TRANSACTION(m_Consumer, retval, m_Data->m_Objects);
    return retval;
}

void CActionCoreProducer::DeleteAction(Qt3DSDMActionHandle inAction,
                                       Qt3DSDMInstanceHandle &outInstance)
{
    // Ensure action exists
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    CREATE_HANDLE_DELETE_TRANSACTION(m_Consumer, inAction, m_Data->m_Objects);
    do_all(theAction->m_ActionInfo.m_HandlerArgs,
           std::bind(DoCreateHandleDeleteTransaction, __FILE__, __LINE__, m_Consumer,
                     std::placeholders::_1, std::ref(m_Data->m_Objects)));
    m_Data->DeleteAction(inAction, outInstance);
}

const SActionInfo &CActionCoreProducer::GetActionInfo(Qt3DSDMActionHandle inAction) const
{
    return m_Data->GetActionInfo(inAction);
}

void CActionCoreProducer::GetActions(Qt3DSDMSlideHandle inSlide, Qt3DSDMInstanceHandle inOwner,
                                     TActionHandleList &outActions) const
{
    return m_Data->GetActions(inSlide, inOwner, outActions);
}

void CActionCoreProducer::GetActions(Qt3DSDMSlideHandle inSlide, TActionHandleList &outActions) const
{
    return m_Data->GetActions(inSlide, outActions);
}

void CActionCoreProducer::GetActions(Qt3DSDMInstanceHandle inOwner,
                                     TActionHandleList &outActions) const
{
    return m_Data->GetActions(inOwner, outActions);
}

void CActionCoreProducer::GetActions(TActionHandleList &outActions) const
{
    return m_Data->GetActions(outActions);
}

Qt3DSDMInstanceHandle CActionCoreProducer::GetActionInstance(Qt3DSDMActionHandle inAction) const
{
    return m_Data->GetActionInstance(inAction);
}

Qt3DSDMActionHandle
CActionCoreProducer::GetActionByInstance(Qt3DSDMInstanceHandle inActionInstance) const
{
    return m_Data->GetActionByInstance(inActionInstance);
}

void CActionCoreProducer::SetTriggerObject(Qt3DSDMActionHandle inAction,
                                           const SObjectRefType &inTriggerObject)
{
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    if (m_Consumer) {
        m_Consumer->OnTransaction(TTransactionPtr(CREATE_GENERIC_TRANSACTION(
            std::bind(&CSimpleActionCore::SetTriggerObject, m_Data, inAction, inTriggerObject),
            std::bind(&CSimpleActionCore::SetTriggerObject, m_Data, inAction,
                        theAction->m_ActionInfo.m_TriggerObject))));
    }
    m_Data->SetTriggerObject(inAction, inTriggerObject);
    GetSignalSender()->SendTriggerObjectSet(inAction, theAction->m_ActionInfo.m_TriggerObject);
}

void CActionCoreProducer::SetTargetObject(Qt3DSDMActionHandle inAction,
                                          const SObjectRefType &inTargetObject)
{
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    if (m_Consumer) {
        m_Consumer->OnTransaction(TTransactionPtr(CREATE_GENERIC_TRANSACTION(
            std::bind(&CSimpleActionCore::SetTargetObject, m_Data, inAction, inTargetObject),
            std::bind(&CSimpleActionCore::SetTargetObject, m_Data, inAction,
                        theAction->m_ActionInfo.m_TargetObject))));
    }
    m_Data->SetTargetObject(inAction, inTargetObject);
    GetSignalSender()->SendTargetObjectSet(inAction, theAction->m_ActionInfo.m_TargetObject);
}

void CActionCoreProducer::SetEvent(Qt3DSDMActionHandle inAction, const wstring &inEventHandle)
{
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    if (m_Consumer) {
        m_Consumer->OnTransaction(TTransactionPtr(CREATE_GENERIC_TRANSACTION(
            std::bind(&CSimpleActionCore::SetEvent, m_Data, inAction, inEventHandle),
            std::bind(&CSimpleActionCore::SetEvent, m_Data, inAction,
                        theAction->m_ActionInfo.m_Event))));
    }
    m_Data->SetEvent(inAction, inEventHandle);
    GetSignalSender()->SendEventSet(inAction, inEventHandle);
}

void CActionCoreProducer::SetHandler(Qt3DSDMActionHandle inAction, const wstring &inHandlerHandle)
{
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    if (m_Consumer) {
        m_Consumer->OnTransaction(TTransactionPtr(CREATE_GENERIC_TRANSACTION(
            std::bind(&CSimpleActionCore::SetHandler, m_Data, inAction, inHandlerHandle),
            std::bind(&CSimpleActionCore::SetHandler, m_Data, inAction,
                        theAction->m_ActionInfo.m_Handler))));
    }
    m_Data->SetHandler(inAction, inHandlerHandle);
    GetSignalSender()->SendHandlerSet(inAction, inHandlerHandle);
}

Qt3DSDMHandlerArgHandle CActionCoreProducer::AddHandlerArgument(Qt3DSDMActionHandle inAction,
                                                               const TCharStr &inName,
                                                               HandlerArgumentType::Value inArgType,
                                                               DataModelDataType::Value inValueType)
{
    Qt3DSDMHandlerArgHandle retval =
        m_Data->AddHandlerArgument(inAction, inName, inArgType, inValueType);
    SAction *theAction = CSimpleActionCore::GetActionNF(inAction, m_Data->m_Objects);
    CreateVecInsertTransaction<Qt3DSDMHandlerArgHandle>(__FILE__, __LINE__, m_Consumer, retval,
                                                       theAction->m_ActionInfo.m_HandlerArgs);
    CREATE_HANDLE_CREATE_TRANSACTION(m_Consumer, retval, m_Data->m_Objects);
    GetSignalSender()->SendHandlerArgumentAdded(inAction, retval, inName, inArgType, inValueType);
    return retval;
}

void CActionCoreProducer::RemoveHandlerArgument(Qt3DSDMHandlerArgHandle inHandlerArgument)
{
    SHandlerArgument *theHandlerArgument =
        CSimpleActionCore::GetHandlerArgumentNF(inHandlerArgument, m_Data->m_Objects);
    SAction *theAction = CSimpleActionCore::GetActionNF(
        theHandlerArgument->m_HandlerArgInfo.m_Action, m_Data->m_Objects);
    if (exists(theAction->m_ActionInfo.m_HandlerArgs,
               std::bind(equal_to<Qt3DSDMHandlerArgHandle>(), inHandlerArgument,
                         std::placeholders::_1))) {
        CreateVecEraseTransaction<Qt3DSDMHandlerArgHandle>(__FILE__, __LINE__, m_Consumer,
                                                          inHandlerArgument,
                                                          theAction->m_ActionInfo.m_HandlerArgs);
        CREATE_HANDLE_DELETE_TRANSACTION(m_Consumer, inHandlerArgument, m_Data->m_Objects);
    }
    m_Data->RemoveHandlerArgument(inHandlerArgument);
    GetSignalSender()->SendHandlerArgumentRemoved(theAction->m_Handle, theHandlerArgument->m_Handle,
                                                  theHandlerArgument->m_HandlerArgInfo.m_Name,
                                                  theHandlerArgument->m_HandlerArgInfo.m_ArgType,
                                                  theHandlerArgument->m_HandlerArgInfo.m_ValueType);
}

const SHandlerArgumentInfo &
CActionCoreProducer::GetHandlerArgumentInfo(Qt3DSDMHandlerArgHandle inHandlerArgument) const
{
    return m_Data->GetHandlerArgumentInfo(inHandlerArgument);
}

void CActionCoreProducer::GetHandlerArguments(Qt3DSDMActionHandle inAction,
                                              THandlerArgHandleList &outHandlerArguments) const
{
    return m_Data->GetHandlerArguments(inAction, outHandlerArguments);
}

void CActionCoreProducer::GetHandlerArgumentValue(Qt3DSDMHandlerArgHandle inHandlerArgument,
                                                  SValue &outValue) const
{
    return m_Data->GetHandlerArgumentValue(inHandlerArgument, outValue);
}

void CActionCoreProducer::SetHandlerArgumentValue(Qt3DSDMHandlerArgHandle inHandlerArgument,
                                                  const SValue &inValue)
{
    SHandlerArgument *theHandlerArgument =
        CSimpleActionCore::GetHandlerArgumentNF(inHandlerArgument, m_Data->m_Objects);
    if (m_Consumer) {
        m_Consumer->OnTransaction(TTransactionPtr(CREATE_GENERIC_TRANSACTION(
            std::bind(&CSimpleActionCore::SetHandlerArgumentValue, m_Data, inHandlerArgument,
                        inValue),
            std::bind(&CSimpleActionCore::SetHandlerArgumentValue, m_Data, inHandlerArgument,
                        theHandlerArgument->m_HandlerArgInfo.m_Value))));
    }
    m_Data->SetHandlerArgumentValue(inHandlerArgument, inValue);
    GetSignalSender()->SendHandlerArgumentValueSet(inHandlerArgument, inValue);
}

// CHandleBase
bool CActionCoreProducer::HandleValid(int inHandle) const
{
    return m_Data->HandleValid(inHandle);
}

// ITransactionProducer implementation
void CActionCoreProducer::SetConsumer(TTransactionConsumerPtr inConsumer)
{
    m_Consumer = inConsumer;
}

TSignalConnectionPtr CActionCoreProducer::ConnectTriggerObjectSet(
    const std::function<void(Qt3DSDMActionHandle, SObjectRefType &)> &inCallback)
{
    return GetSignalProvider()->ConnectTriggerObjectSet(inCallback);
}
TSignalConnectionPtr CActionCoreProducer::ConnectTargetObjectSet(
    const std::function<void(Qt3DSDMActionHandle, SObjectRefType &)> &inCallback)
{
    return GetSignalProvider()->ConnectTargetObjectSet(inCallback);
}
TSignalConnectionPtr CActionCoreProducer::ConnectEventSet(
    const std::function<void(Qt3DSDMActionHandle, const wstring &)> &inCallback)
{
    return GetSignalProvider()->ConnectEventSet(inCallback);
}
TSignalConnectionPtr CActionCoreProducer::ConnectHandlerSet(
    const std::function<void(Qt3DSDMActionHandle, const wstring &)> &inCallback)
{
    return GetSignalProvider()->ConnectHandlerSet(inCallback);
}

TSignalConnectionPtr CActionCoreProducer::ConnectHandlerArgumentAdded(
    const std::function<void(Qt3DSDMActionHandle, Qt3DSDMHandlerArgHandle, const TCharStr &,
                               HandlerArgumentType::Value, DataModelDataType::Value)> &inCallback)
{
    return GetSignalProvider()->ConnectHandlerArgumentAdded(inCallback);
}
TSignalConnectionPtr CActionCoreProducer::ConnectHandlerArgumentRemoved(
    const std::function<void(Qt3DSDMActionHandle, Qt3DSDMHandlerArgHandle, const TCharStr &,
                               HandlerArgumentType::Value, DataModelDataType::Value)> &inCallback)
{
    return GetSignalProvider()->ConnectHandlerArgumentRemoved(inCallback);
}
TSignalConnectionPtr CActionCoreProducer::ConnectHandlerArgumentValueSet(
    const std::function<void(Qt3DSDMHandlerArgHandle, const SValue &)> &inCallback)
{
    return GetSignalProvider()->ConnectHandlerArgumentValueSet(inCallback);
}

void CActionCoreProducer::InitSignaller()
{
    m_Signaller = CreateActionCoreSignaller();
}

IActionCoreSignalProvider *CActionCoreProducer::GetSignalProvider()
{
    return dynamic_cast<IActionCoreSignalProvider *>(m_Signaller.get());
}

IActionCoreSignalSender *CActionCoreProducer::GetSignalSender()
{
    return dynamic_cast<IActionCoreSignalSender *>(m_Signaller.get());
}
}