Gui: Use PyObject_IsTrue in combination with conditional ternary operator

This commit is contained in:
marioalexis
2022-05-17 12:41:58 -03:00
committed by Chris Hennes
parent 80492e81fa
commit ae56fb62a7
8 changed files with 35 additions and 34 deletions

View File

@@ -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();
}