Blender  V2.93
tree_element.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "DNA_anim_types.h"
22 #include "DNA_listBase.h"
23 
26 #include "tree_element_driver.hh"
28 #include "tree_element_id.hh"
29 #include "tree_element_nla.hh"
33 
34 #include "tree_element.h"
35 #include "tree_element.hh"
36 
37 namespace blender::ed::outliner {
38 
39 static AbstractTreeElement *tree_element_create(int type, TreeElement &legacy_te, void *idv)
40 {
41  ID &id = *static_cast<ID *>(idv);
42 
43  /*
44  * The following calls make an implicit assumption about what data was passed to the `idv`
45  * argument of #outliner_add_element(). The old code does this already, here we just centralize
46  * it as much as possible for now. Would be nice to entirely get rid of that, no more `void *`.
47  *
48  * Once #outliner_add_element() is sufficiently simplified, it should be replaced by a C++ call.
49  * It could take the derived type as template parameter (e.g. #TreeElementAnimData) and use C++
50  * perfect forwarding to pass any data to the type's constructor.
51  * If general Outliner code wants to access the data, they can query that through the derived
52  * element type then. There's no need for `void *` anymore then.
53  */
54 
55  switch (type) {
56  case TSE_SOME_ID:
57  return TreeElementID::createFromID(legacy_te, id);
58  case TSE_ANIM_DATA:
59  return new TreeElementAnimData(legacy_te, *reinterpret_cast<IdAdtTemplate &>(id).adt);
60  case TSE_DRIVER_BASE:
61  return new TreeElementDriverBase(legacy_te, *static_cast<AnimData *>(idv));
62  case TSE_NLA:
63  return new TreeElementNLA(legacy_te, *static_cast<AnimData *>(idv));
64  case TSE_NLA_TRACK:
65  return new TreeElementNLATrack(legacy_te, *static_cast<NlaTrack *>(idv));
66  case TSE_NLA_ACTION:
67  return new TreeElementNLAAction(legacy_te, *static_cast<bAction *>(idv));
68  case TSE_GP_LAYER:
69  return new TreeElementGPencilLayer(legacy_te, *static_cast<bGPDlayer *>(idv));
70  case TSE_R_LAYER_BASE:
71  return new TreeElementViewLayerBase(legacy_te, *static_cast<Scene *>(idv));
73  return new TreeElementCollectionBase(legacy_te, *static_cast<Scene *>(idv));
75  return new TreeElementSceneObjectsBase(legacy_te, *static_cast<Scene *>(idv));
77  return new TreeElementOverridesBase(legacy_te, id);
79  return new TreeElementOverridesProperty(legacy_te,
80  *static_cast<TreeElementOverridesData *>(idv));
81  default:
82  break;
83  }
84 
85  return nullptr;
86 }
87 
88 static void tree_element_free(AbstractTreeElement **tree_element)
89 {
90  delete *tree_element;
91  *tree_element = nullptr;
92 }
93 
94 static void tree_element_expand(AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
95 {
96  /* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
97  * expanding. Could be done nicer, we could request a small "expander" helper object from the
98  * element type, that the IDs have a more advanced implementation for. */
99  if (!tree_element.expandPoll(space_outliner)) {
100  return;
101  }
102  tree_element.expand(space_outliner);
103  tree_element.postExpand(space_outliner);
104 }
105 
111  SpaceOutliner &space_outliner)
112 {
113  tree_element.postExpand(space_outliner);
114 }
120  SpaceOutliner &space_outliner)
121 {
122  return tree_element.expandPoll(space_outliner);
123 }
124 
125 } // namespace blender::ed::outliner
126 
127 namespace outliner = blender::ed::outliner;
128 
130 {
132  return reinterpret_cast<TreeElementType *>(element);
133 }
134 
136 {
138  *space_outliner);
139 }
141 {
143  *type);
144  return element.isExpandValid();
145 }
147 {
149  reinterpret_cast<outliner::AbstractTreeElement &>(*type), *space_outliner);
150 }
152 {
154  *space_outliner);
155 }
156 
158 {
160 }
These structs are the foundation for all linked lists in the library system.
@ TSE_GP_LAYER
@ TSE_ANIM_DATA
@ TSE_LIBRARY_OVERRIDE
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_NLA_TRACK
@ TSE_SCENE_COLLECTION_BASE
@ TSE_SCENE_OBJECTS_BASE
@ TSE_R_LAYER_BASE
@ TSE_NLA
@ TSE_SOME_ID
@ TSE_DRIVER_BASE
@ TSE_NLA_ACTION
_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
ATTR_WARN_UNUSED_RESULT const void * element
virtual void postExpand(SpaceOutliner &) const
Definition: tree_element.hh:55
virtual bool expandPoll(const SpaceOutliner &) const
Definition: tree_element.hh:45
virtual void expand(SpaceOutliner &) const
Definition: tree_element.hh:52
static TreeElementID * createFromID(TreeElement &legacy_te, ID &id)
static void tree_element_free(AbstractTreeElement **tree_element)
Definition: tree_element.cc:88
static void tree_element_expand(AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
Definition: tree_element.cc:94
static bool tree_element_expand_poll(AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
static AbstractTreeElement * tree_element_create(int type, TreeElement &legacy_te, void *idv)
Definition: tree_element.cc:39
static void tree_element_post_expand_only(AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
Definition: DNA_ID.h:273
void outliner_tree_element_type_free(TreeElementType **type)
bool outliner_tree_element_type_expand_poll(TreeElementType *type, SpaceOutliner *space_outliner)
TreeElementType * outliner_tree_element_type_create(int type, TreeElement *legacy_te, void *idv)
bool outliner_tree_element_type_is_expand_valid(TreeElementType *type)
void outliner_tree_element_type_expand(TreeElementType *type, SpaceOutliner *space_outliner)
void outliner_tree_element_type_post_expand(TreeElementType *type, SpaceOutliner *space_outliner)
struct TreeElementType TreeElementType
Definition: tree_element.h:36