From 29f279e43dfac8e1e08dbe272d7092eab5a8067d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 22 Oct 2011 17:01:54 +0000 Subject: [PATCH 01/18] Render API: add update_progress() function to update progress bar progress from external render engines. Also refactoring to move some render engine registration stuff out of RNA and into render module. --- source/blender/makesrna/intern/rna_render.c | 49 ++----- source/blender/render/CMakeLists.txt | 15 ++ source/blender/render/SConscript | 10 ++ .../blender/render/extern/include/RE_engine.h | 15 +- .../render/intern/source/external_engine.c | 131 +++++++++++++++--- .../bad_level_call_stubs/stubs.c | 5 + 6 files changed, 164 insertions(+), 61 deletions(-) diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index aeff9240b27..f9b110912ad 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -52,41 +52,6 @@ /* RenderEngine */ -static RenderEngineType internal_render_type = { - NULL, NULL, "BLENDER_RENDER", "Blender Render", RE_INTERNAL, NULL, {NULL, NULL, NULL, NULL}}; -#ifdef WITH_GAMEENGINE -static RenderEngineType internal_game_type = { - NULL, NULL, "BLENDER_GAME", "Blender Game", RE_INTERNAL|RE_GAME, NULL, {NULL, NULL, NULL, NULL}}; -#endif - -ListBase R_engines = {NULL, NULL}; - -void RE_engines_init(void) -{ - BLI_addtail(&R_engines, &internal_render_type); -#ifdef WITH_GAMEENGINE - BLI_addtail(&R_engines, &internal_game_type); -#endif -} - -void RE_engines_exit(void) -{ - RenderEngineType *type, *next; - - for(type=R_engines.first; type; type=next) { - next= type->next; - - BLI_remlink(&R_engines, type); - - if(!(type->flag & RE_INTERNAL)) { - if(type->ext.free) - type->ext.free(type->ext.data); - - MEM_freeN(type); - } - } -} - static void engine_render(RenderEngine *engine, struct Scene *scene) { extern FunctionRNA rna_RenderEngine_render_func; @@ -96,7 +61,7 @@ static void engine_render(RenderEngine *engine, struct Scene *scene) FunctionRNA *func; RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr); - func= &rna_RenderEngine_render_func; /* RNA_struct_find_function(&ptr, "render"); */ + func= &rna_RenderEngine_render_func; RNA_parameter_list_create(&list, &ptr, func); RNA_parameter_set_lookup(&list, "scene", &scene); @@ -105,6 +70,8 @@ static void engine_render(RenderEngine *engine, struct Scene *scene) RNA_parameter_list_free(&list); } +/* RenderEngine registration */ + static void rna_RenderEngine_unregister(Main *UNUSED(bmain), StructRNA *type) { RenderEngineType *et= RNA_struct_blender_type_get(type); @@ -148,7 +115,7 @@ static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, vo } /* create a new engine type */ - et= MEM_callocN(sizeof(RenderEngineType), "python buttons engine"); + et= MEM_callocN(sizeof(RenderEngineType), "python render engine"); memcpy(et, &dummyet, sizeof(dummyet)); et->ext.srna= RNA_def_struct(&BLENDER_RNA, et->idname, "RenderEngine"); @@ -276,6 +243,10 @@ static void rna_def_render_engine(BlenderRNA *brna) prop= RNA_def_string(func, "info", "", 0, "Info", ""); RNA_def_property_flag(prop, PROP_REQUIRED); + func= RNA_def_function(srna, "update_progress", "RE_engine_update_progress"); + prop= RNA_def_float(func, "progress", 0, 0.0f, 1.0f, "", "Percentage of render that's done", 0.0f, 1.0f); + RNA_def_property_flag(prop, PROP_REQUIRED); + func= RNA_def_function(srna, "report", "RE_engine_report"); prop= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", ""); RNA_def_property_flag(prop, PROP_REQUIRED); @@ -294,11 +265,11 @@ static void rna_def_render_engine(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REGISTER); prop= RNA_def_property(srna, "bl_use_preview", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_DO_PREVIEW); + RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_PREVIEW); RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); prop= RNA_def_property(srna, "bl_use_postprocess", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_DO_ALL); + RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_USE_POSTPROCESS); RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); RNA_define_verify_sdna(1); diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt index e2222cad2ea..d5b3bd5e311 100644 --- a/source/blender/render/CMakeLists.txt +++ b/source/blender/render/CMakeLists.txt @@ -118,6 +118,17 @@ set(SRC intern/raytrace/vbvh.h ) +if(WITH_PYTHON) + add_definitions(-DWITH_PYTHON) + list(APPEND INC + ../python + ) + + list(APPEND INC_SYS + ${PYTHON_INCLUDE_DIRS} + ) +endif() + if(WITH_IMAGE_OPENEXR) add_definitions(-DWITH_OPENEXR) endif() @@ -136,6 +147,10 @@ if(WITH_CODEC_QUICKTIME) add_definitions(-DWITH_QUICKTIME) endif() +if(WITH_GAMEENGINE) + add_definitions(-DWITH_GAMEENGINE) +endif() + if(APPLE) if(CMAKE_OSX_ARCHITECTURES MATCHES "i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfpmath=sse") diff --git a/source/blender/render/SConscript b/source/blender/render/SConscript index 4ec1ce3de6b..9c724187c27 100644 --- a/source/blender/render/SConscript +++ b/source/blender/render/SConscript @@ -16,6 +16,13 @@ defs_raytrace = [] defs.append('WITH_SMOKE') # TODO, make optional +if env['WITH_BF_PYTHON']: + incs += ' ../python' + incs += ' ' + env['BF_PYTHON_INC'] + defs.append('WITH_PYTHON') + if env['BF_DEBUG']: + defs.append('DEBUG') + if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): if env['WITH_BF_RAYOPTIMIZATION']: cflags_raytrace = env['CCFLAGS'] + env['BF_RAYOPTIMIZATION_SSE_FLAGS'] @@ -49,6 +56,9 @@ if env['WITH_BF_QUICKTIME']: if env['WITH_BF_OPENEXR']: defs.append('WITH_OPENEXR') +if env['WITH_BF_GAMEENGINE']: + defs.append('WITH_GAMEENGINE') + if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index 23b67854a83..8300582c173 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -48,10 +48,10 @@ struct Scene; /* External Engine */ -#define RE_INTERNAL 1 -#define RE_GAME 2 -#define RE_DO_PREVIEW 4 -#define RE_DO_ALL 8 +#define RE_INTERNAL 1 +#define RE_GAME 2 +#define RE_USE_PREVIEW 4 +#define RE_USE_POSTPROCESS 8 extern ListBase R_engines; @@ -71,10 +71,14 @@ typedef struct RenderEngineType { typedef struct RenderEngine { RenderEngineType *type; + struct Render *re; ListBase fullresult; } RenderEngine; +RenderEngine *RE_engine_create(RenderEngineType *type); +void RE_engine_free(RenderEngine *engine); + void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y); void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename); @@ -84,6 +88,7 @@ void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result); int RE_engine_test_break(RenderEngine *engine); void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info); +void RE_engine_update_progress(RenderEngine *engine, float progress); void RE_engine_report(RenderEngine *engine, int type, const char *msg); int RE_engine_render(struct Render *re, int do_all); @@ -93,5 +98,7 @@ int RE_engine_render(struct Render *re, int do_all); void RE_engines_init(void); void RE_engines_exit(void); +RenderEngineType *RE_engines_find(const char *idname); + #endif /* RE_ENGINE_H */ diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index b76a3e16513..9470101d455 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -47,13 +47,89 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#ifdef WITH_PYTHON +#include "BPY_extern.h" +#endif + #include "RE_engine.h" #include "RE_pipeline.h" #include "render_types.h" #include "renderpipeline.h" -/************************** External Engines ***************************/ +/* Render Engine Types */ + +static RenderEngineType internal_render_type = { + NULL, NULL, + "BLENDER_RENDER", "Blender Render", RE_INTERNAL, + NULL, + {NULL, NULL, NULL}}; + +#ifdef WITH_GAMEENGINE + +static RenderEngineType internal_game_type = { + NULL, NULL, + "BLENDER_GAME", "Blender Game", RE_INTERNAL|RE_GAME, + NULL, + {NULL, NULL, NULL}}; + +#endif + +ListBase R_engines = {NULL, NULL}; + +void RE_engines_init(void) +{ + BLI_addtail(&R_engines, &internal_render_type); +#ifdef WITH_GAMEENGINE + BLI_addtail(&R_engines, &internal_game_type); +#endif +} + +void RE_engines_exit(void) +{ + RenderEngineType *type, *next; + + for(type=R_engines.first; type; type=next) { + next= type->next; + + BLI_remlink(&R_engines, type); + + if(!(type->flag & RE_INTERNAL)) { + if(type->ext.free) + type->ext.free(type->ext.data); + + MEM_freeN(type); + } + } +} + +RenderEngineType *RE_engines_find(const char *idname) +{ + RenderEngineType *type; + + type= BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname)); + if(!type) + type= &internal_render_type; + + return type; +} + +/* Create, Free */ + +RenderEngine *RE_engine_create(RenderEngineType *type) +{ + RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine"); + engine->type= type; + + return engine; +} + +void RE_engine_free(RenderEngine *engine) +{ + MEM_freeN(engine); +} + +/* Render Results */ RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h) { @@ -133,11 +209,24 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char { Render *re= engine->re; - re->i.statstr= stats; - re->i.infostr= info; - re->stats_draw(re->sdh, &re->i); - re->i.infostr= NULL; - re->i.statstr= NULL; + /* stats draw callback */ + if(re) { + re->i.statstr= stats; + re->i.infostr= info; + re->stats_draw(re->sdh, &re->i); + re->i.infostr= NULL; + re->i.statstr= NULL; + } +} + +void RE_engine_update_progress(RenderEngine *engine, float progress) +{ + Render *re= engine->re; + + if(re) { + CLAMP(progress, 0.0f, 1.0f); + re->progress(re->prh, progress); + } } void RE_engine_report(RenderEngine *engine, int type, const char *msg) @@ -149,16 +238,17 @@ void RE_engine_report(RenderEngine *engine, int type, const char *msg) int RE_engine_render(Render *re, int do_all) { - RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname)); - RenderEngine engine; + RenderEngineType *type= RE_engines_find(re->r.engine); + RenderEngine *engine; - if(!(type && type->render)) + /* verify if we can render */ + if(!type->render) return 0; - if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW)) + if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW)) return 0; - if(do_all && !(type->flag & RE_DO_ALL)) + if(do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; - if(!do_all && (type->flag & RE_DO_ALL)) + if(!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* create render result */ @@ -172,14 +262,19 @@ int RE_engine_render(Render *re, int do_all) if(re->result==NULL) return 1; - /* external */ - memset(&engine, 0, sizeof(engine)); - engine.type= type; - engine.re= re; + /* render */ + engine = RE_engine_create(type); + engine->re= re; - type->render(&engine, re->scene); + if((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) + scene_update_for_newframe(re->main, re->scene, re->lay); - free_render_result(&engine.fullresult, engine.fullresult.first); + type->render(engine, re->scene); + + + free_render_result(&engine->fullresult, engine->fullresult.first); + + RE_engine_free(engine); return 1; } diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index 788b4e40eb2..8b9ef3835d2 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -375,6 +375,7 @@ struct RenderResult *RE_AcquireResultRead(struct Render *re){return (struct Rend struct RenderResult *RE_AcquireResultWrite(struct Render *re){return (struct RenderResult *) NULL;} struct RenderStats *RE_GetStats(struct Render *re){return (struct RenderStats *) NULL;} void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *result){} +void RE_engine_update_progress(struct RenderEngine *engine, float progress) {} void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result){} void RE_engine_update_stats(struct RenderEngine *engine, char *stats, char *info){} void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, char *filename){} @@ -383,7 +384,11 @@ void RE_AcquireResultImage(struct Render *re, struct RenderResult *rr){} void RE_ReleaseResult(struct Render *re){} void RE_ReleaseResultImage(struct Render *re){} int RE_engine_test_break(struct RenderEngine *engine){return 0;} +void RE_engines_init() {} +void RE_engines_exit() {} void RE_engine_report(struct RenderEngine *engine, int type, const char *msg) {} +ListBase R_engines = {NULL, NULL}; +void RE_engine_free(struct RenderEngine *engine) {} /* python */ struct wmOperatorType *WM_operatortype_find(const char *idname, int quiet){return (struct wmOperatorType *) NULL;} From 726fa618172733f3c4dc5ee85642829400e68f7b Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sat, 22 Oct 2011 18:08:26 +0000 Subject: [PATCH 02/18] Fix for an unhandled exception. Campbell: please include in 2.60a. --- intern/audaspace/intern/AUD_SequencerReader.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/intern/audaspace/intern/AUD_SequencerReader.cpp b/intern/audaspace/intern/AUD_SequencerReader.cpp index c8af1161530..23d50c78508 100644 --- a/intern/audaspace/intern/AUD_SequencerReader.cpp +++ b/intern/audaspace/intern/AUD_SequencerReader.cpp @@ -107,8 +107,14 @@ void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer) if(result < 0) { - handle = new AUD_SequencerHandle(entry, m_device); - handles.push_front(handle); + try + { + handle = new AUD_SequencerHandle(entry, m_device); + handles.push_front(handle); + } + catch(AUD_Exception&) + { + } eit++; } else if(result == 0) From d541a200c2fcac497ec2a52e6d3c8f31f7032f29 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 00:53:50 +0000 Subject: [PATCH 03/18] rename user interface operator properties from 'op' to 'props' --- .../startup/bl_ui/properties_data_mesh.py | 6 ++--- .../scripts/startup/bl_ui/properties_scene.py | 3 +-- release/scripts/startup/bl_ui/space_image.py | 24 +++++++++---------- .../startup/bl_ui/space_userpref_keymap.py | 6 ++--- release/scripts/startup/bl_ui/space_view3d.py | 5 ++-- release/scripts/templates/driver_functions.py | 1 + 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index ff19ece8f94..425b7a601c8 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -51,8 +51,7 @@ class MESH_MT_shape_key_specials(Menu): layout.operator("object.shape_key_transfer", icon='COPY_ID') # icon is not ideal layout.operator("object.join_shapes", icon='COPY_ID') # icon is not ideal layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT') - op = layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix") - op.from_mix = True + layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True class MeshButtonsPanel(): @@ -207,8 +206,7 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel): col = row.column() sub = col.column(align=True) - op = sub.operator("object.shape_key_add", icon='ZOOMIN', text="") - op.from_mix = False + sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="") sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="") diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py index 167cead9a3b..d3859a78bea 100644 --- a/release/scripts/startup/bl_ui/properties_scene.py +++ b/release/scripts/startup/bl_ui/properties_scene.py @@ -115,8 +115,7 @@ class SCENE_PT_keying_sets(SceneButtonsPanel, Panel): subcol = col.column() subcol.operator_context = 'INVOKE_DEFAULT' - op = subcol.operator("anim.keying_set_export", text="Export to File") - op.filepath = "keyingset.py" + subcol.operator("anim.keying_set_export", text="Export to File").filepath = "keyingset.py" col = row.column() col.label(text="Keyframing Settings:") diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index 051854a28f1..50db989a2e2 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -157,24 +157,24 @@ class IMAGE_MT_image_invert(Menu): def draw(self, context): layout = self.layout - op = layout.operator("image.invert", text="Invert Image Colors") - op.invert_r = True - op.invert_g = True - op.invert_b = True + props = layout.operator("image.invert", text="Invert Image Colors") + props.invert_r = True + props.invert_g = True + props.invert_b = True layout.separator() - op = layout.operator("image.invert", text="Invert Red Channel") - op.invert_r = True + props = layout.operator("image.invert", text="Invert Red Channel") + props.invert_r = True - op = layout.operator("image.invert", text="Invert Green Channel") - op.invert_g = True + props = layout.operator("image.invert", text="Invert Green Channel") + props.invert_g = True - op = layout.operator("image.invert", text="Invert Blue Channel") - op.invert_b = True + props = layout.operator("image.invert", text="Invert Blue Channel") + props.invert_b = True - op = layout.operator("image.invert", text="Invert Alpha Channel") - op.invert_a = True + props = layout.operator("image.invert", text="Invert Alpha Channel") + props.invert_a = True class IMAGE_MT_uvs_showhide(Menu): diff --git a/release/scripts/startup/bl_ui/space_userpref_keymap.py b/release/scripts/startup/bl_ui/space_userpref_keymap.py index 2c537efa61b..5e5ce462da9 100644 --- a/release/scripts/startup/bl_ui/space_userpref_keymap.py +++ b/release/scripts/startup/bl_ui/space_userpref_keymap.py @@ -164,11 +164,9 @@ class InputKeyMapPanel: row.label() if (not kmi.is_user_defined) and kmi.is_user_modified: - op = row.operator("wm.keyitem_restore", text="", icon='BACK') - op.item_id = kmi.id + row.operator("wm.keyitem_restore", text="", icon='BACK').item_id = kmi.id else: - op = row.operator("wm.keyitem_remove", text="", icon='X') - op.item_id = kmi.id + row.operator("wm.keyitem_remove", text="", icon='X').item_id = kmi.id # Expanded, additional event settings if kmi.show_expanded: diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index c6a26cd9bbf..1170bce2c14 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -54,11 +54,10 @@ class VIEW3D_HT_header(Header): else: sub.menu("VIEW3D_MT_object") - # Contains buttons like Mode, Pivot, Manipulator, Layer, Mesh Select Mode... - row = layout.row() #XXX Narrowed down vert/edge/face selector in edit mode/solid drawmode. -DingTo + row = layout.row() # XXX Narrowed down vert/edge/face selector in edit mode/solid drawmode. -DingTo row.template_header_3D() - + if obj: # Particle edit if obj.mode == 'PARTICLE_EDIT': diff --git a/release/scripts/templates/driver_functions.py b/release/scripts/templates/driver_functions.py index db9d4fb4678..1c6af0e574f 100644 --- a/release/scripts/templates/driver_functions.py +++ b/release/scripts/templates/driver_functions.py @@ -16,6 +16,7 @@ def invert(f): uuid_store = {} + def slow_value(value, fac, uuid): """ Delay the value by a factor, use a unique string to allow use in multiple drivers without conflict: From 29417887d7e78f31cbefc5d86c156237484e837a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 01:06:38 +0000 Subject: [PATCH 04/18] fix for own mistake r41192 --- source/blender/windowmanager/intern/wm_event_system.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index c798b284c7b..3e9bce651a8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2616,9 +2616,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* exclude arrow keys, esc, etc from text input */ if(type==GHOST_kEventKeyUp) { - if (event.ascii<32 && event.ascii > 0) { - event.ascii= '\0'; - } + event.ascii= '\0'; /* ghost should do this already for key up */ if (event.utf8_buf[0]) { @@ -2626,6 +2624,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U } event.utf8_buf[0]= '\0'; } + else if (event.ascii<32 && event.ascii > 0) { + event.ascii= '\0'; + /* TODO. should this also zero utf8?, dont for now, campbell */ + } /* modifiers */ /* assigning both first and second is strange - campbell */ From 8e2bc6cdbcb47c5f2e4714241fde0ac970f6f58e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 04:13:56 +0000 Subject: [PATCH 05/18] Context menu 'Edit Source' operator no longer needs to be enabled as a build option, improved this so the python file:line lookups are only done when the operator runs (previously this was done for every button, every draw when the build option was enabled). Perhaps this should be hidden when not running with --debug, easy to change. --- CMakeLists.txt | 7 - source/blender/editors/include/UI_interface.h | 5 + source/blender/editors/interface/interface.c | 19 +- .../editors/interface/interface_handlers.c | 41 +-- .../editors/interface/interface_intern.h | 5 - .../blender/editors/interface/interface_ops.c | 239 ++++++++++++++++++ .../windowmanager/intern/wm_operators.c | 83 ------ 7 files changed, 271 insertions(+), 128 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e3247a7d2c..13be77e90eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,9 +213,6 @@ mark_as_advanced(WITH_CXX_GUARDEDALLOC) option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF) mark_as_advanced(WITH_ASSERT_ABORT) -option(WITH_PYTHON_UI_INFO "Allow navigating to UI source from the context menu" OFF) -mark_as_advanced(WITH_PYTHON_UI_INFO) - if(APPLE) if(NOT CMAKE_OSX_ARCHITECTURES) @@ -1330,10 +1327,6 @@ if(WITH_ASSERT_ABORT) add_definitions(-DWITH_ASSERT_ABORT) endif() -if(WITH_PYTHON_UI_INFO) - add_definitions(-DWITH_PYTHON_UI_INFO) -endif() - # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}") # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}") diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 43f6b36f5eb..5e9e7c65f83 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -787,6 +787,7 @@ void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propn void UI_buttons_operatortypes(void); /* Helpers for Operators */ +uiBut *uiContextActiveButton(const struct bContext *C); void uiContextActiveProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); void uiContextActivePropertyHandle(struct bContext *C); void uiContextAnimUpdate(const struct bContext *C); @@ -817,5 +818,9 @@ const char *UI_translate_do_tooltip(const char *msgid); #define IFACE_(msgid) UI_translate_do_iface(msgid) #define TIP_(msgid) UI_translate_do_tooltip(msgid) +/* UI_OT_editsource helpers */ +int UI_editsource_enable_check(void); +void UI_editsource_active_but_test(uiBut *but); + #endif /* UI_INTERFACE_H */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index b7b572e7217..f9991079507 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2562,23 +2562,10 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, if(block->curlayout) ui_layout_add_but(block->curlayout, but); -#ifdef WITH_PYTHON_UI_INFO - { - extern void PyC_FileAndNum_Safe(const char **filename, int *lineno); - - const char *fn; - int lineno= -1; - PyC_FileAndNum_Safe(&fn, &lineno); - if (lineno != -1) { - BLI_strncpy(but->py_dbg_fn, fn, sizeof(but->py_dbg_fn)); - but->py_dbg_ln= lineno; - } - else { - but->py_dbg_fn[0]= '\0'; - but->py_dbg_ln= -1; - } + /* if the 'UI_OT_editsource' is running, extract the source info from the button */ + if (UI_editsource_enable_check()) { + UI_editsource_active_but_test(but); } -#endif /* WITH_PYTHON_UI_INFO */ return but; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 32c4ec21e13..79080eb5f3b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -4443,16 +4443,8 @@ static int ui_but_menu(bContext *C, uiBut *but) } } -#ifdef WITH_PYTHON_UI_INFO - if (but->py_dbg_ln != -1) { - PointerRNA ptr_props; - - WM_operator_properties_create(&ptr_props, "WM_OT_text_edit"); - RNA_string_set(&ptr_props, "filepath", but->py_dbg_fn); - RNA_int_set(&ptr_props, "line", but->py_dbg_ln); - uiItemFullO(layout, "WM_OT_text_edit", "Edit Source", ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0); - } -#endif /* WITH_PYTHON_UI_INFO */ + /* perhaps we should move this into (G.f & G_DEBUG) - campbell */ + uiItemFullO(layout, "UI_OT_editsource", "Edit Source", ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); uiPupMenuEnd(C, pup); @@ -5146,9 +5138,10 @@ void ui_button_active_free(const bContext *C, uiBut *but) } } -static uiBut *ui_context_rna_button_active(const bContext *C) +/* returns the active button with an optional checking function */ +static uiBut *ui_context_button_active(const bContext *C, int (*but_check_cb)(uiBut *)) { - uiBut *rnabut= NULL; + uiBut *but_found= NULL; ARegion *ar= CTX_wm_region(C); @@ -5166,26 +5159,40 @@ static uiBut *ui_context_rna_button_active(const bContext *C) } } - if(activebut && activebut->rnapoin.data) { + if(activebut && (but_check_cb == NULL || but_check_cb(activebut))) { uiHandleButtonData *data= activebut->active; - rnabut= activebut; + but_found= activebut; /* recurse into opened menu, like colorpicker case */ if(data && data->menu && (ar != data->menu->region)) { ar = data->menu->region; } else { - return rnabut; + return but_found; } } else { /* no active button */ - return rnabut; + return but_found; } } - return rnabut; + return but_found; +} + +static int ui_context_rna_button_active_test(uiBut *but) +{ + return (but->rnapoin.data != NULL); +} +static uiBut *ui_context_rna_button_active(const bContext *C) +{ + return ui_context_button_active(C, ui_context_rna_button_active_test); +} + +uiBut *uiContextActiveButton(const struct bContext *C) +{ + return ui_context_button_active(C, NULL); } /* helper function for insert keyframe, reset to default, etc operators */ diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index b7a2227f98a..9d0383c8812 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -252,11 +252,6 @@ struct uiBut { /* pointer back */ uiBlock *block; - -#ifdef WITH_PYTHON_UI_INFO - char py_dbg_fn[240]; - int py_dbg_ln; -#endif }; struct uiBlock { diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 081b528d153..ebd6150cfd0 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -61,6 +61,10 @@ #include "WM_api.h" #include "WM_types.h" +/* only for UI_OT_editsource */ +#include "ED_screen.h" +#include "BKE_main.h" +#include "BLI_ghash.h" /* ********************************************************** */ @@ -474,6 +478,240 @@ static void UI_OT_reports_to_textblock(wmOperatorType *ot) ot->exec= reports_to_text_exec; } + +/* ------------------------------------------------------------------------- */ +/* EditSource Utility funcs and operator, + * note, this includes itility functions and button matching checks */ + +struct uiEditSourceStore { + uiBut but_orig; + GHash *hash; +} uiEditSourceStore; + +struct uiEditSourceButStore { + char py_dbg_fn[240]; + int py_dbg_ln; +} uiEditSourceButStore; + +/* should only ever be set while the edit source operator is running */ +struct uiEditSourceStore *ui_editsource_info= NULL; + +int UI_editsource_enable_check(void) +{ + return (ui_editsource_info != NULL); +} + +static void ui_editsource_active_but_set(uiBut *but) +{ + BLI_assert(ui_editsource_info == NULL); + + ui_editsource_info= MEM_callocN(sizeof(uiEditSourceStore), __func__); + memcpy(&ui_editsource_info->but_orig, but, sizeof(uiBut)); + + ui_editsource_info->hash = BLI_ghash_new(BLI_ghashutil_ptrhash, + BLI_ghashutil_ptrcmp, + __func__); +} + +static void ui_editsource_active_but_clear(void) +{ + BLI_ghash_free(ui_editsource_info->hash, NULL, (GHashValFreeFP)MEM_freeN); + MEM_freeN(ui_editsource_info); + ui_editsource_info= NULL; +} + +static int ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b) +{ +#if 0 + printf("matching buttons: '%s' == '%s'\n", + but_a->drawstr, but_b->drawstr); +#endif + + /* this just needs to be a 'good-enough' comparison so we can know beyond + * reasonable doubt that these buttons are the same between redraws. + * if this fails it only means edit-source fails - campbell */ + if( (but_a->x1 == but_b->x1) && + (but_a->x2 == but_b->x2) && + (but_a->y1 == but_b->y1) && + (but_a->y2 == but_b->y2) && + (but_a->type == but_b->type) && + (but_a->rnaprop == but_b->rnaprop) && + (but_a->optype == but_b->optype) && + (but_a->unit_type == but_b->unit_type) && + strncmp(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR) == 0 + ) { + return TRUE; + } + else { + return FALSE; + } +} + +void UI_editsource_active_but_test(uiBut *but) +{ + extern void PyC_FileAndNum_Safe(const char **filename, int *lineno); + + struct uiEditSourceButStore *but_store= MEM_callocN(sizeof(uiEditSourceButStore), __func__); + + const char *fn; + int lineno= -1; + +#if 0 + printf("comparing buttons: '%s' == '%s'\n", + but->drawstr, ui_editsource_info->but_orig.drawstr); +#endif + + PyC_FileAndNum_Safe(&fn, &lineno); + + if (lineno != -1) { + BLI_strncpy(but_store->py_dbg_fn, fn, + sizeof(but_store->py_dbg_fn)); + but_store->py_dbg_ln= lineno; + } + else { + but_store->py_dbg_fn[0]= '\0'; + but_store->py_dbg_ln= -1; + } + + BLI_ghash_insert(ui_editsource_info->hash, but, but_store); +} + +/* editsource operator component */ + +static ScrArea *biggest_text_view(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa, *big= NULL; + int size, maxsize= 0; + + for(sa= sc->areabase.first; sa; sa= sa->next) { + if(sa->spacetype==SPACE_TEXT) { + size= sa->winx * sa->winy; + if(size > maxsize) { + maxsize= size; + big= sa; + } + } + } + return big; +} + +static int editsource_text_edit(bContext *C, wmOperator *op, + char filepath[240], int line) +{ + struct Main *bmain= CTX_data_main(C); + Text *text; + + for (text=bmain->text.first; text; text=text->id.next) { + if (text->name && BLI_path_cmp(text->name, filepath) == 0) { + break; + } + } + + if (text == NULL) { + text= add_text(filepath, bmain->name); + } + + if (text == NULL) { + BKE_reportf(op->reports, RPT_WARNING, + "file: '%s' can't be opened", filepath); + return OPERATOR_CANCELLED; + } + else { + /* naughty!, find text area to set, not good behavior + * but since this is a dev tool lets allow it - campbell */ + ScrArea *sa= biggest_text_view(C); + if(sa) { + SpaceText *st= sa->spacedata.first; + st->text= text; + } + else { + BKE_reportf(op->reports, RPT_INFO, + "See '%s' in the text editor", text->id.name + 2); + } + + txt_move_toline(text, line - 1, FALSE); + WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); + } + + return OPERATOR_FINISHED; +} + +static int editsource_exec(bContext *C, wmOperator *op) +{ + uiBut *but= uiContextActiveButton(C); + + if (but) { + GHashIterator ghi; + struct uiEditSourceButStore *but_store= NULL; + + ARegion *ar= CTX_wm_region(C); + int ret; + + uiFreeActiveButtons(C, CTX_wm_screen(C)); + + // printf("%s: begin\n", __func__); + + ui_editsource_active_but_set(but); + + /* redraw and get active button python info */ + ED_region_do_draw(C, ar); + + for(BLI_ghashIterator_init(&ghi, ui_editsource_info->hash); + !BLI_ghashIterator_isDone(&ghi); + BLI_ghashIterator_step(&ghi)) + { + uiBut *but= BLI_ghashIterator_getKey(&ghi); + if (but && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but)) { + but_store= BLI_ghashIterator_getValue(&ghi); + break; + } + + } + + if (but_store) { + if (but_store->py_dbg_ln != -1) { + ret= editsource_text_edit(C, op, + but_store->py_dbg_fn, + but_store->py_dbg_ln); + } + else { + BKE_report(op->reports, RPT_ERROR, + "Active button isn't from a script, cant edit source."); + ret= OPERATOR_CANCELLED; + } + } + else { + BKE_report(op->reports, RPT_ERROR, + "Active button match can't be found."); + ret= OPERATOR_CANCELLED; + } + + + ui_editsource_active_but_clear(); + + // printf("%s: end\n", __func__); + + return ret; + } + else { + BKE_report(op->reports, RPT_ERROR, "Active button not found"); + return OPERATOR_CANCELLED; + } +} + +static void UI_OT_editsource(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Reports to Text Block"; + ot->idname= "UI_OT_editsource"; + ot->description= "Edit source code for a button"; + + /* callbacks */ + ot->exec= editsource_exec; +} + + /* ********************************************************* */ /* Registration */ @@ -485,5 +723,6 @@ void UI_buttons_operatortypes(void) WM_operatortype_append(UI_OT_reset_default_button); WM_operatortype_append(UI_OT_copy_to_selected_button); WM_operatortype_append(UI_OT_reports_to_textblock); // XXX: temp? + WM_operatortype_append(UI_OT_editsource); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 5fee5fb2a57..49bb3132204 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -104,11 +104,6 @@ static GHash *global_ops_hash= NULL; -#ifdef WITH_PYTHON_UI_INFO -# include "DNA_text_types.h" -# include "BKE_text.h" -#endif - /* ************ operator API, exported ********** */ @@ -3509,79 +3504,6 @@ static void operatortype_ghash_free_cb(wmOperatorType *ot) MEM_freeN(ot); } -#ifdef WITH_PYTHON_UI_INFO - -static ScrArea *biggest_text_view(bContext *C) -{ - bScreen *sc= CTX_wm_screen(C); - ScrArea *sa, *big= NULL; - int size, maxsize= 0; - - for(sa= sc->areabase.first; sa; sa= sa->next) { - if(sa->spacetype==SPACE_TEXT) { - size= sa->winx * sa->winy; - if(size > maxsize) { - maxsize= size; - big= sa; - } - } - } - return big; -} - -static int wm_text_edit_exec(bContext *C, wmOperator *op) -{ - Main *bmain= CTX_data_main(C); - Text *text; - - char filepath[240]; - int line= RNA_int_get(op->ptr, "line"); - RNA_string_get(op->ptr, "filepath", filepath); - - for (text=bmain->text.first; text; text=text->id.next) { - if (text->name && BLI_path_cmp(text->name, filepath) == 0) { - break; - } - } - - if (text == NULL) { - text= add_text(filepath, bmain->name); - } - - if (text == NULL) { - BKE_reportf(op->reports, RPT_WARNING, "file: '%s' can't be opened", filepath); - return OPERATOR_CANCELLED; - } - else { - /* naughty!, find text area to set, not good behavior - * but since this is a dev tool lets allow it - campbell */ - ScrArea *sa= biggest_text_view(C); - if(sa) { - SpaceText *st= sa->spacedata.first; - st->text= text; - } - - txt_move_toline(text, line - 1, FALSE); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text); - } - - return OPERATOR_FINISHED; -} - -static void WM_OT_text_edit(wmOperatorType *ot) -{ - ot->name= "Edit Text File"; - ot->idname= "WM_OT_text_edit"; - - ot->exec= wm_text_edit_exec; - - RNA_def_string_file_path(ot->srna, "filepath", "", FILE_MAX, "Path", ""); - RNA_def_int(ot->srna, "line", 0, INT_MIN, INT_MAX, "Line", "", 0, INT_MAX); -} - -#endif /* WITH_PYTHON_UI_INFO */ - - /* ******************************************************* */ /* called on initialize WM_exit() */ void wm_operatortype_free(void) @@ -3624,11 +3546,6 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_collada_export); WM_operatortype_append(WM_OT_collada_import); #endif - -#ifdef WITH_PYTHON_UI_INFO - WM_operatortype_append(WM_OT_text_edit); -#endif - } /* circleselect-like modal operators */ From 6c9362a2ea9afbbe0160624cf6b43e15aa2628fd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 04:48:13 +0000 Subject: [PATCH 06/18] fix for incorrect keying set names 'Scale' vs 'Scaling', where 'Scale' was hard coded in auto keyframe when 'Only Insert Needed' option was enabled and would always fail to return a keying set. - to be included in 2.60a. --- source/blender/editors/transform/transform_conversions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 879dc425091..12e65e9d287 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -4590,7 +4590,7 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doScale) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scale"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling"); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } } @@ -4705,7 +4705,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doScale) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scale"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling"); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } } From e58eb5db6f7340494ceeabafe9e7d04377122d70 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 05:08:02 +0000 Subject: [PATCH 07/18] use defines for keying set names to avoid confusing them with text and having some incorrect names (as fixed in last commit) --- source/blender/editors/animation/keyingsets.c | 9 +++++++-- source/blender/editors/armature/editarmature.c | 8 ++++---- source/blender/editors/armature/poseUtils.c | 2 +- source/blender/editors/armature/poselib.c | 4 ++-- source/blender/editors/armature/poseobject.c | 4 ++-- source/blender/editors/include/ED_keyframing.h | 8 ++++++++ source/blender/editors/interface/interface_ops.c | 2 ++ source/blender/editors/object/object_transform.c | 6 +++--- source/blender/editors/space_view3d/view3d_fly.c | 4 ++-- .../blender/editors/space_view3d/view3d_snap.c | 4 ++-- .../editors/transform/transform_conversions.c | 16 ++++++++-------- 11 files changed, 41 insertions(+), 26 deletions(-) diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 7c2f969e187..95324554a06 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -552,7 +552,12 @@ KeyingSet *ANIM_builtin_keyingset_get_named (KeyingSet *prevKS, const char name[ if (strcmp(name, ks->name) == 0) return ks; } - + + /* complain about missing keying sets on debug builds */ +#ifndef NDEBUG + printf("%s: '%s' not found\n", __func__, name); +#endif + /* no matches found */ return NULL; } @@ -687,7 +692,7 @@ KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *tranformK if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (scene->active_keyingset)) return ANIM_scene_get_active_keyingset(scene); else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) - return ANIM_builtin_keyingset_get_named(NULL, "Available"); + return ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_AVAILABLE_ID); else return ANIM_builtin_keyingset_get_named(NULL, tranformKSName); } diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 11fd932eed6..15c8868f9b9 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4948,7 +4948,7 @@ static int pose_clear_transform_generic_exec(bContext *C, wmOperator *op, static int pose_clear_scale_exec(bContext *C, wmOperator *op) { - return pose_clear_transform_generic_exec(C, op, pchan_clear_scale, "Scaling"); + return pose_clear_transform_generic_exec(C, op, pchan_clear_scale, ANIM_KS_SCALING_ID); } void POSE_OT_scale_clear(wmOperatorType *ot) @@ -4969,7 +4969,7 @@ void POSE_OT_scale_clear(wmOperatorType *ot) static int pose_clear_rot_exec(bContext *C, wmOperator *op) { - return pose_clear_transform_generic_exec(C, op, pchan_clear_rot, "Rotation"); + return pose_clear_transform_generic_exec(C, op, pchan_clear_rot, ANIM_KS_ROTATION_ID); } void POSE_OT_rot_clear(wmOperatorType *ot) @@ -4990,7 +4990,7 @@ void POSE_OT_rot_clear(wmOperatorType *ot) static int pose_clear_loc_exec(bContext *C, wmOperator *op) { - return pose_clear_transform_generic_exec(C, op, pchan_clear_loc, "Location"); + return pose_clear_transform_generic_exec(C, op, pchan_clear_loc, ANIM_KS_LOCATION_ID); } void POSE_OT_loc_clear(wmOperatorType *ot) @@ -5011,7 +5011,7 @@ void POSE_OT_loc_clear(wmOperatorType *ot) static int pose_clear_transforms_exec(bContext *C, wmOperator *op) { - return pose_clear_transform_generic_exec(C, op, pchan_clear_transforms, "LocRotScale"); + return pose_clear_transform_generic_exec(C, op, pchan_clear_transforms, ANIM_KS_LOC_ROT_SCALE_ID); } void POSE_OT_transforms_clear(wmOperatorType *ot) diff --git a/source/blender/editors/armature/poseUtils.c b/source/blender/editors/armature/poseUtils.c index 4b22d76ad0b..5c98fdc08bd 100644 --- a/source/blender/editors/armature/poseUtils.c +++ b/source/blender/editors/armature/poseUtils.c @@ -223,7 +223,7 @@ void poseAnim_mapping_autoKeyframe (bContext *C, Scene *scene, Object *ob, ListB { /* insert keyframes as necessary if autokeyframing */ if (autokeyframe_cfra_can_key(scene, &ob->id)) { - KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Whole Character"); + KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_WHOLE_CHARACTER_ID); ListBase dsources = {NULL, NULL}; tPChanFCurveLink *pfl; diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index 8e9f5c7543c..064defb1aef 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -433,7 +433,7 @@ static int poselib_add_exec (bContext *C, wmOperator *op) bAction *act = poselib_validate(ob); bPose *pose= (ob) ? ob->pose : NULL; TimeMarker *marker; - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Whole Character"); /* this includes custom props :)*/ + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_WHOLE_CHARACTER_ID); /* this includes custom props :)*/ int frame= RNA_int_get(op->ptr, "frame"); char name[64]; @@ -903,7 +903,7 @@ static void poselib_keytag_pose (bContext *C, Scene *scene, tPoseLib_PreviewData bAction *act= pld->act; bActionGroup *agrp; - KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Whole Character"); + KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_WHOLE_CHARACTER_ID); ListBase dsources = {NULL, NULL}; short autokey = autokeyframe_cfra_can_key(scene, &pld->ob->id); diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index a978f327993..beae9c12bfe 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -1151,7 +1151,7 @@ static int pose_paste_exec (bContext *C, wmOperator *op) int selOnly= RNA_boolean_get(op->ptr, "selected_mask"); /* get KeyingSet to use */ - KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale"); + KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOC_ROT_SCALE_ID); /* sanity checks */ if ELEM(NULL, ob, ob->pose) @@ -2165,7 +2165,7 @@ static int pose_flip_quats_exec (bContext *C, wmOperator *UNUSED(op)) { Scene *scene= CTX_data_scene(C); Object *ob= object_pose_armature_get(CTX_data_active_object(C)); - KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); + KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID); /* loop through all selected pchans, flipping and keying (as needed) */ CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pose_bones) diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index 8dd543d8f63..eda84d0e7a4 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -317,6 +317,14 @@ typedef enum eAnimFilterFlags { int ED_autokeyframe_object(struct bContext *C, struct Scene *scene, struct Object *ob, struct KeyingSet *ks); int ED_autokeyframe_pchan(struct bContext *C, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, struct KeyingSet *ks); +/* Names for builtin keying sets so we don't confuse these with labels/text, + * defined in python script: keyingsets_builtins.py */ +#define ANIM_KS_LOCATION_ID "Location" +#define ANIM_KS_ROTATION_ID "Rotation" +#define ANIM_KS_SCALING_ID "Scaling" +#define ANIM_KS_LOC_ROT_SCALE_ID "LocRotScale" +#define ANIM_KS_AVAILABLE_ID "Available" +#define ANIM_KS_WHOLE_CHARACTER_ID "Whole Character" #ifdef __cplusplus } diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index ebd6150cfd0..eee771cbd93 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -648,10 +648,12 @@ static int editsource_exec(bContext *C, wmOperator *op) ARegion *ar= CTX_wm_region(C); int ret; + /* needed else the active button does not get tested */ uiFreeActiveButtons(C, CTX_wm_screen(C)); // printf("%s: begin\n", __func__); + /* take care not to return before calling ui_editsource_active_but_clear */ ui_editsource_active_but_set(but); /* redraw and get active button python info */ diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 4ca7d272503..6d721e828af 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -252,7 +252,7 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, static int object_location_clear_exec(bContext *C, wmOperator *op) { - return object_clear_transform_generic_exec(C, op, object_clear_loc, "Location"); + return object_clear_transform_generic_exec(C, op, object_clear_loc, ANIM_KS_LOCATION_ID); } void OBJECT_OT_location_clear(wmOperatorType *ot) @@ -272,7 +272,7 @@ void OBJECT_OT_location_clear(wmOperatorType *ot) static int object_rotation_clear_exec(bContext *C, wmOperator *op) { - return object_clear_transform_generic_exec(C, op, object_clear_rot, "Rotation"); + return object_clear_transform_generic_exec(C, op, object_clear_rot, ANIM_KS_ROTATION_ID); } void OBJECT_OT_rotation_clear(wmOperatorType *ot) @@ -292,7 +292,7 @@ void OBJECT_OT_rotation_clear(wmOperatorType *ot) static int object_scale_clear_exec(bContext *C, wmOperator *op) { - return object_clear_transform_generic_exec(C, op, object_clear_scale, "Scaling"); + return object_clear_transform_generic_exec(C, op, object_clear_scale, ANIM_KS_SCALING_ID); } void OBJECT_OT_scale_clear(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index b66440738b2..8e2a9c30193 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -699,11 +699,11 @@ static void move_camera(bContext* C, RegionView3D* rv3d, FlyInfo* fly, int orien * TODO: need to check in future that frame changed before doing this */ if (orientationChanged) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); } if (positionChanged) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index fa3007d2fb7..c69d2159ac2 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -495,7 +495,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) } else { - struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location"); + struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob->mode & OB_MODE_POSE) { @@ -625,7 +625,7 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) } else { - struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location"); + struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob->mode & OB_MODE_POSE) { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 12e65e9d287..1d28b594e57 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -4582,21 +4582,21 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, /* insert keyframes for the affected sets of channels using the builtin KeyingSets found */ if (doLoc) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doRot) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doScale) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } } /* insert keyframe in all (transform) channels */ else { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } @@ -4697,21 +4697,21 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o } if (doLoc) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doRot) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } if (doScale) { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } } /* insert keyframe in all (transform) channels */ else { - KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "LocRotScale"); + KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID); ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra); } From 0664868aec515111fe419a7ec73c19441cd1e19d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 05:56:55 +0000 Subject: [PATCH 08/18] BLI_make_file_string wasn't guaranteed to initialize the resulting path, some parts of the code accounted for this but most not, always initialize the string to "". --- source/blender/blenlib/intern/path_util.c | 15 ++++++++++++--- source/blender/blenloader/intern/writefile.c | 1 - source/blender/editors/render/render_preview.c | 2 -- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index d9176c5f162..d28c1e29820 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1257,9 +1257,18 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, { int sl; - if (!string || !dir || !file) return; /* We don't want any NULLs */ - - string[0]= 0; /* ton */ + if (string) { + /* ensure this is always set even if dir/file are NULL */ + string[0]= '\0'; + + if (ELEM(NULL, dir, file)) { + return; /* We don't want any NULLs */ + } + } + else { + return; /* string is NULL, probably shouldnt happen but return anyway */ + } + /* we first push all slashes into unix mode, just to make sure we don't get any mess with slashes later on. -jesterKing */ diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 752677d047d..45eaa6d0156 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2699,7 +2699,6 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL } } - userfilename[0]= '\0'; /* ensure its initialized */ BLI_make_file_string(G.main->name, userfilename, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE); write_user_block= (BLI_path_cmp(filepath, userfilename) == 0); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 697cddfcee0..af2cd431a10 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -122,8 +122,6 @@ ImBuf* get_brush_icon(Brush *brush) if (!(brush->icon_imbuf)) { folder= BLI_get_folder(BLENDER_DATAFILES, "brushicons"); - path[0]= 0; - BLI_make_file_string(G.main->name, path, folder, brush->icon_filepath); if (path[0]) From a0529a8ae82836f41dddc3b7de22b58e1dcc11b8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 06:56:39 +0000 Subject: [PATCH 09/18] py/rna api crash fix: getting event.ascii would crash blender (strange nobody noticed this, seems its been there for over a year???). --- source/blender/makesrna/intern/rna_wm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 676fe1e092d..594b0abb93d 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -460,14 +460,14 @@ static PointerRNA rna_OperatorMacro_properties_get(PointerRNA *ptr) static void rna_Event_ascii_get(PointerRNA *ptr, char *value) { - wmEvent *event= (wmEvent*)ptr->id.data; + wmEvent *event= (wmEvent*)ptr->data; value[0]= event->ascii; value[1]= '\0'; } static int rna_Event_ascii_length(PointerRNA *ptr) { - wmEvent *event= (wmEvent*)ptr->id.data; + wmEvent *event= (wmEvent*)ptr->data; return (event->ascii)? 1 : 0; } From fcb88306b4794e75114038cdc90026ffa3b375fc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 07:03:57 +0000 Subject: [PATCH 10/18] rna access to event.unicode so scripts can get unicode text input. --- source/blender/makesrna/intern/rna_wm.c | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 594b0abb93d..dc9f003ab1a 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -471,6 +471,36 @@ static int rna_Event_ascii_length(PointerRNA *ptr) return (event->ascii)? 1 : 0; } +static void rna_Event_unicode_get(PointerRNA *ptr, char *value) +{ + /* utf8 buf isnt \0 terminated */ + wmEvent *event= (wmEvent*)ptr->data; + size_t len= 0; + + if (event->utf8_buf[0]) { + BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len); + if (len > 0) { + memcpy(value, event->utf8_buf, len); + } + } + + value[len]= '\0'; +} + +static int rna_Event_unicode_length(PointerRNA *ptr) +{ + + wmEvent *event= (wmEvent*)ptr->data; + if (event->utf8_buf[0]) { + size_t len= 0; + BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len); + return (int)len; + } + else { + return 0; + } +} + static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value) { wmWindow *win= (wmWindow*)ptr->data; @@ -1358,6 +1388,11 @@ static void rna_def_event(BlenderRNA *brna) RNA_def_property_ui_text(prop, "ASCII", "Single ASCII character for this event"); + prop= RNA_def_property(srna, "unicode", PROP_STRING, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_string_funcs(prop, "rna_Event_unicode_get", "rna_Event_unicode_length", NULL); + RNA_def_property_ui_text(prop, "Unicode", "Single unicode character for this event"); + /* enums */ prop= RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "val"); From f5b37d40ca51f71bed5d588f2c887bf12ab4ebdc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 07:51:21 +0000 Subject: [PATCH 11/18] set pythons 'sys.stdout' encoding to utf-8 and use surrogateescape error handler. without this printing a unicode string may raise an error which is a real pain especially since script authors often forget this and print the path of a file for example on export which can make a script fail outright when writing to paths with certain encodings. --- source/blender/python/intern/bpy_interface.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index cfd8d9f433b..a96b8209d91 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -203,6 +203,13 @@ void BPY_python_start(int argc, const char **argv) /* allow to use our own included python */ PyC_SetHomePath(BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL)); + /* without this the sys.stdout may be set to 'ascii' + * (it is on my system at least), where printing unicode values will raise + * an error, this is highly annoying, another stumbling block for devs, + * so use a more relaxed error handler and enforce utf-8 since the rest of + * blender is utf-8 too - campbell */ + BLI_setenv("PYTHONIOENCODING", "utf-8:surrogateescape"); + /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to * parse from the 'sysconfig' module which is used by 'site', * so for now disable site. alternatively we could copy the file. */ From 0f5f502f9e433e6f353ccd126e575d9ff9f85689 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 12:17:24 +0000 Subject: [PATCH 12/18] minor formatting edits (80 char width) --- release/scripts/modules/bpy_types.py | 133 +++++++++++++++------- release/scripts/modules/console_python.py | 28 +++-- 2 files changed, 113 insertions(+), 48 deletions(-) diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index cee0712e814..088e239e9a5 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -16,7 +16,7 @@ # # ##### END GPL LICENSE BLOCK ##### -# +# from _bpy import types as bpy_types import _bpy @@ -34,7 +34,8 @@ class Context(StructRNA): def copy(self): from types import BuiltinMethodType new_context = {} - generic_attrs = list(StructRNA.__dict__.keys()) + ["bl_rna", "rna_type", "copy"] + generic_attrs = (list(StructRNA.__dict__.keys()) + + ["bl_rna", "rna_type", "copy"]) for attr in dir(self): if not (attr.startswith("_") or attr in generic_attrs): value = getattr(self, attr) @@ -52,14 +53,19 @@ class Library(bpy_types.ID): """ID data blocks which use this library""" import bpy - # See: readblenentry.c, IDTYPE_FLAGS_ISLINKABLE, we could make this an attribute in rna. - attr_links = "actions", "armatures", "brushes", "cameras", \ - "curves", "grease_pencil", "groups", "images", \ - "lamps", "lattices", "materials", "metaballs", \ - "meshes", "node_groups", "objects", "scenes", \ - "sounds", "speakers", "textures", "texts", "fonts", "worlds" + # See: readblenentry.c, IDTYPE_FLAGS_ISLINKABLE, + # we could make this an attribute in rna. + attr_links = ("actions", "armatures", "brushes", "cameras", + "curves", "grease_pencil", "groups", "images", + "lamps", "lattices", "materials", "metaballs", + "meshes", "node_groups", "objects", "scenes", + "sounds", "speakers", "textures", "texts", + "fonts", "worlds") - return tuple(id_block for attr in attr_links for id_block in getattr(bpy.data, attr) if id_block.library == self) + return tuple(id_block + for attr in attr_links + for id_block in getattr(bpy.data, attr) + if id_block.library == self) class Texture(bpy_types.ID): @@ -69,13 +75,21 @@ class Texture(bpy_types.ID): def users_material(self): """Materials that use this texture""" import bpy - return tuple(mat for mat in bpy.data.materials if self in [slot.texture for slot in mat.texture_slots if slot]) + return tuple(mat for mat in bpy.data.materials + if self in [slot.texture + for slot in mat.texture_slots + if slot] + ) @property def users_object_modifier(self): """Object modifiers that use this texture""" import bpy - return tuple(obj for obj in bpy.data.objects if self in [mod.texture for mod in obj.modifiers if mod.type == 'DISPLACE']) + return tuple(obj for obj in bpy.data.objects if + self in [mod.texture + for mod in obj.modifiers + if mod.type == 'DISPLACE'] + ) class Group(bpy_types.ID): @@ -85,7 +99,8 @@ class Group(bpy_types.ID): def users_dupli_group(self): """The dupli group this group is used in""" import bpy - return tuple(obj for obj in bpy.data.objects if self == obj.dupli_group) + return tuple(obj for obj in bpy.data.objects + if self == obj.dupli_group) class Object(bpy_types.ID): @@ -95,19 +110,22 @@ class Object(bpy_types.ID): def children(self): """All the children of this object""" import bpy - return tuple(child for child in bpy.data.objects if child.parent == self) + return tuple(child for child in bpy.data.objects + if child.parent == self) @property def users_group(self): """The groups this object is in""" import bpy - return tuple(group for group in bpy.data.groups if self in group.objects[:]) + return tuple(group for group in bpy.data.groups + if self in group.objects[:]) @property def users_scene(self): """The scenes this object is in""" import bpy - return tuple(scene for scene in bpy.data.scenes if self in scene.objects[:]) + return tuple(scene for scene in bpy.data.scenes + if self in scene.objects[:]) class _GenericBone: @@ -118,13 +136,14 @@ class _GenericBone: __slots__ = () def translate(self, vec): - """Utility function to add *vec* to the head and tail of this bone.""" + """Utility function to add *vec* to the head and tail of this bone""" self.head += vec self.tail += vec def parent_index(self, parent_test): """ - The same as 'bone in other_bone.parent_recursive' but saved generating a list. + The same as 'bone in other_bone.parent_recursive' + but saved generating a list. """ # use the name so different types can be tested. name = parent_test.name @@ -187,7 +206,9 @@ class _GenericBone: @property def length(self): - """The distance from head to tail, when set the head is moved to fit the length.""" + """ The distance from head to tail, + when set the head is moved to fit the length. + """ return self.vector.length @length.setter @@ -196,7 +217,9 @@ class _GenericBone: @property def vector(self): - """The direction this bone is pointing. Utility function for (tail - head)""" + """ The direction this bone is pointing. + Utility function for (tail - head) + """ return (self.tail - self.head) @property @@ -222,7 +245,8 @@ class _GenericBone: """ Returns a chain of children with the same base name as this bone. Only direct chains are supported, forks caused by multiple children - with matching base names will terminate the function and not be returned. + with matching base names will terminate the function + and not be returned. """ basename = self.basename chain = [] @@ -241,7 +265,9 @@ class _GenericBone: chain.append(child) else: if len(children_basename): - print("multiple basenames found, this is probably not what you want!", self.name, children_basename) + print("multiple basenames found, " + "this is probably not what you want!", + self.name, children_basename) break @@ -284,13 +310,18 @@ class EditBone(StructRNA, _GenericBone, metaclass=StructMetaPropGroup): def transform(self, matrix, scale=True, roll=True): """ - Transform the the bones head, tail, roll and envelope (when the matrix has a scale component). + Transform the the bones head, tail, roll and envelope + (when the matrix has a scale component). :arg matrix: 3x3 or 4x4 transformation matrix. :type matrix: :class:`mathutils.Matrix` :arg scale: Scale the bone envelope by the matrix. :type scale: bool - :arg roll: Correct the roll to point in the same relative direction to the head and tail. + :arg roll: + + Correct the roll to point in the same relative + direction to the head and tail. + :type roll: bool """ from mathutils import Vector @@ -321,11 +352,23 @@ class Mesh(bpy_types.ID): Make a mesh from a list of vertices/edges/faces Until we have a nicer way to make geometry, use this. - :arg vertices: float triplets each representing (X, Y, Z) eg: [(0.0, 1.0, 0.5), ...]. + :arg vertices: + + float triplets each representing (X, Y, Z) + eg: [(0.0, 1.0, 0.5), ...]. + :type vertices: iterable object - :arg edges: int pairs, each pair contains two indices to the *vertices* argument. eg: [(1, 2), ...] + :arg edges: + + int pairs, each pair contains two indices to the + *vertices* argument. eg: [(1, 2), ...] + :type edges: iterable object - :arg faces: iterator of faces, each faces contains three or four indices to the *vertices* argument. eg: [(5, 6, 8, 9), (1, 2, 3), ...] + :arg faces: + + iterator of faces, each faces contains three or four indices to + the *vertices* argument. eg: [(5, 6, 8, 9), (1, 2, 3), ...] + :type faces: iterable object """ self.vertices.add(len(vertices)) @@ -419,7 +462,10 @@ class Text(bpy_types.ID): def users_logic(self): """Logic bricks that use this text""" import bpy - return tuple(obj for obj in bpy.data.objects if self in [cont.text for cont in obj.game.controllers if cont.type == 'PYTHON']) + return tuple(obj for obj in bpy.data.objects + if self in [cont.text for cont in obj.game.controllers + if cont.type == 'PYTHON'] + ) # values are module: [(cls, path, line), ...] TypeMap = {} @@ -510,10 +556,11 @@ class Operator(StructRNA, metaclass=OrderedMeta): return super().__delattr__(attr) def as_keywords(self, ignore=()): - """ Return a copy of the properties as a dictionary. - """ + """Return a copy of the properties as a dictionary""" ignore = ignore + ("rna_type",) - return {attr: getattr(self, attr) for attr in self.properties.rna_type.properties.keys() if attr not in ignore} + return {attr: getattr(self, attr) + for attr in self.properties.rna_type.properties.keys() + if attr not in ignore} class Macro(StructRNA, metaclass=OrderedMeta): @@ -553,7 +600,8 @@ class _GenericUI: operator_context_default = self.layout.operator_context for func in draw_ls._draw_funcs: - # so bad menu functions don't stop the entire menu from drawing + # so bad menu functions don't stop + # the entire menu from drawing try: func(self, context) except: @@ -569,13 +617,19 @@ class _GenericUI: @classmethod def append(cls, draw_func): - """Append a draw function to this menu, takes the same arguments as the menus draw function.""" + """ + Append a draw function to this menu, + takes the same arguments as the menus draw function + """ draw_funcs = cls._dyn_ui_initialize() draw_funcs.append(draw_func) @classmethod def prepend(cls, draw_func): - """Prepend a draw function to this menu, takes the same arguments as the menus draw function.""" + """ + Prepend a draw function to this menu, takes the same arguments as + the menus draw function + """ draw_funcs = cls._dyn_ui_initialize() draw_funcs.insert(0, draw_func) @@ -615,7 +669,8 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): # collect paths files = [] for directory in searchpaths: - files.extend([(f, os.path.join(directory, f)) for f in os.listdir(directory)]) + files.extend([(f, os.path.join(directory, f)) + for f in os.listdir(directory)]) files.sort() @@ -635,9 +690,11 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): props.menu_idname = self.bl_idname def draw_preset(self, context): - """Define these on the subclass - - preset_operator - - preset_subdir + """ + Define these on the subclass + - preset_operator + - preset_subdir """ import bpy - self.path_menu(bpy.utils.preset_paths(self.preset_subdir), self.preset_operator) + self.path_menu(bpy.utils.preset_paths(self.preset_subdir), + self.preset_operator) diff --git a/release/scripts/modules/console_python.py b/release/scripts/modules/console_python.py index f11ccf84f0b..6c49283b3e1 100644 --- a/release/scripts/modules/console_python.py +++ b/release/scripts/modules/console_python.py @@ -16,11 +16,11 @@ # # ##### END GPL LICENSE BLOCK ##### -# +# import sys import bpy -language_id = 'python' +language_id = "python" # store our own __main__ module, not 100% needed # but python expects this in some places @@ -28,8 +28,8 @@ _BPY_MAIN_OWN = True def add_scrollback(text, text_type): - for l in text.split('\n'): - bpy.ops.console.scrollback_append(text=l.replace('\t', ' '), + for l in text.split("\n"): + bpy.ops.console.scrollback_append(text=l.replace("\t", " "), type=text_type) @@ -81,7 +81,8 @@ def get_console(console_id): console, stdout, stderr = console_data # XXX, bug in python 3.1.2, 3.2 ? (worked in 3.1.1) - # seems there is no way to clear StringIO objects for writing, have to make new ones each time. + # seems there is no way to clear StringIO objects for writing, have to + # make new ones each time. import io stdout = io.StringIO() stderr = io.StringIO() @@ -99,7 +100,8 @@ def get_console(console_id): replace_help(namespace) - console = InteractiveConsole(locals=namespace, filename="") + console = InteractiveConsole(locals=namespace, + filename="") console.push("from mathutils import *") console.push("from math import *") @@ -265,7 +267,8 @@ def autocomplete(context): # Separate autocomplete output by command prompts if scrollback != '': - bpy.ops.console.scrollback_append(text=sc.prompt + current_line.body, type='INPUT') + bpy.ops.console.scrollback_append(text=sc.prompt + current_line.body, + type='INPUT') # Now we need to copy back the line from blender back into the # text editor. This will change when we don't use the text editor @@ -296,10 +299,15 @@ def banner(context): add_scrollback("Execute: Enter", 'OUTPUT') add_scrollback("Autocomplete: Ctrl+Space", 'OUTPUT') add_scrollback("Ctrl +/- Wheel: Zoom", 'OUTPUT') - add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bpy.utils, bgl, blf, mathutils", 'OUTPUT') - add_scrollback("Convenience Imports: from mathutils import *; from math import *", 'OUTPUT') + add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, " + "bpy.props, bpy.types, bpy.context, bpy.utils, " + "bgl, blf, mathutils", + 'OUTPUT') + add_scrollback("Convenience Imports: from mathutils import *; " + "from math import *", 'OUTPUT') add_scrollback("", 'OUTPUT') - # add_scrollback(" WARNING!!! Blender 2.5 API is subject to change, see API reference for more info", 'ERROR') + # add_scrollback(" WARNING!!! Blender 2.5 API is subject to change, " + # "see API reference for more info", 'ERROR') # add_scrollback("", 'OUTPUT') sc.prompt = PROMPT From 398fd3621ce62392f1bfcb40757643f9fac19931 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 12:21:41 +0000 Subject: [PATCH 13/18] committing 'a' to merge into the tag --- source/blender/blenkernel/BKE_blender.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 0cad398995a..f5684810e14 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -51,7 +51,7 @@ extern "C" { /* used by packaging tools */ /* can be left blank, otherwise a,b,c... etc with no quotes */ -#define BLENDER_VERSION_CHAR +#define BLENDER_VERSION_CHAR a /* alpha/beta/rc/release, docs use this */ #define BLENDER_VERSION_CYCLE alpha From d1e04d376dfa01037b5671abe53f8fb841be9173 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 23 Oct 2011 12:58:19 +0000 Subject: [PATCH 14/18] RNA: fix collection iterator issue in c++ api with msvc. --- source/blender/makesrna/intern/makesrna.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 871cbad6152..42b78e3ff7e 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -2662,6 +2662,11 @@ static const char *cpp_classes = "" "class Array {\n" "public:\n" " T data[Tsize];\n" +"\n" +" Array() {}\n" +" Array(const Array& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n" +" const Array& operator=(const Array& other) { memcpy(data, other.data, sizeof(T)*Tsize); return *this; }\n" +"\n" " operator T*() { return data; }\n" "};\n" "\n" @@ -2678,8 +2683,6 @@ static const char *cpp_classes = "" " operator bool(void)\n" " { return iter.valid != 0; }\n" " const CollectionIterator& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n" -" const CollectionIterator& operator=(const CollectionIterator& copy)\n" -" { if(init) Tend(&iter); iter= copy.iter; if(iter.internal) iter.internal= MEM_dupallocN(iter.internal); t= copy.t; init= copy.init; return *this; }\n" "\n" " T& operator*(void) { return t; }\n" " T* operator->(void) { return &t; }\n" @@ -2690,6 +2693,8 @@ static const char *cpp_classes = "" " { if(init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n" "\n" "private:\n" +" const CollectionIterator& operator=(const CollectionIterator& copy) {}\n" +"" " CollectionPropertyIterator iter;\n" " T t;\n" " bool init;\n" @@ -2700,8 +2705,8 @@ static const char *cpp_classes = "" "public:\n" " Collection(const PointerRNA& p) : ptr(p) {}\n" "\n" -" CollectionIterator begin()\n" -" { CollectionIterator iter; iter.begin(ptr); return iter; }\n" +" void begin(CollectionIterator& iter)\n" +" { iter.begin(ptr); }\n" " CollectionIterator end()\n" " { return CollectionIterator(); } /* test */ \n" "\n" From 66ef02aaa332039c2338bd4680aba34c748fb319 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 23 Oct 2011 13:00:41 +0000 Subject: [PATCH 15/18] Code refactoring: split main 3d view drawing function into object drawing and info overlay drawing functions. --- source/blender/editors/gpencil/drawgpencil.c | 10 +--- source/blender/editors/include/ED_gpencil.h | 3 +- .../blender/editors/space_view3d/drawmesh.c | 1 - .../editors/space_view3d/view3d_draw.c | 50 ++++++++++++------- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 8e83b01fc2f..07858f7182c 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -778,7 +778,7 @@ void draw_gpencil_view2d (bContext *C, short onlyv2d) * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes */ -void draw_gpencil_view3d_ext (Scene *scene, View3D *v3d, ARegion *ar, short only3d) +void draw_gpencil_view3d (Scene *scene, View3D *v3d, ARegion *ar, short only3d) { bGPdata *gpd; int dflag = 0; @@ -809,12 +809,4 @@ void draw_gpencil_view3d_ext (Scene *scene, View3D *v3d, ARegion *ar, short only gp_draw_data(gpd, rect.xmin, rect.ymin, rect.xmax, rect.ymax, CFRA, dflag); } -void draw_gpencil_view3d (bContext *C, short only3d) -{ - ARegion *ar= CTX_wm_region(C); - View3D *v3d= CTX_wm_view3d(C); - Scene *scene= CTX_data_scene(C); - draw_gpencil_view3d_ext(scene, v3d, ar, only3d); -} - /* ************************************************** */ diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index bfd16487ae5..a640b5c911c 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -78,8 +78,7 @@ void ED_operatortypes_gpencil(void); void draw_gpencil_2dimage(struct bContext *C, struct ImBuf *ibuf); void draw_gpencil_view2d(struct bContext *C, short onlyv2d); -void draw_gpencil_view3d(struct bContext *C, short only3d); -void draw_gpencil_view3d_ext(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, short only3d); +void draw_gpencil_view3d(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, short only3d); void gpencil_panel_standard(const struct bContext *C, struct Panel *pa); diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 76263f5ac3d..df2a7787f79 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -55,7 +55,6 @@ #include "BKE_paint.h" #include "BKE_property.h" - #include "BIF_gl.h" #include "BIF_glutil.h" diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index ba9faf7682e..291ef7a3bbf 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1917,7 +1917,7 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d) v3d->zbuf= TRUE; glEnable(GL_DEPTH_TEST); - draw_gpencil_view3d_ext(scene, v3d, ar, 1); + draw_gpencil_view3d(scene, v3d, ar, 1); v3d->zbuf= zbuf; @@ -2151,6 +2151,7 @@ static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d) CustomDataMask ED_view3d_datamask(Scene *scene, View3D *v3d) { CustomDataMask mask= 0; + if((v3d->drawtype == OB_TEXTURE) || ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX))) { mask |= CD_MASK_MTFACE | CD_MASK_MCOL; @@ -2331,7 +2332,7 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, /* must be before xray draw which clears the depth buffer */ if(v3d->zbuf) glDisable(GL_DEPTH_TEST); - draw_gpencil_view3d_ext(scene, v3d, ar, 1); + draw_gpencil_view3d(scene, v3d, ar, 1); if(v3d->zbuf) glEnable(GL_DEPTH_TEST); /* transp and X-ray afterdraw stuff */ @@ -2352,7 +2353,7 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, ED_region_pixelspace(ar); /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ - draw_gpencil_view3d_ext(scene, v3d, ar, 0); + draw_gpencil_view3d(scene, v3d, ar, 0); /* freeing the images again here could be done after the operator runs, leaving for now */ GPU_free_images_anim(); @@ -2513,16 +2514,14 @@ static void draw_viewport_fps(Scene *scene, ARegion *ar) } /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */ -void view3d_main_area_draw(const bContext *C, ARegion *ar) +static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const char **grid_unit) { Scene *scene= CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d= CTX_wm_region_view3d(C); Base *base; - Object *ob; float backcol[3]; unsigned int lay_used; - const char *grid_unit= NULL; /* shadow buffers, before we setup matrices */ if(draw_glsl_material(scene, NULL, v3d, v3d->drawtype)) @@ -2572,7 +2571,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) if((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) { if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) { - drawfloor(scene, v3d, &grid_unit); + drawfloor(scene, v3d, grid_unit); } if(rv3d->persp==RV3D_CAMOB) { if(scene->world) { @@ -2589,7 +2588,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) else { if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) { ED_region_pixelspace(ar); - drawgrid(&scene->unit, ar, v3d, &grid_unit); + drawgrid(&scene->unit, ar, v3d, grid_unit); /* XXX make function? replaces persp(1) */ glMatrixMode(GL_PROJECTION); glLoadMatrixf(rv3d->winmat); @@ -2664,7 +2663,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) { /* must be before xray draw which clears the depth buffer */ if(v3d->zbuf) glDisable(GL_DEPTH_TEST); - draw_gpencil_view3d((bContext *)C, 1); + draw_gpencil_view3d(scene, v3d, ar, 1); if(v3d->zbuf) glEnable(GL_DEPTH_TEST); } @@ -2697,13 +2696,16 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) // TODO: draw something else (but not this) during fly mode draw_rotation_guide(rv3d); - ED_region_pixelspace(ar); - -// retopo_paint_view_update(v3d); -// retopo_draw_paint_lines(); - - /* Draw particle edit brush XXX (removed) */ - +} + +static void view3d_main_area_draw_info(const bContext *C, ARegion *ar, const char *grid_unit) +{ + Scene *scene= CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d= CTX_wm_region_view3d(C); + bScreen *screen= CTX_wm_screen(C); + + Object *ob; if(rv3d->persp==RV3D_CAMOB) drawviewborder(scene, ar, v3d); @@ -2711,7 +2713,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) if ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) { /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */ // if (v3d->flag2 & V3D_DISPGP) - draw_gpencil_view3d((bContext *)C, 0); + draw_gpencil_view3d(scene, v3d, ar, 0); drawcursor(scene, ar, v3d); } @@ -2721,7 +2723,7 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) else draw_view_icon(rv3d); - if((U.uiflag & USER_SHOW_FPS) && (CTX_wm_screen(C)->animtimer)) { + if((U.uiflag & USER_SHOW_FPS) && screen->animtimer) { draw_viewport_fps(scene, ar); } else if(U.uiflag & USER_SHOW_VIEWPORTNAME) { @@ -2741,8 +2743,18 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar) ob= OBACT; if(U.uiflag & USER_DRAWVIEWINFO) draw_selected_name(scene, ob); +} + +void view3d_main_area_draw(const bContext *C, ARegion *ar) +{ + View3D *v3d = CTX_wm_view3d(C); + const char *grid_unit= NULL; + + view3d_main_area_draw_objects(C, ar, &grid_unit); + + ED_region_pixelspace(ar); - /* XXX here was the blockhandlers for floating panels */ + view3d_main_area_draw_info(C, ar, grid_unit); v3d->flag |= V3D_INVALID_BACKBUF; } From e89107927bcc8297c74f9a8cb10562e6defc867c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 13:52:51 +0000 Subject: [PATCH 16/18] - fix for error with utf8 textinput for buttons - ensure input is valid utf8 from ghost and NULL then complain if its not. - added function to get utf8 size BLI_str_utf8_size() --- source/blender/blenlib/BLI_string_utf8.h | 1 + source/blender/blenlib/intern/string_utf8.c | 12 ++++++++++++ .../blender/editors/interface/interface_handlers.c | 2 +- source/blender/makesrna/intern/rna_wm.c | 4 +--- source/blender/windowmanager/WM_types.h | 4 +++- .../blender/windowmanager/intern/wm_event_system.c | 12 ++++++++++-- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 765ae93828e..bcb641d79d8 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -37,6 +37,7 @@ char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy); int BLI_utf8_invalid_byte(const char *str, int length); int BLI_utf8_invalid_strip(char *str, int length); +int BLI_str_utf8_size(const char *p); /* warning, can return -1 on bad chars */ /* copied from glib */ unsigned int BLI_str_utf8_as_unicode(const char *p); unsigned int BLI_str_utf8_as_unicode_and_size(const char *p, size_t *index); diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index b1ad04eb70d..b4c58d3bab4 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -312,6 +312,18 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size } +/* uses glib functions but not from glib */ +/* gets the size of a single utf8 char */ +int BLI_str_utf8_size(const char *p) +{ + int mask = 0, len; + unsigned char c = (unsigned char) *p; + + UTF8_COMPUTE (c, mask, len); + + return len; +} + /* was g_utf8_get_char */ /** * BLI_str_utf8_as_unicode: diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 79080eb5f3b..9f77317292c 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1447,7 +1447,7 @@ static int ui_textedit_type_utf8(uiBut *but, uiHandleButtonData *data, const cha len= strlen(str); if(len-(but->selend - but->selsta)+1 <= data->maxlen) { - int step= BLI_strnlen(utf8_buf, sizeof(utf8_buf)); + int step= BLI_str_utf8_size(utf8_buf); /* type over the current selection */ if ((but->selend - but->selsta) > 0) { diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index dc9f003ab1a..942c0d39c37 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -492,9 +492,7 @@ static int rna_Event_unicode_length(PointerRNA *ptr) wmEvent *event= (wmEvent*)ptr->data; if (event->utf8_buf[0]) { - size_t len= 0; - BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len); - return (int)len; + return BLI_str_utf8_size(event->utf8_buf); /* invalid value is checked on assignment so we dont need to account for this */ } else { return 0; diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 5048166c8b7..fc96c8804b2 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -346,7 +346,9 @@ typedef struct wmEvent { short val; /* press, release, scrollvalue */ int x, y; /* mouse pointer position, screen coord */ int mval[2]; /* region mouse position, name convention pre 2.5 :) */ - char utf8_buf[6]; /* from, ghost if utf8 is enabled for the platform */ + char utf8_buf[6]; /* from, ghost if utf8 is enabled for the platform, + * BLI_str_utf8_size() must _always_ be valid, check + * when assigning s we dont need to check on every access after */ char ascii; /* from ghost, fallback if utf8 isnt set */ char pad; diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 3e9bce651a8..09ec8bf84ba 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -454,11 +454,12 @@ void WM_event_print(wmEvent *event) printf("wmEvent - type:%d/%s, val:%d/%s, " "shift:%d, ctrl:%d, alt:%d, oskey:%d, keymodifier:%d, " - "mouse:(%d,%d), ascii:'%c', utf8:'%.6s', " + "mouse:(%d,%d), ascii:'%c', utf8:'%.*s', " "keymap_idname:%s, pointer:%p\n", event->type, type_id, event->val, val_id, event->shift, event->ctrl, event->alt, event->oskey, event->keymodifier, - event->x, event->y, event->ascii, event->utf8_buf, + event->x, event->y, event->ascii, + BLI_str_utf8_size(event->utf8_buf), event->utf8_buf, event->keymap_idname, (void *)event); } else { @@ -2629,6 +2630,13 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* TODO. should this also zero utf8?, dont for now, campbell */ } + if (event.utf8_buf[0]) { + if (BLI_str_utf8_size(event.utf8_buf) == -1) { + printf("%s: ghost detected an invalid unicode character '%d'!\n", __func__, (int)(unsigned char)event.utf8_buf[0]); + event.utf8_buf[0]= '\0'; + } + } + /* modifiers */ /* assigning both first and second is strange - campbell */ switch(event.type) { From 67e744ccf0f673891dbf2f9989e56fe92104a7d7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Oct 2011 15:27:36 +0000 Subject: [PATCH 17/18] fix some typo's --- CMakeLists.txt | 2 +- intern/ffmpeg/ffmpeg_compat.h | 2 +- source/blender/blenkernel/intern/brush.c | 2 +- source/blender/editors/interface/interface_widgets.c | 2 +- source/blender/editors/space_graph/space_graph.c | 2 +- source/blender/editors/space_outliner/outliner_tools.c | 2 +- source/blender/makesrna/intern/rna_action.c | 2 +- source/blender/render/intern/source/rayshade.c | 2 +- source/blender/windowmanager/intern/wm_event_system.c | 2 +- source/gameengine/Physics/common/PHY_IMotionState.h | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13be77e90eb..5f3e18df8ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ mark_as_advanced(WITH_GHOST_SDL) option(WITH_HEADLESS "Build without graphical support (renderfarm, server mode only)" OFF) mark_as_advanced(WITH_HEADLESS) -option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON) +option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what your doing!)" ON) mark_as_advanced(WITH_AUDASPACE) diff --git a/intern/ffmpeg/ffmpeg_compat.h b/intern/ffmpeg/ffmpeg_compat.h index a23dd22f932..05299525d67 100644 --- a/intern/ffmpeg/ffmpeg_compat.h +++ b/intern/ffmpeg/ffmpeg_compat.h @@ -29,7 +29,7 @@ /* check our ffmpeg is new enough, avoids user complaints */ #if (LIBAVFORMAT_VERSION_MAJOR < 52) || ((LIBAVFORMAT_VERSION_MAJOR == 52) && (LIBAVFORMAT_VERSION_MINOR <= 64)) -# error "FFmpeg 0.7 or newer is needed, Upgrade you're FFmpeg or disable it" +# error "FFmpeg 0.7 or newer is needed, Upgrade your FFmpeg or disable it" #endif /* end sanity check */ diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index c84a3cfc730..4ab9d085de3 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -930,7 +930,7 @@ void brush_jitter_pos(Brush *brush, float pos[2], float jitterpos[2]) { int use_jitter= brush->jitter != 0; - /* jitter-ed brush gives wierd and unpredictable result for this + /* jitter-ed brush gives weird and unpredictable result for this kinds of stroke, so manyally disable jitter usage (sergey) */ use_jitter&= (brush->flag & (BRUSH_RESTORE_MESH|BRUSH_ANCHORED)) == 0; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 0215cc05d36..ef7fdf67b0b 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1787,7 +1787,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect) /* exception: if 'lock' is set * lock the value of the color wheel to 1. - * Useful for color correction tools where you're only interested in hue. */ + * Useful for color correction tools where your only interested in hue. */ if (but->flag & UI_BUT_COLOR_LOCK) hsv[2] = 1.f; else if (color_profile) diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index 3cc83b12124..3ee8b352caf 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -110,7 +110,7 @@ static SpaceLink *graph_new(const bContext *C) sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet"); sipo->ads->source= (ID *)scene; - /* settings for making it easier by default to just see what you're interested in tweaking */ + /* settings for making it easier by default to just see what your interested in tweaking */ sipo->ads->filterflag |= ADS_FILTER_ONLYSEL; sipo->flag |= SIPO_SELVHANDLESONLY; diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 78907fbd1ed..593f1e44b74 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -298,7 +298,7 @@ static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeSto tselem->id= NULL; /* XXX: tree management normally happens from draw_outliner(), but when - you're clicking to fast on Delete object from context menu in + your clicking to fast on Delete object from context menu in outliner several mouse events can be handled in one cycle without handling notifiers/redraw which leads to deleting the same object twice. cleanup tree here to prevent such cases. */ diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c index f2d1578388d..15c180eb343 100644 --- a/source/blender/makesrna/intern/rna_action.c +++ b/source/blender/makesrna/intern/rna_action.c @@ -612,7 +612,7 @@ static void rna_def_action(BlenderRNA *brna) prop= RNA_def_property(srna, "id_root", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "idroot"); RNA_def_property_enum_items(prop, id_type_items); - RNA_def_property_ui_text(prop, "ID Root Type", "Type of ID-block that action can be used on - DO NOT CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING"); + RNA_def_property_ui_text(prop, "ID Root Type", "Type of ID-block that action can be used on - DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING"); /* API calls */ RNA_api_action(srna); diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 8fa90a51442..0fc00731d60 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -1526,7 +1526,7 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) do_tra= ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha!=1.0f && (shi->depth <= shi->mat->ray_depth_tra)); do_mir= ((shi->mat->mode & MA_RAYMIRROR) && shi->ray_mirror!=0.0f && (shi->depth <= shi->mat->ray_depth)); - /* raytrace mirror amd refract like to separate the spec color */ + /* raytrace mirror and refract like to separate the spec color */ if(shi->combinedflag & SCE_PASS_SPEC) sub_v3_v3v3(diff, shr->combined, shr->spec); else diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 09ec8bf84ba..de2c593043c 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2621,7 +2621,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* ghost should do this already for key up */ if (event.utf8_buf[0]) { - printf("%s: ghost on you're platform is misbehaving, utf8 events on key up!\n", __func__); + printf("%s: ghost on your platform is misbehaving, utf8 events on key up!\n", __func__); } event.utf8_buf[0]= '\0'; } diff --git a/source/gameengine/Physics/common/PHY_IMotionState.h b/source/gameengine/Physics/common/PHY_IMotionState.h index 00b4f105348..3914cb9aef5 100644 --- a/source/gameengine/Physics/common/PHY_IMotionState.h +++ b/source/gameengine/Physics/common/PHY_IMotionState.h @@ -51,7 +51,7 @@ class PHY_IMotionState virtual void getWorldPosition(float& posX,float& posY,float& posZ)=0; virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)=0; virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0; - // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second colum, [8..11] = third column + // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second column, [8..11] = third column virtual void getWorldOrientation(float* ori)=0; virtual void setWorldOrientation(const float* ori)=0; From f1cea89d99f0c80bdccd2ba1359142b5ff14cdb9 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sun, 23 Oct 2011 15:43:12 +0000 Subject: [PATCH 18/18] Typo fixes for the typo fixes. :D --- CMakeLists.txt | 2 +- source/blender/editors/interface/interface_widgets.c | 2 +- source/blender/editors/space_graph/space_graph.c | 2 +- source/blender/editors/space_outliner/outliner_tools.c | 2 +- source/blender/makesrna/intern/rna_action.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f3e18df8ec..13be77e90eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ mark_as_advanced(WITH_GHOST_SDL) option(WITH_HEADLESS "Build without graphical support (renderfarm, server mode only)" OFF) mark_as_advanced(WITH_HEADLESS) -option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what your doing!)" ON) +option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON) mark_as_advanced(WITH_AUDASPACE) diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ef7fdf67b0b..0215cc05d36 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1787,7 +1787,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect) /* exception: if 'lock' is set * lock the value of the color wheel to 1. - * Useful for color correction tools where your only interested in hue. */ + * Useful for color correction tools where you're only interested in hue. */ if (but->flag & UI_BUT_COLOR_LOCK) hsv[2] = 1.f; else if (color_profile) diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index 3ee8b352caf..3cc83b12124 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -110,7 +110,7 @@ static SpaceLink *graph_new(const bContext *C) sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet"); sipo->ads->source= (ID *)scene; - /* settings for making it easier by default to just see what your interested in tweaking */ + /* settings for making it easier by default to just see what you're interested in tweaking */ sipo->ads->filterflag |= ADS_FILTER_ONLYSEL; sipo->flag |= SIPO_SELVHANDLESONLY; diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 593f1e44b74..78907fbd1ed 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -298,7 +298,7 @@ static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeSto tselem->id= NULL; /* XXX: tree management normally happens from draw_outliner(), but when - your clicking to fast on Delete object from context menu in + you're clicking to fast on Delete object from context menu in outliner several mouse events can be handled in one cycle without handling notifiers/redraw which leads to deleting the same object twice. cleanup tree here to prevent such cases. */ diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c index 15c180eb343..f2d1578388d 100644 --- a/source/blender/makesrna/intern/rna_action.c +++ b/source/blender/makesrna/intern/rna_action.c @@ -612,7 +612,7 @@ static void rna_def_action(BlenderRNA *brna) prop= RNA_def_property(srna, "id_root", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "idroot"); RNA_def_property_enum_items(prop, id_type_items); - RNA_def_property_ui_text(prop, "ID Root Type", "Type of ID-block that action can be used on - DO NOT CHANGE UNLESS YOU KNOW WHAT YOUR DOING"); + RNA_def_property_ui_text(prop, "ID Root Type", "Type of ID-block that action can be used on - DO NOT CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING"); /* API calls */ RNA_api_action(srna);