[Bf-blender-cvs] [bab57550b69] master: LibOverride: Abstract a bit handling of local items of RNA collections.

Bastien Montagne noreply at git.blender.org
Mon Dec 7 16:55:56 CET 2020


Commit: bab57550b69b8429bb2f081fbc75f1d1ca035a34
Author: Bastien Montagne
Date:   Mon Dec 7 16:52:45 2020 +0100
Branches: master
https://developer.blender.org/rBbab57550b69b8429bb2f081fbc75f1d1ca035a34

LibOverride: Abstract a bit handling of local items of RNA collections.

RNA collections that support insertion of new items in liboverride
data-block need a special way to distiguish between locale and
orig-from-linked items (since some operations are allowed on the forer,
but no the latter).

In future we want a proper solution to abstract that at the
`BKE_lib_override` level, but for now we need to add some code for each
case.

Note that this commit also fixes a few potential issues with GPencil
modifiers, and constraints, regarding their handling of local overrides.

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

M	source/blender/blenkernel/BKE_constraint.h
M	source/blender/blenkernel/BKE_gpencil_modifier.h
M	source/blender/blenkernel/BKE_modifier.h
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/editors/object/object_constraint.c
M	source/blender/editors/object/object_gpencil_modifier.c
M	source/blender/editors/object/object_modifier.c

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

diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 4b9f480e091..1589bff7501 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -177,6 +177,9 @@ struct bConstraint *BKE_constraint_find_from_target(struct Object *ob,
                                                     struct bConstraintTarget *tgt,
                                                     struct bPoseChannel **r_pchan);
 
