Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_constraint.c
| Context not available. | |||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Find the list that a given constraint belongs to, and/or also get the posechannel this is from (if applicable) */ | |||||
| ListBase *get_constraint_lb(Object *ob, bConstraint *con, bPoseChannel **r_pchan) | |||||
| { | |||||
| if (r_pchan) | |||||
| *r_pchan = NULL; | |||||
| if (ELEM(NULL, ob, con)) | |||||
| return NULL; | |||||
| /* try object constraints first */ | |||||
| if ((BLI_findindex(&ob->constraints, con) != -1)) { | |||||
| return &ob->constraints; | |||||
| } | |||||
| /* if armature, try pose bones too */ | |||||
| if (ob->pose) { | |||||
| bPoseChannel *pchan; | |||||
| /* try each bone in order | |||||
| * NOTE: it's not possible to directly look up the active bone yet, so this will have to do | |||||
| */ | |||||
| for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { | |||||
| if ((BLI_findindex(&pchan->constraints, con) != -1)) { | |||||
| if (r_pchan) | |||||
| *r_pchan = pchan; | |||||
| return &pchan->constraints; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* done */ | |||||
| return NULL; | |||||
| } | |||||
| /* single constraint */ | /* single constraint */ | ||||
| bConstraint *get_active_constraint(Object *ob) | bConstraint *get_active_constraint(Object *ob) | ||||
| { | { | ||||
| Context not available. | |||||
| con = ptr.data; | con = ptr.data; | ||||
| RNA_string_set(op->ptr, "constraint", con->name); | RNA_string_set(op->ptr, "constraint", con->name); | ||||
| list = get_constraint_lb(ob, con, NULL); | list = BKE_object_constraint_listbase_get(ob, con, NULL); | ||||
| if (&ob->constraints == list) | if (&ob->constraints == list) | ||||
| RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_OBJECT); | RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_OBJECT); | ||||
| Context not available. | |||||
| void ED_object_constraint_set_active(Object *ob, bConstraint *con) | void ED_object_constraint_set_active(Object *ob, bConstraint *con) | ||||
| { | { | ||||
| ListBase *lb = get_constraint_lb(ob, con, NULL); | ListBase *lb = BKE_object_constraint_listbase_get(ob, con, NULL); | ||||
| /* lets be nice and escape if its active already */ | /* lets be nice and escape if its active already */ | ||||
| /* NOTE: this assumes that the stack doesn't have other active ones set... */ | /* NOTE: this assumes that the stack doesn't have other active ones set... */ | ||||
| Context not available. | |||||
| return (ptr.id.data && ptr.data); | return (ptr.id.data && ptr.data); | ||||
| } | } | ||||
| static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op)) | static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint); | PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint); | ||||
| Object *ob = ptr.id.data; | Object *ob = ptr.id.data; | ||||
| bConstraint *con = ptr.data; | bConstraint *con = ptr.data; | ||||
| ListBase *lb = get_constraint_lb(ob, con, NULL); | |||||
| const bool is_ik = ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK); | |||||
| /* free the constraint */ | /* free the constraint */ | ||||
| if (BKE_constraint_remove(lb, con)) { | if (BKE_constraint_remove_ex(ob, con, true)) { | ||||
| /* there's no active constraint now, so make sure this is the case */ | /* there's no active constraint now, so make sure this is the case */ | ||||
| BKE_constraints_active_set(lb, NULL); | /* not sure if 'CONSTRAINT_ACTIVE' is even used anywhere/anymore [can be removed]? - lichtwerk */ | ||||
| BKE_constraints_active_set(&ob->constraints, NULL); | |||||
| ED_object_constraint_update(ob); /* needed to set the flags on posebones correctly */ | ED_object_constraint_update(ob); /* needed to set the flags on posebones correctly */ | ||||
| /* ITASC needs to be rebuilt once a constraint is removed [#26920] */ | |||||
| if (is_ik) { | |||||
| BIK_clear_data(ob->pose); | |||||
| } | |||||
| /* notifiers */ | /* notifiers */ | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob); | WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob); | ||||
| Context not available. | |||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(op, ob, 0); | ||||
| if (con && con->next) { | if (con && con->next) { | ||||
| ListBase *conlist = get_constraint_lb(ob, con, NULL); | ListBase *conlist = BKE_object_constraint_listbase_get(ob, con, NULL); | ||||
| bConstraint *nextCon = con->next; | bConstraint *nextCon = con->next; | ||||
| /* insert the nominated constraint after the one that used to be after it */ | /* insert the nominated constraint after the one that used to be after it */ | ||||
| Context not available. | |||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(op, ob, 0); | ||||
| if (con && con->prev) { | if (con && con->prev) { | ||||
| ListBase *conlist = get_constraint_lb(ob, con, NULL); | ListBase *conlist = BKE_object_constraint_listbase_get(ob, con, NULL); | ||||
| bConstraint *prevCon = con->prev; | bConstraint *prevCon = con->prev; | ||||
| /* insert the nominated constraint before the one that used to be before it */ | /* insert the nominated constraint before the one that used to be before it */ | ||||
| Context not available. | |||||