Plasma Engine  2.0
Loading...
Searching...
No Matches
DocumentNodeManager.h
1#pragma once
2
3#include <Foundation/Serialization/AbstractObjectGraph.h>
4#include <Foundation/Types/Status.h>
5#include <ToolsFoundation/Document/Document.h>
6#include <ToolsFoundation/Object/DocumentObjectManager.h>
7
8class plPin;
9class plConnection;
10
11struct PL_TOOLSFOUNDATION_DLL plDocumentNodeManagerEvent
12{
13 enum class Type
14 {
15 NodeMoved,
16 AfterPinsConnected,
17 BeforePinsDisonnected,
18 BeforePinsChanged,
19 AfterPinsChanged,
20 BeforeNodeAdded,
21 AfterNodeAdded,
22 BeforeNodeRemoved,
23 AfterNodeRemoved,
24 };
25
26 plDocumentNodeManagerEvent(Type eventType, const plDocumentObject* pObject = nullptr)
27 : m_EventType(eventType)
28 , m_pObject(pObject)
29 {
30 }
31
32 Type m_EventType;
33 const plDocumentObject* m_pObject;
34};
35
37{
38public:
39 const plPin& GetSourcePin() const { return m_SourcePin; }
40 const plPin& GetTargetPin() const { return m_TargetPin; }
41 const plDocumentObject* GetParent() const { return m_pParent; }
42
43private:
44 friend class plDocumentNodeManager;
45
46 plConnection(const plPin& sourcePin, const plPin& targetPin, const plDocumentObject* pParent)
47 : m_SourcePin(sourcePin)
48 , m_TargetPin(targetPin)
49 , m_pParent(pParent)
50 {
51 }
52
53 const plPin& m_SourcePin;
54 const plPin& m_TargetPin;
55 const plDocumentObject* m_pParent = nullptr;
56};
57
58class PL_TOOLSFOUNDATION_DLL plPin : public plReflectedClass
59{
60 PL_ADD_DYNAMIC_REFLECTION(plPin, plReflectedClass);
61
62public:
63 enum class Type
64 {
65 Input,
66 Output
67 };
68
69 enum class Shape
70 {
71 Circle,
72 Rect,
73 RoundRect,
74 Arrow,
75 Default = Circle
76 };
77
78 plPin(Type type, plStringView sName, const plColorGammaUB& color, const plDocumentObject* pObject)
79 : m_Type(type)
80 , m_Color(color)
81 , m_sName(sName)
82 , m_pParent(pObject)
83 {
84 }
85
86 Shape m_Shape = Shape::Default;
87
88 Type GetType() const { return m_Type; }
89 const char* GetName() const { return m_sName; }
90 const plColorGammaUB& GetColor() const { return m_Color; }
91 const plDocumentObject* GetParent() const { return m_pParent; }
92
93private:
94 friend class plDocumentNodeManager;
95
96 Type m_Type;
97 plColorGammaUB m_Color;
98 plString m_sName;
99 const plDocumentObject* m_pParent = nullptr;
100};
101
103
105{
106 plHashedString m_sPropertyName;
107 plVariant m_Value;
108};
109
116{
117 const plRTTI* m_pType = nullptr;
118 plStringView m_sTypeName;
119 plHashedString m_sCategory;
121};
122
124
127class PL_TOOLSFOUNDATION_DLL plDocumentObject_ConnectionBase : public plReflectedClass
128{
129 PL_ADD_DYNAMIC_REFLECTION(plDocumentObject_ConnectionBase, plReflectedClass);
130
131public:
132 plUuid m_Source;
133 plUuid m_Target;
134 plString m_SourcePin;
135 plString m_TargetPin;
136};
137
139
140class PL_TOOLSFOUNDATION_DLL plDocumentNodeManager : public plDocumentObjectManager
141{
142public:
144
146 virtual ~plDocumentNodeManager();
147
151 virtual void GetNodeCreationTemplates(plDynamicArray<plNodeCreationTemplate>& out_templates) const;
152
153 virtual const plRTTI* GetConnectionType() const;
154
155 plVec2 GetNodePos(const plDocumentObject* pObject) const;
156 const plConnection& GetConnection(const plDocumentObject* pObject) const;
157 const plConnection* GetConnectionIfExists(const plDocumentObject* pObject) const;
158
159 const plPin* GetInputPinByName(const plDocumentObject* pObject, plStringView sName) const;
160 const plPin* GetOutputPinByName(const plDocumentObject* pObject, plStringView sName) const;
161 plArrayPtr<const plUniquePtr<const plPin>> GetInputPins(const plDocumentObject* pObject) const;
162 plArrayPtr<const plUniquePtr<const plPin>> GetOutputPins(const plDocumentObject* pObject) const;
163
165 {
166 ConnectNever,
167 Connect1to1,
168 Connect1toN,
169 ConnectNto1,
170 ConnectNtoN,
171 };
172
173 bool IsNode(const plDocumentObject* pObject) const;
174 bool IsConnection(const plDocumentObject* pObject) const;
175 bool IsDynamicPinProperty(const plDocumentObject* pObject, const plAbstractProperty* pProp) const;
176
177 plArrayPtr<const plConnection* const> GetConnections(const plPin& pin) const;
178 bool HasConnections(const plPin& pin) const;
179 bool IsConnected(const plPin& source, const plPin& target) const;
180
181 plStatus CanConnect(const plRTTI* pObjectType, const plPin& source, const plPin& target, CanConnectResult& ref_result) const;
182 plStatus CanDisconnect(const plConnection* pConnection) const;
183 plStatus CanDisconnect(const plDocumentObject* pObject) const;
184 plStatus CanMoveNode(const plDocumentObject* pObject, const plVec2& vPos) const;
185
186 void Connect(const plDocumentObject* pObject, const plPin& source, const plPin& target);
187 void Disconnect(const plDocumentObject* pObject);
188 void MoveNode(const plDocumentObject* pObject, const plVec2& vPos);
189
190 void AttachMetaDataBeforeSaving(plAbstractObjectGraph& ref_graph) const;
191 void RestoreMetaDataAfterLoading(const plAbstractObjectGraph& graph, bool bUndoable);
192
193 void GetMetaDataHash(const plDocumentObject* pObject, plUInt64& inout_uiHash) const;
194 bool CopySelectedObjects(plAbstractObjectGraph& out_objectGraph) const;
195 bool PasteObjects(const plArrayPtr<plDocument::PasteInfo>& info, const plAbstractObjectGraph& objectGraph, const plVec2& vPickedPosition, bool bAllowPickedPosition);
196
197protected:
199 bool CanReachNode(const plDocumentObject* pSource, const plDocumentObject* pTarget, plSet<const plDocumentObject*>& Visited) const;
200
202 bool WouldConnectionCreateCircle(const plPin& source, const plPin& target) const;
203
204 plResult ResolveConnection(const plUuid& sourceObject, const plUuid& targetObject, plStringView sourcePin, plStringView targetPin, const plPin*& out_pSourcePin, const plPin*& out_pTargetPin) const;
205
206 virtual void GetDynamicPinNames(const plDocumentObject* pObject, plStringView sPropertyName, plStringView sPinName, plDynamicArray<plString>& out_Names) const;
207 virtual bool TryRecreatePins(const plDocumentObject* pObject);
208
210 {
211 plVec2 m_vPos = plVec2::MakeZero();
214 };
215
216private:
217 virtual bool InternalIsNode(const plDocumentObject* pObject) const;
218 virtual bool InternalIsConnection(const plDocumentObject* pObject) const;
219 virtual bool InternalIsDynamicPinProperty(const plDocumentObject* pObject, const plAbstractProperty* pProp) const { return false; }
220 virtual plStatus InternalCanConnect(const plPin& source, const plPin& target, CanConnectResult& out_Result) const;
221 virtual plStatus InternalCanDisconnect(const plPin& source, const plPin& target) const { return plStatus(PL_SUCCESS); }
222 virtual plStatus InternalCanMoveNode(const plDocumentObject* pObject, const plVec2& vPos) const { return plStatus(PL_SUCCESS); }
223 virtual void InternalCreatePins(const plDocumentObject* pObject, NodeInternal& node) = 0;
224
225 void ObjectHandler(const plDocumentObjectEvent& e);
226 void StructureEventHandler(const plDocumentObjectStructureEvent& e);
227 void PropertyEventsHandler(const plDocumentObjectPropertyEvent& e);
228
229 void HandlePotentialDynamicPinPropertyChanged(const plDocumentObject* pObject, plStringView sPropertyName);
230
231private:
235};
Definition AbstractObjectGraph.h:115
This is the base interface for all properties in the reflection system. It provides enough informatio...
Definition AbstractProperty.h:150
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
Definition DocumentNodeManager.h:37
Definition DocumentNodeManager.h:141
CanConnectResult
Definition DocumentNodeManager.h:165
Base class for all node connections. Derive from this class and overwrite plDocumentNodeManager::GetC...
Definition DocumentNodeManager.h:128
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 DynamicArray.h:81
Definition Event.h:177
Definition HashTable.h:333
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
Definition DocumentNodeManager.h:59
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 Set.h:238
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
static constexpr plVec2Template< float > MakeZero()
Definition Vec2.h:49
Definition DocumentNodeManager.h:210
Definition DocumentNodeManager.h:12
Used by plDocumentObjectManager::m_ObjectEvents.
Definition DocumentObjectManager.h:100
Used by plDocumentObjectManager::m_PropertyEvents.
Definition DocumentObjectManager.h:77
Used by plDocumentObjectManager::m_StructureEvents.
Definition DocumentObjectManager.h:45
Describes a template that will be used to create new nodes. In most cases this only contains the type...
Definition DocumentNodeManager.h:116
Definition DocumentNodeManager.h:105
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