summaryrefslogtreecommitdiffstats
path: root/src/dm/systems/cores/SimpleSlideGraphCore.h
blob: 484d6750c790552f4fdce8de39f41e25c450f4f3 (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 SLIDEGRAPHCOREH
#define SLIDEGRAPHCOREH
#include "Qt3DSDMStringTable.h"
#include "Qt3DSDMSlideGraphCore.h"
#include "HandleSystemBase.h"
#include "Qt3DSDMErrors.h"

namespace qt3dsdm {
using namespace std;
struct SSlideGraph : public CHandleObject
{
    SSlideGraph()
        : m_Root(0)
        , m_ActiveSlide(0)
    {
    }
    SSlideGraph(int inHandle, int inSlideRoot)
        : CHandleObject(inHandle)
        , m_Root(inSlideRoot)
        , m_ActiveSlide(0)
    {
    }
    Qt3DSDMSlideHandle m_Root;
    Qt3DSDMSlideHandle m_ActiveSlide;

    static const EHandleObjectType s_Type = CHandleObject::EHandleObjectTypeSSlideGraph;
    EHandleObjectType GetType() override { return s_Type; }
};

class CSimpleSlideGraphCore : public CHandleBase, public ISlideGraphCore
{
    TStringTablePtr m_StringTable;
    typedef std::unordered_map<Qt3DSDMInstanceHandle,
                                 pair<Qt3DSDMSlideGraphHandle, Qt3DSDMSlideHandle>, std::hash<int>>
        TInstanceToGraphMap;
    typedef std::unordered_map<Qt3DSDMSlideGraphHandle, TSlideInstancePairList, std::hash<int>>
        TGraphToInstanceMap;

    TInstanceToGraphMap m_InstanceToGraph;
    TGraphToInstanceMap m_GraphToInstances;

public:
    CSimpleSlideGraphCore(TStringTablePtr strTable = TStringTablePtr())
        : m_StringTable(strTable)
    {
    }
    TStringTablePtr GetStringTablePtr() { return m_StringTable; }
    /**
     *	A slide graph is used to associate a set of instances to a set of slides.
     *	This allows rapid lookup of properties, as an implementation of these.
     *	There are a few assumptions here.  First is that a given slide can be a member
     *	of one and only one graph (i.e. it does not derive from another slide outside of the graph).
     *	Second is that an instance is a member of one and only one graph.
     */
    Qt3DSDMSlideGraphHandle CreateSlideGraph(Qt3DSDMSlideHandle inRoot) override;
    Qt3DSDMSlideHandle GetGraphRoot(Qt3DSDMSlideGraphHandle inGraph) const override;
    Qt3DSDMSlideGraphHandle GetSlideGraph(Qt3DSDMSlideHandle inSlide) const override;
    void GetSlideGraphs(TSlideGraphHandleList &outGraphs) const override;
    void DeleteSlideGraph(Qt3DSDMSlideGraphHandle inHandle) override;

    /**
     *	Associate a given instance handle with a given graph.  This will ensure that property
     *lookups
     *	will travel through this graph before they hit the main data core.  Instances may be
     *associated
     *	with a sub-slide of a given graph, not just the root.  An instance associated with the root
     *is
     *	implicitly associated with any root-derived slides.
     */
    void AssociateInstance(Qt3DSDMSlideGraphHandle inSlideGraph, Qt3DSDMSlideHandle inSlide,
                           Qt3DSDMInstanceHandle inInstance) override;
    void GetAssociatedInstances(Qt3DSDMSlideGraphHandle inSlideGraph,
                                TSlideInstancePairList &outAssociations) const override;
    TGraphSlidePair GetAssociatedGraph(Qt3DSDMInstanceHandle inInstance) const override;
    void DissociateInstance(Qt3DSDMInstanceHandle inInstance) override;

    /**
     *	All graphs always have an active slide.  This is assumed to be the root right off the bat.
     */
    void SetGraphActiveSlide(Qt3DSDMSlideGraphHandle inGraph, Qt3DSDMSlideHandle inSlide) override;
    Qt3DSDMSlideHandle GetGraphActiveSlide(Qt3DSDMSlideGraphHandle inGraph) const override;

    bool HandleValid(int inHandle) const override;

    Qt3DSDMSlideGraphHandle CreateSlideGraphWithHandle(int inHandle, Qt3DSDMSlideHandle inRoot);

    static SSlideGraph *GetSlideGraphNF(int inHandle, THandleObjectMap &inObjects)
    {
        return const_cast<SSlideGraph *>(
            GetSlideGraphNF(inHandle, static_cast<const THandleObjectMap &>(inObjects)));
    }

    static const SSlideGraph *GetSlideGraphNF(int inHandle, const THandleObjectMap &inObjects)
    {
        const SSlideGraph *theSlide = GetHandleObject<SSlideGraph>(inHandle, inObjects);
        if (theSlide)
            return theSlide;
        throw SlideGraphNotFound(L"");
    }
};

typedef std::shared_ptr<CSimpleSlideGraphCore> TSimpleSlideGraphCorePtr;
}

#endif