From 19b82be61e47cd30b72b7b215bd46c78e8207c89 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Tue, 13 May 2014 11:50:54 +0900 Subject: Freestyle: Added .new() and .remove() to the collection type of Python style modules. --- source/blender/blenkernel/BKE_freestyle.h | 8 ++-- source/blender/blenkernel/intern/freestyle.c | 18 +++++++-- source/blender/makesrna/intern/rna_scene.c | 58 ++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_freestyle.h b/source/blender/blenkernel/BKE_freestyle.h index 7d0094d9c1e..bb909e4aa9d 100644 --- a/source/blender/blenkernel/BKE_freestyle.h +++ b/source/blender/blenkernel/BKE_freestyle.h @@ -52,10 +52,10 @@ void BKE_freestyle_config_free(FreestyleConfig *config); void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config); /* FreestyleConfig.modules */ -void BKE_freestyle_module_add(FreestyleConfig *config); -void BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf); -void BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf); -void BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +FreestyleModuleConfig *BKE_freestyle_module_add(FreestyleConfig *config); +bool BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +bool BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +bool BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf); /* FreestyleConfig.linesets */ FreestyleLineSet *BKE_freestyle_lineset_add(FreestyleConfig *config, const char *name); diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c index 495e99d61af..445acc850e6 100644 --- a/source/blender/blenkernel/intern/freestyle.c +++ b/source/blender/blenkernel/intern/freestyle.c @@ -127,12 +127,13 @@ static FreestyleModuleConfig *alloc_module(void) return (FreestyleModuleConfig *)MEM_callocN(sizeof(FreestyleModuleConfig), "style module configuration"); } -void BKE_freestyle_module_add(FreestyleConfig *config) +FreestyleModuleConfig *BKE_freestyle_module_add(FreestyleConfig *config) { FreestyleModuleConfig *module_conf = alloc_module(); BLI_addtail(&config->modules, (void *)module_conf); module_conf->script = NULL; module_conf->is_displayed = 1; + return module_conf; } static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig *module) @@ -141,21 +142,30 @@ static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig new_module->is_displayed = module->is_displayed; } -void BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +bool BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf) { + if (BLI_findindex(&config->modules, module_conf) == -1) + return false; BLI_freelinkN(&config->modules, module_conf); + return true; } -void BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +bool BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf) { + if (BLI_findindex(&config->modules, module_conf) == -1) + return false; BLI_remlink(&config->modules, module_conf); BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf); + return true; } -void BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +bool BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf) { + if (BLI_findindex(&config->modules, module_conf) == -1) + return false; BLI_remlink(&config->modules, module_conf); BLI_insertlinkafter(&config->modules, module_conf->next, module_conf); + return true; } void BKE_freestyle_lineset_unique_name(FreestyleConfig *config, FreestyleLineSet *lineset) diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 49c14e9036e..08fe2701915 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -334,6 +334,7 @@ EnumPropertyItem bake_save_mode_items[] = { #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_mesh_types.h" +#include "DNA_text_types.h" #include "RNA_access.h" @@ -1640,6 +1641,37 @@ static void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int BKE_freestyle_lineset_set_active_index(config, value); } +static FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSettings *config) +{ + Scene *scene = (Scene *)id; + FreestyleModuleConfig *module = BKE_freestyle_module_add((FreestyleConfig *)config); + + DAG_id_tag_update(&scene->id, 0); + WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); + + return module; +} + +static void rna_FreestyleSettings_module_remove(ID *id, FreestyleSettings *config, ReportList *reports, + PointerRNA *module_ptr) +{ + Scene *scene = (Scene *)id; + FreestyleModuleConfig *module = module_ptr->data; + + if (!BKE_freestyle_module_delete((FreestyleConfig *)config, module)) { + if (module->script) + BKE_reportf(reports, RPT_ERROR, "Style module '%s' could not be removed", module->script->id.name+2); + else + BKE_reportf(reports, RPT_ERROR, "Style module could not be removed"); + return; + } + + RNA_POINTER_INVALIDATE(module_ptr); + + DAG_id_tag_update(&scene->id, 0); + WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); +} + #else static void rna_def_transform_orientation(BlenderRNA *brna) @@ -2652,6 +2684,31 @@ void rna_def_render_layer_common(StructRNA *srna, int scene) else RNA_def_property_clear_flag(prop, PROP_EDITABLE); } +static void rna_def_freestyle_modules(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "FreestyleModules"); + srna = RNA_def_struct(brna, "FreestyleModules", NULL); + RNA_def_struct_sdna(srna, "FreestyleSettings"); + RNA_def_struct_ui_text(srna, "Style Modules", "A list of style modules (to be applied from top to bottom)"); + + func = RNA_def_function(srna, "new", "rna_FreestyleSettings_module_add"); + RNA_def_function_ui_description(func, "Add a style module to scene render layer Freestyle settings"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); + parm = RNA_def_pointer(func, "module", "FreestyleModuleSettings", "", "Newly created style module"); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "remove", "rna_FreestyleSettings_module_remove"); + RNA_def_function_ui_description(func, "Remove a style module from scene render layer Freestyle settings"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "module", "FreestyleModuleSettings", "", "Style module to remove"); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); +} + static void rna_def_freestyle_linesets(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; @@ -2988,6 +3045,7 @@ static void rna_def_freestyle_settings(BlenderRNA *brna) RNA_def_property_collection_sdna(prop, NULL, "modules", NULL); RNA_def_property_struct_type(prop, "FreestyleModuleSettings"); RNA_def_property_ui_text(prop, "Style Modules", "A list of style modules (to be applied from top to bottom)"); + rna_def_freestyle_modules(brna, prop); prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "mode"); -- cgit v1.2.3