Blender V4.3
tree_element.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 <iostream>
10#include <string>
11#include <string_view>
12
13#include "DNA_listBase.h"
14#include "DNA_space_types.h"
15
16#include "UI_resources.hh"
17
18#include "tree_display.hh"
20#include "tree_element_bone.hh"
30#include "tree_element_id.hh"
31#include "tree_element_label.hh"
36#include "tree_element_nla.hh"
39#include "tree_element_pose.hh"
40#include "tree_element_rna.hh"
42#include "tree_element_seq.hh"
45
46#include "../outliner_intern.hh"
47#include "tree_element.hh"
48
49namespace blender::ed::outliner {
50
51std::unique_ptr<AbstractTreeElement> AbstractTreeElement::create_from_type(const int type,
52 TreeElement &legacy_te,
53 ID *owner_id,
54 void *create_data)
55{
56 if (owner_id == nullptr && create_data == nullptr) {
57 return nullptr;
58 }
59
60 /*
61 * The following calls make an implicit assumption about what data was passed to the
62 * `create_data` argument of #add_element(). The old code does this already, here we just
63 * centralize it as much as possible for now. Would be nice to entirely get rid of that, no more
64 * `void *`.
65 *
66 * Once #add_element() is sufficiently simplified, it should be replaced by a C++ call. It could
67 * take the derived type as template parameter (e.g. #TreeElementAnimData) and use C++ perfect
68 * forwarding to pass any data to the type's constructor. If general Outliner code wants to
69 * access the data, they can query that through the derived element type then. There's no need
70 * for `void *` anymore then.
71 */
72
73 switch (type) {
74 case TSE_SOME_ID:
75 return TreeElementID::create_from_id(legacy_te, *owner_id);
77 return std::make_unique<TreeElementLabel>(legacy_te, static_cast<const char *>(create_data));
78 case TSE_ANIM_DATA:
79 return std::make_unique<TreeElementAnimData>(legacy_te,
80 *static_cast<AnimData *>(create_data));
81 case TSE_DRIVER_BASE:
82 return std::make_unique<TreeElementDriverBase>(legacy_te,
83 *static_cast<AnimData *>(create_data));
84 case TSE_NLA:
85 return std::make_unique<TreeElementNLA>(legacy_te, *static_cast<AnimData *>(create_data));
86 case TSE_NLA_TRACK:
87 return std::make_unique<TreeElementNLATrack>(legacy_te,
88 *static_cast<NlaTrack *>(create_data));
89 case TSE_NLA_ACTION:
90 return std::make_unique<TreeElementNLAAction>(legacy_te,
91 *reinterpret_cast<bAction *>(owner_id));
92 case TSE_GP_LAYER:
93 return std::make_unique<TreeElementGPencilLayer>(legacy_te,
94 *static_cast<bGPDlayer *>(create_data));
96 return std::make_unique<TreeElementGreasePencilNode>(
97 legacy_te,
98 *reinterpret_cast<GreasePencil *>(owner_id),
99 *static_cast<bke::greasepencil::TreeNode *>(create_data));
100 case TSE_R_LAYER_BASE:
101 return std::make_unique<TreeElementViewLayerBase>(legacy_te,
102 *reinterpret_cast<Scene *>(owner_id));
103 case TSE_R_LAYER:
104 return std::make_unique<TreeElementViewLayer>(
105 legacy_te, *reinterpret_cast<Scene *>(owner_id), *static_cast<ViewLayer *>(create_data));
107 return std::make_unique<TreeElementCollectionBase>(legacy_te,
108 *reinterpret_cast<Scene *>(owner_id));
110 return std::make_unique<TreeElementSceneObjectsBase>(legacy_te,
111 *reinterpret_cast<Scene *>(owner_id));
113 return std::make_unique<TreeElementOverridesBase>(legacy_te, *owner_id);
115 return std::make_unique<TreeElementOverridesProperty>(
116 legacy_te, *static_cast<TreeElementOverridesData *>(create_data));
118 return std::make_unique<TreeElementOverridesPropertyOperation>(
119 legacy_te, *static_cast<TreeElementOverridesData *>(create_data));
120 case TSE_RNA_STRUCT:
121 return std::make_unique<TreeElementRNAStruct>(legacy_te,
122 *static_cast<PointerRNA *>(create_data));
123 case TSE_RNA_PROPERTY:
124 return std::make_unique<TreeElementRNAProperty>(
125 legacy_te, *static_cast<PointerRNA *>(create_data), legacy_te.index);
127 return std::make_unique<TreeElementRNAArrayElement>(
128 legacy_te, *static_cast<PointerRNA *>(create_data), legacy_te.index);
129 case TSE_SEQUENCE:
130 return std::make_unique<TreeElementSequence>(legacy_te,
131 *static_cast<Sequence *>(create_data));
132 case TSE_SEQ_STRIP:
133 return std::make_unique<TreeElementSequenceStrip>(legacy_te,
134 *static_cast<Strip *>(create_data));
135 case TSE_SEQUENCE_DUP:
136 return std::make_unique<TreeElementSequenceStripDuplicate>(
137 legacy_te, *static_cast<Sequence *>(create_data));
138 case TSE_BONE:
139 return std::make_unique<TreeElementBone>(
140 legacy_te, *owner_id, *static_cast<Bone *>(create_data));
141 case TSE_EBONE:
142 return std::make_unique<TreeElementEditBone>(
143 legacy_te, *owner_id, *static_cast<EditBone *>(create_data));
145 return std::make_unique<TreeElementGPencilEffect>(legacy_te,
146 *reinterpret_cast<Object *>(owner_id),
147 *static_cast<ShaderFxData *>(create_data));
149 return std::make_unique<TreeElementGPencilEffectBase>(legacy_te,
150 *reinterpret_cast<Object *>(owner_id));
152 return std::make_unique<TreeElementDeformGroupBase>(legacy_te,
153 *reinterpret_cast<Object *>(owner_id));
154 case TSE_DEFGROUP:
155 return std::make_unique<TreeElementDeformGroup>(legacy_te,
156 *reinterpret_cast<Object *>(owner_id),
157 *static_cast<bDeformGroup *>(create_data));
158 case TSE_LINKED_PSYS:
159 return std::make_unique<TreeElementParticleSystem>(
160 legacy_te,
161 *reinterpret_cast<Object *>(owner_id),
162 *static_cast<ParticleSystem *>(create_data));
164 return std::make_unique<TreeElementConstraintBase>(legacy_te,
165 *reinterpret_cast<Object *>(owner_id));
166 case TSE_CONSTRAINT:
167 return std::make_unique<TreeElementConstraint>(legacy_te,
168 *reinterpret_cast<Object *>(owner_id),
169 *static_cast<bConstraint *>(create_data));
170 case TSE_POSE_BASE:
171 return std::make_unique<TreeElementPoseBase>(legacy_te,
172 *reinterpret_cast<Object *>(owner_id));
173 case TSE_POSE_CHANNEL:
174 return std::make_unique<TreeElementPoseChannel>(legacy_te,
175 *reinterpret_cast<Object *>(owner_id),
176 *static_cast<bPoseChannel *>(create_data));
178 return std::make_unique<TreeElementModifierBase>(legacy_te,
179 *reinterpret_cast<Object *>(owner_id));
180 case TSE_MODIFIER:
181 return std::make_unique<TreeElementModifier>(
182 legacy_te,
183 *reinterpret_cast<Object *>(owner_id),
184 *static_cast<ModifierDataStoreElem *>(create_data));
186 return std::make_unique<TreeElementLinkedNodeTree>(legacy_te, *owner_id);
187 case TSE_LINKED_OB:
188 return std::make_unique<TreeElementLinkedObject>(legacy_te, *owner_id);
190 return std::make_unique<TreeElementViewCollectionBase>(legacy_te,
191 *reinterpret_cast<Scene *>(owner_id));
193 return std::make_unique<TreeElementLayerCollection>(
194 legacy_te, *static_cast<LayerCollection *>(create_data));
195
197 return std::make_unique<TreeElementBoneCollectionBase>(
198 legacy_te, *reinterpret_cast<bArmature *>(owner_id));
200 return std::make_unique<TreeElementBoneCollection>(
201 legacy_te,
202 *reinterpret_cast<bArmature *>(owner_id),
203 *static_cast<BoneCollection *>(create_data));
204
205 default:
206 break;
207 }
208
209 return nullptr;
210}
211
213{
214 return "";
215}
216
217std::optional<BIFIconID> AbstractTreeElement::get_icon() const
218{
219 return {};
220}
221
223{
224 std::string path = legacy_te_.name;
225
226 for (TreeElement *parent = legacy_te_.parent; parent; parent = parent->parent) {
227 path = parent->name + std::string_view("/") + path;
228 }
229
230 std::cout << path << std::endl;
231}
232
234{
235 if (!TREESTORE(legacy_te)->used) {
236 TREESTORE(legacy_te)->flag &= ~TSE_CLOSED;
237 }
238}
239
241 ID *owner_id,
242 void *create_data,
243 TreeElement *parent,
244 short type,
245 short index,
246 const bool expand) const
247{
248 if (!display_) {
249 BLI_assert_msg(false,
250 "Element not registered properly through AbstractTreeDisplay::add_element(), "
251 "can't expand the tree further");
252 return nullptr;
253 }
254
255 return display_->add_element(lb, owner_id, create_data, parent, type, index, expand);
256}
257
258void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
259{
260 /* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
261 * expanding. Could be done nicer, we could request a small "expander" helper object from the
262 * element type, that the IDs have a more advanced implementation for. */
263 if (!tree_element.expand_poll(space_outliner)) {
264 return;
265 }
266 tree_element.expand(space_outliner);
267}
268
269} // namespace blender::ed::outliner
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
These structs are the foundation for all linked lists in the library system.
@ TSE_BONE_COLLECTION
@ TSE_POSE_CHANNEL
@ TSE_CONSTRAINT_BASE
@ TSE_LIBRARY_OVERRIDE_OPERATION
@ TSE_MODIFIER_BASE
@ TSE_GP_LAYER
@ TSE_SEQUENCE_DUP
@ TSE_RNA_ARRAY_ELEM
@ TSE_SEQUENCE
@ TSE_GPENCIL_EFFECT
@ TSE_LINKED_NODE_TREE
@ TSE_VIEW_COLLECTION_BASE
@ TSE_ANIM_DATA
@ TSE_LIBRARY_OVERRIDE
@ TSE_RNA_PROPERTY
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_EBONE
@ TSE_NLA_TRACK
@ TSE_BONE
@ TSE_LINKED_PSYS
@ TSE_DEFGROUP_BASE
@ TSE_CONSTRAINT
@ TSE_SCENE_COLLECTION_BASE
@ TSE_SCENE_OBJECTS_BASE
@ TSE_R_LAYER_BASE
@ TSE_LAYER_COLLECTION
@ TSE_GREASE_PENCIL_NODE
@ TSE_SEQ_STRIP
@ TSE_GENERIC_LABEL
@ TSE_GPENCIL_EFFECT_BASE
@ TSE_LINKED_OB
@ TSE_NLA
@ TSE_SOME_ID
@ TSE_DRIVER_BASE
@ TSE_NLA_ACTION
@ TSE_MODIFIER
@ TSE_BONE_COLLECTION_BASE
@ TSE_R_LAYER
@ TSE_RNA_STRUCT
@ TSE_POSE_BASE
@ TSE_DEFGROUP
static TreeElement * add_element(SpaceOutliner *space_outliner, ListBase *lb, ID *owner_id, void *create_data, TreeElement *parent, short type, short index, const bool expand=true)
virtual StringRefNull get_warning() const
static std::unique_ptr< AbstractTreeElement > create_from_type(int type, TreeElement &legacy_te, ID *owner_id, void *create_data)
TreeElement * add_element(ListBase *lb, ID *owner_id, void *create_data, TreeElement *parent, short type, short index, const bool expand=true) const
static void uncollapse_by_default(TreeElement *legacy_te)
virtual bool expand_poll(const SpaceOutliner &) const
virtual void expand(SpaceOutliner &) const
virtual std::optional< BIFIconID > get_icon() const
static std::unique_ptr< TreeElementID > create_from_id(TreeElement &legacy_te, ID &id)
void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
#define TREESTORE(a)
Definition DNA_ID.h:413
Establish and manage Outliner trees for different display modes.