[Bf-blender-cvs] [3a907e74250] master: Outliner: Barebones to port IDs to new Outliner tree-element code design

Julian Eisel noreply at git.blender.org
Fri Mar 5 18:09:56 CET 2021


Commit: 3a907e742507dde9b26eb5f531c18ad00b0e2ab6
Author: Julian Eisel
Date:   Fri Mar 5 18:01:31 2021 +0100
Branches: master
https://developer.blender.org/rB3a907e742507dde9b26eb5f531c18ad00b0e2ab6

Outliner: Barebones to port IDs to new Outliner tree-element code design

Continuation of work in 2e221de4ceee and 249e4df110e0 .
This prepares things so we can start porting the individual ID types to
the new code design. I already added some code for library IDs, because
they need some special handling during construction, which I didn't want
to break.

The `AbstractTreeElement::isExpandValid()` check can be removed once
types were ported and can be assumed to have a proper `expand()`
implemenation.

Also makes `TreeElementGPencilLayer` `final` which I forgot in
e0442a955bad.

===================================================================

M	source/blender/editors/space_outliner/CMakeLists.txt
M	source/blender/editors/space_outliner/outliner_tree.c
M	source/blender/editors/space_outliner/tree/tree_element.cc
M	source/blender/editors/space_outliner/tree/tree_element.h
M	source/blender/editors/space_outliner/tree/tree_element.hh
M	source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
A	source/blender/editors/space_outliner/tree/tree_element_id.cc
A	source/blender/editors/space_outliner/tree/tree_element_id.hh

===================================================================

diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt
index 040410c0bdd..7b9bc44f986 100644
--- a/source/blender/editors/space_outliner/CMakeLists.txt
+++ b/source/blender/editors/space_outliner/CMakeLists.txt
@@ -58,6 +58,7 @@ set(SRC
   tree/tree_element_anim_data.cc
   tree/tree_element_driver_base.cc
   tree/tree_element_gpencil_layer.cc
+  tree/tree_element_id.cc
   tree/tree_element_nla.cc
 
   outliner_intern.h
@@ -68,6 +69,7 @@ set(SRC
   tree/tree_element_anim_data.hh
   tree/tree_element_driver_base.hh
   tree/tree_element_gpencil_layer.hh
+  tree/tree_element_id.hh
   tree/tree_element_nla.hh
 )
 
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 3696ef8dbce..f109efbaa2b 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -992,6 +992,11 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
   else if (type == TSE_ID_BASE) {
     /* pass */
   }
+  else if (type == TSE_SOME_ID) {
+    if (!te->type) {
+      BLI_assert(!"Expected this ID type to be ported to new Outliner tree-element design");
+    }
+  }
   else {
     /* Other cases must be caught above. */
     BLI_assert(TSE_IS_REAL_ID(tselem));
@@ -1006,7 +1011,7 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
     te->idcode = GS(id->name);
   }
 
-  if (te->type) {
+  if (te->type && outliner_tree_element_type_is_expand_valid(te->type)) {
     outliner_tree_element_type_expand(te->type, space_outliner);
   }
   else if (type == TSE_SOME_ID) {
diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc
index a692aae37c3..79c2831475f 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element.cc
@@ -23,6 +23,7 @@
 #include "tree_element_anim_data.hh"
 #include "tree_element_driver_base.hh"
 #include "tree_element_gpencil_layer.hh"
+#include "tree_element_id.hh"
 #include "tree_element_nla.hh"
 
 #include "tree_element.h"
@@ -37,6 +38,8 @@ static AbstractTreeElement *tree_element_create(int type, TreeElement &legacy_te
   ID &id = *static_cast<ID *>(idv);
 
   switch (type) {
+    case TSE_SOME_ID:
+      return TreeElementID::createFromID(legacy_te, id);
     case TSE_ANIM_DATA:
       return new TreeElementAnimData(legacy_te, id);
     case TSE_DRIVER_BASE:
@@ -82,6 +85,12 @@ void outliner_tree_element_type_expand(TreeElementType *type, SpaceOutliner *spa
   outliner::tree_element_expand(reinterpret_cast<outliner::AbstractTreeElement &>(*type),
                                 *space_outliner);
 }
+bool outliner_tree_element_type_is_expand_valid(TreeElementType *type)
+{
+  outliner::AbstractTreeElement &element = reinterpret_cast<outliner::AbstractTreeElement &>(
+      *type);
+  return element.isExpandValid();
+}
 
 void outliner_tree_element_type_free(TreeElementType **type)
 {
diff --git a/source/blender/editors/space_outliner/tree/tree_element.h b/source/blender/editors/space_outliner/tree/tree_element.h
index d88c37180b3..c3dec1bf68a 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.h
+++ b/source/blender/editors/space_outliner/tree/tree_element.h
@@ -39,6 +39,7 @@ TreeElementType *outliner_tree_element_type_create(int type, TreeElement *legacy
 void outliner_tree_element_type_free(TreeElementType **type);
 
 void outliner_tree_element_type_expand(TreeElementType *type, SpaceOutliner *space_outliner);
+bool outliner_tree_element_type_is_expand_valid(TreeElementType *type);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh
index 8a1ebb51eae..3e61dd25898 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element.hh
@@ -48,6 +48,15 @@ class AbstractTreeElement {
   virtual void expand(SpaceOutliner &) const
   {
   }
+
+  /**
+   * Just while transitioning to the new tree-element design: Some types are only partially ported,
+   * and the expanding isn't done yet.
+   */
+  virtual bool isExpandValid() const
+  {
+    return true;
+  }
 };
 
 }  // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh b/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
index dd18dd42344..da57ef63f1f 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
@@ -26,7 +26,7 @@ struct bGPDlayer;
 
 namespace blender::ed::outliner {
 
-class TreeElementGPencilLayer : public AbstractTreeElement {
+class TreeElementGPencilLayer final : public AbstractTreeElement {
  public:
   TreeElementGPencilLayer(TreeElement &legacy_te, bGPDlayer &gplayer);
 };
diff --git a/source/blender/editors/space_outliner/tree/tree_element_id.cc b/source/blender/editors/space_outliner/tree/tree_element_id.cc
new file mode 100644
index 00000000000..26787475635
--- /dev/null
+++ b/source/blender/editors/space_outliner/tree/tree_element_id.cc
@@ -0,0 +1,100 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup spoutliner
+ */
+
+#include "DNA_ID.h"
+
+#include "BLI_utildefines.h"
+
+#include "../outliner_intern.h"
+
+#include "tree_element_id.hh"
+
+namespace blender::ed::outliner {
+
+TreeElementID::TreeElementID(TreeElement &legacy_te, const ID &id) : AbstractTreeElement(legacy_te)
+{
+  BLI_assert(legacy_te_.store_elem->type == TSE_SOME_ID);
+  BLI_assert(TSE_IS_REAL_ID(legacy_te_.store_elem));
+
+  /* Default, some specific types override this. */
+  legacy_te_.name = id.name + 2;
+  legacy_te_.idcode = GS(id.name);
+}
+
+TreeElementID *TreeElementID::createFromID(TreeElement &legacy_te, const ID &id)
+{
+  switch (ID_Type type = GS(id.name); type) {
+    case ID_LI:
+      return new TreeElementIDLibrary(legacy_te, id);
+    case ID_SCE:
+    case ID_OB:
+    case ID_ME:
+    case ID_CU:
+    case ID_MB:
+    case ID_MA:
+    case ID_TE:
+    case ID_LT:
+    case ID_LA:
+    case ID_CA:
+    case ID_KE:
+    case ID_SCR:
+    case ID_WO:
+    case ID_SPK:
+    case ID_GR:
+    case ID_NT:
+    case ID_BR:
+    case ID_PA:
+    case ID_MC:
+    case ID_MSK:
+    case ID_LS:
+    case ID_LP:
+    case ID_GD:
+    case ID_WS:
+    case ID_HA:
+    case ID_PT:
+    case ID_VO:
+    case ID_SIM:
+    case ID_WM:
+    case ID_IM:
+    case ID_VF:
+    case ID_TXT:
+    case ID_SO:
+    case ID_AR:
+    case ID_AC:
+    case ID_PAL:
+    case ID_PC:
+    case ID_CF:
+      return new TreeElementID(legacy_te, id);
+      /* Deprecated */
+    case ID_IP:
+      BLI_assert(!"Outliner trying to build tree-element for deprecated ID type");
+      return nullptr;
+  }
+
+  return nullptr;
+}
+
+TreeElementIDLibrary::TreeElementIDLibrary(TreeElement &legacy_te, const ID &id)
+    : TreeElementID(legacy_te, id)
+{
+  legacy_te.name = ((Library &)id).filepath;
+}
+
+}  // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh b/source/blender/editors/space_outliner/tree/tree_element_id.hh
similarity index 61%
copy from source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
copy to source/blender/editors/space_outliner/tree/tree_element_id.hh
index dd18dd42344..d1e672ed387 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_gpencil_layer.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_id.hh
@@ -22,13 +22,27 @@
 
 #include "tree_element.hh"
 
-struct bGPDlayer;
-
 namespace blender::ed::outliner {
 
-class TreeElementGPencilLayer : public AbstractTreeElement {
+class TreeElementID : public AbstractTreeElement {
+ public:
+  TreeElementID(TreeElement &legacy_te, const ID &id);
+
+  static TreeElementID *createFromID(TreeElement &legacy_te, const ID &id);
+
+  /**
+   * Expanding not implemented for all types yet. Once it is, this can be set to true or
+   * `AbstractTreeElement::expandValid()` can be removed alltogether.
+   */
+  bool isExpandValid() const override
+  {
+    return false;
+  }
+};
+
+class TreeElementIDLibrary final : public TreeElementID {
  public:
-  TreeElementGPencilLayer(TreeElement &legacy_te, bGPDlayer &gplayer);
+  TreeElementIDLibrary(TreeElement &legacy_te, const ID &id);
 };
 
 }  // namespace blender::ed::outliner



More information about the Bf-blender-cvs mailing list