Enzo
Loading...
Searching...
No Matches
enzo::nt::NetworkManager Class Reference

The central coordinator of the engine's node system. More...

#include <NetworkManager.h>

Classes

class  OperatorRange
 Iterable range over operators, yields {OpId, GeometryOperator&} pairs. More...
 

Public Member Functions

OperatorRange operators ()
 Returns an iterable range over all operators in the network.
 
 NetworkManager (const NetworkManager &obj)=delete
 Deleted the copy constructor for singleton.
 
OpId createOperator (op::OpInfo opInfo, const std::string &path="", Vector2 position={0.f, 0.f})
 Creates a new node in the network.
 
std::optional< OpIdgetDisplayOp ()
 Returns the operator ID for the node with its display flag set. There can only be only be one operator displayed at a time. Return value is nullopt if no node is set to display.
 
enzo::nt::UpdateLock lockUpdates ()
 Creates a lock object that prevents cooking until destroyed.
 
void update ()
 Cooks dirtied nodes, is called automatically.
 
bool isValidOp (nt::OpId opId)
 Returns whether the node exists in the network and is valid.
 
GeometryOperatorgetGeoOperator (nt::OpId opId)
 Returns a reference to the GeometryOperator with the given OpId.
 
void setDisplayOp (OpId opId)
 Sets given OpId to be displayed, releasing previous display Node.
 
void clearDisplayFlag ()
 Clears the display flag so no node is displayed.
 
void setSelectedNode (OpId opId, bool selected, bool add=false)
 Set the selection state for the given node.
 
const std::vector< enzo::nt::OpId > & getSelectedNodes ()
 Returns the OpIds for all selected nodes.
 
void setSelectedNodes (std::vector< enzo::nt::OpId > opIds)
 Replaces the entire selection with the given set of nodes.
 
void moveNode (OpId opId, Vector2 newPos, bool skipUndo=false)
 Moves a node to a new position, pushing an undo command.
 
void deleteNode (OpId opId)
 Deletes a node, pushing an undo command.
 
void removeOperator (OpId opId, bool removeConnections=true)
 Removes an operator from the network.
 
void restoreOperator (OpId opId, op::OpInfo opInfo)
 Restores a previously removed operator with a specific OpId.
 
void clear ()
 Clears all operators and resets the network to its initial state.
 
void cookOp (enzo::nt::OpId opId)
 Cooks the given operator.
 
nt::NetworkGraphgraph ()
 Returns the graph that owns the network's wiring and dependencies.
 
nt::Connection connectNodes (OpId inputOpId, unsigned int inputIndex, OpId outputOpId, unsigned int outputIndex)
 Wires one node's output into another node's input.
 
void disconnectNodes (const nt::Connection &connection)
 Removes a wired connection between two nodes.
 
GeometryOperatorfindOperator (const NetworkPath &path, OpId fromOp=nullOp)
 Resolves a node reference to its operator.
 
std::weak_ptr< prm::NodeParameterfindParameter (const NetworkPath &path, OpId fromOp=nullOp)
 Resolves a parameter reference to its parameter.
 
UndoStackundoStack ()
 
void _reset ()
 For use in unit tests, resets the state of the operator.
 

Static Public Member Functions

static NetworkManagergetInstance ()
 Returns a reference to the singleton instance.
 

Public Attributes

Signals
boost::signals2::signal< void(std::optional< nt::OpId >)> displayNodeChanged
 
boost::signals2::signal< void(std::shared_ptr< const enzo::NodePacket >)> displayGeoChanged
 
boost::signals2::signal< void(std::shared_ptr< const enzo::NodePacket >)> selectedGeoChanged
 
boost::signals2::signal< void(std::vector< nt::OpId > selectedNodeIds)> selectedNodesChanged
 
boost::signals2::signal< void(nt::OpId)> operatorCreated
 
boost::signals2::signal< void(nt::OpId)> operatorRemoved
 
boost::signals2::signal< void(nt::Connection)> connectionCreated
 
boost::signals2::signal< void(nt::Connection)> connectionRemoved
 
boost::signals2::signal< void()> networkCleared
 
boost::signals2::signal< void(nt::OpId, Vector2)> nodePositionChanged
 

Detailed Description

The central coordinator of the engine's node system.

