Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_constraint.c
| Show First 20 Lines • Show All 1,872 Lines • ▼ Show 20 Lines | if (pchan == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No active pose bone to add a constraint to"); | BKE_report(op->reports, RPT_ERROR, "No active pose bone to add a constraint to"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| /* check if constraint to be added is valid for the given constraints stack */ | /* check if constraint to be added is valid for the given constraints stack */ | ||||
| if (type == CONSTRAINT_TYPE_NULL) { | if (type == CONSTRAINT_TYPE_NULL) { | ||||
| return OPERATOR_CANCELLED; | 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, | /* Create a new constraint of the type required, | ||||
| * and add it to the active/given constraints list. */ | * and add it to the active/given constraints list. */ | ||||
| if (pchan) { | if (pchan) { | ||||
| con = BKE_constraint_add_for_pose(ob, pchan, NULL, type); | con = BKE_constraint_add_for_pose(ob, pchan, NULL, type); | ||||
| } | } | ||||
| else { | else { | ||||
| con = BKE_constraint_add_for_object(ob, NULL, type); | con = BKE_constraint_add_for_object(ob, NULL, type); | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | if (strstr(op->idname, "with_targets")) { | ||||
| with_targets = 1; | with_targets = 1; | ||||
| } | } | ||||
| return constraint_add_exec(C, op, ob, get_active_constraints(ob), type, with_targets); | return constraint_add_exec(C, op, ob, get_active_constraints(ob), type, with_targets); | ||||
| } | } | ||||
| /* ------------------ */ | /* ------------------ */ | ||||
| /* 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) | void OBJECT_OT_constraint_add(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Constraint"; | ot->name = "Add Constraint"; | ||||
| ot->description = "Add a constraint to the active object"; | ot->description = "Add a constraint to the active object"; | ||||
| ot->idname = "OBJECT_OT_constraint_add"; | ot->idname = "OBJECT_OT_constraint_add"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = WM_menu_invoke; | ot->invoke = WM_menu_invoke; | ||||
| ot->exec = object_constraint_add_exec; | ot->exec = object_constraint_add_exec; | ||||
| ot->poll = ED_operator_object_active_editable; | ot->poll = ED_operator_object_active_editable; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* 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) | void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | |||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Constraint (with Targets)"; | ot->name = "Add Constraint (with Targets)"; | ||||
| ot->description = | ot->description = | ||||
| "Add a constraint to the active object, with target (where applicable) set to the selected " | "Add a constraint to the active object, with target (where applicable) set to the selected " | ||||
| "Objects/Bones"; | "Objects/Bones"; | ||||
| ot->idname = "OBJECT_OT_constraint_add_with_targets"; | ot->idname = "OBJECT_OT_constraint_add_with_targets"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = WM_menu_invoke; | ot->invoke = WM_menu_invoke; | ||||
| ot->exec = object_constraint_add_exec; | ot->exec = object_constraint_add_exec; | ||||
| ot->poll = ED_operator_object_active_editable; | ot->poll = ED_operator_object_active_editable; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* 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) | void POSE_OT_constraint_add(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Constraint"; | ot->name = "Add Constraint"; | ||||
| ot->description = "Add a constraint to the active bone"; | ot->description = "Add a constraint to the active bone"; | ||||
| ot->idname = "POSE_OT_constraint_add"; | ot->idname = "POSE_OT_constraint_add"; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||