-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVisualNodeSystem.h
More file actions
147 lines (111 loc) · 6.39 KB
/
Copy pathVisualNodeSystem.h
File metadata and controls
147 lines (111 loc) · 6.39 KB
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
#pragma once
#include "SubSystems/VisualNodeArea/VisualNodeArea.h"
namespace VisNodeSys
{
class VISUAL_NODE_SYSTEM_API NodeSystem
{
friend class NodeSocket;
friend class Node;
friend class SocketMirrorNode;
friend class LinkNode;
friend class NodeArea;
SINGLETON_PRIVATE_PART(NodeSystem)
struct NodeAreaLinkRecord
{
std::string ID;
std::string InNodeID;
std::string OutNodeID;
std::string InAreaID;
std::string OutAreaID;
bool IsNull() const
{
return ID.empty() || InNodeID.empty() || OutNodeID.empty() || InAreaID.empty() || OutAreaID.empty();
}
};
std::vector<NodeArea*> Areas;
std::unordered_map<std::string, NodeAreaLinkRecord> NodeAreaLinkRecords;
bool IsAlreadyConnected(NodeSocket* FirstSocket, NodeSocket* SecondSocket, const std::vector<Connection*>& Connections);
void ProcessConnections(const std::vector<NodeSocket*>& Sockets,
std::unordered_map<NodeSocket*, NodeSocket*>& OldToNewSocket,
NodeArea* TargetArea, size_t NodeShift, const std::vector<Node*>& SourceNodes);
void CopyNodesInternal(const std::vector<Node*>& SourceNodes, NodeArea* TargetArea, const size_t NodeShift = 0);
LinkNode* CreateLinkNodeInternal(bool bIsInputNode);
NodeAreaLinkRecord* GetLinkDataByNodeID(const std::string& NodeID);
std::vector<NodeAreaLinkRecord*> GetLinkDataByAreaID(const std::string& AreaID);
void OnNodeDeletion(Node* DeletedNode);
bool DeleteLinkRecord(const std::string& LinkID);
#ifdef VISUAL_NODE_SYSTEM_BUILD_EXECUTION_FLOW_NODES
void RegisterStandardNodes();
#endif
void OnNodeAreaFocusChanging(NodeArea* CurrentNodeArea, bool bNewFocusValue);
bool DeleteSocket(const std::string& NodeID, std::string SocketID);
bool DeleteSocket(NodeSocket* Socket);
bool RevalidateSocketConnections(NodeSocket* Socket);
SocketMirrorNode* GetAppropriatePartner(SocketMirrorNode* MirrorNode, NodeSocket::SocketFlow CurrentDirection);
std::pair<SocketMirrorNode*, NodeSocket*> GetAppropriatePartnerAndSocket(SocketMirrorNode* MirrorNode, NodeSocket* CurrentNodeSocket);
bool AddSocketToMirrorNode(const std::string& NodeID, std::vector<std::string> AllowedTypes, std::string Name, NodeSocket::SocketFlow SocketDirection = NodeSocket::SocketFlow::Input);
bool DeleteSocketFromMirrorNode(const std::string& NodeID, std::string SocketID);
bool SyncMirrorNodeSocketAllowedTypes(const std::string& NodeID, std::string SocketID, std::vector<std::string> NewTypes);
void SyncMirrorNodeSocketName(const std::string& NodeID, std::string SocketID, std::string NewName);
std::vector<std::string> DeduplicateIDList(const std::vector<std::string>& ListOfIDs) const;
// Walks the SubAreaNode ownership graph and get rid of cycles.
void BreakSubAreaOwnershipCycles();
public:
SINGLETON_PUBLIC_PART(NodeSystem)
void Initialize(bool bTestMode = false);
std::string ToJson() const;
bool SaveToFile(const std::string& FilePath) const;
bool LoadFromJson(const std::string& JsonText);
bool LoadFromFile(const std::string& FilePath);
void Clear();
std::vector<std::string> GetNodeAreaIDList() const;
std::string GetVersion();
std::string GetFullVersion();
NodeArea* CreateNodeArea();
NodeArea* CreateNodeArea(const std::vector<Node*> Nodes, const std::vector<GroupComment*> GroupComments);
NodeArea* GetNodeAreaByID(const std::string& NodeAreaID) const;
std::vector<NodeArea*> GetNodeAreasByName(const std::string& Name) const;
void DeleteNodeArea(const NodeArea* NodeAreaToDelete);
void DeleteNodeAreaByID(const std::string& NodeAreaID);
void CopyElementsTo(NodeArea* SourceNodeArea, NodeArea* TargetNodeArea);
size_t GetNodeAreaCount() const;
size_t GetTotalNodeCount(std::vector<std::string> AreaIDFilter = {}) const;
size_t GetTotalConnectionCount(std::vector<std::string> AreaIDFilter = {}) const;
size_t GetGroupCommentCount(std::vector<std::string> AreaIDFilter = {}) const;
size_t GetRerouteConnectionCount(std::vector<std::string> AreaIDFilter = {}) const;
#ifdef VISUAL_NODE_SYSTEM_BUILD_EXECUTION_FLOW_NODES
// Will return a map where key is node area IDs and value is a list of of nodes that were executed last time in that area.
std::unordered_map<std::string, std::vector<Node*>> GetLastExecutedNodes(std::string StartingAreaID = "") const;
#endif
bool MoveNodesTo(NodeArea* SourceNodeArea, NodeArea* TargetNodeArea, bool bSelectNodesAfterMovement = false);
Node* GetNodeByID(const std::string& NodeID) const;
std::vector<Node*> GetNodesByName(const std::string& Name) const;
std::vector<Node*> GetNodesByStringType(const std::string& Type) const;
std::vector<std::pair<std::string, ImColor>> GetAssociationsOfSocketTypeToColor(std::string SocketType, ImColor Color);
void AssociateSocketTypeToColor(std::string SocketType, ImColor Color);
bool IsInAListOfAreas(const std::string& AreaID, const std::vector<std::string>& AreaIDList) const;
bool IsInAListOfAreas(const NodeArea* Area, const std::vector<NodeArea*>& AreaIDList) const;
bool LinkNodeAreas(const std::string& UpstreamAreaID,
const std::string& DownstreamAreaID,
std::pair<std::string, std::string>* CreatedLinkNodeIDs = nullptr);
bool IsLinked(const std::string& FirstAreaID, const std::string& SecondAreaID) const;
bool UnlinkNodeAreas(const std::string& FirstAreaID, const std::string& SecondAreaID);
std::vector<std::pair<std::string, std::string>> GetLinkingNodesForAreas(const std::string& FirstAreaID, const std::string& SecondAreaID) const;
std::vector<LinkNode*> GetDanglingLinkNodes() const;
bool TryToFixDanglingLinkNode(LinkNode* LinkNodeToFix, bool bForceRestorePartner = false);
std::vector<LinkNode*> TryToFixAllDanglingLinkNodes();
std::vector<NodeArea*> GetImmediateDownstreamAreas(const std::string& AreaID);
std::vector<NodeArea*> GetAllDownstreamAreas(const std::string& AreaID);
std::vector<NodeArea*> GetImmediateUpstreamAreas(const std::string& AreaID);
std::vector<NodeArea*> GetAllUpstreamAreas(const std::string& AreaID);
SubAreaNode* CreateSubAreaNode(const std::string& ParentAreaID);
SubAreaNode* FindOwnerSubAreaNode(const std::string& AreaID) const;
SubAreaNode* ConvertNodesToSubArea(NodeArea* ParentArea, const std::vector<Node*>& NodesToConvert);
};
#ifdef VISUAL_NODE_SYSTEM_SHARED
extern "C" __declspec(dllexport) void* GetNodeSystem();
#define NODE_SYSTEM (*static_cast<VisNodeSys::NodeSystem*>(VisNodeSys::GetNodeSystem()))
#else
#define NODE_SYSTEM VisNodeSys::NodeSystem::GetInstance()
#endif
}