[Bf-blender-cvs] [1cc0a59be66] master: Cleanup: Outliner video sequencer display mode

Nathan Craddock noreply at git.blender.org
Sat Dec 5 02:00:38 CET 2020


Commit: 1cc0a59be66a1d42ec316e0c29c2e3e184b26f7d
Author: Nathan Craddock
Date:   Wed Nov 25 14:55:09 2020 -0700
Branches: master
https://developer.blender.org/rB1cc0a59be66a1d42ec316e0c29c2e3e184b26f7d

Cleanup: Outliner video sequencer display mode

No functional changes. Code is ported to C++. Variable names and logic
are also improved.

Differential Revision: https://developer.blender.org/D9741

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

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_display.cc
M	source/blender/editors/space_outliner/tree/tree_display.hh
A	source/blender/editors/space_outliner/tree/tree_display_sequencer.cc

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

diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt
index 996570fae25..41e54ee8b86 100644
--- a/source/blender/editors/space_outliner/CMakeLists.txt
+++ b/source/blender/editors/space_outliner/CMakeLists.txt
@@ -48,6 +48,7 @@ set(SRC
   tree/tree_display.cc
   tree/tree_display_libraries.cc
   tree/tree_display_view_layer.cc
+  tree/tree_display_sequencer.cc
 
   outliner_intern.h
   tree/tree_display.h
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 94d55b13073..d3976821f8f 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -80,8 +80,6 @@
 
 #include "RNA_access.h"
 
-#include "SEQ_sequencer.h"
-
 #include "UI_interface.h"
 
 #include "outliner_intern.h"
@@ -1314,73 +1312,6 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
 }
 
 /* ======================================================= */
