NodesGraphModelInterface Class Reference

#include <nodesgraph.h>

Inheritance diagram for NodesGraphModelInterface:

Detailed Description

A NodesGraphModelRef is an implementation of GraphModelInterface which wraps a NodeSystem. There may be more than one model working on the same NodeSystem reference, this is handled by a shared NodeSystemManagerRef: Each NodesGraphModelRef is a certain view on the NodeSystem with individual filter settings and root paths, and the manager coordinates the accesses of the views.

NodesGraphModelClass is the base implementation of this interface. It has to be used as base class for custom implementations.

Public Member Functions

MAXON_METHOD Result< NodeSystemManagerRef > CreateManager () const
 
MAXON_METHOD Result< void > Init (const NodeSystem &system, const AssetRepositoryRef &lookup, NodeSystemManagerInterface::FILTER filter=NodeSystemManagerInterface::FILTER::NONE, Bool supportRollback=true)
 
MAXON_METHOD const AssetRepositoryRef & GetLookupRepository () const
 
MAXON_METHOD const NodeSystemManagerRef & GetManager () const
 
MAXON_METHOD Result< NodesGraphModelRef > CreateView (NodeSystemManagerInterface::FILTER filter, const NodePath &rootPath)
 
MAXON_METHOD NodeSystemManagerInterface::FILTER GetNodeFilter ()
 
MAXON_METHOD Wires GetWireFilter ()
 
MAXON_METHOD NodeSystem GetNodeSystem ()
 
MAXON_METHOD const NodeSystemGetBase (const GraphNode &node)
 
MAXON_METHOD Result< BoolGetAllBases (const GraphNode &node, const ValueReceiver< const NodeSystem & > &receiver)
 
MAXON_METHOD const NodeTemplate & GetTemplate (const GraphNode &node)
 
MAXON_METHOD Result< BoolGetAllTemplates (const GraphNode &node, const ValueReceiver< const NodeTemplate & > &receiver)
 
MAXON_METHOD Result< NodeSystemInterface * > GetMutableNodeSystem (Bool outsideOfTransaction=false)
 
 MAXON_USING (GraphModelInterface::AddChild)
 
MAXON_METHOD Result< GraphNodeAddChild (const Id &childId, const NodeSystem &base)
 
MAXON_FUNCTION Result< GraphNodeAddChild (const Id &childId, const NodeTemplate &templ, const TemplateArguments &args=maxon::DefaultValue< const TemplateArguments & >())
 
MAXON_METHOD Result< void > ReplaceChild (const GraphNode &childNode, const NodeSystem &base, const HashMap< NodePath, NodePath > &portMap=GetZeroRef< HashMap< NodePath, NodePath >>())
 
MAXON_METHOD Result< GraphNodeMoveToGroup (const NodeSystem &base, const Id &groupId, const Block< const GraphNode > &selection)
 
MAXON_METHOD Result< HashMap< InternedId, InternedId > > Ungroup (const GraphNode &group)
 
MAXON_METHOD Result< AssetDescription > MoveToAsset (const GraphNode &node, const AssetRepositoryRef &repository, const Id &assetId, const Delegate< Result< void >(const MutableRoot &rootNode)> &assetFinalizer)
 
MAXON_METHOD Result< void > ReplaceBase (const GraphNode &node, const NodeSystem &newBase)
 
MAXON_METHOD Result< BoolGetSupportedAssets (const ValueReceiver< const AssetDescription & > &receiver)
 
MAXON_METHOD const GNodeHandlePrivateGetHandle (const GraphNode &node)
 
MAXON_METHOD Result< GNodePrivateToGNode (const GraphNode &node, NODE_KIND mask)
 
MAXON_METHOD Result< MutableGNodePrivateToMutableGNode (const GraphNode &node, NODE_KIND mask)
 
MAXON_METHOD Result< BoolGetAllAssetIds (const GraphNode &node, const ValueReceiver< const IdAndVersion & > &receiver)
 
MAXON_METHOD Result< AssetDescription > MoveGroupToAsset (const GraphNode &node, const AssetRepositoryRef &repository, const Id &assetId, Bool overwrite, const Delegate< Result< void >(const MutableRoot &rootNode)> &assetFinalizer)
 
MAXON_METHOD Result< void > ChangeAssetToEditableGroup (const GraphNode &node, const Delegate< Result< void >(const MutableRoot &rootNode)> &groupFinalizer)
 

Protected Member Functions

MAXON_METHOD Result< void > CopyToImpl (NodesGraphModelImpl &dst) const
 
MAXON_METHOD Result< void > PrivateInit ()
 
