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

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

#include <NetworkManager.h>

Public Member Functions

nt::Networknetwork ()
 Returns the network holding every node, its wiring, and its scopes.
 
auto nodes ()
 Returns an iterable range over all nodes in the network.
 
 NetworkManager (const NetworkManager &obj)=delete
 Deleted the copy constructor for singleton.
 
NodeId createNode (const nt::NodeType &nodeType, const Path &parent=Path("/"), const std::string &name="", Vector2 position={0.f, 0.f})
 Creates a new node inside a scope.
 
NodegetNodeAtPath (const Path &path)
 Returns the node at an exact path, or null when no node is there.
 
ScopegetScope (const Path &path)
 Returns the scope at a path, or null when no scope sits there.
 
std::vector< NodeIdgetChildNodeIds (const Path &scope)
 Returns the ids of the nodes living directly inside a scope, in no particular order.
 
std::optional< NodeIdgetDisplayNode ()
 Returns the node ID for the node with its display flag set. There can only be only be one node 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 isValidNode (nt::NodeId nodeId)
 Returns whether the node exists in the network and is valid.
 
NodegetNode (nt::NodeId nodeId)
 Returns a reference to the Node with the given NodeId.
 
void setDisplayNode (NodeId nodeId)
 Sets given NodeId to be displayed, releasing previous display Node.
 
void clearDisplayFlag ()
 Clears the display flag so no node is displayed.
 
std::optional< NodeIdgetPrimaryNode ()
 Returns the node ID of the primary node, or nullopt when none.
 
void setPrimaryNode (NodeId nodeId)
 Sets the given NodeId as the primary node, releasing the previous one.
 
void clearPrimaryNode ()
 Clears the primary node so none is primary.
 
floatT getFrame () const
 Returns the frame the scene sits on.
 
void setFrame (floatT frame)
 Moves the scene to a frame, clamped to the playback range.
 
intT getStartFrame () const
 Returns the first frame of the playback range.
 
intT getEndFrame () const
 Returns the last frame of the playback range.
 
void setStartFrame (intT frame)
 Sets the frame the playback range starts on.
 
void setEndFrame (intT frame)
 Sets the frame the playback range ends on.
 
floatT getFps () const
 Returns how many frames make up a second of playback.
 
void setFps (floatT fps)
 Sets how many frames make up a second of playback.
 
floatT getTime () const
 Returns the current frame as seconds, where the start of frame 1 is zero.
 
void setSelectedNode (NodeId nodeId, bool selected, bool add=false)
 Set the selection state for the given node.
 
const std::vector< enzo::nt::NodeId > & getSelectedNodes ()
 Returns the NodeIds for all selected nodes.
 
void setSelectedNodes (std::vector< enzo::nt::NodeId > nodeIds)
 Replaces the entire selection with the given set of nodes.
 
void moveNode (NodeId nodeId, Vector2 newPos, bool skipUndo=false)
 Moves a node to a new position, pushing an undo command.
 
void deleteNode (NodeId nodeId)
 Deletes a node, pushing an undo command.
 
void createNodeWithId (NodeId nodeId, const nt::NodeType &nodeType, const Path &path, Vector2 position)
 Creates a node with an identity the caller dictates rather than one picked here.
 
void clear ()
 Clears all nodes and resets the network to its initial state.
 
void cook (enzo::nt::NodeId nodeId)
 Cooks the given node.
 
enzo::NodePacket cookOutput (enzo::nt::NodeId nodeId, unsigned int outputIndex)
 Returns a copy of one of a node's outputs.
 
nt::NetworkGraphgraph ()
 Returns the graph that owns the network's wiring and dependencies.
 
unsigned int getInputCount (NodeId nodeId)
 Returns how many inputs a node currently takes.
 
