Skip to content

Commit

Permalink
WIP: implement MDagPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Muream committed May 2, 2021
1 parent 3f30ad2 commit b4137d1
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 6 deletions.
57 changes: 51 additions & 6 deletions src/MDagPath.inl
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
py::class_<MDagPath>(m, "DagPath")
.def(py::init<>())

.def(py::self == MDagPath())

.def("apiType", [](MDagPath & self) -> MFn::Type {
throw std::logic_error{"Function not yet implemented."};
MStatus status = MStatus();
MFn::Type type = self.apiType(&status);

if (!status){
throw std::logic_error("(kFailure): Object does not exist");
}

return type;
}, R"pbdoc(Returns the type of the object at the end of the path.)pbdoc")

.def("child", [](MDagPath & self, unsigned int i) -> MObject {
throw std::logic_error{"Function not yet implemented."};
MStatus status = MStatus();
MObject child = self.child(i, &status);

switch (status.statusCode()){
case MS::kInvalidParameter:
throw std::out_of_range("(kInvalidParameter): Index not in valid range");
case MS::kFailure:
throw std::logic_error("(kFailure): Object does not exist");
}

return child;
}, R"pbdoc(Returns the specified child of the object at the end of the path.)pbdoc")

.def("childCount", [](MDagPath & self) -> int {
throw std::logic_error{"Function not yet implemented."};
MStatus status = MStatus();
int childCount = self.childCount(&status);

if (!status) {
throw std::logic_error("(kFailure): Object does not exist");
}

return childCount;
}, R"pbdoc(Returns the number of objects parented directly beneath the object at the end of the path.)pbdoc")

.def("exclusiveMatrix", [](MDagPath & self) -> MMatrix {
throw std::logic_error{"Function not yet implemented."};
MStatus status = MStatus();
MMatrix exclusive_matrix = self.exclusiveMatrix(&status);

if (!status) {
throw std::logic_error("(kFailure): Object does not exist");
}

return exclusive_matrix;
}, R"pbdoc(Returns the matrix for all transforms in the path, excluding the end object.)pbdoc")

.def("exclusiveMatrixInverse", [](MDagPath & self) -> MMatrix {
throw std::logic_error{"Function not yet implemented."};
MStatus status = MStatus();
MMatrix exclusive_matrix_inverse = self.exclusiveMatrixInverse(&status);

if (!status) {
throw std::logic_error("(kFailure): Object does not exist");
}

return exclusive_matrix_inverse;
}, R"pbdoc(Returns the inverse of exclusiveMatrix().)pbdoc")

.def("extendToShape", [](MDagPath & self) {
throw std::logic_error{"Function not yet implemented."};
MStatus status = self.extendToShape();

if (!status) {
throw std::logic_error("(kFailure): Object does not exist");
}

}, R"pbdoc(Extends the path to the specified shape node parented directly beneath the transform at the current end of the path.)pbdoc")

.def("fullPathName", [](MDagPath & self) -> MString {
Expand Down
99 changes: 99 additions & 0 deletions tests/test_MDagPath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import nose
import cmdc

def test_equality():
sel = cmdc.SelectionList().add("persp")

a = sel.getDagPath(0)
b = sel.getDagPath(0)
assert a == b


def test_apiType():
sel = cmdc.SelectionList().add("persp")

valid_dag = sel.getDagPath(0)
assert valid_dag.apiType() == cmdc.Fn.Type.kTransform

invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.apiType,
)

def test_child():
sel = cmdc.SelectionList().add("persp").add("perspShape")

dag_with_child = sel.getDagPath(0)
assert isinstance(dag_with_child.child(0), cmdc.Object)

dag_without_children = sel.getDagPath(1)
nose.tools.assert_raises(
IndexError,
dag_without_children.child,
0
)

invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.child,
0
)

def test_childCount():
sel = cmdc.SelectionList().add("persp").add("perspShape")

persp = sel.getDagPath(0)
assert persp.childCount() == 1

persp_shape = sel.getDagPath(1)
assert persp_shape.childCount() == 0

invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.childCount,
)

def test_exclusiveMatrix():
sel = cmdc.SelectionList().add("persp").add("perspShape")

persp = sel.getDagPath(0)
assert isinstance(persp.exclusiveMatrix(), cmdc.Matrix)

# I would have expected this to raise a RuntimeError
invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.exclusiveMatrix,
)


def test_exclusiveMatrixInverse():
sel = cmdc.SelectionList().add("persp").add("perspShape")

persp = sel.getDagPath(0)
assert isinstance(persp.exclusiveMatrixInverse(), cmdc.Matrix)

# I would have expected this to raise a RuntimeError
invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.exclusiveMatrixInverse,
)


def test_extendToShape():
sel = cmdc.SelectionList().add("persp").add("perspShape")

persp = sel.getDagPath(0)
persp_shape = sel.getDagPath(1)
persp.extendToShape()
assert persp == persp_shape

invalid_dag = cmdc.DagPath()
nose.tools.assert_raises(
RuntimeError,
invalid_dag.extendToShape,
)

0 comments on commit b4137d1

Please sign in to comment.