UI: remove bone only constraints from object constraint menu
This is better than showing an error after trying to add them. Ref T61560. Differential Revision: https://developer.blender.org/D4767
This commit is contained in:
parent
68b15fc3ad
commit
f437b958c3
Notes:
blender-bot
2023-02-14 04:24:05 +01:00
Referenced by issue #61560, Remove the IK constraints from the Add Object Constraint menu
|
@ -1878,14 +1878,6 @@ static int constraint_add_exec(
|
|||
if (type == CONSTRAINT_TYPE_NULL) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
if ((type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints))) {
|
||||
BKE_report(op->reports, RPT_ERROR, "IK constraint can only be added to bones");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
if ((type == CONSTRAINT_TYPE_SPLINEIK) && ((!pchan) || (list != &pchan->constraints))) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Spline IK constraint can only be added to bones");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* Create a new constraint of the type required,
|
||||
* and add it to the active/given constraints list. */
|
||||
|
@ -2023,8 +2015,33 @@ static int pose_constraint_add_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* ------------------ */
|
||||
|
||||
/* Filters constraints that are only compatible with bones */
|
||||
static const EnumPropertyItem *object_constraint_add_itemf(bContext *UNUSED(C),
|
||||
PointerRNA *UNUSED(ptr),
|
||||
PropertyRNA *UNUSED(prop),
|
||||
bool *r_free)
|
||||
{
|
||||
const EnumPropertyItem *item = rna_enum_constraint_type_items;
|
||||
EnumPropertyItem *object_constraint_items = NULL;
|
||||
int totitem = 0;
|
||||
|
||||
while(item->identifier) {
|
||||
if((item->value != CONSTRAINT_TYPE_KINEMATIC) && (item->value != CONSTRAINT_TYPE_SPLINEIK)) {
|
||||
RNA_enum_item_add(&object_constraint_items, &totitem, item);
|
||||
}
|
||||
item++;
|
||||
}
|
||||
|
||||
RNA_enum_item_end(&object_constraint_items, &totitem);
|
||||
*r_free = true;
|
||||
|
||||
return object_constraint_items;
|
||||
}
|
||||
|
||||
void OBJECT_OT_constraint_add(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Add Constraint";
|
||||
ot->description = "Add a constraint to the active object";
|
||||
|
@ -2039,11 +2056,15 @@ void OBJECT_OT_constraint_add(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
|
||||
prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
|
||||
RNA_def_enum_funcs(prop, object_constraint_add_itemf);
|
||||
ot->prop = prop;
|
||||
}
|
||||
|
||||
void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Add Constraint (with Targets)";
|
||||
ot->description =
|
||||
|
@ -2060,7 +2081,9 @@ void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
|
||||
prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", "");
|
||||
RNA_def_enum_funcs(prop, object_constraint_add_itemf);
|
||||
ot->prop = prop;
|
||||
}
|
||||
|
||||
void POSE_OT_constraint_add(wmOperatorType *ot)
|
||||
|
|
Loading…
Reference in New Issue