| 323 | } |
| 324 | |
| 325 | PyObject* DocumentPy::addObject(PyObject* args, PyObject* kwd) |
| 326 | { |
| 327 | char *sType, *sName = nullptr, *sViewType = nullptr; |
| 328 | PyObject* obj = nullptr; |
| 329 | PyObject* view = nullptr; |
| 330 | PyObject* attach = Py_False; |
| 331 | static const std::array<const char*, 7> |
| 332 | kwlist {"type", "name", "objProxy", "viewProxy", "attach", "viewType", nullptr}; |
| 333 | if (!Base::Wrapped_ParseTupleAndKeywords(args, |
| 334 | kwd, |
| 335 | "s|sOOO!s", |
| 336 | kwlist, |
| 337 | &sType, |
| 338 | &sName, |
| 339 | &obj, |
| 340 | &view, |
| 341 | &PyBool_Type, |
| 342 | &attach, |
| 343 | &sViewType)) { |
| 344 | return nullptr; |
| 345 | } |
| 346 | |
| 347 | DocumentObject* pcFtr = nullptr; |
| 348 | |
| 349 | if (!obj || !Base::asBoolean(attach)) { |
| 350 | pcFtr = getDocumentPtr()->addObject(sType, sName, true, sViewType); |
| 351 | } |
| 352 | else { |
| 353 | Base::Type type = |
| 354 | Base::Type::getTypeIfDerivedFrom(sType, DocumentObject::getClassTypeId(), true); |
| 355 | if (type.isBad()) { |
| 356 | std::stringstream str; |
| 357 | str << "'" << sType << "' is not a document object type"; |
| 358 | throw Base::TypeError(str.str()); |
| 359 | } |
| 360 | pcFtr = static_cast<DocumentObject*>(type.createInstance()); |
| 361 | } |
| 362 | // the type instance could be a null pointer |
| 363 | if (!pcFtr) { |
| 364 | std::stringstream str; |
| 365 | str << "No document object found of type '" << sType << "'" << std::ends; |
| 366 | throw Py::TypeError(str.str()); |
| 367 | } |
| 368 | // Allows one to hide the handling with Proxy in client python code |
| 369 | if (obj) { |
| 370 | try { |
| 371 | // the python binding class to the document object |
| 372 | Py::Object pyftr = Py::asObject(pcFtr->getPyObject()); |
| 373 | // 'pyobj' is the python class with the implementation for DocumentObject |
| 374 | Py::Object pyobj(obj); |
| 375 | if (pyobj.hasAttr("__object__")) { |
| 376 | pyobj.setAttr("__object__", pyftr); |
| 377 | } |
| 378 | pyftr.setAttr("Proxy", pyobj); |
| 379 | |
| 380 | if (Base::asBoolean(attach)) { |
| 381 | getDocumentPtr()->addObject(pcFtr, sName); |
| 382 |
nothing calls this directly
no test coverage detected