Freestyle: Added .new() and .remove() to the collection type of Python style modules.

This commit is contained in:
Tamito Kajiyama 2014-05-13 11:50:54 +09:00
parent c08f025fe1
commit 19b82be61e
Notes: blender-bot 2023-02-14 10:37:42 +01:00
Referenced by issue #40335, Cycles crash when OSL scripting is enabled
Referenced by issue #40270, Cycles bake: Combined Type fails to bake Emission node
3 changed files with 76 additions and 8 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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");