Gui: Use PyObject_IsTrue in combination with conditional ternary operator
This commit is contained in:
committed by
Chris Hennes
parent
80492e81fa
commit
ae56fb62a7
@@ -831,7 +831,7 @@ PyObject* Application::sSendActiveView(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
const char* ppReturn = nullptr;
|
||||
if (!Instance->sendMsgToActiveView(psCommandStr,&ppReturn)) {
|
||||
if (!PyObject_IsTrue(suppress))
|
||||
if (PyObject_IsTrue(suppress) ? false : true)
|
||||
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))
|
||||
if (PyObject_IsTrue(suppress) ? false : true)
|
||||
Base::Console().Warning("Unknown view command: %s\n",psCommandStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,14 +92,14 @@ PyObject* CommandPy::listByShortcut(PyObject *args)
|
||||
|
||||
std::vector <Command*> cmds = Application::Instance->commandManager().getAllCommands();
|
||||
std::vector <std::string> matches;
|
||||
for (Command* c : cmds){
|
||||
for (Command* c : cmds) {
|
||||
Action* action = c->getAction();
|
||||
if (action){
|
||||
if (action) {
|
||||
QString spc = QString::fromLatin1(" ");
|
||||
if(PyObject_IsTrue(bIsRegularExp)){
|
||||
if (PyObject_IsTrue(bIsRegularExp) ? true : false) {
|
||||
QRegExp re = QRegExp(QString::fromLatin1(shortcut_to_find));
|
||||
re.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
if (!re.isValid()){
|
||||
if (!re.isValid()) {
|
||||
std::stringstream str;
|
||||
str << "Invalid regular expression:" << ' ' << shortcut_to_find;
|
||||
throw Py::RuntimeError(str.str());
|
||||
|
||||
@@ -171,11 +171,11 @@ PyObject* LinkViewPy::setTransform(PyObject *args) {
|
||||
PyObject* LinkViewPy::setType(PyObject *args) {
|
||||
short type;
|
||||
PyObject *sublink = Py_True;
|
||||
if (!PyArg_ParseTuple(args, "h|O", &type,&sublink))
|
||||
if (!PyArg_ParseTuple(args, "h|O!", &type, &PyBool_Type, &sublink))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY{
|
||||
getLinkViewPtr()->setNodeType((LinkView::SnapshotType)type,PyObject_IsTrue(sublink));
|
||||
getLinkViewPtr()->setNodeType((LinkView::SnapshotType)type, PyObject_IsTrue(sublink) ? true : false);
|
||||
Py_Return;
|
||||
} PY_CATCH;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ Py::Object MDIViewPy::getActiveObject(const Py::Tuple& args)
|
||||
{
|
||||
const char* name;
|
||||
PyObject *resolve = Py_True;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O", &name,&resolve))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O!", &name, &PyBool_Type, &resolve))
|
||||
throw Py::Exception();
|
||||
|
||||
App::DocumentObject *parent = nullptr;
|
||||
@@ -269,7 +269,7 @@ Py::Object MDIViewPy::getActiveObject(const Py::Tuple& args)
|
||||
if (!obj)
|
||||
return Py::None();
|
||||
|
||||
if (PyObject_IsTrue(resolve))
|
||||
if (PyObject_IsTrue(resolve) ? true : false)
|
||||
return Py::asObject(obj->getPyObject());
|
||||
|
||||
return Py::TupleN(
|
||||
|
||||
@@ -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));
|
||||
Selection().addSelection(docname,objname,subname,x,y,z,nullptr,PyObject_IsTrue(clearPreselect) ? true : false);
|
||||
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));
|
||||
subname,x,y,z,nullptr,PyObject_IsTrue(clearPreselect) ? true : false);
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
@@ -2114,7 +2114,7 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args)
|
||||
std::string subname = static_cast<std::string>(Py::String(*it));
|
||||
Selection().addSelection(docObj->getDocument()->getName(),
|
||||
docObj->getNameInDocument(),
|
||||
subname.c_str(),0,0,0,nullptr,PyObject_IsTrue(clearPreselect));
|
||||
subname.c_str(),0,0,0,nullptr,PyObject_IsTrue(clearPreselect) ? true : false);
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
@@ -2146,7 +2146,7 @@ PyObject *SelectionSingleton::sUpdateSelection(PyObject * /*self*/, PyObject *ar
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Selection().updateSelection(PyObject_IsTrue(show),
|
||||
Selection().updateSelection(PyObject_IsTrue(show) ? true : false,
|
||||
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));
|
||||
Selection().clearSelection(documentName,PyObject_IsTrue(clearPreSelect) ? true : false);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
@@ -2263,7 +2263,7 @@ PyObject *SelectionSingleton::sGetSelection(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
try {
|
||||
std::vector<SelectionSingleton::SelObj> sel;
|
||||
sel = Selection().getSelection(documentName, toEnum(resolve), PyObject_IsTrue(single));
|
||||
sel = Selection().getSelection(documentName, toEnum(resolve), PyObject_IsTrue(single) ? true : false);
|
||||
|
||||
std::set<App::DocumentObject*> noduplicates;
|
||||
std::vector<App::DocumentObject*> 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));
|
||||
Selection().enablePickedList(PyObject_IsTrue(enable) ? true : false);
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
@@ -2382,7 +2382,7 @@ PyObject *SelectionSingleton::sGetSelectionEx(PyObject * /*self*/, PyObject *arg
|
||||
try {
|
||||
std::vector<SelectionObject> sel;
|
||||
sel = Selection().getSelectionEx(documentName,
|
||||
App::DocumentObject::getClassTypeId(), toEnum(resolve), PyObject_IsTrue(single));
|
||||
App::DocumentObject::getClassTypeId(), toEnum(resolve), PyObject_IsTrue(single) ? true : false);
|
||||
|
||||
Py::List list;
|
||||
for (std::vector<SelectionObject>::iterator it = sel.begin(); it != sel.end(); ++it) {
|
||||
@@ -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));
|
||||
Selection().selStackPush(PyObject_IsTrue(clear), PyObject_IsTrue(overwrite) ? true : false);
|
||||
|
||||
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))));
|
||||
Py::Boolean(Selection().hasSubSelection(doc,PyObject_IsTrue(subElement) ? true : false)));
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), PyObject_IsTrue(m) ? true : false);
|
||||
}
|
||||
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));
|
||||
getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), PyObject_IsTrue(m) ? true : false);
|
||||
}
|
||||
else {
|
||||
throw Py::ValueError("Neither tuple nor rotation object");
|
||||
@@ -1293,11 +1293,11 @@ Py::Object View3DInventorPy::dump(const Py::Tuple& args)
|
||||
{
|
||||
char* filename;
|
||||
PyObject *onlyVisible = Py_False;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O", &filename, &onlyVisible))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O!", &filename, &PyBool_Type, &onlyVisible))
|
||||
throw Py::Exception();
|
||||
|
||||
try {
|
||||
getView3DIventorPtr()->dump(filename, PyObject_IsTrue(onlyVisible));
|
||||
getView3DIventorPtr()->dump(filename, PyObject_IsTrue(onlyVisible) ? true : false);
|
||||
return Py::None();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
@@ -2583,7 +2583,7 @@ Py::Object View3DInventorPy::getActiveObject(const Py::Tuple& args)
|
||||
{
|
||||
char* name;
|
||||
PyObject *resolve = Py_True;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O", &name,&resolve))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|O!", &name, &PyBool_Type, &resolve))
|
||||
throw Py::Exception();
|
||||
|
||||
App::DocumentObject *parent = nullptr;
|
||||
@@ -2592,7 +2592,7 @@ Py::Object View3DInventorPy::getActiveObject(const Py::Tuple& args)
|
||||
if (!obj)
|
||||
return Py::None();
|
||||
|
||||
if (PyObject_IsTrue(resolve))
|
||||
if (PyObject_IsTrue(resolve) ? true : false)
|
||||
return Py::asObject(obj->getPyObject());
|
||||
|
||||
return Py::TupleN(
|
||||
@@ -2652,15 +2652,16 @@ Py::Object View3DInventorPy::toggleClippingPlane(const Py::Tuple& args, const Py
|
||||
PyObject *beforeEditing = Py_False;
|
||||
PyObject *noManip = Py_True;
|
||||
PyObject *pyPla = Py_None;
|
||||
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "|iOOO!", keywords,
|
||||
&toggle, &beforeEditing, &noManip, &Base::PlacementPy::Type,&pyPla))
|
||||
if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "|iO!O!O!", keywords,
|
||||
&toggle, &PyBool_Type, &beforeEditing, &PyBool_Type, &noManip,
|
||||
&Base::PlacementPy::Type, &pyPla))
|
||||
throw Py::Exception();
|
||||
|
||||
Base::Placement pla;
|
||||
if(pyPla!=Py_None)
|
||||
pla = *static_cast<Base::PlacementPy*>(pyPla)->getPlacementPtr();
|
||||
getView3DIventorPtr()->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing),
|
||||
PyObject_IsTrue(noManip),pla);
|
||||
getView3DIventorPtr()->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing) ? true : false,
|
||||
PyObject_IsTrue(noManip) ? true : false,pla);
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
|
||||
@@ -410,11 +410,11 @@ Py::Object View3DInventorViewerPy::setupEditingRoot(const Py::Tuple& args)
|
||||
Py::Object View3DInventorViewerPy::resetEditingRoot(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *updateLinks = Py_True;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|O", &updateLinks)) {
|
||||
if (!PyArg_ParseTuple(args.ptr(), "|O!", &PyBool_Type, &updateLinks)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
try {
|
||||
_viewer->resetEditingRoot(PyObject_IsTrue(updateLinks));
|
||||
_viewer->resetEditingRoot(PyObject_IsTrue(updateLinks) ? true : false);
|
||||
return Py::None();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
@@ -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));
|
||||
_viewer->setEnabledNaviCube(PyObject_IsTrue(m) ? true : false);
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
|
||||
@@ -532,7 +532,7 @@ PyObject *ViewProviderPy::getBoundingBox(PyObject *args) {
|
||||
View3DInventor *view = nullptr;
|
||||
if(pyView)
|
||||
view = static_cast<View3DInventorPy*>(pyView)->getView3DIventorPtr();
|
||||
auto bbox = getViewProviderPtr()->getBoundingBox(subname,PyObject_IsTrue(transform),view);
|
||||
auto bbox = getViewProviderPtr()->getBoundingBox(subname,PyObject_IsTrue(transform) ? true : false,view);
|
||||
return new Base::BoundBoxPy(new Base::BoundBox3d(bbox));
|
||||
}
|
||||
PY_CATCH;
|
||||
|
||||
Reference in New Issue
Block a user