Base: misc patches
Convenience macros/function (in Interpreter.h) * FC_PY_GetObject/Callable(), look for callables in a python object, which will be used in future patch to improve performance in various python observer/features. * pyCall(WithKeywords)(), helper function to invoke the callable Matrix4D: * hasScale(), check if there is any scale in the transformation. If so, further check if the scale is uniform or not. This will be used in future patch for Part::TopoShape to decide which type of transform to apply. Placement: * translate/rotate(), new convenience API Rotation: * isSame/multiVec(), new convenience API Polygon2d: * Intersect(), GetCenter(), new convenience API. FlagToggler: * New class for exception safe flag toggling, similar to StateLocker but with template (actually, FlagToggler is added earlier by me). BitsetLocker: * New class for exception manipulation of a std::bitset variable.
This commit is contained in:
@@ -53,6 +53,40 @@
|
||||
|
||||
#include "Exception.h"
|
||||
|
||||
/** Helper macro to obtain callable from an object
|
||||
*
|
||||
* @param _pyobj: PyObject pointer
|
||||
* @param _name: the callable string name
|
||||
* @param _var: the callable variable to be assigned
|
||||
*
|
||||
* See FeaturePythonImp::init() for example usage
|
||||
*/
|
||||
#define FC_PY_GetCallable(_pyobj,_name,_var) \
|
||||
do {\
|
||||
_var = Py::Object();\
|
||||
if(PyObject_HasAttrString(_pyobj, _name)) {\
|
||||
Py::Object _obj(PyObject_GetAttrString (_pyobj, _name), true);\
|
||||
if(_obj.isCallable())\
|
||||
_var = _obj;\
|
||||
}\
|
||||
}while(0)
|
||||
|
||||
/** Helper macro to obtain attribute from an object
|
||||
*
|
||||
* @param _pyobj: PyObject pointer
|
||||
* @param _name: the attribute string name
|
||||
* @param _var: the attribute variable to be assigned
|
||||
*
|
||||
* See FeaturePythonImp::init() for example usage
|
||||
*/
|
||||
#define FC_PY_GetObject(_pyobj,_name,_var) \
|
||||
do {\
|
||||
_var = Py::Object();\
|
||||
if(PyObject_HasAttrString(_pyobj, _name))\
|
||||
_var = Py::asObject(PyObject_GetAttrString (_pyobj, _name));\
|
||||
}while(0)
|
||||
|
||||
|
||||
namespace Base {
|
||||
|
||||
using std::string;
|
||||
@@ -87,6 +121,20 @@ protected:
|
||||
PyObject *_exceptionType;
|
||||
};
|
||||
|
||||
inline Py::Object pyCall(PyObject *callable, PyObject *args=0) {
|
||||
PyObject *result = PyObject_CallObject(callable, args);
|
||||
if(!result)
|
||||
Base::PyException::ThrowException();
|
||||
return Py::asObject(result);
|
||||
}
|
||||
|
||||
inline Py::Object pyCallWithKeywords(PyObject *callable, PyObject *args, PyObject *kwds=0) {
|
||||
PyObject *result = PyObject_Call(callable, args, kwds);
|
||||
if(!result)
|
||||
Base::PyException::ThrowException();
|
||||
return Py::asObject(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* The SystemExitException is thrown if the Python-internal PyExc_SystemExit exception
|
||||
* was thrown.
|
||||
|
||||
Reference in New Issue
Block a user