Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
Olympe::NodeGraph::GraphDocument Class Reference

Main document class for a node graph. More...

#include <GraphDocument.h>

+ Collaboration diagram for Olympe::NodeGraph::GraphDocument:

Public Member Functions

 GraphDocument ()
 
 ~GraphDocument ()
 
NodeId CreateNode (const std::string &nodeType, Vector2 pos)
 Create a new node in the graph.
 
bool DeleteNode (NodeId id)
 Delete a node from the graph.
 
bool UpdateNodePosition (NodeId id, Vector2 newPos)
 Update node position.
 
bool UpdateNodeParameters (NodeId id, const std::map< std::string, std::string > &params)
 Update node parameters.
 
NodeDataGetNode (NodeId id)
 Get a node by ID.
 
const NodeDataGetNode (NodeId id) const
 
bool UpdateNode (NodeId nodeId, const NodeData &newData)
 Update an existing node's data.
 
LinkId ConnectPins (PinId fromPin, PinId toPin)
 Connect two pins with a link.
 
bool DisconnectLink (LinkId id)
 Disconnect a link.
 
LinkDataGetLink (LinkId id)
 Get a link by ID.
 
const LinkDataGetLink (LinkId id) const
 
bool ValidateGraph (std::string &errorMessage) const
 Validate the graph structure.
 
bool HasCycles () const
 Check if the graph has cycles.
 
json ToJson () const
 Convert graph to JSON format (v2 schema)
 
bool AutoLayout (const AutoLayoutConfig &config)
 Automatically layout nodes in a hierarchical arrangement.
 
const std::vector< NodeData > & GetNodes () const
 
const std::vector< LinkData > & GetLinks () const
 
std::vector< NodeData > & GetNodesRef ()
 
std::vector< LinkData > & GetLinksRef ()
 
bool IsDirty () const
 
void SetDirty (bool dirty)
 
NodeAnnotationsManagerGetNodeAnnotations ()
 Get node annotations manager (non-const)
 
const NodeAnnotationsManagerGetNodeAnnotations () const
 Get node annotations manager (const)
 
BlackboardSystemGetBlackboard ()
 Get blackboard system (non-const)
 
const BlackboardSystemGetBlackboard () const
 Get blackboard system (const)
 

Static Public Member Functions

static GraphDocument FromJson (const json &j)
 Create graph from JSON.
 

Public Attributes

std::string type
 
std::string graphKind
 
NodeId rootNodeId
 
json metadata
 
EditorState editorState
 

Private Member Functions

bool HasCyclesHelper (NodeId nodeId, std::vector< NodeId > &visited, std::vector< NodeId > &recursionStack) const
 
float AutoLayoutNode (NodeId nodeId, const AutoLayoutConfig &config, float startX, float startY, int depth, std::map< NodeId, bool > &visited)
 Helper to recursively layout a node and its children.
 

Private Attributes

std::vector< NodeDatam_nodes
 
std::vector< LinkDatam_links
 
uint32_t m_nextNodeId = 1
 
uint32_t m_nextLinkId = 1
 
bool m_isDirty = false
 
NodeAnnotationsManager m_nodeAnnotations
 
BlackboardSystem m_blackboard
 

Detailed Description

Main document class for a node graph.

Definition at line 30 of file GraphDocument.h.

Constructor & Destructor Documentation

◆ GraphDocument()

Olympe::NodeGraph::GraphDocument::GraphDocument ( )

Definition at line 21 of file GraphDocument.cpp.

References metadata.

◆ ~GraphDocument()

Olympe::NodeGraph::GraphDocument::~GraphDocument ( )

Definition at line 31 of file GraphDocument.cpp.

Member Function Documentation

◆ AutoLayout()

bool Olympe::NodeGraph::GraphDocument::AutoLayout ( const AutoLayoutConfig config)

Automatically layout nodes in a hierarchical arrangement.

Parameters
configLayout configuration (direction, spacing, etc.)
Returns
true if layout was applied, false if graph is empty/invalid

Definition at line 591 of file GraphDocument.cpp.

