Blender V5.3
tree_element_id_action.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_action_types.h"
10#include "DNA_outliner_types.h"
11#include "DNA_space_types.h"
12
13#include "../outliner_intern.hh"
14
15#include "tree_display.hh"
19
20#include "ANIM_action.hh"
21
22namespace blender::ed::outliner {
23
25 : TreeElementID(legacy_te, action.id), action_(action)
26{
27 /* If the outliner is showing the Action because it's in some hierarchical data mode, only show
28 * the slot that is used by the parent ID tree element. Showing all slots will create quadratic
29 * complexity, as each user of the Action has a child tree element for the Action. This means the
30 * complexity is O(U x S), where U = the number of users of the Action, and S = the number of
31 * slots. Typically U = S.
32 *
33 * In `SO_LIBRARIES` mode, the outliner shows Actions as a flat list in the 'Actions' subtree,
34 * and also (just like `SO_SCENES` and `SO_VIEW_LAYER`) underneath each user. The former should
35 * show all slots, whereas the latter should only show the assigned one. The difference is
36 * detected by the type of the parent tree element.
37 *
38 * To simplify the code, the mode of the Outliner is ignored, and whether to show all slots or
39 * not is determined purely by the type of the parent tree element. See the constructor. */
40
41 /* Fetch the assigned slot handle from the parent node in the tree. This is done this way,
42 * because AbstractTreeElement::add_element() constructs the element and immediately calls its
43 * expand() function. That means that there is no time for the creator of this
44 * TreeElementIDAction to pass us the slot handle explicitly.
45 *
46 * Adding a constructor parameter for this is also not feasible, due to the generic nature of the
47 * code that constructs this TreeElement. */
48 const TreeElement *legacy_parent = legacy_te.parent;
49 if (!legacy_parent) {
50 return;
51 }
52
54 legacy_parent);
55 if (!parent_anim_te) {
56 return;
57 }
58
59 this->slot_handle_.emplace(parent_anim_te->get_slot_handle());
60}
61
62void TreeElementIDAction::expand(SpaceOutliner & /*space_outliner*/) const
63{
64 animrig::Action &action = action_.wrap();
65 if (!this->slot_handle_.has_value()) {
66 /* Show all slots of the Action. */
67 int index = 0;
68 for (animrig::Slot *slot : action.slots()) {
70 {.index = index++, .owner_id = reinterpret_cast<ID *>(&action_)}, *slot);
71 }
72 return;
73 }
74
75 /* Only show a single slot. Note that the slot handle value itself could be animrig::unassigned,
76 * in which case there will not be a slot to show. */
77 animrig::Slot *slot = action.slot_for_handle(this->slot_handle_.value());
78 if (!slot) {
79 return;
80 }
81 add_element<TreeElementActionSlot>({.owner_id = reinterpret_cast<ID *>(&action_)}, *slot);
82}
83
84} // namespace blender::ed::outliner
Functions and classes to work with Actions.
Span< const Slot * > slots() const
Slot * slot_for_handle(slot_handle_t handle)
TreeElement * add_element(const TreeElementAddParams &params, Args &&...args) const
TreeElementIDAction(TreeElement &legacy_te, bAction &action)
void expand(SpaceOutliner &space_outliner) const override
TreeElementID(TreeElement &legacy_te, ID &id)
TreeElementT * tree_element_cast(const TreeElement *te)
Establish and manage Outliner trees for different display modes.