| 58 | } |
| 59 | |
| 60 | PyObject* GroupExtensionPy::addObject(PyObject* args) |
| 61 | { |
| 62 | PyObject* object; |
| 63 | if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) { |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
| 67 | DocumentObjectPy* docObj = static_cast<DocumentObjectPy*>(object); |
| 68 | if (!docObj->getDocumentObjectPtr() |
| 69 | || !docObj->getDocumentObjectPtr()->isAttachedToDocument()) { |
| 70 | PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot add an invalid object"); |
| 71 | return nullptr; |
| 72 | } |
| 73 | |
| 74 | if (docObj->getDocumentObjectPtr()->getDocument() |
| 75 | != getGroupExtensionPtr()->getExtendedObject()->getDocument()) { |
| 76 | PyErr_SetString(Base::PyExc_FC_GeneralError, |
| 77 | "Cannot add an object from another document to this group"); |
| 78 | return nullptr; |
| 79 | } |
| 80 | if (docObj->getDocumentObjectPtr() == this->getGroupExtensionPtr()->getExtendedObject()) { |
| 81 | PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot add a group object to itself"); |
| 82 | return nullptr; |
| 83 | } |
| 84 | if (docObj->getDocumentObjectPtr()->hasExtension(GroupExtension::getExtensionClassTypeId())) { |
| 85 | App::GroupExtension* docGrp = |
| 86 | docObj->getDocumentObjectPtr()->getExtensionByType<GroupExtension>(); |
| 87 | if (docGrp->hasObject(getGroupExtensionPtr()->getExtendedObject())) { |
| 88 | PyErr_SetString(Base::PyExc_FC_GeneralError, |
| 89 | "Cannot add a group object to a child group"); |
| 90 | return nullptr; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | GroupExtension* grp = getGroupExtensionPtr(); |
| 95 | |
| 96 | auto vec = grp->addObject(docObj->getDocumentObjectPtr()); |
| 97 | Py::List list; |
| 98 | for (App::DocumentObject* obj : vec) { |
| 99 | list.append(Py::asObject(obj->getPyObject())); |
| 100 | } |
| 101 | |
| 102 | return Py::new_reference_to(list); |
| 103 | } |
| 104 | |
| 105 | PyObject* GroupExtensionPy::addObjects(PyObject* args) |
| 106 | { |
no test coverage detected