+bool BKE_constraint_is_local_in_liboverride(const struct Object *ob,
+                                            const struct bConstraint *con);
+
 struct bConstraint *BKE_constraint_add_for_object(struct Object *ob, const char *name, short type);
 struct bConstraint *BKE_constraint_add_for_pose(struct Object *ob,
                                                 struct bPoseChannel *pchan,
diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h
index 7729d2c53ab..bdc583048b8 100644
--- a/source/blender/blenkernel/BKE_gpencil_modifier.h
+++ b/source/blender/blenkernel/BKE_gpencil_modifier.h
@@ -278,6 +278,9 @@ void BKE_gpencil_modifiers_foreach_tex_link(struct Object *ob,
                                             GreasePencilTexWalkFunc walk,
                                             void *userData);
 
+bool BKE_gpencil_modifier_is_local_in_liboverride(const struct Object *ob,
+                                                  const struct GpencilModifierData *gmd);
+
 typedef struct GpencilVirtualModifierData {
   ArmatureGpencilModifierData amd;
   LatticeGpencilModifierData lmd;
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index b0a7d89e3d8..37f566d6f8e 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -431,6 +431,7 @@ bool BKE_modifier_is_non_geometrical(ModifierData *md);
 bool BKE_modifier_is_enabled(const struct Scene *scene,
                              struct ModifierData *md,
                              int required_mode);
+bool BKE_modifier_is_local_in_liboverride(const struct Object *ob, const struct ModifierData *md);
 void BKE_modifier_set_error(const struct Object *ob,
                             struct ModifierData *md,
                             const char *format,
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 28121206a90..982e91dd1e0 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -5754,6 +5754,7 @@ bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const
   bConstraint *dst = MEM_dupallocN(src);
   constraint_copy_data_ex(dst, src, flag, do_extern);
   dst->next = dst->prev = NULL;
+  dst->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
   return dst;
 }
 
@@ -5788,6 +5789,7 @@ void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag,
   for (con = dst->first, srccon = src->first; con && srccon;
        srccon = srccon->next, con = con->next) {
     constraint_copy_data_ex(con, srccon, flag, do_extern);
+    con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
   }
 }
 
@@ -5954,6 +5956,19 @@ static bConstraint *constraint_find_original_for_update(bConstraintOb *cob, bCon
   return orig_con;
 }
 
+/**
+ * Check whether given constraint is local when the object is a library override.
+ *
+ * \param con May be NULL, in which case we consider it as a non-local constraint case.
+ *
+ * \note This check is only valid for a liboverride data-block, it always return \a true otherwise.
+ */
+bool BKE_constraint_is_local_in_liboverride(const Object *ob, const bConstraint *con)
+{
+  return (!ID_IS_OVERRIDE_LIBRARY(ob) ||
+          (con != NULL && (con->flag & CONSTRAINT_OVERRIDE_LIBRARY_LOCAL) != 0));
+}
+
 /* -------- Constraints and Proxies ------- */
 
 /* Rescue all constraints tagged as being CONSTRAINT_PROXY_LOCAL
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 09f9e9e891c..7425a1a5f7a 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -530,6 +530,19 @@ void BKE_gpencil_modifier_set_error(GpencilModifierData *md, const char *_format
   CLOG_STR_ERROR(&LOG, md->error);
 }
 
+/**
+ * Check whether given modifier is local when the object is a library override.
+ *
+ * \param gmd May be NULL, in which case we consider it as a non-local modifier case.
+ *
+ * \note This check is only valid for a liboverride data-block, it always return \a true otherwise.
+ */
+bool BKE_gpencil_modifier_is_local_in_liboverride(const Object *ob, const GpencilModifierData *gmd)
+{
+  return (!ID_IS_OVERRIDE_LIBRARY(ob) ||
+          (gmd != NULL && (gmd->flag & eGpencilModifierFlag_OverrideLibrary_Local) != 0));
+}
+
 /**
  * Link grease pencil modifier related IDs.
  * \param ob: Grease pencil object
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index c9bdaecfa2a..7865d44c446 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -574,6 +574,19 @@ bool BKE_modifier_is_enabled(const struct Scene *scene, ModifierData *md, int re
   return true;
 }
 
+/**
+ * Check whether given modifier is local when the object is a library override.
+ *
+ * \param md May be NULL, in which case we consider it as a non-local modifier case.
+ *
+ * \note This check is only valid for a liboverride data-block, it always return \a true otherwise.
+ */
+bool BKE_modifier_is_local_in_liboverride(const Object *ob, const ModifierData *md)
+{
+  return (!ID_IS_OVERRIDE_LIBRARY(ob) ||
+          (md != NULL && (md->flag & eModifierFlag_OverrideLibrary_Local) != 0));
+}
+
 CDMaskLink *BKE_modifier_calc_data_masks(struct Scene *scene,
                                          Object *ob,
                                          ModifierData *md,
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index fa8531dfb48..e684ad03f53 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -706,11 +706,9 @@ static bool edit_constraint_poll_generic(bContext *C,
     return false;
   }
 
-  if (ID_IS_OVERRIDE_LIBRARY(ob) && !is_liboverride_allowed) {
-    if ((con == NULL) || (con->flag & CONSTRAINT_OVERRIDE_LIBRARY_LOCAL) == 0) {
-      CTX_wm_operator_poll_msg_set(C, "Cannot edit constraints coming from library override");
-      return false;
-    }
+  if (!is_liboverride_allowed && !BKE_constraint_is_local_in_liboverride(ob, con)) {
+    CTX_wm_operator_poll_msg_set(C, "Cannot edit constraints coming from library override");
+    return false;
   }
 
   return true;
diff --git a/source/blender/editors/object/object_gpencil_modifier.c b/source/blender/editors/object/object_gpencil_modifier.c
index eed3c7f419d..d3f165678c3 100644
--- a/source/blender/editors/object/object_gpencil_modifier.c
+++ b/source/blender/editors/object/object_gpencil_modifier.c
@@ -319,6 +319,8 @@ int ED_object_gpencil_modifier_copy(ReportList *reports, Object *ob, GpencilModi
   BLI_insertlinkafter(&ob->greasepencil_modifiers, md, nmd);
   BKE_gpencil_modifier_unique_name(&ob->greasepencil_modifiers, nmd);
 
+  nmd->flag |= eGpencilModifierFlag_OverrideLibrary_Local;
+
   return 1;
 }
 
@@ -422,7 +424,10 @@ void OBJECT_OT_gpencil_modifier_add(wmOperatorType *ot)
 
 /********** generic functions for operators using mod names and data context *********************/
 
-static bool gpencil_edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag)
+static bool gpencil_edit_modifier_poll_generic(bContext *C,
+                                               StructRNA *rna_type,
+                                               int obtype_flag,
+                                               const bool is_liboverride_allowed)
 {
   PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type);
   Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C);
@@ -438,11 +443,10 @@ static bool gpencil_edit_modifier_poll_generic(bContext *C, StructRNA *rna_type,
     return false;
   }
 
-  if (ID_IS_OVERRIDE_LIBRARY(ob)) {
-    if ((mod == NULL) || (mod->flag & eGpencilModifierFlag_OverrideLibrary_Local) == 0) {
-      CTX_wm_operator_poll_msg_set(C, "Cannot edit modifiers coming from library override");
-      return false;
-    }
+  if (!is_liboverride_allowed &&
+      (mod == NULL || !BKE_gpencil_modifier_is_local_in_liboverride(ob, mod))) {
+    CTX_wm_operator_poll_msg_set(C, "Cannot edit modifiers coming from library override");
+    return false;
   }
 
   return true;
@@ -450,7 +454,14 @@ static bool gpencil_edit_modifier_poll_generic(bContext *C, StructRNA *rna_type,
 
 static bool gpencil_edit_modifier_poll(bContext *C)
 {
-  return gpencil_edit_modifier_poll_generic(C, &RNA_GpencilModifier, 0);
+  return gpencil_edit_modifier_poll_generic(C, &RNA_GpencilModifier, 0, false);
+}
+
+/* Used by operators performing actions allowed also on modifiers from the overridden linked object
+ * (not only from added 'local' ones). */
+static bool gpencil_edit_modifier_liboverride_allowed_poll(bContext *C)
+{
+  return gpencil_edit_modifier_poll_generic(C, &RNA_Modifier, 0, true);
 }
 
 static void gpencil_edit_modifier_properties(wmOperatorType *ot)
@@ -669,11 +680,6 @@ void OBJECT_OT_gpencil_modifier_move_down(wmOperatorType *ot)
 
 /* ************************* Move to Index Gpencil Modifier Operator ************************* */
 
-static bool gpencil_modifier_move_to_index_poll(bContext *C)
-{
-  return gpencil_edit_modifier_poll(C);
-}
-
 static int gpencil_modifier_move_to_index_exec(bContext *C, wmOperator *op)
 {
   Object *ob = ED_object_active_context(C);
@@ -706,7 +712,7 @@ void OBJECT_OT_gpencil_modifier_move_to_index(wmOperatorType *ot)
 
   ot->invoke = gpencil_modifier_move_to_index_invoke;
   ot->exec = gpencil_modifier_move_to_index_exec;
-  ot->poll = gpe

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list