nt::Connection connectNodes (NodeId inputNodeId, unsigned int inputIndex, NodeId outputNodeId, 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.
 
NodefindNode (const NetworkPath &path, NodeId fromNode=nullNode)
 Resolves a node reference such as "grid1" or "../grid1" to its node.
 
std::weak_ptr< prm::NodeParameterfindParameter (const NetworkPath &path, NodeId fromNode=nullNode)
 Resolves a parameter reference such as "grid1.tx" to its parameter.
 
UndoStackundoStack ()
 
void _reset ()
 For use in unit tests, resets the state of the node.
 

Static Public Member Functions

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

Public Attributes

Signals
boost::signals2::signal< void(std::optional< nt::NodeId >)> 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::optional< nt::NodeId >)> primaryNodeChanged
 
boost::signals2::signal< void(std::shared_ptr< const enzo::NodePacket >)> primaryGeoChanged
 
boost::signals2::signal< void(std::vector< nt::NodeId > selectedNodeIds)> selectedNodesChanged
 
boost::signals2::signal< void(nt::NodeId)> nodeCreated
 
boost::signals2::signal< void(nt::NodeId)> nodeRemoved
 
boost::signals2::signal< void(nt::Connection)> connectionCreated
 
boost::signals2::signal< void(nt::Connection)> connectionRemoved
 
boost::signals2::signal< void()> networkCleared
 
boost::signals2::signal< void(nt::NodeId, Vector2)> nodePositionChanged
 
boost::signals2::signal< void(floatT frame)> frameChanged
 
boost::signals2::signal< void(intT startFrame, intT endFrame)> frameRangeChanged
 
boost::signals2::signal< void(floatT fps)> fpsChanged
 

Detailed Description

The central coordinator of the engine's node system.

The manager owns one nt::Network and drives everything that happens to it. The network holds the nodes, the wiring, and the scopes, while the manager owns the lifecycle around them, so creating and deleting nodes, cooking, undo, selection, and the signals the interface listens to.

Keeping the network a plain value means it can be handed straight to something that only needs to read it, such as the serializer.

Note
A singleton, so every part of the engine works against one network.

Member Function Documentation

◆ _reset()

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

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

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 ( NodeId inputNodeId,
unsigned int inputIndex,
NodeId outputNodeId,
unsigned int outputIndex )

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

Returns
The connection that was created.
Note
A single input port holds one connection, so whatever was on it is replaced.
A multi input port makes room, moving the connections from the index onward up one.

◆ cook()

void enzo::nt::NetworkManager::cook ( enzo::nt::NodeId nodeId)

Cooks the given node.

Parameters
nodeIdnode ID to cook

◆ cookOutput()

NodePacket enzo::nt::NetworkManager::cookOutput ( enzo::nt::NodeId nodeId,
unsigned int outputIndex )

Returns a copy of one of a node's outputs.

Naming the node directly reaches geometry that no connection leads to, such as an output node sitting inside a container's child scope.

Note
The node cooks first, so the geometry is never stale.
Returns
A copy the caller owns, so later cooks of the node leave it untouched.

◆ createNode()

nt::NodeId enzo::nt::NetworkManager::createNode ( const nt::NodeType & nodeType,
const Path & parent = Path("/"),
const std::string & name = "",
Vector2 position = {0.f, 0.f} )

Creates a new node inside a scope.

A node left unnamed takes the type name followed by the first free number, so the first grid placed in a scope becomes "grid1" and the next becomes "grid2". Only siblings have to differ, so each scope numbers its own nodes.

Note
The name is in place before the nodeCreated signal fires, so observers see the final name from the start.
Parameters
nodeTypeData designating the properties of the node.
parentThe scope to create the node inside. The root holds the top level nodes.
nameThe name to give the node. Left empty a free one is picked, and a name already taken by a sibling has a number appended until it is free.
positionWhere the node sits in the network view.
Returns
The node ID of the newly created node
Todo
Take the type name rather than the whole node type.

◆ createNodeWithId()

void enzo::nt::NetworkManager::createNodeWithId ( NodeId nodeId,
const nt::NodeType & nodeType,
const Path & path,
Vector2 position )

Creates a node with an identity the caller dictates rather than one picked here.

Every node enters the network here. createNode picks a free id and name and calls this, while undo brings a deleted node back with the id and path it had, since expressions reference nodes by name and a node returning under a new name would break them.

