Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,007 changes: 4,010 additions & 3,997 deletions src/App/Document.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/App/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class AppExport Document : public App::PropertyContainer
std::vector<DocumentObject *>addObjects(const char* sType, const std::vector<std::string>& objectNames, bool isNew=true);
/// Remove a feature out of the document
void removeObject(const char* sName);
/// Remove a feature out of the document
void removeObject(const DocumentObject* object);
/** Add an existing feature with sName (ASCII) to this document and set it active.
* Unicode names are set through the Label property.
* This is an overloaded function of the function above and can be used to create
Expand Down
39 changes: 28 additions & 11 deletions src/App/DocumentPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,38 @@ PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd)

PyObject* DocumentPy::removeObject(PyObject *args)
{
char *sName;
if (!PyArg_ParseTuple(args, "s",&sName))
return nullptr;


DocumentObject *pcFtr = getDocumentPtr()->getObject(sName);
if (pcFtr) {
getDocumentPtr()->removeObject( sName );
Py_Return;
}
else {
char* sName {};
if (PyArg_ParseTuple(args, "s", &sName)) {
DocumentObject* object = getDocumentPtr()->getObject(sName);
if (object) {
getDocumentPtr()->removeObject(sName);
Py_Return;
}
std::stringstream str;
str << "No document object found with name '" << sName << "'" << std::ends;
throw Py::ValueError(str.str());
}
PyErr_Clear();
PyObject* objpy {};
if (PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type, &objpy)) {
DocumentObject* object = static_cast<App::DocumentObjectPy*>(objpy)->getDocumentObjectPtr();
if (!object) {
PyErr_Format(PyExc_RuntimeError, "Invalid document object");
return nullptr;
}

if (object->getDocument() == getDocumentPtr()) {
getDocumentPtr()->removeObject(object);
Py_Return;
}

std::stringstream str;
str << "Document object is not part of this document";
throw Py::ValueError(str.str());
}

PyErr_SetString(PyExc_TypeError, "Expect str or DocumentObject");
return nullptr;
}

PyObject* DocumentPy::copyObject(PyObject *args)
Expand Down
Loading
Loading