diff options
author | Nathan Craddock <Zachman> | 2019-05-03 15:32:45 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-03 16:42:49 +0300 |
commit | f437b958c3ffc7bea0e9869e296da2585f2e75fe (patch) | |
tree | 1190966663f5598082ab312bc42661a2c1d7f4c7 /source/blender/editors/object/object_constraint.c | |
parent | 68b15fc3ad4f74be192150d3a2fb35e7ef2d4edd (diff) |
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
Diffstat (limited to 'source/blender/editors/object/object_constraint.c')
-rw-r--r-- | source/blender/editors/object/object_constraint.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index d92e4aa2b27..078135f46ff 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -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) |