Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tree_display.hh « tree « space_outliner « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 295eeb59eaaa619d0f226caf1c31019d494fa10d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup spoutliner
 *
 * \brief Establish and manage Outliner trees for different display modes.
 *
 * Each Outliner display mode (e.g View Layer, Scenes, Blender File) is implemented as a
 * tree-display class with the #AbstractTreeDisplay interface.
 *
 * Their main responsibility is building the Outliner tree for a display mode. For that, they
 * implement the #buildTree() function, which based on Blender data (#TreeSourceData), builds a
 * custom tree of whatever data it wants to visualize.
 * Further, they can implement display mode dependent queries and general operations using the
 * #AbstractTreeDisplay abstraction as common interface.
 *
 * Outliners keep the current tree-display object alive until the next full tree rebuild to keep
 * access to it.
 */

#pragma once

#include <memory>

struct ID;
struct LayerCollection;
struct Library;
struct ListBase;
struct Main;
struct Scene;
struct Sequence;
struct SpaceOutliner;
struct ViewLayer;

namespace blender::ed::outliner {

struct TreeElement;
class TreeElementID;

/**
 * \brief The data to build the tree from.
 */
struct TreeSourceData {
  Main *bmain;
  Scene *scene;
  ViewLayer *view_layer;

  TreeSourceData(Main &bmain, Scene &scene, ViewLayer &view_layer)
      : bmain(&bmain), scene(&scene), view_layer(&view_layer)
  {
  }
};

/* -------------------------------------------------------------------- */
/* Tree-Display Interface */

/**
 * \brief Base Class For Tree-Displays
 *
 * Abstract base class defining the interface for tree-display variants.
 */
class AbstractTreeDisplay {
 public:
  AbstractTreeDisplay(SpaceOutliner &space_outliner) : space_outliner_(space_outliner)
  {
  }
  virtual ~AbstractTreeDisplay() = default;

  static std::unique_ptr<AbstractTreeDisplay> createFromDisplayMode(
      int /*eSpaceOutliner_Mode*/ mode, SpaceOutliner &space_outliner);

  /**
   * Build a tree for this display mode with the Blender context data given in \a source_data and
   * the view settings in \a space_outliner.
   */
  virtual ListBase buildTree(const TreeSourceData &source_data) = 0;

  /**
   * Define if the display mode should be allowed to show a mode column on the left. This column
   * adds an icon to indicate which objects are in the current mode (edit mode, pose mode, etc.)
   * and allows adding other objects to the mode by clicking the icon.
   *
   * Returns false by default.
   */
  virtual bool supportsModeColumn() const;

  /**
   * Some trees may want to skip building children of collapsed parents. This should be done if the
   * tree type may become very complex, which could cause noticeable slowdowns.
   * Problem: This doesn't address performance issues while searching, since all elements are
   * constructed for that. Trees of this type have to be rebuilt for any change to the collapsed
   * state of any element.
   */
  virtual bool is_lazy_built() const;

 protected:
  /** All derived classes will need a handle to this, so storing it in the base for convenience. */
  SpaceOutliner &space_outliner_;
};

/* -------------------------------------------------------------------- */
/* View Layer Tree-Display */

/**
 * \brief Tree-Display for the View Layer display mode.
 */
class TreeDisplayViewLayer final : public AbstractTreeDisplay {
  ViewLayer *view_layer_ = nullptr;
  bool show_objects_ = true;

 public:
  TreeDisplayViewLayer(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

  bool supportsModeColumn() const override;

 private:
  void add_view_layer(Scene &, ListBase &, TreeElement *);
  void add_layer_collections_recursive(ListBase &, ListBase &, TreeElement &);
  void add_layer_collection_objects(ListBase &, LayerCollection &, TreeElement &);
  void add_layer_collection_objects_children(TreeElement &);
};

/* -------------------------------------------------------------------- */
/* Library Tree-Display */

/**
 * \brief Tree-Display for the Libraries display mode.
 */
class TreeDisplayLibraries final : public AbstractTreeDisplay {
 public:
  TreeDisplayLibraries(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

 private:
  TreeElement *add_library_contents(Main &, ListBase &, Library *);
  bool library_id_filter_poll(const Library *lib, ID *id) const;
  short id_filter_get() const;
};

/* -------------------------------------------------------------------- */
/* Library Overrides Tree-Display. */

/**
 * \brief Tree-Display for the Library Overrides display mode, Properties view mode.
 */
class TreeDisplayOverrideLibraryProperties final : public AbstractTreeDisplay {
 public:
  TreeDisplayOverrideLibraryProperties(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

 private:
  ListBase add_library_contents(Main &);
  short id_filter_get() const;
};

/**
 * \brief Tree-Display for the Library Overrides display mode, Hierarchies view mode.
 */
class TreeDisplayOverrideLibraryHierarchies final : public AbstractTreeDisplay {
 public:
  TreeDisplayOverrideLibraryHierarchies(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

  bool is_lazy_built() const override;

 private:
  ListBase build_hierarchy_for_lib_or_main(Main *bmain,
                                           TreeElement &parent_te,
                                           Library *lib = nullptr);
};

/* -------------------------------------------------------------------- */
/* Video Sequencer Tree-Display */

enum SequenceAddOp {
  SEQUENCE_DUPLICATE_NOOP = 0,
  SEQUENCE_DUPLICATE_ADD,
  SEQUENCE_DUPLICATE_NONE
};

/**
 * \brief Tree-Display for the Video Sequencer display mode
 */
class TreeDisplaySequencer final : public AbstractTreeDisplay {
 public:
  TreeDisplaySequencer(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

 private:
  TreeElement *add_sequencer_contents() const;
  /**
   * Helped function to put duplicate sequence in the same tree.
   */
  SequenceAddOp need_add_seq_dup(Sequence *seq) const;
  void add_seq_dup(Sequence *seq, TreeElement *te, short index) const;
};

/* -------------------------------------------------------------------- */
/* Orphaned Data Tree-Display */

/**
 * \brief Tree-Display for the Orphaned Data display mode
 */
class TreeDisplayIDOrphans final : public AbstractTreeDisplay {
 public:
  TreeDisplayIDOrphans(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

 private:
  bool datablock_has_orphans(ListBase &) const;
};

/* -------------------------------------------------------------------- */
/* Scenes Tree-Display */

/**
 * \brief Tree-Display for the Scenes display mode
 */
class TreeDisplayScenes final : public AbstractTreeDisplay {
 public:
  TreeDisplayScenes(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

  bool supportsModeColumn() const override;
};

/* -------------------------------------------------------------------- */
/* Data API Tree-Display */

/**
 * \brief Tree-Display for the Scenes display mode
 */
class TreeDisplayDataAPI final : public AbstractTreeDisplay {
 public:
  TreeDisplayDataAPI(SpaceOutliner &space_outliner);

  ListBase buildTree(const TreeSourceData &source_data) override;

  bool is_lazy_built() const override;
};

}  // namespace blender::ed::outliner