summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Client/Code/Core/Doc/IDocumentReader.h
blob: d0f563aaceec65883c9024dda3bab9f57d8c891c (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
290
291
292
293
294
/****************************************************************************
**
** Copyright (C) 1999-2005 Anark 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 IDOCUMENTREADERH
#define IDOCUMENTREADERH
#include "Qt3DSDMDataTypes.h"
#include "foundation/Qt3DSOption.h"
#include <vector>
#include <utility>
#include "StudioObjectTypes.h"
#include "Qt3DSDMComposerTypeDefinitions.h"
#include "Qt3DSFileTools.h"

namespace qt3dsdm {
class IDOMWriter;
class IDOMReader;
struct SGuideInfo;
}

namespace qt3dsimp {
class ITranslator;
struct STranslationLog;
}

namespace qt3ds {
class NVFoundationBase;
}

namespace Q3DStudio {
using std::shared_ptr;

typedef std::vector<std::pair<qt3dsdm::Qt3DSDMSlideHandle, qt3dsdm::Qt3DSDMInstanceHandle>>
    TSlideInstanceList;
typedef std::vector<std::pair<qt3dsdm::Qt3DSDMSlideHandle, Q3DStudio::CString>> TSlideStringList;
typedef std::unordered_map<const wchar_t *, TSlideInstanceList> TCharPtrToSlideInstanceMap;
using qt3ds::foundation::Option;
using qt3dsdm::Qt3DSDMInstanceHandle;
using qt3dsdm::Qt3DSDMPropertyHandle;
using qt3dsdm::Qt3DSDMSlideHandle;
using qt3dsdm::Qt3DSDMKeyframeHandle;
using qt3dsdm::Qt3DSDMActionHandle;
using qt3dsdm::Qt3DSDMAnimationHandle;
using qt3dsdm::SValue;
using qt3dsdm::IDOMReader;
using qt3dsdm::IDOMWriter;

// Reader class to read complex information from the document.  Encapsulates the various DataModel
// subsystems
// Implemented in DocumentEditor.cpp
class IDocumentReader
{
protected:
    virtual ~IDocumentReader() {}
public:
    typedef Qt3DSDMInstanceHandle TInstanceHandle;
    typedef Qt3DSDMPropertyHandle TPropertyHandle;
    typedef Qt3DSDMSlideHandle TSlideHandle;
    typedef Qt3DSDMKeyframeHandle TKeyframeHandle;
    typedef qt3dsdm::SValue SValue;
    typedef std::pair<TSlideHandle, SValue> TSlideValuePair;
    typedef std::vector<TSlideValuePair> TSlideValuePairList;
    typedef std::vector<TSlideHandle> TSlideList;
    typedef std::vector<TInstanceHandle> TInstanceList;
    typedef std::vector<TPropertyHandle> TPropertyList;

    // Returns true if this handle points to a valid instance.
    virtual bool IsInstance(TInstanceHandle inInstance) const = 0;
    virtual bool IsCurrentlyActive(TInstanceHandle inInstance) const = 0;
    // Find a property on an instance by name.  Searches derivation parents as well
    virtual TPropertyHandle FindProperty(TInstanceHandle instance, const wchar_t *inName) const = 0;
    // Get the instance property value by going through the current slide
    // This will convert image properties to source paths.  If this is not desired, then use
    virtual Option<SValue> GetInstancePropertyValue(TInstanceHandle instance,
                                                    TPropertyHandle inProperty) const = 0;
    // This will not convert image properties to source paths, they will come across as guids.
    virtual Option<SValue> GetRawInstancePropertyValue(TInstanceHandle instance,
                                                       TPropertyHandle inProperty) const = 0;
    // Get an image instance by dereferencing this property pair
    virtual TInstanceHandle GetImageInstanceForProperty(TInstanceHandle instance,
                                                        TPropertyHandle inProperty) const = 0;
    // Get the property value for this instance from this slide without doing normal slide lookup.
    // If inSlide isn't valid, returns the property value for this instance directly from the data
    // core.
    virtual Option<SValue> GetSpecificInstancePropertyValue(TSlideHandle inSlide,
                                                            TInstanceHandle instance,
                                                            TPropertyHandle inProperty) const = 0;

    virtual Q3DStudio::CString GetObjectTypeName(TInstanceHandle instance) const = 0;

    virtual CString GetName(Qt3DSDMInstanceHandle inInstance) const = 0;
    virtual TInstanceHandle GetFirstBaseClass(Qt3DSDMInstanceHandle inInstance) const = 0;
    virtual CString GetSourcePath(Qt3DSDMInstanceHandle inInstance) const = 0;

    template <typename TDataType>
    inline Option<TDataType> GetTypedInstancePropertyValue(TInstanceHandle instance,
                                                           TPropertyHandle inProperty);
    // Get every property value associated with this instance, from the data core up.  The
    // associated slide will be NULL for the
    // data core.
    virtual void GetAllPropertyValues(TInstanceHandle instance, TPropertyHandle inProperty,
                                      TSlideValuePairList &outList) const = 0;
    // Get the slide this instance was created under
    virtual TSlideHandle GetAssociatedSlide(TInstanceHandle inInstance) const = 0;
    // Is this a master slide?
    virtual bool IsMasterSlide(TSlideHandle inSlide) const = 0;
    // Get the component this instance was created under.
    virtual TInstanceHandle GetAssociatedComponent(TInstanceHandle inInstance) const = 0;
    // Get the slide that is currently active for this instance in the UI.
    virtual TSlideHandle GetActiveSlide(TInstanceHandle inInstance) const = 0;
    // Return the active slide for the given component.
    virtual TSlideHandle GetComponentActiveSlide(TInstanceHandle inInstance) const = 0;
    // Get the component who owns a given slide.
    virtual TInstanceHandle GetComponentForSlide(TSlideHandle inSlide) const = 0;
    // Get every slide, starting with the associated slide (the master slide) that
    // this instance is associated with.  So the first slide will be the slide this
    // instance was created under, then next slides will be that associated slide's
    // children.
    virtual void GetAllAssociatedSlides(TInstanceHandle inInstance, TSlideList &outList) const = 0;

    // Get all the source paths for this instance.  If the slide is zero, this means the source
    // path is set in the data core.  Else this indicates exactly which slide the source path is
    // set under.
    virtual void GetAllSourcePaths(TInstanceHandle inInstance,
                                   TSlideStringList &outPaths) const = 0;

    // Get a map from string table string (datacore.GetStringTable().RegisterStr()) to
    // a list of slide/instance pairs that indicate, for a given source path, which instances
    // link to that source path and under which slide.
    // Pass in true if you want the map keys to include the identifiers (#1, #2).
    virtual void GetSourcePathToInstanceMap(TCharPtrToSlideInstanceMap &outInstanceMap,
                                            bool inIncludeIdentifiers = true) const = 0;
    // Get a map from string table string to list of slide/instance pairs that indicates, for a
    // given source path,
    // which instances link to that source path under which slide.
    virtual void GetImportPathToInstanceMap(TCharPtrToSlideInstanceMap &outInstanceMap) const = 0;

    // Return true if a property is linked (exists only on the associated slide).
    virtual bool CanPropertyBeLinked(TInstanceHandle inInstance,
                                     TPropertyHandle inProperty) const = 0;
    virtual bool IsPropertyLinked(TInstanceHandle inInstance, TPropertyHandle inProperty) const = 0;

    // If this property is linked, return the associated slide for the instance.
    // If this property is unlinked, return the active slide.
    virtual TSlideHandle GetSlideForProperty(TInstanceHandle inInstance,
                                             TPropertyHandle inProperty) const = 0;
    // Return true if this instance is an imported instance.
    virtual bool IsImported(TInstanceHandle inInstance) const = 0;
    virtual CString GetImportId(TInstanceHandle inInstance) const = 0;
    virtual CString GetFileId(TInstanceHandle inInstance) const = 0;

    // Return (start,end), inclusive, that represent this instance's lifetime.
    virtual std::pair<long, long> GetTimeRange(TInstanceHandle instance) const = 0;
    virtual std::pair<long, long> GetTimeRangeInSlide(Qt3DSDMSlideHandle inSlide,
                                                      TInstanceHandle instance) const = 0;
    // Get the GUID for a given instance.
    virtual qt3dsdm::SLong4 GetGuidForInstance(TInstanceHandle instance) const = 0;
    virtual TInstanceHandle GetInstanceForGuid(const qt3dsdm::SLong4 &inGuid) const = 0;
    virtual TInstanceHandle
    GetInstanceForObjectRef(TInstanceHandle inRootInstance,
                            const qt3dsdm::SObjectRefType &inReference) const = 0;
    // Get the scene graph parent of this instance
    virtual TInstanceHandle GetParent(TInstanceHandle child) const = 0;
    // Get all the children if this instance in this slide.  If the slide is invalid,
    // the get all the children of this parent in all slides.
    virtual void GetChildren(TSlideHandle inSlide, TInstanceHandle inParent,
                             TInstanceList &outChildren) const = 0;
    // Returns true if this instance is anywhere the scene graph
    virtual bool IsInSceneGraph(TInstanceHandle child) const = 0;

    virtual bool IsPathExternalizeable(TInstanceHandle path) const = 0;
    virtual bool IsPathInternalizeable(TInstanceHandle path) const = 0;

    virtual bool AnimationExists(TSlideHandle inSlide, TInstanceHandle instance,
                                 const wchar_t *propName, long subIndex) = 0;
    virtual bool IsAnimationArtistEdited(TSlideHandle inSlide, TInstanceHandle instance,
                                         const wchar_t *propName, long subIndex) = 0;

    virtual qt3dsdm::TGuideHandleList GetGuides() const = 0;
    virtual qt3dsdm::SGuideInfo GetGuideInfo(qt3dsdm::Qt3DSDMGuideHandle inGuide) const = 0;
    virtual bool IsGuideValid(qt3dsdm::Qt3DSDMGuideHandle inGuide) const = 0;
    virtual bool AreGuidesEditable() const = 0;
    // This can be done outside a transaction, hence it is an operation on the reader
    // not on the editor.
    virtual void SetGuidesEditable(bool inEditable) = 0;

    // Given the active slide on the document (which we query) and an instance,
    // produce a temporary file (Qt3DSFile::GetTemporaryFile) and serialize this object
    // to that temporary file.
    virtual CFilePath CopySceneGraphObjects(qt3dsdm::TInstanceHandleList inInstances) = 0;

    CFilePath CopySceneGraphObject(Qt3DSDMInstanceHandle inInstance)
    {
        qt3dsdm::TInstanceHandleList theInstances;
        theInstances.push_back(inInstance);
        return CopySceneGraphObjects(theInstances);
    }

    // Copy the object just to a DOM representation, don't serialize to file.
    virtual std::shared_ptr<qt3dsdm::IDOMReader>
    CopySceneGraphObjectToMemory(Qt3DSDMInstanceHandle inInstance) = 0;

    virtual CFilePath CopyAction(Qt3DSDMActionHandle inAction, Qt3DSDMSlideHandle inSlide) = 0;

    virtual void ParseSourcePathsOutOfEffectFile(const QString &inFile,
                                                 const QString &projectPath,
                                                 bool recurseSourceMaterial,
                                                 QHash<QString, QString> &outPathMap,
                                                 QSet<QString> &outPropertyMap) = 0;

    virtual Q3DStudio::CString GetCustomMaterialName(const Q3DStudio::CString &inFullPathToFile) const = 0;
    virtual void getMaterialInfo(const QString &inFullPathToFile,
                                 QString &outName, QMap<QString, QString> &outValues,
                                 QMap<QString, QMap<QString, QString>> &outTextureValues) = 0;

    // Must not be a master slide.  Used during duplicate slide.
    virtual std::shared_ptr<qt3dsdm::IDOMReader> CopySlide(Qt3DSDMSlideHandle inSlide) = 0;

    virtual qt3ds::NVFoundationBase &GetFoundation() = 0;
};

template <typename TDataType>
inline Option<TDataType> IDocumentReader::GetTypedInstancePropertyValue(TInstanceHandle instance,
                                                                        TPropertyHandle inProperty)
{
    Option<SValue> theValue = GetInstancePropertyValue(instance, inProperty);
    if (theValue.isEmpty())
        return qt3ds::foundation::Empty();
    return qt3dsdm::get<TDataType>(*theValue);
}

// Helper function needed by a few objects
inline EStudioObjectType GetStudioObjectType(qt3dsdm::ComposerObjectTypes::Enum inType)
{
    using namespace qt3dsdm;
    switch (inType) {
    case ComposerObjectTypes::Scene:
        return OBJTYPE_SCENE;
    case ComposerObjectTypes::Layer:
        return OBJTYPE_LAYER;
    case ComposerObjectTypes::Behavior:
        return OBJTYPE_BEHAVIOR;
    case ComposerObjectTypes::Material:
        return OBJTYPE_MATERIAL;
    case ComposerObjectTypes::Camera:
        return OBJTYPE_CAMERA;
    case ComposerObjectTypes::Light:
        return OBJTYPE_LIGHT;
    case ComposerObjectTypes::Model:
        return OBJTYPE_MODEL;
    case ComposerObjectTypes::Group:
        return OBJTYPE_GROUP;
    case ComposerObjectTypes::Image:
        return OBJTYPE_IMAGE;
    case ComposerObjectTypes::Text:
        return OBJTYPE_TEXT;
    case ComposerObjectTypes::Component:
        return OBJTYPE_COMPONENT;
    case ComposerObjectTypes::Effect:
        return OBJTYPE_EFFECT;
    case ComposerObjectTypes::Path:
        return OBJTYPE_PATH;
    default: ;
    }
    return OBJTYPE_UNKNOWN;
}
}

#endif