| 419 | } |
| 420 | |
| 421 | PyObject* DocumentPy::removeObject(PyObject* args) |
| 422 | { |
| 423 | char* sName {}; |
| 424 | if (PyArg_ParseTuple(args, "s", &sName)) { |
| 425 | DocumentObject* object = getDocumentPtr()->getObject(sName); |
| 426 | if (object) { |
| 427 | getDocumentPtr()->removeObject(sName); |
| 428 | Py_Return; |
| 429 | } |
| 430 | |
| 431 | std::stringstream str; |
| 432 | str << "No document object found with name '" << sName << "'" << std::ends; |
| 433 | throw Py::ValueError(str.str()); |
| 434 | } |
| 435 | |
| 436 | PyErr_Clear(); |
| 437 | PyObject* objpy {}; |
| 438 | if (PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type, &objpy)) { |
| 439 | DocumentObject* object = static_cast<App::DocumentObjectPy*>(objpy)->getDocumentObjectPtr(); |
| 440 | if (!object) { |
| 441 | PyErr_Format(PyExc_RuntimeError, "Invalid document object"); |
| 442 | return nullptr; |
| 443 | } |
| 444 | |
| 445 | if (object->getDocument() == getDocumentPtr()) { |
| 446 | getDocumentPtr()->removeObject(object); |
| 447 | Py_Return; |
| 448 | } |
| 449 | |
| 450 | std::stringstream str; |
| 451 | str << "Document object is not part of this document"; |
| 452 | throw Py::ValueError(str.str()); |
| 453 | } |
| 454 | |
| 455 | PyErr_SetString(PyExc_TypeError, "Expect str or DocumentObject"); |
| 456 | return nullptr; |
| 457 | } |
| 458 | |
| 459 | PyObject* DocumentPy::copyObject(PyObject* args, PyObject* kwd) |
| 460 | { |
nothing calls this directly
no test coverage detected