MAXON_METHOD Result< NodesGraphModelRef > CreateView (NodeSystemManagerInterface::FILTER filter, const NodePath &rootPath, const Class<> &graphModelClass)
 

Private Member Functions

 MAXON_INTERFACE (NodesGraphModelInterface, MAXON_REFERENCE_NORMAL, "net.maxon.node.interface.nodesgraphmodel", MAXON_IMPLEMENTATION_MODULE("net.maxon.nodes"))
 
MAXON_METHOD Result< ForwardRef< UserStateDerivationRef > > CreateUserStateDerivation (const Block< const Id > &categories, Bool lazy)
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( NodesGraphModelInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.node.interface.nodesgraphmodel"  ,
MAXON_IMPLEMENTATION_MODULE("net.maxon.nodes")   
)
private

◆ CreateManager()

MAXON_METHOD Result<NodeSystemManagerRef> CreateManager ( ) const

Creates a new manager to be used for this graph model. This method should not be invoked by user code, however you can override the default implementation to create a customized manager.

Returns
A new manager to manage this graph model.

◆ Init()

MAXON_METHOD Result<void> Init ( const NodeSystem system,
const AssetRepositoryRef &  lookup,
NodeSystemManagerInterface::FILTER  filter = NodeSystemManagerInterface::FILTER::NONE,
Bool  supportRollback = true 
)

Initializes a new NodesGraphModelRef view for the node system. Also a NodeSystemManagerRef is created which manages the NodesGraphModelRef and possible further views.

Parameters
[in]systemThe initial state of the node system.
[in]lookupThe asset search scope to use for the graph model.
[in]filterThe filter to use for the view.
[in]supportRollbackUse true if GraphTransaction::Rollback shall be supported by the graph model. This keeps a copy of the original state of the node system before a transaction is started.
Returns
A new NodesGraphModelRef view for system. @MAXON_ANNOTATION{returnsThis}

◆ GetLookupRepository()

MAXON_METHOD const AssetRepositoryRef& GetLookupRepository ( ) const

Returns the asset repository to use for lookups for the node graph. This repository is used whenever an asset is looked up.

Returns
The asset repository for lookup.

◆ GetManager()

MAXON_METHOD const NodeSystemManagerRef& GetManager ( ) const

Returns the manager which manages this graph model. The manager may manage more than one graph model, each model represents a specific view on the underlying node system.

Returns
The manager of this graph.

◆ CreateView() [1/2]

MAXON_METHOD Result<NodesGraphModelRef> CreateView ( NodeSystemManagerInterface::FILTER  filter,
const NodePath &  rootPath 
)

Creates a new view for the node system of this view. The returned view will be managed by the same NodeSystemManagerRef as this view.

Note
CreateView does not call Init (just PrivateInit).
Parameters
[in]filterThe filter to use for the view. If this view is read-only, the FILTER::READ_ONLY flag will be set implicitly.
[in]rootPathThe absolute path to the root node of the new view. Use this if the new view shall not represent the whole graph, but only a node and its inner parts. Note that this is an absolute path, so the path of the current view is always ignored.
Returns
A new NodesGraphModelRef view for the same node system.

◆ GetNodeFilter()

Returns flags applied to GetNode and other GraphModelInterface methods.

Returns
The node filtering flags of the view.

◆ GetWireFilter()

MAXON_METHOD Wires GetWireFilter ( )

Returns flags applied to GetConnections other GraphModelInterface methods.

Returns
The node filtering flags of the view.

◆ GetNodeSystem()

MAXON_METHOD NodeSystem GetNodeSystem ( )

Returns the node system reference wrapped by this graph. The node system itself may change over time due to its copy-on-write nature.

Returns
The underlying node system.

◆ GetBase()

MAXON_METHOD const NodeSystem& GetBase ( const GraphNode node)

◆ GetAllBases()

MAXON_METHOD Result<Bool> GetAllBases ( const GraphNode node,
const ValueReceiver< const NodeSystem & > &  receiver 
)

Recursively finds all the bases of a node or port. This is useful for ports which are made from an asset and resource different then their ancestor node.

Parameters
[in]nodeThe node for which we want all base NodeSystem.
[in]receiverValueReceiver or Array that will receive all the base NodeSystem found.
Returns
False if the receiver cancelled further evaluation, true otherwise.

◆ GetTemplate()

MAXON_METHOD const NodeTemplate& GetTemplate ( const GraphNode node)

Returns the NodeTemplate which instantiated node.

Parameters
[in]nodeThe node for which we want the template.
Returns
The NodeTemplate which instantiated the NodeSystem of node, or a null reference.

◆ GetAllTemplates()

MAXON_METHOD Result<Bool> GetAllTemplates ( const GraphNode node,
const ValueReceiver< const NodeTemplate & > &  receiver 
)

