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