[Bf-blender-cvs] [87f9405c9ae] master: Overrides: API to create an override template.

Jeroen Bakker noreply at git.blender.org
Mon Mar 29 09:54:50 CEST 2021


Commit: 87f9405c9aedb4b23c3400780db42ddda0cc4c2b
Author: Jeroen Bakker
Date:   Mon Mar 29 09:53:12 2021 +0200
Branches: master
https://developer.blender.org/rB87f9405c9aedb4b23c3400780db42ddda0cc4c2b

Overrides: API to create an override template.

This is functionality that isn't accessible via the user interface. The
API allows the creation and modification of an override template that
holds rules that needs to be checked when overriding the asset.

The API is setup that it cannot be changed after creation. Later on when
the system is more mature we will allow changing overrides operations.

NOTE: This is an experimental feature and should not be used in productions.

Reviewed By: mont29, sebbas

Differential Revision: https://developer.blender.org/D10792

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_userdef.c
M	tests/python/bl_blendfile_library_overrides.py

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 96695ff1be5..f44cf23fb58 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -2244,6 +2244,7 @@ class USERPREF_PT_experimental_new_features(ExperimentalPanel, Panel):
                 ({"property": "use_switch_object_operator"}, "T80402"),
                 ({"property": "use_sculpt_tools_tilt"}, "T82877"),
                 ({"property": "use_asset_browser"}, ("project/profile/124/", "Milestone 1")),
+                ({"property": "use_override_templates"}, ("T73318", "Milestone 4")),
             ),
         )
 
diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index f69580d38be..0750a3332a8 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -74,6 +74,7 @@ bool BKE_lib_override_library_create(struct Main *bmain,
                                      struct ViewLayer *view_layer,
                                      struct ID *id_root,
                                      struct ID *id_reference);
