Blender V5.0
interface_template_cache_file.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
8
9#include "BLI_listbase.h"
10#include "BLI_string_ref.hh"
11#include "BLI_string_utf8.h"
12
13#include "BKE_context.hh"
14#include "BKE_scene.hh"
15#include "BKE_screen.hh"
16
17#include "BLT_translation.hh"
18
19#include "DNA_cachefile_types.h"
20#include "DNA_space_types.h"
21
23
24#include "RE_engine.h"
25
26#include "RNA_access.hh"
27
29#include "interface_intern.hh"
30
32
34{
35 if (RNA_pointer_is_null(fileptr)) {
36 return;
37 }
38
39 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
40 layout->context_ptr_set("edit_cachefile", fileptr);
41
42 layout->prop(fileptr, "velocity_name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
43 layout->prop(fileptr, "velocity_unit", UI_ITEM_NONE, std::nullopt, ICON_NONE);
44}
45
47{
48 if (RNA_pointer_is_null(fileptr)) {
49 return;
50 }
51
52 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
53 layout->context_ptr_set("edit_cachefile", fileptr);
54
55 uiLayout *row, *sub, *subsub;
56
57 row = &layout->row(false);
58 row->prop(fileptr, "is_sequence", UI_ITEM_NONE, std::nullopt, ICON_NONE);
59
60 row = &layout->row(true, IFACE_("Override Frame"));
61 sub = &row->row(true);
62 sub->use_property_decorate_set(false);
63 sub->prop(fileptr, "override_frame", UI_ITEM_NONE, "", ICON_NONE);
64 subsub = &sub->row(true);
65 subsub->active_set(RNA_boolean_get(fileptr, "override_frame"));
66 subsub->prop(fileptr, "frame", UI_ITEM_NONE, "", ICON_NONE);
67 row->decorator(fileptr, "frame", 0);
68
69 row = &layout->row(false);
70 row->prop(fileptr, "frame_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
71 row->active_set(!RNA_boolean_get(fileptr, "is_sequence"));
72}
73
74static void cache_file_layer_item(uiList * /*ui_list*/,
75 const bContext * /*C*/,
76 uiLayout *layout,
77 PointerRNA * /*dataptr*/,
78 PointerRNA *itemptr,
79 int /*icon*/,
80 PointerRNA * /*active_dataptr*/,
81 const char * /*active_propname*/,
82 int /*index*/,
83 int /*flt_flag*/)
84{
85 uiLayout *row = &layout->row(true);
86 row->prop(itemptr, "hide_layer", UI_ITEM_R_NO_BG, "", ICON_NONE);
87 row->prop(itemptr, "filepath", UI_ITEM_R_NO_BG, "", ICON_NONE);
88}
89
91{
92 uiListType *list_type = (uiListType *)MEM_callocN(sizeof(*list_type), __func__);
93
94 STRNCPY_UTF8(list_type->idname, "UI_UL_cache_file_layers");
96
97 return list_type;
98}
99
101{
102 if (RNA_pointer_is_null(fileptr)) {
103 return;
104 }
105
106 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
107 layout->context_ptr_set("edit_cachefile", fileptr);
108
109 uiLayout *row = &layout->row(false);
110 uiLayout *col = &row->column(true);
111
113 (bContext *)C,
114 "UI_UL_cache_file_layers",
115 "cache_file_layers",
116 fileptr,
117 "layers",
118 fileptr,
119 "active_index",
120 "",
121 1,
122 5,
124 1,
126
127 col = &row->column(true);
128 col->op("cachefile.layer_add", "", ICON_ADD);
129 col->op("cachefile.layer_remove", "", ICON_REMOVE);
130
131 CacheFile *file = static_cast<CacheFile *>(fileptr->data);
132 if (BLI_listbase_count(&file->layers) > 1) {
133 col->separator(1.0f);
134 col->op("cachefile.layer_move", "", ICON_TRIA_UP);
135 col->op("cachefile.layer_move", "", ICON_TRIA_DOWN);
136 }
137}
138
140 const StringRefNull propname,
141 PointerRNA *r_file_ptr)
142{
143 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
144
145 if (!prop) {
146 printf("%s: property not found: %s.%s\n",
147 __func__,
149 propname.c_str());
150 return false;
151 }
152
153 if (RNA_property_type(prop) != PROP_POINTER) {
154 printf("%s: expected pointer property for %s.%s\n",
155 __func__,
157 propname.c_str());
158 return false;
159 }
160
161 *r_file_ptr = RNA_property_pointer_get(ptr, prop);
162 return true;
163}
164
166 const bContext *C,
168 const StringRefNull propname)
169{
170 if (!ptr->data) {
171 return;
172 }
173
174 PointerRNA fileptr;
175 if (!uiTemplateCacheFilePointer(ptr, propname, &fileptr)) {
176 return;
177 }
178
179 CacheFile *file = static_cast<CacheFile *>(fileptr.data);
180
181 layout->context_ptr_set("edit_cachefile", &fileptr);
182
183 uiTemplateID(layout, C, ptr, propname, nullptr, "CACHEFILE_OT_open", nullptr);
184
185 if (!file) {
186 return;
187 }
188
190
191 uiLayout *row, *sub;
192
193 layout->use_property_split_set(true);
194
195 row = &layout->row(true);
196 row->prop(&fileptr, "filepath", UI_ITEM_NONE, std::nullopt, ICON_NONE);
197 sub = &row->row(true);
198 sub->op("cachefile.reload", "", ICON_FILE_REFRESH);
199
200 if (sbuts->mainb == BCONTEXT_CONSTRAINT) {
201 row = &layout->row(false);
202 row->prop(&fileptr, "scale", UI_ITEM_NONE, IFACE_("Manual Scale"), ICON_NONE);
203 }
204
205 /* TODO: unused for now, so no need to expose. */
206#if 0
207 row = &layout->row(false);
208 row->prop(&fileptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
209
210 row = &layout->row(false);
211 row->prop(&fileptr, "up_axis", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
212#endif
213}
SpaceProperties * CTX_wm_space_properties(const bContext *C)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
@ UILST_LAYOUT_DEFAULT
@ BCONTEXT_CONSTRAINT
@ PROP_POINTER
Definition RNA_types.hh:167
#define C
Definition RandGen.cpp:29
void uiTemplateID(uiLayout *layout, const bContext *C, PointerRNA *ptr, blender::StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=UI_TEMPLATE_ID_FILTER_ALL, bool live_icon=false, std::optional< blender::StringRef > text=std::nullopt)
void uiTemplateList(uiLayout *layout, const bContext *C, const char *listtype_name, const char *list_id, PointerRNA *dataptr, blender::StringRefNull propname, PointerRNA *active_dataptr, const char *active_propname, const char *item_dyntip_propname, int rows, int maxrows, int layout_type, int columns, enum uiTemplateListFlags flags)
@ UI_TEMPLATE_LIST_FLAG_NONE
@ UI_ITEM_R_NO_BG
#define UI_ITEM_NONE
constexpr const char * c_str() const
uint col
#define printf(...)
static void cache_file_layer_item(uiList *, const bContext *, uiLayout *layout, PointerRNA *, PointerRNA *itemptr, int, PointerRNA *, const char *, int, int)
void uiTemplateCacheFileLayers(uiLayout *layout, const bContext *C, PointerRNA *fileptr)
void uiTemplateCacheFileVelocity(uiLayout *layout, PointerRNA *fileptr)
bool uiTemplateCacheFilePointer(PointerRNA *ptr, const StringRefNull propname, PointerRNA *r_file_ptr)
uiListType * UI_UL_cache_file_layers()
void uiTemplateCacheFileTimeSettings(uiLayout *layout, PointerRNA *fileptr)
void uiTemplateCacheFile(uiLayout *layout, const bContext *C, PointerRNA *ptr, const StringRefNull propname)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
PropertyType RNA_property_type(PropertyRNA *prop)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_struct_identifier(const StructRNA *type)
bool RNA_pointer_is_null(const PointerRNA *ptr)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void * data
Definition RNA_types.hh:53
void use_property_decorate_set(bool is_sep)
void decorator(PointerRNA *ptr, PropertyRNA *prop, int index)
uiLayout & column(bool align)
void active_set(bool active)
void context_ptr_set(blender::StringRef name, const PointerRNA *ptr)
uiLayout & row(bool align)
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, blender::wm::OpCallContext context, eUI_Item_Flag flag)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
char idname[BKE_ST_MAXNAME]
uiListDrawItemFunc draw_item
PointerRNA * ptr
Definition wm_files.cc:4238