MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / addObject

Method addObject

src/App/GroupExtensionPyImp.cpp:60–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60PyObject* 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
105PyObject* GroupExtensionPy::addObjects(PyObject* args)
106{

Callers 1

newObjectMethod · 0.45

Calls 8

new_reference_toFunction · 0.85
isAttachedToDocumentMethod · 0.45
getDocumentMethod · 0.45
getExtendedObjectMethod · 0.45
hasExtensionMethod · 0.45
hasObjectMethod · 0.45
appendMethod · 0.45
getPyObjectMethod · 0.45

Tested by

no test coverage detected