+bool BKE_lib_override_library_template_create(struct ID *id);
 bool BKE_lib_override_library_proxy_convert(struct Main *bmain,
                                             struct Scene *scene,
                                             struct ViewLayer *view_layer,
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index c755d153100..dbb46aa5780 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -822,6 +822,22 @@ bool BKE_lib_override_library_create(
   return success;
 }
 
+/**
+ * Create a library override template.
+ */
+bool BKE_lib_override_library_template_create(struct ID *id)
+{
+  if (ID_IS_LINKED(id)) {
+    return false;
+  }
+  if (ID_IS_OVERRIDE_LIBRARY(id)) {
+    return false;
+  }
+
+  BKE_lib_override_library_init(id, NULL);
+  return true;
+}
+
 /**
  * Convert a given proxy object into a library override.
  *
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 4595b12e9d4..334669d3433 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -646,7 +646,8 @@ typedef struct UserDef_Experimental {
   char use_switch_object_operator;
   char use_sculpt_tools_tilt;
   char use_asset_browser;
-  char _pad[6];
+  char use_override_templates;
+  char _pad[5];
   /** `makesdna` does not allow empty structs. */
 } UserDef_Experimental;
 
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 6e2005b7314..8d9e7852b4c 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -85,6 +85,47 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static const EnumPropertyItem rna_enum_override_library_property_operation_items[] = {
+    {IDOVERRIDE_LIBRARY_OP_NOOP,
+     "NOOP",
+     0,
+     "No-Op",
+     "Does nothing, prevents adding actual overrides (NOT USED)"},
+    {IDOVERRIDE_LIBRARY_OP_REPLACE,
+     "REPLACE",
+     0,
+     "Replace",
+     "Replace value of reference by overriding one"},
+    {IDOVERRIDE_LIBRARY_OP_ADD,
+     "DIFF_ADD",
+     0,
+     "Differential",
+     "Stores and apply difference between reference and local value (NOT USED)"},
+    {IDOVERRIDE_LIBRARY_OP_SUBTRACT,
+     "DIFF_SUB",
+     0,
+     "Differential",
+     "Stores and apply difference between reference and local value (NOT USED)"},
+    {IDOVERRIDE_LIBRARY_OP_MULTIPLY,
+     "FACT_MULTIPLY",
+     0,
+     "Factor",
+     "Stores and apply multiplication factor between reference and local value (NOT USED)"},
+    {IDOVERRIDE_LIBRARY_OP_INSERT_AFTER,
+     "INSERT_AFTER",
+     0,
+     "Insert After",
+     "Insert a new item into collection after the one referenced in subitem_reference_name or "
+     "_index"},
+    {IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE,
+     "INSERT_BEFORE",
+     0,
+     "Insert Before",
+     "Insert a new item into collection after the one referenced in subitem_reference_name or "
+     "_index (NOT USED)"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 #ifdef RNA_RUNTIME
 
 #  include "DNA_anim_types.h"
@@ -552,6 +593,65 @@ static ID *rna_ID_override_create(ID *id, Main *bmain, bool remap_local_usages)
   return local_id;
 }
 
+static void rna_ID_override_template_create(ID *id, ReportList *reports)
+{
+  if (!U.experimental.use_override_templates) {
+    BKE_report(reports, RPT_WARNING, "Override template experimental feature is disabled");
+    return;
+  }
+  if (ID_IS_LINKED(id)) {
+    BKE_report(reports, RPT_ERROR, "Unable to create override template for linked data-blocks");
+    return;
+  }
+  if (ID_IS_OVERRIDE_LIBRARY(id)) {
+    BKE_report(
+        reports, RPT_ERROR, "Unable to create override template for overridden data-blocks");
+    return;
+  }
+  BKE_lib_override_library_template_create(id);
+}
+
+static IDOverrideLibraryProperty *rna_ID_override_library_properties_add(
+    IDOverrideLibrary *override_library, ReportList *reports, const char rna_path[])
+{
+  bool created;
+  IDOverrideLibraryProperty *result = BKE_lib_override_library_property_get(
+      override_library, rna_path, &created);
+
+  if (!created) {
+    BKE_report(reports, RPT_DEBUG, "No new override property created, property already exists");
+  }
+
+  return result;
+}
+
+static IDOverrideLibraryPropertyOperation *rna_ID_override_library_property_operations_add(
+    IDOverrideLibraryProperty *override_property,
+    ReportList *reports,
+    int operation,
+    const char *subitem_refname,
+    const char *subitem_locname,
+    int subitem_refindex,
+    int subitem_locindex)
+{
+  bool created;
+  bool strict;
+  IDOverrideLibraryPropertyOperation *result = BKE_lib_override_library_property_operation_get(
+      override_property,
+      operation,
+      subitem_refname,
+      subitem_locname,
+      subitem_refindex,
+      subitem_locindex,
+      false,
+      &strict,
+      &created);
+  if (!created) {
+    BKE_report(reports, RPT_DEBUG, "No new override operation created, operation already exists");
+  }
+  return result;
+}
+
 static void rna_ID_update_tag(ID *id, Main *bmain, ReportList *reports, int flag)
 {
   /* XXX, new function for this! */
@@ -1267,47 +1367,6 @@ static void rna_def_ID_override_library_property_operation(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
-  static const EnumPropertyItem override_library_property_operation_items[] = {
-      {IDOVERRIDE_LIBRARY_OP_NOOP,
-       "NOOP",
-       0,
-       "No-Op",
-       "Does nothing, prevents adding actual overrides (NOT USED)"},
-      {IDOVERRIDE_LIBRARY_OP_REPLACE,
-       "REPLACE",
-       0,
-       "Replace",
-       "Replace value of reference by overriding one"},
-      {IDOVERRIDE_LIBRARY_OP_ADD,
-       "DIFF_ADD",
-       0,
-       "Differential",
-       "Stores and apply difference between reference and local value (NOT USED)"},
-      {IDOVERRIDE_LIBRARY_OP_SUBTRACT,
-       "DIFF_SUB",
-       0,
-       "Differential",
-       "Stores and apply difference between reference and local value (NOT USED)"},
-      {IDOVERRIDE_LIBRARY_OP_MULTIPLY,
-       "FACT_MULTIPLY",
-       0,
-       "Factor",
-       "Stores and apply multiplication factor between reference and local value (NOT USED)"},
-      {IDOVERRIDE_LIBRARY_OP_INSERT_AFTER,
-       "INSERT_AFTER",
-       0,
-       "Insert After",
-       "Insert a new item into collection after the one referenced in subitem_reference_name or "
-       "_index"},
-      {IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE,
-       "INSERT_BEFORE",
-       0,
-       "Insert Before",
-       "Insert a new item into collection after the one referenced in subitem_reference_name or "
-       "_index (NOT USED)"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
   static const EnumPropertyItem override_library_property_flag_items[] = {
       {IDOVERRIDE_LIBRARY_FLAG_MANDATORY,
        "MANDATORY",
@@ -1329,7 +1388,7 @@ static void rna_def_ID_override_library_property_operation(BlenderRNA *brna)
 
   prop = RNA_def_enum(srna,
                       "operation",
-                      override_library_property_operation_items,
+                      rna_enum_override_library_property_operation_items,
                       IDOVERRIDE_LIBRARY_OP_REPLACE,
                       "Operation",
                       "What override operation is performed");
@@ -1386,6 +1445,66 @@ static void rna_def_ID_override_library_property_operation(BlenderRNA *brna)
   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
 }
 
+static void rna_def_ID_override_library_property_operations(BlenderRNA *brna, PropertyRNA *cprop)
+{
+  StructRNA *srna;
+  FunctionRNA *func;
+  PropertyRNA *parm;
+
+  RNA_def_property_srna(cprop, "IDOverrideLibraryPropertyOperations");
+  srna = RNA_def_struct(brna, "IDOverrideLibraryPropertyOperations", NULL);
+  RNA_def_struct_sdna(srna, "IDOverrideLibraryProperty");
+  RNA_def_struct_ui_text(srna, "Override Operations", "Collection of override operations");
+
+  /* Add Property */
+  func = RNA_def_function(srna, "add", "rna_ID_override_library_property_operations_add");
+  RNA_def_function_ui_description(func, "Add a new operation");
+  RNA_def_function_flag(func, FUNC_USE_REPORTS);
+  parm = RNA_def_enum(func,
+                      "operation",
+                      rna_enum_override_library_property_operation_items,
+                      IDOVERRIDE_LIBRARY_OP_REPLACE,
+                      "Operation",
+                      "What override operation is performed");
+  RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+  parm = RNA_def_string(func,
+                        "subitem_reference_name",
+                        NULL,
+                        INT_MAX,
+                        "Subitem Reference Name",
+                        "Used to handle insertions into collection");
+  parm = RNA_def_string(func,
+                    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list