Gui: improve accessing active object of an MDI view
* if 2nd argument of getActiveObject() is False and the requested object doesn't exist then return (None, None, "") * remove the exact same implementations from View3DInventorPy
This commit is contained in:
@@ -256,26 +256,37 @@ Py::Object MDIViewPy::setActiveObject(const Py::Tuple& args)
|
||||
|
||||
Py::Object MDIViewPy::getActiveObject(const Py::Tuple& args)
|
||||
{
|
||||
const char* name;
|
||||
PyObject *resolve = Py_True;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O!", &name, &PyBool_Type, &resolve))
|
||||
const char* name{};
|
||||
PyObject *resolve = Py_True; // NOLINT
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O!", &name, &PyBool_Type, &resolve)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
App::DocumentObject *parent = nullptr;
|
||||
std::string subname;
|
||||
App::DocumentObject* obj = nullptr;
|
||||
if (_view)
|
||||
if (_view) {
|
||||
obj = _view->getActiveObject<App::DocumentObject*>(name,&parent,&subname);
|
||||
if (!obj)
|
||||
}
|
||||
|
||||
if (Base::asBoolean(resolve)) {
|
||||
if (obj) {
|
||||
return Py::asObject(obj->getPyObject());
|
||||
}
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
if (Base::asBoolean(resolve))
|
||||
return Py::asObject(obj->getPyObject());
|
||||
// NOLINTBEGIN(cppcoreguidelines-slicing)
|
||||
if (obj) {
|
||||
return Py::TupleN(
|
||||
Py::asObject(obj->getPyObject()),
|
||||
Py::asObject(parent->getPyObject()),
|
||||
Py::String(subname.c_str()));
|
||||
}
|
||||
|
||||
return Py::TupleN(
|
||||
Py::asObject(obj->getPyObject()),
|
||||
Py::asObject(parent->getPyObject()),
|
||||
Py::String(subname.c_str()));
|
||||
return Py::TupleN(Py::None(), Py::None(), Py::String());
|
||||
// NOLINTEND(cppcoreguidelines-slicing)
|
||||
}
|
||||
|
||||
Py::Object MDIViewPy::cast_to_base(const Py::Tuple&)
|
||||
|
||||
Reference in New Issue
Block a user