diff options
author | Hans Goudey <h.goudey@me.com> | 2020-12-02 15:35:07 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-12-02 17:38:47 +0300 |
commit | 600fb28b629598af2537c542e7f3f76ba0e94389 (patch) | |
tree | db944815f74d9c81b48095f4d30402080c9192d6 /source/blender/makesrna | |
parent | fc4a853846123ed320914df7f78340ec95efc97e (diff) |
Geometry Nodes: active modifier + geometry nodes editor
This commit adds functions to set and get the object's active
modifier, which is stored as a flag in the ModifierData struct,
similar to constraints. This will be used to set the context in
the node editor. There are no visible changes in this commit.
Similar to how the node editor context works for materials, this commit
makes the node group displayed in the node editor depend on the active
object and its active modifier. To keep the node group from changing,
just pin the node group in the header.
* Shortcuts performed while there is an active modifier will affect
only that modifier (the exception is the A to expand the modifiers).
* Clicking anywhere on the empty space in a modifier's panel will make it active.
These changes require some refactoring of object modifier code. First
is splitting up the modifier property invoke callback, which now needs
to be able to get the active modifier separately from the hovered
modifier for the different operators.
Second is a change to removing modifiers, where there is now a separate
function to remove a modifier from an object's list, in order to handle
changing the active.
Finally, the panel handler needs a small tweak so that this "click in panel"
event can be handled afterwards.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 26 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 38 |
2 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 09c1869b84b..30d612d2634 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -676,6 +676,23 @@ static void rna_Modifier_dependency_update(Main *bmain, Scene *scene, PointerRNA DEG_relations_tag_update(bmain); } +static void rna_Modifier_is_active_set(PointerRNA *ptr, bool value) +{ + ModifierData *md = ptr->data; + + if (value) { + /* Disable the active flag of all other modif-iers. */ + for (ModifierData *prev_md = md->prev; prev_md != NULL; prev_md = prev_md->prev) { + prev_md->flag &= ~eModifierFlag_Active; + } + for (ModifierData *next_md = md->next; next_md != NULL; next_md = next_md->next) { + next_md->flag &= ~eModifierFlag_Active; + } + + md->flag |= eModifierFlag_Active; + } +} + /* Vertex Groups */ # define RNA_MOD_VGROUP_NAME_SET(_type, _prop) \ @@ -7266,6 +7283,15 @@ void RNA_def_modifier(BlenderRNA *brna) RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1); RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL); + prop = RNA_def_property(srna, "is_active", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", eModifierFlag_Active); + RNA_def_property_boolean_funcs(prop, NULL, "rna_Modifier_is_active_set"); + RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); + RNA_def_property_ui_text(prop, "Active", "The active modifier in the list"); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL); + prop = RNA_def_property(srna, "use_apply_on_spline", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_ApplyOnSpline); RNA_def_property_ui_text( diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 6f7116bfe22..627b8a3140a 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1616,6 +1616,32 @@ static void rna_Object_modifier_clear(Object *object, bContext *C) WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object); } +static PointerRNA rna_Object_active_modifier_get(PointerRNA *ptr) +{ + Object *ob = (Object *)ptr->owner_id; + ModifierData *md = BKE_object_active_modifier(ob); + return rna_pointer_inherit_refine(ptr, &RNA_Modifier, md); +} + +static void rna_Object_active_modifier_set(PointerRNA *ptr, PointerRNA value, ReportList *reports) +{ + Object *ob = (Object *)ptr->owner_id; + ModifierData *md = value.data; + + if (RNA_pointer_is_null(&value)) { + BKE_object_modifier_set_active(ob, NULL); + return; + } + + if (BLI_findindex(&ob->modifiers, md) == -1) { + BKE_reportf( + reports, RPT_ERROR, "Modifier \"%s\" is not in the object's modifier list", md->name); + return; + } + + BKE_object_modifier_set_active(ob, md); +} + bool rna_Object_modifiers_override_apply(Main *bmain, PointerRNA *ptr_dst, PointerRNA *ptr_src, @@ -2287,6 +2313,7 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop) FunctionRNA *func; PropertyRNA *parm; + PropertyRNA *prop; RNA_def_property_srna(cprop, "ObjectModifiers"); srna = RNA_def_struct(brna, "ObjectModifiers", NULL); @@ -2333,6 +2360,17 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "clear", "rna_Object_modifier_clear"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_ui_description(func, "Remove all modifiers from the object"); + + /* Active modifier. */ + prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Modifier"); + RNA_def_property_pointer_funcs( + prop, "rna_Object_active_modifier_get", "rna_Object_active_modifier_set", NULL, NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); + RNA_def_property_ui_text(prop, "Active Modifier", "The active modifier in the list"); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL); } /* object.grease_pencil_modifiers */ |