Plasma Engine  2.0
Loading...
Searching...
No Matches
Document.h
1#pragma once
2
3#include <Foundation/Communication/Event.h>
4#include <Foundation/Logging/Log.h>
5#include <Foundation/Strings/String.h>
6#include <Foundation/Threading/Implementation/TaskSystemDeclarations.h>
7#include <Foundation/Types/Status.h>
8#include <Foundation/Types/UniquePtr.h>
9#include <ToolsFoundation/CommandHistory/CommandHistory.h>
10#include <ToolsFoundation/Document/Implementation/Declarations.h>
11#include <ToolsFoundation/Object/ObjectMetaData.h>
12#include <ToolsFoundation/Selection/SelectionManager.h>
13#include <ToolsFoundation/ToolsFoundationDLL.h>
14
19
20struct PL_TOOLSFOUNDATION_DLL plObjectAccessorChangeEvent
21{
22 plDocument* m_pDocument;
23 plObjectAccessorBase* m_pOldObjectAccessor;
24 plObjectAccessorBase* m_pNewObjectAccessor;
25};
26
27class PL_TOOLSFOUNDATION_DLL plDocumentObjectMetaData : public plReflectedClass
28{
29 PL_ADD_DYNAMIC_REFLECTION(plDocumentObjectMetaData, plReflectedClass);
30
31public:
32 enum ModifiedFlags : unsigned int
33 {
34 HiddenFlag = PL_BIT(0),
35 PrefabFlag = PL_BIT(1),
36
37 AllFlags = 0xFFFFFFFF
38 };
39
40 plDocumentObjectMetaData() { m_bHidden = false; }
41
42 bool m_bHidden;
47};
48
49enum class plManipulatorSearchStrategy
50{
51 None,
52 SelectedObject,
53 ChildrenOfSelectedObject
54};
55
56class PL_TOOLSFOUNDATION_DLL plDocument : public plReflectedClass
57{
58 PL_ADD_DYNAMIC_REFLECTION(plDocument, plReflectedClass);
59
60public:
61 plDocument(plStringView sPath, plDocumentObjectManager* pDocumentObjectManagerImpl);
62 virtual ~plDocument();
63
66
67 bool IsModified() const { return m_bModified; }
68 bool IsReadOnly() const { return m_bReadOnly; }
69 const plUuid GetGuid() const { return m_pDocumentInfo ? m_pDocumentInfo->m_DocumentID : plUuid(); }
70
71 const plDocumentObjectManager* GetObjectManager() const { return m_pObjectManager.Borrow(); }
72 plDocumentObjectManager* GetObjectManager() { return m_pObjectManager.Borrow(); }
73 plSelectionManager* GetSelectionManager() const { return m_pSelectionManager.Borrow(); }
74 plCommandHistory* GetCommandHistory() const { return m_pCommandHistory.Borrow(); }
75 virtual plObjectAccessorBase* GetObjectAccessor() const;
76
80
82 bool IsMainDocument() const { return m_pHostDocument == this; }
84 bool IsSubDocument() const { return m_pHostDocument != this; }
86 const plDocument* GetMainDocument() const { return m_pHostDocument; }
88 const plDocument* GetActiveSubDocument() const { return m_pActiveSubDocument; }
89 plDocument* GetMainDocument() { return m_pHostDocument; }
90 plDocument* GetActiveSubDocument() { return m_pActiveSubDocument; }
91
92protected:
93 plDocument* m_pHostDocument = nullptr;
94 plDocument* m_pActiveSubDocument = nullptr;
95
99
100public:
102 plStringView GetDocumentPath() const { return m_sDocumentPath; }
103
106 plStatus SaveDocument(bool bForce = false);
107 using AfterSaveCallback = plDelegate<void(plDocument*, plStatus)>;
108 plTaskGroupID SaveDocumentAsync(AfterSaveCallback callback, bool bForce = false);
109 void DocumentRenamed(plStringView sNewDocumentPath);
110
111 static plStatus ReadDocument(plStringView sDocumentPath, plUniquePtr<plAbstractObjectGraph>& ref_pHeader, plUniquePtr<plAbstractObjectGraph>& ref_pObjects,
113 static plStatus ReadAndRegisterTypes(const plAbstractObjectGraph& types);
114
115 plStatus LoadDocument() { return InternalLoadDocument(); }
116
118 void EnsureVisible();
119
120 plDocumentManager* GetDocumentManager() const { return m_pDocumentManager; }
121
122 bool HasWindowBeenRequested() const { return m_bWindowRequested; }
123
124 const plDocumentTypeDescriptor* GetDocumentTypeDescriptor() const { return m_pTypeDescriptor; }
125
128 {
129 if (m_pTypeDescriptor == nullptr)
130 {
131 // if this is a document without a type descriptor, use the RTTI type name as a fallback
132 return GetDynamicRTTI()->GetTypeName();
133 }
134
135 return m_pTypeDescriptor->m_sDocumentTypeName;
136 }
137
138 const plDocumentInfo* GetDocumentInfo() const { return m_pDocumentInfo; }
139
145 virtual bool CanEngineProcessBeRestarted() const { return true; }
146
150
152 {
153 PL_DECLARE_POD_TYPE();
154
155 plDocumentObject* m_pObject = nullptr;
156 plDocumentObject* m_pParent = nullptr;
157 plInt32 m_Index = -1;
158 };
159
163 virtual bool CopySelectedObjects(plAbstractObjectGraph& out_objectGraph, plStringBuilder& out_sMimeType) const { return false; };
164 virtual bool Paste(const plArrayPtr<PasteInfo>& info, const plAbstractObjectGraph& objectGraph, bool bAllowPickedPosition, plStringView sMimeType)
165 {
166 return false;
167 };
168
172
174 void BroadcastInterDocumentMessage(plReflectedClass* pMessage, plDocument* pSender);
175
179 virtual void OnInterDocumentMessage(plReflectedClass* pMessage, plDocument* pSender) {}
180
184
189
193
194 virtual void DeleteSelectedObjects() const;
195
196 const plSet<plString>& GetUnknownObjectTypes() const { return m_UnknownObjectTypes; }
197 plUInt32 GetUnknownObjectTypeInstances() const { return m_uiUnknownObjectTypeInstances; }
198
200 void SetAddToResetFilesList(bool b) { m_bAddToRecentFilesList = b; }
201
203 bool GetAddToRecentFilesList() const { return m_bAddToRecentFilesList; }
204
206 void ShowDocumentStatus(const plFormatString& msg) const;
207
209 virtual plResult ComputeObjectTransformation(const plDocumentObject* pObject, plTransform& out_result) const;
210
215 virtual plManipulatorSearchStrategy GetManipulatorSearchStrategy() const { return plManipulatorSearchStrategy::None; }
216
220
222 virtual bool ArePrefabsAllowed() const { return true; }
223
225 virtual void UpdatePrefabs();
226
228 void RevertPrefabs(const plDeque<const plDocumentObject*>& selection);
229
231 virtual void UnlinkPrefabs(const plDeque<const plDocumentObject*>& selection);
232
233 virtual plStatus CreatePrefabDocumentFromSelection(plStringView sFile, const plRTTI* pRootType, plDelegate<void(plAbstractObjectNode*)> adjustGraphNodeCB = {}, plDelegate<void(plDocumentObject*)> adjustNewNodesCB = {}, plDelegate<void(plAbstractObjectGraph& graph, plDynamicArray<plAbstractObjectNode*>& graphRootNodes)> finalizeGraphCB = {});
234 virtual plStatus CreatePrefabDocument(plStringView sFile, plArrayPtr<const plDocumentObject*> rootObjects, const plUuid& invPrefabSeed, plUuid& out_newDocumentGuid, plDelegate<void(plAbstractObjectNode*)> adjustGraphNodeCB = {}, bool bKeepOpen = false, plDelegate<void(plAbstractObjectGraph& graph, plDynamicArray<plAbstractObjectNode*>& graphRootNodes)> finalizeGraphCB = {});
235
236 // Returns new guid of replaced object.
237 virtual plUuid ReplaceByPrefab(const plDocumentObject* pRootObject, plStringView sPrefabFile, const plUuid& prefabAsset, const plUuid& prefabSeed, bool bEnginePrefab);
238 // Returns new guid of reverted object.
239 virtual plUuid RevertPrefab(const plDocumentObject* pObject);
240
242
243public:
245
246 mutable plEvent<const plDocumentEvent&> m_EventsOne;
247 static plEvent<const plDocumentEvent&> s_EventsAny;
248
249 mutable plEvent<const plObjectAccessorChangeEvent&> m_ObjectAccessorChangeEvents;
250
251protected:
252 void SetModified(bool b);
253 void SetReadOnly(bool b);
254 virtual plTaskGroupID InternalSaveDocument(AfterSaveCallback callback);
255 virtual plStatus InternalLoadDocument();
256 virtual plDocumentInfo* CreateDocumentInfo() = 0;
257
260
261 virtual void AttachMetaDataBeforeSaving(plAbstractObjectGraph& graph) const;
262 virtual void RestoreMetaDataAfterLoading(const plAbstractObjectGraph& graph, bool bUndoable);
263
264 virtual void InitializeAfterLoading(bool bFirstTimeCreation) {}
265 virtual void InitializeAfterLoadingAndSaving() {}
266
267 virtual void BeforeClosing();
268
269 void SetUnknownObjectTypes(const plSet<plString>& Types, plUInt32 uiInstances);
270
273
274 virtual void UpdatePrefabsRecursive(plDocumentObject* pObject);
275 virtual void UpdatePrefabObject(plDocumentObject* pObject, const plUuid& PrefabAsset, const plUuid& PrefabSeed, plStringView sBasePrefab);
276
278
280 mutable plUniquePtr<plCommandHistory> m_pCommandHistory;
281 mutable plUniquePtr<plSelectionManager> m_pSelectionManager;
283
284 plDocumentInfo* m_pDocumentInfo = nullptr;
285 const plDocumentTypeDescriptor* m_pTypeDescriptor = nullptr;
286
287private:
288 friend class plDocumentManager;
289 friend class plCommandHistory;
290 friend class plSaveDocumentTask;
291 friend class plAfterSaveDocumentTask;
292
293 void SetupDocumentInfo(const plDocumentTypeDescriptor* pTypeDescriptor);
294
295 plDocumentManager* m_pDocumentManager = nullptr;
296
297 plString m_sDocumentPath;
298 bool m_bModified;
299 bool m_bReadOnly;
300 bool m_bWindowRequested;
301 bool m_bAddToRecentFilesList;
302
303 plSet<plString> m_UnknownObjectTypes;
304 plUInt32 m_uiUnknownObjectTypeInstances;
305
306 plTaskGroupID m_ActiveSaveTask;
307 plStatus m_LastSaveResult;
308};
Definition AbstractObjectGraph.h:115
Definition AbstractObjectGraph.h:17
Definition DocumentTasks.h:25
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Stores the undo / redo stacks of transactions done on a document.
Definition CommandHistory.h:52
Definition Deque.h:270
Definition Document.h:57
bool GetAddToRecentFilesList() const
Whether this document shall be put into the recent files list.
Definition Document.h:203
virtual void OnInterDocumentMessage(plReflectedClass *pMessage, plDocument *pSender)
Called on all documents when BroadcastInterDocumentMessage() is called.
Definition Document.h:179
virtual plManipulatorSearchStrategy GetManipulatorSearchStrategy() const
Needed by plManipulatorManager to know where to look for the manipulator attributes.
Definition Document.h:215
virtual void InternalAfterSaveDocument()
A hook to execute additional code after SUCCESSFULLY saving a document. E.g. manual asset transform c...
Definition Document.h:259
const plDocument * GetActiveSubDocument() const
At any given time, only the active sub-document can be edited. This returns the active sub-document w...
Definition Document.h:88
bool IsMainDocument() const
Returns whether this document is a main document, i.e. self contained.
Definition Document.h:82
virtual plEditorInputContext * GetEditorInputContextOverride()
Allows to return a single input context that currently overrides all others (in priority).
Definition Document.h:188
virtual bool CopySelectedObjects(plAbstractObjectGraph &out_objectGraph, plStringBuilder &out_sMimeType) const
Creates the abstract graph of data to be copied and returns the mime type for the clipboard to identi...
Definition Document.h:163
virtual void GetSupportedMimeTypesForPasting(plHybridArray< plString, 4 > &out_mimeTypes) const
Whether this document supports pasting the given mime format into it.
Definition Document.h:161
bool IsSubDocument() const
Returns whether this document is a sub-document, i.e. is part of another document.
Definition Document.h:84
const plDocument * GetMainDocument() const
In case this is a sub-document, returns the main document this belongs to. Otherwise 'this' is return...
Definition Document.h:86
virtual bool ArePrefabsAllowed() const
Whether the document allows to create prefabs in it. This may note be allowed for prefab documents th...
Definition Document.h:222
plStringView GetDocumentTypeName() const
Returns the document's type name. Same as GetDocumentTypeDescriptor()->m_sDocumentTypeName.
Definition Document.h:127
void SetAddToResetFilesList(bool b)
If disabled, this document will not be put into the recent files list.
Definition Document.h:200
plStringView GetDocumentPath() const
Returns the absolute path to the document.
Definition Document.h:102
virtual bool CanEngineProcessBeRestarted() const
Asks the document whether a restart of the engine process is allowed at this time.
Definition Document.h:145
plUniquePtr< plObjectCommandAccessor > m_pObjectAccessor
Default object accessor used by every doc.
Definition Document.h:282
Definition Declarations.h:72
Definition DocumentManager.h:8
Definition DocumentObjectBase.h:11
Represents to content of a document. Every document has exactly one root object under which all objec...
Definition DocumentObjectManager.h:116
Definition Document.h:28
plUuid m_PrefabSeedGuid
The asset GUID of the prefab from which this object was created. Invalid GUID, if this is not a prefa...
Definition Document.h:44
plUuid m_CreateFromPrefab
Whether the object should be rendered in the editor view (no effect on the runtime)
Definition Document.h:43
plString m_sBasePrefab
The seed GUID used to remap the object GUIDs from the prefab asset into this instance.
Definition Document.h:45
Definition DynamicArray.h:81
Definition EditorInputContext.h:22
Definition Event.h:177
Implements formating of strings with placeholders and formatting options.
Definition FormatString.h:59
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition ObjectAccessorBase.h:8
Definition ObjectCommandAccessor.h:9
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition DocumentTasks.h:10
Selection Manager stores a set of selected document objects.
Definition SelectionManager.h:26
Definition Set.h:238
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Given out by plTaskSystem::CreateTaskGroup to identify a task group.
Definition TaskSystemDeclarations.h:103
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Definition Document.h:152
Definition Declarations.h:35
Definition Document.h:21
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
An plResult with an additional message for the reason of failure.
Definition Status.h:12