The network manager is the central coordinator of the engine’s node system. It manages the lifecycle of operators, including their creation, storage, and validation, while also tracking dependencies between them. Acting as a singleton, it ensures that all parts of the engine work with a single consistent view of the network, providing global access. Beyond just storing operators, it also controls cooking and traversing dependency graphs, ensuring that updates flow correctly through the network when nodes change.

Member Function Documentation

◆ _reset()

void enzo::nt::NetworkManager::_reset ( )

For use in unit tests, resets the state of the operator.

Todo
Find a cleaner way to give tests a fresh manager so this doesn't pollute the public functions.

◆ connectNodes()

nt::Connection enzo::nt::NetworkManager::connectNodes ( OpId inputOpId,
unsigned int inputIndex,
OpId outputOpId,
unsigned int outputIndex )

Wires one node's output into another node's input.

Returns
The connection that was created.
Note
Replaces any connection already on the target input slot.

◆ cookOp()

void enzo::nt::NetworkManager::cookOp ( enzo::nt::OpId opId)

Cooks the given operator.

Parameters
opIdoperator ID to cook

◆ createOperator()

nt::OpId enzo::nt::NetworkManager::createOperator ( op::OpInfo opInfo,
const std::string & path = "",
Vector2 position = {0.f, 0.f} )

Creates a new node in the network.

Parameters
opInfoData designating the properties of the node.
pathOptional explicit path for the node. When empty an auto generated path is used. Supplying it here ensures the path is in place before the operatorCreated signal fires, so observers see the final name from the start.
positionWhere the node sits in the network view.
Returns
The operator ID of the newly created node
Todo
Should probably only have to pass type, now entire opInfo. Fix soon!!!

◆ deleteNode()

void enzo::nt::NetworkManager::deleteNode ( OpId opId)

Deletes a node, pushing an undo command.

Parameters
opIdThe operator to delete.

◆ findOperator()

nt::GeometryOperator * enzo::nt::NetworkManager::findOperator ( const NetworkPath & path,
OpId fromOp = nullOp )

Resolves a node reference to its operator.

Parameters
pathA node path such as "grid_1". An empty node path resolves to fromOp.
fromOpThe node a relative path resolves against, nullOp when there is none.
Returns
The operator, or null when no node matches the path.

◆ findParameter()

std::weak_ptr< prm::NodeParameter > enzo::nt::NetworkManager::findParameter ( const NetworkPath & path,
OpId fromOp = nullOp )

Resolves a parameter reference to its parameter.

Parameters
pathA parameter path such as "grid_1.tx".
fromOpThe node a path with no node part resolves against, nullOp when there is none.
Returns
The parameter, or an empty handle when nothing matches.

◆ isValidOp()

bool enzo::nt::NetworkManager::isValidOp ( nt::OpId opId)

Returns whether the node exists in the network and is valid.

Parameters
opIdOperator ID of the node to check the validity of.

◆ moveNode()

void enzo::nt::NetworkManager::moveNode ( OpId opId,
Vector2 newPos,
bool skipUndo = false )

Moves a node to a new position, pushing an undo command.

Parameters
opIdThe operator to move.
newPosThe new position.
Todo
remove skipUndo argument in favour of a global undo RAII lock

◆ removeOperator()

void enzo::nt::NetworkManager::removeOperator ( OpId opId,
bool removeConnections = true )

Removes an operator from the network.

Note
During a delete the connections are owned by their own undo commands, so callers driving an undo or redo pass removeConnections as false to remove only the bare node.
Parameters
opIdThe operator to remove.
removeConnectionsWhen true the operator's connections are removed first.

◆ restoreOperator()

void enzo::nt::NetworkManager::restoreOperator ( OpId opId,
op::OpInfo opInfo )

Restores a previously removed operator with a specific OpId.

Note
This does not restore the state the node was in, only creates a new node with the given id.
Todo
maybe replace with createNodeWithId
Parameters
opIdThe operator ID to restore.
opInfoThe operator info.
positionThe position to restore the operator at.

◆ setSelectedNode()

void enzo::nt::NetworkManager::setSelectedNode ( OpId opId,
bool selected,
bool add = false )

Set the selection state for the given node.

Parameters
opIdThe node to set the state on.
selectedThe selection state, true selects the node, false unselects it.
addBy default all other nodes are unselected, this parameter allows adding a selected node without deslecting any others.

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