Fix [#21832] Add Modifier, Pinned Context

Added convenience function ED_object_active_context(C) to get either the
object in the data context, or if not, the active object.
This commit is contained in:
2010-03-31 00:55:01 +00:00
parent 05c2906b76
commit 4a451714d6
5 changed files with 22 additions and 22 deletions

View File

@@ -48,6 +48,9 @@ struct wmOperator;
struct wmEvent;
/* object_edit.c */
struct Object *ED_object_active_context(struct bContext *C);
/* object_ops.c */
void ED_operatortypes_object(void);
void ED_operatormacros_object(void);
void ED_keymap_object(struct wmKeyConfig *keyconf);

View File

@@ -64,6 +64,7 @@
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "UI_interface.h"
@@ -801,7 +802,7 @@ void POSE_OT_constraints_clear(wmOperatorType *ot)
static int object_constraints_clear_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
Object *ob= ED_object_active_context(C);
Scene *scene= CTX_data_scene(C);
/* do freeing */
@@ -835,7 +836,7 @@ void OBJECT_OT_constraints_clear(wmOperatorType *ot)
/* get the Object and/or PoseChannel to use as target */
static short get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, short add)
{
Object *obact= CTX_data_active_object(C);
Object *obact= ED_object_active_context(C);
bPoseChannel *pchanact= get_active_posechannel(obact);
short only_curve= 0, only_mesh= 0, only_ob= 0;
short found= 0;
@@ -1090,17 +1091,10 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
/* dummy operator callback */
static int object_constraint_add_exec(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
Object *ob;
Object *ob=ED_object_active_context(C);
int type= RNA_enum_get(op->ptr, "type");
short with_targets= 0;
/* get active object from context */
if (sa->spacetype == SPACE_BUTS)
ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
else
ob= CTX_data_active_object(C);
if (!ob) {
BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to.");
return OPERATOR_CANCELLED;
@@ -1118,17 +1112,10 @@ static int object_constraint_add_exec(bContext *C, wmOperator *op)
/* dummy operator callback */
static int pose_constraint_add_exec(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
Object *ob;
Object *ob= ED_object_active_context(C);
int type= RNA_enum_get(op->ptr, "type");
short with_targets= 0;
/* get active object from context */
if (sa->spacetype == SPACE_BUTS)
ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
else
ob= CTX_data_active_object(C);
if (!ob) {
BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to.");
return OPERATOR_CANCELLED;

View File

@@ -120,6 +120,16 @@ static int pupmenu(const char *msg) {return 0;}
static bContext *C;
static void error_libdata() {}
/* find the correct active object per context */
Object *ED_object_active_context(bContext *C)
{
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
if (!ob) ob= CTX_data_active_object(C);
return ob;
}
/* ********* clear/set restrict view *********/
static int object_restrictview_clear_exec(bContext *C, wmOperator *op)
{

View File

@@ -499,7 +499,7 @@ static int modifier_poll(bContext *C)
static int modifier_add_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
Object *ob = ED_object_active_context(C);
int type= RNA_enum_get(op->ptr, "type");
if(!ED_object_modifier_add(op->reports, scene, ob, NULL, type))
@@ -512,7 +512,7 @@ static int modifier_add_exec(bContext *C, wmOperator *op)
static EnumPropertyItem *modifier_add_itemf(bContext *C, PointerRNA *ptr, int *free)
{
Object *ob= CTX_data_active_object(C);
Object *ob= ED_object_active_context(C);
EnumPropertyItem *item= NULL, *md_item;
ModifierTypeInfo *mti;
int totitem= 0, a;

View File

@@ -199,12 +199,12 @@ int ED_operator_logic_active(bContext *C)
int ED_operator_object_active(bContext *C)
{
return NULL != CTX_data_active_object(C);
return NULL != ED_object_active_context(C);
}
int ED_operator_object_active_editable(bContext *C)
{
Object *ob=CTX_data_active_object(C);
Object *ob = ED_object_active_context(C);
return ((ob != NULL) && !(ob->id.lib));
}