Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2011-06-11 04:22:10 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2011-06-11 04:22:10 +0400
commit32c7e22d3696e3575f4b7d05c1f7140591e88809 (patch)
tree44d501cb62aebd638a7f7b5d0306ecc03e0deb5f /source/blender/python
parentdfcd01553536d63dab1037d0ea289b9d9d90c39c (diff)
parent6fb82a85c9a48c9fad6cb7b42994a9cd7b2b491a (diff)
Merged changes in the trunk up to revision 37388.
Conflicts resolved: release/scripts/startup/bl_ui/properties_render.py source/creator/SConscript source/blender/blenlib/intern/bpath.c source/blender/editors/space_outliner/outliner.c
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/BPY_extern.h14
-rw-r--r--source/blender/python/generic/CMakeLists.txt5
-rw-r--r--source/blender/python/generic/IDProp.c2
-rw-r--r--source/blender/python/generic/bgl.c29
-rw-r--r--source/blender/python/generic/bgl.h2
-rw-r--r--source/blender/python/generic/blf_py_api.c83
-rw-r--r--source/blender/python/generic/bpy_internal_import.c10
-rw-r--r--source/blender/python/generic/bpy_internal_import.h2
-rw-r--r--source/blender/python/generic/mathutils.c4
-rw-r--r--source/blender/python/generic/mathutils_Color.c289
-rw-r--r--source/blender/python/generic/mathutils_Euler.c44
-rw-r--r--source/blender/python/generic/mathutils_Matrix.c128
-rw-r--r--source/blender/python/generic/mathutils_Quaternion.c78
-rw-r--r--source/blender/python/generic/mathutils_Vector.c132
-rw-r--r--source/blender/python/generic/mathutils_geometry.c111
-rw-r--r--source/blender/python/generic/noise_py_api.c110
-rw-r--r--source/blender/python/intern/CMakeLists.txt5
-rw-r--r--source/blender/python/intern/bpy.c32
-rw-r--r--source/blender/python/intern/bpy.h2
-rw-r--r--source/blender/python/intern/bpy_app.h2
-rw-r--r--source/blender/python/intern/bpy_driver.c7
-rw-r--r--source/blender/python/intern/bpy_interface.c2
-rw-r--r--source/blender/python/intern/bpy_library.c79
-rw-r--r--source/blender/python/intern/bpy_props.c587
-rw-r--r--source/blender/python/intern/bpy_props.h2
-rw-r--r--source/blender/python/intern/bpy_rna.c170
-rw-r--r--source/blender/python/intern/bpy_rna.h19
27 files changed, 1391 insertions, 559 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index e8796a6f8dd..ae5253d07a0 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -67,14 +67,14 @@ int BPY_is_pyconstraint(struct Text *text);
// void BPY_free_pyconstraint_links(struct Text *text);
//
void BPY_python_start(int argc, const char **argv);
-void BPY_python_end( void );
-// void init_syspath( int first_time );
-// void syspath_append( char *dir );
-// void BPY_rebuild_syspath( void );
-// int BPY_path_update( void );
+void BPY_python_end(void);
+// void init_syspath(int first_time);
+// void syspath_append(char *dir);
+// void BPY_rebuild_syspath(void);
+// int BPY_path_update(void);
//
-// int BPY_Err_getLinenumber( void );
-// const char *BPY_Err_getFilename( void );
+// int BPY_Err_getLinenumber(void);
+// const char *BPY_Err_getFilename(void);
/* 2.5 UI Scripts */
int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports);
diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt
index 5e4eae4f809..0889c77f9ad 100644
--- a/source/blender/python/generic/CMakeLists.txt
+++ b/source/blender/python/generic/CMakeLists.txt
@@ -25,6 +25,9 @@ set(INC
../../blenkernel
../../blenloader
../../../../intern/guardedalloc
+)
+
+set(INC_SYS
${GLEW_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
)
@@ -60,4 +63,4 @@ set(SRC
)
-blender_add_lib(bf_python_ext "${SRC}" "${INC}")
+blender_add_lib(bf_python_ext "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/generic/IDProp.c b/source/blender/python/generic/IDProp.c
index 8330927d920..a807624187a 100644
--- a/source/blender/python/generic/IDProp.c
+++ b/source/blender/python/generic/IDProp.c
@@ -114,7 +114,7 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
Py_RETURN_NONE;
}
-#if 0 /* UNUSED, currenly assignment overwrites into new properties, rather then setting in-place */
+#if 0 /* UNUSED, currenly assignment overwrites into new properties, rather than setting in-place */
static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
{
switch (prop->type) {
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 730db73e685..b5a693c397c 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -45,7 +45,7 @@
#include "BLI_utildefines.h"
-static char Method_Buffer_doc[] =
+PyDoc_STRVAR(Method_Buffer_doc,
"(type, dimensions, [template]) - Create a new Buffer object\n\n\
(type) - The format to store data in\n\
(dimensions) - An int or sequence specifying the dimensions of the buffer\n\
@@ -59,18 +59,19 @@ will have len(sequence) dimensions, where the size for each dimension\n\
is determined by the value in the sequence at that index.\n\n\
For example, passing [100, 100] will create a 2 dimensional\n\
square buffer. Passing [16, 16, 32] will create a 3 dimensional\n\
-buffer which is twice as deep as it is wide or high.";
+buffer which is twice as deep as it is wide or high."
+);
-static PyObject *Method_Buffer( PyObject * self, PyObject *args );
+static PyObject *Method_Buffer(PyObject *self, PyObject *args);
/* Buffer sequence methods */
-static int Buffer_len( PyObject * self );
-static PyObject *Buffer_item( PyObject * self, int i );
-static PyObject *Buffer_slice( PyObject * self, int begin, int end );
-static int Buffer_ass_item( PyObject * self, int i, PyObject * v );
-static int Buffer_ass_slice( PyObject * self, int begin, int end,
- PyObject * seq );
+static int Buffer_len(PyObject *self);
+static PyObject *Buffer_item(PyObject *self, int i);
+static PyObject *Buffer_slice(PyObject *self, int begin, int end);
+static int Buffer_ass_item(PyObject *self, int i, PyObject *v);
+static int Buffer_ass_slice(PyObject *self, int begin, int end,
+ PyObject *seq);
static PySequenceMethods Buffer_SeqMethods = {
( lenfunc ) Buffer_len, /*sq_length */
@@ -85,11 +86,11 @@ static PySequenceMethods Buffer_SeqMethods = {
(ssizeargfunc) NULL, /* sq_inplace_repeat */
};
-static void Buffer_dealloc( PyObject * self );
-static PyObject *Buffer_tolist( PyObject * self );
-static PyObject *Buffer_dimensions( PyObject * self );
-static PyObject *Buffer_getattr( PyObject * self, char *name );
-static PyObject *Buffer_repr( PyObject * self );
+static void Buffer_dealloc(PyObject *self);
+static PyObject *Buffer_tolist(PyObject *self);
+static PyObject *Buffer_dimensions(PyObject *self);
+static PyObject *Buffer_getattr(PyObject *self, char *name);
+static PyObject *Buffer_repr(PyObject *self);
PyTypeObject BGL_bufferType = {
PyVarObject_HEAD_INIT(NULL, 0)
diff --git a/source/blender/python/generic/bgl.h b/source/blender/python/generic/bgl.h
index a870e82d4fd..81b570c8505 100644
--- a/source/blender/python/generic/bgl.h
+++ b/source/blender/python/generic/bgl.h
@@ -55,7 +55,7 @@ int BGL_typeSize( int type );
/*@ For Python access to OpenGL functions requiring a pointer. */
typedef struct _Buffer {
PyObject_VAR_HEAD
- PyObject * parent;
+ PyObject *parent;
int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */
int ndimensions;
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 0653f967c14..3cf0b0f1f27 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -36,7 +36,7 @@
-static char py_blf_position_doc[] =
+PyDoc_STRVAR(py_blf_position_doc,
".. function:: position(fontid, x, y, z)\n"
"\n"
" Set the position for drawing text.\n"
@@ -48,7 +48,8 @@ static char py_blf_position_doc[] =
" :arg y: Y axis position to draw the text.\n"
" :type y: float\n"
" :arg z: Z axis position to draw the text.\n"
-" :type z: float\n";
+" :type z: float\n"
+);
static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args)
{
@@ -64,7 +65,7 @@ static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args)
}
-static char py_blf_size_doc[] =
+PyDoc_STRVAR(py_blf_size_doc,
".. function:: size(fontid, size, dpi)\n"
"\n"
" Set the size and dpi for drawing text.\n"
@@ -74,8 +75,8 @@ static char py_blf_size_doc[] =
" :arg size: Point size of the font.\n"
" :type size: int\n"
" :arg dpi: dots per inch value to use for drawing.\n"
-" :type dpi: int\n";
-
+" :type dpi: int\n"
+);
static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args)
{
int fontid, size, dpi;
@@ -89,7 +90,7 @@ static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args)
}
-static char py_blf_aspect_doc[] =
+PyDoc_STRVAR(py_blf_aspect_doc,
".. function:: aspect(fontid, aspect)\n"
"\n"
" Set the aspect for drawing text.\n"
@@ -97,8 +98,8 @@ static char py_blf_aspect_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg aspect: The aspect ratio for text drawing to use.\n"
-" :type aspect: float\n";
-
+" :type aspect: float\n"
+);
static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
{
float aspect;
@@ -113,7 +114,7 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
}
-static char py_blf_blur_doc[] =
+PyDoc_STRVAR(py_blf_blur_doc,
".. function:: blur(fontid, radius)\n"
"\n"
" Set the blur radius for drawing text.\n"
@@ -121,8 +122,8 @@ static char py_blf_blur_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg radius: The radius for blurring text (in pixels).\n"
-" :type radius: int\n";
-
+" :type radius: int\n"
+);
static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args)
{
int blur, fontid;
@@ -136,7 +137,7 @@ static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args)
}
-static char py_blf_draw_doc[] =
+PyDoc_STRVAR(py_blf_draw_doc,
".. function:: draw(fontid, text)\n"
"\n"
" Draw text in the current context.\n"
@@ -144,8 +145,8 @@ static char py_blf_draw_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg text: the text to draw.\n"
-" :type text: string\n";
-
+" :type text: string\n"
+);
static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args)
{
char *text;
@@ -160,7 +161,7 @@ static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_dimensions_doc[] =
+PyDoc_STRVAR(py_blf_dimensions_doc,
".. function:: dimensions(fontid, text)\n"
"\n"
" Return the width and height of the text.\n"
@@ -170,8 +171,8 @@ static char py_blf_dimensions_doc[] =
" :arg text: the text to draw.\n"
" :type text: string\n"
" :return: the width and height of the text.\n"
-" :rtype: tuple of 2 floats\n";
-
+" :rtype: tuple of 2 floats\n"
+);
static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
{
char *text;
@@ -190,7 +191,7 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
return ret;
}
-static char py_blf_clipping_doc[] =
+PyDoc_STRVAR(py_blf_clipping_doc,
".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
"\n"
" Set the clipping, enable/disable using CLIPPING.\n"
@@ -204,8 +205,8 @@ static char py_blf_clipping_doc[] =
" :arg xmax: Clip the drawing area by these bounds.\n"
" :type xmax: float\n"
" :arg ymax: Clip the drawing area by these bounds.\n"
-" :type ymax: float\n";
-
+" :type ymax: float\n"
+);
static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args)
{
float xmin, ymin, xmax, ymax;
@@ -219,7 +220,7 @@ static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_disable_doc[] =
+PyDoc_STRVAR(py_blf_disable_doc,
".. function:: disable(fontid, option)\n"
"\n"
" Disable option.\n"
@@ -227,8 +228,8 @@ static char py_blf_disable_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
-" :type option: int\n";
-
+" :type option: int\n"
+);
static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
@@ -241,7 +242,7 @@ static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_enable_doc[] =
+PyDoc_STRVAR(py_blf_enable_doc,
".. function:: enable(fontid, option)\n"
"\n"
" Enable option.\n"
@@ -249,8 +250,8 @@ static char py_blf_enable_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
-" :type option: int\n";
-
+" :type option: int\n"
+);
static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
@@ -263,7 +264,7 @@ static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_rotation_doc[] =
+PyDoc_STRVAR(py_blf_rotation_doc,
".. function:: rotation(fontid, angle)\n"
"\n"
" Set the text rotation angle, enable/disable using ROTATION.\n"
@@ -271,8 +272,8 @@ static char py_blf_rotation_doc[] =
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg angle: The angle for text drawing to use.\n"
-" :type angle: float\n";
-
+" :type angle: float\n"
+);
static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args)
{
float angle;
@@ -286,7 +287,7 @@ static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_shadow_doc[] =
+PyDoc_STRVAR(py_blf_shadow_doc,
".. function:: shadow(fontid, level, r, g, b, a)\n"
"\n"
" Shadow options, enable/disable using SHADOW .\n"
@@ -302,8 +303,8 @@ static char py_blf_shadow_doc[] =
" :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
" :type b: float\n"
" :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
-" :type a: float\n";
-
+" :type a: float\n"
+);
static PyObject *py_blf_shadow(PyObject *UNUSED(self), PyObject *args)
{
int level, fontid;
@@ -322,7 +323,7 @@ static PyObject *py_blf_shadow(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_shadow_offset_doc[] =
+PyDoc_STRVAR(py_blf_shadow_offset_doc,
".. function:: shadow_offset(fontid, x, y)\n"
"\n"
" Set the offset for shadow text.\n"
@@ -332,8 +333,8 @@ static char py_blf_shadow_offset_doc[] =
" :arg x: Vertical shadow offset value in pixels.\n"
" :type x: float\n"
" :arg y: Horizontal shadow offset value in pixels.\n"
-" :type y: float\n";
-
+" :type y: float\n"
+);
static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args)
{
int x, y, fontid;
@@ -346,7 +347,7 @@ static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
-static char py_blf_load_doc[] =
+PyDoc_STRVAR(py_blf_load_doc,
".. function:: load(filename)\n"
"\n"
" Load a new font.\n"
@@ -354,8 +355,8 @@ static char py_blf_load_doc[] =
" :arg filename: the filename of the font.\n"
" :type filename: string\n"
" :return: the new font's fontid or -1 if there was an error.\n"
-" :rtype: integer\n";
-
+" :rtype: integer\n"
+);
static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
{
char* filename;
@@ -384,9 +385,9 @@ static PyMethodDef BLF_methods[] = {
{NULL, NULL, 0, NULL}
};
-static char BLF_doc[] =
-"This module provides access to blenders text drawing functions.\n";
-
+PyDoc_STRVAR(BLF_doc,
+"This module provides access to blenders text drawing functions."
+);
static struct PyModuleDef BLF_module_def = {
PyModuleDef_HEAD_INIT,
"blf", /* m_name */
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index 96fe13bf6fc..f0158fe72c3 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -34,9 +34,6 @@
#include <Python.h>
#include <stddef.h>
-#include "compile.h" /* for the PyCodeObject */
-#include "eval.h" /* for PyEval_EvalCode */
-
#include "bpy_internal_import.h"
#include "MEM_guardedalloc.h"
@@ -51,7 +48,6 @@
/* UNUSED */
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h"
-#include "BKE_global.h" /* grr, only for G.main->name */
static Main *bpy_import_main= NULL;
@@ -97,7 +93,7 @@ void bpy_import_main_set(struct Main *maggie)
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
{
- BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : G.main->name, SEP, text->id.name+2);
+ BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : bpy_import_main->name, SEP, text->id.name+2);
}
PyObject *bpy_text_import(Text *text)
@@ -221,7 +217,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
}
-static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject * kw)
+static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
PyObject *exception, *err, *tb;
char *name;
@@ -274,7 +270,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
* our reload() module, to handle reloading in-memory scripts
*/
-static PyObject *blender_reload(PyObject *UNUSED(self), PyObject * module)
+static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
{
PyObject *exception, *err, *tb;
PyObject *newmodule= NULL;
diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h
index 0ef31229f8d..dd1596efe4e 100644
--- a/source/blender/python/generic/bpy_internal_import.h
+++ b/source/blender/python/generic/bpy_internal_import.h
@@ -59,7 +59,7 @@ void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text);
extern PyMethodDef bpy_import_meth;
extern PyMethodDef bpy_reload_meth;
-/* The game engine has its own Main struct, if this is set search this rather then G.main */
+/* The game engine has its own Main struct, if this is set search this rather than G.main */
struct Main *bpy_import_main_get(void);
void bpy_import_main_set(struct Main *maggie);
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c
index e94f7f798fc..30f4e5b7ffe 100644
--- a/source/blender/python/generic/mathutils.c
+++ b/source/blender/python/generic/mathutils.c
@@ -38,9 +38,9 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
-static char M_Mathutils_doc[] =
+PyDoc_STRVAR(M_Mathutils_doc,
"This module provides access to matrices, eulers, quaternions and vectors."
-;
+);
static int mathutils_array_parse_fast(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
{
PyObject *value_fast= NULL;
diff --git a/source/blender/python/generic/mathutils_Color.c b/source/blender/python/generic/mathutils_Color.c
index 2b68828ea0a..c59cb501d86 100644
--- a/source/blender/python/generic/mathutils_Color.c
+++ b/source/blender/python/generic/mathutils_Color.c
@@ -85,7 +85,7 @@ static PyObject *Color_ToTupleExt(ColorObject *self, int ndigits)
return ret;
}
-static char Color_copy_doc[] =
+PyDoc_STRVAR(Color_copy_doc,
".. function:: copy()\n"
"\n"
" Returns a copy of this color.\n"
@@ -93,8 +93,9 @@ static char Color_copy_doc[] =
" :return: A copy of the color.\n"
" :rtype: :class:`Color`\n"
"\n"
-" .. note:: use this to get a copy of a wrapped color with no reference to the original data.\n"
-;
+" .. note:: use this to get a copy of a wrapped color with\n"
+" no reference to the original data.\n"
+);
static PyObject *Color_copy(ColorObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -185,7 +186,7 @@ static PyObject *Color_item(ColorObject * self, int i)
}
//----------------------------object[]-------------------------
//sequence accessor (set)
-static int Color_ass_item(ColorObject * self, int i, PyObject * value)
+static int Color_ass_item(ColorObject * self, int i, PyObject *value)
{
float f = PyFloat_AsDouble(value);
@@ -232,7 +233,7 @@ static PyObject *Color_slice(ColorObject * self, int begin, int end)
}
//----------------------------object[z:y]------------------------
//sequence slice (set)
-static int Color_ass_slice(ColorObject * self, int begin, int end, PyObject * seq)
+static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
{
int i, size;
float col[COLOR_SIZE];
@@ -343,13 +344,279 @@ static PyMappingMethods Color_AsMapping = {
(objobjargproc)Color_ass_subscript
};
+/* numeric */
+
+
+/* addition: obj + obj */
+static PyObject *Color_add(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float col[COLOR_SIZE];
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color addition: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
+
+ return newColorObject(col, Py_NEW, Py_TYPE(v1));
+}
+
+/* addition in-place: obj += obj */
+static PyObject *Color_iadd(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color addition: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ add_vn_vn(color1->col, color2->col, COLOR_SIZE);
+
+ (void)BaseMath_WriteCallback(color1);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* subtraction: obj - obj */
+static PyObject *Color_sub(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float col[COLOR_SIZE];
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color subtraction: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
+
+ return newColorObject(col, Py_NEW, Py_TYPE(v1));
+}
+
+/* subtraction in-place: obj -= obj */
+static PyObject *Color_isub(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1= NULL, *color2= NULL;
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color subtraction: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ sub_vn_vn(color1->col, color2->col, COLOR_SIZE);
+
+ (void)BaseMath_WriteCallback(color1);
+ Py_INCREF(v1);
+ return v1;
+}
+
+static PyObject *color_mul_float(ColorObject *color, const float scalar)
+{
+ float tcol[COLOR_SIZE];
+ mul_vn_vn_fl(tcol, color->col, COLOR_SIZE, scalar);
+ return newColorObject(tcol, Py_NEW, Py_TYPE(color));
+}
+
+
+static PyObject *Color_mul(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float scalar;
+
+ if ColorObject_Check(v1) {
+ color1= (ColorObject *)v1;
+ if(BaseMath_ReadCallback(color1) == -1)
+ return NULL;
+ }
+ if ColorObject_Check(v2) {
+ color2= (ColorObject *)v2;
+ if(BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+ }
+
+
+ /* make sure v1 is always the vector */
+ if (color1 && color2) {
+ /* col * col, dont support yet! */
+ }
+ else if (color1) {
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR * FLOAT */
+ return color_mul_float(color1, scalar);
+ }
+ }
+ else if (color2) {
+ if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* FLOAT * COLOR */
+ return color_mul_float(color2, scalar);
+ }
+ }
+ else {
+ BLI_assert(!"internal error");
+ }
+
+ PyErr_Format(PyExc_TypeError, "Color multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name);
+ return NULL;
+}
+
+static PyObject *Color_div(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL;
+ float scalar;
+
+ if ColorObject_Check(v1) {
+ color1= (ColorObject *)v1;
+ if(BaseMath_ReadCallback(color1) == -1)
+ return NULL;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color division not supported in this order");
+ return NULL;
+ }
+
+ /* make sure v1 is always the vector */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR * FLOAT */
+ if(scalar==0.0f) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
+ return NULL;
+ }
+ return color_mul_float(color1, 1.0f / scalar);
+ }
+
+ PyErr_Format(PyExc_TypeError, "Color multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name);
+ return NULL;
+}
+
+/* mulplication in-place: obj *= obj */
+static PyObject *Color_imul(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color = (ColorObject *)v1;
+ float scalar;
+
+ if(BaseMath_ReadCallback(color) == -1)
+ return NULL;
+
+ /* only support color *= float */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR *= FLOAT */
+ mul_vn_fl(color->col, COLOR_SIZE, scalar);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color multiplication: arguments not acceptable for this operation");
+ return NULL;
+ }
+
+ (void)BaseMath_WriteCallback(color);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* mulplication in-place: obj *= obj */
+static PyObject *Color_idiv(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color = (ColorObject *)v1;
+ float scalar;
+
+ if(BaseMath_ReadCallback(color) == -1)
+ return NULL;
+
+ /* only support color /= float */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR /= FLOAT */
+ if(scalar==0.0f) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
+ return NULL;
+ }
+
+ mul_vn_fl(color->col, COLOR_SIZE, 1.0f / scalar);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color multiplication: arguments not acceptable for this operation");
+ return NULL;
+ }
+
+ (void)BaseMath_WriteCallback(color);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* -obj
+ returns the negative of this object*/
+static PyObject *Color_neg(ColorObject *self)
+{
+ float tcol[COLOR_SIZE];
+
+ if(BaseMath_ReadCallback(self) == -1)
+ return NULL;
+
+ negate_vn_vn(tcol, self->col, COLOR_SIZE);
+ return newColorObject(tcol, Py_NEW, Py_TYPE(self));
+}
+
+
+static PyNumberMethods Color_NumMethods = {
+ (binaryfunc) Color_add, /*nb_add*/
+ (binaryfunc) Color_sub, /*nb_subtract*/
+ (binaryfunc) Color_mul, /*nb_multiply*/
+ NULL, /*nb_remainder*/
+ NULL, /*nb_divmod*/
+ NULL, /*nb_power*/
+ (unaryfunc) Color_neg, /*nb_negative*/
+ (unaryfunc) NULL, /*tp_positive*/
+ (unaryfunc) NULL, /*tp_absolute*/
+ (inquiry) NULL, /*tp_bool*/
+ (unaryfunc) NULL, /*nb_invert*/
+ NULL, /*nb_lshift*/
+ (binaryfunc)NULL, /*nb_rshift*/
+ NULL, /*nb_and*/
+ NULL, /*nb_xor*/
+ NULL, /*nb_or*/
+ NULL, /*nb_int*/
+ NULL, /*nb_reserved*/
+ NULL, /*nb_float*/
+ Color_iadd, /* nb_inplace_add */
+ Color_isub, /* nb_inplace_subtract */
+ Color_imul, /* nb_inplace_multiply */
+ NULL, /* nb_inplace_remainder */
+ NULL, /* nb_inplace_power */
+ NULL, /* nb_inplace_lshift */
+ NULL, /* nb_inplace_rshift */
+ NULL, /* nb_inplace_and */
+ NULL, /* nb_inplace_xor */
+ NULL, /* nb_inplace_or */
+ NULL, /* nb_floor_divide */
+ Color_div, /* nb_true_divide */
+ NULL, /* nb_inplace_floor_divide */
+ Color_idiv, /* nb_inplace_true_divide */
+ NULL, /* nb_index */
+};
+
/* color channel, vector.r/g/b */
static PyObject *Color_getChannel(ColorObject * self, void *type)
{
return Color_item(self, GET_INT_FROM_POINTER(type));
}
-static int Color_setChannel(ColorObject * self, PyObject * value, void * type)
+static int Color_setChannel(ColorObject * self, PyObject *value, void * type)
{
return Color_ass_item(self, GET_INT_FROM_POINTER(type), value);
}
@@ -368,7 +635,7 @@ static PyObject *Color_getChannelHSV(ColorObject * self, void *type)
return PyFloat_FromDouble(hsv[i]);
}
-static int Color_setChannelHSV(ColorObject * self, PyObject * value, void * type)
+static int Color_setChannelHSV(ColorObject * self, PyObject *value, void * type)
{
float hsv[3];
int i= GET_INT_FROM_POINTER(type);
@@ -411,7 +678,7 @@ static PyObject *Color_getHSV(ColorObject * self, void *UNUSED(closure))
return ret;
}
-static int Color_setHSV(ColorObject * self, PyObject * value, void *UNUSED(closure))
+static int Color_setHSV(ColorObject * self, PyObject *value, void *UNUSED(closure))
{
float hsv[3];
@@ -458,9 +725,9 @@ static struct PyMethodDef Color_methods[] = {
};
//------------------PY_OBECT DEFINITION--------------------------
-static char color_doc[] =
+PyDoc_STRVAR(color_doc,
"This object gives access to Colors in Blender."
-;
+);
PyTypeObject color_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"mathutils.Color", //tp_name
@@ -472,7 +739,7 @@ PyTypeObject color_Type = {
NULL, //tp_setattr
NULL, //tp_compare
(reprfunc) Color_repr, //tp_repr
- NULL, //tp_as_number
+ &Color_NumMethods, //tp_as_number
&Color_SeqMethods, //tp_as_sequence
&Color_AsMapping, //tp_as_mapping
NULL, //tp_hash
diff --git a/source/blender/python/generic/mathutils_Euler.c b/source/blender/python/generic/mathutils_Euler.c
index d8dd4e5fbb3..4281c7bf6c5 100644
--- a/source/blender/python/generic/mathutils_Euler.c
+++ b/source/blender/python/generic/mathutils_Euler.c
@@ -126,14 +126,14 @@ static PyObject *Euler_ToTupleExt(EulerObject *self, int ndigits)
//-----------------------------METHODS----------------------------
//return a quaternion representation of the euler
-static char Euler_to_quaternion_doc[] =
+PyDoc_STRVAR(Euler_to_quaternion_doc,
".. method:: to_quaternion()\n"
"\n"
" Return a quaternion representation of the euler.\n"
"\n"
" :return: Quaternion representation of the euler.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Euler_to_quaternion(EulerObject * self)
{
float quat[4];
@@ -147,14 +147,14 @@ static PyObject *Euler_to_quaternion(EulerObject * self)
}
//return a matrix representation of the euler
-static char Euler_to_matrix_doc[] =
+PyDoc_STRVAR(Euler_to_matrix_doc,
".. method:: to_matrix()\n"
"\n"
" Return a matrix representation of the euler.\n"
"\n"
" :return: A 3x3 roation matrix representation of the euler.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Euler_to_matrix(EulerObject * self)
{
float mat[9];
@@ -167,12 +167,11 @@ static PyObject *Euler_to_matrix(EulerObject * self)
return newMatrixObject(mat, 3, 3 , Py_NEW, NULL);
}
-//sets the euler to 0,0,0
-static char Euler_zero_doc[] =
+PyDoc_STRVAR(Euler_zero_doc,
".. method:: zero()\n"
"\n"
" Set all values to zero.\n"
-;
+);
static PyObject *Euler_zero(EulerObject * self)
{
zero_v3(self->eul);
@@ -183,16 +182,17 @@ static PyObject *Euler_zero(EulerObject * self)
Py_RETURN_NONE;
}
-static char Euler_rotate_axis_doc[] =
+PyDoc_STRVAR(Euler_rotate_axis_doc,
".. method:: rotate_axis(axis, angle)\n"
"\n"
-" Rotates the euler a certain amount and returning a unique euler rotation (no 720 degree pitches).\n"
+" Rotates the euler a certain amount and returning a unique euler rotation\n"
+" (no 720 degree pitches).\n"
"\n"
" :arg axis: single character in ['X, 'Y', 'Z'].\n"
" :type axis: string\n"
" :arg angle: angle in radians.\n"
" :type angle: float\n"
-;
+);
static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
{
float angle = 0.0f;
@@ -218,14 +218,14 @@ static PyObject *Euler_rotate_axis(EulerObject * self, PyObject *args)
Py_RETURN_NONE;
}
-static char Euler_rotate_doc[] =
+PyDoc_STRVAR(Euler_rotate_doc,
".. method:: rotate(other)\n"
"\n"
" Rotates the euler a by another mathutils value.\n"
"\n"
" :arg other: rotation component of mathutils value\n"
" :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
-;
+);
static PyObject *Euler_rotate(EulerObject * self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
@@ -245,13 +245,14 @@ static PyObject *Euler_rotate(EulerObject * self, PyObject *value)
Py_RETURN_NONE;
}
-static char Euler_make_compatible_doc[] =
+PyDoc_STRVAR(Euler_make_compatible_doc,
".. method:: make_compatible(other)\n"
"\n"
-" Make this euler compatible with another, so interpolating between them works as intended.\n"
+" Make this euler compatible with another,\n"
+" so interpolating between them works as intended.\n"
"\n"
" .. note:: the rotation order is not taken into account for this function.\n"
-;
+);
static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
{
float teul[EULER_SIZE];
@@ -272,7 +273,7 @@ static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)
//----------------------------Euler.rotate()-----------------------
// return a copy of the euler
-static char Euler_copy_doc[] =
+PyDoc_STRVAR(Euler_copy_doc,
".. function:: copy()\n"
"\n"
" Returns a copy of this euler.\n"
@@ -280,8 +281,9 @@ static char Euler_copy_doc[] =
" :return: A copy of the euler.\n"
" :rtype: :class:`Euler`\n"
"\n"
-" .. note:: use this to get a copy of a wrapped euler with no reference to the original data.\n"
-;
+" .. note:: use this to get a copy of a wrapped euler with\n"
+" no reference to the original data.\n"
+);
static PyObject *Euler_copy(EulerObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -417,7 +419,7 @@ static PyObject *Euler_slice(EulerObject * self, int begin, int end)
}
//----------------------------object[z:y]------------------------
//sequence slice (set)
-static int Euler_ass_slice(EulerObject * self, int begin, int end, PyObject * seq)
+static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
{
int i, size;
float eul[EULER_SIZE];
@@ -593,9 +595,9 @@ static struct PyMethodDef Euler_methods[] = {
};
//------------------PY_OBECT DEFINITION--------------------------
-static char euler_doc[] =
+PyDoc_STRVAR(euler_doc,
"This object gives access to Eulers in Blender."
-;
+);
PyTypeObject euler_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"mathutils.Euler", //tp_name
diff --git a/source/blender/python/generic/mathutils_Matrix.c b/source/blender/python/generic/mathutils_Matrix.c
index 2b9de49bf3f..4b7f9dc0d97 100644
--- a/source/blender/python/generic/mathutils_Matrix.c
+++ b/source/blender/python/generic/mathutils_Matrix.c
@@ -132,12 +132,12 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
const unsigned short row_size= PySequence_Size(arg); /* -1 is an error, size checks will accunt for this */
- if(IN_RANGE_INCL(row_size, 2, 4)) {
+ if(row_size >= 2 && row_size <= 4) {
PyObject *item= PySequence_GetItem(arg, 0);
const unsigned short col_size= PySequence_Size(item);
Py_XDECREF(item);
- if(IN_RANGE_INCL(col_size, 2, 4)) {
+ if(col_size >= 2 && col_size <= 4) {
/* sane row & col size, new matrix and assign as slice */
PyObject *matrix= newMatrixObject(NULL, row_size, col_size, Py_NEW, type);
if(Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
@@ -186,7 +186,7 @@ static void matrix_3x3_as_4x4(float mat[16])
/*-----------------------CLASS-METHODS----------------------------*/
//mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc.
-static char C_Matrix_Rotation_doc[] =
+PyDoc_STRVAR(C_Matrix_Rotation_doc,
".. classmethod:: Rotation(angle, size, axis)\n"
"\n"
" Create a matrix representing a rotation.\n"
@@ -195,11 +195,12 @@ static char C_Matrix_Rotation_doc[] =
" :type angle: float\n"
" :arg size: The size of the rotation matrix to construct [2, 4].\n"
" :type size: int\n"
-" :arg axis: a string in ['X', 'Y', 'Z'] or a 3D Vector Object (optional when size is 2).\n"
+" :arg axis: a string in ['X', 'Y', 'Z'] or a 3D Vector Object\n"
+" (optional when size is 2).\n"
" :type axis: string or :class:`Vector`\n"
" :return: A new rotation matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
{
PyObject *vec= NULL;
@@ -295,7 +296,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
}
-static char C_Matrix_Translation_doc[] =
+PyDoc_STRVAR(C_Matrix_Translation_doc,
".. classmethod:: Translation(vector)\n"
"\n"
" Create a matrix representing a translation.\n"
@@ -304,7 +305,7 @@ static char C_Matrix_Translation_doc[] =
" :type vector: :class:`Vector`\n"
" :return: An identity matrix with a translation.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value)
{
float mat[16], tvec[3];
@@ -319,7 +320,7 @@ static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value)
}
//----------------------------------mathutils.Matrix.Scale() -------------
//mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc.
-static char C_Matrix_Scale_doc[] =
+PyDoc_STRVAR(C_Matrix_Scale_doc,
".. classmethod:: Scale(factor, size, axis)\n"
"\n"
" Create a matrix representing a scaling.\n"
@@ -332,7 +333,7 @@ static char C_Matrix_Scale_doc[] =
" :type axis: :class:`Vector`\n"
" :return: A new scale matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
{
PyObject *vec= NULL;
@@ -402,18 +403,20 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
}
//----------------------------------mathutils.Matrix.OrthoProjection() ---
//mat is a 1D array of floats - row[0][0], row[0][1], row[1][0], etc.
-static char C_Matrix_OrthoProjection_doc[] =
+PyDoc_STRVAR(C_Matrix_OrthoProjection_doc,
".. classmethod:: OrthoProjection(axis, size)\n"
"\n"
" Create a matrix to represent an orthographic projection.\n"
"\n"
-" :arg axis: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'], where a single axis is for a 2D matrix. Or a vector for an arbitrary axis\n"
+" :arg axis: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'],\n"
+" where a single axis is for a 2D matrix.\n"
+" Or a vector for an arbitrary axis\n"
" :type axis: string or :class:`Vector`\n"
" :arg size: The size of the projection matrix to construct [2, 4].\n"
" :type size: int\n"
" :return: A new projection matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
{
PyObject *axis;
@@ -508,20 +511,22 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
return newMatrixObject(mat, matSize, matSize, Py_NEW, (PyTypeObject *)cls);
}
-static char C_Matrix_Shear_doc[] =
+PyDoc_STRVAR(C_Matrix_Shear_doc,
".. classmethod:: Shear(plane, size, factor)\n"
"\n"
" Create a matrix to represent an shear transformation.\n"
"\n"
-" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'], where a single axis is for a 2D matrix only.\n"
+" :arg plane: Can be any of the following: ['X', 'Y', 'XY', 'XZ', 'YZ'],\n"
+" where a single axis is for a 2D matrix only.\n"
" :type plane: string\n"
" :arg size: The size of the shear matrix to construct [2, 4].\n"
" :type size: int\n"
-" :arg factor: The factor of shear to apply. For a 3 or 4 *size* matrix pass a pair of floats corrasponding with the *plane* axis.\n"
+" :arg factor: The factor of shear to apply. For a 3 or 4 *size* matrix\n"
+" pass a pair of floats corrasponding with the *plane* axis.\n"
" :type factor: float or float pair\n"
" :return: A new shear matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
{
int matSize;
@@ -626,14 +631,14 @@ static float matrix_determinant_internal(MatrixObject *self)
/*-----------------------------METHODS----------------------------*/
-static char Matrix_to_quaternion_doc[] =
+PyDoc_STRVAR(Matrix_to_quaternion_doc,
".. method:: to_quaternion()\n"
"\n"
" Return a quaternion representation of the rotation matrix.\n"
"\n"
" :return: Quaternion representation of the rotation matrix.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Matrix_to_quaternion(MatrixObject *self)
{
float quat[4];
@@ -657,18 +662,22 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
}
/*---------------------------Matrix.toEuler() --------------------*/
-static char Matrix_to_euler_doc[] =
+PyDoc_STRVAR(Matrix_to_euler_doc,
".. method:: to_euler(order, euler_compat)\n"
"\n"
-" Return an Euler representation of the rotation matrix (3x3 or 4x4 matrix only).\n"
+" Return an Euler representation of the rotation matrix\n"
+" (3x3 or 4x4 matrix only).\n"
"\n"
-" :arg order: Optional rotation order argument in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n"
+" :arg order: Optional rotation order argument in\n"
+" ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n"
" :type order: string\n"
-" :arg euler_compat: Optional euler argument the new euler will be made compatible with (no axis flipping between them). Useful for converting a series of matrices to animation curves.\n"
+" :arg euler_compat: Optional euler argument the new euler will be made\n"
+" compatible with (no axis flipping between them).\n"
+" Useful for converting a series of matrices to animation curves.\n"
" :type euler_compat: :class:`Euler`\n"
" :return: Euler representation of the matrix.\n"
" :rtype: :class:`Euler`\n"
-;
+);
static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
{
const char *order_str= NULL;
@@ -724,11 +733,11 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
return newEulerObject(eul, order, Py_NEW, NULL);
}
-static char Matrix_resize_4x4_doc[] =
+PyDoc_STRVAR(Matrix_resize_4x4_doc,
".. method:: resize_4x4()\n"
"\n"
" Resize the matrix to 4x4.\n"
-;
+);
static PyObject *Matrix_resize_4x4(MatrixObject *self)
{
int x, first_row_elem, curr_pos, new_pos, blank_columns, blank_rows, index;
@@ -781,14 +790,14 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self)
Py_RETURN_NONE;
}
-static char Matrix_to_4x4_doc[] =
+PyDoc_STRVAR(Matrix_to_4x4_doc,
".. method:: to_4x4()\n"
"\n"
" Return a 4x4 copy of this matrix.\n"
"\n"
" :return: a new matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_to_4x4(MatrixObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -808,14 +817,14 @@ static PyObject *Matrix_to_4x4(MatrixObject *self)
return NULL;
}
-static char Matrix_to_3x3_doc[] =
+PyDoc_STRVAR(Matrix_to_3x3_doc,
".. method:: to_3x3()\n"
"\n"
" Return a 3x3 copy of this matrix.\n"
"\n"
" :return: a new matrix.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_to_3x3(MatrixObject *self)
{
float mat[3][3];
@@ -833,14 +842,14 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
return newMatrixObject((float *)mat, 3, 3, Py_NEW, Py_TYPE(self));
}
-static char Matrix_to_translation_doc[] =
+PyDoc_STRVAR(Matrix_to_translation_doc,
".. method:: to_translation()\n"
"\n"
" Return a the translation part of a 4 row matrix.\n"
"\n"
" :return: Return a the translation of a matrix.\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Matrix_to_translation(MatrixObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -854,7 +863,7 @@ static PyObject *Matrix_to_translation(MatrixObject *self)
return newVectorObject(self->matrix[3], 3, Py_NEW, NULL);
}
-static char Matrix_to_scale_doc[] =
+PyDoc_STRVAR(Matrix_to_scale_doc,
".. method:: to_scale()\n"
"\n"
" Return a the scale part of a 3x3 or 4x4 matrix.\n"
@@ -863,7 +872,7 @@ static char Matrix_to_scale_doc[] =
" :rtype: :class:`Vector`\n"
"\n"
" .. note:: This method does not return negative a scale on any axis because it is not possible to obtain this data from the matrix alone.\n"
-;
+);
static PyObject *Matrix_to_scale(MatrixObject *self)
{
float rot[3][3];
@@ -888,7 +897,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
}
/*---------------------------Matrix.invert() ---------------------*/
-static char Matrix_invert_doc[] =
+PyDoc_STRVAR(Matrix_invert_doc,
".. method:: invert()\n"
"\n"
" Set the matrix to its inverse.\n"
@@ -896,7 +905,7 @@ static char Matrix_invert_doc[] =
" .. note:: :exc:`ValueError` exception is raised.\n"
"\n"
" .. seealso:: <http://en.wikipedia.org/wiki/Inverse_matrix>\n"
-;
+);
static PyObject *Matrix_invert(MatrixObject *self)
{
@@ -950,7 +959,7 @@ static PyObject *Matrix_invert(MatrixObject *self)
Py_RETURN_NONE;
}
-static char Matrix_inverted_doc[] =
+PyDoc_STRVAR(Matrix_inverted_doc,
".. method:: inverted()\n"
"\n"
" Return an inverted copy of the matrix.\n"
@@ -959,13 +968,13 @@ static char Matrix_inverted_doc[] =
" :rtype: :class:`Matrix`\n"
"\n"
" .. note:: :exc:`ValueError` exception is raised.\n"
-;
+);
static PyObject *Matrix_inverted(MatrixObject *self)
{
return matrix__apply_to_copy((PyNoArgsFunction)Matrix_invert, self);
}
-static char Matrix_rotate_doc[] =
+PyDoc_STRVAR(Matrix_rotate_doc,
".. method:: rotate(other)\n"
"\n"
" Rotates the matrix a by another mathutils value.\n"
@@ -974,7 +983,7 @@ static char Matrix_rotate_doc[] =
" :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
"\n"
" .. note:: If any of the columns are not unit length this may not have desired results.\n"
-;
+);
static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
@@ -1000,14 +1009,14 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
}
/*---------------------------Matrix.decompose() ---------------------*/
-static char Matrix_decompose_doc[] =
+PyDoc_STRVAR(Matrix_decompose_doc,
".. method:: decompose()\n"
"\n"
" Return the location, rotaion and scale components of this matrix.\n"
"\n"
" :return: loc, rot, scale triple.\n"
" :rtype: (:class:`Vector`, :class:`Quaternion`, :class:`Vector`)"
-;
+);
static PyObject *Matrix_decompose(MatrixObject *self)
{
PyObject *ret;
@@ -1037,7 +1046,7 @@ static PyObject *Matrix_decompose(MatrixObject *self)
-static char Matrix_lerp_doc[] =
+PyDoc_STRVAR(Matrix_lerp_doc,
".. function:: lerp(other, factor)\n"
"\n"
" Returns the interpolation of two matricies.\n"
@@ -1048,7 +1057,7 @@ static char Matrix_lerp_doc[] =
" :type factor: float\n"
" :return: The interpolated rotation.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
{
MatrixObject *mat2 = NULL;
@@ -1081,7 +1090,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
}
/*---------------------------Matrix.determinant() ----------------*/
-static char Matrix_determinant_doc[] =
+PyDoc_STRVAR(Matrix_determinant_doc,
".. method:: determinant()\n"
"\n"
" Return the determinant of a matrix.\n"
@@ -1090,7 +1099,7 @@ static char Matrix_determinant_doc[] =
" :rtype: float\n"
"\n"
" .. seealso:: <http://en.wikipedia.org/wiki/Determinant>\n"
-;
+);
static PyObject *Matrix_determinant(MatrixObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -1104,13 +1113,13 @@ static PyObject *Matrix_determinant(MatrixObject *self)
return PyFloat_FromDouble((double)matrix_determinant_internal(self));
}
/*---------------------------Matrix.transpose() ------------------*/
-static char Matrix_transpose_doc[] =
+PyDoc_STRVAR(Matrix_transpose_doc,
".. method:: transpose()\n"
"\n"
" Set the matrix to its transpose.\n"
"\n"
" .. seealso:: <http://en.wikipedia.org/wiki/Transpose>\n"
-;
+);
static PyObject *Matrix_transpose(MatrixObject *self)
{
float t = 0.0f;
@@ -1137,28 +1146,28 @@ static PyObject *Matrix_transpose(MatrixObject *self)
Py_RETURN_NONE;
}
-static char Matrix_transposed_doc[] =
+PyDoc_STRVAR(Matrix_transposed_doc,
".. method:: transposed()\n"
"\n"
" Return a new, transposed matrix.\n"
"\n"
" :return: a transposed matrix\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_transposed(MatrixObject *self)
{
return matrix__apply_to_copy((PyNoArgsFunction)Matrix_transpose, self);
}
/*---------------------------Matrix.zero() -----------------------*/
-static char Matrix_zero_doc[] =
+PyDoc_STRVAR(Matrix_zero_doc,
".. method:: zero()\n"
"\n"
" Set all the matrix values to zero.\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_zero(MatrixObject *self)
{
fill_vn(self->contigPtr, self->row_size * self->col_size, 0.0f);
@@ -1169,15 +1178,16 @@ static PyObject *Matrix_zero(MatrixObject *self)
Py_RETURN_NONE;
}
/*---------------------------Matrix.identity(() ------------------*/
-static char Matrix_identity_doc[] =
+PyDoc_STRVAR(Matrix_identity_doc,
".. method:: identity()\n"
"\n"
" Set the matrix to the identity matrix.\n"
"\n"
-" .. note:: An object with zero location and rotation, a scale of one, will have an identity matrix.\n"
+" .. note:: An object with zero location and rotation, a scale of one,\n"
+" will have an identity matrix.\n"
"\n"
" .. seealso:: <http://en.wikipedia.org/wiki/Identity_matrix>\n"
-;
+);
static PyObject *Matrix_identity(MatrixObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -1206,14 +1216,14 @@ static PyObject *Matrix_identity(MatrixObject *self)
}
/*---------------------------Matrix.copy() ------------------*/
-static char Matrix_copy_doc[] =
+PyDoc_STRVAR(Matrix_copy_doc,
".. method:: copy()\n"
"\n"
" Returns a copy of this matrix.\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Matrix_copy(MatrixObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -1475,7 +1485,7 @@ static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar)
return newMatrixObject(tmat, mat->row_size, mat->col_size, Py_NEW, Py_TYPE(mat));
}
-static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
+static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
{
float scalar;
@@ -1780,9 +1790,9 @@ static struct PyMethodDef Matrix_methods[] = {
};
/*------------------PY_OBECT DEFINITION--------------------------*/
-static char matrix_doc[] =
+PyDoc_STRVAR(matrix_doc,
"This object gives access to Matrices in Blender."
-;
+);
PyTypeObject matrix_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"mathutils.Matrix", /*tp_name*/
diff --git a/source/blender/python/generic/mathutils_Quaternion.c b/source/blender/python/generic/mathutils_Quaternion.c
index 9c79ccb442f..90447e7093a 100644
--- a/source/blender/python/generic/mathutils_Quaternion.c
+++ b/source/blender/python/generic/mathutils_Quaternion.c
@@ -67,18 +67,21 @@ static PyObject *Quaternion_to_tuple_ext(QuaternionObject *self, int ndigits)
return ret;
}
-static char Quaternion_to_euler_doc[] =
+PyDoc_STRVAR(Quaternion_to_euler_doc,
".. method:: to_euler(order, euler_compat)\n"
"\n"
" Return Euler representation of the quaternion.\n"
"\n"
-" :arg order: Optional rotation order argument in ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n"
+" :arg order: Optional rotation order argument in\n"
+" ['XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'].\n"
" :type order: string\n"
-" :arg euler_compat: Optional euler argument the new euler will be made compatible with (no axis flipping between them). Useful for converting a series of matrices to animation curves.\n"
+" :arg euler_compat: Optional euler argument the new euler will be made\n"
+" compatible with (no axis flipping between them).\n"
+" Useful for converting a series of matrices to animation curves.\n"
" :type euler_compat: :class:`Euler`\n"
" :return: Euler representation of the quaternion.\n"
" :rtype: :class:`Euler`\n"
-;
+);
static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args)
{
float tquat[4];
@@ -121,14 +124,14 @@ static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args)
return newEulerObject(eul, order, Py_NEW, NULL);
}
//----------------------------Quaternion.toMatrix()------------------
-static char Quaternion_to_matrix_doc[] =
+PyDoc_STRVAR(Quaternion_to_matrix_doc,
".. method:: to_matrix()\n"
"\n"
" Return a matrix representation of the quaternion.\n"
"\n"
" :return: A 3x3 rotation matrix representation of the quaternion.\n"
" :rtype: :class:`Matrix`\n"
-;
+);
static PyObject *Quaternion_to_matrix(QuaternionObject *self)
{
float mat[9]; /* all values are set */
@@ -141,7 +144,7 @@ static PyObject *Quaternion_to_matrix(QuaternionObject *self)
}
//----------------------------Quaternion.cross(other)------------------
-static char Quaternion_cross_doc[] =
+PyDoc_STRVAR(Quaternion_cross_doc,
".. method:: cross(other)\n"
"\n"
" Return the cross product of this quaternion and another.\n"
@@ -150,7 +153,7 @@ static char Quaternion_cross_doc[] =
" :type other: :class:`Quaternion`\n"
" :return: The cross product.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value)
{
float quat[QUAT_SIZE], tquat[QUAT_SIZE];
@@ -166,7 +169,7 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value)
}
//----------------------------Quaternion.dot(other)------------------
-static char Quaternion_dot_doc[] =
+PyDoc_STRVAR(Quaternion_dot_doc,
".. method:: dot(other)\n"
"\n"
" Return the dot product of this quaternion and another.\n"
@@ -175,7 +178,7 @@ static char Quaternion_dot_doc[] =
" :type other: :class:`Quaternion`\n"
" :return: The dot product.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value)
{
float tquat[QUAT_SIZE];
@@ -189,7 +192,7 @@ static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value)
return PyFloat_FromDouble(dot_qtqt(self->quat, tquat));
}
-static char Quaternion_rotation_difference_doc[] =
+PyDoc_STRVAR(Quaternion_rotation_difference_doc,
".. function:: difference(other)\n"
"\n"
" Returns a quaternion representing the rotational difference.\n"
@@ -198,7 +201,7 @@ static char Quaternion_rotation_difference_doc[] =
" :type other: :class:`Quaternion`\n"
" :return: the rotational difference between the two quat rotations.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject *value)
{
float tquat[QUAT_SIZE], quat[QUAT_SIZE];
@@ -214,7 +217,7 @@ static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject
return newQuaternionObject(quat, Py_NEW, Py_TYPE(self));
}
-static char Quaternion_slerp_doc[] =
+PyDoc_STRVAR(Quaternion_slerp_doc,
".. function:: slerp(other, factor)\n"
"\n"
" Returns the interpolation of two quaternions.\n"
@@ -225,7 +228,7 @@ static char Quaternion_slerp_doc[] =
" :type factor: float\n"
" :return: The interpolated rotation.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args)
{
PyObject *value;
@@ -252,14 +255,14 @@ static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args)
return newQuaternionObject(quat, Py_NEW, Py_TYPE(self));
}
-static char Quaternion_rotate_doc[] =
+PyDoc_STRVAR(Quaternion_rotate_doc,
".. method:: rotate(other)\n"
"\n"
" Rotates the quaternion a by another mathutils value.\n"
"\n"
" :arg other: rotation component of mathutils value\n"
" :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
-;
+);
static PyObject *Quaternion_rotate(QuaternionObject *self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
@@ -284,11 +287,11 @@ static PyObject *Quaternion_rotate(QuaternionObject *self, PyObject *value)
//----------------------------Quaternion.normalize()----------------
//normalize the axis of rotation of [theta, vector]
-static char Quaternion_normalize_doc[] =
+PyDoc_STRVAR(Quaternion_normalize_doc,
".. function:: normalize()\n"
"\n"
" Normalize the quaternion.\n"
-;
+);
static PyObject *Quaternion_normalize(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -299,25 +302,25 @@ static PyObject *Quaternion_normalize(QuaternionObject *self)
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
}
-static char Quaternion_normalized_doc[] =
+PyDoc_STRVAR(Quaternion_normalized_doc,
".. function:: normalized()\n"
"\n"
" Return a new normalized quaternion.\n"
"\n"
" :return: a normalized copy.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_normalized(QuaternionObject *self)
{
return quat__apply_to_copy((PyNoArgsFunction)Quaternion_normalize, self);
}
//----------------------------Quaternion.invert()------------------
-static char Quaternion_invert_doc[] =
+PyDoc_STRVAR(Quaternion_invert_doc,
".. function:: invert()\n"
"\n"
" Set the quaternion to its inverse.\n"
-;
+);
static PyObject *Quaternion_invert(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -328,28 +331,28 @@ static PyObject *Quaternion_invert(QuaternionObject *self)
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
}
-static char Quaternion_inverted_doc[] =
+PyDoc_STRVAR(Quaternion_inverted_doc,
".. function:: inverted()\n"
"\n"
" Return a new, inverted quaternion.\n"
"\n"
" :return: the inverted value.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_inverted(QuaternionObject *self)
{
return quat__apply_to_copy((PyNoArgsFunction)Quaternion_invert, self);
}
//----------------------------Quaternion.identity()-----------------
-static char Quaternion_identity_doc[] =
+PyDoc_STRVAR(Quaternion_identity_doc,
".. function:: identity()\n"
"\n"
" Set the quaternion to an identity quaternion.\n"
"\n"
" :return: an instance of itself.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_identity(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -361,14 +364,14 @@ static PyObject *Quaternion_identity(QuaternionObject *self)
Py_RETURN_NONE;
}
//----------------------------Quaternion.negate()-------------------
-static char Quaternion_negate_doc[] =
+PyDoc_STRVAR(Quaternion_negate_doc,
".. function:: negate()\n"
"\n"
" Set the quaternion to its negative.\n"
"\n"
" :return: an instance of itself.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_negate(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -380,11 +383,11 @@ static PyObject *Quaternion_negate(QuaternionObject *self)
Py_RETURN_NONE;
}
//----------------------------Quaternion.conjugate()----------------
-static char Quaternion_conjugate_doc[] =
+PyDoc_STRVAR(Quaternion_conjugate_doc,
".. function:: conjugate()\n"
"\n"
" Set the quaternion to its conjugate (negate x, y, z).\n"
-;
+);
static PyObject *Quaternion_conjugate(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -395,21 +398,21 @@ static PyObject *Quaternion_conjugate(QuaternionObject *self)
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
}
-static char Quaternion_conjugated_doc[] =
+PyDoc_STRVAR(Quaternion_conjugated_doc,
".. function:: conjugated()\n"
"\n"
" Return a new conjugated quaternion.\n"
"\n"
" :return: a new quaternion.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Quaternion_conjugated(QuaternionObject *self)
{
return quat__apply_to_copy((PyNoArgsFunction)Quaternion_conjugate, self);
}
//----------------------------Quaternion.copy()----------------
-static char Quaternion_copy_doc[] =
+PyDoc_STRVAR(Quaternion_copy_doc,
".. function:: copy()\n"
"\n"
" Returns a copy of this quaternion.\n"
@@ -417,8 +420,9 @@ static char Quaternion_copy_doc[] =
" :return: A copy of the quaternion.\n"
" :rtype: :class:`Quaternion`\n"
"\n"
-" .. note:: use this to get a copy of a wrapped quaternion with no reference to the original data.\n"
-;
+" .. note:: use this to get a copy of a wrapped quaternion with\n"
+" no reference to the original data.\n"
+);
static PyObject *Quaternion_copy(QuaternionObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -1026,9 +1030,9 @@ static PyGetSetDef Quaternion_getseters[] = {
};
//------------------PY_OBECT DEFINITION--------------------------
-static char quaternion_doc[] =
+PyDoc_STRVAR(quaternion_doc,
"This object gives access to Quaternions in Blender."
-;
+);
PyTypeObject quaternion_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"mathutils.Quaternion", //tp_name
diff --git a/source/blender/python/generic/mathutils_Vector.c b/source/blender/python/generic/mathutils_Vector.c
index 8e0c53be308..d0ba94474d4 100644
--- a/source/blender/python/generic/mathutils_Vector.c
+++ b/source/blender/python/generic/mathutils_Vector.c
@@ -87,11 +87,11 @@ static PyObject *vec__apply_to_copy(PyNoArgsFunction vec_func, VectorObject *sel
}
/*-----------------------------METHODS---------------------------- */
-static char Vector_zero_doc[] =
+PyDoc_STRVAR(Vector_zero_doc,
".. method:: zero()\n"
"\n"
" Set all values to zero.\n"
-;
+);
static PyObject *Vector_zero(VectorObject *self)
{
fill_vn(self->vec, self->size, 0.0f);
@@ -102,15 +102,17 @@ static PyObject *Vector_zero(VectorObject *self)
Py_RETURN_NONE;
}
-static char Vector_normalize_doc[] =
+PyDoc_STRVAR(Vector_normalize_doc,
".. method:: normalize()\n"
"\n"
" Normalize the vector, making the length of the vector always 1.0.\n"
"\n"
-" .. warning:: Normalizing a vector where all values are zero results in all axis having a nan value (not a number).\n"
+" .. warning:: Normalizing a vector where all values are zero results\n"
+" in all axis having a nan value (not a number).\n"
"\n"
-" .. note:: Normalize works for vectors of all sizes, however 4D Vectors w axis is left untouched.\n"
-;
+" .. note:: Normalize works for vectors of all sizes,\n"
+" however 4D Vectors w axis is left untouched.\n"
+);
static PyObject *Vector_normalize(VectorObject *self)
{
int i;
@@ -130,27 +132,27 @@ static PyObject *Vector_normalize(VectorObject *self)
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
}
-static char Vector_normalized_doc[] =
+PyDoc_STRVAR(Vector_normalized_doc,
".. method:: normalized()\n"
"\n"
" Return a new, normalized vector.\n"
"\n"
" :return: a normalized copy of the vector\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_normalized(VectorObject *self)
{
return vec__apply_to_copy((PyNoArgsFunction)Vector_normalize, self);
}
-static char Vector_resize_2d_doc[] =
+PyDoc_STRVAR(Vector_resize_2d_doc,
".. method:: resize_2d()\n"
"\n"
" Resize the vector to 2D (x, y).\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_resize_2d(VectorObject *self)
{
if(self->wrapped==Py_WRAP) {
@@ -172,14 +174,14 @@ static PyObject *Vector_resize_2d(VectorObject *self)
Py_RETURN_NONE;
}
-static char Vector_resize_3d_doc[] =
+PyDoc_STRVAR(Vector_resize_3d_doc,
".. method:: resize_3d()\n"
"\n"
" Resize the vector to 3D (x, y, z).\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_resize_3d(VectorObject *self)
{
if (self->wrapped==Py_WRAP) {
@@ -204,14 +206,14 @@ static PyObject *Vector_resize_3d(VectorObject *self)
Py_RETURN_NONE;
}
-static char Vector_resize_4d_doc[] =
+PyDoc_STRVAR(Vector_resize_4d_doc,
".. method:: resize_4d()\n"
"\n"
" Resize the vector to 4D (x, y, z, w).\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_resize_4d(VectorObject *self)
{
if(self->wrapped==Py_WRAP) {
@@ -239,14 +241,14 @@ static PyObject *Vector_resize_4d(VectorObject *self)
self->size = 4;
Py_RETURN_NONE;
}
-static char Vector_to_2d_doc[] =
+PyDoc_STRVAR(Vector_to_2d_doc,
".. method:: to_2d()\n"
"\n"
" Return a 2d copy of the vector.\n"
"\n"
" :return: a new vector\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_to_2d(VectorObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -254,14 +256,14 @@ static PyObject *Vector_to_2d(VectorObject *self)
return newVectorObject(self->vec, 2, Py_NEW, Py_TYPE(self));
}
-static char Vector_to_3d_doc[] =
+PyDoc_STRVAR(Vector_to_3d_doc,
".. method:: to_3d()\n"
"\n"
" Return a 3d copy of the vector.\n"
"\n"
" :return: a new vector\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_to_3d(VectorObject *self)
{
float tvec[3]= {0.0f};
@@ -272,14 +274,14 @@ static PyObject *Vector_to_3d(VectorObject *self)
memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 3));
return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(self));
}
-static char Vector_to_4d_doc[] =
+PyDoc_STRVAR(Vector_to_4d_doc,
".. method:: to_4d()\n"
"\n"
" Return a 4d copy of the vector.\n"
"\n"
" :return: a new vector\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_to_4d(VectorObject *self)
{
float tvec[4]= {0.0f, 0.0f, 0.0f, 1.0f};
@@ -291,7 +293,7 @@ static PyObject *Vector_to_4d(VectorObject *self)
return newVectorObject(tvec, 4, Py_NEW, Py_TYPE(self));
}
-static char Vector_to_tuple_doc[] =
+PyDoc_STRVAR(Vector_to_tuple_doc,
".. method:: to_tuple(precision=-1)\n"
"\n"
" Return this vector as a tuple with.\n"
@@ -300,7 +302,7 @@ static char Vector_to_tuple_doc[] =
" :type precision: int\n"
" :return: the values of the vector rounded by *precision*\n"
" :rtype: tuple\n"
-;
+);
/* note: BaseMath_ReadCallback must be called beforehand */
static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits)
{
@@ -344,7 +346,7 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args)
return Vector_to_tuple_ext(self, ndigits);
}
-static char Vector_to_track_quat_doc[] =
+PyDoc_STRVAR(Vector_to_track_quat_doc,
".. method:: to_track_quat(track, up)\n"
"\n"
" Return a quaternion rotation from the vector and the track and up axis.\n"
@@ -355,7 +357,7 @@ static char Vector_to_track_quat_doc[] =
" :type up: string\n"
" :return: rotation from the vector and the track and up axis.\n"
" :rtype: :class:`Quaternion`\n"
-;
+);
static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
{
float vec[3], quat[4];
@@ -462,7 +464,7 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
* Vector.reflect(mirror): return a reflected vector on the mirror normal
* vec - ((2 * DotVecs(vec, mirror)) * mirror)
*/
-static char Vector_reflect_doc[] =
+PyDoc_STRVAR(Vector_reflect_doc,
".. method:: reflect(mirror)\n"
"\n"
" Return the reflection vector from the *mirror* argument.\n"
@@ -471,7 +473,7 @@ static char Vector_reflect_doc[] =
" :type mirror: :class:`Vector`\n"
" :return: The reflected vector matching the size of this vector.\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_reflect(VectorObject *self, PyObject *value)
{
int value_size;
@@ -501,7 +503,7 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value)
return newVectorObject(reflect, self->size, Py_NEW, Py_TYPE(self));
}
-static char Vector_cross_doc[] =
+PyDoc_STRVAR(Vector_cross_doc,
".. method:: cross(other)\n"
"\n"
" Return the cross product of this vector and another.\n"
@@ -512,7 +514,7 @@ static char Vector_cross_doc[] =
" :rtype: :class:`Vector`\n"
"\n"
" .. note:: both vectors must be 3D\n"
-;
+);
static PyObject *Vector_cross(VectorObject *self, PyObject *value)
{
VectorObject *ret;
@@ -529,7 +531,7 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value)
return (PyObject *)ret;
}
-static char Vector_dot_doc[] =
+PyDoc_STRVAR(Vector_dot_doc,
".. method:: dot(other)\n"
"\n"
" Return the dot product of this vector and another.\n"
@@ -538,7 +540,7 @@ static char Vector_dot_doc[] =
" :type other: :class:`Vector`\n"
" :return: The dot product.\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_dot(VectorObject *self, PyObject *value)
{
float tvec[MAX_DIMENSIONS];
@@ -558,20 +560,21 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value)
return PyFloat_FromDouble(dot);
}
-static char Vector_angle_doc[] =
+PyDoc_STRVAR(Vector_angle_doc,
".. function:: angle(other, fallback)\n"
"\n"
" Return the angle between two vectors.\n"
"\n"
" :arg other: another vector to compare the angle with\n"
" :type other: :class:`Vector`\n"
-" :arg fallback: return this value when the angle cant be calculated (zero length vector)\n"
+" :arg fallback: return this value when the angle cant be calculated\n"
+" (zero length vector)\n"
" :type fallback: any\n"
" :return: angle in radians or fallback when given\n"
" :rtype: float\n"
"\n"
" .. note:: Zero length vectors raise an :exc:`AttributeError`.\n"
-;
+);
static PyObject *Vector_angle(VectorObject *self, PyObject *args)
{
const int size= self->size;
@@ -615,10 +618,11 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
return PyFloat_FromDouble(saacos(dot));
}
-static char Vector_rotation_difference_doc[] =
+PyDoc_STRVAR(Vector_rotation_difference_doc,
".. function:: difference(other)\n"
"\n"
-" Returns a quaternion representing the rotational difference between this vector and another.\n"
+" Returns a quaternion representing the rotational difference between this\n"
+" vector and another.\n"
"\n"
" :arg other: second vector.\n"
" :type other: :class:`Vector`\n"
@@ -626,7 +630,7 @@ static char Vector_rotation_difference_doc[] =
" :rtype: :class:`Quaternion`\n"
"\n"
" .. note:: 2D vectors raise an :exc:`AttributeError`.\n"
-;
+);
static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value)
{
float quat[4], vec_a[3], vec_b[3];
@@ -650,7 +654,7 @@ static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value)
return newQuaternionObject(quat, Py_NEW, NULL);
}
-static char Vector_project_doc[] =
+PyDoc_STRVAR(Vector_project_doc,
".. function:: project(other)\n"
"\n"
" Return the projection of this vector onto the *other*.\n"
@@ -659,7 +663,7 @@ static char Vector_project_doc[] =
" :type other: :class:`Vector`\n"
" :return: the parallel projection vector\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_project(VectorObject *self, PyObject *value)
{
const int size= self->size;
@@ -690,7 +694,7 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value)
return newVectorObject(vec, size, Py_NEW, Py_TYPE(self));
}
-static char Vector_lerp_doc[] =
+PyDoc_STRVAR(Vector_lerp_doc,
".. function:: lerp(other, factor)\n"
"\n"
" Returns the interpolation of two vectors.\n"
@@ -701,7 +705,7 @@ static char Vector_lerp_doc[] =
" :type factor: float\n"
" :return: The interpolated rotation.\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
{
const int size= self->size;
@@ -727,14 +731,14 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
return newVectorObject(vec, size, Py_NEW, Py_TYPE(self));
}
-static char Vector_rotate_doc[] =
+PyDoc_STRVAR(Vector_rotate_doc,
".. function:: rotate(other)\n"
"\n"
" Return vector by a rotation value.\n"
"\n"
" :arg other: rotation component of mathutils value\n"
" :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"
-;
+);
static PyObject *Vector_rotate(VectorObject *self, PyObject *value)
{
float other_rmat[3][3];
@@ -756,7 +760,7 @@ static PyObject *Vector_rotate(VectorObject *self, PyObject *value)
Py_RETURN_NONE;
}
-static char Vector_copy_doc[] =
+PyDoc_STRVAR(Vector_copy_doc,
".. function:: copy()\n"
"\n"
" Returns a copy of this vector.\n"
@@ -764,8 +768,9 @@ static char Vector_copy_doc[] =
" :return: A copy of the vector.\n"
" :rtype: :class:`Vector`\n"
"\n"
-" .. note:: use this to get a copy of a wrapped vector with no reference to the original data.\n"
-;
+" .. note:: use this to get a copy of a wrapped vector with\n"
+" no reference to the original data.\n"
+);
static PyObject *Vector_copy(VectorObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -864,8 +869,7 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
return tuple;
}
/* sequence slice (set): vector[a:b] = value */
-static int Vector_ass_slice(VectorObject *self, int begin, int end,
- PyObject * seq)
+static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq)
{
int y, size = 0;
float vec[MAX_DIMENSIONS];
@@ -894,7 +898,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end,
/* Numeric Protocols */
/* addition: obj + obj */
-static PyObject *Vector_add(PyObject * v1, PyObject * v2)
+static PyObject *Vector_add(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float vec[MAX_DIMENSIONS];
@@ -921,7 +925,7 @@ static PyObject *Vector_add(PyObject * v1, PyObject * v2)
}
/* addition in-place: obj += obj */
-static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
+static PyObject *Vector_iadd(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
@@ -948,7 +952,7 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
}
/* subtraction: obj - obj */
-static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
+static PyObject *Vector_sub(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float vec[MAX_DIMENSIONS];
@@ -974,7 +978,7 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
}
/* subtraction in-place: obj -= obj */
-static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
+static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
{
VectorObject *vec1= NULL, *vec2= NULL;
@@ -1050,7 +1054,7 @@ static PyObject *vector_mul_float(VectorObject *vec, const float scalar)
return newVectorObject(tvec, vec->size, Py_NEW, Py_TYPE(vec));
}
-static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
+static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float scalar;
@@ -1111,12 +1115,12 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
mul_qt_v3(quat2->quat, tvec);
return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec1));
}
- else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC*FLOAT */
+ else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC * FLOAT */
return vector_mul_float(vec1, scalar);
}
}
else if (vec2) {
- if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* VEC*FLOAT */
+ if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* FLOAT * VEC */
return vector_mul_float(vec2, scalar);
}
}
@@ -1129,7 +1133,7 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
}
/* mulplication in-place: obj *= obj */
-static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
+static PyObject *Vector_imul(PyObject *v1, PyObject *v2)
{
VectorObject *vec = (VectorObject *)v1;
float scalar;
@@ -1163,7 +1167,7 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
}
mul_qt_v3(quat2->quat, vec->vec);
}
- else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC*=FLOAT */
+ else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC *= FLOAT */
mul_vn_fl(vec->vec, vec->size, scalar);
}
else {
@@ -1177,7 +1181,7 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
}
/* divid: obj / obj */
-static PyObject *Vector_div(PyObject * v1, PyObject * v2)
+static PyObject *Vector_div(PyObject *v1, PyObject *v2)
{
int i;
float vec[4], scalar;
@@ -1209,7 +1213,7 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
}
/* divide in-place: obj /= obj */
-static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
+static PyObject *Vector_idiv(PyObject *v1, PyObject *v2)
{
int i;
float scalar;
@@ -1484,7 +1488,7 @@ static PyObject *Vector_getAxis(VectorObject *self, void *type)
return vector_item_internal(self, GET_INT_FROM_POINTER(type), TRUE);
}
-static int Vector_setAxis(VectorObject *self, PyObject * value, void *type)
+static int Vector_setAxis(VectorObject *self, PyObject *value, void *type)
{
return vector_ass_item_internal(self, GET_INT_FROM_POINTER(type), value, TRUE);
}
@@ -1591,7 +1595,7 @@ static PyObject *Vector_getSwizzle(VectorObject *self, void *closure)
Returns 0 on success and -1 on failure. On failure, the vector will be
unchanged. */
-static int Vector_setSwizzle(VectorObject *self, PyObject * value, void *closure)
+static int Vector_setSwizzle(VectorObject *self, PyObject *value, void *closure)
{
size_t size_from;
float scalarVal;
@@ -2094,14 +2098,14 @@ static int row_vector_multiplication(float rvec[4], VectorObject* vec, MatrixObj
#endif
/*----------------------------Vector.negate() -------------------- */
-static char Vector_negate_doc[] =
+PyDoc_STRVAR(Vector_negate_doc,
".. method:: negate()\n"
"\n"
" Set all values to their negative.\n"
"\n"
" :return: an instance of itself\n"
" :rtype: :class:`Vector`\n"
-;
+);
static PyObject *Vector_negate(VectorObject *self)
{
if(BaseMath_ReadCallback(self) == -1)
@@ -2153,9 +2157,9 @@ static struct PyMethodDef Vector_methods[] = {
vec*mat and mat*vec both get sent to Vector_mul and it neesd to sort out the order
*/
-static char vector_doc[] =
+PyDoc_STRVAR(vector_doc,
"This object gives access to Vectors in Blender."
-;
+);
PyTypeObject vector_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
/* For printing, in format "<module>.<name>" */
diff --git a/source/blender/python/generic/mathutils_geometry.c b/source/blender/python/generic/mathutils_geometry.c
index 6031c716807..53c066d1a85 100644
--- a/source/blender/python/generic/mathutils_geometry.c
+++ b/source/blender/python/generic/mathutils_geometry.c
@@ -53,11 +53,13 @@
/*-------------------------DOC STRINGS ---------------------------*/
-static char M_Geometry_doc[]= "The Blender geometry module\n\n";
+PyDoc_STRVAR(M_Geometry_doc,
+"The Blender geometry module"
+);
//---------------------------------INTERSECTION FUNCTIONS--------------------
-static char M_Geometry_intersect_ray_tri_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_ray_tri_doc,
".. function:: intersect_ray_tri(v1, v2, v3, ray, orig, clip=True)\n"
"\n"
" Returns the intersection between a ray and a triangle, if possible, returns None otherwise.\n"
@@ -76,7 +78,7 @@ static char M_Geometry_intersect_ray_tri_doc[] =
" :type clip: boolean\n"
" :return: The point of intersection or None if no intersection is found\n"
" :rtype: :class:`mathutils.Vector` or None\n"
-;
+);
static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *ray, *ray_off, *vec1, *vec2, *vec3;
@@ -150,7 +152,7 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject*
/* Line-Line intersection using algorithm from mathworld.wolfram.com */
-static char M_Geometry_intersect_line_line_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_line_line_doc,
".. function:: intersect_line_line(v1, v2, v3, v4)\n"
"\n"
" Returns a tuple with the points on each line respectively closest to the other.\n"
@@ -164,10 +166,10 @@ static char M_Geometry_intersect_line_line_doc[] =
" :arg v4: Second point of the second line\n"
" :type v4: :class:`mathutils.Vector`\n"
" :rtype: tuple of :class:`mathutils.Vector`'s\n"
-;
+);
static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject *args)
{
- PyObject * tuple;
+ PyObject *tuple;
VectorObject *vec1, *vec2, *vec3, *vec4;
float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3];
@@ -232,7 +234,7 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
//----------------------------geometry.normal() -------------------
-static char M_Geometry_normal_doc[] =
+PyDoc_STRVAR(M_Geometry_normal_doc,
".. function:: normal(v1, v2, v3, v4=None)\n"
"\n"
" Returns the normal of the 3D tri or quad.\n"
@@ -246,7 +248,7 @@ static char M_Geometry_normal_doc[] =
" :arg v4: Point4 (optional)\n"
" :type v4: :class:`mathutils.Vector`\n"
" :rtype: :class:`mathutils.Vector`\n"
-;
+);
static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *vec1, *vec2, *vec3, *vec4;
@@ -294,7 +296,7 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args)
//--------------------------------- AREA FUNCTIONS--------------------
-static char M_Geometry_area_tri_doc[] =
+PyDoc_STRVAR(M_Geometry_area_tri_doc,
".. function:: area_tri(v1, v2, v3)\n"
"\n"
" Returns the area size of the 2D or 3D triangle defined.\n"
@@ -306,7 +308,7 @@ static char M_Geometry_area_tri_doc[] =
" :arg v3: Point3\n"
" :type v3: :class:`mathutils.Vector`\n"
" :rtype: float\n"
-;
+);
static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *vec1, *vec2, *vec3;
@@ -336,14 +338,14 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args)
}
/*----------------------------------geometry.PolyFill() -------------------*/
-static char M_Geometry_tesselate_polygon_doc[] =
+PyDoc_STRVAR(M_Geometry_tesselate_polygon_doc,
".. function:: tesselate_polygon(veclist_list)\n"
"\n"
" Takes a list of polylines (each point a vector) and returns the point indices for a polyline filled with triangles.\n"
"\n"
" :arg veclist_list: list of polylines\n"
" :rtype: list\n"
-;
+);
/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */
static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *polyLineSeq)
{
@@ -456,7 +458,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
return tri_list;
}
-static char M_Geometry_intersect_line_line_2d_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_line_line_2d_doc,
".. function:: intersect_line_line_2d(lineA_p1, lineA_p2, lineB_p1, lineB_p2)\n"
"\n"
" Takes 2 lines (as 4 vectors) and returns a vector for their point of intersection or None.\n"
@@ -471,7 +473,7 @@ static char M_Geometry_intersect_line_line_2d_doc[] =
" :type lineB_p2: :class:`mathutils.Vector`\n"
" :return: The point of intersection or None when not found\n"
" :rtype: :class:`mathutils.Vector` or None\n"
-;
+);
static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *line_a1, *line_a2, *line_b1, *line_b2;
@@ -497,7 +499,61 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj
}
-static char M_Geometry_intersect_point_line_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_line_plane_doc,
+".. function:: intersect_line_plane(line_a, line_b, plane_co, plane_no, no_flip=False)\n"
+"\n"
+" Takes 2 lines (as 4 vectors) and returns a vector for their point of intersection or None.\n"
+"\n"
+" :arg line_a: First point of the first line\n"
+" :type line_a: :class:`mathutils.Vector`\n"
+" :arg line_b: Second point of the first line\n"
+" :type line_b: :class:`mathutils.Vector`\n"
+" :arg plane_co: A point on the plane\n"
+" :type plane_co: :class:`mathutils.Vector`\n"
+" :arg plane_no: The direction the plane is facing\n"
+" :type plane_no: :class:`mathutils.Vector`\n"
+" :arg no_flip: Always return an intersection on the directon defined bt line_a -> line_b\n"
+" :type no_flip: :boolean\n"
+" :return: The point of intersection or None when not found\n"
+" :rtype: :class:`mathutils.Vector` or None\n"
+);
+static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObject* args)
+{
+ VectorObject *line_a, *line_b, *plane_co, *plane_no;
+ int no_flip= 0;
+ float isect[3];
+ if(!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_line_2d",
+ &vector_Type, &line_a,
+ &vector_Type, &line_b,
+ &vector_Type, &plane_co,
+ &vector_Type, &plane_no,
+ &no_flip)
+ ) {
+ return NULL;
+ }
+
+ if( BaseMath_ReadCallback(line_a) == -1 ||
+ BaseMath_ReadCallback(line_b) == -1 ||
+ BaseMath_ReadCallback(plane_co) == -1 ||
+ BaseMath_ReadCallback(plane_no) == -1
+ ) {
+ return NULL;
+ }
+
+ if(ELEM4(2, line_a->size, line_b->size, plane_co->size, plane_no->size)) {
+ PyErr_SetString(PyExc_RuntimeError, "geometry.intersect_line_plane(...) can't use 2D Vectors");
+ return NULL;
+ }
+
+ if(isect_line_plane_v3(isect, line_a->vec, line_b->vec, plane_co->vec, plane_no->vec, no_flip) == 1) {
+ return newVectorObject(isect, 3, Py_NEW, NULL);
+ }
+ else {
+ Py_RETURN_NONE;
+ }
+}
+
+PyDoc_STRVAR(M_Geometry_intersect_point_line_doc,
".. function:: intersect_point_line(pt, line_p1, line_p2)\n"
"\n"
" Takes a point and a line and returns a tuple with the closest point on the line and its distance from the first point of the line as a percentage of the length of the line.\n"
@@ -509,7 +565,7 @@ static char M_Geometry_intersect_point_line_doc[] =
" :arg line_p1: Second point of the line\n"
" :type line_p1: :class:`mathutils.Vector`\n"
" :rtype: (:class:`mathutils.Vector`, float)\n"
-;
+);
static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *pt, *line_1, *line_2;
@@ -547,7 +603,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
return ret;
}
-static char M_Geometry_intersect_point_tri_2d_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_point_tri_2d_doc,
".. function:: intersect_point_tri_2d(pt, tri_p1, tri_p2, tri_p3)\n"
"\n"
" Takes 4 vectors (using only the x and y coordinates): one is the point and the next 3 define the triangle. Returns 1 if the point is within the triangle, otherwise 0.\n"
@@ -561,7 +617,7 @@ static char M_Geometry_intersect_point_tri_2d_doc[] =
" :arg tri_p3: Third point of the triangle\n"
" :type tri_p3: :class:`mathutils.Vector`\n"
" :rtype: int\n"
-;
+);
static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3;
@@ -581,7 +637,7 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj
return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec));
}
-static char M_Geometry_intersect_point_quad_2d_doc[] =
+PyDoc_STRVAR(M_Geometry_intersect_point_quad_2d_doc,
".. function:: intersect_point_quad_2d(pt, quad_p1, quad_p2, quad_p3, quad_p4)\n"
"\n"
" Takes 5 vectors (using only the x and y coordinates): one is the point and the next 4 define the quad, only the x and y are used from the vectors. Returns 1 if the point is within the quad, otherwise 0.\n"
@@ -597,7 +653,7 @@ static char M_Geometry_intersect_point_quad_2d_doc[] =
" :arg quad_p4: Forth point of the quad\n"
" :type quad_p4: :class:`mathutils.Vector`\n"
" :rtype: int\n"
-;
+);
static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *pt_vec, *quad_p1, *quad_p2, *quad_p3, *quad_p4;
@@ -664,7 +720,7 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
return 0;
}
-static void boxPack_ToPyObject(PyObject * value, boxPack **boxarray)
+static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray)
{
int len, i;
PyObject *list_item;
@@ -681,7 +737,7 @@ static void boxPack_ToPyObject(PyObject * value, boxPack **boxarray)
MEM_freeN(*boxarray);
}
-static char M_Geometry_box_pack_2d_doc[] =
+PyDoc_STRVAR(M_Geometry_box_pack_2d_doc,
".. function:: box_pack_2d(boxes)\n"
"\n"
" Returns the normal of the 3D tri or quad.\n"
@@ -690,7 +746,7 @@ static char M_Geometry_box_pack_2d_doc[] =
" :type boxes: list\n"
" :return: the width and height of the packed bounding box\n"
" :rtype: tuple, pair of floats\n"
-;
+);
static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist)
{
float tot_width= 0.0f, tot_height= 0.0f;
@@ -722,7 +778,7 @@ static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlis
return ret;
}
-static char M_Geometry_interpolate_bezier_doc[] =
+PyDoc_STRVAR(M_Geometry_interpolate_bezier_doc,
".. function:: interpolate_bezier(knot1, handle1, handle2, knot2, resolution)\n"
"\n"
" Interpolate a bezier spline segment.\n"
@@ -739,7 +795,7 @@ static char M_Geometry_interpolate_bezier_doc[] =
" :type resolution: int\n"
" :return: The interpolated points\n"
" :rtype: list of :class:`mathutils.Vector`'s\n"
-;
+);
static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject* args)
{
VectorObject *vec_k1, *vec_h1, *vec_k2, *vec_h2;
@@ -793,7 +849,7 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject*
return list;
}
-static char M_Geometry_barycentric_transform_doc[] =
+PyDoc_STRVAR(M_Geometry_barycentric_transform_doc,
".. function:: barycentric_transform(point, tri_a1, tri_a2, tri_a3, tri_b1, tri_b2, tri_b3)\n"
"\n"
" Return a transformed point, the transformation is defined by 2 triangles.\n"
@@ -814,7 +870,7 @@ static char M_Geometry_barycentric_transform_doc[] =
" :type tri_a3: :class:`mathutils.Vector`\n"
" :return: The transformed point\n"
" :rtype: :class:`mathutils.Vector`'s\n"
-;
+);
static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObject *args)
{
VectorObject *vec_pt;
@@ -860,6 +916,7 @@ static PyMethodDef M_Geometry_methods[]= {
{"intersect_point_quad_2d", (PyCFunction) M_Geometry_intersect_point_quad_2d, METH_VARARGS, M_Geometry_intersect_point_quad_2d_doc},
{"intersect_line_line", (PyCFunction) M_Geometry_intersect_line_line, METH_VARARGS, M_Geometry_intersect_line_line_doc},
{"intersect_line_line_2d", (PyCFunction) M_Geometry_intersect_line_line_2d, METH_VARARGS, M_Geometry_intersect_line_line_2d_doc},
+ {"intersect_line_plane", (PyCFunction) M_Geometry_intersect_line_plane, METH_VARARGS, M_Geometry_intersect_line_plane_doc},
{"interpolate_bezier", (PyCFunction) M_Geometry_interpolate_bezier, METH_VARARGS, M_Geometry_interpolate_bezier_doc},
{"area_tri", (PyCFunction) M_Geometry_area_tri, METH_VARARGS, M_Geometry_area_tri_doc},
{"normal", (PyCFunction) M_Geometry_normal, METH_VARARGS, M_Geometry_normal_doc},
diff --git a/source/blender/python/generic/noise_py_api.c b/source/blender/python/generic/noise_py_api.c
index dbae0fb13bc..f5761f713a6 100644
--- a/source/blender/python/generic/noise_py_api.c
+++ b/source/blender/python/generic/noise_py_api.c
@@ -478,111 +478,134 @@ static PyObject *Noise_cell_vector(PyObject *UNUSED(self), PyObject *args)
In the original module I actually kept the docs stings with the functions themselves,
but I grouped them here so that it can easily be moved to a header if anyone thinks that is necessary. */
-static char random__doc__[] = "() No arguments.\n\n\
-Returns a random floating point number in the range [0, 1)";
+PyDoc_STRVAR(random__doc__,
+"() No arguments.\n\n\
+Returns a random floating point number in the range [0, 1)"
+);
-static char random_unit_vector__doc__[] =
- "() No arguments.\n\nReturns a random unit vector (3-float list).";
+PyDoc_STRVAR(random_unit_vector__doc__,
+"() No arguments.\n\nReturns a random unit vector (3-float list)."
+);
-static char seed_set__doc__[] = "(seed value)\n\n\
+PyDoc_STRVAR(seed_set__doc__,
+"(seed value)\n\n\
Initializes random number generator.\n\
-if seed is zero, the current time will be used instead.";
+if seed is zero, the current time will be used instead."
+);
-static char noise__doc__[] = "((x,y,z) tuple, [noisetype])\n\n\
+PyDoc_STRVAR(noise__doc__,
+"((x,y,z) tuple, [noisetype])\n\n\
Returns general noise of the optional specified type.\n\
-Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes."
+);
-static char noise_vector__doc__[] = "((x,y,z) tuple, [noisetype])\n\n\
+PyDoc_STRVAR(noise_vector__doc__,
+"((x,y,z) tuple, [noisetype])\n\n\
Returns noise vector (3-float list) of the optional specified type.\
-Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisetype determines the type of noise, STDPERLIN by default, see NoiseTypes."
+);
-static char turbulence__doc__[] =
- "((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
+PyDoc_STRVAR(turbulence__doc__,
+"((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
Returns general turbulence value using the optional specified noisebasis function.\n\
octaves (integer) is the number of noise values added.\n\
hard (bool), when false (0) returns 'soft' noise, when true (1) returns 'hard' noise (returned value always positive).\n\
Optional arguments:\n\
noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.\n\
ampscale sets the amplitude scale value of the noise frequencies added, 0.5 by default.\n\
-freqscale sets the frequency scale factor, 2.0 by default.";
+freqscale sets the frequency scale factor, 2.0 by default."
+);
-static char turbulence_vector__doc__[] =
- "((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
+PyDoc_STRVAR(turbulence_vector__doc__,
+"((x,y,z) tuple, octaves, hard, [noisebasis], [ampscale], [freqscale])\n\n\
Returns general turbulence vector (3-float list) using the optional specified noisebasis function.\n\
octaves (integer) is the number of noise values added.\n\
hard (bool), when false (0) returns 'soft' noise, when true (1) returns 'hard' noise (returned vector always positive).\n\
Optional arguments:\n\
noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.\n\
ampscale sets the amplitude scale value of the noise frequencies added, 0.5 by default.\n\
-freqscale sets the frequency scale factor, 2.0 by default.";
+freqscale sets the frequency scale factor, 2.0 by default."
+);
-static char fractal__doc__[] =
- "((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
+PyDoc_STRVAR(fractal__doc__,
+"((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
Returns Fractal Brownian Motion noise value(fBm).\n\
H is the fractal increment parameter.\n\
lacunarity is the gap between successive frequencies.\n\
octaves is the number of frequencies in the fBm.\n\
-Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes."
+);
-static char multi_fractal__doc__[] =
- "((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
+PyDoc_STRVAR(multi_fractal__doc__,
+"((x,y,z) tuple, H, lacunarity, octaves, [noisebasis])\n\n\
Returns Multifractal noise value.\n\
H determines the highest fractal dimension.\n\
lacunarity is gap between successive frequencies.\n\
octaves is the number of frequencies in the fBm.\n\
-Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes."
+);
-static char vl_vector__doc__[] =
- "((x,y,z) tuple, distortion, [noisetype1], [noisetype2])\n\n\
+PyDoc_STRVAR(vl_vector__doc__,
+"((x,y,z) tuple, distortion, [noisetype1], [noisetype2])\n\n\
Returns Variable Lacunarity Noise value, a distorted variety of noise.\n\
distortion sets the amount of distortion.\n\
Optional arguments noisetype1 and noisetype2 set the noisetype to distort and the noisetype used for the distortion respectively.\n\
-See NoiseTypes, both are STDPERLIN by default.";
+See NoiseTypes, both are STDPERLIN by default."
+);
-static char hetero_terrain__doc__[] =
- "((x,y,z) tuple, H, lacunarity, octaves, offset, [noisebasis])\n\n\
+PyDoc_STRVAR(hetero_terrain__doc__,
+"((x,y,z) tuple, H, lacunarity, octaves, offset, [noisebasis])\n\n\
returns Heterogeneous Terrain value\n\
H determines the fractal dimension of the roughest areas.\n\
lacunarity is the gap between successive frequencies.\n\
octaves is the number of frequencies in the fBm.\n\
offset raises the terrain from 'sea level'.\n\
-Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes."
+);
-static char hybrid_multi_fractal__doc__[] =
- "((x,y,z) tuple, H, lacunarity, octaves, offset, gain, [noisebasis])\n\n\
+PyDoc_STRVAR(hybrid_multi_fractal__doc__,
+"((x,y,z) tuple, H, lacunarity, octaves, offset, gain, [noisebasis])\n\n\
returns Hybrid Multifractal value.\n\
H determines the fractal dimension of the roughest areas.\n\
lacunarity is the gap between successive frequencies.\n\
octaves is the number of frequencies in the fBm.\n\
offset raises the terrain from 'sea level'.\n\
gain scales the values.\n\
-Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes."
+);
-static char ridged_multi_fractal__doc__[] =
- "((x,y,z) tuple, H, lacunarity, octaves, offset, gain [noisebasis])\n\n\
+PyDoc_STRVAR(ridged_multi_fractal__doc__,
+"((x,y,z) tuple, H, lacunarity, octaves, offset, gain [noisebasis])\n\n\
returns Ridged Multifractal value.\n\
H determines the fractal dimension of the roughest areas.\n\
lacunarity is the gap between successive frequencies.\n\
octaves is the number of frequencies in the fBm.\n\
offset raises the terrain from 'sea level'.\n\
gain scales the values.\n\
-Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes.";
+Optional argument noisebasis determines the type of noise used for the turbulence, STDPERLIN by default, see NoiseTypes."
+);
-static char voronoi__doc__[] =
- "((x,y,z) tuple, distance_metric, [exponent])\n\n\
+PyDoc_STRVAR(voronoi__doc__,
+"((x,y,z) tuple, distance_metric, [exponent])\n\n\
returns a list, containing a list of distances in order of closest feature,\n\
and a list containing the positions of the four closest features\n\
Optional arguments:\n\
distance_metric: see DistanceMetrics, default is DISTANCE\n\
-exponent is only used with MINKOVSKY, default is 2.5.";
+exponent is only used with MINKOVSKY, default is 2.5."
+);
-static char cell__doc__[] = "((x,y,z) tuple)\n\n\
-returns cellnoise float value.";
+PyDoc_STRVAR(cell__doc__,
+"((x,y,z) tuple)\n\n\
+returns cellnoise float value."
+);
-static char cell_vector__doc__[] = "((x,y,z) tuple)\n\n\
-returns cellnoise vector/point/color (3-float list).";
+PyDoc_STRVAR(cell_vector__doc__,
+"((x,y,z) tuple)\n\n\
+returns cellnoise vector/point/color (3-float list)."
+);
-static char Noise__doc__[] = "Blender Noise and Turbulence Module\n\n\
+PyDoc_STRVAR(Noise__doc__,
+"Blender Noise and Turbulence Module\n\n\
This module can be used to generate noise of various types.\n\
This can be used for terrain generation, to create textures,\n\
make animations more 'animated', object deformation, etc.\n\
@@ -610,7 +633,8 @@ look like anything from an earthquake to a very nervous or maybe even drunk came
\trv = Noise.turbulence_vector(ps, 3, 0, Noise.NoiseTypes.NEWPERLIN)\n\
\tob.dloc = (sp*rv[0], sp*rv[1], sp*rv[2])\n\
\tob.drot = (sr*rv[0], sr*rv[1], sr*rv[2])\n\
-\n";
+\n"
+);
/* Just in case, declarations for a header file */
/*
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index 30e3d5a1052..0233f85ae91 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -35,6 +35,9 @@ set(INC
../../freestyle/intern/python
../../../../intern/guardedalloc
../../../../intern/audaspace/intern
+)
+
+set(INC_SYS
${PYTHON_INCLUDE_DIRS}
)
@@ -82,4 +85,4 @@ if(WITH_PYTHON_SAFETY)
add_definitions(-DWITH_PYTHON_SAFETY)
endif()
-blender_add_lib(bf_python "${SRC}" "${INC}")
+blender_add_lib(bf_python "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index e43d3a8e98c..ce548af3780 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -66,28 +66,28 @@
PyObject *bpy_package_py= NULL;
-static char bpy_script_paths_doc[] =
+PyDoc_STRVAR(bpy_script_paths_doc,
".. function:: script_paths()\n"
"\n"
" Return 2 paths to blender scripts directories.\n"
"\n"
" :return: (system, user) strings will be empty when not found.\n"
" :rtype: tuple of strings\n"
-;
+);
static PyObject *bpy_script_paths(PyObject *UNUSED(self))
{
PyObject *ret= PyTuple_New(2);
char *path;
- path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
- PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
path= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
+ PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
+ path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
return ret;
}
-static char bpy_blend_paths_doc[] =
+PyDoc_STRVAR(bpy_blend_paths_doc,
".. function:: blend_paths(absolute=False)\n"
"\n"
" Returns a list of paths to external files referenced by the loaded .blend file.\n"
@@ -96,7 +96,7 @@ static char bpy_blend_paths_doc[] =
" :type absolute: boolean\n"
" :return: path list.\n"
" :rtype: list of strings\n"
-;
+);
static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
struct BPathIterator *bpi;
@@ -139,7 +139,7 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
}
-// static char bpy_user_resource_doc[]= // now in bpy/utils.py
+// PyDoc_STRVAR(bpy_user_resource_doc[]= // now in bpy/utils.py
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
char *type;
@@ -171,7 +171,7 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
return PyUnicode_DecodeFSDefault(path ? path : "");
}
-static char bpy_resource_path_doc[] =
+PyDoc_STRVAR(bpy_resource_path_doc,
".. function:: resource_path(type, major=2, minor=57)\n"
"\n"
" Return the base path for storing system files.\n"
@@ -184,7 +184,7 @@ static char bpy_resource_path_doc[] =
" :type minor: string\n"
" :return: the resource path (not necessarily existing).\n"
" :rtype: string\n"
-;
+);
static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
char *type;
@@ -233,7 +233,7 @@ static PyObject *bpy_import_test(const char *modname)
/*****************************************************************************
* Description: Creates the bpy module and adds it to sys.modules for importing
*****************************************************************************/
-void BPy_init_modules( void )
+void BPy_init_modules(void)
{
extern BPy_StructRNA *bpy_context_module;
extern int bpy_lib_init(PyObject *);
@@ -241,7 +241,7 @@ void BPy_init_modules( void )
PyObject *mod;
/* Needs to be first since this dir is needed for future modules */
- char *modpath= BLI_get_folder(BLENDER_SCRIPTS, "modules");
+ char *modpath= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules");
if(modpath) {
// printf("bpy: found module path '%s'.\n", modpath);
PyObject *sys_path= PySys_GetObject("path"); /* borrow */
@@ -265,17 +265,17 @@ void BPy_init_modules( void )
/* run first, initializes rna types */
BPY_rna_init();
- PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
+ PyModule_AddObject(mod, "types", BPY_rna_types()); /* needs to be first so bpy_types can run */
PyModule_AddObject(mod, "StructMetaPropGroup", (PyObject *)&pyrna_struct_meta_idprop_Type); /* metaclass for idprop types, bpy_types.py needs access */
bpy_lib_init(mod); /* adds '_bpy._library_load', must be called before 'bpy_types' which uses it */
bpy_import_test("bpy_types");
- PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
+ PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */
bpy_import_test("bpy_types");
- PyModule_AddObject( mod, "props", BPY_rna_props() );
- PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
- PyModule_AddObject( mod, "app", BPY_app_struct() );
+ PyModule_AddObject(mod, "props", BPY_rna_props());
+ PyModule_AddObject(mod, "ops", BPY_operator_module()); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
+ PyModule_AddObject(mod, "app", BPY_app_struct());
/* bpy context */
RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr);
diff --git a/source/blender/python/intern/bpy.h b/source/blender/python/intern/bpy.h
index 0f298c1daf1..0ebc6bb2438 100644
--- a/source/blender/python/intern/bpy.h
+++ b/source/blender/python/intern/bpy.h
@@ -26,5 +26,5 @@
*/
-void BPy_init_modules( void );
+void BPy_init_modules(void);
extern PyObject *bpy_package_py;
diff --git a/source/blender/python/intern/bpy_app.h b/source/blender/python/intern/bpy_app.h
index d57e4688f46..fbc5696875a 100644
--- a/source/blender/python/intern/bpy_app.h
+++ b/source/blender/python/intern/bpy_app.h
@@ -29,6 +29,6 @@
#ifndef BPY_APP_H
#define BPY_APP_H
-PyObject *BPY_app_struct( void );
+PyObject *BPY_app_struct(void);
#endif // BPY_APP_H
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index df31fab6bde..dec393bd1e4 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -60,7 +60,7 @@ int bpy_pydriver_create_dict(void)
else
bpy_pydriver_Dict= d;
- /* import some modules: builtins, bpy, math, (Blender.noise )*/
+ /* import some modules: builtins, bpy, math, (Blender.noise)*/
PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins());
mod= PyImport_ImportModule("math");
@@ -185,12 +185,11 @@ float BPY_driver_exec(ChannelDriver *driver)
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
Py_XDECREF(expr_vars);
- /* intern the arg names so creating the namespace for every run is faster */
expr_vars= PyTuple_New(BLI_countlist(&driver->variables));
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars);
for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) {
- PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_InternFromString(dvar->name));
+ PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_FromString(dvar->name));
}
driver->flag &= ~DRIVER_FLAG_RENAMEVAR;
@@ -211,7 +210,7 @@ float BPY_driver_exec(ChannelDriver *driver)
/* try to add to dictionary */
/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
- if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) { /* use string interning for faster namespace creation */
+ if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) {
/* this target failed - bad name */
if (targets_ok) {
/* first one - print some extra info for easier identification */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index acd23887af0..e6f4c5713a1 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -197,7 +197,7 @@ void BPY_python_start(int argc, const char **argv)
PyImport_ExtendInittab(bpy_internal_modules);
/* allow to use our own included python */
- PyC_SetHomePath(BLI_get_folder(BLENDER_PYTHON, NULL));
+ PyC_SetHomePath(BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL));
/* Python 3.2 now looks for '2.57/python/include/python3.2d/pyconfig.h' to parse
* from the 'sysconfig' module which is used by 'site', so for now disable site.
diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c
index b66b2109329..85bffb5a8cc 100644
--- a/source/blender/python/intern/bpy_library.c
+++ b/source/blender/python/intern/bpy_library.c
@@ -26,6 +26,9 @@
* \ingroup pythonintern
*/
+/* nifty feature. swap out strings for RNA data */
+#define USE_RNA_DATABLOCKS
+
#include <Python.h>
#include <stddef.h>
@@ -47,6 +50,11 @@
#include "bpy_util.h"
+#ifdef USE_RNA_DATABLOCKS
+# include "bpy_rna.h"
+# include "RNA_access.h"
+#endif
+
typedef struct {
PyObject_HEAD /* required python macro */
/* collection iterator spesific parts */
@@ -155,7 +163,7 @@ static PyTypeObject bpy_lib_Type= {
NULL
};
-static char bpy_lib_load_doc[] =
+PyDoc_STRVAR(bpy_lib_load_doc,
".. method:: load(filepath, link=False, relative=False)\n"
"\n"
" Returns a context manager which exposes 2 library objects on entering.\n"
@@ -167,7 +175,7 @@ static char bpy_lib_load_doc[] =
" :type link: bool\n"
" :arg relative: When True the path is stored relative to the open blend file.\n"
" :type relative: bool\n"
-;
+);
static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
static const char *kwlist[]= {"filepath", "link", "relative", NULL};
@@ -205,7 +213,7 @@ static PyObject *_bpy_names(BPy_Library *self, int blocktype)
int counter= 0;
list= PyList_New(totnames);
for(l= names; l; l= l->next) {
- PyList_SET_ITEM(list, counter, PyUnicode_FromString((char * )l->link));
+ PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
counter++;
}
BLI_linklist_free(names, free); /* free linklist *and* each node's data */
@@ -271,6 +279,36 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
return ret;
}
+static void bpy_lib_exit_warn_idname(BPy_Library *self, const char *name_plural, const char *idname)
+{
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
+ if (PyErr_WarnFormat(PyExc_UserWarning, 1,
+ "load: '%s' does not contain %s[\"%s\"]",
+ self->abspath, name_plural, idname)) {
+ /* Spurious errors can appear at shutdown */
+ if (PyErr_ExceptionMatches(PyExc_Warning)) {
+ PyErr_WriteUnraisable((PyObject *)self);
+ }
+ }
+ PyErr_Restore(exc, val, tb);
+}
+
+static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
+{
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
+ if (PyErr_WarnFormat(PyExc_UserWarning, 1,
+ "load: '%s' expected a string type, not a %.200s",
+ self->abspath, Py_TYPE(item)->tp_name)) {
+ /* Spurious errors can appear at shutdown */
+ if (PyErr_ExceptionMatches(PyExc_Warning)) {
+ PyErr_WriteUnraisable((PyObject *)self);
+ }
+ }
+ PyErr_Restore(exc, val, tb);
+}
+
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
{
Main *mainl= NULL;
@@ -302,18 +340,41 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
// printf(" %s\n", item_str);
if(item_str) {
- if(!BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, self->flag)) {
- PyErr_Format(PyExc_KeyError,
- "load: %s does not contain %s[\"%s\"]",
- self->abspath, name_plural, item_str);
- err= -1;
- break;
+ ID *id= BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code);
+ if(id) {
+#ifdef USE_RNA_DATABLOCKS
+ PointerRNA id_ptr;
+ RNA_id_pointer_create(id, &id_ptr);
+ Py_DECREF(item);
+ item= pyrna_struct_CreatePyObject(&id_ptr);
+#endif
}
+ else {
+ bpy_lib_exit_warn_idname(self, name_plural, item_str);
+ /* just warn for now */
+ /* err = -1; */
+#ifdef USE_RNA_DATABLOCKS
+ item= Py_None;
+ Py_INCREF(item);
+#endif
+ }
+
+ /* ID or None */
}
else {
/* XXX, could complain about this */
+ bpy_lib_exit_warn_type(self, item);
PyErr_Clear();
+
+#ifdef USE_RNA_DATABLOCKS
+ item= Py_None;
+ Py_INCREF(item);
+#endif
}
+
+#ifdef USE_RNA_DATABLOCKS
+ PyList_SET_ITEM(ls, i, item);
+#endif
}
}
}
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 6ea52abc5f4..8ed4e41de3e 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -47,13 +47,22 @@
#include "../generic/py_capi_utils.h"
+/* initial definition of callback slots we'll probably have more then 1 */
+#define BPY_DATA_CB_SLOT_SIZE 1
+
+#define BPY_DATA_CB_SLOT_UPDATE 0
+
+extern BPy_StructRNA *bpy_context_module;
+
static EnumPropertyItem property_flag_items[]= {
{PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
+ {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
{PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem property_flag_enum_items[]= {
{PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
+ {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
{PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
{PROP_ENUM_FLAG, "ENUM_FLAG", 0, "Enum Flag", ""},
{0, NULL, 0, NULL, NULL}};
@@ -108,6 +117,45 @@ static PyObject *pymeth_PointerProperty= NULL;
static PyObject *pymeth_CollectionProperty= NULL;
static PyObject *pymeth_RemoveProperty= NULL;
+PyObject *pyrna_struct_as_instance(PointerRNA *ptr)
+{
+ PyObject *self= NULL;
+ /* first get self */
+ /* operators can store their own instance for later use */
+ if(ptr->data) {
+ void **instance= RNA_struct_instance(ptr);
+
+ if(instance) {
+ if(*instance) {
+ self= *instance;
+ Py_INCREF(self);
+ }
+ }
+ }
+
+ /* in most cases this will run */
+ if(self == NULL) {
+ self= pyrna_struct_CreatePyObject(ptr);
+ }
+
+ return self;
+}
+
+/* could be moved into bpy_utils */
+static void printf_func_error(PyObject *py_func)
+{
+ /* since we return to C code we can't leave the error */
+ PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func);
+ PyErr_Print();
+ PyErr_Clear();
+
+ /* use py style error */
+ fprintf(stderr, "File \"%s\", line %d, in %s\n",
+ _PyUnicode_AsString(f_code->co_filename),
+ f_code->co_firstlineno,
+ _PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name)
+ );
+}
/* operators and classes use this so it can store the args given but defer
* running it until the operator runs where these values are used to setup
@@ -128,6 +176,96 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
return ret;
}
+/* callbacks */
+void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop)
+{
+ PyGILState_STATE gilstate;
+ PyObject **py_data= (PyObject **)RNA_property_py_data_get(prop);
+ PyObject *py_func;
+ PyObject *args;
+ PyObject *self;
+ PyObject *ret;
+ const int is_write_ok= pyrna_write_check();
+
+ BLI_assert(py_data != NULL);
+
+ if(!is_write_ok) {
+ pyrna_write_set(TRUE);
+ }
+
+ bpy_context_set(C, &gilstate);
+
+ py_func= py_data[BPY_DATA_CB_SLOT_UPDATE];
+
+ args= PyTuple_New(2);
+ self= pyrna_struct_as_instance(ptr);
+ PyTuple_SET_ITEM(args, 0, self);
+
+ PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
+ Py_INCREF(bpy_context_module);
+
+ ret= PyObject_CallObject(py_func, args);
+
+ Py_DECREF(args);
+
+ if(ret == NULL) {
+ printf_func_error(py_func);
+ }
+ else {
+ if(ret != Py_None) {
+ PyErr_SetString(PyExc_ValueError, "the return value must be None");
+ printf_func_error(py_func);
+ }
+
+ Py_DECREF(ret);
+ }
+
+ bpy_context_clear(C, &gilstate);
+
+ if(!is_write_ok) {
+ pyrna_write_set(FALSE);
+ }
+}
+
+static int bpy_prop_callback_check(PyObject *py_func, int argcount)
+{
+ if(py_func) {
+ if(!PyFunction_Check(py_func)) {
+ PyErr_Format(PyExc_TypeError,
+ "update keyword: expected a function type, not a %.200s",
+ Py_TYPE(py_func)->tp_name);
+ return -1;
+ }
+ else {
+ PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func);
+ if (f_code->co_argcount != argcount) {
+ PyErr_Format(PyExc_TypeError,
+ "update keyword: expected a function taking %d arguments, not %d",
+ argcount, f_code->co_argcount);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_cb)
+{
+ /* assume this is already checked for type and arg length */
+ if(update_cb) {
+ PyObject **py_data= MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, "bpy_prop_callback_assign");
+ RNA_def_property_update_runtime(prop, (void *)bpy_prop_update_cb);
+ py_data[BPY_DATA_CB_SLOT_UPDATE]= update_cb;
+ RNA_def_py_data(prop, py_data);
+
+ RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE);
+ }
+
+ return 0;
+}
+
/* this define runs at the start of each function and deals with
* returning a deferred property (to be registered later) */
#define BPY_PROPDEF_HEAD(_func) \
@@ -154,11 +292,15 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
* calls because of static strins passed to pyrna_set_to_enum_bitfield */
#define BPY_PROPDEF_CHECK(_func, _property_flag_items) \
if(id_len >= MAX_IDPROP_NAME) { \
- PyErr_Format(PyExc_TypeError, #_func"(): '%.200s' too long, max length is %d", id, MAX_IDPROP_NAME-1); \
+ PyErr_Format(PyExc_TypeError, \
+ #_func"(): '%.200s' too long, max length is %d", \
+ id, MAX_IDPROP_NAME-1); \
return NULL; \
} \
if(RNA_def_property_free_identifier(srna, id) == -1) { \
- PyErr_Format(PyExc_TypeError, #_func"(): '%s' is defined as a non-dynamic type", id); \
+ PyErr_Format(PyExc_TypeError, \
+ #_func"(): '%s' is defined as a non-dynamic type", \
+ id); \
return NULL; \
} \
if(pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, pyopts, &opts, #_func"(options={...}):")) \
@@ -167,7 +309,9 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
#define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype) \
BPY_PROPDEF_CHECK(_func, _property_flag_items) \
if(pysubtype && RNA_enum_value_from_id(_subtype, pysubtype, &subtype)==0) { \
- PyErr_Format(PyExc_TypeError, #_func"(subtype='%s'): invalid subtype", pysubtype); \
+ PyErr_Format(PyExc_TypeError, \
+ #_func"(subtype='%s'): invalid subtype", \
+ pysubtype); \
return NULL; \
} \
@@ -182,6 +326,11 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
" :type description: string\n" \
+#define BPY_PROPDEF_UPDATE_DOC \
+" :arg update: function to be called when this value is modified,\n" \
+" This function must take 2 values (self, context) and return None.\n" \
+" :type update: function\n" \
+
#if 0
static int bpy_struct_id_used(StructRNA *srna, char *identifier)
{
@@ -194,18 +343,19 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
/* Function that sets RNA, NOTE - self is NULL when called from python, but being abused from C so we can pass the srna allong
* This isnt incorrect since its a python object - but be careful */
-static char BPy_BoolProperty_doc[] =
-".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATABLE'}, subtype='NONE')\n"
+PyDoc_STRVAR(BPy_BoolProperty_doc,
+".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
"\n"
" Returns a new boolean property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -213,7 +363,7 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_HEAD(BoolProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
int def=0;
@@ -222,18 +372,24 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssiO!s:BoolProperty",
+ "s#|ssiO!sO:BoolProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &def,
- &PySet_Type, &pyopts, &pysubtype))
+ &PySet_Type, &pyopts, &pysubtype,
+ &update_cb))
{
return NULL;
}
BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty, property_flag_items, property_subtype_number_items)
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
RNA_def_property_boolean_default(prop, def);
RNA_def_property_ui_text(prop, name, description);
@@ -242,14 +398,15 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_BoolVectorProperty_doc[] =
-".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
+PyDoc_STRVAR(BPy_BoolVectorProperty_doc,
+".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
"\n"
" Returns a new vector boolean property definition.\n"
"\n"
@@ -257,13 +414,14 @@ BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of booleans the length of *size*.\n"
" :type default: sequence\n"
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -271,7 +429,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
BPY_PROPDEF_HEAD(BoolVectorProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", "size", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "options", "subtype", "size", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
int def[PYRNA_STACK_ARRAY]={0};
@@ -282,12 +440,14 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssOO!si:BoolVectorProperty",
+ "s#|ssOO!siO:BoolVectorProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &pydef,
- &PySet_Type, &pyopts, &pysubtype,&size))
+ &PySet_Type, &pyopts, &pysubtype, &size,
+ &update_cb))
{
return NULL;
}
@@ -302,6 +462,10 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
if(pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0)
return NULL;
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
// prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
RNA_def_property_array(prop, size);
@@ -312,24 +476,26 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_IntProperty_doc[] =
-".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATABLE'}, subtype='NONE')\n"
+PyDoc_STRVAR(BPy_IntProperty_doc,
+".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
"\n"
" Returns a new int property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -337,7 +503,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_HEAD(IntProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0;
@@ -346,19 +512,25 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssiiiiiiO!s:IntProperty",
+ "s#|ssiiiiiiO!sO:IntProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &def,
&min, &max, &soft_min, &soft_max,
- &step, &PySet_Type, &pyopts, &pysubtype))
+ &step, &PySet_Type, &pyopts, &pysubtype,
+ &update_cb))
{
return NULL;
}
BPY_PROPDEF_SUBTYPE_CHECK(IntProperty, property_flag_items, property_subtype_number_items)
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_INT, subtype);
RNA_def_property_int_default(prop, def);
RNA_def_property_range(prop, min, max);
@@ -369,13 +541,14 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_IntVectorProperty_doc[] =
-".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
+PyDoc_STRVAR(BPy_IntVectorProperty_doc,
+".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
"\n"
" Returns a new vector int property definition.\n"
"\n"
@@ -383,13 +556,14 @@ BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of ints the length of *size*.\n"
" :type default: sequence\n"
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -397,7 +571,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
BPY_PROPDEF_HEAD(IntVectorProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0};
@@ -408,14 +582,16 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssOiiiiiO!si:IntVectorProperty",
+ "s#|ssOiiiiiO!siO:IntVectorProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &pydef,
&min, &max, &soft_min, &soft_max,
&step, &PySet_Type, &pyopts,
- &pysubtype, &size))
+ &pysubtype, &size,
+ &update_cb))
{
return NULL;
}
@@ -430,6 +606,10 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
if(pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0)
return NULL;
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_INT, subtype);
RNA_def_property_array(prop, size);
if(pydef) RNA_def_property_int_array_default(prop, def);
@@ -441,26 +621,28 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_FloatProperty_doc[] =
-".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE')\n"
+PyDoc_STRVAR(BPy_FloatProperty_doc,
+".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE', update=None)\n"
"\n"
" Returns a new float property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string\n"
" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n"
" :type unit: string\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -468,7 +650,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_HEAD(FloatProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
@@ -480,14 +662,16 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
int subtype= PROP_NONE;
char *pyunit= NULL;
int unit= PROP_UNIT_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssffffffiO!ss:FloatProperty",
+ "s#|ssffffffiO!ssO:FloatProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &def,
&min, &max, &soft_min, &soft_max,
&step, &precision, &PySet_Type,
- &pyopts, &pysubtype, &pyunit))
+ &pyopts, &pysubtype, &pyunit,
+ &update_cb))
{
return NULL;
}
@@ -499,6 +683,10 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
RNA_def_property_float_default(prop, def);
RNA_def_property_range(prop, min, max);
@@ -509,13 +697,14 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_FloatVectorProperty_doc[] =
-".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', size=3)\n"
+PyDoc_STRVAR(BPy_FloatVectorProperty_doc,
+".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', size=3, update=None)\n"
"\n"
" Returns a new vector float property definition.\n"
"\n"
@@ -523,13 +712,14 @@ BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of floats the length of *size*.\n"
" :type default: sequence\n"
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -537,7 +727,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
BPY_PROPDEF_HEAD(FloatVectorProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
@@ -548,14 +738,16 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|ssOfffffiO!si:FloatVectorProperty",
+ "s#|ssOfffffiO!siO:FloatVectorProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &pydef,
&min, &max, &soft_min, &soft_max,
&step, &precision, &PySet_Type,
- &pyopts, &pysubtype, &size))
+ &pyopts, &pysubtype, &size,
+ &update_cb))
{
return NULL;
}
@@ -570,6 +762,10 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
if(pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0)
return NULL;
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
RNA_def_property_array(prop, size);
if(pydef) RNA_def_property_float_array_default(prop, def);
@@ -581,23 +777,25 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_StringProperty_doc[] =
-".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATABLE'}, subtype='NONE')\n"
+PyDoc_STRVAR(BPy_StringProperty_doc,
+".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATABLE'}, subtype='NONE', update=None)\n"
"\n"
" Returns a new string property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILENAME', 'NONE'].\n"
" :type subtype: string\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -605,7 +803,7 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
BPY_PROPDEF_HEAD(StringProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "name", "description", "default", "maxlen", "options", "subtype", NULL};
+ static const char *kwlist[]= {"attr", "name", "description", "default", "maxlen", "options", "subtype", "update", NULL};
const char *id=NULL, *name="", *description="", *def="";
int id_len;
int maxlen=0;
@@ -614,18 +812,24 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
int opts=0;
char *pysubtype= NULL;
int subtype= PROP_NONE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#|sssiO!s:StringProperty",
+ "s#|sssiO!sO:StringProperty",
(char **)kwlist, &id, &id_len,
&name, &description, &def,
- &maxlen, &PySet_Type, &pyopts, &pysubtype))
+ &maxlen, &PySet_Type, &pyopts, &pysubtype,
+ &update_cb))
{
return NULL;
}
BPY_PROPDEF_SUBTYPE_CHECK(StringProperty, property_flag_items, property_subtype_string_items)
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_property(srna, id, PROP_STRING, subtype);
if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */
if(def) RNA_def_property_string_default(prop, def);
@@ -635,21 +839,35 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
+#if 0
+/* copies orig to buf, then sets orig to buf, returns copy length */
+static size_t strswapbufcpy(char *buf, const char **orig)
+{
+ const char *src= *orig;
+ char *dst= buf;
+ size_t i= 0;
+ *orig= buf;
+ while((*dst= *src)) { dst++; src++; i++; }
+ return i + 1; /* include '\0' */
+}
+#endif
+
static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const short is_enum_flag)
{
- EnumPropertyItem *items= NULL;
+ EnumPropertyItem *items;
PyObject *item;
- int seq_len, i, totitem= 0;
+ const Py_ssize_t seq_len= PySequence_Fast_GET_SIZE(seq_fast);
+ Py_ssize_t totbuf= 0;
+ int i;
short def_used= 0;
const char *def_cmp= NULL;
- seq_len= PySequence_Fast_GET_SIZE(seq_fast);
-
if(is_enum_flag) {
if(seq_len > RNA_ENUM_BITFLAG_SIZE) {
PyErr_SetString(PyExc_TypeError, "EnumProperty(...): maximum " STRINGIFY(RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
@@ -679,43 +897,52 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
/* blank value */
*defvalue= 0;
+ items= MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
+
for(i=0; i<seq_len; i++) {
EnumPropertyItem tmp= {0, "", 0, "", ""};
+ Py_ssize_t id_str_size;
+ Py_ssize_t name_str_size;
+ Py_ssize_t desc_str_size;
item= PySequence_Fast_GET_ITEM(seq_fast, i);
- if(PyTuple_Check(item)==0) {
- PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items");
- if(items) MEM_freeN(items);
- return NULL;
- }
- if(!PyArg_ParseTuple(item, "sss", &tmp.identifier, &tmp.name, &tmp.description)) {
- PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an identifier, name and description in the tuple");
- return NULL;
- }
-
- if(is_enum_flag) {
- tmp.value= 1<<i;
+ if( (PyTuple_CheckExact(item)) &&
+ (PyTuple_GET_SIZE(item) == 3) &&
+ (tmp.identifier= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
+ (tmp.name= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
+ (tmp.description= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size))
+ ) {
+ if(is_enum_flag) {
+ tmp.value= 1<<i;
+
+ if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
+ *defvalue |= tmp.value;
+ def_used++;
+ }
+ }
+ else {
+ tmp.value= i;
- if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
- *defvalue |= tmp.value;
- def_used++;
+ if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
+ *defvalue= tmp.value;
+ def_used++; /* only ever 1 */
+ }
}
+
+ items[i]= tmp;
+
+ /* calculate combine string length */
+ totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */
}
else {
- tmp.value= i;
-
- if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
- *defvalue= tmp.value;
- def_used++; /* only ever 1 */
- }
+ MEM_freeN(items);
+ PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an tuple containing (identifier, name description)");
+ return NULL;
}
- RNA_enum_item_add(&items, &totitem, &tmp);
}
- RNA_enum_item_end(&items, &totitem);
-
if(is_enum_flag) {
/* strict check that all set members were used */
if(def && def_used != PySet_GET_SIZE(def)) {
@@ -738,23 +965,117 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
}
}
+ /* disabled duplicating strings because the array can still be freed and
+ * the strings from it referenced, for now we can't support dynamically
+ * created strings from python. */
+#if 0
+ /* this would all work perfectly _but_ the python strings may be freed
+ * immediately after use, so we need to duplicate them, ugh.
+ * annoying because it works most of the time without this. */
+ {
+ EnumPropertyItem *items_dup= MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf), "enum_items_from_py2");
+ EnumPropertyItem *items_ptr= items_dup;
+ char *buf= ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
+ memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
+ for(i=0; i<seq_len; i++, items_ptr++) {
+ buf += strswapbufcpy(buf, &items_ptr->identifier);
+ buf += strswapbufcpy(buf, &items_ptr->name);
+ buf += strswapbufcpy(buf, &items_ptr->description);
+ }
+ MEM_freeN(items);
+ items=items_dup;
+ }
+ /* end string duplication */
+#endif
+
return items;
}
-static char BPy_EnumProperty_doc[] =
-".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
+static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int *free)
+{
+ PyGILState_STATE gilstate;
+
+ PyObject *py_func= RNA_property_enum_py_data_get(prop);
+ PyObject *self= NULL;
+ PyObject *args;
+ PyObject *items; /* returned from the function call */
+
+ EnumPropertyItem *eitems= NULL;
+ int err= 0;
+
+ bpy_context_set(C, &gilstate);
+
+ args= PyTuple_New(2);
+ self= pyrna_struct_as_instance(ptr);
+ PyTuple_SET_ITEM(args, 0, self);
+
+ /* now get the context */
+ PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
+ Py_INCREF(bpy_context_module);
+
+ items= PyObject_CallObject(py_func, args);
+
+ Py_DECREF(args);
+
+ if(items==NULL) {
+ err= -1;
+ }
+ else {
+ PyObject *items_fast;
+ int defvalue_dummy=0;
+
+ if(!(items_fast= PySequence_Fast(items, "EnumProperty(...): return value from the callback was not a sequence"))) {
+ err= -1;
+ }
+ else {
+ eitems= enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG)!=0);
+
+ Py_DECREF(items_fast);
+
+ if(!eitems) {
+ err= -1;
+ }
+ }
+
+ Py_DECREF(items);
+ }
+
+ if(err != -1) { /* worked */
+ *free= 1;
+ }
+ else {
+ printf_func_error(py_func);
+
+ eitems= DummyRNA_NULL_items;
+ }
+
+
+ bpy_context_clear(C, &gilstate);
+ return eitems;
+}
+
+PyDoc_STRVAR(BPy_EnumProperty_doc,
+".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATABLE'}, update=None)\n"
"\n"
" Returns a new enumerator property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg default: The default value for this enum, A string when *ENUM_FLAG* is disabled otherwise a set which may only contain string identifiers used in *items*.\n"
+" :arg default: The default value for this enum, A string when *ENUM_FLAG*\n"
+" is disabled otherwise a set which may only contain string identifiers\n"
+" used in *items*.\n"
" :type default: string or set\n"
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE', 'ENUM_FLAG'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE', 'ENUM_FLAG'].\n"
" :type options: set\n"
-" :arg items: sequence of enum items formatted: [(identifier, name, description), ...] where the identifier is used for python access and other values are used for the interface.\n"
-" :type items: sequence of string triplets\n"
-;
+" :arg items: sequence of enum items formatted:\n"
+" [(identifier, name, description), ...] where the identifier is used\n"
+" for python access and other values are used for the interface.\n"
+" For dynamic values a callback can be passed which returns a list in\n"
+" the same format as the static list.\n"
+" This function must take 2 arguments (self, context)\n"
+" :type items: sequence of string triplets or a function\n"
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -762,7 +1083,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_HEAD(EnumProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "items", "name", "description", "default", "options", NULL};
+ static const char *kwlist[]= {"attr", "items", "name", "description", "default", "options", "update", NULL};
const char *id=NULL, *name="", *description="";
PyObject *def= NULL;
int id_len;
@@ -772,38 +1093,78 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
PropertyRNA *prop;
PyObject *pyopts= NULL;
int opts=0;
+ short is_itemf= FALSE;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#O|ssOO!:EnumProperty",
+ "s#O|ssOO!O:EnumProperty",
(char **)kwlist, &id, &id_len,
&items, &name, &description,
- &def, &PySet_Type, &pyopts))
+ &def, &PySet_Type, &pyopts,
+ &update_cb))
{
return NULL;
}
BPY_PROPDEF_CHECK(EnumProperty, property_flag_enum_items)
- if(!(items_fast= PySequence_Fast(items, "EnumProperty(...): expected a sequence of tuples for the enum items"))) {
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
return NULL;
}
- eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0);
+ /* items can be a list or a callable */
+ if(PyFunction_Check(items)) { /* dont use PyCallable_Check because we need the function code for errors */
+ PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(items);
+ if(f_code->co_argcount != 2) {
+ PyErr_Format(PyExc_ValueError,
+ "EnumProperty(...): expected 'items' function to take 2 arguments, not %d",
+ f_code->co_argcount);
+ return NULL;
+ }
- Py_DECREF(items_fast);
+ if(def) {
+ /* note, using type error here is odd but python does this for invalid arguments */
+ PyErr_SetString(PyExc_TypeError,
+ "EnumProperty(...): 'default' can't be set when 'items' is a function");
+ return NULL;
+ }
- if(!eitems)
- return NULL;
+ is_itemf= TRUE;
+ eitems= DummyRNA_NULL_items;
+ }
+ else {
+ if(!(items_fast= PySequence_Fast(items, "EnumProperty(...): expected a sequence of tuples for the enum items or a function"))) {
+ return NULL;
+ }
+
+ eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0);
+
+ Py_DECREF(items_fast);
+
+ if(!eitems) {
+ return NULL;
+ }
+ }
if(opts & PROP_ENUM_FLAG) prop= RNA_def_enum_flag(srna, id, eitems, defvalue, name, description);
else prop= RNA_def_enum(srna, id, eitems, defvalue, name, description);
+ if(is_itemf) {
+ RNA_def_enum_funcs(prop, bpy_props_enum_itemf);
+ RNA_def_enum_py_data(prop, (void *)items);
+ /* Py_INCREF(items); */ /* watch out!, if user is tricky they can probably crash blender if they manage to free the callback, take care! */
+ }
+
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
- MEM_freeN(eitems);
+
+ if(is_itemf == FALSE) {
+ MEM_freeN(eitems);
+ }
}
Py_RETURN_NONE;
}
@@ -840,8 +1201,8 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
return srna;
}
-static char BPy_PointerProperty_doc[] =
-".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'})\n"
+PyDoc_STRVAR(BPy_PointerProperty_doc,
+".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'}, update=None)\n"
"\n"
" Returns a new pointer property definition.\n"
"\n"
@@ -849,9 +1210,10 @@ static char BPy_PointerProperty_doc[] =
" :type type: class\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-;
+BPY_PROPDEF_UPDATE_DOC
+);
static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -859,7 +1221,7 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
BPY_PROPDEF_HEAD(PointerProperty)
if(srna) {
- static const char *kwlist[]= {"attr", "type", "name", "description", "options", NULL};
+ static const char *kwlist[]= {"attr", "type", "name", "description", "options", "update", NULL};
const char *id=NULL, *name="", *description="";
int id_len;
PropertyRNA *prop;
@@ -867,12 +1229,14 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
PyObject *type= Py_None;
PyObject *pyopts= NULL;
int opts=0;
+ PyObject *update_cb= NULL;
if (!PyArg_ParseTupleAndKeywords(args, kw,
- "s#O|ssO!:PointerProperty",
+ "s#O|ssO!O:PointerProperty",
(char **)kwlist, &id, &id_len,
&type, &name, &description,
- &PySet_Type, &pyopts))
+ &PySet_Type, &pyopts,
+ &update_cb))
{
return NULL;
}
@@ -883,17 +1247,22 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
if(!ptype)
return NULL;
+ if (bpy_prop_callback_check(update_cb, 2) == -1) {
+ return NULL;
+ }
+
prop= RNA_def_pointer_runtime(srna, id, ptype, name, description);
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
+ bpy_prop_callback_assign(prop, update_cb);
RNA_def_property_duplicate_pointers(srna, prop);
}
Py_RETURN_NONE;
}
-static char BPy_CollectionProperty_doc[] =
+PyDoc_STRVAR(BPy_CollectionProperty_doc,
".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
"\n"
" Returns a new collection property definition.\n"
@@ -902,9 +1271,9 @@ static char BPy_CollectionProperty_doc[] =
" :type type: class\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
-" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
+" :arg options: Enumerator in ['HIDDEN', 'SKIP_SAVE', 'ANIMATABLE'].\n"
" :type options: set\n"
-;
+);
static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -946,14 +1315,14 @@ static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject
Py_RETURN_NONE;
}
-static char BPy_RemoveProperty_doc[] =
+PyDoc_STRVAR(BPy_RemoveProperty_doc,
".. function:: RemoveProperty(attr)\n"
"\n"
" Removes a dynamically defined property.\n"
"\n"
" :arg attr: Property name.\n"
" :type attr: string\n"
-;
+);
static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -1025,7 +1394,7 @@ static struct PyModuleDef props_module= {
NULL, NULL, NULL, NULL
};
-PyObject *BPY_rna_props( void )
+PyObject *BPY_rna_props(void)
{
PyObject *submodule;
PyObject *submodule_dict;
diff --git a/source/blender/python/intern/bpy_props.h b/source/blender/python/intern/bpy_props.h
index f306d6898d1..8b64d04e092 100644
--- a/source/blender/python/intern/bpy_props.h
+++ b/source/blender/python/intern/bpy_props.h
@@ -30,7 +30,7 @@
#ifndef BPY_PROPS_H
#define BPY_PROPS_H
-PyObject *BPY_rna_props( void );
+PyObject *BPY_rna_props(void);
#define PYRNA_STACK_ARRAY 32
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 4f62c545a71..38cc3edd8f6 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -323,11 +323,20 @@ int pyrna_write_check(void)
{
return !rna_disallow_writes;
}
+
+void pyrna_write_set(int val)
+{
+ rna_disallow_writes= !val;
+}
#else // USE_PEDANTIC_WRITE
int pyrna_write_check(void)
{
return TRUE;
}
+void pyrna_write_set(int UNUSED(val))
+{
+ /* nothing */
+}
#endif // USE_PEDANTIC_WRITE
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self);
@@ -1200,7 +1209,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
return ret;
}
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
+PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
{
PyObject *ret;
int type= RNA_property_type(prop);
@@ -1334,7 +1343,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha
return error_val;
}
-static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
+static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
{
@@ -2527,16 +2536,18 @@ static PyMappingMethods pyrna_struct_as_mapping= {
(objobjargproc) pyrna_struct_ass_subscript, /* mp_ass_subscript */
};
-static char pyrna_struct_keys_doc[] =
+PyDoc_STRVAR(pyrna_struct_keys_doc,
".. method:: keys()\n"
"\n"
-" Returns the keys of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the keys of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property keys.\n"
" :rtype: list of strings\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes\n"
+" support custom properties.\n"
+);
static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2554,16 +2565,18 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
return BPy_Wrap_GetKeys(group);
}
-static char pyrna_struct_items_doc[] =
+PyDoc_STRVAR(pyrna_struct_items_doc,
".. method:: items()\n"
"\n"
-" Returns the items of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the items of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property key, value pairs.\n"
" :rtype: list of key, value tuples\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2581,16 +2594,18 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
return BPy_Wrap_GetItems(self->ptr.id.data, group);
}
-static char pyrna_struct_values_doc[] =
+PyDoc_STRVAR(pyrna_struct_values_doc,
".. method:: values()\n"
"\n"
-" Returns the values of this objects custom properties (matches pythons dictionary function of the same name).\n"
+" Returns the values of this objects custom properties (matches pythons\n"
+" dictionary function of the same name).\n"
"\n"
" :return: custom property values.\n"
" :rtype: list\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n";
-
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
{
IDProperty *group;
@@ -2609,14 +2624,14 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
}
-static char pyrna_struct_is_property_set_doc[] =
+PyDoc_STRVAR(pyrna_struct_is_property_set_doc,
".. method:: is_property_set(property)\n"
"\n"
" Check if a property is set, use for testing operator properties.\n"
"\n"
" :return: True when the property has been set.\n"
" :rtype: boolean\n"
-;
+);
static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *args)
{
PropertyRNA *prop;
@@ -2653,14 +2668,14 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg
return PyBool_FromLong(ret);
}
-static char pyrna_struct_is_property_hidden_doc[] =
+PyDoc_STRVAR(pyrna_struct_is_property_hidden_doc,
".. method:: is_property_hidden(property)\n"
"\n"
" Check if a property is hidden.\n"
"\n"
" :return: True when the property is hidden.\n"
" :rtype: boolean\n"
-;
+);
static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *args)
{
PropertyRNA *prop;
@@ -2681,16 +2696,17 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
return PyBool_FromLong(RNA_property_flag(prop) & PROP_HIDDEN);
}
-static char pyrna_struct_path_resolve_doc[] =
+PyDoc_STRVAR(pyrna_struct_path_resolve_doc,
".. method:: path_resolve(path, coerce=True)\n"
"\n"
" Returns the property from the path, raise an exception when not found.\n"
"\n"
" :arg path: path which this property resolves.\n"
" :type path: string\n"
-" :arg coerce: optional argument, when True, the property will be converted into its python representation.\n"
+" :arg coerce: optional argument, when True, the property will be converted\n"
+" into its python representation.\n"
" :type coerce: boolean\n"
-;
+);
static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
{
const char *path;
@@ -2738,16 +2754,18 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
}
}
-static char pyrna_struct_path_from_id_doc[] =
+PyDoc_STRVAR(pyrna_struct_path_from_id_doc,
".. method:: path_from_id(property=\"\")\n"
"\n"
" Returns the data path from the ID to this object (string).\n"
"\n"
-" :arg property: Optional property name which can be used if the path is to a property of this object.\n"
+" :arg property: Optional property name which can be used if the path is\n"
+" to a property of this object.\n"
" :type property: string\n"
-" :return: The path from :class:`bpy_struct.id_data` to this struct and property (when given).\n"
+" :return: The path from :class:`bpy_struct.id_data`\n"
+" to this struct and property (when given).\n"
" :rtype: str\n"
-;
+);
static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
{
const char *name= NULL;
@@ -2795,14 +2813,14 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
return ret;
}
-static char pyrna_prop_path_from_id_doc[] =
+PyDoc_STRVAR(pyrna_prop_path_from_id_doc,
".. method:: path_from_id()\n"
"\n"
" Returns the data path from the ID to this property (string).\n"
"\n"
" :return: The path from :class:`bpy_struct.id_data` to this property.\n"
" :rtype: str\n"
-;
+);
static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
{
const char *path;
@@ -2824,14 +2842,15 @@ static PyObject *pyrna_prop_path_from_id(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_struct_type_recast_doc[] =
+PyDoc_STRVAR(pyrna_struct_type_recast_doc,
".. method:: type_recast()\n"
"\n"
-" Return a new instance, this is needed because types such as textures can be changed at runtime.\n"
+" Return a new instance, this is needed because types\n"
+" such as textures can be changed at runtime.\n"
"\n"
" :return: a new instance of this object with the type initialized again.\n"
" :rtype: subclass of :class:`bpy_struct`\n"
-;
+);
static PyObject *pyrna_struct_type_recast(BPy_StructRNA *self)
{
PointerRNA r_ptr;
@@ -3091,7 +3110,7 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr
* >>> bpy.types.Scene.foo= BoolProperty()
* >>> bpy.types.Scene.foo
* <bpy_struct, BooleanProperty("foo")>
- * ...rather then returning the deferred class register tuple as checked by pyrna_is_deferred_prop()
+ * ...rather than returning the deferred class register tuple as checked by pyrna_is_deferred_prop()
*
* Disable for now, this is faking internal behavior in a way thats too tricky to maintain well. */
#if 0
@@ -3434,14 +3453,15 @@ static PyGetSetDef pyrna_struct_getseters[]= {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
-static char pyrna_prop_collection_keys_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_keys_doc,
".. method:: keys()\n"
"\n"
-" Return the identifiers of collection members (matching pythons dict.keys() functionality).\n"
+" Return the identifiers of collection members\n"
+" (matching pythons dict.keys() functionality).\n"
"\n"
" :return: the identifiers for each member of this collection.\n"
" :rtype: list of stings\n"
-;
+);
static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
{
PyObject *ret= PyList_New(0);
@@ -3467,14 +3487,15 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_prop_collection_items_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_items_doc,
".. method:: items()\n"
"\n"
-" Return the identifiers of collection members (matching pythons dict.items() functionality).\n"
+" Return the identifiers of collection members\n"
+" (matching pythons dict.items() functionality).\n"
"\n"
" :return: (key, value) pairs for each member of this collection.\n"
" :rtype: list of tuples\n"
-;
+);
static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
{
PyObject *ret= PyList_New(0);
@@ -3508,32 +3529,36 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
return ret;
}
-static char pyrna_prop_collection_values_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_values_doc,
".. method:: values()\n"
"\n"
-" Return the values of collection (matching pythons dict.values() functionality).\n"
+" Return the values of collection\n"
+" (matching pythons dict.values() functionality).\n"
"\n"
" :return: the members of this collection.\n"
" :rtype: list\n"
-;
+);
static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self)
{
/* re-use slice*/
return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
}
-static char pyrna_struct_get_doc[] =
+PyDoc_STRVAR(pyrna_struct_get_doc,
".. method:: get(key, default=None)\n"
"\n"
-" Returns the value of the custom property assigned to key or default when not found (matches pythons dictionary function of the same name).\n"
+" Returns the value of the custom property assigned to key or default\n"
+" when not found (matches pythons dictionary function of the same name).\n"
"\n"
" :arg key: The key assosiated with the custom property.\n"
" :type key: string\n"
-" :arg default: Optional argument for the value to return if *key* is not found.\n"
+" :arg default: Optional argument for the value to return if\n"
+" *key* is not found.\n"
" :type default: Undefined\n"
"\n"
-" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone` classes support custom properties.\n"
-;
+" .. note:: Only :class:`ID`, :class:`Bone` and :class:`PoseBone`\n"
+" classes support custom properties.\n"
+);
static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
{
IDProperty *group, *idprop;
@@ -3563,7 +3588,7 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
return Py_INCREF(def), def;
}
-static char pyrna_struct_as_pointer_doc[] =
+PyDoc_STRVAR(pyrna_struct_as_pointer_doc,
".. method:: as_pointer()\n"
"\n"
" Returns the memory address which holds a pointer to blenders internal data\n"
@@ -3571,23 +3596,26 @@ static char pyrna_struct_as_pointer_doc[] =
" :return: int (memory address).\n"
" :rtype: int\n"
"\n"
-" .. note:: This is intended only for advanced script writers who need to pass blender data to their own C/Python modules.\n"
-;
+" .. note:: This is intended only for advanced script writers who need to\n"
+" pass blender data to their own C/Python modules.\n"
+);
static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self)
{
return PyLong_FromVoidPtr(self->ptr.data);
}
-static char pyrna_prop_collection_get_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_get_doc,
".. method:: get(key, default=None)\n"
"\n"
-" Returns the value of the item assigned to key or default when not found (matches pythons dictionary function of the same name).\n"
+" Returns the value of the item assigned to key or default when not found\n"
+" (matches pythons dictionary function of the same name).\n"
"\n"
" :arg key: The identifier for the collection member.\n"
" :type key: string\n"
-" :arg default: Optional argument for the value to return if *key* is not found.\n"
+" :arg default: Optional argument for the value to return if\n"
+" *key* is not found.\n"
" :type default: Undefined\n"
-;
+);
static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args)
{
PointerRNA newptr;
@@ -3851,7 +3879,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
Py_RETURN_NONE;
}
-static char pyrna_prop_collection_foreach_get_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_foreach_get_doc,
".. method:: foreach_get(attr, seq)\n"
"\n"
" This is a function to give fast access to attributes within a collection.\n"
@@ -3863,7 +3891,7 @@ static char pyrna_prop_collection_foreach_get_doc[] =
" # Python equivalent\n"
" for i in range(len(seq)): someseq[i]= getattr(collection, attr)\n"
"\n"
-;
+);
static PyObject *pyrna_prop_collection_foreach_get(BPy_PropertyRNA *self, PyObject *args)
{
PYRNA_PROP_CHECK_OBJ(self)
@@ -3871,7 +3899,7 @@ static PyObject *pyrna_prop_collection_foreach_get(BPy_PropertyRNA *self, PyObje
return foreach_getset(self, args, 0);
}
-static char pyrna_prop_collection_foreach_set_doc[] =
+PyDoc_STRVAR(pyrna_prop_collection_foreach_set_doc,
".. method:: foreach_set(attr, seq)\n"
"\n"
" This is a function to give fast access to attributes within a collection.\n"
@@ -3883,7 +3911,7 @@ static char pyrna_prop_collection_foreach_set_doc[] =
" # Python equivalent\n"
" for i in range(len(seq)): setattr(collection[i], attr, seq[i])\n"
"\n"
-;
+);
static PyObject *pyrna_prop_collection_foreach_set(BPy_PropertyRNA *self, PyObject *args)
{
PYRNA_PROP_CHECK_OBJ(self)
@@ -5498,7 +5526,7 @@ PyObject *BPY_rna_module(void)
BPy_StructRNA *pyrna;
PointerRNA ptr;
- /* for now, return the base RNA type rather then a real module */
+ /* for now, return the base RNA type rather than a real module */
RNA_main_pointer_create(G.main, &ptr);
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
@@ -5518,7 +5546,7 @@ PyObject *BPY_rna_doc(void)
{
PointerRNA ptr;
- /* for now, return the base RNA type rather then a real module */
+ /* for now, return the base RNA type rather than a real module */
RNA_blender_rna_pointer_create(&ptr);
return pyrna_struct_CreatePyObject(&ptr);
@@ -5863,7 +5891,6 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
PyObject *py_class= (PyObject*)py_data;
PyObject *base_class= RNA_struct_py_type_get(srna);
PyObject *item;
- PyObject *py_arg_count;
int i, flag, arg_count, func_arg_count;
const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__
@@ -5926,9 +5953,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
func_arg_count= rna_function_arg_count(func);
if (func_arg_count >= 0) { /* -1 if we dont care*/
- py_arg_count= PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
- arg_count= PyLong_AsLong(py_arg_count);
- Py_DECREF(py_arg_count);
+ arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
/* note, the number of args we check for and the number of args we give to
* @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/
@@ -6359,16 +6384,20 @@ void pyrna_free_types(void)
* the decref. This is not so bad because the leak only happens when re-registering (hold F8)
* - Should still be fixed - Campbell
* */
-static char pyrna_register_class_doc[] =
+PyDoc_STRVAR(pyrna_register_class_doc,
".. method:: register_class(cls)\n"
"\n"
-" Register a subclass of a blender type in (:class:`Panel`, :class:`Menu`, :class:`Header`, :class:`Operator`, :class:`KeyingSetInfo`, :class:`RenderEngine`).\n"
+" Register a subclass of a blender type in (:class:`Panel`,\n"
+" :class:`Menu`, :class:`Header`, :class:`Operator`,\n"
+" :class:`KeyingSetInfo`, :class:`RenderEngine`).\n"
"\n"
-" If the class has a *register* class method it will be called before registration.\n"
+" If the class has a *register* class method it will be called\n"
+" before registration.\n"
"\n"
-" .. note:: :exc:`ValueError` exception is raised if the class is not a subclass of a registerable blender class.\n"
+" .. note:: :exc:`ValueError` exception is raised if the class is not a\n"
+" subclass of a registerable blender class.\n"
"\n"
-;
+);
PyMethodDef meth_bpy_register_class= {"register_class", pyrna_register_class, METH_O, pyrna_register_class_doc};
static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class)
{
@@ -6487,13 +6516,14 @@ static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRN
return 0;
}
-static char pyrna_unregister_class_doc[] =
+PyDoc_STRVAR(pyrna_unregister_class_doc,
".. method:: unregister_class(cls)\n"
"\n"
" Unload the python class from blender.\n"
"\n"
-" If the class has an *unregister* class method it will be called before unregistering.\n"
-;
+" If the class has an *unregister* class method it will be called\n"
+" before unregistering.\n"
+);
PyMethodDef meth_bpy_unregister_class= {"unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc};
static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_class)
{
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 28459677b32..5db352af53d 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -44,7 +44,7 @@
/* support for inter references, currently only needed for corner case */
#define USE_PYRNA_STRUCT_REFERENCE
-/* use real collection iterators rather then faking with a list */
+/* use real collection iterators rather than faking with a list */
#define USE_PYRNA_ITER
#else /* WITH_PYTHON_SAFETY */
@@ -148,18 +148,18 @@ typedef struct {
StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix);
-void BPY_rna_init( void );
-PyObject *BPY_rna_module( void );
-void BPY_update_rna_module( void );
-/*PyObject *BPY_rna_doc( void );*/
-PyObject *BPY_rna_types( void );
+void BPY_rna_init(void);
+PyObject *BPY_rna_module(void);
+void BPY_update_rna_module(void);
+/*PyObject *BPY_rna_doc(void);*/
+PyObject *BPY_rna_types(void);
-PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
-PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
+PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr);
+PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop);
/* operators also need this to set args */
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
+PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
@@ -183,6 +183,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);
int pyrna_write_check(void);
+void pyrna_write_set(int val);
int pyrna_struct_validity_check(BPy_StructRNA *pysrna);
int pyrna_prop_validity_check(BPy_PropertyRNA *self);