[Bf-blender-cvs] [f437b958c3f] master: UI: remove bone only constraints from object constraint menu
Nathan Craddock
noreply at git.blender.org
Fri May 3 15:43:37 CEST 2019
Commit: f437b958c3ffc7bea0e9869e296da2585f2e75fe
Author: Nathan Craddock
Date: Fri May 3 14:32:45 2019 +0200
Branches: master
https://developer.blender.org/rBf437b958c3ffc7bea0e9869e296da2585f2e75fe
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
===================================================================
M source/blender/editors/object/object_constraint.c
===================================================================
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)
More information about the Bf-blender-cvs
mailing list