Blender V5.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
8
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"
19#include "tree_element_id.hh"
20
21#include "../outliner_intern.hh"
22#include "tree_element.hh"
23
24namespace blender::ed::outliner {
25
27{
28 return "";
29}
30
31std::optional<BIFIconID> AbstractTreeElement::get_icon() const
32{
33 return {};
34}
35
37{
38 std::string path = legacy_te_.name;
39
40 for (TreeElement *parent = legacy_te_.parent; parent; parent = parent->parent) {
41 path = parent->name + std::string_view("/") + path;
42 }
43
44 std::cout << path << std::endl;
45}
46
48{
49 if (!TREESTORE(legacy_te)->used) {
50 TREESTORE(legacy_te)->flag &= ~TSE_CLOSED;
51 }
52}
53
54AbstractTreeDisplay *AbstractTreeElement::display_for_adding(TreeElementAddParams &params) const
55{
56 if (!display_) {
57 BLI_assert_msg(false,
58 "Element not registered properly through AbstractTreeDisplay::add_element(), "
59 "cannot expand the tree further");
60 return nullptr;
61 }
62
63 /* Default to adding a child to this element itself. Note that the sub-tree to add to is derived
64 * from the parent by #AbstractTreeDisplay::add_element(), so it doesn't have to be filled in
65 * here (which would need a complete #TreeElement in the header). */
66 if (!params.parent) {
67 params.parent = &legacy_te_;
68 }
69
70 return display_;
71}
72
74{
75 TreeElementAddParams resolved_params = params;
76 AbstractTreeDisplay *display = display_for_adding(resolved_params);
77 return display ? display->add_id_element(resolved_params, id) : nullptr;
78}
79
80void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
81{
82 /* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
83 * expanding. Could be done nicer, we could request a small "expander" helper object from the
84 * element type, that the IDs have a more advanced implementation for. */
85 if (!tree_element.expand_poll(space_outliner)) {
86 return;
87 }
88 tree_element.expand(space_outliner);
89}
90
91} // namespace blender::ed::outliner
These structs are the foundation for all linked lists in the library system.
#define BLI_assert_msg(a, msg)
TreeElement * add_id_element(const TreeElementAddParams &params, ID *id)
virtual StringRefNull get_warning() const
friend void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
static void uncollapse_by_default(TreeElement *legacy_te)
virtual bool expand_poll(const SpaceOutliner &) const
virtual void expand(SpaceOutliner &) const
TreeElement * add_id_element(const TreeElementAddParams &params, ID *id) const
virtual std::optional< BIFIconID > get_icon() const
#define TREESTORE(a)
Establish and manage Outliner trees for different display modes.