de-duplicate parent loop checking function
This commit is contained in:
parent
68dd398063
commit
ce8f64d9f9
|
@ -120,6 +120,8 @@ void BKE_scene_foreach_display_point(
|
|||
const short flag,
|
||||
void (*func_cb)(const float[3], void *), void *user_data);
|
||||
|
||||
int BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob);
|
||||
|
||||
void solve_tracking (struct Object *ob, float targetmat[][4]);
|
||||
int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]);
|
||||
|
||||
|
|
|
@ -2473,6 +2473,14 @@ void object_tfm_restore(Object *ob, void *obtfm_pt)
|
|||
copy_m4_m4(ob->imat, obtfm->imat);
|
||||
}
|
||||
|
||||
int BKE_object_parent_loop_check(const Object *par, const Object *ob)
|
||||
{
|
||||
/* test if 'ob' is a parent somewhere in par's parents */
|
||||
if(par == NULL) return 0;
|
||||
if(ob == par) return 1;
|
||||
return BKE_object_parent_loop_check(par->parent, ob);
|
||||
}
|
||||
|
||||
/* proxy rule: lib_object->proxy_from == the one we borrow from, only set temporal and cleared here */
|
||||
/* local_object->proxy == pointer to library object, saved in files and read */
|
||||
|
||||
|
|
|
@ -512,19 +512,9 @@ static EnumPropertyItem prop_make_parent_types[] = {
|
|||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static int test_parent_loop(Object *par, Object *ob)
|
||||
{
|
||||
/* test if 'ob' is a parent somewhere in par's parents */
|
||||
|
||||
if(par == NULL) return 0;
|
||||
if(ob == par) return 1;
|
||||
|
||||
return test_parent_loop(par->parent, ob);
|
||||
}
|
||||
|
||||
void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
|
||||
{
|
||||
if(!par || test_parent_loop(par, ob)) {
|
||||
if (!par || BKE_object_parent_loop_check(par, ob)) {
|
||||
ob->parent= NULL;
|
||||
ob->partype= PAROBJECT;
|
||||
ob->parsubstr[0]= 0;
|
||||
|
@ -593,7 +583,7 @@ static int parent_set_exec(bContext *C, wmOperator *op)
|
|||
|
||||
if(ob!=par) {
|
||||
|
||||
if( test_parent_loop(par, ob) ) {
|
||||
if (BKE_object_parent_loop_check(par, ob)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Loop in parents");
|
||||
}
|
||||
else {
|
||||
|
@ -766,7 +756,7 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op)
|
|||
/* context iterator */
|
||||
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
|
||||
if (ob != par) {
|
||||
if (test_parent_loop(par, ob)) {
|
||||
if (BKE_object_parent_loop_check(par, ob)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Loop in parents");
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#include "BKE_mesh.h"
|
||||
#include "BKE_screen.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_object.h"
|
||||
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
|
@ -1105,14 +1106,6 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob)
|
|||
}
|
||||
}
|
||||
|
||||
/* test if 'ob' is a parent somewhere in par's parents */
|
||||
static int test_parent_loop(Object *par, Object *ob)
|
||||
{
|
||||
if(par == NULL) return 0;
|
||||
if(ob == par) return 1;
|
||||
return test_parent_loop(par->parent, ob);
|
||||
}
|
||||
|
||||
static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event)
|
||||
{
|
||||
Main *bmain= CTX_data_main(C);
|
||||
|
@ -1144,7 +1137,7 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
|
|||
/* note; this case also used for parbone */
|
||||
case B_OBJECTPANELPARENT:
|
||||
if(ob) {
|
||||
if(ob->id.lib || test_parent_loop(ob->parent, ob) )
|
||||
if (ob->id.lib || BKE_object_parent_loop_check(ob->parent, ob))
|
||||
ob->parent= NULL;
|
||||
else {
|
||||
DAG_scene_sort(bmain, scene);
|
||||
|
|
Loading…
Reference in New Issue