Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-01-26 20:02:33 +0300
committerJulian Eisel <julian@blender.org>2022-01-26 21:15:57 +0300
commitb57db4b79ed25f07176474b864d698ef48578f42 (patch)
tree73bbf756ae938b68a15a12ad9404b9c47092b111
parentfc0dd5583c3132cde4208bc8944469a92a601c62 (diff)
Cleanup: Reduce `void *` reliance of new RNA C++ Outliner elements
Continuation of the previous commit, this time addressing the same for RNA tree-elements.
-rw-r--r--source/blender/editors/space_outliner/outliner_draw.cc10
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.cc26
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_rna.cc31
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_rna.hh10
4 files changed, 55 insertions, 22 deletions
diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index 6de8d9539a9..1b64efd0088 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -81,6 +81,7 @@
#include "outliner_intern.hh"
#include "tree/tree_display.hh"
#include "tree/tree_element.hh"
+#include "tree/tree_element_rna.hh"
using namespace blender::ed::outliner;
@@ -1915,9 +1916,9 @@ static void outliner_draw_rnabuts(
LISTBASE_FOREACH (TreeElement *, te, lb) {
TreeStoreElem *tselem = TREESTORE(te);
if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
- if (tselem->type == TSE_RNA_PROPERTY) {
+ if (TreeElementRNAProperty *te_rna_prop = tree_element_cast<TreeElementRNAProperty>(te)) {
ptr = &te->rnaptr;
- prop = reinterpret_cast<PropertyRNA *>(te->directdata);
+ prop = te_rna_prop->getRNAProperty();
if (!TSELEM_OPEN(tselem, space_outliner)) {
if (RNA_property_type(prop) == PROP_POINTER) {
@@ -1959,9 +1960,10 @@ static void outliner_draw_rnabuts(
}
}
}
- else if (tselem->type == TSE_RNA_ARRAY_ELEM) {
+ else if (TreeElementRNAArrayElement *te_rna_array_elem =
+ tree_element_cast<TreeElementRNAArrayElement>(te)) {
ptr = &te->rnaptr;
- prop = reinterpret_cast<PropertyRNA *>(te->directdata);
+ prop = te_rna_array_elem->getRNAProperty();
uiDefAutoButR(block,
ptr,
diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc
index a10dbc94b34..f45e7607534 100644
--- a/source/blender/editors/space_outliner/outliner_edit.cc
+++ b/source/blender/editors/space_outliner/outliner_edit.cc
@@ -74,6 +74,9 @@
#include "GPU_material.h"
#include "outliner_intern.hh"
+#include "tree/tree_element_rna.hh"
+
+using namespace blender::ed::outliner;
static void outliner_show_active(SpaceOutliner *space_outliner,
ARegion *region,
@@ -1718,7 +1721,6 @@ static void tree_element_to_path(TreeElement *te,
TreeElement *tem, *temnext;
TreeStoreElem *tse /* , *tsenext */ /* UNUSED */;
PointerRNA *ptr, *nextptr;
- PropertyRNA *prop;
char *newpath = nullptr;
/* optimize tricks:
@@ -1751,7 +1753,6 @@ static void tree_element_to_path(TreeElement *te,
tem = (TreeElement *)ld->data;
tse = TREESTORE(tem);
ptr = &tem->rnaptr;
- prop = reinterpret_cast<PropertyRNA *>(tem->directdata);
/* check if we're looking for first ID, or appending to path */
if (*id) {
@@ -1759,7 +1760,9 @@ static void tree_element_to_path(TreeElement *te,
* - to prevent memory leaks, we must write to newpath not path,
* then free old path + swap them.
*/
- if (tse->type == TSE_RNA_PROPERTY) {
+ if (TreeElementRNAProperty *tem_rna_prop = tree_element_cast<TreeElementRNAProperty>(tem)) {
+ PropertyRNA *prop = tem_rna_prop->getRNAProperty();
+
if (RNA_property_type(prop) == PROP_POINTER) {
/* for pointer we just append property name */
newpath = RNA_path_append(*path, ptr, prop, 0, nullptr);
@@ -1827,8 +1830,7 @@ static void tree_element_to_path(TreeElement *te,
/* step 3: if we've got an ID, add the current item to the path */
if (*id) {
/* add the active property to the path */
- ptr = &te->rnaptr;
- prop = reinterpret_cast<PropertyRNA *>(te->directdata);
+ PropertyRNA *prop = tree_element_cast<TreeElementRNACommon>(te)->getRNAProperty();
/* array checks */
if (tselem->type == TSE_RNA_ARRAY_ELEM) {
@@ -1886,9 +1888,11 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner,
short flag = 0;
short groupmode = KSP_GROUP_KSNAME;
+ TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te);
+ PropertyRNA *prop = te_rna ? te_rna->getRNAProperty() : nullptr;
+
/* check if RNA-property described by this selected element is an animatable prop */
- if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) &&
- RNA_property_animateable(&te->rnaptr, reinterpret_cast<PropertyRNA *>(te->directdata))) {
+ if (prop && RNA_property_animateable(&te->rnaptr, prop)) {
/* get id + path + index info from the selected element */
tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
}
@@ -1901,8 +1905,7 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner,
/* array checks */
if (flag & KSP_FLAG_WHOLE_ARRAY) {
/* entire array was selected, so add drivers for all */
- arraylen = RNA_property_array_length(&te->rnaptr,
- reinterpret_cast<PropertyRNA *>(te->directdata));
+ arraylen = RNA_property_array_length(&te->rnaptr, prop);
}
else {
arraylen = array_index;
@@ -2084,8 +2087,9 @@ static void do_outliner_keyingset_editop(SpaceOutliner *space_outliner,
short groupmode = KSP_GROUP_KSNAME;
/* check if RNA-property described by this selected element is an animatable prop */
- if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) &&
- RNA_property_animateable(&te->rnaptr, reinterpret_cast<PropertyRNA *>(te->directdata))) {
+ if (TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te);
+ te_rna && te_rna->getRNAProperty() &&
+ RNA_property_animateable(&te->rnaptr, te_rna->getRNAProperty())) {
/* get id + path + index info from the selected element */
tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
}
diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc b/source/blender/editors/space_outliner/tree/tree_element_rna.cc
index 1aa30e1a99a..b39ff74b03a 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_rna.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_rna.cc
@@ -73,6 +73,11 @@ bool TreeElementRNACommon::expandPoll(const SpaceOutliner &) const
return isRNAValid();
}
+PropertyRNA *TreeElementRNACommon::getRNAProperty() const
+{
+ return nullptr;
+}
+
/* -------------------------------------------------------------------- */
/* RNA Struct */
@@ -108,10 +113,12 @@ void TreeElementRNAStruct::expand(SpaceOutliner &space_outliner) const
int tot = RNA_property_collection_length(ptr, iterprop);
CLAMP_MAX(tot, max_index);
+ TreeElementRNAProperty *parent_prop_te = legacy_te_.parent ?
+ tree_element_cast<TreeElementRNAProperty>(
+ legacy_te_.parent) :
+ nullptr;
/* auto open these cases */
- if (!legacy_te_.parent ||
- (RNA_property_type(reinterpret_cast<PropertyRNA *>(legacy_te_.parent->directdata))) ==
- PROP_POINTER) {
+ if (!parent_prop_te || (RNA_property_type(parent_prop_te->getRNAProperty()) == PROP_POINTER)) {
if (!tselem.used) {
tselem.flag &= ~TSE_CLOSED;
}
@@ -157,7 +164,6 @@ TreeElementRNAProperty::TreeElementRNAProperty(TreeElement &legacy_te,
PropertyRNA *prop = reinterpret_cast<PropertyRNA *>(propptr.data);
legacy_te_.name = RNA_property_ui_name(prop);
- legacy_te_.directdata = prop;
rna_prop_ = prop;
}
@@ -225,6 +231,11 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
}
}
+PropertyRNA *TreeElementRNAProperty::getRNAProperty() const
+{
+ return rna_prop_;
+}
+
/* -------------------------------------------------------------------- */
/* RNA Array Element */
@@ -236,11 +247,9 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te,
BLI_assert(legacy_te.store_elem->type == TSE_RNA_ARRAY_ELEM);
BLI_assert(legacy_te.parent && (legacy_te.parent->store_elem->type == TSE_RNA_PROPERTY));
- PropertyRNA *prop = reinterpret_cast<PropertyRNA *>(legacy_te_.parent->directdata);
- legacy_te_.directdata = prop;
legacy_te_.index = index;
- char c = RNA_property_array_item_char(prop, index);
+ char c = RNA_property_array_item_char(TreeElementRNAArrayElement::getRNAProperty(), index);
legacy_te_.name = reinterpret_cast<char *>(
MEM_callocN(sizeof(char[20]), "OutlinerRNAArrayName"));
@@ -253,4 +262,12 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te,
legacy_te_.flag |= TE_FREE_NAME;
}
+PropertyRNA *TreeElementRNAArrayElement::getRNAProperty() const
+{
+ /* Forward query to the parent (which is expected to be a #TreeElementRNAProperty). */
+ const TreeElementRNAProperty *parent_prop_te = tree_element_cast<TreeElementRNAProperty>(
+ legacy_te_.parent);
+ return parent_prop_te ? parent_prop_te->getRNAProperty() : nullptr;
+}
+
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.hh b/source/blender/editors/space_outliner/tree/tree_element_rna.hh
index 352b8763acb..bce527e724b 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_rna.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_rna.hh
@@ -43,6 +43,12 @@ class TreeElementRNACommon : public AbstractTreeElement {
bool isExpandValid() const override;
bool expandPoll(const SpaceOutliner &) const override;
+ /**
+ * If this element represents a property or is part of a property (array element), this returns
+ * the property. Otherwise nullptr.
+ */
+ virtual PropertyRNA *getRNAProperty() const;
+
bool isRNAValid() const;
};
@@ -63,6 +69,8 @@ class TreeElementRNAProperty : public TreeElementRNACommon {
public:
TreeElementRNAProperty(TreeElement &legacy_te, PointerRNA &rna_ptr, int index);
void expand(SpaceOutliner &space_outliner) const override;
+
+ PropertyRNA *getRNAProperty() const override;
};
/* -------------------------------------------------------------------- */
@@ -70,6 +78,8 @@ class TreeElementRNAProperty : public TreeElementRNACommon {
class TreeElementRNAArrayElement : public TreeElementRNACommon {
public:
TreeElementRNAArrayElement(TreeElement &legacy_te, PointerRNA &rna_ptr, int index);
+
+ PropertyRNA *getRNAProperty() const override;
};
} // namespace blender::ed::outliner