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