Blender V5.3
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.hh"
10#include "BLI_string_ref.hh"
11#include "BLI_string_utf8.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
29#include "interface_intern.hh"
30
31namespace blender::ui {
32
34{
35 if (!*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 (!*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 Layout *row = &layout->row(false);
56 row->prop(fileptr, "is_sequence", UI_ITEM_NONE, std::nullopt, ICON_NONE);
57
58 row = &layout->row(true, IFACE_("Override Frame"));
59 Layout &sub = row->row(true);
61 sub.prop(fileptr, "override_frame", UI_ITEM_NONE, "", ICON_NONE);
62 Layout &subsub = sub.row(true);
63 subsub.active_set(RNA_boolean_get(fileptr, "override_frame"));
64 subsub.prop(fileptr, "frame", UI_ITEM_NONE, "", ICON_NONE);
65 row->decorator(fileptr, "frame", 0);
66
67 row = &layout->row(false);
68 row->prop(fileptr, "frame_offset", UI_ITEM_NONE, std::nullopt, ICON_NONE);
69 row->active_set(!RNA_boolean_get(fileptr, "is_sequence"));
70}
71
72static void cache_file_layer_item(uiList * /*ui_list*/,
73 const bContext * /*C*/,
74 Layout &layout,
75 PointerRNA * /*dataptr*/,
76 PointerRNA *itemptr,
77 int /*icon*/,
78 PointerRNA * /*active_dataptr*/,
79 const char * /*active_propname*/,
80 int /*index*/,
81 int /*flt_flag*/)
82{
83 Layout &row = layout.row(true);
84 row.prop(itemptr, "hide_layer", ITEM_R_NO_BG, "", ICON_NONE);
85 row.prop(itemptr, "filepath", ITEM_R_NO_BG, "", ICON_NONE);
86}
87
89{
90 uiListType *list_type = MEM_new_zeroed<uiListType>(__func__);
91
92 STRNCPY_UTF8(list_type->idname, "UI_UL_cache_file_layers");
94
95 return list_type;
96}
97
98void template_uilist_flags(Layout *layout, const bContext *C, PointerRNA *fileptr)
99{
100 if (!*fileptr) {
101 return;
102 }
103
104 /* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
105 layout->context_ptr_set("edit_cachefile", fileptr);
106
107 Layout &row = layout->row(false);
108 Layout *col = &row.column(true);
109
110 template_uilist(col,
111 const_cast<bContext *>(C),
112 "UI_UL_cache_file_layers",
113 "cache_file_layers",
114 fileptr,
115 "layers",
116 fileptr,
117 "active_index",
118 "",
119 1,
120 5,
123
124 col = &row.column(true);
125 col->op("cachefile.layer_add", "", ICON_ADD);
126 col->op("cachefile.layer_remove", "", ICON_REMOVE);
127
128 CacheFile *file = static_cast<CacheFile *>(fileptr->data);
129 if (file->layers.count() > 1) {
130 col->separator(1.0f);
131 col->op("cachefile.layer_move", "", ICON_TRIA_UP);
132 col->op("cachefile.layer_move", "", ICON_TRIA_DOWN);
133 }
134}
135
137 const StringRefNull propname,
138 PointerRNA *r_file_ptr)
139{
140 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
141
142 if (!prop) {
143 printf("%s: property not found: %s.%s\n",
144 __func__,
146 propname.c_str());
147 return false;
148 }
149
150 if (RNA_property_type(prop) != PROP_POINTER) {
151 printf("%s: expected pointer property for %s.%s\n",
152 __func__,
154 propname.c_str());
155 return false;
156 }
157
158 *r_file_ptr = RNA_property_pointer_get(ptr, prop);
159 return true;
160}
161
163 const bContext *C,
164 PointerRNA *ptr,
165 const StringRefNull propname)
166{
167 if (!*ptr) {
168 return;
169 }
170
171 PointerRNA fileptr;
172 if (!template_cache_file_pointer(ptr, propname, &fileptr)) {
173 return;
174 }
175
176 CacheFile *file = static_cast<CacheFile *>(fileptr.data);
177
178 layout->context_ptr_set("edit_cachefile", &fileptr);
179
180 template_id(layout, C, ptr, propname, nullptr, "CACHEFILE_OT_open", nullptr);
181
182 if (!file) {
183 return;
184 }
185
187
188 layout->use_property_split_set(true);
189
190 Layout &row = layout->row(true);
191 row.prop(&fileptr, "filepath", UI_ITEM_NONE, std::nullopt, ICON_NONE);
192 Layout &sub = row.row(true);
193 sub.op("cachefile.reload", "", ICON_FILE_REFRESH);
194
195 if (sbuts->mainb == BCONTEXT_CONSTRAINT) {
196 layout->row(false).prop(&fileptr, "scale", UI_ITEM_NONE, IFACE_("Manual Scale"), ICON_NONE);
197 }
198
199 /* TODO: unused for now, so no need to expose. */
200#if 0
201 row = &layout->row(false);
202 row->prop(&fileptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
203
204 row = &layout->row(false);
205 row->prop(&fileptr, "up_axis", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
206#endif
207}
208
209} // namespace blender::ui
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
constexpr const char * c_str() const
bool template_cache_file_pointer(PointerRNA *ptr, StringRefNull propname, PointerRNA *r_file_ptr)
void template_uilist_flags(Layout *layout, const bContext *C, PointerRNA *fileptr)
uiListType * UI_UL_cache_file_layers()
void template_uilist(Layout *layout, const bContext *C, const char *listtype_name, const char *list_id, PointerRNA *dataptr, StringRefNull propname, PointerRNA *active_dataptr, StringRefNull active_propname, const char *item_dyntip_propname, int rows, int maxrows, int layout_type, enum TemplateListFlags flags)
void template_id(Layout *layout, const bContext *C, PointerRNA *ptr, StringRefNull propname, const char *newop, const char *openop, const char *unlinkop, int filter=TEMPLATE_ID_FILTER_ALL, bool live_icon=false, std::optional< StringRef > text=std::nullopt)
void template_cache_file(Layout *layout, const bContext *C, PointerRNA *ptr, StringRefNull propname)
void template_cache_file_time_settings(Layout *layout, PointerRNA *fileptr)
void template_cache_file_velocity(Layout *layout, PointerRNA *fileptr)
static void cache_file_layer_item(uiList *, const bContext *, Layout &layout, PointerRNA *, PointerRNA *itemptr, int, PointerRNA *, const char *, int, int)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
PropertyType RNA_property_type(PropertyRNA *prop)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ PROP_POINTER
Definition RNA_types.hh:215
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
const char * RNA_struct_identifier(const StructRNA *type)
SpaceProperties * CTX_wm_space_properties(const bContext *C)
ListBaseT< CacheFileLayer > layers
StructRNA * type
Definition RNA_types.hh:63
eSpaceButtons_Context mainb
char idname[BKE_ST_MAXNAME]
uiListDrawItemFunc draw_item
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void decorator(PointerRNA *ptr, PropertyRNA *prop, int index)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
void context_ptr_set(StringRef name, const PointerRNA *ptr)