From 201f4c9a5a45de7d82c363ec816c97a8cfd22962 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 16 Jul 2022 14:04:05 +0200 Subject: [PATCH] Core: replace PyObject_IsTrue with Base::asBoolean --- src/App/ApplicationPy.cpp | 14 ++++++-------- src/App/DocumentObjectPyImp.cpp | 14 +++++++------- src/App/DocumentPyImp.cpp | 18 +++++++++--------- src/App/ExtensionContainerPyImp.cpp | 2 +- src/App/GroupExtensionPyImp.cpp | 2 +- src/App/LinkBaseExtensionPyImp.cpp | 2 +- src/App/PropertyStandard.cpp | 8 ++++---- src/Base/PlacementPyImp.cpp | 4 ++-- src/Base/TypePyImp.cpp | 2 +- src/Gui/ApplicationPy.cpp | 6 +++--- src/Gui/Command.cpp | 7 ++++--- src/Gui/CommandPyImp.cpp | 2 +- src/Gui/ExpressionBindingPy.cpp | 2 +- src/Gui/LinkViewPyImp.cpp | 2 +- src/Gui/MDIViewPy.cpp | 2 +- src/Gui/Selection.cpp | 22 +++++++++++----------- src/Gui/View3DPy.cpp | 12 ++++++------ src/Gui/View3DViewerPy.cpp | 6 +++--- src/Gui/ViewProviderExtensionPyImp.cpp | 2 +- src/Gui/ViewProviderPyImp.cpp | 6 +++--- src/Main/FreeCADGuiPy.cpp | 2 +- 21 files changed, 68 insertions(+), 69 deletions(-) diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 043637b520..83ac48a225 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -250,7 +250,7 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args, PyObje PyMem_Free(Name); try { // return new document - return (GetApplication().openDocument(EncodedName.c_str(),PyObject_IsTrue(hidden) ? false : true)->getPyObject()); + return (GetApplication().openDocument(EncodedName.c_str(), !Base::asBoolean(hidden))->getPyObject()); } catch (const Base::Exception& e) { PyErr_SetString(PyExc_IOError, e.what()); @@ -275,9 +275,7 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec return nullptr; PY_TRY { - App::Document* doc = GetApplication().newDocument(docName, usrName, - PyObject_IsTrue(hidden) ? false : true, - PyObject_IsTrue(temp) ? true : false); + App::Document* doc = GetApplication().newDocument(docName, usrName, !Base::asBoolean(hidden), Base::asBoolean(temp)); PyMem_Free(docName); PyMem_Free(usrName); return doc->getPyObject(); @@ -701,7 +699,7 @@ PyObject* Application::sGetUserMacroPath(PyObject * /*self*/, PyObject *args) return nullptr; std::string macroDir = Application::getUserMacroDir(); - if (PyObject_IsTrue(actual) ? true : false) { + if (Base::asBoolean(actual)) { macroDir = App::GetApplication(). GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro") ->GetASCII("MacroPath",macroDir.c_str()); @@ -740,7 +738,7 @@ PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args) Base::PyObjectBase* pValue; std::vector docs = GetApplication().getDocuments();; - if(PyObject_IsTrue(sort) ? true : false) + if (Base::asBoolean(sort)) docs = Document::getDependentDocuments(docs,true); for (auto doc : docs) { @@ -946,7 +944,7 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args return nullptr; PY_TRY { - Py::Int ret(GetApplication().setActiveTransaction(name,PyObject_IsTrue(persist) ? true : false)); + Py::Int ret(GetApplication().setActiveTransaction(name, Base::asBoolean(persist))); return Py::new_reference_to(ret); }PY_CATCH; } @@ -976,7 +974,7 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar return nullptr; PY_TRY { - GetApplication().closeActiveTransaction(PyObject_IsTrue(abort) ? true : false, id); + GetApplication().closeActiveTransaction(Base::asBoolean(abort), id); Py_Return; } PY_CATCH; } diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index ad2a4b7a63..314936b57a 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -91,7 +91,7 @@ PyObject* DocumentObjectPy::addProperty(PyObject *args) } getDocumentObjectPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr, - PyObject_IsTrue(ro) ? true : false, PyObject_IsTrue(hd) ? true : false); + Base::asBoolean(ro), Base::asBoolean(hd)); return Py::new_reference_to(this); } @@ -379,7 +379,7 @@ PyObject* DocumentObjectPy::recompute(PyObject *args) return nullptr; try { - bool ok = getDocumentObjectPtr()->recomputeFeature(PyObject_IsTrue(recursive) ? true : false); + bool ok = getDocumentObjectPtr()->recomputeFeature(Base::asBoolean(recursive)); return Py_BuildValue("O", (ok ? Py_True : Py_False)); } catch (const Base::Exception& e) { @@ -469,7 +469,7 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds) return nullptr; } - bool transform = PyObject_IsTrue(doTransform) ? true : false; + bool transform = Base::asBoolean(doTransform); struct SubInfo { App::DocumentObject *sobj; @@ -595,7 +595,7 @@ PyObject* DocumentObjectPy::getLinkedObject(PyObject *args, PyObject *keywds) PY_TRY { auto linked = getDocumentObjectPtr()->getLinkedObject( - PyObject_IsTrue(recursive) ? true : false, mat, PyObject_IsTrue(transform) ? true : false, depth); + Base::asBoolean(recursive), mat, Base::asBoolean(transform), depth); if(!linked) linked = getDocumentObjectPtr(); auto pyObj = Py::Object(linked->getPyObject(),true); @@ -626,7 +626,7 @@ PyObject* DocumentObjectPy::setElementVisible(PyObject *args) if (!PyArg_ParseTuple(args, "s|O!", &element, &PyBool_Type, &visible)) return nullptr; PY_TRY { - return Py_BuildValue("h", getDocumentObjectPtr()->setElementVisible(element,PyObject_IsTrue(visible) ? true : false)); + return Py_BuildValue("h", getDocumentObjectPtr()->setElementVisible(element, Base::asBoolean(visible))); } PY_CATCH; } @@ -836,7 +836,7 @@ PyObject *DocumentObjectPy::resolveSubElement(PyObject *args) PY_TRY { std::pair elementName; auto obj = GeoFeature::resolveElement(getDocumentObjectPtr(), subname,elementName, - PyObject_IsTrue(append) ? true : false,(GeoFeature::ElementNameType)type); + Base::asBoolean(append), (GeoFeature::ElementNameType)type); Py::Tuple ret(3); ret.setItem(0,obj?Py::Object(obj->getPyObject(),true):Py::None()); ret.setItem(1,Py::String(elementName.first)); @@ -866,7 +866,7 @@ PyObject *DocumentObjectPy::adjustRelativeLinks(PyObject *args) { std::set visited; return Py::new_reference_to(Py::Boolean( getDocumentObjectPtr()->adjustRelativeLinks(inList, - PyObject_IsTrue(recursive) ? &visited : nullptr))); + Base::asBoolean(recursive) ? &visited : nullptr))); }PY_CATCH } diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index cee93faace..b7caacbe9a 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -218,7 +218,7 @@ PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd) DocumentObject *pcFtr = nullptr; - if (!obj || (PyObject_IsTrue(attach) ? false : true)) { + if (!obj || !Base::asBoolean(attach)) { pcFtr = getDocumentPtr()->addObject(sType,sName,true,sViewType); } else { @@ -248,7 +248,7 @@ PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd) } pyftr.setAttr("Proxy", pyobj); - if (PyObject_IsTrue(attach) ? true : false) { + if (Base::asBoolean(attach)) { getDocumentPtr()->addObject(pcFtr,sName); try { @@ -333,7 +333,7 @@ PyObject* DocumentPy::copyObject(PyObject *args) } PY_TRY { - auto ret = getDocumentPtr()->copyObject(objs, PyObject_IsTrue(rec) ? true : false, PyObject_IsTrue(retAll) ? true : false); + auto ret = getDocumentPtr()->copyObject(objs, Base::asBoolean(rec), Base::asBoolean(retAll)); if (ret.size()==1 && single) return ret[0]->getPyObject(); @@ -393,7 +393,7 @@ PyObject* DocumentPy::moveObject(PyObject *args) return nullptr; DocumentObjectPy* docObj = static_cast(obj); - DocumentObject* move = getDocumentPtr()->moveObject(docObj->getDocumentObjectPtr(), PyObject_IsTrue(rec) ? true : false); + DocumentObject* move = getDocumentPtr()->moveObject(docObj->getDocumentObjectPtr(), Base::asBoolean(rec)); if (move) { return move->getPyObject(); } @@ -485,7 +485,7 @@ PyObject* DocumentPy::setClosable(PyObject* args) PyObject* close; if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &close)) return nullptr; - getDocumentPtr()->setClosable(PyObject_IsTrue(close) ? true : false); + getDocumentPtr()->setClosable(Base::asBoolean(close)); Py_Return; } @@ -525,10 +525,10 @@ PyObject* DocumentPy::recompute(PyObject * args) } int options = 0; - if (PyObject_IsTrue(checkCycle) ? true : false) + if (Base::asBoolean(checkCycle)) options = Document::DepNoCycle; - int objectCount = getDocumentPtr()->recompute(objs, PyObject_IsTrue(force) ? true : false, nullptr, options); + int objectCount = getDocumentPtr()->recompute(objs, Base::asBoolean(force), nullptr, options); // Document::recompute() hides possibly raised Python exceptions by its features // So, check if an error is set and return null if yes @@ -835,7 +835,7 @@ int DocumentPy::setCustomAttributes(const char* attr, PyObject *) return 0; } PyObject* item = PyDict_GetItemString(this->ob_type->tp_dict, attr); - if (item) + if (item) return 0; DocumentObject* obj = getDocumentPtr()->getObject(attr); if (obj) @@ -904,7 +904,7 @@ PyObject *DocumentPy::getDependentDocuments(PyObject *args) { if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &sort)) return nullptr; PY_TRY { - auto docs = getDocumentPtr()->getDependentDocuments(PyObject_IsTrue(sort) ? true : false); + auto docs = getDocumentPtr()->getDependentDocuments(Base::asBoolean(sort)); Py::List ret; for (auto doc : docs) ret.append(Py::Object(doc->getPyObject(), true)); diff --git a/src/App/ExtensionContainerPyImp.cpp b/src/App/ExtensionContainerPyImp.cpp index 273df968d5..76b03308cf 100644 --- a/src/App/ExtensionContainerPyImp.cpp +++ b/src/App/ExtensionContainerPyImp.cpp @@ -178,7 +178,7 @@ PyObject* ExtensionContainerPy::hasExtension(PyObject *args) { return nullptr; //get the extension type asked for - bool derived = PyObject_IsTrue(deriv) ? true : false; + bool derived = Base::asBoolean(deriv); Base::Type extension = Base::Type::fromName(type); if (extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) { std::stringstream str; diff --git a/src/App/GroupExtensionPyImp.cpp b/src/App/GroupExtensionPyImp.cpp index e57bc6578c..f4fd6f6ecd 100644 --- a/src/App/GroupExtensionPyImp.cpp +++ b/src/App/GroupExtensionPyImp.cpp @@ -261,7 +261,7 @@ PyObject* GroupExtensionPy::hasObject(PyObject *args) return nullptr; DocumentObjectPy* docObj = static_cast(object); - bool recursive = PyObject_IsTrue(recursivePy) ? true : false; + bool recursive = Base::asBoolean(recursivePy); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot check an invalid object"); return nullptr; diff --git a/src/App/LinkBaseExtensionPyImp.cpp b/src/App/LinkBaseExtensionPyImp.cpp index 0fa3a5895b..8fcddb3fb4 100644 --- a/src/App/LinkBaseExtensionPyImp.cpp +++ b/src/App/LinkBaseExtensionPyImp.cpp @@ -256,7 +256,7 @@ PyObject* LinkBaseExtensionPy::cacheChildLabel(PyObject *args) { if(!PyArg_ParseTuple(args,"|O",&enable)) return nullptr; PY_TRY { - getLinkBaseExtensionPtr()->cacheChildLabel(PyObject_IsTrue(enable)?-1:0); + getLinkBaseExtensionPtr()->cacheChildLabel(Base::asBoolean(enable) ? -1 : 0); Py_Return; }PY_CATCH; } diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 99b4e32fd9..4246380bf4 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -2065,9 +2065,9 @@ PyObject *PropertyBool::getPyObject() void PropertyBool::setPyObject(PyObject *value) { - if (PyBool_Check(value) || PyLong_Check(value)) { - setValue(PyObject_IsTrue(value) ? true : false); - } + if (PyBool_Check(value) || PyLong_Check(value)) { + setValue(Base::asBoolean(value)); + } else { std::string error = std::string("type must be bool, not "); error += value->ob_type->tp_name; @@ -2189,7 +2189,7 @@ void PropertyBoolList::setPyObject(PyObject *value) bool PropertyBoolList::getPyValue(PyObject *item) const { if (PyBool_Check(item)) { - return (PyObject_IsTrue(item) ? true : false); + return Base::asBoolean(item); } else if (PyLong_Check(item)) { return (PyLong_AsLong(item) ? true : false); } else { diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index 2d7c4a43f4..f7d9761492 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -234,7 +234,7 @@ PyObject* PlacementPy::pow(PyObject* args) PyObject* shorten = Py_True; if (!PyArg_ParseTuple(args, "d|O!", &t, &(PyBool_Type), &shorten)) return nullptr; - Base::Placement ret = getPlacementPtr()->pow(t, PyObject_IsTrue(shorten) ? true : false); + Base::Placement ret = getPlacementPtr()->pow(t, Base::asBoolean(shorten)); return new PlacementPy(new Placement(ret)); } @@ -247,7 +247,7 @@ PyObject* PlacementPy::sclerp(PyObject* args) if (!PyArg_ParseTuple(args, "O!d|O!", &(PlacementPy::Type), &pyplm2, &t, &(PyBool_Type), &shorten)) return nullptr; Base::Placement plm2 = static_cast(pyplm2)->value(); - Base::Placement ret = Base::Placement::sclerp(*getPlacementPtr(), plm2, t, PyObject_IsTrue(shorten) ? true : false); + Base::Placement ret = Base::Placement::sclerp(*getPlacementPtr(), plm2, t, Base::asBoolean(shorten)); return new PlacementPy(new Placement(ret)); } diff --git a/src/Base/TypePyImp.cpp b/src/Base/TypePyImp.cpp index cb100869db..8d335392c4 100644 --- a/src/Base/TypePyImp.cpp +++ b/src/Base/TypePyImp.cpp @@ -229,7 +229,7 @@ PyObject* TypePy::createInstanceByName (PyObject *args) if (!PyArg_ParseTuple(args, "s|O!", &name, &PyBool_Type, &load)) return nullptr; - bool bLoad = PyObject_IsTrue(load) ? true : false; + bool bLoad = Base::asBoolean(load); Base::Type type = Base::Type::getTypeIfDerivedFrom(name, Base::BaseClass::getClassTypeId(), bLoad); if (type.isBad()) Py_Return; diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 9ecd9c571b..4710b78f86 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -463,7 +463,7 @@ PyObject* Gui::Application::sActivateView(PyObject * /*self*/, PyObject *args) return nullptr; Base::Type type = Base::Type::fromName(typeStr); - Instance->activateView(type, PyObject_IsTrue(create) ? true : false); + Instance->activateView(type, Base::asBoolean(create)); Py_Return; } @@ -831,7 +831,7 @@ PyObject* Application::sSendActiveView(PyObject * /*self*/, PyObject *args) const char* ppReturn = nullptr; if (!Instance->sendMsgToActiveView(psCommandStr,&ppReturn)) { - if (PyObject_IsTrue(suppress) ? false : true) + if (!Base::asBoolean(suppress)) Base::Console().Warning("Unknown view command: %s\n",psCommandStr); } @@ -852,7 +852,7 @@ PyObject* Application::sSendFocusView(PyObject * /*self*/, PyObject *args) const char* ppReturn = nullptr; if (!Instance->sendMsgToFocusView(psCommandStr,&ppReturn)) { - if (PyObject_IsTrue(suppress) ? false : true) + if (!Base::asBoolean(suppress)) Base::Console().Warning("Unknown view command: %s\n",psCommandStr); } diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index cf555439fc..07194c422c 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "Command.h" @@ -1434,7 +1435,7 @@ bool PythonCommand::isChecked() const } if (PyBool_Check(item)) { - return PyObject_IsTrue(item) ? true : false; + return Base::asBoolean(item); } else { throw Base::ValueError("PythonCommand::isChecked(): Method GetResources() of the Python " @@ -1726,7 +1727,7 @@ bool PythonGroupCommand::isExclusive() const } if (PyBool_Check(item)) { - return PyObject_IsTrue(item) ? true : false; + return Base::asBoolean(item); } else { throw Base::TypeError("PythonGroupCommand::isExclusive(): Method GetResources() of the Python " @@ -1742,7 +1743,7 @@ bool PythonGroupCommand::hasDropDownMenu() const } if (PyBool_Check(item)) { - return PyObject_IsTrue(item) ? true : false; + return Base::asBoolean(item); } else { throw Base::TypeError("PythonGroupCommand::hasDropDownMenu(): Method GetResources() of the Python " diff --git a/src/Gui/CommandPyImp.cpp b/src/Gui/CommandPyImp.cpp index 73745d5f9e..0070a4a807 100644 --- a/src/Gui/CommandPyImp.cpp +++ b/src/Gui/CommandPyImp.cpp @@ -96,7 +96,7 @@ PyObject* CommandPy::listByShortcut(PyObject *args) Action* action = c->getAction(); if (action) { QString spc = QString::fromLatin1(" "); - if (PyObject_IsTrue(bIsRegularExp) ? true : false) { + if (Base::asBoolean(bIsRegularExp)) { QRegExp re = QRegExp(QString::fromLatin1(shortcut_to_find)); re.setCaseSensitivity(Qt::CaseInsensitive); if (!re.isValid()) { diff --git a/src/Gui/ExpressionBindingPy.cpp b/src/Gui/ExpressionBindingPy.cpp index 1353019d5f..d134347d0d 100644 --- a/src/Gui/ExpressionBindingPy.cpp +++ b/src/Gui/ExpressionBindingPy.cpp @@ -162,7 +162,7 @@ Py::Object ExpressionBindingPy::setAutoApply(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "O!", &PyBool_Type, &b)) throw Py::Exception(); - bool value = PyObject_IsTrue(b) ? true : false; + bool value = Base::asBoolean(b); expr->setAutoApply(value); return Py::None(); } diff --git a/src/Gui/LinkViewPyImp.cpp b/src/Gui/LinkViewPyImp.cpp index 7fc4fa9d9d..13fb912348 100644 --- a/src/Gui/LinkViewPyImp.cpp +++ b/src/Gui/LinkViewPyImp.cpp @@ -175,7 +175,7 @@ PyObject* LinkViewPy::setType(PyObject *args) { return nullptr; PY_TRY{ - getLinkViewPtr()->setNodeType((LinkView::SnapshotType)type, PyObject_IsTrue(sublink) ? true : false); + getLinkViewPtr()->setNodeType((LinkView::SnapshotType)type, Base::asBoolean(sublink)); Py_Return; } PY_CATCH; } diff --git a/src/Gui/MDIViewPy.cpp b/src/Gui/MDIViewPy.cpp index 168f4cf788..a78bea8ee0 100644 --- a/src/Gui/MDIViewPy.cpp +++ b/src/Gui/MDIViewPy.cpp @@ -269,7 +269,7 @@ Py::Object MDIViewPy::getActiveObject(const Py::Tuple& args) if (!obj) return Py::None(); - if (PyObject_IsTrue(resolve) ? true : false) + if (Base::asBoolean(resolve)) return Py::asObject(obj->getPyObject()); return Py::TupleN( diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 63b15d6a12..5c35241465 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -2072,7 +2072,7 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args) float x = 0, y = 0, z = 0; if (PyArg_ParseTuple(args, "ss|sfffO!", &docname, &objname , &subname,&x,&y,&z,&PyBool_Type,&clearPreselect)) { - Selection().addSelection(docname,objname,subname,x,y,z,nullptr,PyObject_IsTrue(clearPreselect) ? true : false); + Selection().addSelection(docname, objname, subname, x, y, z, nullptr, Base::asBoolean(clearPreselect)); Py_Return; } @@ -2091,7 +2091,7 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args) Selection().addSelection(docObj->getDocument()->getName(), docObj->getNameInDocument(), - subname,x,y,z,nullptr,PyObject_IsTrue(clearPreselect) ? true : false); + subname, x, y, z, nullptr, Base::asBoolean(clearPreselect)); Py_Return; } @@ -2114,7 +2114,7 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args) std::string subname = static_cast(Py::String(*it)); Selection().addSelection(docObj->getDocument()->getName(), docObj->getNameInDocument(), - subname.c_str(),0,0,0,nullptr,PyObject_IsTrue(clearPreselect) ? true : false); + subname.c_str(), 0, 0, 0, nullptr, Base::asBoolean(clearPreselect)); } Py_Return; @@ -2146,7 +2146,7 @@ PyObject *SelectionSingleton::sUpdateSelection(PyObject * /*self*/, PyObject *ar return nullptr; } - Selection().updateSelection(PyObject_IsTrue(show) ? true : false, + Selection().updateSelection(Base::asBoolean(show), docObj->getDocument()->getName(), docObj->getNameInDocument(), subname); Py_Return; @@ -2193,7 +2193,7 @@ PyObject *SelectionSingleton::sClearSelection(PyObject * /*self*/, PyObject *arg if (!PyArg_ParseTuple(args, "|sO!", &documentName, &PyBool_Type, &clearPreSelect)) return nullptr; } - Selection().clearSelection(documentName,PyObject_IsTrue(clearPreSelect) ? true : false); + Selection().clearSelection(documentName, Base::asBoolean(clearPreSelect)); Py_Return; } @@ -2263,7 +2263,7 @@ PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args) try { std::vector sel; - sel = Selection().getSelection(documentName, toEnum(resolve), PyObject_IsTrue(single) ? true : false); + sel = Selection().getSelection(documentName, toEnum(resolve), Base::asBoolean(single)); std::set noduplicates; std::vector selectedObjects; // keep the order of selection @@ -2293,7 +2293,7 @@ PyObject *SelectionSingleton::sEnablePickedList(PyObject * /*self*/, PyObject *a if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &enable)) return nullptr; - Selection().enablePickedList(PyObject_IsTrue(enable) ? true : false); + Selection().enablePickedList(Base::asBoolean(enable)); Py_Return; } @@ -2382,7 +2382,7 @@ PyObject *SelectionSingleton::sGetSelectionEx(PyObject * /*self*/, PyObject *arg try { std::vector sel; sel = Selection().getSelectionEx(documentName, - App::DocumentObject::getClassTypeId(), toEnum(resolve), PyObject_IsTrue(single) ? true : false); + App::DocumentObject::getClassTypeId(), toEnum(resolve), Base::asBoolean(single)); Py::List list; for (std::vector::iterator it = sel.begin(); it != sel.end(); ++it) { @@ -2543,7 +2543,7 @@ PyObject *SelectionSingleton::sSetVisible(PyObject * /*self*/, PyObject *args) vis = VisToggle; } else if (PyBool_Check(visible)) { - vis = PyObject_IsTrue(visible) ? VisShow : VisHide; + vis = Base::asBoolean(visible) ? VisShow : VisHide; } else { PyErr_SetString(PyExc_ValueError, "Argument is neither None nor Bool"); @@ -2563,7 +2563,7 @@ PyObject *SelectionSingleton::sPushSelStack(PyObject * /*self*/, PyObject *args) if (!PyArg_ParseTuple(args, "|O!O!", &PyBool_Type, &clear, &PyBool_Type, &overwrite)) return nullptr; - Selection().selStackPush(PyObject_IsTrue(clear), PyObject_IsTrue(overwrite) ? true : false); + Selection().selStackPush(Base::asBoolean(clear), Base::asBoolean(overwrite)); Py_Return; } @@ -2596,7 +2596,7 @@ PyObject *SelectionSingleton::sHasSubSelection(PyObject * /*self*/, PyObject *ar PY_TRY { return Py::new_reference_to( - Py::Boolean(Selection().hasSubSelection(doc,PyObject_IsTrue(subElement) ? true : false))); + Py::Boolean(Selection().hasSubSelection(doc, Base::asBoolean(subElement)))); } PY_CATCH; } diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 58e39589d0..5b3c862df4 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -885,13 +885,13 @@ Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args) float q1 = (float)Py::Float(tuple[1]); float q2 = (float)Py::Float(tuple[2]); float q3 = (float)Py::Float(tuple[3]); - getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), PyObject_IsTrue(m) ? true : false); + getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), Base::asBoolean(m)); } else if (PyObject_TypeCheck(o, &Base::RotationPy::Type)) { Base::Rotation r = (Base::Rotation)Py::Rotation(o,false); double q0, q1, q2, q3; r.getValue(q0, q1, q2, q3); - getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), PyObject_IsTrue(m) ? true : false); + getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), Base::asBoolean(m)); } else { throw Py::ValueError("Neither tuple nor rotation object"); @@ -1297,7 +1297,7 @@ Py::Object View3DInventorPy::dump(const Py::Tuple& args) throw Py::Exception(); try { - getView3DIventorPtr()->dump(filename, PyObject_IsTrue(onlyVisible) ? true : false); + getView3DIventorPtr()->dump(filename, Base::asBoolean(onlyVisible)); return Py::None(); } catch (const Base::Exception& e) { @@ -2592,7 +2592,7 @@ Py::Object View3DInventorPy::getActiveObject(const Py::Tuple& args) if (!obj) return Py::None(); - if (PyObject_IsTrue(resolve) ? true : false) + if (Base::asBoolean(resolve)) return Py::asObject(obj->getPyObject()); return Py::TupleN( @@ -2660,8 +2660,8 @@ Py::Object View3DInventorPy::toggleClippingPlane(const Py::Tuple& args, const Py Base::Placement pla; if(pyPla!=Py_None) pla = *static_cast(pyPla)->getPlacementPtr(); - getView3DIventorPtr()->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing) ? true : false, - PyObject_IsTrue(noManip) ? true : false,pla); + getView3DIventorPtr()->getViewer()->toggleClippingPlane(toggle, Base::asBoolean(beforeEditing), + Base::asBoolean(noManip), pla); return Py::None(); } diff --git a/src/Gui/View3DViewerPy.cpp b/src/Gui/View3DViewerPy.cpp index 27da7d1e2c..afe5287547 100644 --- a/src/Gui/View3DViewerPy.cpp +++ b/src/Gui/View3DViewerPy.cpp @@ -414,7 +414,7 @@ Py::Object View3DInventorViewerPy::resetEditingRoot(const Py::Tuple& args) throw Py::Exception(); } try { - _viewer->resetEditingRoot(PyObject_IsTrue(updateLinks) ? true : false); + _viewer->resetEditingRoot(Base::asBoolean(updateLinks)); return Py::None(); } catch (const Base::Exception& e) { @@ -456,7 +456,7 @@ Py::Object View3DInventorViewerPy::setRedirectToSceneGraph(const Py::Tuple& args PyObject* m=Py_False; if (!PyArg_ParseTuple(args.ptr(), "O!", &PyBool_Type, &m)) throw Py::Exception(); - _viewer->setRedirectToSceneGraph(PyObject_IsTrue(m) ? true : false); + _viewer->setRedirectToSceneGraph(Base::asBoolean(m)); return Py::None(); } @@ -473,7 +473,7 @@ Py::Object View3DInventorViewerPy::setEnabledNaviCube(const Py::Tuple& args) PyObject* m=Py_False; if (!PyArg_ParseTuple(args.ptr(), "O!", &PyBool_Type, &m)) throw Py::Exception(); - _viewer->setEnabledNaviCube(PyObject_IsTrue(m) ? true : false); + _viewer->setEnabledNaviCube(Base::asBoolean(m)); return Py::None(); } diff --git a/src/Gui/ViewProviderExtensionPyImp.cpp b/src/Gui/ViewProviderExtensionPyImp.cpp index cbd30f4bfc..3bb08a0392 100644 --- a/src/Gui/ViewProviderExtensionPyImp.cpp +++ b/src/Gui/ViewProviderExtensionPyImp.cpp @@ -57,7 +57,7 @@ PyObject* ViewProviderExtensionPy::setIgnoreOverlayIcon(PyObject *args) } } - ext->setIgnoreOverlayIcon(PyObject_IsTrue(ignore) ? true : false); + ext->setIgnoreOverlayIcon(Base::asBoolean(ignore)); Py_Return; } diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index c2b510e1a0..ce00d8b3f6 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -77,7 +77,7 @@ PyObject* ViewProviderPy::addProperty(PyObject *args) App::Property* prop=nullptr; try { prop = getViewProviderPtr()->addDynamicProperty(sType,sName,sGroup,sDocStr.c_str(),attr, - PyObject_IsTrue(ro) ? true : false, PyObject_IsTrue(hd) ? true : false); + Base::asBoolean(ro), Base::asBoolean(hd)); } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); @@ -427,7 +427,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) } } - Py::Int ret(getViewProviderPtr()->partialRender(values, PyObject_IsTrue(clear) ? true : false)); + Py::Int ret(getViewProviderPtr()->partialRender(values, Base::asBoolean(clear))); return Py::new_reference_to(ret); } @@ -532,7 +532,7 @@ PyObject *ViewProviderPy::getBoundingBox(PyObject *args) { View3DInventor *view = nullptr; if(pyView) view = static_cast(pyView)->getView3DIventorPtr(); - auto bbox = getViewProviderPtr()->getBoundingBox(subname,PyObject_IsTrue(transform) ? true : false,view); + auto bbox = getViewProviderPtr()->getBoundingBox(subname, Base::asBoolean(transform), view); return new Base::BoundBoxPy(new Base::BoundBox3d(bbox)); } PY_CATCH; diff --git a/src/Main/FreeCADGuiPy.cpp b/src/Main/FreeCADGuiPy.cpp index 5388226d6f..77af8dc250 100644 --- a/src/Main/FreeCADGuiPy.cpp +++ b/src/Main/FreeCADGuiPy.cpp @@ -101,7 +101,7 @@ FreeCADGui_showMainWindow(PyObject * /*self*/, PyObject *args) static bool thr = false; if (!qApp) { - if ((PyObject_IsTrue(inThread) ? true : false) && !thr) { + if (Base::asBoolean(inThread) && !thr) { thr = true; std::thread t([]() { static int argc = 0;