Recursively finds all the templates of a node or port. This is useful for ports which are made from an asset and resource different then their ancestor node.

Parameters
[in]nodeThe node for which we want all templates.
[in]receiverValueReceiver or Array that will receive all the NodeTemplate found.
Returns
False if ValueReceiver was canceled. True otherwise.

◆ GetMutableNodeSystem()

MAXON_METHOD Result<NodeSystemInterface*> GetMutableNodeSystem ( Bool  outsideOfTransaction = false)

Returns a pointer to the node system in mutable state. When outsideOfTransaction is false (the default) a GraphTransaction has to be active, otherwise an IllegalStateError is returned. When outsideOfTransaction is true the NodeSystem is made writable like a usual copy-on-write reference, you should use this only to set values of attributes which don't need validation or notification.

Parameters
[in]outsideOfTransactionUsually false (the default), use true for a modification which shall bypass the normal validation and notification mechanism.
Returns
Pointer to the underlying node system with write access.

◆ MAXON_USING()

MAXON_USING ( GraphModelInterface::AddChild  )

◆ AddChild() [1/2]

MAXON_METHOD Result<GraphNode> AddChild ( const Id childId,
const NodeSystem base 
)

Adds an instance of a node system as child of the root node to this graph. If #childId is empty, a UUID will be chosen as identifier of the child, otherwise #childId. In the latter case it is an error if this root node already has a child with that identifier.

Parameters
[in]childIdIdentifier for the child node (if empty, a UUID is chosen).
[in]baseNode system to add as an instance.
Returns
A GraphNode referencing the added child.

◆ AddChild() [2/2]

MAXON_FUNCTION Result<GraphNode> AddChild ( const Id childId,
const NodeTemplate &  templ,
const TemplateArguments args = maxon::DefaultValue< const TemplateArguments & >() 
)

Adds an instance of a node system as child of the root node to this graph. If #childId is empty, a UUID will be chosen as identifier of the child, otherwise #childId. In the latter case it is an error if this root node already has a child with that identifier.

Parameters
[in]childIdIdentifier for the child node (if empty, a UUID is chosen).
[in]templNodeTemplate of which an instantiation shall be added as an instance to the root node.
[in]argsTemplate arguments for templ.
Returns
A GraphNode referencing the added child.

◆ ReplaceChild()

MAXON_METHOD Result<void> ReplaceChild ( const GraphNode childNode,
const NodeSystem base,
const HashMap< NodePath, NodePath > &  portMap = GetZeroRef< HashMap< NodePath, NodePath >>() 
)

Replaces the given child node with an instance of a node system. This removes the original child, adds an instance of base as new child (with the same identifier), and finally tries to re-establish connections and attribute values of the original node at the new node.

Parameters
[in]childNodeThe child node which shall be replaced.
[in]baseNode system to use for the replacement.
[in]portMapAn optional port mapping from old port paths to new port paths, see MutableRoot::ReplaceChild.

◆ MoveToGroup()

MAXON_METHOD Result<GraphNode> MoveToGroup ( const NodeSystem base,
const Id groupId,
const Block< const GraphNode > &  selection 
)

Groups the selection of nodes of this graph into a new group node. The new group node will be set up as an instance of base.

All selected nodes are moved to the group using their original identifiers, including inner connections. Afterwards the group is finalized and an instance of the group is added to this graph using the given groupId. Connections which leave the group are kept by adding ports to the group node as needed, and connecting them correspondingly. If the used group node already has ports, these will be used where identifiers match.

Parameters
[in]baseThe base NodeSystem for the group. If null, an instantiation of the NODE::GROUP template is used.
[in]groupIdIdentifier for the new group within this node system (if empty, a UUID is chosen).
[in]selectionA selection of nodes. Only nodes which are direct children of the root node of this view are considered.
Returns
A GraphNode referencing the added child.
See also
MutableRoot::MoveToGroup

◆ Ungroup()

MAXON_METHOD Result<HashMap<InternedId, InternedId> > Ungroup ( const GraphNode group)

Dissolves the given group into its children. This moves all children of group including their inner connections to the parent of group. External connections (from the group to other nodes) are moved to the inner nodes as well.

Parameters
[in]groupThe group node to dissolve.
Returns
The mapping from original identifiers within the group to the new identifiers used at parent level.
See also
MutableNode::Ungroup

◆ MoveToAsset()

MAXON_METHOD Result<AssetDescription> MoveToAsset ( const GraphNode node,
const AssetRepositoryRef &  repository,
const Id assetId,
const Delegate< Result< void >(const MutableRoot &rootNode)> &  assetFinalizer 
)

Makes an asset for the given node and replaces the node by a reference to that asset.