References AutoLayoutNode(), GetComponentTypeID_Static(), GetNode(), m_isDirty, m_nodes, rootNodeId, SYSTEM_LOG, and Olympe::NodeGraph::NodeId::value.

+ Here is the call graph for this function:

◆ AutoLayoutNode()

float Olympe::NodeGraph::GraphDocument::AutoLayoutNode ( NodeId  nodeId,
const AutoLayoutConfig config,
float  startX,
float  startY,
int  depth,
std::map< NodeId, bool > &  visited 
)
private

Helper to recursively layout a node and its children.

Parameters
nodeIdNode to layout
configLayout configuration
startXStarting X position
startYStarting Y position
depthCurrent depth in tree (0 = root)
visitedMap to track visited nodes (cycle detection)
Returns
Total width consumed by this subtree

Definition at line 637 of file GraphDocument.cpp.

References AutoLayoutNode(), GetComponentTypeID_Static(), GetNode(), SYSTEM_LOG, UpdateNodePosition(), Olympe::NodeGraph::NodeId::value, and Olympe::Vector2.

Referenced by AutoLayout(), and AutoLayoutNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConnectPins()

LinkId Olympe::NodeGraph::GraphDocument::ConnectPins ( PinId  fromPin,
PinId  toPin 
)

Connect two pins with a link.

Parameters
fromPinSource pin
toPinTarget pin
Returns
ID of created link

Definition at line 156 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), Olympe::NodeGraph::LinkData::id, m_isDirty, m_links, m_nextLinkId, and Olympe::NodeGraph::LinkId::value.

Referenced by Olympe::NodeGraph::ConnectPinsCommand::Execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateNode()

NodeId Olympe::NodeGraph::GraphDocument::CreateNode ( const std::string &  nodeType,
Vector2  pos 
)

Create a new node in the graph.

Parameters
nodeTypeType of the node (e.g., "BT_Selector", "BT_Action")
posPosition of the node
Returns
ID of the created node

Definition at line 39 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), Olympe::NodeGraph::NodeData::id, m_isDirty, m_nextNodeId, m_nodes, and Olympe::NodeGraph::NodeId::value.

Referenced by Olympe::NodeGraph::CreateNodeCommand::Execute(), Test15_SaveLoadIntegration(), Test6_ValidateGraph(), and Test7_SaveLoadRoundtrip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeleteNode()

bool Olympe::NodeGraph::GraphDocument::DeleteNode ( NodeId  id)

Delete a node from the graph.

Parameters
idID of the node to delete
Returns
true if deleted, false if not found

Definition at line 53 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), m_isDirty, m_links, and m_nodes.

Referenced by Olympe::NodeGraph::DeleteNodeCommand::Execute(), and Olympe::NodeGraph::CreateNodeCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DisconnectLink()

bool Olympe::NodeGraph::GraphDocument::DisconnectLink ( LinkId  id)

Disconnect a link.

Parameters
idLink ID
Returns
true if deleted, false if not found

Definition at line 169 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), m_isDirty, and m_links.

Referenced by Olympe::NodeGraph::ConnectPinsCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FromJson()

GraphDocument Olympe::NodeGraph::GraphDocument::FromJson ( const json j)
static

Create graph from JSON.

Parameters
jJSON object
Returns
GraphDocument instance

Definition at line 420 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), JsonHelper::GetFloat(), JsonHelper::GetString(), JsonHelper::GetUInt(), Olympe::NodeGraph::NodeData::id, Olympe::NodeGraph::LinkData::id, type, Olympe::NodeGraph::NodeId::value, and Olympe::NodeGraph::LinkId::value.

Referenced by Olympe::NodeGraph::GraphMigrator::LoadWithMigration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBlackboard() [1/2]

BlackboardSystem & Olympe::NodeGraph::GraphDocument::GetBlackboard ( )
inline

Get blackboard system (non-const)

Definition at line 198 of file GraphDocument.h.

References m_blackboard.

◆ GetBlackboard() [2/2]

const BlackboardSystem & Olympe::NodeGraph::GraphDocument::GetBlackboard ( ) const
inline

Get blackboard system (const)

Definition at line 203 of file GraphDocument.h.

References m_blackboard.

◆ GetLink() [1/2]

