Blender V4.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
9#include <climits>
10#include <iostream>
11
12#include "BLI_string.h"
13
14#include "BLT_translation.hh"
15
16#include "DNA_outliner_types.h"
17#include "DNA_space_types.h"
18
19#include "MEM_guardedalloc.h"
20
21#include "RNA_access.hh"
22
23#include "../outliner_intern.hh"
24
25#include "tree_element_rna.hh"
26
27namespace blender::ed::outliner {
28
29/* Don't display arrays larger, weak but index is stored as a short,
30 * also the outliner isn't intended for editing such large data-sets. */
31BLI_STATIC_ASSERT(sizeof(TreeElement::index) == 2, "Index is no longer short!")
32
33/* -------------------------------------------------------------------- */
34/* Common functionality (#TreeElementRNACommon Base Class) */
35
37 : AbstractTreeElement(legacy_te), rna_ptr_(rna_ptr)
38{
39 /* Create an empty tree-element. */
40 if (!is_rna_valid()) {
41 legacy_te_.name = IFACE_("(empty)");
42 return;
43 }
44}
45
47{
48 return rna_ptr_.data != nullptr;
49}
50
51bool TreeElementRNACommon::expand_poll(const SpaceOutliner & /*space_outliner*/) const
52{
53 return is_rna_valid();
54}
55
60
62{
63 return nullptr;
64}
65
66/* -------------------------------------------------------------------- */
67/* RNA Struct */
68
70 : TreeElementRNACommon(legacy_te, rna_ptr)
71{
73
74 if (!is_rna_valid()) {
75 return;
76 }
77
78 legacy_te_.name = RNA_struct_name_get_alloc(&rna_ptr, nullptr, 0, nullptr);
79 if (legacy_te_.name) {
81 }
82 else {
84 }
85}
86
88{
91
92 /* If searching don't expand RNA entries */
93 if (SEARCHING_OUTLINER(&space_outliner) && BLI_strcasecmp("RNA", legacy_te_.name) == 0) {
94 tselem.flag &= ~TSE_CHILDSEARCH;
95 }
96
98 int tot = RNA_property_collection_length(&ptr, iterprop);
99 CLAMP_MAX(tot, max_index);
100
101 TreeElementRNAProperty *parent_prop_te = legacy_te_.parent ?
104 nullptr;
105 /* auto open these cases */
106 if (!parent_prop_te || (RNA_property_type(parent_prop_te->get_property_rna()) == PROP_POINTER)) {
107 if (!tselem.used) {
108 tselem.flag &= ~TSE_CLOSED;
109 }
110 }
111
112 if (TSELEM_OPEN(&tselem, &space_outliner)) {
113 for (int index = 0; index < tot; index++) {
114 PointerRNA propptr;
115 RNA_property_collection_lookup_int(&ptr, iterprop, index, &propptr);
116 if (!(RNA_property_flag(static_cast<PropertyRNA *>(propptr.data)) & PROP_HIDDEN)) {
118 }
119 }
120 }
121 else if (tot) {
123 }
124}
125
126/* -------------------------------------------------------------------- */
127/* RNA Property */
128
130 PointerRNA &rna_ptr,
131 const int index)
132 : TreeElementRNACommon(legacy_te, rna_ptr)
133{
135
136 if (!is_rna_valid()) {
137 return;
138 }
139
140 PointerRNA propptr;
141 PropertyRNA *iterprop = RNA_struct_iterator_property(rna_ptr.type);
142 RNA_property_collection_lookup_int(&rna_ptr, iterprop, index, &propptr);
143
144 PropertyRNA *prop = static_cast<PropertyRNA *>(propptr.data);
145
147 rna_prop_ = prop;
148}
149
151{
153 PointerRNA rna_ptr = rna_ptr_;
154 PropertyType proptype = RNA_property_type(rna_prop_);
155
156 /* If searching don't expand RNA entries */
157 if (SEARCHING_OUTLINER(&space_outliner) && BLI_strcasecmp("RNA", legacy_te_.name) == 0) {
158 tselem.flag &= ~TSE_CHILDSEARCH;
159 }
160
161 if (proptype == PROP_POINTER) {
162 PointerRNA pptr = RNA_property_pointer_get(&rna_ptr, rna_prop_);
163
164 if (pptr.data) {
165 if (TSELEM_OPEN(&tselem, &space_outliner)) {
167 }
168 else {
170 }
171 }
172 }
173 else if (proptype == PROP_COLLECTION) {
174 int tot = RNA_property_collection_length(&rna_ptr, rna_prop_);
175 CLAMP_MAX(tot, max_index);
176
177 if (TSELEM_OPEN(&tselem, &space_outliner)) {
178 for (int index = 0; index < tot; index++) {
179 PointerRNA pptr;
180 RNA_property_collection_lookup_int(&rna_ptr, rna_prop_, index, &pptr);
182 }
183 }
184 else if (tot) {
186 }
187 }
188 else if (ELEM(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
189 int tot = RNA_property_array_length(&rna_ptr, rna_prop_);
190 CLAMP_MAX(tot, max_index);
191
192 if (TSELEM_OPEN(&tselem, &space_outliner)) {
193 for (int index = 0; index < tot; index++) {
195 rna_ptr.owner_id,
196 &rna_ptr,
197 &legacy_te_,
199 index);
200 }
201 }
202 else if (tot) {
204 }
205 }
206}
207
209{
210 return rna_prop_;
211}
212
213/* -------------------------------------------------------------------- */
214/* RNA Array Element */
215
217 PointerRNA &rna_ptr,
218 const int index)
219 : TreeElementRNACommon(legacy_te, rna_ptr)
220{
222
223 BLI_assert(legacy_te.parent && (legacy_te.parent->store_elem->type == TSE_RNA_PROPERTY));
224 legacy_te_.index = index;
225
227
228 const size_t name_size = sizeof(char[20]);
229 legacy_te_.name = static_cast<char *>(MEM_callocN(name_size, "OutlinerRNAArrayName"));
230 if (c) {
231 BLI_snprintf((char *)legacy_te_.name, name_size, " %c", c);
232 }
233 else {
234 BLI_snprintf((char *)legacy_te_.name, name_size, " %d", index + 1);
235 }
237}
238
240{
241 /* Forward query to the parent (which is expected to be a #TreeElementRNAProperty). */
244 return parent_prop_te ? parent_prop_te->get_property_rna() : nullptr;
245}
246
247} // namespace blender::ed::outliner
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:87
#define BLI_assert(a)
Definition BLI_assert.h:50
int char char int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define CLAMP_MAX(a, c)
#define ELEM(...)
#define IFACE_(msgid)
@ TSE_RNA_ARRAY_ELEM
@ TSE_RNA_PROPERTY
@ TSE_RNA_STRUCT
Read Guarded memory(de)allocation.
PropertyType
Definition RNA_types.hh:64
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
@ PROP_HIDDEN
Definition RNA_types.hh:239
TreeElement * add_element(ListBase *lb, ID *owner_id, void *create_data, TreeElement *parent, short type, short index, const bool expand=true) const
TreeElementRNAArrayElement(TreeElement &legacy_te, PointerRNA &rna_ptr, int index)
bool expand_poll(const SpaceOutliner &) const override
virtual PropertyRNA * get_property_rna() const
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
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
TreeElementT * tree_element_cast(const TreeElement *te)
#define SEARCHING_OUTLINER(sov)
#define TREESTORE(a)
#define TSELEM_OPEN(telm, sv)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
PropertyType RNA_property_type(PropertyRNA *prop)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
char RNA_property_array_item_char(PropertyRNA *prop, int index)
int RNA_property_flag(PropertyRNA *prop)
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
const char * RNA_struct_ui_name(const StructRNA *type)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_property_ui_name(const PropertyRNA *prop)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
ID * owner_id
Definition RNA_types.hh:40
StructRNA * type
Definition RNA_types.hh:41
void * data
Definition RNA_types.hh:42
PointerRNA * ptr
Definition wm_files.cc:4126