| 262 | } |
| 263 | |
| 264 | bool FeaturePythonImp::getSubObject(DocumentObject*& ret, |
| 265 | const char* subname, |
| 266 | PyObject** pyObj, |
| 267 | Base::Matrix4D* _mat, |
| 268 | bool transform, |
| 269 | int depth) const |
| 270 | { |
| 271 | FC_PY_CALL_CHECK(getSubObject); |
| 272 | Base::PyGILStateLocker lock; |
| 273 | try { |
| 274 | Py::Tuple args(6); |
| 275 | args.setItem(0, Py::Object(object->getPyObject(), true)); |
| 276 | if (!subname) { |
| 277 | subname = ""; |
| 278 | } |
| 279 | args.setItem(1, Py::String(subname)); |
| 280 | args.setItem(2, Py::Long(pyObj ? 2 : 1)); |
| 281 | Base::MatrixPy* pyMat = new Base::MatrixPy(new Base::Matrix4D); |
| 282 | if (_mat) { |
| 283 | *pyMat->getMatrixPtr() = *_mat; |
| 284 | } |
| 285 | args.setItem(3, Py::asObject(pyMat)); |
| 286 | args.setItem(4, Py::Boolean(transform)); |
| 287 | args.setItem(5, Py::Long(depth)); |
| 288 | |
| 289 | Py::Object res(Base::pyCall(py_getSubObject.ptr(), args.ptr())); |
| 290 | if (res.isNone()) { |
| 291 | ret = nullptr; |
| 292 | return true; |
| 293 | } |
| 294 | if (!res.isTrue()) { |
| 295 | return false; |
| 296 | } |
| 297 | if (!res.isSequence()) { |
| 298 | throw Py::TypeError("getSubObject expects return type of tuple"); |
| 299 | } |
| 300 | Py::Sequence seq(res); |
| 301 | if (seq.length() < 2 |
| 302 | || (!seq.getItem(0).isNone() |
| 303 | && !PyObject_TypeCheck(seq.getItem(0).ptr(), &DocumentObjectPy::Type)) |
| 304 | || !PyObject_TypeCheck(seq.getItem(1).ptr(), &Base::MatrixPy::Type)) { |
| 305 | throw Py::TypeError("getSubObject expects return type of (obj,matrix,pyobj)"); |
| 306 | } |
| 307 | if (_mat) { |
| 308 | *_mat = *static_cast<Base::MatrixPy*>(seq.getItem(1).ptr())->getMatrixPtr(); |
| 309 | } |
| 310 | if (pyObj) { |
| 311 | if (seq.length() > 2) { |
| 312 | *pyObj = Py::new_reference_to(seq.getItem(2)); |
| 313 | } |
| 314 | else { |
| 315 | *pyObj = Py::new_reference_to(Py::None()); |
| 316 | } |
| 317 | } |
| 318 | if (seq.getItem(0).isNone()) { |
| 319 | ret = nullptr; |
| 320 | } |
| 321 | else { |
no test coverage detected