[Bf-blender-cvs] [5adcf6c85e4] master: LibOverride: Add initial System Override flag.

Bastien Montagne noreply at git.blender.org
Tue Mar 29 18:05:43 CEST 2022


Commit: 5adcf6c85e4c28fcfda0048a9ec7cceae105046d
Author: Bastien Montagne
Date:   Tue Feb 22 17:20:18 2022 +0100
Branches: master
https://developer.blender.org/rB5adcf6c85e4c28fcfda0048a9ec7cceae105046d

LibOverride: Add initial System Override flag.

This merely adds the flag, exposes it in RMA, and uses it in some of the
most common 'is editable' checks (RNA, `BASE_EDITABLE` macro...).

Next step: do_version and defining systemoverrides at creation.

Ref: {T95707}.

===================================================================

M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_access.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 98301ca7a70..daa94031489 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -64,6 +64,11 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, bool do_
  */
 bool BKE_lib_override_library_is_user_edited(struct ID *id);
 
+/**
+ * Check if given ID is a system override.
+ */
+bool BKE_lib_override_library_is_system_defined(struct Main *bmain, struct ID *id);
+
 /**
  * Create an overridden local copy of linked reference.
  *
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index cd5855af043..c0d49105dad 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -276,6 +276,18 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id)
   return false;
 }
 
+bool BKE_lib_override_library_is_system_defined(Main *bmain, ID *id)
+{
+
+  if (ID_IS_OVERRIDE_LIBRARY(id)) {
+    ID *override_owner_id;
+    lib_override_get(bmain, id, &override_owner_id);
+    return (override_owner_id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) !=
+           0;
+  }
+  return false;
+}
+
 ID *BKE_lib_override_library_create_from_id(Main *bmain,
                                             ID *reference_id,
                                             const bool do_tagged_remap)
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index c3132eeab3d..3ebf085443a 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -319,6 +319,11 @@ enum {
    * because it was created as an single override, outside of any hierarchy consideration).
    */
   IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY = 1 << 0,
+  /**
+   * The override ID is required for the system to work (because of ID dependencies), but is not
+   * seen as editable by the user.
+   */
+  IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED = 1 << 1,
 };
 
 /* watch it: Sequence has identical beginning. */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index d0c23f5d452..28c2d8427a8 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -2017,7 +2017,10 @@ extern const char *RE_engine_id_CYCLES;
    ((v3d == NULL) || (((1 << (base)->object->type) & (v3d)->object_type_exclude_select) == 0)) && \
    (((base)->flag & BASE_SELECTABLE) != 0))
 #define BASE_SELECTED(v3d, base) (BASE_VISIBLE(v3d, base) && (((base)->flag & BASE_SELECTED) != 0))
-#define BASE_EDITABLE(v3d, base) (BASE_VISIBLE(v3d, base) && !ID_IS_LINKED((base)->object))
+#define BASE_EDITABLE(v3d, base) \
+  (BASE_VISIBLE(v3d, base) && !ID_IS_LINKED((base)->object) && \
+   (!ID_IS_OVERRIDE_LIBRARY_REAL((base)->object) || \
+    ((base)->object->id.override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) == 0))
 #define BASE_SELECTED_EDITABLE(v3d, base) \
   (BASE_EDITABLE(v3d, base) && (((base)->flag & BASE_SELECTED) != 0))
 
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 82d90a5c54b..7fa6dad7730 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -1833,6 +1833,15 @@ static void rna_def_ID_override_library(BlenderRNA *brna)
   RNA_def_property_update(prop, NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY);
 
+  prop = RNA_def_boolean(srna,
+                         "is_system_override",
+                         false,
+                         "Is System Override",
+                         "Whether this library override exists only for the override hierarchy, "
+                         "or if it is actually editable by the user");
+  RNA_def_property_update(prop, NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED);
+
   prop = RNA_def_collection(srna,
                             "properties",
                             "IDOverrideLibraryProperty",
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 67fa29adb47..5690d864a75 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -32,8 +32,10 @@
 #include "BKE_collection.h"
 #include "BKE_context.h"
 #include "BKE_fcurve.h"
+#include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_idtype.h"
+#include "BKE_lib_override.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_report.h"
@@ -1930,17 +1932,29 @@ static bool rna_property_editable_do(PointerRNA *ptr,
 
   /* Handle linked or liboverride ID cases. */
   const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0;
-  if (ID_IS_LINKED(id) && !is_linked_prop_exception) {
+  if (ID_IS_LINKED(id)) {
+    if (is_linked_prop_exception) {
+      return true;
+    }
     if (r_info != NULL && (*r_info)[0] == '\0') {
       *r_info = N_("Can't edit this property from a linked data-block");
     }
     return false;
   }
-  if (ID_IS_OVERRIDE_LIBRARY(id) && !RNA_property_overridable_get(ptr, prop_orig)) {
-    if (r_info != NULL && (*r_info)[0] == '\0') {
-      *r_info = N_("Can't edit this property from an override data-block");
+  if (ID_IS_OVERRIDE_LIBRARY(id)) {
+    const bool is_liboverride_system = BKE_lib_override_library_is_system_defined(G_MAIN, id);
+    if (!RNA_property_overridable_get(ptr, prop_orig)) {
+      if (r_info != NULL && (*r_info)[0] == '\0') {
+        *r_info = N_("Can't edit this property from an override data-block");
+      }
+      return false;
+    }
+    if (is_liboverride_system && !is_linked_prop_exception) {
+      if (r_info != NULL && (*r_info)[0] == '\0') {
+        *r_info = N_("Can't edit this property from a system override data-block");
+      }
+      return false;
     }
-    return false;
   }
 
   /* At this point, property is owned by a local ID and therefore fully editable. */



More information about the Bf-blender-cvs mailing list