Blender V5.0
tree_element_id.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 "DNA_ID.h"
10#include "DNA_space_types.h"
11
12#include "BKE_anim_data.hh"
13
14#include "../outliner_intern.hh"
15#include "common.hh"
29
30#include "tree_element_id.hh"
31
32namespace blender::ed::outliner {
33
34std::unique_ptr<TreeElementID> TreeElementID::create_from_id(TreeElement &legacy_te, ID &id)
35{
36 if (ID_TYPE_IS_DEPRECATED(GS(id.name))) {
37 BLI_assert_msg(0, "Outliner trying to build tree-element for deprecated ID type");
38 return nullptr;
39 }
40
41 switch (ID_Type type = GS(id.name); type) {
42 case ID_LI:
43 return std::make_unique<TreeElementIDLibrary>(legacy_te, (Library &)id);
44 case ID_SCE:
45 return std::make_unique<TreeElementIDScene>(legacy_te, (Scene &)id);
46 case ID_ME:
47 return std::make_unique<TreeElementIDMesh>(legacy_te, (Mesh &)id);
48 case ID_CU_LEGACY:
49 return std::make_unique<TreeElementIDCurve>(legacy_te, (Curve &)id);
50 case ID_MB:
51 return std::make_unique<TreeElementIDMetaBall>(legacy_te, (MetaBall &)id);
52 case ID_TE:
53 return std::make_unique<TreeElementIDTexture>(legacy_te, (Tex &)id);
54 case ID_LS:
55 return std::make_unique<TreeElementIDLineStyle>(legacy_te, (FreestyleLineStyle &)id);
56 case ID_GD_LEGACY:
57 return std::make_unique<TreeElementIDGPLegacy>(legacy_te, (bGPdata &)id);
58 case ID_GP:
59 return std::make_unique<TreeElementIDGreasePencil>(legacy_te, (GreasePencil &)id);
60 case ID_GR:
61 return std::make_unique<TreeElementIDCollection>(legacy_te, (Collection &)id);
62 case ID_AR:
63 return std::make_unique<TreeElementIDArmature>(legacy_te, (bArmature &)id);
64 case ID_OB:
65 return std::make_unique<TreeElementIDObject>(legacy_te, (Object &)id);
66 case ID_AC:
67 return std::make_unique<TreeElementIDAction>(legacy_te, (bAction &)id);
68 case ID_MA:
69 case ID_LT:
70 case ID_LA:
71 case ID_CA:
72 case ID_KE:
73 case ID_SCR:
74 case ID_WO:
75 case ID_SPK:
76 case ID_NT:
77 case ID_BR:
78 case ID_PA:
79 case ID_MC:
80 case ID_MSK:
81 case ID_LP:
82 case ID_WS:
83 case ID_CV:
84 case ID_PT:
85 case ID_VO:
86 case ID_WM:
87 case ID_IM:
88 case ID_VF:
89 case ID_TXT:
90 case ID_SO:
91 case ID_PAL:
92 case ID_PC:
93 case ID_CF:
94 return std::make_unique<TreeElementID>(legacy_te, id);
95 }
96
97 return nullptr;
98}
99
100/* -------------------------------------------------------------------- */
101/* ID Tree-Element Base Class (common/default logic) */
102
104 : AbstractTreeElement(legacy_te), id_(id)
105{
106 BLI_assert(legacy_te_.store_elem->type == TSE_SOME_ID);
108
109 /* Default, some specific types override this. */
110 legacy_te_.name = id.name + 2;
111 legacy_te_.idcode = GS(id.name);
112}
113
114bool TreeElementID::expand_poll(const SpaceOutliner &space_outliner) const
115{
116 const TreeStoreElem *tsepar = legacy_te_.parent ? TREESTORE(legacy_te_.parent) : nullptr;
117 return (tsepar == nullptr || tsepar->type != TSE_ID_BASE || space_outliner.filter_id_type);
118}
119
120void TreeElementID::expand(SpaceOutliner & /*space_outliner*/) const
121{
122 /* Not all IDs support animation data. Will be null then. */
123 AnimData *anim_data = BKE_animdata_from_id(&id_);
124 if (anim_data) {
125 expand_animation_data(anim_data);
126 }
127}
128
130{
131 if (outliner_animdata_test(anim_data)) {
132 add_element(&legacy_te_.subtree, &id_, anim_data, &legacy_te_, TSE_ANIM_DATA, 0);
133 }
134}
135
136} // namespace blender::ed::outliner
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:83
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
ID and Library types, which are fundamental for SDNA.
#define ID_TYPE_IS_DEPRECATED(id_type)
Definition DNA_ID.h:749
ID_Type
@ ID_WM
@ ID_CA
@ ID_AR
@ ID_MC
@ ID_CF
@ ID_LI
@ ID_TE
@ ID_IM
@ ID_VO
@ ID_WS
@ ID_NT
@ ID_LA
@ ID_KE
@ ID_TXT
@ ID_SO
@ ID_SCE
@ ID_LS
@ ID_MSK
@ ID_CV
@ ID_PAL
@ ID_BR
@ ID_LP
@ ID_WO
@ ID_MA
@ ID_AC
@ ID_SCR
@ ID_CU_LEGACY
@ ID_GD_LEGACY
@ ID_VF
@ ID_ME
@ ID_GR
@ ID_SPK
@ ID_MB
@ ID_LT
@ ID_OB
@ ID_GP
@ ID_PA
@ ID_PT
@ ID_PC
#define TSE_IS_REAL_ID(_tse)
@ TSE_ANIM_DATA
@ TSE_ID_BASE
@ TSE_SOME_ID
TreeElement * add_element(ListBase *lb, ID *owner_id, void *create_data, TreeElement *parent, short type, short index, const bool expand=true) const
bool expand_poll(const SpaceOutliner &) const override
TreeElementID(TreeElement &legacy_te, ID &id)
static std::unique_ptr< TreeElementID > create_from_id(TreeElement &legacy_te, ID &id)
void expand_animation_data(AnimData *) const
void expand(SpaceOutliner &) const override
#define GS(x)
bool outliner_animdata_test(const AnimData *adt)
Definition common.cc:62
#define TREESTORE(a)
const char * name
Definition DNA_ID.h:414