[Bf-blender-cvs] [a21cb22f8b1] master: Cleanup: Deduplicate code for finding context object

Hans Goudey noreply at git.blender.org
Fri Jul 3 17:58:50 CEST 2020


Commit: a21cb22f8b12ea73937e7e6eda8465f1cba02b6e
Author: Hans Goudey
Date:   Fri Jul 3 11:58:43 2020 -0400
Branches: master
https://developer.blender.org/rBa21cb22f8b12ea73937e7e6eda8465f1cba02b6e

Cleanup: Deduplicate code for finding context object

Instead of manually checking the pinned object, use the existing
ED_object_active_context function. This requires adding const
to the context in that function.

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

M	source/blender/editors/include/ED_object.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/object/object_edit.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
M	source/blender/modifiers/intern/MOD_ui_common.c
M	source/blender/shader_fx/intern/FX_ui_common.c

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

diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 10cd6980c90..a851eb735b8 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -58,9 +58,9 @@ struct wmWindowManager;
 
 /* object_edit.c */
 /* context.object */
-struct Object *ED_object_context(struct bContext *C);
+struct Object *ED_object_context(const struct bContext *C);
 /* context.object or context.active_object */
-struct Object *ED_object_active_context(struct bContext *C);
+struct Object *ED_object_active_context(const struct bContext *C);
 void ED_collection_hide_menu_draw(const struct bContext *C, struct uiLayout *layout);
 
 /* object_utils.c */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 992c9e07033..f3e2eef6f31 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1836,18 +1836,6 @@ void uiTemplatePathBuilder(uiLayout *layout,
  *  Template for building the panel layout for the active object's modifiers.
  * \{ */
 
-/**
- * Get the active object or the property region's pinned object.
- */
-static Object *get_context_object(const bContext *C)
-{
-  SpaceProperties *sbuts = CTX_wm_space_properties(C);
-  if (sbuts != NULL && (sbuts->pinid != NULL) && GS(sbuts->pinid->name) == ID_OB) {
-    return (Object *)sbuts->pinid;
-  }
-  return CTX_data_active_object(C);
-}
-
 static void modifier_panel_id(void *md_link, char *r_name)
 {
   ModifierData *md = (ModifierData *)md_link;
@@ -1859,7 +1847,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
   ScrArea *sa = CTX_wm_area(C);
   ARegion *region = CTX_wm_region(C);
 
-  Object *ob = get_context_object(C);
+  Object *ob = ED_object_active_context(C);
   ListBase *modifiers = &ob->modifiers;
 
   bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
@@ -1952,7 +1940,7 @@ static ListBase *get_constraints(const bContext *C, bool use_bone_constraints)
     }
   }
   else {
-    Object *ob = get_context_object(C);
+    Object *ob = ED_object_active_context(C);
     if (ob != NULL) {
       constraints = &ob->constraints;
     }
@@ -2095,7 +2083,7 @@ void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C)
 {
   ScrArea *sa = CTX_wm_area(C);
   ARegion *region = CTX_wm_region(C);
-  Object *ob = get_context_object(C);
+  Object *ob = ED_object_active_context(C);
   ListBase *modifiers = &ob->greasepencil_modifiers;
 
   bool panels_match = UI_panel_list_matches_data(region, modifiers, gpencil_modifier_panel_id);
@@ -2183,7 +2171,7 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
 {
   ScrArea *sa = CTX_wm_area(C);
   ARegion *region = CTX_wm_region(C);
-  Object *ob = get_context_object(C);
+  Object *ob = ED_object_active_context(C);
   ListBase *shaderfx = &ob->shader_fx;
 
   bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 0ea9d24a016..a9eb454eb04 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -126,14 +126,14 @@ static ListBase selected_objects_get(bContext *C);
 /** \name Internal Utilities
  * \{ */
 
-Object *ED_object_context(bContext *C)
+Object *ED_object_context(const bContext *C)
 {
   return CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
 }
 
 /* find the correct active object per context
  * note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */
-Object *ED_object_active_context(bContext *C)
+Object *ED_object_active_context(const bContext *C)
 {
   Object *ob = NULL;
   if (C) {
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
index c15bef1f748..a9afbc4b6ae 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
@@ -34,7 +34,6 @@
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_space_types.h"
 
 #include "ED_object.h"
 
@@ -50,23 +49,12 @@
 
 #include "MOD_gpencil_ui_common.h" /* Self include */
 
-static Object *get_gpencilmodifier_object(const bContext *C)
-{
-  SpaceProperties *sbuts = CTX_wm_space_properties(C);
-  if (sbuts != NULL && (sbuts->pinid != NULL) && GS(sbuts->pinid->name) == ID_OB) {
-    return (Object *)sbuts->pinid;
-  }
-  else {
-    return CTX_data_active_object(C);
-  }
-}
-
 /**
  * Poll function so these modifier panels only show for grease pencil objects.
  */
 static bool gpencil_modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt))
 {
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
 
   return (ob != NULL) && (ob->type == OB_GPENCIL);
 }
@@ -80,7 +68,7 @@ static bool gpencil_modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt))
  */
 static void gpencil_modifier_reorder(bContext *C, Panel *panel, int new_index)
 {
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
 
   GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index);
   PointerRNA props_ptr;
@@ -94,7 +82,7 @@ static void gpencil_modifier_reorder(bContext *C, Panel *panel, int new_index)
 
 static short get_gpencil_modifier_expand_flag(const bContext *C, Panel *panel)
 {
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
   GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index);
   return md->ui_expand_flag;
   return 0;
@@ -102,7 +90,7 @@ static short get_gpencil_modifier_expand_flag(const bContext *C, Panel *panel)
 
 static void set_gpencil_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag)
 {
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
   GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index);
   md->ui_expand_flag = expand_flag;
 }
