#include <graph.h>
GraphModelInterface is an abstraction of a hierarchical graph. A GraphModelInterface has a single root node (see GetRoot()). The root node and any other node may have an arbitrary number of child nodes. Also each node may have a number of input ports and output ports, and those ports may have nested ports, too. So nodes and ports of a graph can be arranged in a single tree, for example:
In fact, GraphModelInterface represents nodes and ports by the same class GraphNode. To distinguish between the different kinds of a GraphNode, a value of type NODE_KIND is returned by GraphNode::GetKind(). The example tree shows the possible kinds in parentheses:
It is not required for an implementation of GraphModelInterface to support arbitrary nestings. For example, the implementation for nodes supports arbitrarily nested ports, but depending on its filter settings it doesn't support nodes nested within other nodes.
In addition to the tree of nodes and ports, a hierarchical graph also has a number of connections between ports. They are represented by GraphConnection. Typically a connection goes from an output port to an input port, but this is not always the case. The following connections are allowed:
In all cases it doesn't matter if the ports are top-level ports or nested ports. This is an example graph which shows all four cases: @graph +-Root-------------------------------------—+ | ,-------------—> p o | +-N------—+ / | | | p o -* | o x --> o x —> x o \ +-M--—+ | o y --> o y —> y o `--> o p q o --> q o | +--------—+ +----—+ | +------------------------------------------—+ @endgraph
Each node may have attributes. An attribute is identified by an InternedId, typically this id is defined together with the type of the attribute value by MAXON_ATTRIBUTE.
Public Types | |
enum class | GET_CONNECTIONS_MODE { NONE , CONNECTIONS , INDUCED_DEPENDENCIES , DERIVATION_FILTER , EXTERNAL_CONNECTIONS , WITHOUT_INHIBITED , INCLUDE_HIDDEN , INTERNAL_CONNECTIONS , SKIP_REROUTER } |
enum class | MODIFIED { NONE , COMPLETE , DIRECT_ATTRIBUTE , DIRECT_META_ATTRIBUTE , INHERITED_ATTRIBUTE , SYNTHESIZED_ATTRIBUTE , USER_STATE_ATTRIBUTE , NODE_ADDED , CHILD_REMOVED , INPUT_CONNECTION , OUTPUT_CONNECTION , SPECIAL0 , SPECIAL1 , SPECIAL_NAME , ALL_MASK , DERIVED_ATTRIBUTE_MASK , DIRECT_ATTRIBUTE_MASK , DATA_ATTRIBUTE_MASK , ATTRIBUTE_MASK , CONNECTION_MASK , NODE_MASK , STRUCTURE_MASK } |
Public Member Functions | |
enum maxon::GraphModelInterface::GET_CONNECTIONS_MODE | MAXON_ENUM_FLAGS_CLASS (GET_CONNECTIONS_MODE) |
MAXON_METHOD const NodePath & | GetRootPath () |
MAXON_METHOD GraphNode | GetRoot () |
MAXON_METHOD Bool | IsReadOnly () |
MAXON_METHOD GraphNode | GetNode (const NodePath &path, Bool filtered=true) |
MAXON_METHOD Result< GraphNode > | GetNode (const PathBlock &path, Bool filtered=true) |
MAXON_METHOD Result< void > | Validate () |
MAXON_METHOD void | ResetUserState (const InternedId &attr) |
MAXON_METHOD const GraphAttribute & | GetGraphAttribute (const InternedId &attr) |
MAXON_METHOD GraphAttribute::FLAGS | GetGraphAttributeFlags (const InternedId &attr) |
MAXON_FUNCTION Result< GraphTransaction > | BeginTransaction (const DataDictionary &userData=GetPtrSizedZeroRef< DataDictionary >()) |
MAXON_METHOD Int | GetTransactionCount () |
MAXON_METHOD Result< GraphNode > | AddChild (const Id &childId, const Id &nodeId, const DataDictionary &args=DataDictionary::NullValue()) |
MAXON_OBSERVABLE (void, ObservableTransactionStarted,(const GraphModelRef &graph, const DataDictionary &userData), ObservableCombinerRunAllComponent) | |
MAXON_OBSERVABLE (void, ObservableTransactionCommitted,(const GraphModelRef &graph, const DataDictionary &userData), ObservableCombinerRunAllComponent) | |
MAXON_OBSERVABLE (void, ObservableTransactionRolledBack,(const GraphModelRef &graph), ObservableCombinerRunAllComponent) | |
MAXON_METHOD TimeStamp | GetModificationStamp () |
enum maxon::GraphModelInterface::MODIFIED | MAXON_ENUM_FLAGS_CLASS (MODIFIED) |
MAXON_METHOD Result< Bool > | GetModificationsSince (TimeStamp stamp, const ValueReceiver< const GraphNode &, MODIFIED > &receiver, Bool filtered=true) |
MAXON_METHOD MODIFIED | GetModificationsSince (TimeStamp stamp) |
MAXON_METHOD const ChangeList & | GetChangeList () |
MAXON_METHOD Result< ChangeList > | StartNewChangeList () |
MAXON_METHOD Result< ChangeList > | Apply (const ChangeList &list, Bool inverse) |
MAXON_METHOD Result< GraphModelRef > | CreateCopyOfSelection (const Block< const GraphNode > &selection) |
MAXON_METHOD Result< HomogenousTupleType< 3, HashMap< InternedId, InternedId > > > | Merge (const GraphModelRef &other) |
MAXON_METHOD const Data * | GetUserState (const NodePath &path, const InternedId &attr) |
MAXON_METHOD Result< HomogenousTupleType< 3, HashMap< InternedId, InternedId > > > | Duplicate (const Block< const GraphNode > &selection, Bool withConnections) |
Private Member Functions | |
MAXON_INTERFACE (GraphModelInterface, MAXON_REFERENCE_NORMAL, "net.maxon.graph.interface.graphmodel") | |
Friends | |
class | GraphNode |
class | GraphTransaction |
template<typename BASE > | |
class | GraphNodeFunctions |
|
strong |
This enum is needed for GraphNode::GetConnections to control which connections shall be reported. At least one of CONNECTIONS or INDUCED_DEPENDENCIES has to be set.
Enumerator | |
---|---|
NONE | No flags. |
CONNECTIONS | Report normal connections, the default. |
INDUCED_DEPENDENCIES | Report induced dependencies (due to loop dependencies or sequencing). |
DERIVATION_FILTER | Apply the derivation filter. |
EXTERNAL_CONNECTIONS | Only report connections which leave the node to which the port belongs (so they are external to the node). |
WITHOUT_INHIBITED | Don't report inhibited connections (those where Wires::inhibit is present). |
INCLUDE_HIDDEN | Report connections where the hidden flag is set or which go to hidden ports. |
INTERNAL_CONNECTIONS | Only report connections which don't leave the node to which the port belongs (so they are internal to the node). |
SKIP_REROUTER | Hop over rerouter nodes. |
|
strong |
These flags are reported by GetModificationsSince() to tell which properties of the node have changed.
Enumerator | |
---|---|
NONE | No flag. |
COMPLETE | The graph has changed completely. This is only reported for the root node. |
DIRECT_ATTRIBUTE | Direct non-meta attributes of the node have changed. |
DIRECT_META_ATTRIBUTE | Direct meta attributes of the node have changed (see GraphAttributeInterface::FLAGS::META). |
INHERITED_ATTRIBUTE | Inherited attributes (derived from left to right) of the node have changed. |
SYNTHESIZED_ATTRIBUTE | Synthesized attributes (derived from right to left) of the node have changed. |
USER_STATE_ATTRIBUTE | User state attributes of the node have changed (see GraphAttributeInterface::FLAGS::USER_STATE). |
NODE_ADDED | The node has been added. |
CHILD_REMOVED | Children of the node have been removed. |
INPUT_CONNECTION | Input connections of the port have changed. |
OUTPUT_CONNECTION | Output connections of the port have changed. |
SPECIAL0 | This is set to indicate a special change, the exact meaning is graph-specific. |
SPECIAL1 | This is set to indicate a special change, the exact meaning is graph-specific. |
SPECIAL_NAME | This is set to indicate a change which affects names of nodes or ports. |
ALL_MASK | A mask containing all possible MODIFIED bits. |
DERIVED_ATTRIBUTE_MASK | Derived attributes of the node have changed. |
DIRECT_ATTRIBUTE_MASK | Mask to test for changes to direct attributes (whether meta or non-meta). |
DATA_ATTRIBUTE_MASK | Mask to test for changes to attributes belonging to the data model of the graph (non-meta, non-user-state attributes). |
ATTRIBUTE_MASK | Mask to test for attribute changes. |
CONNECTION_MASK | Mask to test for connection changes of ports. |
NODE_MASK | Mask to test for added or removed nodes. |
STRUCTURE_MASK | Mask to test for any structural change (changed connections, added or removed nodes). |
|
private |
enum maxon::GraphModelInterface::GET_CONNECTIONS_MODE MAXON_ENUM_FLAGS_CLASS | ( | GET_CONNECTIONS_MODE | ) |
MAXON_METHOD const NodePath& GetRootPath | ( | ) |
Returns the path of the root node of this graph. Usually this is an empty path, but a graph model may be a view of a nested part of an enclosing graph. In the latter case the path points to the root node of the nested part.
MAXON_METHOD GraphNode GetRoot | ( | ) |
Returns the root node of this graph. The whole graph can be traversed starting from the root node.
MAXON_METHOD Bool IsReadOnly | ( | ) |
Checks if this graph is read-only. You can't modify read-only graphs.
MAXON_METHOD GraphNode GetNode | ( | const NodePath & | path, |
Bool | filtered = true |
||
) |
Returns the GraphNode corresponding to path. If no such node exists in the graph, an empty node is returned.
[in] | path | A node path. This has to be an absolute path, so if the current graph is view of a nested part of an enclosing graph, the path has to be the full path starting at the root of the enclosing graph. |
[in] | filtered | With the default value of true the filter settings (if any) of this graph will be used. When false this is disabled, then you'll get a valid GraphNode even for paths which don't belong to this graph, but e.g. to nested graphs which are hidden by the filter settings. |
MAXON_METHOD Result<GraphNode> GetNode | ( | const PathBlock & | path, |
Bool | filtered = true |
||
) |
Returns the GraphNode corresponding to path. If no such node exists in the graph, an empty node is returned.
[in] | path | A node path. This has to be an absolute path, so if the current graph is view of a nested part of an enclosing graph, the path has to be the full path starting at the root of the enclosing graph. |
[in] | filtered | With the default value of true the filter settings (if any) of this graph will be used. When false this is disabled, then you'll get a valid GraphNode even for paths which don't belong to this graph, but e.g. to nested graphs which are hidden by the filter settings. |
MAXON_METHOD Result<void> Validate | ( | ) |
Validates the graph. This is an implementation-specific operation and should be invoked when a batch of changes has been applied to the graph and the graph should be brought into a valid state again. For example, the implementation of GraphModelInterface for nodes may update the type of an output port of a polymorphic node based on the types of the input ports.
MAXON_METHOD void ResetUserState | ( | const InternedId & | attr | ) |
Removes all values for the given user state attribute attr from this graph (so from all of its nodes).
[in] | attr | A user state attribute. |
MAXON_METHOD const GraphAttribute& GetGraphAttribute | ( | const InternedId & | attr | ) |
Returns the GraphAttribute which this graph model uses for the attribute identified by attr. The model may return a null reference if it doesn't provide a GraphAttribute for attr. This doesn't mean that the attribute is unsupported, it just means that there is no need for special handling of the attribute (which would require a GraphAttribute).
[in] | attr | The identifier of the attribute. |
MAXON_METHOD GraphAttribute::FLAGS GetGraphAttributeFlags | ( | const InternedId & | attr | ) |
Returns the GraphAttribute::FLAGS to use for the attribute identified by attr. This allows the graph model to override the default flags of the attribute, for example to mark an attribute as meta attribute.
[in] | attr | The identifier of the attribute. |
MAXON_FUNCTION Result<GraphTransaction> BeginTransaction | ( | const DataDictionary & | userData = GetPtrSizedZeroRef< DataDictionary >() | ) |
Begins a new transaction within which modifications can be made. You have to do this in order to modify the graph, modifications outside of transactions are not allowed (with the exception of changing user state attributes).
If there already is an active transaction, this will create a nested transaction. Otherwise a non-nested transaction starts, only then the observable GraphModelInterface::ObservableTransactionStarted informs its observers about the start of a transaction.
[in] | userData | User data to pass to the observers of GraphModelInterface::ObservableTransactionStarted. Because nested transactions don't trigger the observable, the user data of them is ignored. |
MAXON_METHOD Int GetTransactionCount | ( | ) |
MAXON_METHOD Result<GraphNode> AddChild | ( | const Id & | childId, |
const Id & | nodeId, | ||
const DataDictionary & | args = DataDictionary::NullValue() |
||
) |
Adds an instance of the node given by the identifier nodeId 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.
[in] | childId | Identifier for the child node (if empty, a UUID is chosen). |
[in] | nodeId | Identifier for the type of the node to add. How this is resolved to an actual node type is model-specific. |
[in] | args | Arguments to use for the node creation. The exact meaning is model-specific. |
MAXON_OBSERVABLE | ( | void | , |
ObservableTransactionStarted | , | ||
(const GraphModelRef &graph, const DataDictionary &userData) | , | ||
ObservableCombinerRunAllComponent | |||
) |
Informs about the start of a transaction. This is called during BeginTransaction(), but only for outmost transactions (which aren't nested within other transactions).
[in] | graph | The graph at which the observer was registered. |
[in] | userData | The user data given to GraphModelRef::BeginTransaction(). In case of nested transactions, this is the user data of the outmost (i.e. first) invocation. |
MAXON_OBSERVABLE | ( | void | , |
ObservableTransactionCommitted | , | ||
(const GraphModelRef &graph, const DataDictionary &userData) | , | ||
ObservableCombinerRunAllComponent | |||
) |
Informs about the commit of a transaction. This is called during GraphTransaction::Commit(), but only for outmost transactions (which aren't nested within other transactions).
[in] | graph | The graph at which the observer was registered. |
[in] | userData | The user data given to GraphTransaction::Commit(). In case of nested transactions, this is the merger of the user datas given to all commits. |
MAXON_OBSERVABLE | ( | void | , |
ObservableTransactionRolledBack | , | ||
(const GraphModelRef &graph) | , | ||
ObservableCombinerRunAllComponent | |||
) |
Informs about the rollback of a transaction. This is called during GraphTransaction::Rollback(), but only for outmost transactions (which aren't nested within other transactions).
[in] | graph | The graph at which the observer was registered. |
MAXON_METHOD TimeStamp GetModificationStamp | ( | ) |
Returns a time stamp of this graph which can be used to test for modifications. Each transaction or change of user state increments the stamp. The time stamp is also needed for GetModificationsSince and GraphNodeFunctions::GetAttributeModificationsSince to get all modifications which have happened since then.
enum maxon::GraphModelInterface::MODIFIED MAXON_ENUM_FLAGS_CLASS | ( | MODIFIED | ) |
MAXON_METHOD Result<Bool> GetModificationsSince | ( | TimeStamp | stamp, |
const ValueReceiver< const GraphNode &, MODIFIED > & | receiver, | ||
Bool | filtered = true |
||
) |
Reports all modifications which have been made since the given stamp to the receiver. A typical usage is
[in] | stamp | A reference time stamp. Only modifications newer than this stamp are reported. |
[in] | receiver | Modifications are reported to this receiver. |
[in] | filtered | With the default value of true the filter settings (if any) of this graph will be used, so modifications to nodes which don't pass the filter aren't reported. |
MAXON_METHOD MODIFIED GetModificationsSince | ( | TimeStamp | stamp | ) |
Returns flags which tell which kinds of changes have happened since the given time stamp. From the returned value you can't tell exactly which nodes or ports are affected, but you can tell for example if only attributes have changed or also the structure.
[in] | stamp | A reference time stamp. Only modifications newer than this stamp are reported. |
MAXON_METHOD const ChangeList& GetChangeList | ( | ) |
Returns the change list to which this graph model currently logs its modifications. A newly created graph model doesn't automatically create a change list, so to start logging you need to call StartNewChangeList() once. The change list can be used to undo or redo the changes or even to apply them to a different graph, see Apply().
MAXON_METHOD Result<ChangeList> StartNewChangeList | ( | ) |
Starts a new change list and returns the previous one. Afterwards the graph will log all modifications to the newly created change list. The new change list can be obtained with GetChangeList() or as the result of the next call to StartNewChangeList(). The returned change list contains all modifications which have been made since the previous call to StartNewChangeList(). You can pass it to Apply() to undo or redo the changes or apply them to a different graph.
MAXON_METHOD Result<ChangeList> Apply | ( | const ChangeList & | list, |
Bool | inverse | ||
) |
Applies the given change list to this graph. For an undo set inverse to true, for a redo or if you want to apply the change list to a different graph use false.
[in] | list | Change list to apply. |
[in] | inverse | Use true if the inverse of the change list shall be applied (for an undo), false otherwise. |
MAXON_METHOD Result<GraphModelRef> CreateCopyOfSelection | ( | const Block< const GraphNode > & | selection | ) |
Returns a new graph model which is a copy of the subgraph given by the selection.
[in] | selection | A selection of nodes. Nodes which aren't direct children of this graph are ignored. |
MAXON_METHOD Result<HomogenousTupleType<3, HashMap<InternedId, InternedId> > > Merge | ( | const GraphModelRef & | other | ) |
Merges the other graph into this graph. Top-level nodes and ports are added into this graph using new unique identifiers to prevent naming conflicts. The mapping from the original identifiers of other to the new ones is returned.
[in] | other | Another graph to merge into this graph. |
MAXON_METHOD const Data* GetUserState | ( | const NodePath & | path, |
const InternedId & | attr | ||
) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
MAXON_METHOD Result<HomogenousTupleType<3, HashMap<InternedId, InternedId> > > Duplicate | ( | const Block< const GraphNode > & | selection, |
Bool | withConnections | ||
) |
Duplicates the subgraph given by the selection within this graph. The nodes and ports of the subgraph are added into this graph using new unique identifiers. The mapping from the original identifiers to the new ones is returned.
[in] | selection | A selection of nodes and ports. Nodes/ports which aren't direct children of this graph are ignored. |
[in] | withConnections | True if incoming connections shall be duplicated as well, false otherwise. |
|
friend |
|
friend |
|
friend |