Skip to content

Commit

Permalink
Make validate function calls multi-line to keep line lengths short
Browse files Browse the repository at this point in the history
  • Loading branch information
yantor3d committed Jun 6, 2021
1 parent 51726a1 commit b4ded3e
Showing 1 changed file with 92 additions and 24 deletions.
116 changes: 92 additions & 24 deletions src/MDGModifier.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ py::class_<MDGModifier>(m, "DGModifier")

.def("addAttribute", [](MDGModifier & self, MObject node, MObject attribute) {
validate::is_not_null(node, "Cannot add attribute to a null object.");
validate::has_fn(node, MFn::kDependencyNode, "Cannot add attribute - 'node' must be a 'kDependencyNode' object, not a(n) '^1s' object.");
validate::has_fn(
node, MFn::kDependencyNode,
"Cannot add attribute - 'node' must be a 'kDependencyNode' object, not a(n) '^1s' object."
);

validate::is_not_null(attribute, "Cannot add null attribute to a node.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot add attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot add attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.addAttribute(node, attribute);

Expand All @@ -17,7 +23,10 @@ If the attribute is a compound its children will ae added as well, so only the p

.def("addExtensionAttribute", [](MDGModifier & self, MNodeClass nodeClass, MObject attribute) {
validate::is_not_null(attribute, "Cannot add null extension attribute.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot add extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot add extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.addExtensionAttribute(nodeClass, attribute);

Expand Down Expand Up @@ -45,16 +54,28 @@ but Maya will better be able to recover if one of the commands fails.)pbdoc")

.def("connect", [](MDGModifier & self, MObject sourceNode, MObject sourceAttr, MObject destNode, MObject destAttr) {
validate::is_not_null(sourceNode, "Cannot connect - sourceNode is null.");
validate::has_fn(sourceNode, MFn::kDependencyNode, "Cannot connect - 'sourceNode' must be a 'node' object , not a '^1s' object.");
validate::has_fn(
sourceNode, MFn::kDependencyNode,
"Cannot connect - 'sourceNode' must be a 'node' object , not a '^1s' object."
);

validate::is_not_null(sourceAttr, "Cannot connect - 'sourceAttr' is null.");
validate::has_fn(sourceAttr, MFn::kAttribute, "Cannot connect - 'sourceAttr' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
sourceAttr, MFn::kAttribute,
"Cannot connect - 'sourceAttr' must be a 'kAttribute' object, not a(n) '^1s' object."
);

validate::is_not_null(destNode, "Cannot connect - 'destNode' is null.");
validate::has_fn(destNode, MFn::kDependencyNode, "Cannot connect - 'destNode' must be a 'kDependencyNode' object , not a '^1s' object.");
validate::has_fn(
destNode, MFn::kDependencyNode,
"Cannot connect - 'destNode' must be a 'kDependencyNode' object , not a '^1s' object."
);

validate::is_not_null(destAttr, "Cannot connect - 'destAttr' is null.");
validate::has_fn(destAttr, MFn::kAttribute, "Cannot connect - 'destAttr' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
destAttr, MFn::kAttribute,
"Cannot connect - 'destAttr' must be a 'kAttribute' object, not a(n) '^1s' object."
);

// TODO: Once the MFnAttribute classes are implemented,
// add additional validation to ensure that the attributes can be connected
Expand Down Expand Up @@ -158,17 +179,28 @@ doIt() should be called immediately after to ensure that the queue is emptied be

.def("disconnect", [](MDGModifier & self, MObject sourceNode, MObject sourceAttr, MObject destNode, MObject destAttr) {
validate::is_not_null(sourceNode, "Cannot disconnect - sourceNode is null.");
validate::has_fn(sourceNode, MFn::kDependencyNode, "Cannot disconnect - 'sourceNode' must be a 'node' object , not a '^1s' object.");
validate::has_fn(
sourceNode, MFn::kDependencyNode,
"Cannot disconnect - 'sourceNode' must be a 'node' object , not a '^1s' object."
);

validate::is_not_null(sourceAttr, "Cannot disconnect - 'sourceAttr' is null.");
validate::has_fn(sourceAttr, MFn::kAttribute, "Cannot disconnect - 'sourceAttr' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
sourceAttr, MFn::kAttribute,
"Cannot disconnect - 'sourceAttr' must be a 'kAttribute' object, not a(n) '^1s' object."
);

validate::is_not_null(destNode, "Cannot disconnect - 'destNode' is null.");
validate::has_fn(destNode, MFn::kDependencyNode, "Cannot disconnect - 'destNode' must be a 'kDependencyNode' object , not a '^1s' object.");
validate::has_fn(
destNode, MFn::kDependencyNode,
"Cannot disconnect - 'destNode' must be a 'kDependencyNode' object , not a '^1s' object."
);

validate::is_not_null(destAttr, "Cannot disconnect - 'destAttr' is null.");
validate::has_fn(destAttr, MFn::kAttribute, "Cannot disconnect - 'destAttr' must be a 'kAttribute' object, not a(n) '^1s' object.");

validate::has_fn(
destAttr, MFn::kAttribute,
"Cannot disconnect - 'destAttr' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.disconnect(sourceNode, sourceAttr, destNode, destAttr);
CHECK_STATUS(status)
Expand Down Expand Up @@ -203,10 +235,16 @@ If undoIt() has been called then the next call to doIt() will do all operations.

.def("linkExtensionAttributeToPlugin", [](MDGModifier & self, MObject plugin, MObject attribute) {
validate::is_not_null(plugin, "Cannot link extension attribute to a null plugin.");
validate::has_fn(plugin, MFn::kPlugin, "Cannot link extension attribute to plugin - must specify a 'kPlugin' object, not a '^1s' object.");
validate::has_fn(
plugin, MFn::kPlugin,
"Cannot link extension attribute to plugin - must specify a 'kPlugin' object, not a '^1s' object."
);

validate::is_not_null(attribute, "Cannot link null extension attribute from a plugin.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot link extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot link extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.linkExtensionAttributeToPlugin(plugin, attribute);

Expand Down Expand Up @@ -330,10 +368,16 @@ but Maya will better be able to recover if one of the commands fails.)pbdoc")

.def("removeAttribute", [](MDGModifier & self, MObject node, MObject attribute) {
validate::is_not_null(node, "Cannot remove an attribute from a null node.");
validate::has_fn(node, MFn::kDependencyNode, "Cannot remove attribute - node must be a 'node' object , not a '^1s' object.");
validate::has_fn(
node, MFn::kDependencyNode,
"Cannot remove attribute - node must be a 'node' object , not a '^1s' object."
);

validate::is_not_null(attribute, "Cannot remove a null attribute.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot remove attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot remove attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.removeAttribute(node, attribute);

Expand All @@ -347,7 +391,10 @@ There should be no function sets attached to the attribute at the time of the ca

.def("removeExtensionAttribute", [](MDGModifier & self, MNodeClass nodeClass, MObject attribute) {
validate::is_not_null(attribute, "Cannot remove null extension attribute.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot remove extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot remove extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.removeExtensionAttribute(nodeClass, attribute);

Expand All @@ -361,7 +408,10 @@ There should be no function sets attached to the attribute at the time of the ca

.def("removeExtensionAttributeIfUnset", [](MDGModifier & self, MNodeClass nodeClass, MObject attribute) {
validate::is_not_null(attribute, "Cannot remove null extension attribute (if unset).");
validate::has_fn(attribute, MFn::kAttribute, "Cannot remove extension attribute (if unset) - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot remove extension attribute (if unset) - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.removeExtensionAttribute(nodeClass, attribute);

Expand All @@ -385,10 +435,16 @@ There should be no function sets attached to the attribute at the time of the ca

.def("renameAttribute", [](MDGModifier & self, MObject node, MObject attribute, std::string shortName, std::string longName) {
validate::is_not_null(node, "Cannot rename an attribute from a null node.");
validate::has_fn(node, MFn::kDependencyNode, "Cannot rename attribute - node must be a 'node' object , not a '^1s' object.");
validate::has_fn(
node, MFn::kDependencyNode,
"Cannot rename attribute - node must be a 'node' object , not a '^1s' object."
);

validate::is_not_null(attribute, "Cannot rename a null attribute.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot rename attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot rename attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

if (shortName.empty() || longName.empty())
{
Expand All @@ -407,7 +463,10 @@ There should be no function sets attached to the attribute at the time of the ca

.def("renameNode", [](MDGModifier & self, MObject node, std::string newName) {
validate::is_not_null(node, "Cannot rename a null node.");
validate::has_fn(node, MFn::kDependencyNode, "Cannot rename object - 'node' must be a 'kDependencyNode' object , not a '^1s' object.");
validate::has_fn(
node, MFn::kDependencyNode,
"Cannot rename object - 'node' must be a 'kDependencyNode' object , not a '^1s' object."
);

if (newName.empty())
{
Expand All @@ -421,7 +480,10 @@ There should be no function sets attached to the attribute at the time of the ca

.def("setNodeLockState", [](MDGModifier & self, MObject node, bool newState) {
validate::is_not_null(node, "Cannot un/lock a null node.");
validate::has_fn(node, MFn::kDependencyNode, "Cannot un/lock object - 'node' must be a 'kDependencyNode' object , not a '^1s' object.");
validate::has_fn(
node, MFn::kDependencyNode,
"Cannot un/lock object - 'node' must be a 'kDependencyNode' object , not a '^1s' object."
);

MStatus status = self.setNodeLockState(node, newState);

Expand All @@ -436,10 +498,16 @@ There should be no function sets attached to the attribute at the time of the ca

.def("unlinkExtensionAttributeFromPlugin", [](MDGModifier & self, MObject plugin, MObject attribute) {
validate::is_not_null(plugin, "Cannot unlink extension attribute from a null plugin.");
validate::has_fn(plugin, MFn::kPlugin, "Cannot unlink extension attribute from plugin - must specify a 'kPlugin' object, not a '^1s' object.");
validate::has_fn(
plugin, MFn::kPlugin,
"Cannot unlink extension attribute from plugin - must specify a 'kPlugin' object, not a '^1s' object."
);

validate::is_not_null(attribute, "Cannot unlink null extension attribute from a plugin.");
validate::has_fn(attribute, MFn::kAttribute, "Cannot unlink extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object.");
validate::has_fn(
attribute, MFn::kAttribute,
"Cannot unlink extension attribute - 'attribute' must be a 'kAttribute' object, not a(n) '^1s' object."
);

MStatus status = self.unlinkExtensionAttributeFromPlugin(plugin, attribute);

Expand Down

0 comments on commit b4ded3e

Please sign in to comment.