diff options
Diffstat (limited to 'source/blender/editors/object/object_relations.c')
-rw-r--r-- | source/blender/editors/object/object_relations.c | 216 |
1 files changed, 128 insertions, 88 deletions
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 52d6a7a7b8b..b8eebd161dc 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -41,6 +41,7 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_world_types.h" +#include "DNA_object_types.h" #include "BLI_math.h" #include "BLI_editVert.h" @@ -68,7 +69,6 @@ #include "BKE_sca.h" #include "BKE_scene.h" #include "BKE_texture.h" -#include "BKE_utildefines.h" #include "WM_api.h" #include "WM_types.h" @@ -97,6 +97,7 @@ static int vertex_parent_set_poll(bContext *C) static int vertex_parent_set_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); EditVert *eve; @@ -171,8 +172,8 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) else if(obedit->type==OB_LATTICE) { Lattice *lt= obedit->data; - a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw; - bp= lt->editlatt->def; + a= lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw; + bp= lt->editlatt->latt->def; while(a--) { if(bp->f1 & SELECT) { if(v1==0) v1= nr; @@ -193,7 +194,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob != obedit) { - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; par= obedit->parent; while(par) { @@ -230,7 +231,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_OBJECT, NULL); @@ -295,6 +296,7 @@ static int make_proxy_invoke (bContext *C, wmOperator *op, wmEvent *evt) static int make_proxy_exec (bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Object *ob, *gob= CTX_data_active_object(C); GroupObject *go; Scene *scene= CTX_data_scene(C); @@ -338,8 +340,8 @@ static int make_proxy_exec (bContext *C, wmOperator *op) object_make_proxy(newob, ob, gob); /* depsgraph flushes are needed for the new data */ - DAG_scene_sort(scene); - DAG_id_flush_update(&newob->id, OB_RECALC); + DAG_scene_sort(bmain, scene); + DAG_id_flush_update(&newob->id, OB_RECALC_ALL); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, newob); } else { @@ -413,6 +415,8 @@ static EnumPropertyItem prop_clear_parent_types[] = { /* note, poll should check for editable scene */ static int parent_clear_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); + Scene *scene= CTX_data_scene(C); int type= RNA_enum_get(op->ptr, "type"); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { @@ -427,12 +431,12 @@ static int parent_clear_exec(bContext *C, wmOperator *op) else if(type == 2) unit_m4(ob->parentinv); - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; } CTX_DATA_END; - DAG_scene_sort(CTX_data_scene(C)); - DAG_ids_flush_update(0); + DAG_scene_sort(bmain, scene); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -517,6 +521,7 @@ void ED_object_parent(Object *ob, Object *par, int type, const char *substr) static int parent_set_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *par= CTX_data_active_object(C); bPoseChannel *pchan= NULL; @@ -594,15 +599,15 @@ static int parent_set_exec(bContext *C, wmOperator *op) switch (partype) { case PAR_CURVE: /* curve deform */ - md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Curve); + md= ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, eModifierType_Curve); ((CurveModifierData *)md)->object= par; break; case PAR_LATTICE: /* lattice deform */ - md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Lattice); + md= ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, eModifierType_Lattice); ((LatticeModifierData *)md)->object= par; break; default: /* armature deform */ - md= ED_object_modifier_add(op->reports, scene, ob, NULL, eModifierType_Armature); + md= ED_object_modifier_add(op->reports, bmain, scene, ob, NULL, eModifierType_Armature); ((ArmatureModifierData *)md)->object= par; break; } @@ -657,8 +662,8 @@ static int parent_set_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_scene_sort(scene); - DAG_ids_flush_update(0); + DAG_scene_sort(bmain, scene); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -719,6 +724,7 @@ void OBJECT_OT_parent_set(wmOperatorType *ot) static int parent_noinv_set_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Object *par= CTX_data_active_object(C); par->recalc |= OB_RECALC_OB; @@ -745,8 +751,8 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_scene_sort(CTX_data_scene(C)); - DAG_ids_flush_update(0); + DAG_scene_sort(bmain, CTX_data_scene(C)); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -772,6 +778,7 @@ void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot) static int object_slow_parent_clear_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { @@ -786,7 +793,7 @@ static int object_slow_parent_clear_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_ids_flush_update(0); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_SCENE, scene); return OPERATOR_FINISHED; @@ -813,6 +820,7 @@ void OBJECT_OT_slow_parent_clear(wmOperatorType *ot) static int object_slow_parent_set_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { @@ -824,7 +832,7 @@ static int object_slow_parent_set_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_ids_flush_update(0); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_SCENE, scene); return OPERATOR_FINISHED; @@ -858,6 +866,8 @@ static EnumPropertyItem prop_clear_track_types[] = { /* note, poll should check for editable scene */ static int object_track_clear_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); + Scene *scene= CTX_data_scene(C); int type= RNA_enum_get(op->ptr, "type"); if(CTX_data_edit_object(C)) { @@ -869,7 +879,7 @@ static int object_track_clear_exec(bContext *C, wmOperator *op) /* remove track-object for old track */ ob->track= NULL; - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; /* also remove all tracking constraints */ for (con= ob->constraints.last; con; con= pcon) { @@ -883,8 +893,8 @@ static int object_track_clear_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_ids_flush_update(0); - DAG_scene_sort(CTX_data_scene(C)); + DAG_ids_flush_update(bmain, 0); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -920,6 +930,7 @@ static EnumPropertyItem prop_make_track_types[] = { static int track_set_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *obact= CTX_data_active_object(C); @@ -935,7 +946,7 @@ static int track_set_exec(bContext *C, wmOperator *op) data = con->data; data->tar = obact; - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; /* Lamp and Camera track differently by default */ if (ob->type == OB_LAMP || ob->type == OB_CAMERA) @@ -954,7 +965,7 @@ static int track_set_exec(bContext *C, wmOperator *op) data = con->data; data->tar = obact; - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; /* Lamp and Camera track differently by default */ if (ob->type == OB_LAMP || ob->type == OB_CAMERA) { @@ -975,7 +986,7 @@ static int track_set_exec(bContext *C, wmOperator *op) data = con->data; data->tar = obact; - ob->recalc |= OB_RECALC; + ob->recalc |= OB_RECALC_ALL; /* Lamp and Camera track differently by default */ if (ob->type == OB_LAMP || ob->type == OB_CAMERA) { @@ -987,8 +998,8 @@ static int track_set_exec(bContext *C, wmOperator *op) CTX_DATA_END; } - DAG_scene_sort(scene); - DAG_ids_flush_update(0); + DAG_scene_sort(bmain, scene); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); return OPERATOR_FINISHED; @@ -1021,7 +1032,7 @@ static unsigned int move_to_layer_init(bContext *C, wmOperator *op) int values[20], a; unsigned int lay= 0; - if(!RNA_property_is_set(op->ptr, "layer")) { + if(!RNA_property_is_set(op->ptr, "layers")) { CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { lay |= base->lay; } @@ -1030,10 +1041,10 @@ static unsigned int move_to_layer_init(bContext *C, wmOperator *op) for(a=0; a<20; a++) values[a]= (lay & (1<<a)); - RNA_boolean_set_array(op->ptr, "layer", values); + RNA_boolean_set_array(op->ptr, "layers", values); } else { - RNA_boolean_get_array(op->ptr, "layer", values); + RNA_boolean_get_array(op->ptr, "layers", values); for(a=0; a<20; a++) if(values[a]) @@ -1057,6 +1068,7 @@ static int move_to_layer_invoke(bContext *C, wmOperator *op, wmEvent *event) static int move_to_layer_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); View3D *v3d= CTX_wm_view3d(C); unsigned int lay, local; @@ -1097,7 +1109,7 @@ static int move_to_layer_exec(bContext *C, wmOperator *op) /* warning, active object may be hidden now */ WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_DRAW, scene); /* is NC_SCENE needed ? */ - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); return OPERATOR_FINISHED; } @@ -1118,15 +1130,15 @@ void OBJECT_OT_move_to_layer(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - RNA_def_boolean_layer_member(ot->srna, "layer", 20, NULL, "Layer", ""); + RNA_def_boolean_layer_member(ot->srna, "layers", 20, NULL, "Layer", ""); } /************************** Link to Scene Operator *****************************/ -void link_to_scene(unsigned short nr) +void link_to_scene(Main *bmain, unsigned short nr) { #if 0 - Scene *sce= (Scene*) BLI_findlink(&G.main->scene, G.curscreen->scenenr-1); + Scene *sce= (Scene*) BLI_findlink(&bmain->scene, G.curscreen->scenenr-1); Base *base, *nbase; if(sce==0) return; @@ -1146,7 +1158,8 @@ void link_to_scene(unsigned short nr) static int make_links_scene_exec(bContext *C, wmOperator *op) { - Scene *scene_to= BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "type")); + Main *bmain= CTX_data_main(C); + Scene *scene_to= BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene")); if(scene_to==NULL) { BKE_report(op->reports, RPT_ERROR, "Scene not found"); @@ -1174,7 +1187,7 @@ static int make_links_scene_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_ids_flush_update(0); + DAG_ids_flush_update(bmain, 0); /* one day multiple scenes will be visible, then we should have some update function for them */ return OPERATOR_FINISHED; @@ -1188,8 +1201,33 @@ enum { MAKE_LINKS_MODIFIERS }; +/* Return 1 if make link data is allow, zero otherwise */ +static int allow_make_links_data(int ev, Object *ob, Object *obt) +{ + switch(ev) { + case MAKE_LINKS_OBDATA: + if (ob->type == obt->type && ob->type != OB_EMPTY) + return 1; + break; + case MAKE_LINKS_MATERIALS: + if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL) && + ELEM5(obt->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_MBALL)) + return 1; + break; + case MAKE_LINKS_ANIMDATA: + case MAKE_LINKS_DUPLIGROUP: + return 1; + case MAKE_LINKS_MODIFIERS: + if (ob->type != OB_EMPTY && obt->type != OB_EMPTY) + return 1; + break; + } + return 0; +} + static int make_links_data_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); int event = RNA_int_get(op->ptr, "type"); Object *ob; ID *id; @@ -1199,49 +1237,50 @@ static int make_links_data_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN(C, Object*, obt, selected_editable_objects) { if(ob != obt) { - switch(event) { - case MAKE_LINKS_OBDATA: /* obdata */ - id= obt->data; - id->us--; + if (allow_make_links_data(event, ob, obt)) { + switch(event) { + case MAKE_LINKS_OBDATA: /* obdata */ + id= obt->data; + id->us--; - id= ob->data; - id_us_plus(id); - obt->data= id; + id= ob->data; + id_us_plus(id); + obt->data= id; - /* if amount of material indices changed: */ - test_object_materials(obt->data); + /* if amount of material indices changed: */ + test_object_materials(obt->data); - obt->recalc |= OB_RECALC_DATA; - break; - case MAKE_LINKS_MATERIALS: - /* new approach, using functions from kernel */ - for(a=0; a<ob->totcol; a++) { - Material *ma= give_current_material(ob, a+1); - assign_material(obt, ma, a+1); /* also works with ma==NULL */ - } - break; - case MAKE_LINKS_ANIMDATA: - BKE_copy_animdata_id((ID *)obt, (ID *)ob); - BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data); - break; - case MAKE_LINKS_DUPLIGROUP: - if(ob->dup_group) ob->dup_group->id.us--; - obt->dup_group= ob->dup_group; - if(obt->dup_group) { - id_us_plus((ID *)obt->dup_group); - obt->transflag |= OB_DUPLIGROUP; + obt->recalc |= OB_RECALC_DATA; + break; + case MAKE_LINKS_MATERIALS: + /* new approach, using functions from kernel */ + for(a=0; a<ob->totcol; a++) { + Material *ma= give_current_material(ob, a+1); + assign_material(obt, ma, a+1); /* also works with ma==NULL */ + } + break; + case MAKE_LINKS_ANIMDATA: + BKE_copy_animdata_id((ID *)obt, (ID *)ob); + BKE_copy_animdata_id((ID *)obt->data, (ID *)ob->data); + break; + case MAKE_LINKS_DUPLIGROUP: + obt->dup_group= ob->dup_group; + if(obt->dup_group) { + id_lib_extern(&obt->dup_group->id); + obt->transflag |= OB_DUPLIGROUP; + } + break; + case MAKE_LINKS_MODIFIERS: + object_link_modifiers(obt, ob); + obt->recalc |= OB_RECALC_ALL; + break; } - break; - case MAKE_LINKS_MODIFIERS: - object_link_modifiers(obt, ob); - obt->recalc |= OB_RECALC; - break; } } } CTX_DATA_END; - DAG_ids_flush_update(0); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C)); return OPERATOR_FINISHED; } @@ -1264,8 +1303,9 @@ void OBJECT_OT_make_links_scene(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, 0, "Type", ""); - RNA_def_enum_funcs(prop, RNA_scene_itemf); + prop= RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", ""); + RNA_def_enum_funcs(prop, RNA_scene_local_itemf); + ot->prop= prop; } void OBJECT_OT_make_links_data(wmOperatorType *ot) @@ -1370,7 +1410,7 @@ void new_id_matar(Material **matar, int totcol) } } -void single_obdata_users(Scene *scene, int flag) +void single_obdata_users(Main *bmain, Scene *scene, int flag) { Object *ob; Lamp *la; @@ -1486,7 +1526,7 @@ void single_obdata_users(Scene *scene, int flag) } } - me= G.main->mesh.first; + me= bmain->mesh.first; while(me) { ID_NEW(me->texcomesh); me= me->id.next; @@ -1584,10 +1624,9 @@ void do_single_tex_user(Tex **from) } } -void single_tex_users_expand() +void single_tex_users_expand(Main *bmain) { /* only when 'parent' blocks are LIB_NEW */ - Main *bmain= G.main; Material *ma; Lamp *la; World *wo; @@ -1624,10 +1663,9 @@ void single_tex_users_expand() } } -static void single_mat_users_expand(void) +static void single_mat_users_expand(Main *bmain) { /* only when 'parent' blocks are LIB_NEW */ - Main *bmain= G.main; Object *ob; Mesh *me; Curve *cu; @@ -1660,14 +1698,14 @@ static void single_mat_users_expand(void) } /* used for copying scenes */ -void ED_object_single_users(Scene *scene, int full) +void ED_object_single_users(Main *bmain, Scene *scene, int full) { single_object_users(scene, NULL, 0); if(full) { - single_obdata_users(scene, 0); - single_mat_users_expand(); - single_tex_users_expand(); + single_obdata_users(bmain, scene, 0); + single_mat_users_expand(bmain); + single_tex_users_expand(bmain); } clear_id_newpoins(); @@ -1710,21 +1748,21 @@ static int make_local_exec(bContext *C, wmOperator *op) clear_id_newpoins(); - CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { + CTX_DATA_BEGIN(C, Object*, ob, selected_objects) { if(ob->id.lib) id_make_local(&ob->id, 0); } CTX_DATA_END; /* maybe object pointers */ - CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { + CTX_DATA_BEGIN(C, Object*, ob, selected_objects) { if(ob->id.lib==NULL) { ID_NEW(ob->parent); } } CTX_DATA_END; - CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { + CTX_DATA_BEGIN(C, Object*, ob, selected_objects) { id= ob->data; if(id && mode>1) { @@ -1742,7 +1780,7 @@ static int make_local_exec(bContext *C, wmOperator *op) CTX_DATA_END; if(mode>1) { - CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { + CTX_DATA_BEGIN(C, Object*, ob, selected_objects) { if(ob->type==OB_LAMP) { la= ob->data; @@ -1802,6 +1840,7 @@ void OBJECT_OT_make_local(wmOperatorType *ot) static int make_single_user_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); View3D *v3d= CTX_wm_view3d(C); /* ok if this is NULL */ int flag= RNA_enum_get(op->ptr, "type"); /* 0==ALL, SELECTED==selected objecs */ @@ -1810,7 +1849,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op) single_object_users(scene, v3d, flag); if(RNA_boolean_get(op->ptr, "obdata")) - single_obdata_users(scene, flag); + single_obdata_users(bmain, scene, flag); if(RNA_boolean_get(op->ptr, "material")) single_mat_users(scene, flag, FALSE); @@ -1859,6 +1898,7 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot) static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *event) { + Main *bmain= CTX_data_main(C); Base *base= ED_view3d_give_base_under_cursor(C, event->mval); Material *ma; char name[32]; @@ -1870,7 +1910,7 @@ static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *even assign_material(base->object, ma, 1); - DAG_ids_flush_update(0); + DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C)); return OPERATOR_FINISHED; |