Blender V5.3
tree_element_rna.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_string.hh"
10#include "BLI_string_utf8.hh"
11
12#include "BLT_translation.hh"
13
14#include "DNA_outliner_types.h"
15#include "DNA_space_types.h"
16
17#include "MEM_guardedalloc.h"
18
19#include "RNA_access.hh"
20
21#include "../outliner_intern.hh"
22
23#include "tree_display.hh"
24#include "tree_element_rna.hh"
25
26namespace blender::ed::outliner {
27
28/* Don't display arrays larger, weak but index is stored as a short,
29 * also the outliner isn't intended for editing such large data-sets. */
30BLI_STATIC_ASSERT(sizeof(TreeElement::index) == 2, "Index is no longer short!")
31
32/* -------------------------------------------------------------------- */
33/* Common functionality (#TreeElementRNACommon Base Class) */
34
36 : AbstractTreeElement(legacy_te), rna_ptr_(rna_ptr)
37{
38 /* Create an empty tree-element. */
39 if (!is_rna_valid()) {
40 legacy_te_.name = IFACE_("(empty)");
41 return;
42 }
43}
44
46{
47 return rna_ptr_;
48}
49
50bool TreeElementRNACommon::expand_poll(const SpaceOutliner & /*space_outliner*/) const
51{
52 return is_rna_valid();
53}
54
56{
57 return rna_ptr.owner_id;
58}
59
61{
62 return owner_id(rna_ptr);
63}
64
66{
67 /* Not owned by an ID (e.g. a run-time only pointer), identify it by the data it points at. */
68 return rna_ptr.data;
69}
70
71const void *TreeElementRNACommon::persistent_ptr(PointerRNA &rna_ptr, int /*index*/)
72{
73 return persistent_ptr(rna_ptr);
74}
75
80
82{
83 return nullptr;
84}
85
86/* -------------------------------------------------------------------- */
87/* RNA Struct */
88
90 : TreeElementRNACommon(legacy_te, rna_ptr)
91{
93
94 if (!is_rna_valid()) {
95 return;
96 }
97
98 legacy_te_.name = RNA_struct_name_get_alloc(&rna_ptr, nullptr, 0, nullptr);
99 if (legacy_te_.name) {
101 }
102 else {
104 }
105}
106
108{
110 PointerRNA ptr = rna_ptr_;
111
112 /* If searching don't expand RNA entries */
113 if (SEARCHING_OUTLINER(&space_outliner) && BLI_strcasecmp("RNA", legacy_te_.name) == 0) {
114 tselem.flag &= ~TSE_CHILDSEARCH;
115 }
116
118 int tot = RNA_property_collection_length(&ptr, iterprop);
119 CLAMP_MAX(tot, max_index);
120
121 TreeElementRNAProperty *parent_prop_te = legacy_te_.parent ?
124 nullptr;
125 /* auto open these cases */
126 if (!parent_prop_te || (RNA_property_type(parent_prop_te->get_property_rna()) == PROP_POINTER)) {
127 if (!tselem.used) {
128 tselem.flag &= ~TSE_CLOSED;
129 }
130 }
131
132 if (TSELEM_OPEN(&tselem, &space_outliner)) {
133 for (int index = 0; index < tot; index++) {
134 PointerRNA propptr;
135 RNA_property_collection_lookup_int(&ptr, iterprop, index, &propptr);
136 if (!(RNA_property_flag(static_cast<PropertyRNA *>(propptr.data)) & PROP_HIDDEN)) {
138 }
139 }
140 }
141 else if (tot) {
143 }
144}
145
146std::optional<BIFIconID> TreeElementRNAStruct::get_icon() const
147{
149 ID *id = static_cast<ID *>(rna_ptr_.data);
150 if (id && GS(id->name) == ID_LI && id_cast<Library *>(id)->flag & LIBRARY_FLAG_IS_ARCHIVE) {
151 return ICON_PACKAGE;
152 }
153 else {
155 }
156 }
157 else {
159 }
160}
161/* -------------------------------------------------------------------- */
162/* RNA Property */
163
165 PointerRNA &rna_ptr,
166 const int index)
167 : TreeElementRNACommon(legacy_te, rna_ptr)
168{
170
171 if (!is_rna_valid()) {
172 return;
173 }
174
175 PointerRNA propptr;
176 PropertyRNA *iterprop = RNA_struct_iterator_property(rna_ptr.type);
177 RNA_property_collection_lookup_int(&rna_ptr, iterprop, index, &propptr);
178
179 PropertyRNA *prop = static_cast<PropertyRNA *>(propptr.data);
180
182 rna_prop_ = prop;
183}
184
186{
188 PointerRNA rna_ptr = rna_ptr_;
189 PropertyType proptype = RNA_property_type(rna_prop_);
190
191 /* If searching don't expand RNA entries */
192 if (SEARCHING_OUTLINER(&space_outliner) && BLI_strcasecmp("RNA", legacy_te_.name) == 0) {
193 tselem.flag &= ~TSE_CHILDSEARCH;
194 }
195
196 if (proptype == PROP_POINTER) {
197 PointerRNA pptr = RNA_property_pointer_get(&rna_ptr, rna_prop_);
198
199 if (pptr) {
200 if (TSELEM_OPEN(&tselem, &space_outliner)) {
201 add_element<TreeElementRNAStruct>({.index = -1}, pptr);
202 }
203 else {
205 }
206 }
207 }
208 else if (proptype == PROP_COLLECTION) {
209 int tot = RNA_property_collection_length(&rna_ptr, rna_prop_);
210 CLAMP_MAX(tot, max_index);
211
212 if (TSELEM_OPEN(&tselem, &space_outliner)) {
213 for (int index = 0; index < tot; index++) {
214 PointerRNA pptr;
215 RNA_property_collection_lookup_int(&rna_ptr, rna_prop_, index, &pptr);
217 }
218 }
219 else if (tot) {
221 }
222 }
223 else if (ELEM(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
224 int tot = RNA_property_array_length(&rna_ptr, rna_prop_);
225 CLAMP_MAX(tot, max_index);
226
227 if (TSELEM_OPEN(&tselem, &space_outliner)) {
228 for (int index = 0; index < tot; index++) {
230 }
231 }
232 else if (tot) {
234 }
235 }
236}
237
239{
240 return rna_prop_;
241}
242
243/* -------------------------------------------------------------------- */
244/* RNA Array Element */
245
247 PointerRNA &rna_ptr,
248 const int index)
249 : TreeElementRNACommon(legacy_te, rna_ptr)
250{
252
253 BLI_assert(legacy_te.parent && (legacy_te.parent->store_elem->type == TSE_RNA_PROPERTY));
255
257
258 const size_t name_size = sizeof(char[20]);
259 char *name = MEM_new_array_zeroed<char>(name_size, "OutlinerRNAArrayName");
260 if (c) {
261 BLI_snprintf_utf8(name, name_size, " %c", c);
262 }
263 else {
264 BLI_snprintf_utf8(name, name_size, " %d", index + 1);
265 }
266 legacy_te_.name = name;
268}
269
271{
272 /* Forward query to the parent (which is expected to be a #TreeElementRNAProperty). */
275 return parent_prop_te ? parent_prop_te->get_property_rna() : nullptr;
276}
277
278} // namespace blender::ed::outliner
#define IFACE_(msgid)
Read Blender memory allocation and freeing.
#define CLAMP_MAX(a, c)
#define ELEM(...)
TreeElement * add_element(const TreeElementAddParams &params, Args &&...args) const
TreeElementRNAArrayElement(TreeElement &legacy_te, PointerRNA &rna_ptr, int index)
bool expand_poll(const SpaceOutliner &) const override
virtual PropertyRNA * get_property_rna() const
static const void * persistent_ptr(PointerRNA &rna_ptr)
TreeElementRNACommon(TreeElement &legacy_te, PointerRNA &rna_ptr)
static ID * owner_id(PointerRNA &rna_ptr)
void expand(SpaceOutliner &space_outliner) const override
TreeElementRNAProperty(TreeElement &legacy_te, PointerRNA &rna_ptr, int index)
PropertyRNA * get_property_rna() const override
TreeElementRNAStruct(TreeElement &legacy_te, PointerRNA &rna_ptr)
void expand(SpaceOutliner &space_outliner) const override
std::optional< BIFIconID > get_icon() const override
BLI_STATIC_ASSERT(MBC_BATCH_LEN< 64, "Number of batches exceeded the limit of bit fields")
TreeElementT * tree_element_cast(const TreeElement *te)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int char char int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
const char * RNA_struct_ui_name(const StructRNA *type)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
PropertyType RNA_property_type(PropertyRNA *prop)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_COLLECTION
Definition RNA_types.hh:216
char RNA_property_array_item_char(PropertyRNA *prop, int index)
int RNA_property_flag(PropertyRNA *prop)
@ LIBRARY_FLAG_IS_ARCHIVE
int RNA_struct_ui_icon(const StructRNA *type)
bool RNA_struct_is_ID(const StructRNA *type)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_HIDDEN
Definition RNA_types.hh:408
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
#define SEARCHING_OUTLINER(sov)
#define TREESTORE(a)
#define TSELEM_OPEN(telm, sv)
StructRNA * type
Definition RNA_types.hh:63
eTreeStoreElem_Flag flag
Establish and manage Outliner trees for different display modes.