Base: Wrap PyArg_ParseTupleAndKeywords

This commit is contained in:
Chris Hennes
2023-08-25 13:15:59 -05:00
parent ada736696e
commit 3b79fd58b7
4 changed files with 15 additions and 10 deletions

View File

@@ -320,6 +320,7 @@ SET(FreeCADBase_HPP_SRCS
ProgressIndicatorPy.h
PyExport.h
PyObjectBase.h
PyWrapParseTupleAndKeywords.h
PythonTypeExt.h
QtTools.h
Reader.h

View File

@@ -27,6 +27,7 @@
#include "Persistence.h"
#include "Writer.h"
#include <Base/PyWrapParseTupleAndKeywords.h>
// inclusion of the generated files (generated By PersitancePy.xml)
#include "PersistencePy.h"
@@ -59,9 +60,9 @@ Py::Int PersistencePy::getMemSize() const
PyObject* PersistencePy::dumpContent(PyObject *args, PyObject *kwds)
{
int compression = 3;
static char* kwds_def[] = {"Compression",nullptr};
static const std::array<const char *, 2> kwds_def {"Compression", nullptr};
PyErr_Clear();
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwds_def, &compression)) {
if (!Wrapped_ParseTupleAndKeywords(args, kwds, "|i", kwds_def, &compression)) {
return nullptr;
}

View File

@@ -24,6 +24,7 @@
#include "PreCompiled.h"
#include "GeometryPyCXX.h"
#include <Base/PyWrapParseTupleAndKeywords.h>
// inclusion of the generated files (generated out of PlacementPy.xml)
#include "PlacementPy.h"
@@ -172,14 +173,15 @@ PyObject* PlacementPy::translate(PyObject * args)
PyObject* PlacementPy::rotate(PyObject *args, PyObject *kwds)
{
double angle{};
char *keywords[] = { "center", "axis", "angle", "comp", nullptr };
static const std::array<const char *, 6> kwlist { "center", "axis", "angle", "comp", nullptr };
Vector3d center;
Vector3d axis;
PyObject* pyComp = Py_False;
PyObject* pyComp = Py_False; // NOLINT
if (!PyArg_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|O!", keywords, &center.x, &center.y, &center.z,
&axis.x, &axis.y, &axis.z, &angle, &PyBool_Type, &pyComp))
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "(ddd)(ddd)d|O!", kwlist, &center.x, &center.y, &center.z,
&axis.x, &axis.y, &axis.z, &angle, &PyBool_Type, &pyComp)) {
return nullptr;
}
try {
/*

View File

@@ -25,6 +25,7 @@
#include <Base/GeometryPyCXX.h>
#include <Base/Tools.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
// inclusion of the generated files (generated out of RotationPy.xml)
#include "RotationPy.h"
@@ -76,16 +77,16 @@ int RotationPy::PyInit(PyObject* args, PyObject* kwds)
PyErr_Clear();
double angle{};
static char *kw_deg[] = {"Axis", "Degree", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", kw_deg, &(Base::VectorPy::Type), &o, &angle)) {
static const std::array<const char *, 3> kw_deg {"Axis", "Degree", nullptr};
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!d", kw_deg, &(Base::VectorPy::Type), &o, &angle)) {
// NOTE: The last parameter defines the rotation angle in degree.
getRotationPtr()->setValue(static_cast<Base::VectorPy*>(o)->value(), Base::toRadians<double>(angle));
return 0;
}
PyErr_Clear();
static char *kw_rad[] = {"Axis", "Radian", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", kw_rad, &(Base::VectorPy::Type), &o, &angle)) {
static const std::array<const char *, 3> kw_rad {"Axis", "Radian", nullptr};
if (Base::Wrapped_ParseTupleAndKeywords(args, kwds, "O!d", kw_rad, &(Base::VectorPy::Type), &o, &angle)) {
getRotationPtr()->setValue(static_cast<Base::VectorPy*>(o)->value(), angle);
return 0;
}