From 485c98cc2c2bcb4b36e1e33b4d2fffa0b520f6e5 Mon Sep 17 00:00:00 2001 From: Almaz-Shinbay Date: Mon, 14 Aug 2023 12:36:06 +0200 Subject: [PATCH] Outliner: Port pose base elements to new tree-element code design No user visible changes expected. Part of #96713, continuation of work started in 249e4df110 and 2e221de4ce. Refer to these for a motivation and design overview. Adds a new class for pose base elements. Pull Request: https://projects.blender.org/blender/blender/pulls/110806 --- .../editors/space_outliner/CMakeLists.txt | 2 + .../editors/space_outliner/outliner_tree.cc | 4 + .../space_outliner/tree/tree_element.cc | 3 + .../tree/tree_element_id_object.cc | 50 +---------- .../space_outliner/tree/tree_element_pose.cc | 82 +++++++++++++++++++ .../space_outliner/tree/tree_element_pose.hh | 25 ++++++ 6 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 source/blender/editors/space_outliner/tree/tree_element_pose.cc create mode 100644 source/blender/editors/space_outliner/tree/tree_element_pose.hh diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index 7b408479f77..4ec91175d99 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -71,6 +71,7 @@ set(SRC tree/tree_element_nla.cc tree/tree_element_overrides.cc tree/tree_element_particle_system.cc + tree/tree_element_pose.cc tree/tree_element_pose_group.cc tree/tree_element_rna.cc tree/tree_element_scene_objects.cc @@ -106,6 +107,7 @@ set(SRC tree/tree_element_nla.hh tree/tree_element_overrides.hh tree/tree_element_particle_system.hh + tree/tree_element_pose.hh tree/tree_element_pose_group.hh tree/tree_element_rna.hh tree/tree_element_scene_objects.hh diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index ec11790a528..21266c1ff3b 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -331,6 +331,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, else if (type == TSE_LINKED_PSYS) { /* pass */ } + else if (type == TSE_POSE_BASE) { + /* pass */ + } else if (ELEM(type, TSE_POSEGRP, TSE_POSEGRP_BASE)) { /* pass */ } @@ -392,6 +395,7 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, TSE_DEFGROUP_BASE, TSE_GPENCIL_EFFECT, TSE_GPENCIL_EFFECT_BASE, + TSE_POSE_BASE, TSE_POSEGRP, TSE_POSEGRP_BASE, TSE_R_LAYER, diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc index 0d93bf2ccdd..1a72c9665c1 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.cc +++ b/source/blender/editors/space_outliner/tree/tree_element.cc @@ -30,6 +30,7 @@ #include "tree_element_nla.hh" #include "tree_element_overrides.hh" #include "tree_element_particle_system.hh" +#include "tree_element_pose.hh" #include "tree_element_pose_group.hh" #include "tree_element_rna.hh" #include "tree_element_scene_objects.hh" @@ -146,6 +147,8 @@ std::unique_ptr AbstractTreeElement::createFromType(const i return std::make_unique( legacy_te, *psys_data->object, *psys_data->psys); } + case TSE_POSE_BASE: + return std::make_unique(legacy_te, *static_cast(idv)); case TSE_POSEGRP_BASE: return std::make_unique(legacy_te, *static_cast(idv)); case TSE_POSEGRP: { diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_object.cc b/source/blender/editors/space_outliner/tree/tree_element_id_object.cc index 632182e3355..85e3b34ce84 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id_object.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_id_object.cc @@ -62,56 +62,8 @@ void TreeElementIDObject::expand_pose(SpaceOutliner &space_outliner) const if (!object_.pose) { return; } - bArmature *arm = static_cast(object_.data); - TreeElement *tenla = outliner_add_element( + outliner_add_element( &space_outliner, &legacy_te_.subtree, &object_, &legacy_te_, TSE_POSE_BASE, 0); - tenla->name = IFACE_("Pose"); - - /* channels undefined in editmode, but we want the 'tenla' pose icon itself */ - if ((arm->edbo == nullptr) && (object_.mode & OB_MODE_POSE)) { - int const_index = 1000; /* ensure unique id for bone constraints */ - int a; - LISTBASE_FOREACH_INDEX (bPoseChannel *, pchan, &object_.pose->chanbase, a) { - TreeElement *ten = outliner_add_element( - &space_outliner, &tenla->subtree, &object_, tenla, TSE_POSE_CHANNEL, a); - ten->name = pchan->name; - ten->directdata = pchan; - pchan->temp = (void *)ten; - - if (!BLI_listbase_is_empty(&pchan->constraints)) { - /* Object *target; */ - TreeElement *tenla1 = outliner_add_element( - &space_outliner, &ten->subtree, &object_, ten, TSE_CONSTRAINT_BASE, 0); - tenla1->name = IFACE_("Constraints"); - /* char *str; */ - - LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { - TreeElement *ten1 = outliner_add_element( - &space_outliner, &tenla1->subtree, &object_, tenla1, TSE_CONSTRAINT, const_index); - ten1->name = con->name; - ten1->directdata = con; - /* possible add all other types links? */ - } - const_index++; - } - } - /* make hierarchy */ - TreeElement *ten = static_cast(tenla->subtree.first); - while (ten) { - TreeElement *nten = ten->next, *par; - TreeStoreElem *tselem = TREESTORE(ten); - if (tselem->type == TSE_POSE_CHANNEL) { - bPoseChannel *pchan = (bPoseChannel *)ten->directdata; - if (pchan->parent) { - BLI_remlink(&tenla->subtree, ten); - par = (TreeElement *)pchan->parent->temp; - BLI_addtail(&par->subtree, ten); - ten->parent = par; - } - } - ten = nten; - } - } /* Pose Groups */ if (!BLI_listbase_is_empty(&object_.pose->agroups)) { diff --git a/source/blender/editors/space_outliner/tree/tree_element_pose.cc b/source/blender/editors/space_outliner/tree/tree_element_pose.cc new file mode 100644 index 00000000000..f1e52482fd9 --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_pose.cc @@ -0,0 +1,82 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#include "DNA_armature_types.h" +#include "DNA_constraint_types.h" +#include "DNA_object_types.h" +#include "DNA_outliner_types.h" + +#include "BLI_listbase.h" + +#include "BLT_translation.h" + +#include "../outliner_intern.hh" + +#include "tree_element_pose.hh" + +namespace blender::ed::outliner { + +TreeElementPoseBase::TreeElementPoseBase(TreeElement &legacy_te, Object &object) + : AbstractTreeElement(legacy_te), object_(object) +{ + BLI_assert(legacy_te.store_elem->type == TSE_POSE_BASE); + legacy_te.name = IFACE_("Pose"); +} + +void TreeElementPoseBase::expand(SpaceOutliner &space_outliner) const +{ + bArmature *arm = static_cast(object_.data); + + /* channels undefined in editmode, but we want the 'tenla' pose icon itself */ + if ((arm->edbo == nullptr) && (object_.mode & OB_MODE_POSE)) { + int const_index = 1000; /* ensure unique id for bone constraints */ + int a; + LISTBASE_FOREACH_INDEX (bPoseChannel *, pchan, &object_.pose->chanbase, a) { + TreeElement *ten = outliner_add_element( + &space_outliner, &legacy_te_.subtree, &object_, &legacy_te_, TSE_POSE_CHANNEL, a); + ten->name = pchan->name; + ten->directdata = pchan; + pchan->temp = (void *)ten; + + if (!BLI_listbase_is_empty(&pchan->constraints)) { + /* Object *target; */ + TreeElement *tenla1 = outliner_add_element( + &space_outliner, &ten->subtree, &object_, ten, TSE_CONSTRAINT_BASE, 0); + tenla1->name = IFACE_("Constraints"); + /* char *str; */ + + LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) { + TreeElement *ten1 = outliner_add_element( + &space_outliner, &tenla1->subtree, &object_, tenla1, TSE_CONSTRAINT, const_index); + ten1->name = con->name; + ten1->directdata = con; + /* possible add all other types links? */ + } + const_index++; + } + } + /* make hierarchy */ + TreeElement *ten = static_cast(legacy_te_.subtree.first); + while (ten) { + TreeElement *nten = ten->next, *par; + TreeStoreElem *tselem = TREESTORE(ten); + if (tselem->type == TSE_POSE_CHANNEL) { + bPoseChannel *pchan = (bPoseChannel *)ten->directdata; + if (pchan->parent) { + BLI_remlink(&legacy_te_.subtree, ten); + par = (TreeElement *)pchan->parent->temp; + BLI_addtail(&par->subtree, ten); + ten->parent = par; + } + } + ten = nten; + } + } +} + +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_pose.hh b/source/blender/editors/space_outliner/tree/tree_element_pose.hh new file mode 100644 index 00000000000..79b1e544aa6 --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_pose.hh @@ -0,0 +1,25 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#pragma once + +#include "tree_element.hh" + +struct Object; + +namespace blender::ed::outliner { + +class TreeElementPoseBase final : public AbstractTreeElement { + Object &object_; + + public: + TreeElementPoseBase(TreeElement &legacy_te, Object &object); + void expand(SpaceOutliner &) const override; +}; + +} // namespace blender::ed::outliner