From 5ea992df98d152f83072e886a0b1f9464a4883d6 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 18 Jun 2009 14:20:25 +0000 Subject: [PATCH 1/8] UI: * Fix context.cloth, was not being set correct. * Fix errors with context pinning, scripts should not assume context.object to be there. * Always show preview even if e.g. the material is not set, to keep ID buttons from jumping while you're using them. --- release/ui/buttons_data_armature.py | 4 ++-- release/ui/buttons_data_camera.py | 4 ++-- release/ui/buttons_data_curve.py | 6 +++--- release/ui/buttons_data_empty.py | 4 ++-- release/ui/buttons_data_lamp.py | 4 ++-- release/ui/buttons_data_lattice.py | 4 ++-- release/ui/buttons_data_mesh.py | 4 ++-- release/ui/buttons_data_text.py | 4 ++-- release/ui/buttons_material.py | 7 +++++-- release/ui/buttons_physic_cloth.py | 6 +++--- release/ui/buttons_texture.py | 5 ++++- release/ui/buttons_world.py | 5 ++++- source/blender/editors/space_buttons/buttons_context.c | 10 ++++++++-- 13 files changed, 41 insertions(+), 26 deletions(-) diff --git a/release/ui/buttons_data_armature.py b/release/ui/buttons_data_armature.py index 1086e77c3f7..c536f6bb87d 100644 --- a/release/ui/buttons_data_armature.py +++ b/release/ui/buttons_data_armature.py @@ -14,7 +14,7 @@ class DATA_PT_skeleton(DataButtonsPanel): __label__ = "Skeleton" def poll(self, context): - return (context.object.type == 'ARMATURE' or context.armature) + return ((context.object and context.object.type == 'ARMATURE') or context.armature) def draw(self, context): layout = self.layout @@ -127,4 +127,4 @@ class DATA_PT_ghost(DataButtonsPanel): bpy.types.register(DATA_PT_skeleton) bpy.types.register(DATA_PT_display) bpy.types.register(DATA_PT_paths) -bpy.types.register(DATA_PT_ghost) \ No newline at end of file +bpy.types.register(DATA_PT_ghost) diff --git a/release/ui/buttons_data_camera.py b/release/ui/buttons_data_camera.py index 57abafb95c8..db2a1f9db25 100644 --- a/release/ui/buttons_data_camera.py +++ b/release/ui/buttons_data_camera.py @@ -14,7 +14,7 @@ class DATA_PT_camera(DataButtonsPanel): __label__ = "Lens" def poll(self, context): - return (context.object.type == 'CAMERA') + return (context.object and context.object.type == 'CAMERA') def draw(self, context): layout = self.layout @@ -87,4 +87,4 @@ class DATA_PT_camera_display(DataButtonsPanel): col.itemR(cam, "draw_size", text="Size") bpy.types.register(DATA_PT_camera) -bpy.types.register(DATA_PT_camera_display) \ No newline at end of file +bpy.types.register(DATA_PT_camera_display) diff --git a/release/ui/buttons_data_curve.py b/release/ui/buttons_data_curve.py index f42c991a36f..869d29802e1 100644 --- a/release/ui/buttons_data_curve.py +++ b/release/ui/buttons_data_curve.py @@ -7,14 +7,14 @@ class DataButtonsPanel(bpy.types.Panel): __context__ = "data" def poll(self, context): - return (context.object.type == 'CURVE' and context.curve) + return (context.object and context.object.type == 'CURVE' and context.curve) class DATA_PT_shape_curve(DataButtonsPanel): __idname__ = "DATA_PT_shape_curve" __label__ = "Shape" def poll(self, context): - return (context.object.type == 'CURVE') + return (context.object and context.object.type == 'CURVE') def draw(self, context): layout = self.layout @@ -144,4 +144,4 @@ class DATA_PT_current_curve(DataButtonsPanel): bpy.types.register(DATA_PT_shape_curve) bpy.types.register(DATA_PT_geometry) bpy.types.register(DATA_PT_pathanim) -bpy.types.register(DATA_PT_current_curve) \ No newline at end of file +bpy.types.register(DATA_PT_current_curve) diff --git a/release/ui/buttons_data_empty.py b/release/ui/buttons_data_empty.py index 7eed54d1db6..f97dedcf6cf 100644 --- a/release/ui/buttons_data_empty.py +++ b/release/ui/buttons_data_empty.py @@ -7,7 +7,7 @@ class DataButtonsPanel(bpy.types.Panel): __context__ = "data" def poll(self, context): - return (context.object.type == 'EMPTY') + return (context.object and context.object.type == 'EMPTY') class DATA_PT_empty(DataButtonsPanel): __idname__ = "DATA_PT_empty" @@ -20,4 +20,4 @@ class DATA_PT_empty(DataButtonsPanel): layout.itemR(ob, "empty_draw_type") layout.itemR(ob, "empty_draw_size") -bpy.types.register(DATA_PT_empty) \ No newline at end of file +bpy.types.register(DATA_PT_empty) diff --git a/release/ui/buttons_data_lamp.py b/release/ui/buttons_data_lamp.py index 7328abc7c35..52a60ce617e 100644 --- a/release/ui/buttons_data_lamp.py +++ b/release/ui/buttons_data_lamp.py @@ -24,7 +24,7 @@ class DATA_PT_lamp(DataButtonsPanel): __label__ = "Lamp" def poll(self, context): - return (context.object.type == 'LAMP') + return ((context.object and context.object.type == 'LAMP') or context.lamp) def draw(self, context): layout = self.layout @@ -249,4 +249,4 @@ bpy.types.register(DATA_PT_lamp) bpy.types.register(DATA_PT_shadow) bpy.types.register(DATA_PT_sunsky) bpy.types.register(DATA_PT_spot) -bpy.types.register(DATA_PT_falloff_curve) \ No newline at end of file +bpy.types.register(DATA_PT_falloff_curve) diff --git a/release/ui/buttons_data_lattice.py b/release/ui/buttons_data_lattice.py index 9382ee3525c..ad9b1b518b8 100644 --- a/release/ui/buttons_data_lattice.py +++ b/release/ui/buttons_data_lattice.py @@ -14,7 +14,7 @@ class DATA_PT_lattice(DataButtonsPanel): __label__ = "Lattice" def poll(self, context): - return (context.object.type == 'LATTICE') + return (context.object and context.object.type == 'LATTICE') def draw(self, context): layout = self.layout @@ -51,4 +51,4 @@ class DATA_PT_lattice(DataButtonsPanel): row.itemR(lat, "outside") row.itemR(lat, "shape_keys") -bpy.types.register(DATA_PT_lattice) \ No newline at end of file +bpy.types.register(DATA_PT_lattice) diff --git a/release/ui/buttons_data_mesh.py b/release/ui/buttons_data_mesh.py index 5e4fb203944..c103a0f7055 100644 --- a/release/ui/buttons_data_mesh.py +++ b/release/ui/buttons_data_mesh.py @@ -14,7 +14,7 @@ class DATA_PT_mesh(DataButtonsPanel): __label__ = "Mesh" def poll(self, context): - return (context.object.type == 'MESH') + return (context.object and context.object.type == 'MESH') def draw(self, context): layout = self.layout @@ -48,4 +48,4 @@ class DATA_PT_mesh(DataButtonsPanel): layout.itemR(mesh, "texco_mesh") -bpy.types.register(DATA_PT_mesh) \ No newline at end of file +bpy.types.register(DATA_PT_mesh) diff --git a/release/ui/buttons_data_text.py b/release/ui/buttons_data_text.py index d6f6feaa389..bce16e78a40 100644 --- a/release/ui/buttons_data_text.py +++ b/release/ui/buttons_data_text.py @@ -7,7 +7,7 @@ class DataButtonsPanel(bpy.types.Panel): __context__ = "data" def poll(self, context): - return (context.object.type == 'TEXT' and context.curve) + return (context.object and context.object.type == 'TEXT' and context.curve) class DATA_PT_shape_text(DataButtonsPanel): __idname__ = "DATA_PT_shape_text" @@ -15,7 +15,7 @@ class DATA_PT_shape_text(DataButtonsPanel): def poll(self, context): ob = context.object - return (context.object.type == 'TEXT') + return (context.object and context.object.type == 'TEXT') def draw(self, context): layout = self.layout diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index b7703bca94e..124fba83608 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -13,6 +13,9 @@ class MATERIAL_PT_preview(MaterialButtonsPanel): __idname__= "MATERIAL_PT_preview" __label__ = "Preview" + def poll(self, context): + return (context.material or context.material_slot) + def draw(self, context): layout = self.layout mat = context.material @@ -24,7 +27,7 @@ class MATERIAL_PT_material(MaterialButtonsPanel): __label__ = "Material" def poll(self, context): - return (context.object != None) + return (context.material or context.material_slot) def draw(self, context): layout = self.layout @@ -419,4 +422,4 @@ bpy.types.register(MATERIAL_PT_raytransp) bpy.types.register(MATERIAL_PT_sss) bpy.types.register(MATERIAL_PT_halo) bpy.types.register(MATERIAL_PT_strand) -bpy.types.register(MATERIAL_PT_options) \ No newline at end of file +bpy.types.register(MATERIAL_PT_options) diff --git a/release/ui/buttons_physic_cloth.py b/release/ui/buttons_physic_cloth.py index 09c21b4eb64..bd65392ad63 100644 --- a/release/ui/buttons_physic_cloth.py +++ b/release/ui/buttons_physic_cloth.py @@ -50,13 +50,13 @@ class Physic_PT_cloth_collision(PhysicButtonsPanel): def draw_header(self, context): layout = self.layout - cloth = context.cloth.settings + cloth = context.cloth.collision_settings layout.itemR(cloth, "enable_collision", text="") def draw(self, context): layout = self.layout - cloth = context.cloth.settings + cloth = context.cloth.collision_settings layout.active = cloth.enable_collision @@ -103,4 +103,4 @@ class Physic_PT_cloth_stiffness(PhysicButtonsPanel): bpy.types.register(Physic_PT_cloth) bpy.types.register(Physic_PT_cloth_collision) -bpy.types.register(Physic_PT_cloth_stiffness) \ No newline at end of file +bpy.types.register(Physic_PT_cloth_stiffness) diff --git a/release/ui/buttons_texture.py b/release/ui/buttons_texture.py index 286c1240d0e..de166cef796 100644 --- a/release/ui/buttons_texture.py +++ b/release/ui/buttons_texture.py @@ -13,6 +13,9 @@ class TEXTURE_PT_preview(TextureButtonsPanel): __idname__= "TEXTURE_PT_preview" __label__ = "Preview" + def poll(self, context): + return (context.material or context.world or context.lamp or context.texture) + def draw(self, context): layout = self.layout tex = context.texture @@ -24,7 +27,7 @@ class TEXTURE_PT_texture(TextureButtonsPanel): __label__ = "Texture" def poll(self, context): - return (context.material or context.world or context.lamp) + return (context.material or context.world or context.lamp or context.texture) def draw(self, context): layout = self.layout diff --git a/release/ui/buttons_world.py b/release/ui/buttons_world.py index 647ef8aa65e..d9516cb7900 100644 --- a/release/ui/buttons_world.py +++ b/release/ui/buttons_world.py @@ -12,6 +12,9 @@ class WorldButtonsPanel(bpy.types.Panel): class WORLD_PT_preview(WorldButtonsPanel): __label__ = "Preview" + def poll(self, context): + return (context.scene or context.world) + def draw(self, context): layout = self.layout world = context.world @@ -176,4 +179,4 @@ bpy.types.register(WORLD_PT_world) bpy.types.register(WORLD_PT_ambient_occlusion) bpy.types.register(WORLD_PT_mist) bpy.types.register(WORLD_PT_stars) -bpy.types.register(WORLD_PT_color_correction) \ No newline at end of file +bpy.types.register(WORLD_PT_color_correction) diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 255bee1bf5a..42180e7902f 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -574,8 +574,14 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r return 1; } else if(CTX_data_equals(member, "cloth")) { - set_pointer_type(path, result, &RNA_ClothModifier); - return 1; + PointerRNA *ptr= get_pointer_type(path, &RNA_Object); + + if(ptr && ptr->data) { + Object *ob= ptr->data; + ModifierData *md= modifiers_findByType(ob, eModifierType_Cloth); + CTX_data_pointer_set(result, &ob->id, &RNA_ClothModifier, md); + return 1; + } } else if(CTX_data_equals(member, "soft_body")) { PointerRNA *ptr= get_pointer_type(path, &RNA_Object); From 8130fb29b2a80a795fd891d2c9a74f86993221e2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 18 Jun 2009 14:29:24 +0000 Subject: [PATCH 2/8] RNA: * Make cloth settings animateable from buttons. --- source/blender/makesrna/intern/rna_cloth.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index 919ae210801..361c1b61303 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -31,6 +31,8 @@ #include "rna_internal.h" #include "BKE_cloth.h" +#include "BKE_modifier.h" + #include "DNA_cloth_types.h" #ifdef RNA_RUNTIME @@ -129,6 +131,22 @@ static void rna_ClothSettings_gravity_set(PointerRNA *ptr, const float *values) sim->gravity[2]= values[2]; } +static char *rna_ClothSettings_path(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + ModifierData *md= modifiers_findByType(ob, eModifierType_Cloth); + + return BLI_sprintfN("modifiers[%s].settings", md->name); +} + +static char *rna_ClothCollisionSettings_path(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + ModifierData *md= modifiers_findByType(ob, eModifierType_Cloth); + + return BLI_sprintfN("modifiers[%s].collision_settings", md->name); +} + #else static void rna_def_cloth_sim_settings(BlenderRNA *brna) @@ -139,6 +157,7 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna) srna = RNA_def_struct(brna, "ClothSettings", NULL); RNA_def_struct_ui_text(srna, "Cloth Settings", "Cloth simulation settings for an object."); RNA_def_struct_sdna(srna, "ClothSimSettings"); + RNA_def_struct_path_func(srna, "rna_ClothSettings_path"); /* goal */ @@ -297,6 +316,7 @@ static void rna_def_cloth_collision_settings(BlenderRNA *brna) srna = RNA_def_struct(brna, "ClothCollisionSettings", NULL); RNA_def_struct_ui_text(srna, "Cloth Collision Settings", "Cloth simulation settings for self collision and collision with other objects."); RNA_def_struct_sdna(srna, "ClothCollSettings"); + RNA_def_struct_path_func(srna, "rna_ClothCollisionSettings_path"); /* general collision */ From 2f48d0b46bc76e0f06cf499cf51aa833340a6c04 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Thu, 18 Jun 2009 15:31:14 +0000 Subject: [PATCH 3/8] Added Make for new python/generic dir. Also included GLEW. --- source/blender/python/Makefile | 2 +- source/blender/python/generic/Makefile | 66 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 source/blender/python/generic/Makefile diff --git a/source/blender/python/Makefile b/source/blender/python/Makefile index c830fbb3ccf..0c4b9ab6578 100644 --- a/source/blender/python/Makefile +++ b/source/blender/python/Makefile @@ -29,6 +29,6 @@ # Bounces make to subdirectories. SOURCEDIR = source/blender/python -DIRS = intern +DIRS = intern generic include nan_subdirs.mk diff --git a/source/blender/python/generic/Makefile b/source/blender/python/generic/Makefile new file mode 100644 index 00000000000..6e8e5bc1d2e --- /dev/null +++ b/source/blender/python/generic/Makefile @@ -0,0 +1,66 @@ +# +# $Id: Makefile 11904 2007-08-31 16:16:33Z sirdude $ +# +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL LICENSE BLOCK ***** +# +# + +LIBNAME = python +DIR = $(OCGDIR)/blender/$(LIBNAME) + +include nan_compile.mk + +CFLAGS += $(LEVEL_1_C_WARNINGS) + +# OpenGL and Python +CPPFLAGS += -I$(NAN_GLEW)/include +CPPFLAGS += $(OGL_CPPFLAGS) +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) + +# PreProcessor stuff + +CPPFLAGS += -I$(NAN_GHOST)/include +CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include $(NAN_SDLCFLAGS) + +# modules +CPPFLAGS += -I../../editors/include +CPPFLAGS += -I../../python +CPPFLAGS += -I../../makesdna +CPPFLAGS += -I../../makesrna +CPPFLAGS += -I../../blenlib +CPPFLAGS += -I../../blenkernel +CPPFLAGS += -I../../nodes +CPPFLAGS += -I../../imbuf +CPPFLAGS += -I../../blenloader +CPPFLAGS += -I../../windowmanager +CPPFLAGS += -I../../render/extern/include + +# path to the guarded memory allocator +CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include +CPPFLAGS += -I$(NAN_MEMUTIL)/include + +# path to our own headerfiles +CPPFLAGS += -I.. From 122b206de35b72cd65934a3183331a93674559a2 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Thu, 18 Jun 2009 15:33:58 +0000 Subject: [PATCH 4/8] Fixing gl/glw.h compiiler error --- source/blender/python/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript index c974ebe1092..4b62c912d34 100644 --- a/source/blender/python/SConscript +++ b/source/blender/python/SConscript @@ -5,7 +5,7 @@ sources = env.Glob('intern/*.c') incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes' incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager' -incs += ' #intern/guardedalloc #intern/memutil' +incs += ' #intern/guardedalloc #intern/memutil #/extern/glew/include' incs += ' ' + env['BF_PYTHON_INC'] defs = [] From 025b6dcbc3f6303e051354cbfb694ee810934979 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 18 Jun 2009 17:34:39 +0000 Subject: [PATCH 5/8] fix for building with py2.3 --- source/blender/python/generic/BGL.h | 1 + source/blender/python/generic/Mathutils.h | 1 + .../python/generic/bpy_internal_import.h | 1 + source/blender/python/generic/euler.h | 1 + source/blender/python/generic/quat.h | 1 + source/blender/python/generic/vector.h | 1 + source/blender/python/intern/bpy_compat.h | 18 ++++++++++++++++++ source/gameengine/Expressions/ListValue.cpp | 1 + 8 files changed, 25 insertions(+) diff --git a/source/blender/python/generic/BGL.h b/source/blender/python/generic/BGL.h index 345536d64be..0e82ddf6d29 100755 --- a/source/blender/python/generic/BGL.h +++ b/source/blender/python/generic/BGL.h @@ -41,6 +41,7 @@ #endif #include +#include "../intern/bpy_compat.h" #include "BIF_gl.h" PyObject *BGL_Init( const char *from ); diff --git a/source/blender/python/generic/Mathutils.h b/source/blender/python/generic/Mathutils.h index 4c8153e5e54..173922fe09a 100644 --- a/source/blender/python/generic/Mathutils.h +++ b/source/blender/python/generic/Mathutils.h @@ -32,6 +32,7 @@ #define EXPP_Mathutils_H #include +#include "../intern/bpy_compat.h" #include "vector.h" #include "matrix.h" #include "quat.h" diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h index 9c3ce572cc4..475ec8dd118 100644 --- a/source/blender/python/generic/bpy_internal_import.h +++ b/source/blender/python/generic/bpy_internal_import.h @@ -32,6 +32,7 @@ #define EXPP_bpy_import_h #include +#include "../intern/bpy_compat.h" #include "compile.h" /* for the PyCodeObject */ #include "eval.h" /* for PyEval_EvalCode */ diff --git a/source/blender/python/generic/euler.h b/source/blender/python/generic/euler.h index f94f060a61d..773b024f174 100644 --- a/source/blender/python/generic/euler.h +++ b/source/blender/python/generic/euler.h @@ -32,6 +32,7 @@ #define EXPP_euler_h #include +#include "../intern/bpy_compat.h" extern PyTypeObject euler_Type; diff --git a/source/blender/python/generic/quat.h b/source/blender/python/generic/quat.h index f98665ded55..8a4602c1d8e 100644 --- a/source/blender/python/generic/quat.h +++ b/source/blender/python/generic/quat.h @@ -32,6 +32,7 @@ #define EXPP_quat_h #include +#include "../intern/bpy_compat.h" extern PyTypeObject quaternion_Type; diff --git a/source/blender/python/generic/vector.h b/source/blender/python/generic/vector.h index e53a0c1f24b..930e987fcc7 100644 --- a/source/blender/python/generic/vector.h +++ b/source/blender/python/generic/vector.h @@ -31,6 +31,7 @@ #define EXPP_vector_h #include +#include "../intern/bpy_compat.h" extern PyTypeObject vector_Type; diff --git a/source/blender/python/intern/bpy_compat.h b/source/blender/python/intern/bpy_compat.h index ad6b7a5e85c..3a2d4bda84c 100644 --- a/source/blender/python/intern/bpy_compat.h +++ b/source/blender/python/intern/bpy_compat.h @@ -88,6 +88,24 @@ typedef Py_ssize_t (*lenfunc)(PyObject *); #endif +#ifndef ssizeargfunc +#define ssizeargfunc intargfunc +#endif + +#ifndef ssizessizeargfunc +#define ssizessizeargfunc intintargfunc +#endif + +#ifndef ssizeobjargproc +#define ssizeobjargproc intobjargproc +#endif + +#ifndef ssizessizeobjargproc +#define ssizessizeobjargproc intintobjargproc +#endif + + + /* defined in bpy_util.c */ #if PY_VERSION_HEX < 0x03000000 PyObject *Py_CmpToRich(int op, int cmp); diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index ea097ddff5b..d3df36fbff0 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -18,6 +18,7 @@ #include "StringValue.h" #include "VoidValue.h" #include +#include #include "BoolValue.h" #ifdef HAVE_CONFIG_H From 89d2559e6dbde26acdd45e3fe9d6eff2c62d98c0 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 18 Jun 2009 19:25:58 +0000 Subject: [PATCH 6/8] 2.5 * Update cmake and makefiles to link python generic. * Fix game engine building for cmake and makefiles. * Fix compile error with py 3.x, due to 2.x compat fix. --- source/Makefile | 1 + source/blender/python/SConscript | 2 +- source/blender/python/generic/BGL.h | 2 +- source/blender/python/generic/Makefile | 2 +- source/blender/python/intern/Makefile | 1 + source/blender/python/intern/bpy_compat.h | 2 ++ source/creator/CMakeLists.txt | 2 ++ source/gameengine/Converter/CMakeLists.txt | 1 + source/gameengine/Converter/Makefile | 1 + source/gameengine/Ketsji/CMakeLists.txt | 3 ++- source/gameengine/Ketsji/Makefile | 2 +- 11 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/Makefile b/source/Makefile index 94446f4d1d5..2df57f58c73 100644 --- a/source/Makefile +++ b/source/Makefile @@ -162,6 +162,7 @@ COMLIB += $(OCGDIR)/blender/makesdna/$(DEBUG_DIR)libdna.a COMLIB += $(NAN_GUARDEDALLOC)/lib/libguardedalloc.a COMLIB += $(NAN_MEMUTIL)/lib/libmemutil.a COMLIB += $(NAN_PNG)/lib/libpng.a +COMLIB += $(OCGDIR)/blender/gen_python/$(DEBUG_DIR)libgen_python.a ifeq ($(WITH_QUICKTIME), true) COMLIB += $(OCGDIR)/blender/blenderqt/$(DEBUG_DIR)libblenderqt.a diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript index 4b62c912d34..73dc171fc3e 100644 --- a/source/blender/python/SConscript +++ b/source/blender/python/SConscript @@ -5,7 +5,7 @@ sources = env.Glob('intern/*.c') incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes' incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager' -incs += ' #intern/guardedalloc #intern/memutil #/extern/glew/include' +incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include' incs += ' ' + env['BF_PYTHON_INC'] defs = [] diff --git a/source/blender/python/generic/BGL.h b/source/blender/python/generic/BGL.h index 0e82ddf6d29..e2d1b0bb495 100755 --- a/source/blender/python/generic/BGL.h +++ b/source/blender/python/generic/BGL.h @@ -41,8 +41,8 @@ #endif #include +#include #include "../intern/bpy_compat.h" -#include "BIF_gl.h" PyObject *BGL_Init( const char *from ); diff --git a/source/blender/python/generic/Makefile b/source/blender/python/generic/Makefile index 6e8e5bc1d2e..20cf7f19ec7 100644 --- a/source/blender/python/generic/Makefile +++ b/source/blender/python/generic/Makefile @@ -28,7 +28,7 @@ # # -LIBNAME = python +LIBNAME = gen_python DIR = $(OCGDIR)/blender/$(LIBNAME) include nan_compile.mk diff --git a/source/blender/python/intern/Makefile b/source/blender/python/intern/Makefile index 3e28f5aac31..0c4a540a4bd 100644 --- a/source/blender/python/intern/Makefile +++ b/source/blender/python/intern/Makefile @@ -37,6 +37,7 @@ CFLAGS += $(LEVEL_1_C_WARNINGS) # OpenGL and Python CPPFLAGS += $(OGL_CPPFLAGS) +CPPFLAGS += -I$(NAN_GLEW)/include CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) # PreProcessor stuff diff --git a/source/blender/python/intern/bpy_compat.h b/source/blender/python/intern/bpy_compat.h index 3a2d4bda84c..1ad9376c13b 100644 --- a/source/blender/python/intern/bpy_compat.h +++ b/source/blender/python/intern/bpy_compat.h @@ -88,6 +88,7 @@ typedef Py_ssize_t (*lenfunc)(PyObject *); #endif +#if PY_VERSION_HEX < 0x03000000 #ifndef ssizeargfunc #define ssizeargfunc intargfunc #endif @@ -103,6 +104,7 @@ typedef Py_ssize_t (*lenfunc)(PyObject *); #ifndef ssizessizeobjargproc #define ssizessizeobjargproc intintobjargproc #endif +#endif diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 221c0a92e09..4701eba810f 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -221,6 +221,7 @@ IF(UNIX) blender_radiosity blender_ONL bf_python + bf_gen_python bf_blenkernel bf_nodes bf_gpu @@ -269,6 +270,7 @@ IF(UNIX) extern_qhull bf_moto bf_python + bf_gen_python bf_quicktime extern_binreloc extern_glew diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt index 44692241e6f..031c2234ea8 100644 --- a/source/gameengine/Converter/CMakeLists.txt +++ b/source/gameengine/Converter/CMakeLists.txt @@ -49,6 +49,7 @@ SET(INC ../../../source/blender ../../../source/blender/include ../../../source/blender/makesdna + ../../../source/blender/makesrna ../../../source/gameengine/Rasterizer ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer ../../../source/gameengine/GameLogic diff --git a/source/gameengine/Converter/Makefile b/source/gameengine/Converter/Makefile index 938994e8b62..abded70f289 100644 --- a/source/gameengine/Converter/Makefile +++ b/source/gameengine/Converter/Makefile @@ -48,6 +48,7 @@ CPPFLAGS += -I../../blender CPPFLAGS += -I../../blender/windowmanager CPPFLAGS += -I../../blender/imbuf CPPFLAGS += -I../../blender/makesdna +CPPFLAGS += -I../../blender/makesrna CPPFLAGS += -I../../blender/editors/include CPPFLAGS += -I../../blender/blenlib CPPFLAGS += -I../../blender/blenkernel diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4aaa49a8493..ee1ff2c6502 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -53,7 +53,8 @@ SET(INC ../../../source/gameengine/Ketsji ../../../source/blender/blenlib ../../../source/blender/blenkernel - ../../../source/blender/python/api2_2x + ../../../source/blender/python + ../../../source/blender/python/generic ../../../source/blender ../../../source/blender/include ../../../source/blender/makesdna diff --git a/source/gameengine/Ketsji/Makefile b/source/gameengine/Ketsji/Makefile index bdc0b335b02..59b3ff178fb 100644 --- a/source/gameengine/Ketsji/Makefile +++ b/source/gameengine/Ketsji/Makefile @@ -41,7 +41,7 @@ CPPFLAGS += -I$(NAN_GLEW)/include CPPFLAGS += -I$(OPENGL_HEADERS) CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) CPPFLAGS += -I../../blender/python -CPPFLAGS += -I../../blender/python/api2_2x +CPPFLAGS += -I../../blender/python/generic CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include CPPFLAGS += -I$(NAN_FUZZICS)/include -I$(NAN_SUMO) -I$(NAN_MOTO)/include From 4cd24cf05809557e0d620dccf1f19a570784f6fe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 18 Jun 2009 19:48:55 +0000 Subject: [PATCH 7/8] RNA Merging changes made by Arystanbek in the soc-2009-kazanbas branch, plus some things modified and added by me. * The API files now all in the makesrna module, convention is to call them e.g. rna_mesh_api.c for rna_mesh.c. Note for visual studio build maintainers, the rna_*_api.c files are compiled as part of "makesrna", but do not have rna_*_gen.c generated as part of the library. SCons/cmake/make were updated. * Added function flags FUNC_USE_CONTEXT and FUNC_USE_REPORTS, to allow RNA functions to get context and error reporting parameters optionally. Renamed FUNC_TYPESTATIC to FUNC_NO_SELF. * RNA collections now have a pointer to add/remove FunctionRNA's, this isn't actually used anywhere yet, purpose is to make an alias main.meshes.add() for main.add_mesh() in python. * Fixes to make autogenerating property set/get for multidimensional arrays work, though a 4x4 matrix will be exposed as a length 16 one dimensional RNA array. * Functions and properties added: * Main.add_mesh() * Main.remove_mesh() * Object.matrix * Object.create_render_mesh() * WindowManager.add_fileselect() --- .../editors/space_script/space_script.c | 21 +- source/blender/makesrna/RNA_access.h | 13 +- source/blender/makesrna/RNA_define.h | 2 +- source/blender/makesrna/RNA_types.h | 10 +- source/blender/makesrna/intern/CMakeLists.txt | 3 +- source/blender/makesrna/intern/Makefile | 23 +- source/blender/makesrna/intern/SConscript | 7 +- source/blender/makesrna/intern/makesrna.c | 203 +++++++++++------- source/blender/makesrna/intern/rna_ID.c | 6 - source/blender/makesrna/intern/rna_access.c | 50 +++-- source/blender/makesrna/intern/rna_color.c | 2 +- source/blender/makesrna/intern/rna_curve.c | 2 +- source/blender/makesrna/intern/rna_define.c | 6 +- source/blender/makesrna/intern/rna_group.c | 2 +- source/blender/makesrna/intern/rna_internal.h | 4 + .../makesrna/intern/rna_internal_types.h | 1 + source/blender/makesrna/intern/rna_key.c | 2 +- source/blender/makesrna/intern/rna_lattice.c | 4 +- source/blender/makesrna/intern/rna_main.c | 6 +- source/blender/makesrna/intern/rna_main_api.c | 81 +++++++ source/blender/makesrna/intern/rna_material.c | 2 +- source/blender/makesrna/intern/rna_mesh.c | 25 ++- source/blender/makesrna/intern/rna_mesh_api.c | 108 ++++++++++ source/blender/makesrna/intern/rna_modifier.c | 2 +- source/blender/makesrna/intern/rna_object.c | 14 +- .../blender/makesrna/intern/rna_object_api.c | 83 +++++++ source/blender/makesrna/intern/rna_rna.c | 10 +- source/blender/makesrna/intern/rna_scene.c | 2 +- source/blender/makesrna/intern/rna_sequence.c | 2 +- .../intern/rna_ui_api.c} | 6 + source/blender/makesrna/intern/rna_wm.c | 2 + source/blender/makesrna/intern/rna_wm_api.c | 56 +++++ source/blender/python/CMakeLists.txt | 4 + source/blender/python/intern/bpy_rna.c | 16 +- 34 files changed, 594 insertions(+), 186 deletions(-) create mode 100644 source/blender/makesrna/intern/rna_main_api.c create mode 100644 source/blender/makesrna/intern/rna_mesh_api.c create mode 100644 source/blender/makesrna/intern/rna_object_api.c rename source/blender/{editors/interface/interface_api.c => makesrna/intern/rna_ui_api.c} (99%) create mode 100644 source/blender/makesrna/intern/rna_wm_api.c diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c index 4c17ed16475..99233cc5020 100644 --- a/source/blender/editors/space_script/space_script.c +++ b/source/blender/editors/space_script/space_script.c @@ -175,29 +175,12 @@ static void script_main_area_draw(const bContext *C, ARegion *ar) /* add handlers, stuff you only do once or on area/region changes */ static void script_header_area_init(wmWindowManager *wm, ARegion *ar) { - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); + ED_region_header_init(ar); } static void script_header_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - if(ED_screen_area_active(C)) - UI_GetThemeColor3fv(TH_HEADER, col); - else - UI_GetThemeColor3fv(TH_HEADERDESEL, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - script_header_buttons(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_header(C, ar); } static void script_main_area_listener(ARegion *ar, wmNotifier *wmn) diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index f7b069d8227..1907b2cedb4 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -37,6 +37,7 @@ extern "C" { struct bContext; struct ID; struct Main; +struct ReportList; /* Types */ @@ -719,13 +720,13 @@ void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, void *value); void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, void *value); -int RNA_function_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms); -int RNA_function_call_lookup(PointerRNA *ptr, const char *identifier, ParameterList *parms); +int RNA_function_call(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms); +int RNA_function_call_lookup(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms); -int RNA_function_call_direct(PointerRNA *ptr, FunctionRNA *func, const char *format, ...); -int RNA_function_call_direct_lookup(PointerRNA *ptr, const char *identifier, const char *format, ...); -int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args); -int RNA_function_call_direct_va_lookup(PointerRNA *ptr, const char *identifier, const char *format, va_list args); +int RNA_function_call_direct(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...); +int RNA_function_call_direct_lookup(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, ...); +int RNA_function_call_direct_va(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args); +int RNA_function_call_direct_va_lookup(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, va_list args); /* ID */ diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 6cd8cce59a3..dfe072c4b8e 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -147,7 +147,7 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item); void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set); void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef); -void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring); +void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *add, const char *remove); /* Function */ diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index b527a4f11b3..75f52ededd0 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -161,11 +161,13 @@ typedef struct ParameterIterator { /* Function */ typedef enum FunctionFlag { - FUNC_TYPESTATIC = 1, /* for static functions, FUNC_ STATIC is taken by some windows header it seems */ + FUNC_NO_SELF = 1, /* for static functions */ + FUNC_USE_CONTEXT = 2, + FUNC_USE_REPORTS = 4, /* registering */ - FUNC_REGISTER = 2, - FUNC_REGISTER_OPTIONAL = 2|4, + FUNC_REGISTER = 8, + FUNC_REGISTER_OPTIONAL = 8|16, /* internal flags */ FUNC_BUILTIN = 128, @@ -173,7 +175,7 @@ typedef enum FunctionFlag { FUNC_RUNTIME = 512 } FunctionFlag; -typedef void (*CallFunc)(PointerRNA *ptr, ParameterList *parms); +typedef void (*CallFunc)(struct bContext *C, struct ReportList *reports, PointerRNA *ptr, ParameterList *parms); typedef struct FunctionRNA FunctionRNA; diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 2914e488efa..963e4f9aeff 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -25,8 +25,9 @@ # ***** END GPL LICENSE BLOCK ***** FILE(GLOB DEFSRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c") +FILE(GLOB APISRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*_api.c") LIST(REMOVE_ITEM DEFSRC rna_access.c rna_define.c makesrna.c) -FILE(GLOB_RECURSE APISRC "../../editors/*/*_api.c") +LIST(REMOVE_ITEM DEFSRC ${APISRC}) STRING(REGEX REPLACE "rna_([a-zA-Z0-9_-]*).c" "${CMAKE_CURRENT_BINARY_DIR}/rna_\\1_gen.c" GENSRC "${DEFSRC}") diff --git a/source/blender/makesrna/intern/Makefile b/source/blender/makesrna/intern/Makefile index 78757c4f4b5..03f75f0bea6 100644 --- a/source/blender/makesrna/intern/Makefile +++ b/source/blender/makesrna/intern/Makefile @@ -28,10 +28,11 @@ DIR = $(OCGDIR)/blender/makesrna ALLRNA = $(wildcard rna_*.c) DEFRNA = $(filter-out %rna_define.c, $(filter-out %rna_access.c, $(ALLRNA))) -GENSRCS = $(patsubst rna_%.c, rna_%_gen.c, $(DEFRNA)) +GENRNA = $(filter-out %_api.c, $(DEFRNA)) +GENSRCS = $(patsubst rna_%.c, rna_%_gen.c, $(GENRNA)) GENTARGET = $(patsubst %.c, $(DIR)/$(DEBUG_DIR)%.c, $(GENSRCS)) -MAKESRCS = $(DEFRNA) makesrna.c rna_define.c $(wildcard ../../editors/*/*_api.c) +MAKESRCS = $(DEFRNA) makesrna.c rna_define.c MAKEOBJS = $(patsubst %.c, $(DIR)/$(DEBUG_DIR)%.o, $(notdir $(MAKESRCS))) CSRCS = $(GENSRCS) rna_access.c @@ -94,24 +95,6 @@ clean:: # TODO include right .mk for ldflags -# XXX this is an ugly hack, copying code from nan_compile.mk -# we want the .o's to be in the makesrna/ directory, but the -# .c's are in the editors/*/ directories - -$(DIR)/$(DEBUG_DIR)%_api.o: ../../editors/interface/%_api.c - ifdef NAN_DEPEND - @set -e; $(CC) -M $(CPPFLAGS) $< 2>/dev/null \ - | sed 's@\($*\)\.o[ :]*@$(DIR)/$(DEBUG_DIR)\1.o : @g' \ - > $(DIR)/$(DEBUG_DIR)$*.d; \ - [ -s $(DIR)/$(DEBUG_DIR)$*.d ] || $(RM) $(DIR)/$*.d - endif - ifdef NAN_QUIET - @echo " -- $< -- " - @$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ - else - $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ - endif - # A small note: we do not use the debug version of the alloc lib. That # is done quite intentionally. If there is a bug in that lib, it needs # to be fixed by the module maintainer. diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript index 041f743a056..03f0afdb2cc 100644 --- a/source/blender/makesrna/intern/SConscript +++ b/source/blender/makesrna/intern/SConscript @@ -16,9 +16,12 @@ source_files.remove('rna_access.c') generated_files = source_files[:] generated_files.remove('rna_define.c') generated_files.remove('makesrna.c') -generated_files = [filename[:-2] + '_gen.c' for filename in generated_files] -source_files.extend(env.Glob('../../editors/*/*_api.c')) +api_files = env.Glob('*_api.c') +for api_file in api_files: + generated_files.remove(api_file) + +generated_files = [filename[:-2] + '_gen.c' for filename in generated_files] makesrna_tool = env.Clone() rna = env.Clone() diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index dd438cfe164..a8fe025fd46 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -394,7 +394,7 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr else if(rna_color_quantize(prop, dp)) fprintf(f, " values[%d]= (%s)(data->%s[%d]*(1.0f/255.0f));\n", i, rna_type_type(prop), dp->dnaname, i); else - fprintf(f, " values[%d]= (%s)%s(data->%s[%d]);\n", i, rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname, i); + fprintf(f, " values[%d]= (%s)%s(((%s*)data->%s)[%d]);\n", i, rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname, i); } } } @@ -559,7 +559,7 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr fprintf(f, " data->%s[%d]= FTOCHAR(values[%d]);\n", dp->dnaname, i, i); } else { - fprintf(f, " data->%s[%d]= %s", dp->dnaname, i, (dp->booleannegative)? "!": ""); + fprintf(f, " ((%s*)data->%s)[%d]= %s", dp->dnatype, dp->dnaname, i, (dp->booleannegative)? "!": ""); rna_clamp_value(f, prop, 1, i); } } @@ -1104,6 +1104,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA FunctionRNA *func; PropertyDefRNA *dparm; char *funcname, *ptrstr; + int first; srna= dsrna->srna; func= dfunc->func; @@ -1113,10 +1114,10 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call"); - fprintf(f, "void %s(PointerRNA *_ptr, ParameterList *_parms)", funcname); + fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname); fprintf(f, "\n{\n"); - if((func->flag & FUNC_TYPESTATIC)==0) { + if((func->flag & FUNC_NO_SELF)==0) { if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname); else fprintf(f, "\tstruct %s *_self;\n", srna->identifier); } @@ -1132,7 +1133,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA fprintf(f, ";\n"); fprintf(f, "\t\n"); - if((func->flag & FUNC_TYPESTATIC)==0) { + if((func->flag & FUNC_NO_SELF)==0) { if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname); else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier); } @@ -1164,16 +1165,33 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA if(func->ret) fprintf(f, "%s= ", func->ret->identifier); fprintf(f, "%s(", dfunc->call); - if((func->flag & FUNC_TYPESTATIC)==0) + first= 1; + + if((func->flag & FUNC_NO_SELF)==0) { fprintf(f, "_self"); + first= 0; + } + + if(func->flag & FUNC_USE_CONTEXT) { + if(!first) fprintf(f, ", "); + first= 0; + fprintf(f, "C"); + } + + if(func->flag & FUNC_USE_REPORTS) { + if(!first) fprintf(f, ", "); + first= 0; + fprintf(f, "reports"); + } dparm= dfunc->cont.properties.first; for(; dparm; dparm= dparm->next) { if(dparm->prop==func->ret) continue; - if((func->flag & FUNC_TYPESTATIC)==0 || dparm!=dfunc->cont.properties.first) - fprintf(f, ", "); + if(!first) fprintf(f, ", "); + first= 0; + fprintf(f, "%s", dparm->prop->identifier); } @@ -1356,7 +1374,7 @@ static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, base= srna->base; while (base) { for(func= base->functions.first; func; func= func->cont.next) { - fprintf(f, "%s%s rna_%s_%s;\n", "extern ", "FunctionRNA", base->identifier, func->identifier); + fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier); rna_generate_parameter_prototypes(brna, base, func, f); } @@ -1367,7 +1385,7 @@ static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, } for(func= srna->functions.first; func; func= func->cont.next) { - fprintf(f, "%s%s rna_%s_%s;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier); + fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier); rna_generate_parameter_prototypes(brna, srna, func, f); } @@ -1380,6 +1398,7 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA FunctionRNA *func; PropertyDefRNA *dparm; StructDefRNA *dsrna; + int first; dsrna= rna_find_struct_def(srna); func= dfunc->func; @@ -1402,17 +1421,39 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA fprintf(f, "%s(", dfunc->call); - if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname); - else fprintf(f, "struct %s *_self", srna->identifier); + first= 1; + + if((func->flag & FUNC_NO_SELF)==0) { + if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname); + else fprintf(f, "struct %s *_self", srna->identifier); + first= 0; + } + + if(func->flag & FUNC_USE_CONTEXT) { + if(!first) fprintf(f, ", "); + first= 0; + fprintf(f, "bContext *C"); + } + + if(func->flag & FUNC_USE_REPORTS) { + if(!first) fprintf(f, ", "); + first= 0; + fprintf(f, "ReportList *reports"); + } for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) { - if(dparm->prop==func->ret) ; - else if(dparm->prop->arraylength) - fprintf(f, ", %s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->arraylength); + if(dparm->prop==func->ret) + continue; + + if(!first) fprintf(f, ", "); + first= 0; + + if(dparm->prop->arraylength) + fprintf(f, "%s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->arraylength); else if(dparm->prop->type == PROP_POINTER) - fprintf(f, ", %s%s *%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier); + fprintf(f, "%s%s *%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier); else - fprintf(f, ", %s%s %s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier); + fprintf(f, "%s%s %s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier); } fprintf(f, ");\n"); @@ -1629,10 +1670,14 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr case PROP_COLLECTION: { CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring)); + if(cprop->add) fprintf(f, "&rna_%s_%s_func, ", srna->identifier, (char*)cprop->add); + else fprintf(f, "NULL, "); + if(cprop->remove) fprintf(f, "&rna_%s_%s_func, ", srna->identifier, (char*)cprop->remove); + else fprintf(f, "NULL, "); if(cprop->type) fprintf(f, "&RNA_%s\n", (char*)cprop->type); else fprintf(f, "NULL\n"); break; - } + } } fprintf(f, "};\n\n"); @@ -1659,11 +1704,11 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) for(parm= func->cont.properties.first; parm; parm= parm->next) rna_generate_property(f, srna, func->identifier, parm); - fprintf(f, "%s%s rna_%s_%s = {\n", "", "FunctionRNA", srna->identifier, func->identifier); + fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier); - if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier); + if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier); else fprintf(f, "\t{NULL, "); - if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier); + if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier); else fprintf(f, "NULL,\n"); parm= func->cont.properties.first; @@ -1749,11 +1794,11 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) } func= srna->functions.first; - if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s, ", srna->identifier, func->identifier); + if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier); else fprintf(f, "\t{NULL, "); func= srna->functions.last; - if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s}\n", srna->identifier, func->identifier); + if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier); else fprintf(f, "NULL}\n"); fprintf(f, "};\n"); @@ -1763,63 +1808,64 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) typedef struct RNAProcessItem { char *filename; + char *api_filename; void (*define)(BlenderRNA *brna); } RNAProcessItem; RNAProcessItem PROCESS_ITEMS[]= { - {"rna_rna.c", RNA_def_rna}, - {"rna_ID.c", RNA_def_ID}, - {"rna_texture.c", RNA_def_texture}, - {"rna_action.c", RNA_def_action}, - {"rna_animation.c", RNA_def_animation}, - {"rna_actuator.c", RNA_def_actuator}, - {"rna_armature.c", RNA_def_armature}, - {"rna_brush.c", RNA_def_brush}, - {"rna_camera.c", RNA_def_camera}, - {"rna_cloth.c", RNA_def_cloth}, - {"rna_color.c", RNA_def_color}, - {"rna_constraint.c", RNA_def_constraint}, - {"rna_context.c", RNA_def_context}, - {"rna_controller.c", RNA_def_controller}, - {"rna_curve.c", RNA_def_curve}, - {"rna_fcurve.c", RNA_def_fcurve}, - {"rna_fluidsim.c", RNA_def_fluidsim}, - {"rna_group.c", RNA_def_group}, - {"rna_image.c", RNA_def_image}, - {"rna_key.c", RNA_def_key}, - {"rna_lamp.c", RNA_def_lamp}, - {"rna_lattice.c", RNA_def_lattice}, - {"rna_main.c", RNA_def_main}, - {"rna_material.c", RNA_def_material}, - {"rna_mesh.c", RNA_def_mesh}, - {"rna_meta.c", RNA_def_meta}, - {"rna_modifier.c", RNA_def_modifier}, - {"rna_nodetree.c", RNA_def_nodetree}, - {"rna_object.c", RNA_def_object}, - {"rna_object_force.c", RNA_def_object_force}, - {"rna_packedfile.c", RNA_def_packedfile}, - {"rna_particle.c", RNA_def_particle}, - {"rna_pose.c", RNA_def_pose}, - {"rna_property.c", RNA_def_gameproperty}, - {"rna_radio.c", RNA_def_radio}, - {"rna_scene.c", RNA_def_scene}, - {"rna_screen.c", RNA_def_screen}, - {"rna_scriptlink.c", RNA_def_scriptlink}, - {"rna_sensor.c", RNA_def_sensor}, - {"rna_sequence.c", RNA_def_sequence}, - {"rna_space.c", RNA_def_space}, - {"rna_text.c", RNA_def_text}, - {"rna_timeline.c", RNA_def_timeline_marker}, - {"rna_sound.c", RNA_def_sound}, - {"rna_ui.c", RNA_def_ui}, - {"rna_userdef.c", RNA_def_userdef}, - {"rna_vfont.c", RNA_def_vfont}, - {"rna_vpaint.c", RNA_def_vpaint}, - {"rna_wm.c", RNA_def_wm}, - {"rna_world.c", RNA_def_world}, + {"rna_rna.c", NULL, RNA_def_rna}, + {"rna_ID.c", NULL, RNA_def_ID}, + {"rna_texture.c", NULL, RNA_def_texture}, + {"rna_action.c", NULL, RNA_def_action}, + {"rna_animation.c", NULL, RNA_def_animation}, + {"rna_actuator.c", NULL, RNA_def_actuator}, + {"rna_armature.c", NULL, RNA_def_armature}, + {"rna_brush.c", NULL, RNA_def_brush}, + {"rna_camera.c", NULL, RNA_def_camera}, + {"rna_cloth.c", NULL, RNA_def_cloth}, + {"rna_color.c", NULL, RNA_def_color}, + {"rna_constraint.c", NULL, RNA_def_constraint}, + {"rna_context.c", NULL, RNA_def_context}, + {"rna_controller.c", NULL, RNA_def_controller}, + {"rna_curve.c", NULL, RNA_def_curve}, + {"rna_fcurve.c", NULL, RNA_def_fcurve}, + {"rna_fluidsim.c", NULL, RNA_def_fluidsim}, + {"rna_group.c", NULL, RNA_def_group}, + {"rna_image.c", NULL, RNA_def_image}, + {"rna_key.c", NULL, RNA_def_key}, + {"rna_lamp.c", NULL, RNA_def_lamp}, + {"rna_lattice.c", NULL, RNA_def_lattice}, + {"rna_main.c", "rna_main_api.c", RNA_def_main}, + {"rna_material.c", NULL, RNA_def_material}, + {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh}, + {"rna_meta.c", NULL, RNA_def_meta}, + {"rna_modifier.c", NULL, RNA_def_modifier}, + {"rna_nodetree.c", NULL, RNA_def_nodetree}, + {"rna_object.c", "rna_object_api.c", RNA_def_object}, + {"rna_object_force.c", NULL, RNA_def_object_force}, + {"rna_packedfile.c", NULL, RNA_def_packedfile}, + {"rna_particle.c", NULL, RNA_def_particle}, + {"rna_pose.c", NULL, RNA_def_pose}, + {"rna_property.c", NULL, RNA_def_gameproperty}, + {"rna_radio.c", NULL, RNA_def_radio}, + {"rna_scene.c", NULL, RNA_def_scene}, + {"rna_screen.c", NULL, RNA_def_screen}, + {"rna_scriptlink.c", NULL, RNA_def_scriptlink}, + {"rna_sensor.c", NULL, RNA_def_sensor}, + {"rna_sequence.c", NULL, RNA_def_sequence}, + {"rna_space.c", NULL, RNA_def_space}, + {"rna_text.c", NULL, RNA_def_text}, + {"rna_timeline.c", NULL, RNA_def_timeline_marker}, + {"rna_sound.c", NULL, RNA_def_sound}, + {"rna_ui.c", "rna_ui_api.c", RNA_def_ui}, + {"rna_userdef.c", NULL, RNA_def_userdef}, + {"rna_vfont.c", NULL, RNA_def_vfont}, + {"rna_vpaint.c", NULL, RNA_def_vpaint}, + {"rna_wm.c", "rna_wm_api.c", RNA_def_wm}, + {"rna_world.c", NULL, RNA_def_world}, {NULL, NULL}}; -static void rna_generate(BlenderRNA *brna, FILE *f, char *filename) +static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_filename) { StructDefRNA *ds; PropertyDefRNA *dp; @@ -1837,7 +1883,9 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename) fprintf(f, "#include \"BLI_blenlib.h\"\n\n"); + fprintf(f, "#include \"BKE_context.h\"\n"); fprintf(f, "#include \"BKE_library.h\"\n"); + fprintf(f, "#include \"BKE_report.h\"\n"); fprintf(f, "#include \"BKE_utildefines.h\"\n\n"); fprintf(f, "#include \"RNA_define.h\"\n"); @@ -1846,7 +1894,10 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename) rna_generate_prototypes(brna, f); - fprintf(f, "#include \"%s\"\n\n", filename); + fprintf(f, "#include \"%s\"\n", filename); + if(api_filename) + fprintf(f, "#include \"%s\"\n", api_filename); + fprintf(f, "\n"); fprintf(f, "/* Autogenerated Functions */\n\n"); @@ -2169,7 +2220,7 @@ static int rna_preprocess(char *outfile) status = 1; } else { - rna_generate(brna, file, PROCESS_ITEMS[i].filename); + rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename); fclose(file); status= (DefRNA.error != 0); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 56eda4eb735..52680e26afe 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -246,12 +246,6 @@ static void rna_def_ID(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "lib"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from."); - - /* XXX temporary for testing */ - func= RNA_def_function(srna, "rename", "rename_id"); - RNA_def_function_ui_description(func, "Rename this ID datablock."); - prop= RNA_def_string(func, "name", "", 0, "", "New name for the datablock."); - RNA_def_property_flag(prop, PROP_REQUIRED); } static void rna_def_library(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 2413cd46eed..cfddb1daf10 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -33,7 +33,9 @@ #include "BLI_blenlib.h" #include "BLI_dynstr.h" +#include "BKE_context.h" #include "BKE_idprop.h" +#include "BKE_report.h" #include "BKE_utildefines.h" #include "WM_api.h" @@ -725,7 +727,7 @@ int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop) return 0; } -void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop) +void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop) { prop= rna_ensure_property(prop); @@ -1321,6 +1323,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr) { IDProperty *idprop; + //CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDPropertyTemplate val = {0}; @@ -1346,8 +1349,17 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA MEM_freeN(item); } } +#if 0 + else if(cprop->add){ + if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ + ParameterList *params= RNA_parameter_list_create(ptr, cprop->add); + RNA_function_call(NULL, NULL, ptr, cprop->add, params); + RNA_parameter_list_free(params); + } + } +#endif else - printf("RNA_property_collection_add %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier); + printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier); if(r_ptr) { if(idprop) { @@ -1365,6 +1377,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) { IDProperty *idprop; + //CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if((idprop=rna_idproperty_check(&prop, ptr))) { IDProperty tmp, *array; @@ -1385,6 +1398,15 @@ void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) } } else if(prop->flag & PROP_IDPROPERTY); +#if 0 + else if(cprop->remove){ + if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */ + ParameterList *params= RNA_parameter_list_create(ptr, cprop->remove); + RNA_function_call(NULL, NULL, ptr, cprop->remove, params); + RNA_parameter_list_free(params); + } + } +#endif else printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier); } @@ -2524,10 +2546,10 @@ void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, void RNA_parameter_set(parms, parm, value); } -int RNA_function_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) +int RNA_function_call(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) { if(func->call) { - func->call(ptr, parms); + func->call(C, reports, ptr, parms); return 0; } @@ -2535,33 +2557,33 @@ int RNA_function_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) return -1; } -int RNA_function_call_lookup(PointerRNA *ptr, const char *identifier, ParameterList *parms) +int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms) { FunctionRNA *func; func= RNA_struct_find_function(ptr, identifier); if(func) - return RNA_function_call(ptr, func, parms); + return RNA_function_call(C, reports, ptr, func, parms); return -1; } -int RNA_function_call_direct(PointerRNA *ptr, FunctionRNA *func, const char *format, ...) +int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...) { va_list args; int ret; va_start(args, format); - ret= RNA_function_call_direct_va(ptr, func, format, args); + ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args); va_end(args); return ret; } -int RNA_function_call_direct_lookup(PointerRNA *ptr, const char *identifier, const char *format, ...) +int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, ...) { FunctionRNA *func; @@ -2573,7 +2595,7 @@ int RNA_function_call_direct_lookup(PointerRNA *ptr, const char *identifier, con va_start(args, format); - ret= RNA_function_call_direct_va(ptr, func, format, args); + ret= RNA_function_call_direct_va(C, reports, ptr, func, format, args); va_end(args); @@ -2715,7 +2737,7 @@ static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, Prop return 0; } -int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args) +int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args) { PointerRNA funcptr; ParameterList *parms; @@ -2810,7 +2832,7 @@ int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char * } if (err==0) - err= RNA_function_call(ptr, func, parms); + err= RNA_function_call(C, reports, ptr, func, parms); /* XXX throw error when more parameters than those needed are passed or leave silent? */ if (err==0 && pret && ofslength= (PropCollectionLengthFunc)length; if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint; if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring; + if(add) cprop->add= (FunctionRNA*)add; + if(remove) cprop->remove= (FunctionRNA*)remove; break; } default: diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index 059b2ce78f7..1406ad1ae60 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -61,7 +61,7 @@ void RNA_def_group(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects."); - RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Group_objects_get", 0, 0, 0, 0, 0); prop= RNA_def_property(srna, "layer", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "layer", 1); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 9071efe71f7..61cde5a01a3 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -188,7 +188,11 @@ void rna_object_vcollayer_name_set(struct PointerRNA *ptr, const char *value, ch /* API functions */ +void RNA_api_main(struct StructRNA *srna); +void RNA_api_mesh(struct StructRNA *srna); +void RNA_api_object(struct StructRNA *srna); void RNA_api_ui_layout(struct StructRNA *srna); +void RNA_api_wm(struct StructRNA *srna); /* ID Properties */ diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 3a5a4fa1ced..d93e6f4d7cf 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -245,6 +245,7 @@ typedef struct CollectionPropertyRNA { PropCollectionLengthFunc length; /* optional */ PropCollectionLookupIntFunc lookupint; /* optional */ PropCollectionLookupStringFunc lookupstring; /* optional */ + FunctionRNA *add, *remove; struct StructRNA *type; } CollectionPropertyRNA; diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c index 896f660c720..b97dd95c4d4 100644 --- a/source/blender/makesrna/intern/rna_key.c +++ b/source/blender/makesrna/intern/rna_key.c @@ -335,7 +335,7 @@ static void rna_def_keyblock(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "data", "totelem"); RNA_def_property_struct_type(prop, "UnknownType"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_ShapeKey_data_begin", 0, 0, "rna_ShapeKey_data_get", "rna_ShapeKey_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_ShapeKey_data_begin", 0, 0, "rna_ShapeKey_data_get", "rna_ShapeKey_data_length", 0, 0, 0, 0); } static void rna_def_key(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index 0e341fcdbd0..3af448b0233 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -99,7 +99,7 @@ static void rna_def_latticepoint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Deformed Location", ""); prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_funcs(prop, "rna_LatticePoint_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_LatticePoint_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_struct_type(prop, "VertexGroupElement"); RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this point is member of."); } @@ -159,7 +159,7 @@ static void rna_def_lattice(BlenderRNA *brna) prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "LatticePoint"); - RNA_def_property_collection_funcs(prop, "rna_Lattice_points_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Lattice_points_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Points", "Points of the lattice."); } diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index fdd0349b25e..8d98036290a 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -33,6 +33,7 @@ #ifdef RNA_RUNTIME #include "BKE_main.h" +#include "BKE_mesh.h" /* all the list begin functions are added manually here, Main is not in SDNA */ @@ -218,6 +219,7 @@ void RNA_def_main(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + const char *lists[][5]= { {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks."}, {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks."}, @@ -262,9 +264,11 @@ void RNA_def_main(BlenderRNA *brna) { prop= RNA_def_property(srna, lists[i][0], PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, lists[i][1]); - RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, "add_mesh", "remove_mesh"); RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]); } + + RNA_api_main(srna); } #endif diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c new file mode 100644 index 00000000000..6d56b2b00f9 --- /dev/null +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -0,0 +1,81 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include + +#include "RNA_define.h" +#include "RNA_types.h" + +#ifdef RNA_RUNTIME + +#include "BKE_main.h" +#include "BKE_mesh.h" +#include "BKE_library.h" + +#include "DNA_mesh_types.h" + +Mesh *rna_Main_add_mesh(Main *main, char *name) +{ + Mesh *me= add_mesh(name); + me->id.us--; + return me; +} + +void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me) +{ + if(me->id.us == 0) + free_libblock(&main->mesh, me); + else + BKE_report(reports, RPT_ERROR, "Mesh must have zero users to be removed."); + + /* XXX python now has invalid pointer? */ +} + +#else + +void RNA_api_main(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *prop; + + func= RNA_def_function(srna, "add_mesh", "rna_Main_add_mesh"); + RNA_def_function_ui_description(func, "Add a new mesh."); + prop= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock."); + prop= RNA_def_pointer(func, "mesh", "Mesh", "", "New mesh."); + RNA_def_function_return(func, prop); + + func= RNA_def_function(srna, "remove_mesh", "rna_Main_remove_mesh"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a mesh if it has zero users."); + prop= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove."); + RNA_def_property_flag(prop, PROP_REQUIRED); +} + +#endif + diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 1c16e793fdc..41f31594f6e 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -1143,7 +1143,7 @@ void rna_def_mtex_common(StructRNA *srna, const char *begin, const char *activeg /* mtex */ prop= RNA_def_property(srna, "textures", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, structname); - RNA_def_property_collection_funcs(prop, begin, "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, begin, "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures."); prop= RNA_def_property(srna, "active_texture", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 3499ee16258..653f9d61fa5 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -646,7 +646,7 @@ static void rna_def_mvert(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Bevel Weight", "Weight used by the Bevel modifier 'Only Vertices' option"); prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_funcs(prop, "rna_MeshVertex_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshVertex_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_struct_type(prop, "VertexGroupElement"); RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this vertex is member of."); } @@ -761,7 +761,7 @@ static void rna_def_mtface(BlenderRNA *brna) prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "MeshTextureFace"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_MeshTextureFaceLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshTextureFaceLayer_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshTextureFaceLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshTextureFaceLayer_data_length", 0, 0, 0, 0); srna= RNA_def_struct(brna, "MeshTextureFace", NULL); RNA_def_struct_sdna(srna, "MTFace"); @@ -898,7 +898,7 @@ static void rna_def_mcol(BlenderRNA *brna) prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "MeshColor"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_MeshColorLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshColorLayer_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshColorLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshColorLayer_data_length", 0, 0, 0, 0); srna= RNA_def_struct(brna, "MeshColor", NULL); RNA_def_struct_sdna(srna, "MCol"); @@ -944,7 +944,7 @@ static void rna_def_mproperties(BlenderRNA *brna) prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "MeshFloatProperty"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_MeshFloatPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshFloatPropertyLayer_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshFloatPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshFloatPropertyLayer_data_length", 0, 0, 0, 0); srna= RNA_def_struct(brna, "MeshFloatProperty", NULL); RNA_def_struct_sdna(srna, "MFloatProperty"); @@ -968,7 +968,7 @@ static void rna_def_mproperties(BlenderRNA *brna) prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "MeshIntProperty"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_MeshIntPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshIntPropertyLayer_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshIntPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshIntPropertyLayer_data_length", 0, 0, 0, 0); srna= RNA_def_struct(brna, "MeshIntProperty", NULL); RNA_def_struct_sdna(srna, "MIntProperty"); @@ -992,7 +992,7 @@ static void rna_def_mproperties(BlenderRNA *brna) prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "MeshStringProperty"); RNA_def_property_ui_text(prop, "Data", ""); - RNA_def_property_collection_funcs(prop, "rna_MeshStringPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshStringPropertyLayer_data_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_MeshStringPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshStringPropertyLayer_data_length", 0, 0, 0, 0); srna= RNA_def_struct(brna, "MeshStringProperty", NULL); RNA_def_struct_sdna(srna, "MStringProperty"); @@ -1049,6 +1049,7 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert"); RNA_def_property_struct_type(prop, "MeshVertex"); RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh."); + // XXX RNA_def_property_collection_funcs(prop, "rna_Mesh_verts_begin", 0, 0, 0, 0, 0, 0, "add_verts", "remove_verts"); prop= RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge"); @@ -1067,31 +1068,31 @@ static void rna_def_mesh(BlenderRNA *brna) prop= RNA_def_property(srna, "uv_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); - RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_layers_begin", 0, 0, 0, "rna_Mesh_uv_layers_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_layers_begin", 0, 0, 0, "rna_Mesh_uv_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshTextureFaceLayer"); RNA_def_property_ui_text(prop, "UV Layers", ""); prop= RNA_def_property(srna, "vcol_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); - RNA_def_property_collection_funcs(prop, "rna_Mesh_vcol_layers_begin", 0, 0, 0, "rna_Mesh_vcol_layers_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Mesh_vcol_layers_begin", 0, 0, 0, "rna_Mesh_vcol_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshColorLayer"); RNA_def_property_ui_text(prop, "Vertex Color Layers", ""); prop= RNA_def_property(srna, "float_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); - RNA_def_property_collection_funcs(prop, "rna_Mesh_float_layers_begin", 0, 0, 0, "rna_Mesh_float_layers_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Mesh_float_layers_begin", 0, 0, 0, "rna_Mesh_float_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshFloatPropertyLayer"); RNA_def_property_ui_text(prop, "Float Property Layers", ""); prop= RNA_def_property(srna, "int_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); - RNA_def_property_collection_funcs(prop, "rna_Mesh_int_layers_begin", 0, 0, 0, "rna_Mesh_int_layers_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Mesh_int_layers_begin", 0, 0, 0, "rna_Mesh_int_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshIntPropertyLayer"); RNA_def_property_ui_text(prop, "Int Property Layers", ""); prop= RNA_def_property(srna, "string_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); - RNA_def_property_collection_funcs(prop, "rna_Mesh_string_layers_begin", 0, 0, 0, "rna_Mesh_string_layers_length", 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Mesh_string_layers_begin", 0, 0, 0, "rna_Mesh_string_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshStringPropertyLayer"); RNA_def_property_ui_text(prop, "String Property Layers", ""); @@ -1122,6 +1123,8 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Shape Keys", ""); rna_def_texmat_common(srna, "rna_Mesh_texspace_editable"); + + RNA_api_mesh(srna); } void RNA_def_mesh(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c new file mode 100644 index 00000000000..26fb77777d7 --- /dev/null +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -0,0 +1,108 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include + +#include "RNA_define.h" +#include "RNA_types.h" + +#ifdef RNA_RUNTIME + +#include "BKE_customdata.h" +#include "BKE_DerivedMesh.h" + +#include "DNA_mesh_types.h" +#include "DNA_scene_types.h" + +/* +void rna_Mesh_copy(Mesh *me, Mesh *from) +{ + copy_mesh_data(me, from); +} + +void rna_Mesh_copy_applied(Mesh *me, Scene *sce, Object *ob) +{ + DerivedMesh *dm= mesh_create_derived_view(sce, ob, CD_MASK_MESH); + DM_to_mesh(dm, me); + dm->release(dm); +} +*/ + +void rna_Mesh_transform(Mesh *me, float **mat) +{ +} + +#if 0 +/* extern struct EditVert *addvertlist(EditMesh *em, float *vec, struct EditVert *example); */ + +static void rna_Mesh_verts_add(PointerRNA *ptr, PointerRNA *ptr_item) +{ + //Mesh *me= (Mesh*)ptr->data; + + /* + // XXX if item is not MVert we fail silently + if (item->type == RNA_MeshVertex) + return; + + // XXX this must be slow... + EditMesh *em= BKE_mesh_get_editmesh(me); + + MVert *v = (MVert*)ptr_item->ptr->data; + addvertlist(em, v->co, NULL); + + BKE_mesh_end_editmesh(me, em); + */ +} +#endif + +#else + +void RNA_api_mesh(StructRNA *srna) +{ + /*FunctionRNA *func; + PropertyRNA *prop;*/ + + /* + func= RNA_def_function(srna, "copy", "rna_Mesh_copy"); + RNA_def_function_ui_description(func, "Copy mesh data."); + prop= RNA_def_pointer(func, "src", "Mesh", "", "A mesh to copy data from."); + RNA_def_property_flag(prop, PROP_REQUIRED);*/ + + /* + func= RNA_def_function(srna, "add_geom", "rna_Mesh_add_geom"); + RNA_def_function_ui_description(func, "Add geometry data to mesh."); + prop= RNA_def_collection(func, "verts", "?", "", "Vertices."); + RNA_def_property_flag(prop, PROP_REQUIRED); + prop= RNA_def_collection(func, "faces", "?", "", "Faces."); + RNA_def_property_flag(prop, PROP_REQUIRED); + */ +} + +#endif + diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 30f4936a06d..dab7a94584f 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1089,7 +1089,7 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna) prop= RNA_def_property(srna, "projectors", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Object"); - RNA_def_property_collection_funcs(prop, "rna_UVProject_projectors_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_UVProject_projectors_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Projectors", ""); prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 9d7da401ec1..ff9777d283e 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -584,7 +584,7 @@ static void rna_def_object_game_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Debug State", "Print state debug info in the game engine."); } -static StructRNA *rna_def_object(BlenderRNA *brna) +static void rna_def_object(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; @@ -739,7 +739,7 @@ static StructRNA *rna_def_object(BlenderRNA *brna) prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol"); RNA_def_property_struct_type(prop, "MaterialSlot"); - RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_iterator_array_get", 0, 0, 0); /* don't dereference pointer! */ + RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_iterator_array_get", 0, 0, 0, 0, 0); /* don't dereference pointer! */ RNA_def_property_ui_text(prop, "Materials", "Material slots in the object."); prop= RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE); @@ -799,6 +799,12 @@ static StructRNA *rna_def_object(BlenderRNA *brna) RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface."); + /* matrix */ + prop= RNA_def_property(srna, "matrix", PROP_FLOAT, PROP_MATRIX); + RNA_def_property_float_sdna(prop, NULL, "obmat"); + RNA_def_property_array(prop, 16); + RNA_def_property_ui_text(prop, "Matrix", "Transformation matrix."); + /* collections */ prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Constraint"); @@ -1103,8 +1109,8 @@ static StructRNA *rna_def_object(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "shapenr"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Active Shape Key", "Current shape key index."); - - return srna; + + RNA_api_object(srna); } void RNA_def_object(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c new file mode 100644 index 00000000000..053ab115b3b --- /dev/null +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -0,0 +1,83 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include + +#include "RNA_define.h" +#include "RNA_types.h" + +#ifdef RNA_RUNTIME + +#include "BKE_customdata.h" +#include "BKE_DerivedMesh.h" + +#include "DNA_mesh_types.h" +#include "DNA_scene_types.h" + +/* copied from init_render_mesh (render code) */ +Mesh *rna_Object_create_render_mesh(Object *ob, Scene *scene) +{ + CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; + DerivedMesh *dm; + Mesh *me; + + /* TODO: other types */ + if(ob->type != OB_MESH) + return NULL; + + dm= mesh_create_derived_render(scene, ob, mask); + + if(!dm) + return NULL; + + me= add_mesh("tmp_render_mesh"); + me->id.us--; /* we don't assign it to anything */ + DM_to_mesh(dm, me); + dm->release(dm); + + return me; +} + +#else + +void RNA_api_object(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *prop; + + func= RNA_def_function(srna, "create_render_mesh", "rna_Object_create_render_mesh"); + RNA_def_function_ui_description(func, "Create a Mesh datablock with all modifiers applied."); + prop= RNA_def_pointer(func, "scene", "Scene", "", ""); + RNA_def_property_flag(prop, PROP_REQUIRED); + prop= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh created from object, remove it if it is only used for export."); + RNA_def_function_return(func, prop); +} + +#endif + diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 329175ad68b..bd3a8ae5580 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -611,13 +611,13 @@ static void rna_def_struct(BlenderRNA *brna) prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Property"); - RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Properties", "Properties in the struct."); prop= RNA_def_property(srna, "functions", PROP_COLLECTION, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Function"); - RNA_def_property_collection_funcs(prop, "rna_Struct_functions_begin", "rna_Struct_functions_next", "rna_iterator_listbase_end", "rna_Struct_functions_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Struct_functions_begin", "rna_Struct_functions_next", "rna_iterator_listbase_end", "rna_Struct_functions_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Functions", ""); } @@ -719,7 +719,7 @@ static void rna_def_function(BlenderRNA *brna) prop= RNA_def_property(srna, "parameters", PROP_COLLECTION, PROP_NONE); /*RNA_def_property_clear_flag(prop, PROP_EDITABLE);*/ RNA_def_property_struct_type(prop, "Property"); - RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function."); prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE); @@ -800,7 +800,7 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) prop= RNA_def_property(srna, "items", PROP_COLLECTION, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "EnumPropertyItem"); - RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Items", "Possible values for the property."); srna= RNA_def_struct(brna, "EnumPropertyItem", NULL); @@ -895,7 +895,7 @@ void RNA_def_rna(BlenderRNA *brna) prop= RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Struct"); - RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Structs", ""); } diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 64ba6e11e56..1365ab75fc7 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -866,7 +866,7 @@ void RNA_def_scene(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "base", NULL); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Objects", ""); - RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Scene_objects_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_Scene_objects_get", 0, 0, 0, 0, 0); prop= RNA_def_property(srna, "visible_layers", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "lay", 1); diff --git a/source/blender/makesrna/intern/rna_sequence.c b/source/blender/makesrna/intern/rna_sequence.c index 69e884fe249..055e67fb135 100644 --- a/source/blender/makesrna/intern/rna_sequence.c +++ b/source/blender/makesrna/intern/rna_sequence.c @@ -521,7 +521,7 @@ void rna_def_editor(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "metastack", NULL); RNA_def_property_struct_type(prop, "Sequence"); RNA_def_property_ui_text(prop, "Meta Stack", "Meta strip stack, last is currently edited meta strip."); - RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_SequenceEdtior_meta_stack_get", 0, 0, 0); + RNA_def_property_collection_funcs(prop, 0, 0, 0, "rna_SequenceEdtior_meta_stack_get", 0, 0, 0, 0, 0); prop= RNA_def_property(srna, "active_strip", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "act_seq"); diff --git a/source/blender/editors/interface/interface_api.c b/source/blender/makesrna/intern/rna_ui_api.c similarity index 99% rename from source/blender/editors/interface/interface_api.c rename to source/blender/makesrna/intern/rna_ui_api.c index 31b0b85fae6..d06d4d4406d 100644 --- a/source/blender/editors/interface/interface_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -35,6 +35,10 @@ #include "UI_interface.h" #include "UI_resources.h" +#ifdef RNA_RUNTIME + +#else + #define DEF_ICON(name) {name, #name, 0, #name, ""}, static EnumPropertyItem icon_items[] = { #include "UI_icons.h" @@ -243,3 +247,5 @@ void RNA_api_ui_layout(StructRNA *srna) api_ui_item_rna_common(func); } +#endif + diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 22ce207c6a9..df07e03850a 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -160,6 +160,8 @@ static void rna_def_windowmanager(BlenderRNA *brna) prop= RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Operator"); RNA_def_property_ui_text(prop, "Operators", "Operator registry."); + + RNA_api_wm(srna); } void RNA_def_wm(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c new file mode 100644 index 00000000000..fd34d7c4d70 --- /dev/null +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -0,0 +1,56 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include + +#include "RNA_define.h" +#include "RNA_types.h" + +#ifdef RNA_RUNTIME + +#include "BKE_context.h" + +#include "WM_api.h" + +#else + +void RNA_api_wm(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *prop; + + func= RNA_def_function(srna, "add_fileselect", "WM_event_add_fileselect"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Show up the file selector."); + prop= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call."); + RNA_def_property_flag(prop, PROP_REQUIRED); +} + +#endif + diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt index d15970e1df4..7700e6bc2aa 100644 --- a/source/blender/python/CMakeLists.txt +++ b/source/blender/python/CMakeLists.txt @@ -24,10 +24,12 @@ # ***** END GPL LICENSE BLOCK ***** FILE(GLOB SRC intern/*.c) +FILE(GLOB GENSRC generic/*.c) SET(INC . ../../../intern/guardedalloc ../blenlib ../makesdna ../makesrna ../blenkernel ../editors/include ../windowmanager ${PYTHON_INC} + ../../../extern/glew/include ) IF(WITH_OPENEXR) @@ -47,3 +49,5 @@ ENDIF(WITH_FFMPEG) ADD_DEFINITIONS(-DWITH_CCGSUBSURF) BLENDERLIB(bf_python "${SRC}" "${INC}") +BLENDERLIB(bf_gen_python "${GENSRC}" "${INC}") + diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 4cdc78297d4..a0fb4865548 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1310,11 +1310,19 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) ret= NULL; if (err==0) { /* call function */ - RNA_function_call(self_ptr, self_func, parms); + ReportList reports; + bContext *C= BPy_GetContext(); + + BKE_reports_init(&reports, RPT_STORE); + RNA_function_call(C, &reports, self_ptr, self_func, parms); + + err= (BPy_reports_to_error(&reports))? -1: 0; + BKE_reports_clear(&reports); /* return value */ - if(pret) - ret= pyrna_param_to_py(&funcptr, pret, retdata); + if(err==0) + if(pret) + ret= pyrna_param_to_py(&funcptr, pret, retdata); } /* cleanup */ @@ -2121,7 +2129,7 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *args) C= BPy_GetContext(); /* call the register callback */ - BKE_reports_init(&reports, RPT_PRINT); + BKE_reports_init(&reports, RPT_STORE); srna= reg(C, &reports, py_class, bpy_class_validate, bpy_class_call, bpy_class_free); if(!srna) { From 94dbb3bbdd612247f757d1962d2604737eb72f64 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 18 Jun 2009 19:51:22 +0000 Subject: [PATCH 8/8] 2.5 Python Merging changes made by Arystanbek in the soc-2009-kazanbas branch, plus some things modified and added by me. * Operator exec is called execute in python now, due to conflicts with python exec keyword. * Operator invoke/execute now get context argument. * Fix crash executing operators due to bpy_import_main_set not being set with Main pointer. * The bpy.props module now has the FloatProperty/IntProperty/ StringProperty/BoolProperty functions to define RNA properties for operators. * Operators now have an __operator__ property to get the actual RNA operator pointers, this is only temporary though. * bpy.ops.add now allows the operator to be already registered, it will simply overwrite the existing one. * Both the ui and io directories are now scanned and run on startup. --- SConstruct | 32 ++---- source/blender/python/intern/bpy_interface.c | 100 ++++++++++-------- .../blender/python/intern/bpy_operator_wrap.c | 74 ++++++++++--- source/blender/python/intern/bpy_rna.c | 70 +++++++++++- source/blender/python/intern/bpy_rna.h | 2 + source/blender/python/intern/bpy_util.c | 4 + 6 files changed, 197 insertions(+), 85 deletions(-) diff --git a/SConstruct b/SConstruct index dcea0f511eb..808fa09bea0 100644 --- a/SConstruct +++ b/SConstruct @@ -468,27 +468,17 @@ if env['OURPLATFORM']!='darwin': dotblenderinstall.append(env.Install(dir=td, source=srcfile)) if env['WITH_BF_PYTHON']: - #-- .blender/scripts - scriptpath='release/scripts' - for dp, dn, df in os.walk(scriptpath): - if 'CVS' in dn: - dn.remove('CVS') - if '.svn' in dn: - dn.remove('.svn') - dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):] - source=[dp+os.sep+f for f in df] - scriptinstall.append(env.Install(dir=dir,source=source)) - - #-- .blender/ui - scriptpath='release/ui' - for dp, dn, df in os.walk(scriptpath): - if 'CVS' in dn: - dn.remove('CVS') - if '.svn' in dn: - dn.remove('.svn') - dir=env['BF_INSTALLDIR']+'/.blender/ui'+dp[len(scriptpath):] - source=[dp+os.sep+f for f in df] - scriptinstall.append(env.Install(dir=dir,source=source)) + #-- .blender/scripts, .blender/ui, .blender/io + scriptpaths=['release/scripts', 'release/ui', 'release/io'] + for scriptpath in scriptpaths: + for dp, dn, df in os.walk(scriptpath): + if 'CVS' in dn: + dn.remove('CVS') + if '.svn' in dn: + dn.remove('.svn') + dir=env['BF_INSTALLDIR']+'/.blender/'+os.path.basename(scriptpath)+dp[len(scriptpath):] + source=[dp+os.sep+f for f in df] + scriptinstall.append(env.Install(dir=dir,source=source)) #-- icons if env['OURPLATFORM']=='linux2': diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 0c063c0192b..559ed537757 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -59,6 +59,7 @@ static void bpy_init_modules( void ) PyModule_AddObject( mod, "data", BPY_rna_module() ); /* PyModule_AddObject( mod, "doc", BPY_rna_doc() ); */ PyModule_AddObject( mod, "types", BPY_rna_types() ); + PyModule_AddObject( mod, "props", BPY_rna_props() ); PyModule_AddObject( mod, "ops", BPY_operator_module() ); PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experemental, consider this a test, especially PyCObject is not meant to be perminant @@ -103,6 +104,7 @@ static PyObject *CreateGlobalDictionary( bContext *C ) {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""}, {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""}, {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""}, {NULL, NULL, 0, NULL} }; @@ -369,70 +371,76 @@ void BPY_run_ui_scripts(bContext *C, int reload) DIR *dir; struct dirent *de; char *file_extension; + char *dirname; char path[FILE_MAX]; - char *dirname= BLI_gethome_folder("ui"); - int filelen; /* filename length */ + char *dirs[] = {"io", "ui", NULL}; + int a, filelen; /* filename length */ PyGILState_STATE gilstate; PyObject *mod; PyObject *sys_path_orig; PyObject *sys_path_new; - - if(!dirname) - return; - - dir = opendir(dirname); - if(!dir) - return; - gilstate = PyGILState_Ensure(); - /* backup sys.path */ - sys_path_orig= PySys_GetObject("path"); - Py_INCREF(sys_path_orig); /* dont free it */ - - sys_path_new= PyList_New(1); - PyList_SET_ITEM(sys_path_new, 0, PyUnicode_FromString(dirname)); - PySys_SetObject("path", sys_path_new); - Py_DECREF(sys_path_new); - // XXX - evil, need to access context BPy_SetContext(C); bpy_import_main_set(CTX_data_main(C)); - - while((de = readdir(dir)) != NULL) { - /* We could stat the file but easier just to let python - * import it and complain if theres a problem */ + + for(a=0; dirs[a]; a++) { + dirname= BLI_gethome_folder(dirs[a]); + + if(!dirname) + continue; + + dir = opendir(dirname); + + if(!dir) + continue; + + /* backup sys.path */ + sys_path_orig= PySys_GetObject("path"); + Py_INCREF(sys_path_orig); /* dont free it */ - file_extension = strstr(de->d_name, ".py"); - - if(file_extension && *(file_extension + 3) == '\0') { - filelen = strlen(de->d_name); - BLI_strncpy(path, de->d_name, filelen-2); /* cut off the .py on copy */ + sys_path_new= PyList_New(1); + PyList_SET_ITEM(sys_path_new, 0, PyUnicode_FromString(dirname)); + PySys_SetObject("path", sys_path_new); + Py_DECREF(sys_path_new); - mod= PyImport_ImportModuleLevel(path, NULL, NULL, NULL, 0); - if (mod) { - if (reload) { - PyObject *mod_orig= mod; - mod= PyImport_ReloadModule(mod); - Py_DECREF(mod_orig); + while((de = readdir(dir)) != NULL) { + /* We could stat the file but easier just to let python + * import it and complain if theres a problem */ + + file_extension = strstr(de->d_name, ".py"); + + if(file_extension && *(file_extension + 3) == '\0') { + filelen = strlen(de->d_name); + BLI_strncpy(path, de->d_name, filelen-2); /* cut off the .py on copy */ + + mod= PyImport_ImportModuleLevel(path, NULL, NULL, NULL, 0); + if (mod) { + if (reload) { + PyObject *mod_orig= mod; + mod= PyImport_ReloadModule(mod); + Py_DECREF(mod_orig); + } } - } - - if(mod) { - Py_DECREF(mod); /* could be NULL from reloading */ - } else { - BPy_errors_to_report(NULL); // TODO - reports - fprintf(stderr, "unable to import \"%s\" %s/%s\n", path, dirname, de->d_name); + + if(mod) { + Py_DECREF(mod); /* could be NULL from reloading */ + } else { + BPy_errors_to_report(NULL); // TODO - reports + fprintf(stderr, "unable to import \"%s\" %s/%s\n", path, dirname, de->d_name); + } + } } - } - closedir(dir); - - PySys_SetObject("path", sys_path_orig); - Py_DECREF(sys_path_orig); + closedir(dir); + + PySys_SetObject("path", sys_path_orig); + Py_DECREF(sys_path_orig); + } bpy_import_main_set(NULL); diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 9b7893a949b..f4fdd0c6194 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -40,6 +40,8 @@ #include "bpy_compat.h" #include "bpy_util.h" +#include "../generic/bpy_internal_import.h" // our own imports + #define PYOP_ATTR_PROP "__props__" #define PYOP_ATTR_UINAME "__label__" #define PYOP_ATTR_IDNAME "__name__" /* use pythons class name */ @@ -177,9 +179,12 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve PyObject *ret= NULL, *py_class_instance, *item= NULL; int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED); PointerRNA ptr_context; - PyObject *py_context; + PointerRNA ptr_operator; + PyObject *py_operator; PyGILState_STATE gilstate = PyGILState_Ensure(); + + bpy_import_main_set(CTX_data_main(C)); BPY_update_modules(); // XXX - the RNA pointers can change so update before running, would like a nicer solutuon for this. @@ -213,20 +218,29 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve RNA_property_collection_end(&iter); } - + + /* set operator pointer RNA as instance "__operator__" attribute */ + RNA_pointer_create(NULL, &RNA_Operator, op, &ptr_operator); + py_operator= pyrna_struct_CreatePyObject(&ptr_operator); + PyObject_SetAttrString(py_class_instance, "__operator__", py_operator); + Py_DECREF(py_operator); + + RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context); if (mode==PYOP_INVOKE) { item= PyObject_GetAttrString(py_class, "invoke"); - args = PyTuple_New(2); - PyTuple_SET_ITEM(args, 1, pyop_dict_from_event(event)); + args = PyTuple_New(3); + + // PyTuple_SET_ITEM "steals" object reference, it is + // an object passed shouldn't be DECREF'ed + PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context)); + PyTuple_SET_ITEM(args, 2, pyop_dict_from_event(event)); } else if (mode==PYOP_EXEC) { - item= PyObject_GetAttrString(py_class, "exec"); + item= PyObject_GetAttrString(py_class, "execute"); args = PyTuple_New(2); - RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context); - py_context = pyrna_struct_CreatePyObject(&ptr_context); - PyTuple_SET_ITEM(args, 1, py_context); + PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context)); } else if (mode==PYOP_POLL) { item= PyObject_GetAttrString(py_class, "poll"); @@ -258,7 +272,8 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve } else if (BPY_flag_from_seq(pyop_ret_flags, ret, &ret_flag) == -1) { /* the returned value could not be converted into a flag */ BPy_errors_to_report(op->reports); - + + ret_flag = OPERATOR_CANCELLED; } /* there is no need to copy the py keyword dict modified by * pyot->py_invoke(), back to the operator props since they are just @@ -271,7 +286,34 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve Py_DECREF(ret); } + /* print operator return value */ + if (mode != PYOP_POLL) { + char flag_str[100]; + char class_name[100]; + BPY_flag_def *flag_def = pyop_ret_flags; + + strcpy(flag_str, ""); + + while(flag_def->name) { + if (ret_flag & flag_def->flag) { + if(flag_str[1]) + sprintf(flag_str, "%s | %s", flag_str, flag_def->name); + else + strcpy(flag_str, flag_def->name); + } + flag_def++; + } + + /* get class name */ + item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME); + Py_DECREF(item); + strcpy(class_name, _PyUnicode_AsString(item)); + + fprintf(stderr, "%s's %s returned %s\n", class_name, mode == PYOP_EXEC ? "execute" : "invoke", flag_str); + } + PyGILState_Release(gilstate); + bpy_import_main_set(NULL); return ret_flag; } @@ -321,7 +363,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) /* api callbacks, detailed checks dont on adding */ if (PyObject_HasAttrString(py_class, "invoke")) ot->invoke= PYTHON_OT_invoke; - if (PyObject_HasAttrString(py_class, "exec")) + if (PyObject_HasAttrString(py_class, "execute")) ot->exec= PYTHON_OT_exec; if (PyObject_HasAttrString(py_class, "poll")) ot->poll= PYTHON_OT_poll; @@ -374,6 +416,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) { PyObject *base_class, *item; + wmOperatorType *ot; char *idname= NULL; @@ -384,8 +427,8 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) {PYOP_ATTR_UINAME, 's', 0, BPY_CLASS_ATTR_OPTIONAL}, {PYOP_ATTR_PROP, 'l', 0, BPY_CLASS_ATTR_OPTIONAL}, {PYOP_ATTR_DESCRIPTION, 's', 0, BPY_CLASS_ATTR_NONE_OK}, - {"exec", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, - {"invoke", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, + {"execute", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, + {"invoke", 'f', 3, BPY_CLASS_ATTR_OPTIONAL}, {"poll", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, {NULL, 0, 0, 0} }; @@ -404,9 +447,10 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) Py_DECREF(item); idname = _PyUnicode_AsString(item); - if (WM_operatortype_find(idname)) { - PyErr_Format( PyExc_AttributeError, "Operator alredy exists with this name \"%s\"", idname); - return NULL; + /* remove if it already exists */ + if ((ot=WM_operatortype_find(idname))) { + Py_XDECREF((PyObject*)ot->pyop_data); + WM_operatortype_remove(idname); } /* If we have properties set, check its a list of dicts */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index a0fb4865548..57a4de21443 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1760,7 +1760,44 @@ PyObject *BPY_rna_types(void) return (PyObject *)self; } +static struct PyMethodDef props_methods[] = { + {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""}, + {NULL, NULL, 0, NULL} +}; +#if PY_VERSION_HEX >= 0x03000000 +static struct PyModuleDef props_module = { + PyModuleDef_HEAD_INIT, + "bpyprops", + "", + -1,/* multiple "initialization" just copies the module dict. */ + props_methods, + NULL, NULL, NULL, NULL +}; +#endif + +PyObject *BPY_rna_props( void ) +{ + PyObject *submodule, *mod; +#if PY_VERSION_HEX >= 0x03000000 + submodule= PyModule_Create(&props_module); +#else /* Py2.x */ + submodule= Py_InitModule3( "bpy.props", props_methods, "" ); +#endif + + mod = PyModule_New("props"); + PyModule_AddObject( submodule, "props", mod ); + + /* INCREF since its its assumed that all these functions return the + * module with a new ref like PyDict_New, since they are passed to + * PyModule_AddObject which steals a ref */ + Py_INCREF(submodule); + + return submodule; +} /* Orphan functions, not sure where they should go */ @@ -1780,7 +1817,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (self) { + if (self && PyCObject_Check(self)) { StructRNA *srna = PyCObject_AsVoidPtr(self); RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max); Py_RETURN_NONE; @@ -1807,7 +1844,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (self) { + if (self && PyCObject_Check(self)) { StructRNA *srna = PyCObject_AsVoidPtr(self); RNA_def_int(srna, id, def, min, max, name, description, soft_min, soft_max); Py_RETURN_NONE; @@ -1834,7 +1871,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (self) { + if (self && PyCObject_Check(self)) { StructRNA *srna = PyCObject_AsVoidPtr(self); RNA_def_boolean(srna, id, def, name, description); Py_RETURN_NONE; @@ -1847,6 +1884,33 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) } } +PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw) +{ + static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL}; + char *id, *name="", *description="", *def=""; + int maxlen=0; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def)) + return NULL; + + if (PyTuple_Size(args) > 0) { + PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. + return NULL; + } + + if (self && PyCObject_Check(self)) { + StructRNA *srna = PyCObject_AsVoidPtr(self); + RNA_def_string(srna, id, def, maxlen, name, description); + Py_RETURN_NONE; + } else { + PyObject *ret = PyTuple_New(2); + PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_StringProperty, NULL)); + PyTuple_SET_ITEM(ret, 1, kw); + Py_INCREF(kw); + return ret; + } +} + /*-------------------- Type Registration ------------------------*/ static int rna_function_arg_count(FunctionRNA *func) diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index a2a3015912b..d2f01b06336 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -63,6 +63,7 @@ typedef struct { PyObject *BPY_rna_module( void ); /*PyObject *BPY_rna_doc( void );*/ PyObject *BPY_rna_types( void ); +PyObject *BPY_rna_props( void ); PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr ); PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop ); @@ -76,6 +77,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop); PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw); +PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw); /* function for registering types */ PyObject *pyrna_basetype_register(PyObject *self, PyObject *args); diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index d5b131583dc..d837892fb4d 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -81,6 +81,7 @@ int BPY_flag_from_seq(BPY_flag_def *flagdef, PyObject *seq, int *flag) char *cstring; PyObject *item; BPY_flag_def *fd; + *flag = 0; if (PySequence_Check(seq)) { i= PySequence_Length(seq); @@ -108,6 +109,9 @@ int BPY_flag_from_seq(BPY_flag_def *flagdef, PyObject *seq, int *flag) error_val= 1; } + if (*flag == 0) + error_val = 1; + if (error_val) { char *buf = bpy_flag_error_str(flagdef); PyErr_SetString(PyExc_AttributeError, buf);