Blender V4.5
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.h"
11#include "BLI_string_ref.hh"
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
28#include "UI_interface.hh"
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 uiLayoutSetContextPointer(layout, "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 uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
54
55 uiLayout *row, *sub;
56
57 /* Only enable render procedural option if the active engine supports it. */
58 const RenderEngineType *engine_type = CTX_data_engine_type(C);
59
60 Scene *scene = CTX_data_scene(C);
61 const bool engine_supports_procedural = RE_engine_supports_alembic_procedural(engine_type,
62 scene);
63 CacheFile *cache_file = static_cast<CacheFile *>(fileptr->data);
64 CacheFile *cache_file_eval = DEG_get_evaluated(CTX_data_depsgraph_pointer(C), cache_file);
65 bool is_alembic = cache_file_eval->type == CACHEFILE_TYPE_ALEMBIC;
66
67 if (!is_alembic) {
68 row = &layout->row(false);
69 row->label(RPT_("Only Alembic Procedurals supported"), ICON_INFO);
70 }
71 else if (!engine_supports_procedural) {
72 row = &layout->row(false);
73 /* For Cycles, verify that experimental features are enabled. */
75 row->label(
76 RPT_(
77 "The Cycles Alembic Procedural is only available with the experimental feature set"),
78 ICON_INFO);
79 }
80 else {
81 row->label(RPT_("The active render engine does not have an Alembic Procedural"), ICON_INFO);
82 }
83 }
84
85 row = &layout->row(false);
86 uiLayoutSetActive(row, is_alembic && engine_supports_procedural);
87 row->prop(fileptr, "use_render_procedural", UI_ITEM_NONE, std::nullopt, ICON_NONE);
88
89 const bool use_render_procedural = RNA_boolean_get(fileptr, "use_render_procedural");
90 const bool use_prefetch = RNA_boolean_get(fileptr, "use_prefetch");
91
92 row = &layout->row(false);
93 uiLayoutSetEnabled(row, use_render_procedural);
94 row->prop(fileptr, "use_prefetch", UI_ITEM_NONE, std::nullopt, ICON_NONE);
95
96 sub = &layout->row(false);
97 uiLayoutSetEnabled(sub, use_prefetch && use_render_procedural);
98 sub->prop(fileptr, "prefetch_cache_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
99}
100
102{
103 if (RNA_pointer_is_null(fileptr)) {
104 return;
105 }
106
107 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
108 uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
109
110 uiLayout *row, *sub, *subsub;
111
112 row = &layout->row(false);
113 row->prop(fileptr, "is_sequence", UI_ITEM_NONE, std::nullopt, ICON_NONE);
114
115 row = &layout->row(true, IFACE_("Override Frame"));
116 sub = &row->row(true);
117 uiLayoutSetPropDecorate(sub, false);
118 sub->prop(fileptr, "override_frame", UI_ITEM_NONE, "", ICON_NONE);
119 subsub = &sub->row(true);
120 uiLayoutSetActive(subsub, RNA_boolean_get(fileptr, "override_frame"));
121 subsub->prop(fileptr, "frame", UI_ITEM_NONE, "", ICON_NONE);
122 uiItemDecoratorR(row, fileptr, "frame", 0);
123
124 row = &layout->row(false);
125 row->prop(fileptr, "frame_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
126 uiLayoutSetActive(row, !RNA_boolean_get(fileptr, "is_sequence"));
127}
128
129static void cache_file_layer_item(uiList * /*ui_list*/,
130 const bContext * /*C*/,
131 uiLayout *layout,
132 PointerRNA * /*dataptr*/,
133 PointerRNA *itemptr,
134 int /*icon*/,
135 PointerRNA * /*active_dataptr*/,
136 const char * /*active_propname*/,
137 int /*index*/,
138 int /*flt_flag*/)
139{
140 uiLayout *row = &layout->row(true);
141 row->prop(itemptr, "hide_layer", UI_ITEM_R_NO_BG, "", ICON_NONE);
142 row->prop(itemptr, "filepath", UI_ITEM_R_NO_BG, "", ICON_NONE);
143}
144
146{
147 uiListType *list_type = (uiListType *)MEM_callocN(sizeof(*list_type), __func__);
148
149 STRNCPY(list_type->idname, "UI_UL_cache_file_layers");
150 list_type->draw_item = cache_file_layer_item;
151
152 return list_type;
153}
154
156{
157 if (RNA_pointer_is_null(fileptr)) {
158 return;
159 }
160
161 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
162 uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
163
164 uiLayout *row = &layout->row(false);
165 uiLayout *col = &row->column(true);
166
168 (bContext *)C,
169 "UI_UL_cache_file_layers",
170 "cache_file_layers",
171 fileptr,
172 "layers",
173 fileptr,
174 "active_index",
175 "",
176 1,
177 5,
179 1,
181
182 col = &row->column(true);
183 col->op("cachefile.layer_add", "", ICON_ADD);
184 col->op("cachefile.layer_remove", "", ICON_REMOVE);
185
186 CacheFile *file = static_cast<CacheFile *>(fileptr->data);
187 if (BLI_listbase_count(&file->layers) > 1) {
188 col->separator(1.0f);
189 col->op("cachefile.layer_move", "", ICON_TRIA_UP);
190 col->op("cachefile.layer_move", "", ICON_TRIA_DOWN);
191 }
192}
193
195 const StringRefNull propname,
196 PointerRNA *r_file_ptr)
197{
198 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
199
200 if (!prop) {
201 printf("%s: property not found: %s.%s\n",
202 __func__,
204 propname.c_str());
205 return false;
206 }
207
208 if (RNA_property_type(prop) != PROP_POINTER) {
209 printf("%s: expected pointer property for %s.%s\n",
210 __func__,
212 propname.c_str());
213 return false;
214 }
215
216 *r_file_ptr = RNA_property_pointer_get(ptr, prop);
217 return true;
218}
219
221 const bContext *C,
223 const StringRefNull propname)
224{
225 if (!ptr->data) {
226 return;
227 }
228
229 PointerRNA fileptr;
230 if (!uiTemplateCacheFilePointer(ptr, propname, &fileptr)) {
231 return;
232 }
233
234 CacheFile *file = static_cast<CacheFile *>(fileptr.data);
235
236 uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr);
237
238 uiTemplateID(layout, C, ptr, propname, nullptr, "CACHEFILE_OT_open", nullptr);
239
240 if (!file) {
241 return;
242 }
243
245
246 uiLayout *row, *sub;
247
248 uiLayoutSetPropSep(layout, true);
249
250 row = &layout->row(true);
251 row->prop(&fileptr, "filepath", UI_ITEM_NONE, std::nullopt, ICON_NONE);
252 sub = &row->row(true);
253 sub->op("cachefile.reload", "", ICON_FILE_REFRESH);
254
255 if (sbuts->mainb == BCONTEXT_CONSTRAINT) {
256 row = &layout->row(false);
257 row->prop(&fileptr, "scale", UI_ITEM_NONE, IFACE_("Manual Scale"), ICON_NONE);
258 }
259
260 /* TODO: unused for now, so no need to expose. */
261#if 0
262 row = &layout->row(false);
263 row->prop(&fileptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
264
265 row = &layout->row(false);
266 row->prop(&fileptr, "up_axis", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
267#endif
268}
SpaceProperties * CTX_wm_space_properties(const bContext *C)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
RenderEngineType * CTX_data_engine_type(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
bool BKE_scene_uses_cycles(const Scene *scene)
Definition scene.cc:2832
bool BKE_scene_uses_cycles_experimental_features(Scene *scene)
Definition scene.cc:2848
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#define RPT_(msgid)
#define IFACE_(msgid)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ CACHEFILE_TYPE_ALEMBIC
@ UILST_LAYOUT_DEFAULT
@ BCONTEXT_CONSTRAINT
@ PROP_POINTER
Definition RNA_types.hh:155
#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
void uiLayoutSetContextPointer(uiLayout *layout, blender::StringRef name, PointerRNA *ptr)
@ UI_ITEM_R_NO_BG
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
void uiItemDecoratorR(uiLayout *layout, PointerRNA *ptr, std::optional< blender::StringRefNull > propname, int index)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
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 uiTemplateCacheFileProcedural(uiLayout *layout, const bContext *C, PointerRNA *fileptr)
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)
bool RE_engine_supports_alembic_procedural(const RenderEngineType *render_type, Scene *scene)
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
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, wmOperatorCallContext context, eUI_Item_Flag flag)
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
uiLayout & row(bool align)
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:4227