Outliner: Port remaining ID elements to new tree-element code design #109256

Merged
Julian Eisel merged 7 commits from :temp-default-element-expand into main 2023-06-26 16:11:37 +02:00
3 changed files with 12 additions and 133 deletions

View File

@ -11,21 +11,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_camera_types.h"
#include "DNA_collection_types.h"
#include "DNA_curves_types.h"
#include "DNA_key_types.h"
#include "DNA_light_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_material_types.h"
#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_simulation_types.h"
#include "DNA_speaker_types.h"
#include "DNA_volume_types.h"
#include "DNA_world_types.h"
#include "BLI_blenlib.h"
#include "BLI_fnmatch.h"
@ -229,118 +215,6 @@ static void outliner_add_line_styles(SpaceOutliner *space_outliner,
}
}
#endif
/* Can be inlined if necessary. */
static void outliner_add_id_contents(SpaceOutliner *space_outliner, TreeElement *te, ID *id)
{
/* expand specific data always */
switch (GS(id->name)) {
case ID_LI:
case ID_SCE:
case ID_ME:
case ID_CU_LEGACY:
case ID_MB:
case ID_TE:
case ID_LS:
case ID_GD_LEGACY:
case ID_GR:
case ID_AR:
case ID_OB:
BLI_assert_msg(0, "ID type expected to be expanded through new tree-element design");
break;
case ID_MA: {
Material *ma = (Material *)id;
if (outliner_animdata_test(ma->adt)) {
outliner_add_element(space_outliner, &te->subtree, ma, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_CA: {
Camera *ca = (Camera *)id;
if (outliner_animdata_test(ca->adt)) {
outliner_add_element(space_outliner, &te->subtree, ca, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_CF: {
CacheFile *cache_file = (CacheFile *)id;
if (outliner_animdata_test(cache_file->adt)) {
outliner_add_element(space_outliner, &te->subtree, cache_file, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_LA: {
Light *la = (Light *)id;
if (outliner_animdata_test(la->adt)) {
outliner_add_element(space_outliner, &te->subtree, la, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_SPK: {
Speaker *spk = (Speaker *)id;
if (outliner_animdata_test(spk->adt)) {
outliner_add_element(space_outliner, &te->subtree, spk, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_LP: {
LightProbe *prb = (LightProbe *)id;
if (outliner_animdata_test(prb->adt)) {
outliner_add_element(space_outliner, &te->subtree, prb, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_WO: {
World *wrld = (World *)id;
if (outliner_animdata_test(wrld->adt)) {
outliner_add_element(space_outliner, &te->subtree, wrld, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_KE: {
Key *key = (Key *)id;
if (outliner_animdata_test(key->adt)) {
outliner_add_element(space_outliner, &te->subtree, key, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_AC: {
/* XXX do we want to be exposing the F-Curves here? */
/* bAction *act = (bAction *)id; */
break;
}
case ID_CV: {
Curves *curves = (Curves *)id;
if (outliner_animdata_test(curves->adt)) {
outliner_add_element(space_outliner, &te->subtree, curves, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_PT: {
PointCloud *pointcloud = (PointCloud *)id;
if (outliner_animdata_test(pointcloud->adt)) {
outliner_add_element(space_outliner, &te->subtree, pointcloud, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_VO: {
Volume *volume = (Volume *)id;
if (outliner_animdata_test(volume->adt)) {
outliner_add_element(space_outliner, &te->subtree, volume, te, TSE_ANIM_DATA, 0);
}
break;
}
case ID_SIM: {
Simulation *simulation = (Simulation *)id;
if (outliner_animdata_test(simulation->adt)) {
outliner_add_element(space_outliner, &te->subtree, simulation, te, TSE_ANIM_DATA, 0);
}
break;
}
default:
break;
}
}
TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
ListBase *lb,
@ -453,12 +327,6 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
else if (te->abstract_element && te->abstract_element->isExpandValid()) {
tree_element_expand(*te->abstract_element, *space_outliner);
}
else if (type == TSE_SOME_ID) {
/* ID types not (fully) ported to new design yet. */
if (te->abstract_element->expandPoll(*space_outliner)) {
outliner_add_id_contents(space_outliner, te, id);
}
}
else if (ELEM(type,
TSE_ANIM_DATA,
TSE_DRIVER_BASE,

View File

@ -12,6 +12,7 @@
#include "BLI_listbase_wrapper.hh"
#include "BLI_utildefines.h"
#include "BKE_anim_data.h"
#include "BKE_lib_override.h"
#include "BLT_translation.h"
@ -124,6 +125,15 @@ bool TreeElementID::expandPoll(const SpaceOutliner &space_outliner) const
return (tsepar == nullptr || tsepar->type != TSE_ID_BASE || space_outliner.filter_id_type);
}
void TreeElementID::expand(SpaceOutliner &space_outliner) const
{
/* Not all IDs support animation data. Will be null then. */
Almaz-Shinbay marked this conversation as resolved Outdated

You can also just do a single call to BKE_animdata_from_id(). It will return null for IDs that don't support animation data.

You can also just do a single call to `BKE_animdata_from_id()`. It will return null for IDs that don't support animation data.

Nitpick: It's not immediately clear by just looking at this function that the animation data may be null. So I would make that explicit:

/* Not all IDs support animation data. Will be null then. */
const AnimData *anim_data = BKE_animdata_from_id(&id_);
if (anim_data) {
  expand_animation_data(space_outliner, anim_data);
}
Nitpick: It's not immediately clear by just looking at this function that the animation data may be null. So I would make that explicit: ```Cpp /* Not all IDs support animation data. Will be null then. */ const AnimData *anim_data = BKE_animdata_from_id(&id_); if (anim_data) { expand_animation_data(space_outliner, anim_data); } ```
const AnimData *anim_data = BKE_animdata_from_id(&id_);
if (anim_data) {
expand_animation_data(space_outliner, anim_data);
}
}
void TreeElementID::expand_animation_data(SpaceOutliner &space_outliner,
const AnimData *anim_data) const
{

View File

@ -34,8 +34,9 @@ class TreeElementID : public AbstractTreeElement {
*/
bool isExpandValid() const override
{
return false;
return true;
}
void expand(SpaceOutliner &) const override;
ID &get_ID()
{