-/* Sequencer mode tree building */
-
-/* Helped function to put duplicate sequence in the same tree. */
-static int need_add_seq_dup(Sequence *seq)
-{
-  Sequence *p;
-
-  if ((!seq->strip) || (!seq->strip->stripdata)) {
-    return 1;
-  }
-
-  /*
-   * First check backward, if we found a duplicate
-   * sequence before this, don't need it, just return.
-   */
-  p = seq->prev;
-  while (p) {
-    if ((!p->strip) || (!p->strip->stripdata)) {
-      p = p->prev;
-      continue;
-    }
-
-    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
-      return 2;
-    }
-    p = p->prev;
-  }
-
-  p = seq->next;
-  while (p) {
-    if ((!p->strip) || (!p->strip->stripdata)) {
-      p = p->next;
-      continue;
-    }
-
-    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
-      return 0;
-    }
-    p = p->next;
-  }
-  return 1;
-}
-
-static void outliner_add_seq_dup(SpaceOutliner *space_outliner,
-                                 Sequence *seq,
-                                 TreeElement *te,
-                                 short index)
-{
-  /* TreeElement *ch; */ /* UNUSED */
-  Sequence *p;
-
-  p = seq;
-  while (p) {
-    if ((!p->strip) || (!p->strip->stripdata) || (p->strip->stripdata->name[0] == '\0')) {
-      p = p->next;
-      continue;
-    }
-
-    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
-      /* ch = */ /* UNUSED */ outliner_add_element(
-          space_outliner, &te->subtree, (void *)p, te, TSE_SEQUENCE, index);
-    }
-    p = p->next;
-  }
-}
-
-/* ----------------------------------------------- */
 
 static void outliner_add_orphaned_datablocks(Main *mainvar, SpaceOutliner *space_outliner)
 {
@@ -2246,32 +2177,8 @@ void outliner_build_tree(Main *mainvar,
     }
   }
   else if (space_outliner->outlinevis == SO_SEQUENCE) {
-    Sequence *seq;
-    Editing *ed = BKE_sequencer_editing_get(scene, false);
-    int op;
-
-    if (ed == NULL) {
-      return;
-    }
-
-    seq = ed->seqbasep->first;
-    if (!seq) {
-      return;
-    }
-
-    while (seq) {
-      op = need_add_seq_dup(seq);
-      if (op == 1) {
-        /* ten = */ outliner_add_element(
-            space_outliner, &space_outliner->tree, (void *)seq, NULL, TSE_SEQUENCE, 0);
-      }
-      else if (op == 0) {
-        ten = outliner_add_element(
-            space_outliner, &space_outliner->tree, (void *)seq, NULL, TSE_SEQUENCE_DUP, 0);
-        outliner_add_seq_dup(space_outliner, seq, ten, 0);
-      }
-      seq = seq->next;
-    }
+    /* Ported to new tree-display, should be built there already. */
+    BLI_assert(false);
   }
   else if (space_outliner->outlinevis == SO_DATA_API) {
     PointerRNA mainptr;
diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc
index 12599733275..1419295c81c 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display.cc
@@ -37,6 +37,8 @@ TreeDisplay *outliner_tree_display_create(eSpaceOutliner_Mode mode, SpaceOutline
       tree_display = new TreeDisplayLibraries(*space_outliner);
       break;
     case SO_SEQUENCE:
+      tree_display = new TreeDisplaySequencer(*space_outliner);
+      break;
     case SO_DATA_API:
     case SO_ID_ORPHANS:
       break;
diff --git a/source/blender/editors/space_outliner/tree/tree_display.hh b/source/blender/editors/space_outliner/tree/tree_display.hh
index a3d9a626d1d..0901451e5d3 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.hh
+++ b/source/blender/editors/space_outliner/tree/tree_display.hh
@@ -110,4 +110,28 @@ class TreeDisplayLibraries final : public AbstractTreeDisplay {
   short id_filter_get() const;
 };
 
+/* -------------------------------------------------------------------- */
+/* 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;
+  SequenceAddOp need_add_seq_dup(Sequence *seq) const;
+  void add_seq_dup(Sequence *seq, TreeElement *te, short index) const;
+};
+
 }  // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display_sequencer.cc b/source/blender/editors/space_outliner/tree/tree_display_sequencer.cc
new file mode 100644
index 00000000000..486f735be9f
--- /dev/null
+++ b/source/blender/editors/space_outliner/tree/tree_display_sequencer.cc
@@ -0,0 +1,122 @@
+/*
+ * 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 <string.h>
+
+#include "BLI_listbase.h"
+#include "BLI_listbase_wrapper.hh"
+#include "BLI_utildefines.h"
+
+#include "SEQ_sequencer.h"
+
+#include "../outliner_intern.h"
+#include "tree_display.hh"
+
+namespace blender::ed::outliner {
+
+/* Convenience/readability. */
+template<typename T> using List = ListBaseWrapper<T>;
+
+TreeDisplaySequencer::TreeDisplaySequencer(SpaceOutliner &space_outliner)
+    : AbstractTreeDisplay(space_outliner)
+{
+}
+
+ListBase TreeDisplaySequencer::buildTree(const TreeSourceData &source_data)
+{
+  ListBase tree = {nullptr};
+
+  Editing *ed = BKE_sequencer_editing_get(source_data.scene, false);
+  if (ed == nullptr) {
+    return tree;
+  }
+
+  for (Sequence *seq : List<Sequence>(ed->seqbasep)) {
+    SequenceAddOp op = need_add_seq_dup(seq);
+    if (op == SEQUENCE_DUPLICATE_NONE) {
+      outliner_add_element(&space_outliner_, &tree, seq, NULL, TSE_SEQUENCE, 0);
+    }
+    else if (op == SEQUENCE_DUPLICATE_ADD) {
+      TreeElement *te = outliner_add_element(
+          &space_outliner_, &tree, seq, NULL, TSE_SEQUENCE_DUP, 0);
+      add_seq_dup(seq, te, 0);
+    }
+  }
+
+  return tree;
+}
+
+/* Helped function to put duplicate sequence in the same tree. */
+SequenceAddOp TreeDisplaySequencer::need_add_seq_dup(Sequence *seq) const
+{
+  if ((!seq->strip) || (!seq->strip->stripdata)) {
+    return SEQUENCE_DUPLICATE_NONE;
+  }
+
+  /*
+   * First check backward, if we found a duplicate
+   * sequence before this, don't need it, just return.
+   */
+  Sequence *p = seq->prev;
+  while (p) {
+    if ((!p->strip) || (!p->strip->stripdata)) {
+      p = p->prev;
+      continue;
+    }
+
+    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
+      return SEQUENCE_DUPLICATE_NOOP;
+    }
+    p = p->prev;
+  }
+
+  p = seq->next;
+  while (p) {
+    if ((!p->strip) || (!p->strip->stripdata)) {
+      p = p->next;
+      continue;
+    }
+
+    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
+      return SEQUENCE_DUPLICATE_ADD;
+    }
+    p = p->next;
+  }
+
+  return SEQUENCE_DUPLICATE_NONE;
+}
+
+void TreeDisplaySequencer::add_seq_dup(Sequence *seq, TreeElement *te, short index) const
+{
+  Sequence *p = seq;
+  while (p) {
+    if ((!p->strip) || (!p->strip->stripdata) || (p->strip->stripdata->name[0] == '\0')) {
+      p = p->next;
+      continue;
+    }
+
+    if (STREQ(p->strip->stripdata->name, seq->strip->stripdata->name)) {
+      outliner_add_element(&space_outliner_, &te->subtree, (void *)p, te, TSE_SEQUENCE, index);
+    }
+    p = p->next;
+  }
+}
+
+}  // namespace blender::ed::outliner



More information about the Bf-blender-cvs mailing list