Blender V5.3
interface_template_modifiers.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BKE_context.hh"
12#include "BKE_modifier.hh"
13#include "BKE_screen.hh"
14
15#include "BLI_listbase.hh"
16
17#include "ED_object.hh"
18
19#include "RNA_access.hh"
20#include "RNA_prototypes.hh"
21
22#include "UI_interface.hh"
24
25namespace blender::ui {
26
27static void modifier_panel_id(void *md_link, char *r_name)
28{
29 ModifierData *md = static_cast<ModifierData *>(md_link);
31}
32
33void template_modifiers(Layout * /*layout*/, bContext *C)
34{
35 ARegion *region = CTX_wm_region(C);
36
38 ListBaseT<ModifierData> *modifiers = &ob->modifiers;
39
40 const bool panels_match = panel_list_matches_data(region, modifiers, modifier_panel_id);
41
42 if (!panels_match) {
43 panels_free_instanced(C, region);
44 for (ModifierData &md : *modifiers) {
45 const ModifierTypeInfo *mti = BKE_modifier_get_info(md.type);
46 if (mti->panel_register == nullptr) {
47 continue;
48 }
49
50 char panel_idname[MAX_NAME];
51 modifier_panel_id(&md, panel_idname);
52
53 /* Create custom data RNA pointer. */
54 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
55 *md_ptr = RNA_pointer_create_id_subdata(ob->id, RNA_Modifier, &md);
56
57 panel_add_instanced(C, region, &region->panels, panel_idname, md_ptr);
58 }
59 }
60 else {
61 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
62 Panel *panel = region->panels.first();
63 for (ModifierData &md : *modifiers) {
64 const ModifierTypeInfo *mti = BKE_modifier_get_info(md.type);
65 if (mti->panel_register == nullptr) {
66 continue;
67 }
68
69 /* Move to the next instanced panel corresponding to the next modifier. */
70 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
71 panel = panel->next;
72 BLI_assert(panel !=
73 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
74 }
75
76 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
77 *md_ptr = RNA_pointer_create_id_subdata(ob->id, RNA_Modifier, &md);
78 panel_custom_data_set(panel, md_ptr);
79
80 panel = panel->next;
81 }
82 }
83}
84
85} // namespace blender::ui
#define MAX_NAME
Definition DNA_defs.h:63
#define C
Definition RandGen.cpp:29
Object * context_active_object(const bContext *C)
void template_modifiers(Layout *layout, bContext *C)
static void modifier_panel_id(void *md_link, char *r_name)
bool panel_list_matches_data(ARegion *region, ListBase *data, ListPanelIDFromDataFunc panel_idname_func)
void panels_free_instanced(const bContext *C, ARegion *region)
void panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
Panel * panel_add_instanced(const bContext *C, ARegion *region, ListBaseT< Panel > *panels, const char *panel_idname, PointerRNA *custom_data)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ PANEL_TYPE_INSTANCED
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
void BKE_modifier_type_panel_id(ModifierType type, char *r_idname)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
ARegion * CTX_wm_region(const bContext *C)
ListBaseT< Panel > panels
void(*) panel_register(ARegionType *region_type)
ListBaseT< ModifierData > modifiers
struct PanelType * type
struct Panel * next