[Bf-blender-cvs] [b4f3c3cca00] geometry-nodes: Geometry Nodes: Use context for active modifier operators

Hans Goudey noreply at git.blender.org
Wed Nov 25 17:46:11 CET 2020


Commit: b4f3c3cca00d889abb585e3bc7d9806e003c3a11
Author: Hans Goudey
Date:   Wed Nov 25 11:46:02 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rBb4f3c3cca00d889abb585e3bc7d9806e003c3a11

Geometry Nodes: Use context for active modifier operators

This adds "modifier" as a new context variable in the property editor.
It is used instead of getting the active modifier directly. This way it
displays in the breadcrumbs panel, and the variable can be set only
in the modifier tab, meaning it won't work from the shortcut even
when the modifiers aren't visible.

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

M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/space_buttons/buttons_context.c

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

diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 864b3357ea2..7d12fa1805b 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -1101,7 +1101,7 @@ static void edit_modifier_report_property(wmOperatorType *ot)
  * Using modifier names and data context.
  * \{ */
 
-static bool edit_modifier_properties_base(bContext *C, wmOperator *op)
+bool edit_modifier_invoke_properties(bContext *C, wmOperator *op)
 {
   if (RNA_struct_property_is_set(op->ptr, "modifier")) {
     return true;
@@ -1117,73 +1117,6 @@ static bool edit_modifier_properties_base(bContext *C, wmOperator *op)
   return false;
 }
 
-static bool edit_modifier_properties_active(bContext *C, wmOperator *op)
-{
-  Object *ob = ED_object_active_context(C);
-  if (ob != NULL) {
-    ModifierData *md = BKE_object_active_modifier(ob);
-    if (md != NULL) {
-      RNA_string_set(op->ptr, "modifier", md->name);
-      return true;
-    }
-  }
-
-  return false;
-}
-
-bool edit_modifier_invoke_properties(bContext *C, wmOperator *op)
-{
-  if (edit_modifier_properties_base(C, op)) {
-    return true;
-  }
-  if (edit_modifier_properties_active(C, op)) {
-    return true;
-  }
-
-  return false;
-}
-
-/**
- * Run the regular invoke properties, then also check the custom data
- * of panels under the mouse for a modifier.
- *
- * \param event: If this isn't NULL, the operator will also look for panels underneath
- * the cursor with customdata set to a modifier.
- * \param r_retval: This should be used if #event is used in order to to return
- * #OPERATOR_PASS_THROUGH to check other operators with the same key set.
- */
-bool edit_modifier_invoke_properties_with_hover_no_active(bContext *C,
-                                                          wmOperator *op,
-                                                          const wmEvent *event,
-                                                          int *r_retval)
-{
-
-  if (edit_modifier_properties_base(C, op)) {
-    return true;
-  }
-
-  PointerRNA *panel_ptr = UI_region_panel_custom_data_under_cursor(C, event);
-
-  if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) {
-    if (RNA_struct_is_a(panel_ptr->type, &RNA_Modifier)) {
-      ModifierData *md = panel_ptr->data;
-      RNA_string_set(op->ptr, "modifier", md->name);
-      return true;
-    }
-    BLI_assert(r_retval != NULL); /* We need the return value in this case. */
-    if (r_retval != NULL) {
-      *r_retval = (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
-    }
-    return false;
-  }
-
-  if (r_retval != NULL) {
-    *r_retval = OPERATOR_CANCELLED;
-  }
-
-  return false;
-}
-
 ModifierData *edit_modifier_property_get(wmOperator *op, Object *ob, int type)
 {
   char modifier_name[MAX_NAME];
@@ -1248,7 +1181,9 @@ static int modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UN
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_remove_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 void OBJECT_OT_modifier_remove(wmOperatorType *ot)
@@ -1293,7 +1228,8 @@ static int modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *U
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_move_up_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 void OBJECT_OT_modifier_move_up(wmOperatorType *ot)
@@ -1337,7 +1273,8 @@ static int modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_move_down_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 void OBJECT_OT_modifier_move_down(wmOperatorType *ot)
@@ -1483,7 +1420,8 @@ static int modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *UNU
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_apply_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 void OBJECT_OT_modifier_apply(wmOperatorType *ot)
@@ -1528,7 +1466,8 @@ static int modifier_apply_as_shapekey_invoke(bContext *C,
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_apply_as_shapekey_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 static char *modifier_apply_as_shapekey_get_description(struct bContext *UNUSED(C),
@@ -1639,7 +1578,8 @@ static int modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
   if (edit_modifier_invoke_properties(C, op)) {
     return modifier_copy_exec(C, op);
   }
-  return OPERATOR_CANCELLED;
+  /* Work around multiple operators using the same shortcut. */
+  return (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
 }
 
 void OBJECT_OT_modifier_copy(wmOperatorType *ot)
@@ -1676,6 +1616,47 @@ static int modifier_set_active_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
+/**
+ * Get the modifier below the mouse cursor modifier without checking the context pointer.
+ * Used in order to set the active modifier on mouse click. If this checked the context
+ * pointer then it would always set the active modifier to the already active modifier.
+ *
+ * \param event: If this isn't NULL, the operator will also look for panels underneath
+ * the cursor with customdata set to a modifier.
+ * \param r_retval: This should be used if #event is used in order to to return
+ * #OPERATOR_PASS_THROUGH to check other operators with the same key set.
+ */
+bool edit_modifier_invoke_properties_with_hover_no_active(bContext *C,
+                                                          wmOperator *op,
+                                                          const wmEvent *event,
+                                                          int *r_retval)
+{
+  if (RNA_struct_property_is_set(op->ptr, "modifier")) {
+    return true;
+  }
+
+  PointerRNA *panel_ptr = UI_region_panel_custom_data_under_cursor(C, event);
+
+  if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) {
+    if (RNA_struct_is_a(panel_ptr->type, &RNA_Modifier)) {
+      ModifierData *md = panel_ptr->data;
+      RNA_string_set(op->ptr, "modifier", md->name);
+      return true;
+    }
+    BLI_assert(r_retval != NULL); /* We need the return value in this case. */
+    if (r_retval != NULL) {
+      *r_retval = (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
+    }
+    return false;
+  }
+
+  if (r_retval != NULL) {
+    *r_retval = OPERATOR_CANCELLED;
+  }
+
+  return false;
+}
+
 static int modifier_set_active_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
   int retval;
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index b532e030140..8b39995a5c9 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -49,6 +49,7 @@
 #include "BKE_linestyle.h"
 #include "BKE_material.h"
 #include "BKE_modifier.h"
+#include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_screen.h"
@@ -272,16 +273,22 @@ static bool buttons_context_path_modifier(ButsContextPath *path)
   if (buttons_context_path_object(path)) {
     Object *ob = path->ptr[path->len - 1].data;
 
-    if (ob && ELEM(ob->type,
-                   OB_MESH,
-                   OB_CURVE,
-                   OB_FONT,
-                   OB_SURF,
-                   OB_LATTICE,
-                   OB_GPENCIL,
-                   OB_HAIR,
-                   OB_POINTCLOUD,
-                   OB_VOLUME)) {
+    if (ELEM(ob->type,
+             OB_MESH,
+             OB_CURVE,
+             OB_FONT,
+             OB_SURF,
+             OB_LATTICE,
+             OB_GPENCIL,
+             OB_HAIR,
+             OB_POINTCLOUD,
+             OB_VOLUME)) {
+      ModifierData *md = BKE_object_active_modifier(ob);
+      if (md != NULL) {
+        RNA_pointer_create(&ob->id, &RNA_Modifier, md, &path->ptr[path->len]);
+        path->len++;
+      }
+
       return true;
     }
   }
@@ -935,6 +942,17 @@ int /*eContextResult*/ buttons_context(const bContext *C,
 
     return CTX_RESULT_OK;
   }
+  if (CTX_data_equals(member, "modifier")) {
+    PointerRNA *ptr = get_pointer_type(path, &RNA_Modifier);
+
+    if (ptr != NULL && !RNA_pointer_is_null(ptr)) {
+      Object *ob = (Object *)ptr->owner_id;
+      ModifierData *md = ptr->data;
+      CTX_data_pointer_set(result, &ob->id, &RNA_Modifier, md);
+      return CTX_RESULT_OK;
+    }
+    return CTX_RESULT_NO_DATA;
+  }
   if (CTX_data_equals(member, "texture_user")) {
     ButsContextTexture *ct = sbuts->texuser;



More information about the Bf-blender-cvs mailing list