Outliner: Port armature elements to new tree-element code design #108964

Merged
Julian Eisel merged 5 commits from :temp-id-armature-refactor into main 2023-06-19 19:01:31 +02:00
5 changed files with 149 additions and 69 deletions

View File

@ -57,6 +57,7 @@ set(SRC
tree/tree_element_driver.cc
tree/tree_element_gpencil_layer.cc
tree/tree_element_id.cc
tree/tree_element_id_armature.cc
tree/tree_element_id_collection.cc
tree/tree_element_id_curve.cc
tree/tree_element_id_gpencil_legacy.cc
@ -84,6 +85,7 @@ set(SRC
tree/tree_element_driver.hh
tree/tree_element_gpencil_layer.hh
tree/tree_element_id.hh
tree/tree_element_id_armature.hh
tree/tree_element_id_collection.hh
tree/tree_element_id_curve.hh
tree/tree_element_id_gpencil_legacy.hh

View File

@ -218,25 +218,6 @@ bool outliner_requires_rebuild_on_select_or_active_change(const SpaceOutliner *s
return exclude_flags & (SO_FILTER_OB_STATE_SELECTED | SO_FILTER_OB_STATE_ACTIVE);
}
/* special handling of hierarchical non-lib data */
static void outliner_add_bone(SpaceOutliner *space_outliner,
ListBase *lb,
ID *id,
Bone *curBone,
TreeElement *parent,
int *a)
{
TreeElement *te = outliner_add_element(space_outliner, lb, id, parent, TSE_BONE, *a);
(*a)++;
te->name = curBone->name;
te->directdata = curBone;
LISTBASE_FOREACH (Bone *, child_bone, &curBone->childbase) {
outliner_add_bone(space_outliner, &te->subtree, id, child_bone, te, a);
}
}
#ifdef WITH_FREESTYLE
static void outliner_add_line_styles(SpaceOutliner *space_outliner,
ListBase *lb,
@ -558,6 +539,7 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
case ID_LS:
case ID_GD_LEGACY:
case ID_GR:
case ID_AR:
BLI_assert_msg(0, "ID type expected to be expanded through new tree-element design");
break;
case ID_OB: {
@ -626,55 +608,6 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
/* bAction *act = (bAction *)id; */
break;
}
case ID_AR: {
bArmature *arm = (bArmature *)id;
if (outliner_animdata_test(arm->adt)) {
outliner_add_element(space_outliner, &te->subtree, arm, te, TSE_ANIM_DATA, 0);
}
if (arm->edbo) {
int a = 0;
LISTBASE_FOREACH_INDEX (EditBone *, ebone, arm->edbo, a) {
TreeElement *ten = outliner_add_element(
space_outliner, &te->subtree, id, te, TSE_EBONE, a);
ten->directdata = ebone;
ten->name = ebone->name;
ebone->temp.p = ten;
}
/* make hierarchy */
TreeElement *ten = arm->edbo->first ?
static_cast<TreeElement *>(((EditBone *)arm->edbo->first)->temp.p) :
nullptr;
while (ten) {
TreeElement *nten = ten->next, *par;
EditBone *ebone = (EditBone *)ten->directdata;
if (ebone->parent) {
BLI_remlink(&te->subtree, ten);
par = static_cast<TreeElement *>(ebone->parent->temp.p);
BLI_addtail(&par->subtree, ten);
ten->parent = par;
}
ten = nten;
}
}
else {
/* do not extend Armature when we have posemode */
tselem = TREESTORE(te->parent);
if (TSE_IS_REAL_ID(tselem) && GS(tselem->id->name) == ID_OB &&
((Object *)tselem->id)->mode & OB_MODE_POSE)
{
/* pass */
}
else {
int a = 0;
LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) {
outliner_add_bone(space_outliner, &te->subtree, id, bone, te, &a);
}
}
}
break;
}
case ID_CV: {
Curves *curves = (Curves *)id;
if (outliner_animdata_test(curves->adt)) {

View File

@ -20,6 +20,7 @@
#include "../outliner_intern.hh"
#include "common.hh"
#include "tree_element_id_armature.hh"
#include "tree_element_id_collection.hh"
#include "tree_element_id_curve.hh"
#include "tree_element_id_gpencil_legacy.hh"
@ -60,6 +61,8 @@ std::unique_ptr<TreeElementID> TreeElementID::createFromID(TreeElement &legacy_t
return std::make_unique<TreeElementIDGPLegacy>(legacy_te, (bGPdata &)id);
case ID_GR:
return std::make_unique<TreeElementIDCollection>(legacy_te, (Collection &)id);
case ID_AR:
return std::make_unique<TreeElementIDArmature>(legacy_te, (bArmature &)id);
case ID_OB:
case ID_MA:
case ID_LT:
@ -85,7 +88,6 @@ std::unique_ptr<TreeElementID> TreeElementID::createFromID(TreeElement &legacy_t
case ID_VF:
case ID_TXT:
case ID_SO:
case ID_AR:
case ID_AC:
case ID_PAL:
case ID_PC:

View File

@ -0,0 +1,110 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#include "DNA_ID.h"
#include "DNA_armature_types.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_outliner_types.h"
#include "BLI_listbase.h"
#include "BKE_armature.h"
#include "../outliner_intern.hh"
#include "tree_element_id_armature.hh"
namespace blender::ed::outliner {
TreeElementIDArmature::TreeElementIDArmature(TreeElement &legacy_te, bArmature &arm)
: TreeElementID(legacy_te, arm.id), arm_(arm)

Just move it before the expandBones() function, close to where it's actually used :)

You should also be getting a compiler warning about a missing function declaration. You have to make the function static to avoid that.

Just move it before the `expandBones()` function, close to where it's actually used :) You should also be getting a compiler warning about a missing function declaration. You have to make the function `static` to avoid that.

Oh, now I see

Oh, now I see
{
}
void TreeElementIDArmature::expand(SpaceOutliner &space_outliner) const
{
expand_animation_data(space_outliner, arm_.adt);
if (arm_.edbo) {
expandEditBones(space_outliner);
}
else {
/* do not extend Armature when we have posemode */
TreeStoreElem *tselem = TREESTORE(legacy_te_.parent);
if (TSE_IS_REAL_ID(tselem) && GS(tselem->id->name) == ID_OB &&
((Object *)tselem->id)->mode & OB_MODE_POSE)
{
/* pass */
}
else {
expandBones(space_outliner);
}
}
}
bool TreeElementIDArmature::isExpandValid() const
{
return true;
}
void TreeElementIDArmature::expandEditBones(SpaceOutliner &space_outiner) const
{
int a = 0;
LISTBASE_FOREACH_INDEX (EditBone *, ebone, arm_.edbo, a) {
TreeElement *ten = outliner_add_element(
&space_outiner, &legacy_te_.subtree, &arm_.id, &legacy_te_, TSE_EBONE, a);
ten->directdata = ebone;
ten->name = ebone->name;
ebone->temp.p = ten;
}
/* make hierarchy */
TreeElement *ten = arm_.edbo->first ?
static_cast<TreeElement *>(((EditBone *)arm_.edbo->first)->temp.p) :
nullptr;
while (ten) {
TreeElement *nten = ten->next, *par;
EditBone *ebone = (EditBone *)ten->directdata;
if (ebone->parent) {
BLI_remlink(&legacy_te_.subtree, ten);
par = static_cast<TreeElement *>(ebone->parent->temp.p);
BLI_addtail(&par->subtree, ten);
ten->parent = par;
}
ten = nten;
}
}
/* special handling of hierarchical non-lib data */
static void outliner_add_bone(SpaceOutliner *space_outliner,
ListBase *lb,
ID *id,
Bone *curBone,
TreeElement *parent,
int *a)
{
TreeElement *te = outliner_add_element(space_outliner, lb, id, parent, TSE_BONE, *a);

Simply move this function up a bit before it is called, and remove the declaration in the header.

Simply move this function up a bit before it is called, and remove the declaration in the header.
(*a)++;
te->name = curBone->name;
te->directdata = curBone;
LISTBASE_FOREACH (Bone *, child_bone, &curBone->childbase) {
outliner_add_bone(space_outliner, &te->subtree, id, child_bone, te, a);
}
}
void TreeElementIDArmature::expandBones(SpaceOutliner &space_outliner) const
{
int a = 0;
LISTBASE_FOREACH (Bone *, bone, &arm_.bonebase) {
outliner_add_bone(&space_outliner, &legacy_te_.subtree, &arm_.id, bone, &legacy_te_, &a);
}
}
} // namespace blender::ed::outliner

View File

@ -0,0 +1,33 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#pragma once
#include "tree_element_id.hh"
struct Bone;
struct EditBone;
struct bArmature;
namespace blender::ed::outliner {
class TreeElementIDArmature final : public TreeElementID {
bArmature &arm_;
public:
TreeElementIDArmature(TreeElement &legacy_te, bArmature &arm);
void expand(SpaceOutliner &) const override;
bool isExpandValid() const override;
private:
void expandEditBones(SpaceOutliner &) const;
void expandBones(SpaceOutliner &) const;
};
} // namespace blender::ed::outliner