Note
Throws std::out_of_range when no scope sits at the path's parent.
Only the node itself is created, not the parameter values or connections it had. The undo commands restore those around this call.
Parameters
nodeIdThe node ID to give the node.
nodeTypeThe type of node to create.
pathThe path to place the node at, whose leaf is the node name.
positionWhere the node sits in the network view.

◆ deleteNode()

void enzo::nt::NetworkManager::deleteNode ( NodeId nodeId)

Deletes a node, pushing an undo command.

Note
A node holding a scope takes the nodes living inside it along, and the whole removal undoes as one step.
Parameters
nodeIdThe node to delete.

◆ disconnectNodes()

void enzo::nt::NetworkManager::disconnectNodes ( const nt::Connection & connection)

Removes a wired connection between two nodes.

Note
Leaving a multi input port closes the gap, moving the connections above the index down one.

◆ findNode()

Node * enzo::nt::NetworkManager::findNode ( const NetworkPath & path,
NodeId fromNode = nullNode )
inline

Resolves a node reference such as "grid1" or "../grid1" to its node.

Note
A relative path is read from the scope holding fromNode.

◆ findParameter()

std::weak_ptr< prm::NodeParameter > enzo::nt::NetworkManager::findParameter ( const NetworkPath & path,
NodeId fromNode = nullNode )
inline

Resolves a parameter reference such as "grid1.tx" to its parameter.

Note
A path with no node part resolves against fromNode.

◆ getChildNodeIds()

std::vector< NodeId > enzo::nt::NetworkManager::getChildNodeIds ( const Path & scope)
inline

Returns the ids of the nodes living directly inside a scope, in no particular order.

Note
Nodes deeper inside a nested scope are not included.

◆ getFrame()

floatT enzo::nt::NetworkManager::getFrame ( ) const
inline

Returns the frame the scene sits on.

Note
A fractional frame is allowed, so a sample can fall between two frames.

◆ getInputCount()

unsigned int enzo::nt::NetworkManager::getInputCount ( NodeId nodeId)

Returns how many inputs a node currently takes.

Note
A single port holds one input. A multi input port holds one input per connection it has.

◆ getNodeAtPath()

Node * enzo::nt::NetworkManager::getNodeAtPath ( const Path & path)
inline

Returns the node at an exact path, or null when no node is there.

Note
Takes a resolved absolute path. findNode resolves a reference into one.

◆ getPrimaryNode()

std::optional< nt::NodeId > enzo::nt::NetworkManager::getPrimaryNode ( )

Returns the node ID of the primary node, or nullopt when none.

The primary node is the single node that drives the parameter and geometry panes. There can only be one at a time. It persists when the selection is cleared, unlike the selection itself.

◆ getScope()

Scope * enzo::nt::NetworkManager::getScope ( const Path & path)
inline

Returns the scope at a path, or null when no scope sits there.

Note
The root scope always exists, so getScope("/") never returns null.

◆ getTime()

floatT enzo::nt::NetworkManager::getTime ( ) const
inline

Returns the current frame as seconds, where the start of frame 1 is zero.

Returns
Frame 25 at 24 fps gives 1.0.

◆ isValidNode()

bool enzo::nt::NetworkManager::isValidNode ( nt::NodeId nodeId)

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

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

◆ moveNode()

void enzo::nt::NetworkManager::moveNode ( NodeId nodeId,
Vector2 newPos,
bool skipUndo = false )

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

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

◆ setEndFrame()

void enzo::nt::NetworkManager::setEndFrame ( intT frame)

Sets the frame the playback range ends on.

Note
The start frame moves down with it rather than letting the range invert.

◆ setFps()

void enzo::nt::NetworkManager::setFps ( floatT fps)

Sets how many frames make up a second of playback.

Note
A rate of zero or less is ignored, since it has no time to measure.

◆ setSelectedNode()

void enzo::nt::NetworkManager::setSelectedNode ( NodeId nodeId,
bool selected,
bool add = false )

Set the selection state for the given node.

Parameters
nodeIdThe 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.

◆ setStartFrame()

void enzo::nt::NetworkManager::setStartFrame ( intT frame)

Sets the frame the playback range starts on.

Note
The end frame moves up with it rather than letting the range invert.

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