Blender  V3.3
tree_element.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "DNA_anim_types.h"
8 #include "DNA_listBase.h"
9 #include "DNA_space_types.h"
10 
11 #include "UI_resources.h"
12 
13 #include "BLT_translation.h"
14 
17 #include "tree_element_driver.hh"
19 #include "tree_element_id.hh"
20 #include "tree_element_label.hh"
21 #include "tree_element_nla.hh"
23 #include "tree_element_rna.hh"
25 #include "tree_element_seq.hh"
27 
28 #include "../outliner_intern.hh"
29 #include "tree_element.hh"
30 
31 namespace blender::ed::outliner {
32 
33 std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const int type,
34  TreeElement &legacy_te,
35  void *idv)
36 {
37  if (idv == nullptr) {
38  return nullptr;
39  }
40 
41  /*
42  * The following calls make an implicit assumption about what data was passed to the `idv`
43  * argument of #outliner_add_element(). The old code does this already, here we just centralize
44  * it as much as possible for now. Would be nice to entirely get rid of that, no more `void *`.
45  *
46  * Once #outliner_add_element() is sufficiently simplified, it should be replaced by a C++ call.
47  * It could take the derived type as template parameter (e.g. #TreeElementAnimData) and use C++
48  * perfect forwarding to pass any data to the type's constructor.
49  * If general Outliner code wants to access the data, they can query that through the derived
50  * element type then. There's no need for `void *` anymore then.
51  */
52 
53  switch (type) {
54  case TSE_SOME_ID:
55  return TreeElementID::createFromID(legacy_te, *static_cast<ID *>(idv));
56  case TSE_GENERIC_LABEL:
57  return std::make_unique<TreeElementLabel>(legacy_te, static_cast<const char *>(idv));
58  case TSE_ANIM_DATA:
59  return std::make_unique<TreeElementAnimData>(legacy_te,
60  *reinterpret_cast<IdAdtTemplate *>(idv)->adt);
61  case TSE_DRIVER_BASE:
62  return std::make_unique<TreeElementDriverBase>(legacy_te, *static_cast<AnimData *>(idv));
63  case TSE_NLA:
64  return std::make_unique<TreeElementNLA>(legacy_te, *static_cast<AnimData *>(idv));
65  case TSE_NLA_TRACK:
66  return std::make_unique<TreeElementNLATrack>(legacy_te, *static_cast<NlaTrack *>(idv));
67  case TSE_NLA_ACTION:
68  return std::make_unique<TreeElementNLAAction>(legacy_te, *static_cast<bAction *>(idv));
69  case TSE_GP_LAYER:
70  return std::make_unique<TreeElementGPencilLayer>(legacy_te, *static_cast<bGPDlayer *>(idv));
71  case TSE_R_LAYER_BASE:
72  return std::make_unique<TreeElementViewLayerBase>(legacy_te, *static_cast<Scene *>(idv));
74  return std::make_unique<TreeElementCollectionBase>(legacy_te, *static_cast<Scene *>(idv));
76  return std::make_unique<TreeElementSceneObjectsBase>(legacy_te, *static_cast<Scene *>(idv));
78  return std::make_unique<TreeElementOverridesBase>(legacy_te, *static_cast<ID *>(idv));
80  return std::make_unique<TreeElementOverridesProperty>(
81  legacy_te, *static_cast<TreeElementOverridesData *>(idv));
83  return std::make_unique<TreeElementOverridesPropertyOperation>(
84  legacy_te, *static_cast<TreeElementOverridesData *>(idv));
85  case TSE_RNA_STRUCT:
86  return std::make_unique<TreeElementRNAStruct>(legacy_te,
87  *reinterpret_cast<PointerRNA *>(idv));
88  case TSE_RNA_PROPERTY:
89  return std::make_unique<TreeElementRNAProperty>(
90  legacy_te, *reinterpret_cast<PointerRNA *>(idv), legacy_te.index);
91  case TSE_RNA_ARRAY_ELEM:
92  return std::make_unique<TreeElementRNAArrayElement>(
93  legacy_te, *reinterpret_cast<PointerRNA *>(idv), legacy_te.index);
94  case TSE_SEQUENCE:
95  return std::make_unique<TreeElementSequence>(legacy_te, *reinterpret_cast<Sequence *>(idv));
96  case TSE_SEQ_STRIP:
97  return std::make_unique<TreeElementSequenceStrip>(legacy_te,
98  *reinterpret_cast<Strip *>(idv));
99  case TSE_SEQUENCE_DUP:
100  return std::make_unique<TreeElementSequenceStripDuplicate>(
101  legacy_te, *reinterpret_cast<Sequence *>(idv));
102  default:
103  break;
104  }
105 
106  return nullptr;
107 }
108 
110 {
111  return "";
112 }
113 
114 std::optional<BIFIconID> AbstractTreeElement::getIcon() const
115 {
116  return {};
117 }
118 
120 {
121  if (!TREESTORE(legacy_te)->used) {
122  TREESTORE(legacy_te)->flag &= ~TSE_CLOSED;
123  }
124 }
125 
126 void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
127 {
128  /* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
129  * expanding. Could be done nicer, we could request a small "expander" helper object from the
130  * element type, that the IDs have a more advanced implementation for. */
131  if (!tree_element.expandPoll(space_outliner)) {
132  return;
133  }
134  tree_element.expand(space_outliner);
135 }
136 
137 } // namespace blender::ed::outliner
These structs are the foundation for all linked lists in the library system.
@ TSE_LIBRARY_OVERRIDE_OPERATION
@ TSE_GP_LAYER
@ TSE_SEQUENCE_DUP
@ TSE_RNA_ARRAY_ELEM
@ TSE_SEQUENCE
@ TSE_ANIM_DATA
@ TSE_LIBRARY_OVERRIDE
@ TSE_RNA_PROPERTY
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_NLA_TRACK
@ TSE_SCENE_COLLECTION_BASE
@ TSE_SCENE_OBJECTS_BASE
@ TSE_R_LAYER_BASE
@ TSE_SEQ_STRIP
@ TSE_GENERIC_LABEL
@ TSE_NLA
@ TSE_SOME_ID
@ TSE_DRIVER_BASE
@ TSE_NLA_ACTION
@ TSE_RNA_STRUCT
@ TSE_CLOSED
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
virtual std::optional< BIFIconID > getIcon() const
static std::unique_ptr< AbstractTreeElement > createFromType(int type, TreeElement &legacy_te, void *idv)
Definition: tree_element.cc:33
virtual bool expandPoll(const SpaceOutliner &) const
Definition: tree_element.hh:43
static void uncollapse_by_default(TreeElement *legacy_te)
virtual void expand(SpaceOutliner &) const
Definition: tree_element.hh:97
virtual StringRefNull getWarning() const
static std::unique_ptr< TreeElementID > createFromID(TreeElement &legacy_te, ID &id)
void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
#define TREESTORE(a)
Definition: DNA_ID.h:368