Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2022-03-24 18:57:16 +0300
committerBastien Montagne <bastien@blender.org>2022-03-29 18:59:43 +0300
commit354db59fb12a5ee595ae650ac3a736e3cc6df39d (patch)
treef0e70f85d9a4e116a156335a61b3674c643ef649 /source/blender/blenkernel
parent6cc9ba94b78c203e905c6974c9ff68409c5c22da (diff)
LibOverride: Rename 'delete hierarchy' to 'clear hierarchy', add 'clear single' operations.
'Delete' was a confusing name, even though it would delete the overrides it would replace them by linked data. Adding the 'single' version of that operation made it even more confusing, since often it has to keep the override ID for sakes of hierarchy, and just reset it and turn it back into a non-editable system override. Ref: {T95707}.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_lib_override.h22
-rw-r--r--source/blender/blenkernel/intern/lib_override.c56
2 files changed, 67 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index daa94031489..2447208b49d 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -70,6 +70,14 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id);
bool BKE_lib_override_library_is_system_defined(struct Main *bmain, struct ID *id);
/**
+ * Check if given ID is a leaf in its liboverride hierarchy (i.e. if it does not use any other
+ * override ID).
+ *
+ * NOTE: Embedded IDs of override IDs are not considered as leaves.
+ */
+bool BKE_lib_override_library_is_hierarchy_leaf(struct Main *bmain, struct ID *id);
+
+/**
* Create an overridden local copy of linked reference.
*
* \note This function is very basic, low-level. It does not consider any hierarchical dependency,
@@ -374,12 +382,22 @@ bool BKE_lib_override_library_main_operations_create(struct Main *bmain, bool fo
/**
* Reset all overrides in given \a id_root, while preserving ID relations.
+ *
+ * \param do_reset_system_override If \a true, reset the given ID as a system override one (i.e.
+ * non-editable).
*/
-void BKE_lib_override_library_id_reset(struct Main *bmain, struct ID *id_root);
+void BKE_lib_override_library_id_reset(struct Main *bmain,
+ struct ID *id_root,
+ bool do_reset_system_override);
/**
* Reset all overrides in given \a id_root and its dependencies, while preserving ID relations.
+ *
+ * \param do_reset_system_override If \a true, reset the given ID and all of its descendants in the
+ * override hierarchy as system override ones (i.e. non-editable).
*/
-void BKE_lib_override_library_id_hierarchy_reset(struct Main *bmain, struct ID *id_root);
+void BKE_lib_override_library_id_hierarchy_reset(struct Main *bmain,
+ struct ID *id_root,
+ bool do_reset_system_override);
/**
* Set or clear given tag in all operations in that override property data.
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index edb23f51308..eb6d9fe358e 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -291,6 +291,32 @@ bool BKE_lib_override_library_is_system_defined(Main *bmain, ID *id)
return false;
}
+static int foreachid_is_hierarchy_leaf_fn(LibraryIDLinkCallbackData *cb_data)
+{
+ ID *id_owner = cb_data->id_owner;
+ ID *id = *cb_data->id_pointer;
+ bool *is_leaf = cb_data->user_data;
+
+ if (id != NULL && ID_IS_OVERRIDE_LIBRARY_REAL(id) &&
+ id->override_library->hierarchy_root == id_owner->override_library->hierarchy_root) {
+ *is_leaf = false;
+ return IDWALK_RET_STOP_ITER;
+ }
+ return IDWALK_RET_NOP;
+}
+
+bool BKE_lib_override_library_is_hierarchy_leaf(Main *bmain, ID *id)
+{
+ if (ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
+ bool is_leaf = true;
+ BKE_library_foreach_ID_link(
+ bmain, id, foreachid_is_hierarchy_leaf_fn, &is_leaf, IDWALK_READONLY);
+ return is_leaf;
+ }
+
+ return false;
+}
+
ID *BKE_lib_override_library_create_from_id(Main *bmain,
ID *reference_id,
const bool do_tagged_remap)
@@ -3058,10 +3084,16 @@ bool BKE_lib_override_library_main_operations_create(Main *bmain, const bool for
return create_pool_data.changed;
}
-static bool lib_override_library_id_reset_do(Main *bmain, ID *id_root)
+static bool lib_override_library_id_reset_do(Main *bmain,
+ ID *id_root,
+ const bool do_reset_system_override)
{
bool was_op_deleted = false;
+ if (do_reset_system_override) {
+ id_root->override_library->flag |= IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED;
+ }
+
LISTBASE_FOREACH_MUTABLE (
IDOverrideLibraryProperty *, op, &id_root->override_library->properties) {
bool do_op_delete = true;
@@ -3117,13 +3149,15 @@ static bool lib_override_library_id_reset_do(Main *bmain, ID *id_root)
return was_op_deleted;
}
-void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root)
+void BKE_lib_override_library_id_reset(Main *bmain,
+ ID *id_root,
+ const bool do_reset_system_override)
{
if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root)) {
return;
}
- if (lib_override_library_id_reset_do(bmain, id_root)) {
+ if (lib_override_library_id_reset_do(bmain, id_root, do_reset_system_override)) {
if (id_root->override_library->runtime != NULL &&
(id_root->override_library->runtime->tag & IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RELOAD) !=
0) {
@@ -3133,7 +3167,9 @@ void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root)
}
}
-static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain, ID *id_root)
+static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain,
+ ID *id_root,
+ const bool do_reset_system_override)
{
if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root)) {
return;
@@ -3142,7 +3178,7 @@ static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain, ID *i
void **entry_vp = BLI_ghash_lookup_p(bmain->relations->relations_from_pointers, id_root);
if (entry_vp == NULL) {
/* This ID is not used by nor using any other ID. */
- lib_override_library_id_reset_do(bmain, id_root);
+ lib_override_library_id_reset_do(bmain, id_root, do_reset_system_override);
return;
}
@@ -3152,7 +3188,7 @@ static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain, ID *i
return;
}
- lib_override_library_id_reset_do(bmain, id_root);
+ lib_override_library_id_reset_do(bmain, id_root, do_reset_system_override);
/* This way we won't process again that ID, should we encounter it again through another
* relationship hierarchy. */
@@ -3169,17 +3205,19 @@ static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain, ID *i
if (*to_id_entry->id_pointer.to != NULL) {
ID *to_id = *to_id_entry->id_pointer.to;
if (to_id->override_library != NULL) {
- lib_override_library_id_hierarchy_recursive_reset(bmain, to_id);
+ lib_override_library_id_hierarchy_recursive_reset(bmain, to_id, do_reset_system_override);
}
}
}
}
-void BKE_lib_override_library_id_hierarchy_reset(Main *bmain, ID *id_root)
+void BKE_lib_override_library_id_hierarchy_reset(Main *bmain,
+ ID *id_root,
+ const bool do_reset_system_override)
{
BKE_main_relations_create(bmain, 0);
- lib_override_library_id_hierarchy_recursive_reset(bmain, id_root);
+ lib_override_library_id_hierarchy_recursive_reset(bmain, id_root, do_reset_system_override);
BKE_main_relations_free(bmain);