LinkData * Olympe::NodeGraph::GraphDocument::GetLink ( LinkId  id)

Get a link by ID.

Parameters
idLink ID
Returns
Pointer to link data or nullptr if not found

Definition at line 184 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), and m_links.

+ Here is the call graph for this function:

◆ GetLink() [2/2]

const LinkData * Olympe::NodeGraph::GraphDocument::GetLink ( LinkId  id) const

Definition at line 194 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), and m_links.

+ Here is the call graph for this function:

◆ GetLinks()

const std::vector< LinkData > & Olympe::NodeGraph::GraphDocument::GetLinks ( ) const
inline

Definition at line 169 of file GraphDocument.h.

References m_links.

Referenced by Olympe::NodeGraph::DeleteNodeCommand::Execute(), and Olympe::AI::AIEditorGUI::RenderConnections().

+ Here is the caller graph for this function:

◆ GetLinksRef()

std::vector< LinkData > & Olympe::NodeGraph::GraphDocument::GetLinksRef ( )
inline

Definition at line 172 of file GraphDocument.h.

References m_links.

◆ GetNode() [1/2]

NodeData * Olympe::NodeGraph::GraphDocument::GetNode ( NodeId  id)

Get a node by ID.

Parameters
idNode ID
Returns
Pointer to node data or nullptr if not found

Definition at line 104 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), and m_nodes.

Referenced by AutoLayout(), AutoLayoutNode(), Olympe::NodeGraph::DeleteNodeCommand::Execute(), HasCyclesHelper(), UpdateNodeParameters(), UpdateNodePosition(), and ValidateGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetNode() [2/2]

const NodeData * Olympe::NodeGraph::GraphDocument::GetNode ( NodeId  id) const

Definition at line 114 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), and m_nodes.

+ Here is the call graph for this function:

◆ GetNodeAnnotations() [1/2]

NodeAnnotationsManager & Olympe::NodeGraph::GraphDocument::GetNodeAnnotations ( )
inline

Get node annotations manager (non-const)

Definition at line 184 of file GraphDocument.h.

References m_nodeAnnotations.

◆ GetNodeAnnotations() [2/2]

const NodeAnnotationsManager & Olympe::NodeGraph::GraphDocument::GetNodeAnnotations ( ) const
inline

Get node annotations manager (const)

Definition at line 189 of file GraphDocument.h.

References m_nodeAnnotations.

◆ GetNodes()

const std::vector< NodeData > & Olympe::NodeGraph::GraphDocument::GetNodes ( ) const
inline

Definition at line 168 of file GraphDocument.h.

References m_nodes.

Referenced by Olympe::AI::AIEditorGUI::MenuAction_SelectAll(), and Olympe::AI::AIEditorGUI::RenderNodeGraphCanvas().

+ Here is the caller graph for this function:

◆ GetNodesRef()

std::vector< NodeData > & Olympe::NodeGraph::GraphDocument::GetNodesRef ( )
inline

Definition at line 171 of file GraphDocument.h.

References m_nodes.

Referenced by Olympe::NodeGraph::DeleteNodeCommand::Undo().

+ Here is the caller graph for this function:

◆ HasCycles()

bool Olympe::NodeGraph::GraphDocument::HasCycles ( ) const

Check if the graph has cycles.

Returns
true if cycles detected, false otherwise

Definition at line 251 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), HasCyclesHelper(), and m_nodes.

Referenced by ValidateGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasCyclesHelper()

bool Olympe::NodeGraph::GraphDocument::HasCyclesHelper ( NodeId  nodeId,
std::vector< NodeId > &  visited,
std::vector< NodeId > &  recursionStack 
) const
private

Definition at line 271 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), GetNode(), and HasCyclesHelper().

Referenced by HasCycles(), and HasCyclesHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsDirty()

bool Olympe::NodeGraph::GraphDocument::IsDirty ( ) const
inline

Definition at line 174 of file GraphDocument.h.

References m_isDirty.

◆ SetDirty()

void Olympe::NodeGraph::GraphDocument::SetDirty ( bool  dirty)
inline

Definition at line 175 of file GraphDocument.h.

