Changeset View
Standalone View
source/blender/editors/object/object_constraint.c
| Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
| #include "object_intern.h" | #include "object_intern.h" | ||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Constraint Data Accessors | /** \name Constraint Data Accessors | ||||
| * \{ */ | * \{ */ | ||||
| /* if object in posemode, active bone constraints, else object constraints */ | /* if object in posemode, active bone constraints, else object constraints */ | ||||
| ListBase *ED_object_constraint_list_from_context(Object *ob) | ListBase *ED_object_constraint_list_from_context(Object *ob) | ||||
sybren: This sentence is missing a verb. | |||||
| { | { | ||||
Not Done Inline ActionsThe part between parentheses can be removed, or moved down into the function itself. It only means something when you know the exact implementation of the function. sybren: The part between parentheses can be removed, or moved down into the function itself. It only… | |||||
| if (ob == NULL) { | if (ob == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (ob->mode & OB_MODE_POSE) { | if (ob->mode & OB_MODE_POSE) { | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| pchan = BKE_pose_channel_active(ob); | pchan = BKE_pose_channel_active(ob); | ||||
| if (pchan) { | if (pchan) { | ||||
| return &pchan->constraints; | return &pchan->constraints; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| return &ob->constraints; | return &ob->constraints; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Get the constraints for the active pose bone or the active / pinned object. | |||||
Not Done Inline Actions"the context pose bone" is a weird concept. Probably clearer to write "the active pose bone". The fact that it comes from the context is already clear as that's the only parameter given. sybren: "the context pose bone" is a weird concept. Probably clearer to write "the active pose bone". | |||||
| * Does not check if bone is on an active layer. */ | |||||
| ListBase *ED_object_constraint_list_from_context_no_layer_check(const bContext *C, | |||||
| bool use_bone_constraints) | |||||
sybrenUnsubmitted Not Done Inline ActionsThis boolean indicates that this function is actually two functions in disguise. Functions should do one thing, and if there is a boolean that makes it switch between two things, it should be two functions. sybren: This boolean indicates that this function is actually two functions in disguise. Functions… | |||||
| { | |||||
| ListBase *constraints = {NULL}; | |||||
| if (use_bone_constraints) { | |||||
| bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data; | |||||
| if (pose_bone != NULL) { | |||||
| constraints = &pose_bone->constraints; | |||||
| } | |||||
| } | |||||
Not Done Inline ActionsThis function is now too complex. The initialisation of constraints looks like it initialises a ListBase, but it's actually just setting constraints = NULL. The only case in which the function can actually return NULL is when pose_bone == NULL. This seems much simpler to me: bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
if (pose_bone == NULL) {
return NULL;
}
return &pose_bone->constraints;sybren: This function is now too complex. The initialisation of `constraints` looks like it initialises… | |||||
| else { | |||||
| Object *ob = ED_object_active_context(C); | |||||
| if (ob != NULL) { | |||||
| constraints = &ob->constraints; | |||||
| } | |||||
| } | |||||
| return constraints; | |||||
| } | |||||
| /* Find the list that a given constraint belongs to, | /* Find the list that a given constraint belongs to, | ||||
| * and/or also get the posechannel this is from (if applicable) */ | * and/or also get the posechannel this is from (if applicable) */ | ||||
| ListBase *ED_object_constraint_list_from_constraint(Object *ob, | ListBase *ED_object_constraint_list_from_constraint(Object *ob, | ||||
| bConstraint *con, | bConstraint *con, | ||||
| bPoseChannel **r_pchan) | bPoseChannel **r_pchan) | ||||
| { | { | ||||
| if (r_pchan) { | if (r_pchan) { | ||||
| *r_pchan = NULL; | *r_pchan = NULL; | ||||
| ▲ Show 20 Lines • Show All 662 Lines • ▼ Show 20 Lines | if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) { | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int type) | static bConstraint *edit_constraint_property_get(bContext *C, wmOperator *op, Object *ob, int type) | ||||
| { | { | ||||
| char constraint_name[MAX_NAME]; | char constraint_name[MAX_NAME]; | ||||
| int owner = RNA_enum_get(op->ptr, "owner"); | int owner = RNA_enum_get(op->ptr, "owner"); | ||||
| bConstraint *con; | bConstraint *con; | ||||
| ListBase *list = NULL; | ListBase *list = NULL; | ||||
| RNA_string_get(op->ptr, "constraint", constraint_name); | RNA_string_get(op->ptr, "constraint", constraint_name); | ||||
| if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { | ||||
| list = &ob->constraints; | list = ED_object_constraint_list_from_context_no_layer_check(C, false); | ||||
| } | } | ||||
| else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { | ||||
| bPoseChannel *pchan = BKE_pose_channel_active(ob); | list = ED_object_constraint_list_from_context_no_layer_check(C, true); | ||||
| if (pchan) { | |||||
| list = &pchan->constraints; | |||||
| } | |||||
| else { | |||||
| #if 0 | |||||
| if (G.debug & G_DEBUG) { | |||||
| printf("edit_constraint_property_get: No active bone for object '%s'\n", | |||||
| (ob) ? ob->id.name + 2 : "<None>"); | |||||
| } | |||||
| #endif | |||||
| return NULL; | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| #if 0 | #if 0 | ||||
| if (G.debug & G_DEBUG) { | if (G.debug & G_DEBUG) { | ||||
| printf("edit_constraint_property_get: defaulting to getting list in the standard way\n"); | printf("edit_constraint_property_get: defaulting to getting list in the standard way\n"); | ||||
| } | } | ||||
| #endif | #endif | ||||
| list = ED_object_constraint_list_from_context(ob); | list = ED_object_constraint_list_from_context(ob); | ||||
| Show All 20 Lines | |||||
| * | * | ||||
| * For Stretch-To & Limit-Distance constraints. | * For Stretch-To & Limit-Distance constraints. | ||||
| * \{ */ | * \{ */ | ||||
| static int stretchto_reset_exec(bContext *C, wmOperator *op) | static int stretchto_reset_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_STRETCHTO); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_STRETCHTO); | ||||
| bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : NULL; | bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : NULL; | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* just set original length to 0.0, which will cause a reset on next recalc */ | /* just set original length to 0.0, which will cause a reset on next recalc */ | ||||
| Show All 38 Lines | |||||
| * | * | ||||
| * For Limit-Distance constraint. | * For Limit-Distance constraint. | ||||
| * \{ */ | * \{ */ | ||||
| static int limitdistance_reset_exec(bContext *C, wmOperator *op) | static int limitdistance_reset_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_DISTLIMIT); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_DISTLIMIT); | ||||
| bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : NULL; | bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : NULL; | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* just set original length to 0.0, which will cause a reset on next recalc */ | /* just set original length to 0.0, which will cause a reset on next recalc */ | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | static void force_evaluation_if_constraint_disabled(bContext *C, Object *ob, bConstraint *con) | ||||
| con->flag = flag_backup; | con->flag = flag_backup; | ||||
| } | } | ||||
| /* ChildOf Constraint - set inverse callback */ | /* ChildOf Constraint - set inverse callback */ | ||||
| static int childof_set_inverse_exec(bContext *C, wmOperator *op) | static int childof_set_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_CHILDOF); | ||||
| bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | ||||
| BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 37 Lines | void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot) | ||||
| edit_constraint_properties(ot); | edit_constraint_properties(ot); | ||||
| } | } | ||||
| /* ChildOf Constraint - clear inverse callback */ | /* ChildOf Constraint - clear inverse callback */ | ||||
| static int childof_clear_inverse_exec(bContext *C, wmOperator *op) | static int childof_clear_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_CHILDOF); | ||||
| bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found"); | BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* simply clear the matrix */ | /* simply clear the matrix */ | ||||
| Show All 37 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Follow Path Constraint (Auto Animate Path Operator) | /** \name Follow Path Constraint (Auto Animate Path Operator) | ||||
| * \{ */ | * \{ */ | ||||
| static int followpath_path_animate_exec(bContext *C, wmOperator *op) | static int followpath_path_animate_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_FOLLOWPATH); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_FOLLOWPATH); | ||||
| bFollowPathConstraint *data = (con) ? (bFollowPathConstraint *)con->data : NULL; | bFollowPathConstraint *data = (con) ? (bFollowPathConstraint *)con->data : NULL; | ||||
| bAction *act = NULL; | bAction *act = NULL; | ||||
| FCurve *fcu = NULL; | FCurve *fcu = NULL; | ||||
| int sfra = RNA_int_get(op->ptr, "frame_start"); | int sfra = RNA_int_get(op->ptr, "frame_start"); | ||||
| int len = RNA_int_get(op->ptr, "length"); | int len = RNA_int_get(op->ptr, "length"); | ||||
| float standardRange = 1.0; | float standardRange = 1.0; | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Object Solver Constraint (Set Inverse Operator) | /** \name Object Solver Constraint (Set Inverse Operator) | ||||
| * \{ */ | * \{ */ | ||||
| static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) | static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | ||||
| bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | ||||
| /* despite 3 layers of checks, we may still not be able to find a constraint */ | /* despite 3 layers of checks, we may still not be able to find a constraint */ | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| printf("DEBUG: ObjectSolver Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | printf("DEBUG: ObjectSolver Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>"); | ||||
| BKE_report( | BKE_report( | ||||
| op->reports, RPT_ERROR, "Could not find constraint data for ObjectSolver Set Inverse"); | op->reports, RPT_ERROR, "Could not find constraint data for ObjectSolver Set Inverse"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Object Solver Constraint (Clear Inverse Operator) | /** \name Object Solver Constraint (Clear Inverse Operator) | ||||
| * \{ */ | * \{ */ | ||||
| static int objectsolver_clear_inverse_exec(bContext *C, wmOperator *op) | static int objectsolver_clear_inverse_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); | ||||
| bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; | ||||
| if (data == NULL) { | if (data == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found"); | BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* simply clear the matrix */ | /* simply clear the matrix */ | ||||
| ▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Delete Constraint Operator | /** \name Delete Constraint Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int constraint_delete_exec(bContext *C, wmOperator *op) | static int constraint_delete_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(C, op, ob, 0); | ||||
| ListBase *lb = ED_object_constraint_list_from_constraint(ob, con, NULL); | ListBase *lb = ED_object_constraint_list_from_constraint(ob, con, NULL); | ||||
| /* Store name temporarily for report. */ | /* Store name temporarily for report. */ | ||||
| char name[MAX_NAME]; | char name[MAX_NAME]; | ||||
| strcpy(name, con->name); | strcpy(name, con->name); | ||||
| /* free the constraint */ | /* free the constraint */ | ||||
| if (BKE_constraint_remove_ex(lb, ob, con, true)) { | if (BKE_constraint_remove_ex(lb, ob, con, true)) { | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Move Down Constraint Operator | /** \name Move Down Constraint Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int constraint_move_down_exec(bContext *C, wmOperator *op) | static int constraint_move_down_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(C, op, ob, 0); | ||||
| if (con && con->next) { | if (con && con->next) { | ||||
| ListBase *conlist = ED_object_constraint_list_from_constraint(ob, con, NULL); | ListBase *conlist = ED_object_constraint_list_from_constraint(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 */ | ||||
| BLI_remlink(conlist, con); | BLI_remlink(conlist, con); | ||||
| BLI_insertlinkafter(conlist, nextCon, con); | BLI_insertlinkafter(conlist, nextCon, con); | ||||
| Show All 38 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Move Up Constraint Operator | /** \name Move Up Constraint Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int constraint_move_up_exec(bContext *C, wmOperator *op) | static int constraint_move_up_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(C, op, ob, 0); | ||||
| if (con && con->prev) { | if (con && con->prev) { | ||||
| ListBase *conlist = ED_object_constraint_list_from_constraint(ob, con, NULL); | ListBase *conlist = ED_object_constraint_list_from_constraint(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 */ | ||||
| BLI_remlink(conlist, con); | BLI_remlink(conlist, con); | ||||
| BLI_insertlinkbefore(conlist, prevCon, con); | BLI_insertlinkbefore(conlist, prevCon, con); | ||||
| Show All 36 Lines | |||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Move Constraint To Index Operator | /** \name Move Constraint To Index Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int constraint_move_to_index_exec(bContext *C, wmOperator *op) | static int constraint_move_to_index_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | Object *ob = ED_object_active_context(C); | ||||
| bConstraint *con = edit_constraint_property_get(op, ob, 0); | bConstraint *con = edit_constraint_property_get(C, op, ob, 0); | ||||
| int new_index = RNA_int_get(op->ptr, "index"); | int new_index = RNA_int_get(op->ptr, "index"); | ||||
| if (new_index < 0) { | if (new_index < 0) { | ||||
| new_index = 0; | new_index = 0; | ||||
| } | } | ||||
| if (con) { | if (con) { | ||||
| ListBase *conlist = ED_object_constraint_list_from_constraint(ob, con, NULL); | ListBase *conlist = ED_object_constraint_list_from_constraint(ob, con, NULL); | ||||
| ▲ Show 20 Lines • Show All 838 Lines • Show Last 20 Lines | |||||
This sentence is missing a verb.