Dependency graph modifier.
An MDGModifier is used to change the structure of the dependency graph. This includes adding nodes, making new connections, and removing existing connections. To perform operations using an MDGModifier, register all of the changes that are to be made and then call the doIt method to make the changes. Undo is provided through the undoIt method.
Under some situations, a doIt() call may be required to separate some of the operations. The specific case of interest involves performing a disconnect() and a deleteNode() on the same node within the stack of operations.
Assuming that the Maya model has a connected node that was going to be deleted, do the following:
MStatus cmd::redoIt() { MStatus result = dgModifier.disconnect(plugA, plugB); if (!result) ... result = dgModifier.doIt(); if (!result) ... result = dgModifier.deleteNode(plugBNode); if (!result) ... result = dgModifier.doIt(); if (!result) ... return result; }
Then undoIt() can be implemented as:
MStatus cmd::undoIt() { MStatus result = dgModifier.undoIt(); if (!result) ... return result; }
cgfxAttrDef.cpp, cgfxAttrDef.h, cgfxShaderCmd.cpp, cgfxShaderCmd.h, cgfxShaderNode.cpp, closestPointOnCurveCmd.cpp, createClipCmd.cpp, D3DResourceManager.cpp, deletedMsgCmd.cpp, geometrySurfaceConstraint.cpp, geometrySurfaceConstraint.h, GLSLShaderNode.cpp, GLSLShaderNode.h, latticeNoiseCmd.cpp, narrowPolyViewer.h, pointOnMeshCmd.cpp, polyModifierCmd.cpp, polyModifierCmd.h, and polyPrimitiveCmd.cpp.
#include <MDGModifier.h>
Public Member Functions |
|
MDGModifier () | |
The class constructor. |
|
virtual | ~MDGModifier () |
The class destructor. |
|
MObject | createNode (const MTypeId &typeId, MStatus *ReturnStatus=NULL) |
This method adds an operation to this
dependency graph modifier that will add a new dependency graph node
of the given type to the dependency graph. |
|
MObject | createNode (const MString &type, MStatus *ReturnStatus=NULL) |
This method adds an operation to this
dependency graph modifier that will add a new dependency graph node
of the given type to the dependency graph. |
|
MStatus | deleteNode (const MObject &node) |
This method adds an operation to this
dependency graph modifier that will delete a dependency graph node
from the dependency graph. |
|
MStatus | renameNode (const MObject &node, const MString &newName) |
This method adds an operation to this
dependency graph modifier that will rename a dependency graph node.
|
|
MStatus | setNodeLockState (const MObject &node, bool newState) |
This method adds an operation to this
dependency graph modifier that will set the lock state of the node.
|
|
MStatus | connect (const MObject &sourceNode, const MObject &sourceAttr, const MObject &destNode, const MObject &destAttr) |
Adds an operation to this dependency graph
modifier that connects two attributes of two nodes in the
dependency graph. |
|
MStatus | disconnect (const MObject &sourceNode, const MObject &sourceAttr, const MObject &destNode, const MObject &destAttr) |
Adds an operation to this dependency graph
modifier that disconnects two attributes of two nodes in the
dependency graph. |
|
MStatus | connect (const MPlug &source, const MPlug &dest) |
Adds an operation to this dependency graph
modifier that connects two plugs in the dependency graph. |
|
MStatus | disconnect (const MPlug &source, const MPlug &dest) |
Adds an operation to this dependency graph
modifier that disconnects two plugs in the dependency graph.
|
|
MStatus | addAttribute (const MObject &node, const MObject &attribute) |
Add a new dynamic attribute to the given
dependency node. |
|
MStatus | removeAttribute (const MObject &node, const MObject &attribute) |
Removes a dynamic attribute from the given
dependency node. |
|
MStatus | addExtensionAttribute (const MNodeClass &nodeClass, const MObject &attribute) |
Add a new extension attribute to the given
dependency node class. |
|
MStatus | removeExtensionAttribute (const MNodeClass &nodeClass, const MObject &attribute) |
Removes an extension attribute from the
given dependency node type. |
|
MStatus | removeExtensionAttributeIfUnset (const MNodeClass &nodeClass, const MObject &attribute) |
Removes an extension attribute from the
given dependency node type but only if there are no nodes in the
graph with non-default values for this attribute. |
|
MStatus | linkExtensionAttributeToPlugin (const MObject &plugin, const MObject &attribute) |
The plugin calls this to indicate that the
extension attribute defines part of the plugin, regardless of the
node type to which it attaches itself. |
|
MStatus | unlinkExtensionAttributeFromPlugin (const MObject &mPlugin, const MObject &mAttribute) |
Tells a plugin that it no longer requires an
extension attribute for operation. |
|
MStatus | commandToExecute (const MString &command) |
Adds an operation to this dependency graph
modifier that executes a MEL command. |
|
MStatus | newPlugValue (const MPlug &plug, MObject &plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug value. |
|
MStatus | newPlugValueBool (const MPlug &plug, bool plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a boolean value. |
|
MStatus | newPlugValueChar (const MPlug &plug, char plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a char value. |
|
MStatus | newPlugValueDouble (const MPlug &plug, double plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a double value. |
|
MStatus | newPlugValueFloat (const MPlug &plug, float plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a float value. |
|
MStatus | newPlugValueInt (const MPlug &plug, int plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to an int value. |
|
MStatus | newPlugValueMAngle (const MPlug &plug, const MAngle &plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to an MAngle
value. |
|
MStatus | newPlugValueMDistance (const MPlug &plug, const MDistance &plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to an MDistance value. |
|
MStatus | newPlugValueMTime (const MPlug &plug, const MTime &plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to an MTime
value. |
|
MStatus | newPlugValueShort (const MPlug &plug, short plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a short value. |
|
MStatus | newPlugValueString (const MPlug &plug, const MString &plugValue) |
Adds an operation to this dependency graph
modifier that sets a plug to a string value. |
|
MStatus | doIt () |
Executes all of the operations that have
been given to this modifier. |
|
MStatus | undoIt () |
Undoes all of the operations that have been
given to this modifier. |
|
MStatus | addAttribute (const MObject &node, const MObject &attribute, MFnDependencyNode::MAttrClass type) |
MStatus | removeAttribute (const MObject &node, const MObject &attribute, MFnDependencyNode::MAttrClass type) |
Static Public Member Functions |
|
static const char * | className () |
Returns the name of this class. |
This method adds an operation to this dependency graph modifier that will add a new dependency graph node of the given type to the dependency graph.
This method may not be used to construct new DAG nodes. Use MDagModifier for that purpose.
When createNode is called, the new node is created and the MObject handle for it is returned. It should be noted that the node will not be added to the dependency graph until the doIt method is called.
If a node is created with this method, but the operation is undone, then the MDGModifier will take responsibility for freeing the node. This will be done when the MDGModifier is destructed.
[in] | typeId | type of the node to create |
[out] | ReturnStatus | return status |
This method adds an operation to this dependency graph modifier that will add a new dependency graph node of the given type to the dependency graph.
This method may not be used to construct new DAG nodes. Use MDagModifier for that purpose.
When createNode is called, the new node is created and the MObject handle for it is returned. It should be noted that the node will not be added to the dependency graph until the doIt method is called.
If a node is created with this method, but the operation is undone, then the MDGModifier will take responsibility for freeing the node. This will be done when the MDGModifier is destructed.
[in] | type | type name of the node to create |
[out] | ReturnStatus | return status |
This method adds an operation to this dependency graph modifier that will delete a dependency graph node from the dependency graph.
Information on disconnecting and deleting a node using a single MDGModifier can be found in the class description.
[in] | node | node to delete |
This method adds an operation to this dependency graph modifier that will rename a dependency graph node.
[in] | node | node to rename |
[in] | newName | new name for the node |
This method adds an operation to this dependency graph modifier that will set the lock state of the node.
[in] | node | node to toggle lock state |
[in] | newState | new lock state |
MStatus connect | ( | const MObject & | sourceNode, |
const MObject & | sourceAttr, | ||
const MObject & | destNode, | ||
const MObject & | destAttr | ||
) |
Adds an operation to this dependency graph modifier that connects two attributes of two nodes in the dependency graph.
The value of the destination attribute is supplied by the value of the source attribute once they are connected.
It is the users responsibility to ensure that the source and destination attributes are of compatible types. For instance, if the source attribute is a nurbs surface then the destination must also be a nurbs surface.
To connect array attributes use the other version of connect which takes MPlugs as parameters.
[in] | sourceNode | the source node in the connection |
[in] | sourceAttr | the attribute of the source node that is to be connected |
[in] | destNode | the destination node in the connection |
[in] | destAttr | the attribute of the destination node that is to be connected |
MStatus disconnect | ( | const MObject & | sourceNode, |
const MObject & | sourceAttr, | ||
const MObject & | destNode, | ||
const MObject & | destAttr | ||
) |
Adds an operation to this dependency graph modifier that disconnects two attributes of two nodes in the dependency graph.
[in] | sourceNode | the source node in the connection |
[in] | sourceAttr | the attribute of the source node that is connected |
[in] | destNode | the destination node in the connection |
[in] | destAttr | the attribute of the destination node that is connected |
Adds an operation to this dependency graph modifier that connects two plugs in the dependency graph.
The value of the destination plug is supplied by the value of the source plug once they are connected.
It is the users responsibility to ensure that the source and destination attributes are of compatible types. For instance, if the source attribute is a nurbs surface then the destination must also be a nurbs surface.
[in] | source | the source plug in the connection |
[in] | dest | the destination plug in the connection |
Adds an operation to this dependency graph modifier that disconnects two plugs in the dependency graph.
[in] | source | the source plug in the connection |
[in] | dest | the destination plug in the connection |
Add a new dynamic attribute to the given dependency node.
This method also adds all children of the attribute if it is a compound. So, if a compound attribute is being added to a node, then only the parent attribute needs to be added using this method.
[in] | node | node to which to add the attribute |
[in] | attribute | attribute to add |
Removes a dynamic attribute from the given dependency node.
This method also removes all children of the attribute if it is a compound.
Note: After a successful call to this method, the MObject passed to it that contains the attribute will have been reset to MObject::kNullObj because the attribute it referenced no longer exists. Thus no function sets, such as MFnAttribute, should be attached to the MObject at the time this call is made.
[in] | node | node to add an attribute to |
[in] | attribute | attribute to add |
MStatus addExtensionAttribute | ( | const MNodeClass & | nodeClass, |
const MObject & | attribute | ||
) |
Add a new extension attribute to the given dependency node class.
This method also adds all children of the attribute if it is a compound. So, if a compound attribute is being added to a node type, then only the parent attribute needs to be added using this method.
[in] | nodeClass | class of node to which to add the attribute |
[in] | attribute | attribute to add |
MStatus removeExtensionAttribute | ( | const MNodeClass & | nodeClass, |
const MObject & | attribute | ||
) |
Removes an extension attribute from the given dependency node type.
This method also removes all children of the attribute if it is a compound.
Note: After a successful call to this method, the MObject passed to it that contains the attribute will have been reset to MObject::kNullObj because the attribute it referenced may no longer exist. Thus no function sets, such as MFnAttribute, should be attached to the MObject at the time this call is made.
[in] | nodeClass | class of node from which to remove the attribute |
[in] | attribute | attribute to remove |
MStatus removeExtensionAttributeIfUnset | ( | const MNodeClass & | nodeClass, |
const MObject & | attribute | ||
) |
Removes an extension attribute from the given dependency node type but only if there are no nodes in the graph with non-default values for this attribute.
This method also removes all children of the attribute if it is a compound.
Note: After a successful call to this method, the MObject passed to it that contains the attribute may have been reset to MObject::kNullObj because the attribute it referenced may no longer exist. Thus no function sets, such as MFnAttribute, should be attached to the MObject at the time this call is made.
[in] | nodeClass | class of node from which to remove the attribute |
[in] | attribute | attribute to remove |
The plugin calls this to indicate that the extension attribute defines part of the plugin, regardless of the node type to which it attaches itself.
This requirement is used when the plugin is checked to see if it is in use or if is able to be unloaded or if it is required as part of a stored file.
This should only be called once for root attributes (i.e. those with no parent). It is an error to call it with a child attribute. All children and ancestors are recursively tested. Forcing it to be called only on the root keeps the calling code simple and avoids duplicate calls.
[in] | mPlugin | plugin to which the attribute is to be tied |
[in] | mAttribute | attribute to associate with the plugin, must not have a parent |
Tells a plugin that it no longer requires an extension attribute for operation.
This requirement is used when the plugin is checked to see if it is in use or if is able to be unloaded.
This should only be called once for root attributes (i.e. those with no parent). It is an error to call it with a child attribute. All children and ancestors are recursively removed. Forcing it to be called only on the root keeps the calling code simple and avoids duplicate calls.
[in] | mPlugin | plugin from which the attribute is to be released |
[in] | mAttribute | attribute to disassociate with the plugin, must not have a parent |
Adds an operation to this dependency graph modifier that executes a MEL command.
The specified command must be undoable otherwise unexepected results may occur.
NOTE: It is best to use multiple commandToExecute() calls rather than batching multiple commands into one call to commandToExecute(). Using one command per call to commandToExecute() will simplify the undo stack which is important in case of command failure.
[in] | command | the command that will be executed (should be undoable) |
Adds an operation to this dependency graph modifier that sets a plug value.
Plug values can be created with the MFnNumericData class.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a boolean value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a char value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a double value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a float value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to an int value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to an MAngle value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to an MDistance value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to an MTime value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a short value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
Adds an operation to this dependency graph modifier that sets a plug to a string value.
[in] | plug | the plug to set |
[in] | plugValue | the value to set |
MStatus doIt | ( | ) |
Executes all of the operations that have been given to this modifier.
It is only valid to call this method after all of the operations have been specified. This method may also be called after undoIt to redo the operations.
MStatus undoIt | ( | ) |
Undoes all of the operations that have been given to this modifier.
It is only valid to call this method after the doIt method has been called.
const char * className | ( | ) | [static] |
MStatus addAttribute | ( | const MObject & | node, |
const MObject & | attribute, | ||
MFnDependencyNode::MAttrClass | type | ||
) |
This method also adds all children of the attribute if it is a compound. So, if a compound attribute is being added to a node, then only the parent attribute needs to be added using this method.
[in] | node | node to add an attribute to |
[in] | attribute | attribute to add |
[in] | type | determines if this is a local or global attribute |
MStatus removeAttribute | ( | const MObject & | node, |
const MObject & | attribute, | ||
MFnDependencyNode::MAttrClass | type | ||
) |
Removes a dynamic attribute from the given dependency node.
This method also removes all children of the attribute if it is a compound.
Note: After a successful call to this method, the MObject passed to it that contains the attribute will have been reset to MObject::kNullObj because the attribute it referenced no longer exists. Thus no function sets, such as MFnAttribute, should be attached to the MObject at the time this call is made.
[in] | node | node to add an attribute to |
[in] | attribute | attribute to add |
[in] | type | determines if this is a local or global attribute |