References GetComponentTypeID_Static(), and m_isDirty.

+ Here is the call graph for this function:

◆ ToJson()

json Olympe::NodeGraph::GraphDocument::ToJson ( ) const

◆ UpdateNode()

bool Olympe::NodeGraph::GraphDocument::UpdateNode ( NodeId  nodeId,
const NodeData newData 
)

Update an existing node's data.

Parameters
nodeIdThe node to update
newDataNew node data (position, type, parameters)
Returns
true if node was found and updated, false otherwise

Definition at line 124 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), m_nodes, SYSTEM_LOG, and Olympe::NodeGraph::NodeId::value.

+ Here is the call graph for this function:

◆ UpdateNodeParameters()

bool Olympe::NodeGraph::GraphDocument::UpdateNodeParameters ( NodeId  id,
const std::map< std::string, std::string > &  params 
)

Update node parameters.

Parameters
idNode ID
paramsNew parameters
Returns
true if updated, false if not found

Definition at line 92 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), GetNode(), and m_isDirty.

+ Here is the call graph for this function:

◆ UpdateNodePosition()

bool Olympe::NodeGraph::GraphDocument::UpdateNodePosition ( NodeId  id,
Vector2  newPos 
)

Update node position.

Parameters
idNode ID
newPosNew position
Returns
true if updated, false if not found

Definition at line 80 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), GetNode(), and m_isDirty.

Referenced by AutoLayoutNode(), Olympe::NodeGraph::MoveNodeCommand::Execute(), and Olympe::NodeGraph::MoveNodeCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValidateGraph()

bool Olympe::NodeGraph::GraphDocument::ValidateGraph ( std::string &  errorMessage) const

Validate the graph structure.

Parameters
errorMessageOutput error message if validation fails
Returns
true if valid, false otherwise

Definition at line 208 of file GraphDocument.cpp.

References GetComponentTypeID_Static(), GetNode(), HasCycles(), m_nodes, rootNodeId, and Olympe::NodeGraph::NodeId::value.

Referenced by Test8_ValidateGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ editorState

EditorState Olympe::NodeGraph::GraphDocument::editorState

Definition at line 43 of file GraphDocument.h.

Referenced by ToJson().

◆ graphKind

std::string Olympe::NodeGraph::GraphDocument::graphKind

Definition at line 40 of file GraphDocument.h.

Referenced by ToJson().

◆ m_blackboard

BlackboardSystem Olympe::NodeGraph::GraphDocument::m_blackboard
private

Definition at line 218 of file GraphDocument.h.

Referenced by GetBlackboard(), GetBlackboard(), and ToJson().

◆ m_isDirty

bool Olympe::NodeGraph::GraphDocument::m_isDirty = false
private

◆ m_links

std::vector<LinkData> Olympe::NodeGraph::GraphDocument::m_links
private

◆ m_nextLinkId

uint32_t Olympe::NodeGraph::GraphDocument::m_nextLinkId = 1
private

Definition at line 211 of file GraphDocument.h.

Referenced by ConnectPins().

◆ m_nextNodeId

uint32_t Olympe::NodeGraph::GraphDocument::m_nextNodeId = 1
private

Definition at line 210 of file GraphDocument.h.

Referenced by CreateNode().

◆ m_nodeAnnotations

NodeAnnotationsManager Olympe::NodeGraph::GraphDocument::m_nodeAnnotations
private

Definition at line 215 of file GraphDocument.h.

Referenced by GetNodeAnnotations(), GetNodeAnnotations(), and ToJson().

◆ m_nodes

std::vector<NodeData> Olympe::NodeGraph::GraphDocument::m_nodes
private

◆ metadata

json Olympe::NodeGraph::GraphDocument::metadata

Definition at line 42 of file GraphDocument.h.

Referenced by GraphDocument(), and ToJson().

◆ rootNodeId

NodeId Olympe::NodeGraph::GraphDocument::rootNodeId

Definition at line 41 of file GraphDocument.h.

Referenced by AutoLayout(), ToJson(), and ValidateGraph().

◆ type

std::string Olympe::NodeGraph::GraphDocument::type

The documentation for this class was generated from the following files: