Outliner: Port constraint 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 new classes for constraint elements.

Pull Request: https://projects.blender.org/blender/blender/pulls/111108
This commit is contained in:
Almaz-Shinbay
2023-08-14 14:56:18 +02:00
committed by Julian Eisel
parent 4cefe0ec80
commit 02969de155
7 changed files with 99 additions and 5 deletions

View File

@@ -50,6 +50,7 @@ set(SRC
tree/tree_element_anim_data.cc
tree/tree_element_bone.cc
tree/tree_element_collection.cc
tree/tree_element_constraint.cc
tree/tree_element_defgroup.cc
tree/tree_element_driver.cc
tree/tree_element_edit_bone.cc
@@ -86,6 +87,7 @@ set(SRC
tree/tree_element_anim_data.hh
tree/tree_element_bone.hh
tree/tree_element_collection.hh
tree/tree_element_constraint.hh
tree/tree_element_defgroup.hh
tree/tree_element_driver.hh
tree/tree_element_edit_bone.hh

View File

@@ -31,6 +31,7 @@ struct ShaderFxData;
struct TreeStoreElem;
struct ViewLayer;
struct bActionGroup;
struct bConstraint;
struct bContext;
struct bContextDataResult;
struct bDeformGroup;
@@ -301,6 +302,11 @@ struct EditBoneElementCreateData {
EditBone *ebone;
};
struct ConstraintElementCreateData {
Object *object;
bConstraint *con;
};
struct DeformGroupElementCreateData {
Object *object;
bDeformGroup *defgroup;

View File

@@ -258,6 +258,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
else if (type == TSE_LINKED_PSYS) {
id = &static_cast<ParticleSystemElementCreateData *>(idv)->object->id;
}
else if (type == TSE_CONSTRAINT) {
id = &static_cast<ConstraintElementCreateData *>(idv)->object->id;
}
else if (type == TSE_POSEGRP) {
id = &static_cast<PoseGroupElementCreateData *>(idv)->object->id;
}
@@ -331,6 +334,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
else if (type == TSE_LINKED_PSYS) {
/* pass */
}
else if (ELEM(type, TSE_CONSTRAINT, TSE_CONSTRAINT_BASE)) {
/* pass */
}
else if (type == TSE_POSE_BASE) {
/* pass */
}
@@ -395,6 +401,8 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
TSE_DEFGROUP_BASE,
TSE_GPENCIL_EFFECT,
TSE_GPENCIL_EFFECT_BASE,
TSE_CONSTRAINT,
TSE_CONSTRAINT_BASE,
TSE_POSE_BASE,
TSE_POSEGRP,
TSE_POSEGRP_BASE,

View File

@@ -20,6 +20,7 @@
#include "tree_element_anim_data.hh"
#include "tree_element_bone.hh"
#include "tree_element_collection.hh"
#include "tree_element_constraint.hh"
#include "tree_element_defgroup.hh"
#include "tree_element_driver.hh"
#include "tree_element_edit_bone.hh"
@@ -147,6 +148,12 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
return std::make_unique<TreeElementParticleSystem>(
legacy_te, *psys_data->object, *psys_data->psys);
}
case TSE_CONSTRAINT_BASE:
return std::make_unique<TreeElementConstraintBase>(legacy_te, *static_cast<Object *>(idv));
case TSE_CONSTRAINT: {
ConstraintElementCreateData *con_data = static_cast<ConstraintElementCreateData *>(idv);
return std::make_unique<TreeElementConstraint>(legacy_te, *con_data->object, *con_data->con);
}
case TSE_POSE_BASE:
return std::make_unique<TreeElementPoseBase>(legacy_te, *static_cast<Object *>(idv));
case TSE_POSEGRP_BASE:

View File

@@ -0,0 +1,38 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#include "DNA_constraint_types.h"
#include "DNA_object_types.h"
#include "DNA_outliner_types.h"
#include "BLT_translation.h"
#include "../outliner_intern.hh"
#include "tree_element_constraint.hh"
namespace blender::ed::outliner {
TreeElementConstraintBase::TreeElementConstraintBase(TreeElement &legacy_te, Object & /* object */)
: AbstractTreeElement(legacy_te) /* , object_(object) */
{
BLI_assert(legacy_te.store_elem->type == TSE_CONSTRAINT_BASE);
legacy_te.name = IFACE_("Constraints");
}
TreeElementConstraint::TreeElementConstraint(TreeElement &legacy_te,
Object & /* object */,
bConstraint &con)
: AbstractTreeElement(legacy_te), /* object_(object), */ con_(con)
{
BLI_assert(legacy_te.store_elem->type == TSE_CONSTRAINT);
legacy_te.name = con_.name;
legacy_te.directdata = &con_;
}
} // namespace blender::ed::outliner

View File

@@ -0,0 +1,34 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#pragma once
#include "tree_element.hh"
struct bConstraint;
namespace blender::ed::outliner {
class TreeElementConstraintBase final : public AbstractTreeElement {
/* Not needed right now, avoid unused member variable warning. */
// Object &object_;
public:
TreeElementConstraintBase(TreeElement &legacy_te, Object &object);
};
class TreeElementConstraint final : public AbstractTreeElement {
/* Not needed right now, avoid unused member variable warning. */
// Object &object_;
bConstraint &con_;
public:
TreeElementConstraint(TreeElement &legacy_te, Object &object, bConstraint &con);
};
} // namespace blender::ed::outliner

View File

@@ -87,14 +87,13 @@ void TreeElementIDObject::expand_constraints(SpaceOutliner &space_outliner) cons
}
TreeElement *tenla = outliner_add_element(
&space_outliner, &legacy_te_.subtree, &object_, &legacy_te_, TSE_CONSTRAINT_BASE, 0);
tenla->name = IFACE_("Constraints");
int index;
LISTBASE_FOREACH_INDEX (bConstraint *, con, &object_.constraints, index) {
TreeElement *ten = outliner_add_element(
&space_outliner, &tenla->subtree, &object_, tenla, TSE_CONSTRAINT, index);
ten->name = con->name;
ten->directdata = con;
ConstraintElementCreateData con_data = {&object_, con};
outliner_add_element(
&space_outliner, &tenla->subtree, &con_data, tenla, TSE_CONSTRAINT, index);
/* possible add all other types links? */
}
}