Outliner: Barebones to port IDs to new Outliner tree-element code design
Continuation of work in2e221de4ce
and249e4df110
. This prepares things so we can start porting the individual ID types to the new code design. I already added some code for library IDs, because they need some special handling during construction, which I didn't want to break. The `AbstractTreeElement::isExpandValid()` check can be removed once types were ported and can be assumed to have a proper `expand()` implemenation. Also makes `TreeElementGPencilLayer` `final` which I forgot ine0442a955b
.
This commit is contained in:
parent
ae005393dc
commit
3a907e7425
Notes:
blender-bot
2023-06-07 10:31:13 +02:00
Referenced by commit4292bb060d
, Outliner: Port scene elements and some related types to new tree-element code design Referenced by commit4addcf1efc
, Cleanup: Remove redundant special handling after previous commit Referenced by issue #97790, Regression: Crash when setting Outliner to "Blender File" with old files (IPO IDs)
|
@ -58,6 +58,7 @@ set(SRC
|
|||
tree/tree_element_anim_data.cc
|
||||
tree/tree_element_driver_base.cc
|
||||
tree/tree_element_gpencil_layer.cc
|
||||
tree/tree_element_id.cc
|
||||
tree/tree_element_nla.cc
|
||||
|
||||
outliner_intern.h
|
||||
|
@ -68,6 +69,7 @@ set(SRC
|
|||
tree/tree_element_anim_data.hh
|
||||
tree/tree_element_driver_base.hh
|
||||
tree/tree_element_gpencil_layer.hh
|
||||
tree/tree_element_id.hh
|
||||
tree/tree_element_nla.hh
|
||||
)
|
||||
|
||||
|
|
|
@ -992,6 +992,11 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
|
|||
else if (type == TSE_ID_BASE) {
|
||||
/* pass */
|
||||
}
|
||||
else if (type == TSE_SOME_ID) {
|
||||
if (!te->type) {
|
||||
BLI_assert(!"Expected this ID type to be ported to new Outliner tree-element design");
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Other cases must be caught above. */
|
||||
BLI_assert(TSE_IS_REAL_ID(tselem));
|
||||
|
@ -1006,7 +1011,7 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
|
|||
te->idcode = GS(id->name);
|
||||
}
|
||||
|
||||
if (te->type) {
|
||||
if (te->type && outliner_tree_element_type_is_expand_valid(te->type)) {
|
||||
outliner_tree_element_type_expand(te->type, space_outliner);
|
||||
}
|
||||
else if (type == TSE_SOME_ID) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "tree_element_anim_data.hh"
|
||||
#include "tree_element_driver_base.hh"
|
||||
#include "tree_element_gpencil_layer.hh"
|
||||
#include "tree_element_id.hh"
|
||||
#include "tree_element_nla.hh"
|
||||
|
||||
#include "tree_element.h"
|
||||
|
@ -37,6 +38,8 @@ static AbstractTreeElement *tree_element_create(int type, TreeElement &legacy_te
|
|||
ID &id = *static_cast<ID *>(idv);
|
||||
|
||||
switch (type) {
|
||||
case TSE_SOME_ID:
|
||||
return TreeElementID::createFromID(legacy_te, id);
|
||||
case TSE_ANIM_DATA:
|
||||
return new TreeElementAnimData(legacy_te, id);
|
||||
case TSE_DRIVER_BASE:
|
||||
|
@ -82,6 +85,12 @@ void outliner_tree_element_type_expand(TreeElementType *type, SpaceOutliner *spa
|
|||
outliner::tree_element_expand(reinterpret_cast<outliner::AbstractTreeElement &>(*type),
|
||||
*space_outliner);
|
||||
}
|
||||
bool outliner_tree_element_type_is_expand_valid(TreeElementType *type)
|
||||
{
|
||||
outliner::AbstractTreeElement &element = reinterpret_cast<outliner::AbstractTreeElement &>(
|
||||
*type);
|
||||
return element.isExpandValid();
|
||||
}
|
||||
|
||||
void outliner_tree_element_type_free(TreeElementType **type)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@ TreeElementType *outliner_tree_element_type_create(int type, TreeElement *legacy
|
|||
void outliner_tree_element_type_free(TreeElementType **type);
|
||||
|
||||
void outliner_tree_element_type_expand(TreeElementType *type, SpaceOutliner *space_outliner);
|
||||
bool outliner_tree_element_type_is_expand_valid(TreeElementType *type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -48,6 +48,15 @@ class AbstractTreeElement {
|
|||
virtual void expand(SpaceOutliner &) const
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Just while transitioning to the new tree-element design: Some types are only partially ported,
|
||||
* and the expanding isn't done yet.
|
||||
*/
|
||||
virtual bool isExpandValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blender::ed::outliner
|
||||
|
|
|
@ -26,7 +26,7 @@ struct bGPDlayer;
|
|||
|
||||
namespace blender::ed::outliner {
|
||||
|
||||
class TreeElementGPencilLayer : public AbstractTreeElement {
|
||||
class TreeElementGPencilLayer final : public AbstractTreeElement {
|
||||
public:
|
||||
TreeElementGPencilLayer(TreeElement &legacy_te, bGPDlayer &gplayer);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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 "DNA_ID.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "../outliner_intern.h"
|
||||
|
||||
#include "tree_element_id.hh"
|
||||
|
||||
namespace blender::ed::outliner {
|
||||
|
||||
TreeElementID::TreeElementID(TreeElement &legacy_te, const ID &id) : AbstractTreeElement(legacy_te)
|
||||
{
|
||||
BLI_assert(legacy_te_.store_elem->type == TSE_SOME_ID);
|
||||
BLI_assert(TSE_IS_REAL_ID(legacy_te_.store_elem));
|
||||
|
||||
/* Default, some specific types override this. */
|
||||
legacy_te_.name = id.name + 2;
|
||||
legacy_te_.idcode = GS(id.name);
|
||||
}
|
||||
|
||||
TreeElementID *TreeElementID::createFromID(TreeElement &legacy_te, const ID &id)
|
||||
{
|
||||
switch (ID_Type type = GS(id.name); type) {
|
||||
case ID_LI:
|
||||
return new TreeElementIDLibrary(legacy_te, id);
|
||||
case ID_SCE:
|
||||
case ID_OB:
|
||||
case ID_ME:
|
||||
case ID_CU:
|
||||
case ID_MB:
|
||||
case ID_MA:
|
||||
case ID_TE:
|
||||
case ID_LT:
|
||||
case ID_LA:
|
||||
case ID_CA:
|
||||
case ID_KE:
|
||||
case ID_SCR:
|
||||
case ID_WO:
|
||||
case ID_SPK:
|
||||
case ID_GR:
|
||||
case ID_NT:
|
||||
case ID_BR:
|
||||
case ID_PA:
|
||||
case ID_MC:
|
||||
case ID_MSK:
|
||||
case ID_LS:
|
||||
case ID_LP:
|
||||
case ID_GD:
|
||||
case ID_WS:
|
||||
case ID_HA:
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_WM:
|
||||
case ID_IM:
|
||||
case ID_VF:
|
||||
case ID_TXT:
|
||||
case ID_SO:
|
||||
case ID_AR:
|
||||
case ID_AC:
|
||||
case ID_PAL:
|
||||
case ID_PC:
|
||||
case ID_CF:
|
||||
return new TreeElementID(legacy_te, id);
|
||||
/* Deprecated */
|
||||
case ID_IP:
|
||||
BLI_assert(!"Outliner trying to build tree-element for deprecated ID type");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TreeElementIDLibrary::TreeElementIDLibrary(TreeElement &legacy_te, const ID &id)
|
||||
: TreeElementID(legacy_te, id)
|
||||
{
|
||||
legacy_te.name = ((Library &)id).filepath;
|
||||
}
|
||||
|
||||
} // namespace blender::ed::outliner
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "tree_element.hh"
|
||||
|
||||
namespace blender::ed::outliner {
|
||||
|
||||
class TreeElementID : public AbstractTreeElement {
|
||||
public:
|
||||
TreeElementID(TreeElement &legacy_te, const ID &id);
|
||||
|
||||
static TreeElementID *createFromID(TreeElement &legacy_te, const ID &id);
|
||||
|
||||
/**
|
||||
* Expanding not implemented for all types yet. Once it is, this can be set to true or
|
||||
* `AbstractTreeElement::expandValid()` can be removed alltogether.
|
||||
*/
|
||||
bool isExpandValid() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class TreeElementIDLibrary final : public TreeElementID {
|
||||
public:
|
||||
TreeElementIDLibrary(TreeElement &legacy_te, const ID &id);
|
||||
};
|
||||
|
||||
} // namespace blender::ed::outliner
|
Loading…
Reference in New Issue