Parameters
[in]nodeThe node which shall be made an asset.
[in]repositoryThe asset repository where the node asset shall be stored.
[in]assetIdThe asset identifier to use. This must not be empty.
[in]overwriteTrue to overwrite last version of the asset with identifier #assetId, false to create a new version.
[in]assetFinalizerThis Delegate is called right before the asset is stored. This allows to do some finalization on the node system.
Returns
The AssetDescription for the new asset.

◆ ReplaceBase()

MAXON_METHOD Result<void> ReplaceBase ( const GraphNode node,
const NodeSystem newBase 
)

Replaces the base node system of the given node with another one.

Parameters
[in]nodeThe node whose base shall be replaced, either the root node or a group node.
[in]newBaseThe new base node system to use for node.

◆ GetSupportedAssets()

MAXON_METHOD Result<Bool> GetSupportedAssets ( const ValueReceiver< const AssetDescription & > &  receiver)

Yields the descriptions of all node template assets which are supported by this graph to receiver.

Parameters
[in]receiverAll supported assets are reported to this receiver.
Returns
False if the receiver cancelled further evaluation, true otherwise.

◆ CreateUserStateDerivation()

MAXON_METHOD Result<ForwardRef<UserStateDerivationRef> > CreateUserStateDerivation ( const Block< const Id > &  categories,
Bool  lazy 
)
private

◆ PrivateGetHandle()

MAXON_METHOD const GNodeHandle& PrivateGetHandle ( const GraphNode node)

◆ PrivateToGNode()

MAXON_METHOD Result<GNode> PrivateToGNode ( const GraphNode node,
NODE_KIND  mask 
)

◆ PrivateToMutableGNode()

MAXON_METHOD Result<MutableGNode> PrivateToMutableGNode ( const GraphNode node,
NODE_KIND  mask 
)

◆ GetAllAssetIds()

MAXON_METHOD Result<Bool> GetAllAssetIds ( const GraphNode node,
const ValueReceiver< const IdAndVersion & > &  receiver 
)

Recursively finds all the node asset identifier and version of a node. The top level assets will be reported first.

Parameters
[in]nodeThe node for which we want all templates (NODE_KIND::NODE is mandatory).
[in]receiverValueReceiver or Array that will collect all asset identifiers found.
Returns
False if ValueReceiver was by the #receiver before last asset was reached. True otherwise.

◆ CopyToImpl()

MAXON_METHOD Result<void> CopyToImpl ( NodesGraphModelImpl &  dst) const
protected

◆ PrivateInit()

MAXON_METHOD Result<void> PrivateInit ( )
protected

Common init code used by Init method and CreateView method can be placed here.

Note
CreateView does not call Init.
Returns
OK on success.

◆ CreateView() [2/2]

MAXON_METHOD Result<NodesGraphModelRef> CreateView ( NodeSystemManagerInterface::FILTER  filter,
const NodePath &  rootPath,
const Class<> &  graphModelClass 
)
protected

Creates a view of the node system using the given class.

Parameters
[in]filterThe filter to use for the view.
[in]rootPathThe path to the root node of the view. Use this if the view shall not represent the whole graph, but only a node and its inner parts.
[in]graphModelClassThe class to use. Usually "self.GetClass()" is used internally to keep the same model implementation.
Returns
A GraphModelInterface reference, could be "this" if arguments yield no change.

◆ MoveGroupToAsset()

MAXON_METHOD Result<AssetDescription> MoveGroupToAsset ( const GraphNode node,
const AssetRepositoryRef &  repository,
const Id assetId,
Bool  overwrite,
const Delegate< Result< void >(const MutableRoot &rootNode)> &  assetFinalizer 
)

Makes an asset for the given node and replaces the node by a reference to that asset.

Parameters
[in]nodeThe node which shall be made an asset.
[in]repositoryThe asset repository where the node asset shall be stored.
[in]assetIdThe asset identifier to use. This must not be empty.
[in]overwriteTrue to overwrite last version of the asset with identifier #assetId, false to create a new version.
[in]assetFinalizerThis Delegate is called right before the asset is stored. This allows to do some finalization on the node system.
Returns
The AssetDescription for the new asset.

◆ ChangeAssetToEditableGroup()

MAXON_METHOD Result<void> ChangeAssetToEditableGroup ( const GraphNode node,
const Delegate< Result< void >(const MutableRoot &rootNode)> &  groupFinalizer 
)

Changes a NodeTemplate instance into an editable group.

Parameters
[in]nodeThe node which shall be made an editable group.
[in]groupFinalizerThis Delegate is called right before the editable group replaces the original node. This allows to do some finalization on the node system.
Returns
OK on success.