GraphModelInterface Manual

About

A maxon::GraphModelInterface contains a basic graph model containing a hierarchy of nodes and a collection of connections between these nodes. It is reused as a node material's node system with maxon::nodes::NodesGraphModel (see NodesGraphModelInterface Manual).

Nodes

The maxon::GraphNode nodes stored in the model are accessed with:

// This example accesses the root node of the given model in two different ways.
// get root node
const maxon::GraphNode rootNode = model.GetRoot();
// or get root path
const maxon::NodePath rootPath = model.GetRootPath();
const maxon::GraphNode rootNodeFromPath = model.GetNode(rootPath);
Definition: graph.h:1950

See GraphNodes Manual.

Edit

Editing a maxon::GraphModelInterface reference is done through transactions:

Additionally, information relative to a maxon::GraphModelInterface reference can be retrieved with:

Note
A graph model may only be modified when there is an active transaction.

A change list stores changes and allows to reproduce these changes on a different graph.

// This example obtains a node graph from a node material and inserts a new node.
// get graph
const maxon::nodes::NodesGraphModelRef& nodeGraph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;
if (nodeGraph.IsReadOnly())
return maxon::IllegalStateError(MAXON_SOURCE_LOCATION);
// start a new change list if we want to apply the changes also to a different graph
nodeGraph.StartNewChangeList() iferr_return;
// start transaction
maxon::GraphTransaction transaction = nodeGraph.BeginTransaction() iferr_return;
// prepare for adding a new node
const maxon::Id nodeAssetId { "net.maxonexample.noderenderer.usernode" };
const maxon::AssetRepositoryRef& repository = maxon::AssetInterface::GetBuiltinRepository();
maxon::nodes::NodeTemplate nodeTemplate = maxon::nodes::NodesLib::LoadTemplate(repository, nodeAssetId) iferr_return;
// add new node
// leave the 'childId' parameter empty to create a UUID
maxon::GraphNode userGraphNode = nodeGraph.AddChild(maxon::Id(), nodeTemplate) iferr_return;
// set node name
userGraphNode.SetValue<decltype(maxon::NODE::BASE::NAME)>("My user node"_s) iferr_return;
// commit transaction
transaction.Commit() iferr_return;
// this change list contains the latest changes
const maxon::ChangeList& list = nodeGraph.GetChangeList();
static MAXON_METHOD const AssetRepositoryRef & GetBuiltinRepository()
Result< Bool > SetValue(const InternedId &attr, ForwardingDataPtr &&value, Bool checkAndInvalidate=true) const
Definition: graph.h:1698
Definition: graph.h:979
Result< void > Commit(const DataDictionary &userData=GetPtrSizedZeroRef< DataDictionary >(), Bool validate=true)
Definition: apibaseid.h:253
static MAXON_METHOD Result< NodeTemplate > LoadTemplate(const AssetRepositoryRef &repo, const Id &assetId)
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
PyWideStringList * list
Definition: initconfig.h:447
#define iferr_return
Definition: resultbase.h:1519

Related observables are:

  • ObservableTransactionStarted: Informs about the start of a transaction.
  • ObservableTransactionCommitted: Informs about the commit of a transaction.
  • ObservableTransactionRolledBack: Informs about the rollback of a transaction.
// This example stores the current modification stamp and registers a transaction observer.
g_timeStamp = model.GetModificationStamp();
model.ObservableTransactionCommitted().AddObserver(ObserveCommit) iferr_return;
// This observer function accesses all modifications since the last change
// and checks if a node has been added.
static void ObserveCommit(const maxon::GraphModelRef& graph, const maxon::DataDictionary& userData)
{
{
DiagnosticOutput("Error @ in observer.", err);
return;
};
graph.GetModificationsSince(g_timeStamp,
{
// check if node was added
{
DiagnosticOutput("New Node: @", node.GetId());
return false;
}
return true;
// store time stamp
g_timeStamp = graph.GetModificationStamp();
}
MODIFIED
These flags are reported by GetModificationsSince() to tell which properties of the node have changed...
Definition: graph.h:694
@ NODE_ADDED
The node has been added.
Definition: resultbase.h:766
void * userData
Definition: fileobject.h:20
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_scope_handler
Definition: resultbase.h:1402
Definition: node.h:10

Attributes

A graph model can store attributes:

The attribute IDs can be found in graphattribs.h and portattributes.h.

Selection

Selection state can be retrieved with the maxon::GraphModelHelper interface and the next methods:

Miscellaneous

Further functions are:

Further utility functions are found in maxon::GraphLib.