@@ -245,7 +233,7 @@ void gpencil_modifier_panel_get_property_pointers(const bContext *C,
                                                   PointerRNA *r_ob_ptr,
                                                   PointerRNA *r_md_ptr)
 {
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
   GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index);
 
   RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, r_md_ptr);
@@ -269,7 +257,7 @@ static void gpencil_modifier_ops_extra_draw(bContext *C, uiLayout *layout, void
   const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
 
   PointerRNA ptr;
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
   RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr);
   uiLayoutSetContextPointer(layout, "modifier", &ptr);
   uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
@@ -328,7 +316,7 @@ static void gpencil_modifier_panel_header(const bContext *C, Panel *panel)
   uiLayout *row, *sub;
   uiLayout *layout = panel->layout;
 
-  Object *ob = get_gpencilmodifier_object(C);
+  Object *ob = ED_object_active_context(C);
   GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index);
   PointerRNA ptr;
   RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr);
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index 2f0e70d1bee..137f52782a9 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -33,7 +33,6 @@
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_space_types.h"
 
 #include "ED_object.h"
 
@@ -50,24 +49,13 @@
 #include "MOD_modifiertypes.h"
 #include "MOD_ui_common.h" /* Self include */
 
-static Object *get_modifier_object(const bContext *C)
-{
-  SpaceProperties *sbuts = CTX_wm_space_properties(C);
-  if (sbuts != NULL && (sbuts->pinid != NULL) && GS(sbuts->pinid->name) == ID_OB) {
-    return (Object *)sbuts->pinid;
-  }
-  else {
-    return CTX_data_active_object(C);
-  }
-}
-
 /**
  * Poll function so these modifier panels don't show for other object types with modifiers (only
  * grease pencil currently).
  */
 static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt))
 {
-  Object *ob = get_modifier_object(C);
+  Object *ob = ED_object_active_context(C);
 
   return (ob != NULL) && (ob->type != OB_GPENCIL);
 }
@@ -81,7 +69,7 @@ static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt))
  */
 static void modifier_reorder(bContext *C, Panel *panel, int new_index)
 {
-  Object *ob = get_modifier_object(C);
+  Object *ob = ED_object_active_context(C);
 
   ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index);
   PointerRNA props_ptr;
@@ -95,14 +83,14 @@ static void modifier_reorder(bContext *C, Panel *panel, int new_index)
 
 static short get_modifier_expand_flag(const bContext *C, Panel *panel)
 {
-  Object *ob = get_modifier_object(C);
+  Object *ob = ED_object_active_context(C);
   ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index);
   return md->ui_expand_flag;
 }
 
 static void set_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag)
 {
-  Object *ob = get_modifier_object(C);
+  Object *ob = ED_object_active_context(C);
   ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index);
   md->ui_expand_flag = expand_flag;
 }
@@ -135,7 +123,7 @@ void modifier_panel_get_property_pointers(const bContext *C,
                                           PointerRNA *r_ob_ptr,
                                           PointerRNA *r_md_ptr)
 {
-  Object *ob = get_modifier_object(C);
+  Object *ob = ED_object_active_context(C);
 
   ModifierData *md

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list