From ee7ba1955c1acb5a2901c6b97b34a2b6f32c012d Mon Sep 17 00:00:00 2001 From: Almaz-Shinbay Date: Thu, 27 Jul 2023 16:29:19 +0200 Subject: [PATCH] Outliner: Port particle system 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 particle system elements. Pull Request: https://projects.blender.org/blender/blender/pulls/110245 --- .../editors/space_outliner/CMakeLists.txt | 2 ++ .../editors/space_outliner/outliner_intern.hh | 5 ++++ .../editors/space_outliner/outliner_tree.cc | 7 +++++ .../space_outliner/tree/tree_element.cc | 7 +++++ .../tree/tree_element_id_object.cc | 9 +++---- .../tree/tree_element_particle_system.cc | 26 +++++++++++++++++++ .../tree/tree_element_particle_system.hh | 24 +++++++++++++++++ 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 source/blender/editors/space_outliner/tree/tree_element_particle_system.cc create mode 100644 source/blender/editors/space_outliner/tree/tree_element_particle_system.hh diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index b91951d434c..ec400455b88 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -68,6 +68,7 @@ set(SRC tree/tree_element_label.cc tree/tree_element_nla.cc tree/tree_element_overrides.cc + tree/tree_element_particle_system.cc tree/tree_element_rna.cc tree/tree_element_scene_objects.cc tree/tree_element_seq.cc @@ -99,6 +100,7 @@ set(SRC tree/tree_element_label.hh tree/tree_element_nla.hh tree/tree_element_overrides.hh + tree/tree_element_particle_system.hh tree/tree_element_rna.hh tree/tree_element_scene_objects.hh tree/tree_element_seq.hh diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh index ab9629603bb..1101f187dd0 100644 --- a/source/blender/editors/space_outliner/outliner_intern.hh +++ b/source/blender/editors/space_outliner/outliner_intern.hh @@ -296,6 +296,11 @@ struct EditBoneElementCreateData { EditBone *ebone; }; +struct ParticleSystemElementCreateData { + Object *object; + ParticleSystem *psys; +}; + TreeTraversalAction outliner_collect_selected_collections(TreeElement *te, void *customdata); TreeTraversalAction outliner_collect_selected_objects(TreeElement *te, void *customdata); diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index f52df941f53..8e9356dffdd 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -245,6 +245,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, else if (type == TSE_EBONE) { id = static_cast(idv)->armature_id; } + else if (type == TSE_LINKED_PSYS) { + id = &static_cast(idv)->object->id; + } /* exceptions */ if (ELEM(type, TSE_ID_BASE, TSE_GENERIC_LABEL)) { @@ -303,6 +306,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, else if (ELEM(type, TSE_BONE, TSE_EBONE)) { /* pass */ } + else if (type == TSE_LINKED_PSYS) { + /* pass */ + } else if (type == TSE_SOME_ID) { if (!te->abstract_element) { BLI_assert_msg(0, "Expected this ID type to be ported to new Outliner tree-element design"); @@ -341,6 +347,7 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, TSE_BONE, TSE_DRIVER_BASE, TSE_EBONE, + TSE_LINKED_PSYS, TSE_NLA, TSE_NLA_ACTION, TSE_NLA_TRACK, diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc index c7cb80f520d..550ad121a93 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.cc +++ b/source/blender/editors/space_outliner/tree/tree_element.cc @@ -27,6 +27,7 @@ #include "tree_element_label.hh" #include "tree_element_nla.hh" #include "tree_element_overrides.hh" +#include "tree_element_particle_system.hh" #include "tree_element_rna.hh" #include "tree_element_scene_objects.hh" #include "tree_element_seq.hh" @@ -114,6 +115,12 @@ std::unique_ptr AbstractTreeElement::createFromType(const i return std::make_unique( legacy_te, *ebone_data->armature_id, *ebone_data->ebone); } + case TSE_LINKED_PSYS: { + ParticleSystemElementCreateData *psys_data = static_cast( + idv); + return std::make_unique( + legacy_te, *psys_data->object, *psys_data->psys); + } default: break; } 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 d28031e7599..cb44a360d84 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 @@ -202,12 +202,11 @@ void TreeElementIDObject::expand_modifiers(SpaceOutliner &space_outliner) const } else if (md->type == eModifierType_ParticleSystem) { ParticleSystem *psys = ((ParticleSystemModifierData *)md)->psys; - TreeElement *ten_psys; - ten_psys = outliner_add_element( - &space_outliner, &ten->subtree, &object_, &legacy_te_, TSE_LINKED_PSYS, 0); - ten_psys->directdata = psys; - ten_psys->name = psys->part->id.name + 2; + ParticleSystemElementCreateData psys_data = {&object_, psys}; + + outliner_add_element( + &space_outliner, &ten->subtree, &psys_data, &legacy_te_, TSE_LINKED_PSYS, 0); } } } diff --git a/source/blender/editors/space_outliner/tree/tree_element_particle_system.cc b/source/blender/editors/space_outliner/tree/tree_element_particle_system.cc new file mode 100644 index 00000000000..ef62df90e8f --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_particle_system.cc @@ -0,0 +1,26 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#include "DNA_particle_types.h" + +#include "../outliner_intern.hh" + +#include "tree_element_particle_system.hh" + +namespace blender::ed::outliner { + +TreeElementParticleSystem::TreeElementParticleSystem(TreeElement &legacy_te, + Object & /* object */, + ParticleSystem &psys) + : AbstractTreeElement(legacy_te), /* object_(object), */ psys_(psys) +{ + legacy_te.directdata = &psys_; + legacy_te.name = psys_.part->id.name + 2; +} + +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_particle_system.hh b/source/blender/editors/space_outliner/tree/tree_element_particle_system.hh new file mode 100644 index 00000000000..37c847c7237 --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_particle_system.hh @@ -0,0 +1,24 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#pragma once + +#include "tree_element.hh" + +namespace blender::ed::outliner { + +class TreeElementParticleSystem final : public AbstractTreeElement { + /* Not needed right now, avoid unused member variable warning. */ + // Object &object_; + ParticleSystem &psys_; + + public: + TreeElementParticleSystem(TreeElement &legacy_te, Object &object, ParticleSystem &psys); +}; + +} // namespace blender::ed::outliner