From 87b974caa1e2b780c8031d67a42488039036c489 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 10 Jul 2016 14:52:00 +0200 Subject: Cleanup/Refactor: pass Main pointer to all ID copy functions. Also allows us to get rid of a few _copy_ex() versions... --- source/blender/blenkernel/BKE_action.h | 2 +- source/blender/blenkernel/BKE_armature.h | 2 +- source/blender/blenkernel/BKE_brush.h | 2 +- source/blender/blenkernel/BKE_camera.h | 2 +- source/blender/blenkernel/BKE_curve.h | 3 +- source/blender/blenkernel/BKE_gpencil.h | 3 +- source/blender/blenkernel/BKE_group.h | 2 +- source/blender/blenkernel/BKE_key.h | 3 +- source/blender/blenkernel/BKE_lamp.h | 2 +- source/blender/blenkernel/BKE_lattice.h | 3 +- source/blender/blenkernel/BKE_library.h | 5 +- source/blender/blenkernel/BKE_mask.h | 2 +- source/blender/blenkernel/BKE_material.h | 2 +- source/blender/blenkernel/BKE_mball.h | 3 +- source/blender/blenkernel/BKE_mesh.h | 3 +- source/blender/blenkernel/BKE_node.h | 2 +- source/blender/blenkernel/BKE_object.h | 2 +- source/blender/blenkernel/BKE_particle.h | 2 +- source/blender/blenkernel/BKE_scene.h | 2 +- source/blender/blenkernel/BKE_speaker.h | 2 +- source/blender/blenkernel/BKE_texture.h | 2 +- source/blender/blenkernel/BKE_world.h | 2 +- source/blender/blenkernel/intern/action.c | 8 +-- source/blender/blenkernel/intern/anim_sys.c | 12 ++--- source/blender/blenkernel/intern/armature.c | 8 +-- source/blender/blenkernel/intern/brush.c | 11 ++-- source/blender/blenkernel/intern/camera.c | 8 +-- source/blender/blenkernel/intern/curve.c | 13 ++--- source/blender/blenkernel/intern/gpencil.c | 5 +- source/blender/blenkernel/intern/group.c | 6 +-- source/blender/blenkernel/intern/key.c | 9 +--- source/blender/blenkernel/intern/lamp.c | 10 ++-- source/blender/blenkernel/intern/lattice.c | 13 ++--- source/blender/blenkernel/intern/library.c | 61 ++++++++++------------ source/blender/blenkernel/intern/linestyle.c | 2 +- source/blender/blenkernel/intern/mask.c | 6 +-- source/blender/blenkernel/intern/material.c | 12 ++--- source/blender/blenkernel/intern/mball.c | 11 ++-- source/blender/blenkernel/intern/mesh.c | 17 +++--- source/blender/blenkernel/intern/nla.c | 2 +- source/blender/blenkernel/intern/node.c | 10 ++-- source/blender/blenkernel/intern/object.c | 8 +-- source/blender/blenkernel/intern/particle.c | 8 +-- source/blender/blenkernel/intern/scene.c | 16 +++--- source/blender/blenkernel/intern/speaker.c | 6 +-- source/blender/blenkernel/intern/text.c | 2 +- source/blender/blenkernel/intern/texture.c | 10 ++-- source/blender/blenkernel/intern/world.c | 10 ++-- source/blender/collada/DocumentImporter.cpp | 2 +- source/blender/editors/curve/editcurve.c | 2 +- source/blender/editors/gpencil/gpencil_undo.c | 4 +- .../editors/interface/interface_templates.c | 2 +- source/blender/editors/mesh/meshtools.c | 2 +- source/blender/editors/object/object_add.c | 52 +++++++++--------- source/blender/editors/object/object_relations.c | 50 +++++++++--------- source/blender/editors/physics/particle_object.c | 2 +- source/blender/editors/render/render_shading.c | 6 +-- source/blender/editors/screen/screen_ops.c | 2 +- source/blender/editors/sculpt_paint/paint_ops.c | 2 +- source/blender/editors/space_action/action_data.c | 2 +- source/blender/editors/space_nla/nla_edit.c | 6 ++- source/blender/editors/space_node/node_group.c | 2 +- source/blender/makesrna/intern/rna_ID.c | 5 +- 63 files changed, 226 insertions(+), 252 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index cb282b46bec..07fa6ac71f6 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -58,7 +58,7 @@ extern "C" { struct bAction *add_empty_action(struct Main *bmain, const char name[]); /* Allocate a copy of the given Action and all its data */ -struct bAction *BKE_action_copy(struct bAction *src); +struct bAction *BKE_action_copy(struct Main *bmain, struct bAction *src); /* Deallocate all of the Action's data, but not the Action itself */ void BKE_action_free(struct bAction *act); diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index cc082c084ce..8004724ddf3 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -77,7 +77,7 @@ int BKE_armature_bonelist_count(struct ListBase *lb); void BKE_armature_bonelist_free(struct ListBase *lb); void BKE_armature_free(struct bArmature *arm); void BKE_armature_make_local(struct bArmature *arm); -struct bArmature *BKE_armature_copy(struct bArmature *arm); +struct bArmature *BKE_armature_copy(struct Main *bmain, struct bArmature *arm); /* Bounding box. */ struct BoundBox *BKE_armature_boundbox_get(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index c663458963c..309785783ec 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -44,7 +44,7 @@ void BKE_brush_system_exit(void); void BKE_brush_init(struct Brush *brush); struct Brush *BKE_brush_add(struct Main *bmain, const char *name, short ob_mode); struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode); -struct Brush *BKE_brush_copy(struct Brush *brush); +struct Brush *BKE_brush_copy(struct Main *bmain, struct Brush *brush); void BKE_brush_make_local(struct Brush *brush); void BKE_brush_unlink(struct Main *bmain, struct Brush *brush); void BKE_brush_free(struct Brush *brush); diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h index d13a711c589..f78df88c77a 100644 --- a/source/blender/blenkernel/BKE_camera.h +++ b/source/blender/blenkernel/BKE_camera.h @@ -52,7 +52,7 @@ struct GPUFXSettings; void BKE_camera_init(struct Camera *cam); void *BKE_camera_add(struct Main *bmain, const char *name); -struct Camera *BKE_camera_copy(struct Camera *cam); +struct Camera *BKE_camera_copy(struct Main *bmain, struct Camera *cam); void BKE_camera_make_local(struct Camera *cam); void BKE_camera_free(struct Camera *ca); diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index ef3d14ce16b..89dbe246910 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -70,8 +70,7 @@ void BKE_curve_free(struct Curve *cu); void BKE_curve_editfont_free(struct Curve *cu); void BKE_curve_init(struct Curve *cu); struct Curve *BKE_curve_add(struct Main *bmain, const char *name, int type); -struct Curve *BKE_curve_copy(struct Curve *cu); -struct Curve *BKE_curve_copy_ex(struct Main *bmain, struct Curve *cu); +struct Curve *BKE_curve_copy(struct Main *bmain, struct Curve *cu); void BKE_curve_make_local(struct Main *bmain, struct Curve *cu); short BKE_curve_type_get(struct Curve *cu); void BKE_curve_type_test(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 24e330d927f..6159531d8bd 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -36,6 +36,7 @@ struct bGPdata; struct bGPDlayer; struct bGPDframe; struct bGPDstroke; +struct Main; /* ------------ Grease-Pencil API ------------------ */ @@ -53,7 +54,7 @@ struct bGPdata *gpencil_data_addnew(const char name[]); struct bGPDframe *gpencil_frame_duplicate(struct bGPDframe *src); struct bGPDlayer *gpencil_layer_duplicate(struct bGPDlayer *src); -struct bGPdata *gpencil_data_duplicate(struct bGPdata *gpd, bool internal_copy); +struct bGPdata *gpencil_data_duplicate(struct Main *bmain, struct bGPdata *gpd, bool internal_copy); void gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf); diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index ae6e52b613b..4f2c89070cb 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -42,7 +42,7 @@ struct Scene; void BKE_group_free(struct Group *group); struct Group *BKE_group_add(struct Main *bmain, const char *name); -struct Group *BKE_group_copy(struct Group *group); +struct Group *BKE_group_copy(struct Main *bmain, struct Group *group); bool BKE_group_object_add(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); bool BKE_group_object_unlink(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base); struct Group *BKE_group_object_find(struct Group *group, struct Object *ob); diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index 86484db3809..f30f9eac4e8 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -51,8 +51,7 @@ extern "C" { void BKE_key_free(struct Key *sc); void BKE_key_free_nolib(struct Key *key); struct Key *BKE_key_add(struct ID *id); -struct Key *BKE_key_copy(struct Key *key); -struct Key *BKE_key_copy_ex(struct Main *bmain, struct Key *key); +struct Key *BKE_key_copy(struct Main *bmain, struct Key *key); struct Key *BKE_key_copy_nolib(struct Key *key); void BKE_key_make_local(struct Main *bmain, struct Key *key); void BKE_key_sort(struct Key *key); diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h index d830c19651f..3bdef8eca48 100644 --- a/source/blender/blenkernel/BKE_lamp.h +++ b/source/blender/blenkernel/BKE_lamp.h @@ -44,7 +44,7 @@ struct Scene; void BKE_lamp_init(struct Lamp *la); struct Lamp *BKE_lamp_add(struct Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT; -struct Lamp *BKE_lamp_copy(struct Lamp *la) ATTR_WARN_UNUSED_RESULT; +struct Lamp *BKE_lamp_copy(struct Main *bmain, struct Lamp *la) ATTR_WARN_UNUSED_RESULT; struct Lamp *localize_lamp(struct Lamp *la) ATTR_WARN_UNUSED_RESULT; void BKE_lamp_make_local(struct Lamp *la); void BKE_lamp_free(struct Lamp *la); diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index a82525225d5..606df9dcec8 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -47,8 +47,7 @@ struct MDeformVert; void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb); void BKE_lattice_init(struct Lattice *lt); struct Lattice *BKE_lattice_add(struct Main *bmain, const char *name); -struct Lattice *BKE_lattice_copy(struct Lattice *lt); -struct Lattice *BKE_lattice_copy_ex(struct Main *bmain, struct Lattice *lt); +struct Lattice *BKE_lattice_copy(struct Main *bmain, struct Lattice *lt); void BKE_lattice_free(struct Lattice *lt); void BKE_lattice_make_local(struct Main *bmain, struct Lattice *lt); void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du); diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 37937aa20b3..f3a02019064 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -52,9 +52,8 @@ struct PropertyRNA; void *BKE_libblock_alloc_notest(short type); void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void BKE_libblock_init_empty(struct ID *id); -void *BKE_libblock_copy_ex(struct Main *bmain, struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void *BKE_libblock_copy(struct Main *bmain, struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void *BKE_libblock_copy_nolib(struct ID *id, const bool do_action) ATTR_NONNULL(); -void *BKE_libblock_copy(struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); void BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const bool do_action); void BKE_libblock_relink(struct ID *id); void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL(); @@ -83,7 +82,7 @@ void id_fake_user_clear(struct ID *id); bool id_make_local(struct Main *bmain, struct ID *id, bool test); bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop); -bool id_copy(struct ID *id, struct ID **newid, bool test); +bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test); void id_sort_by_name(struct ListBase *lb, struct ID *id); bool new_id(struct ListBase *lb, struct ID *id, const char *name); diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index f3d12b5a8cc..97bfd0f3f07 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -123,7 +123,7 @@ void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point, const eMask /* general */ struct Mask *BKE_mask_new(struct Main *bmain, const char *name); struct Mask *BKE_mask_copy_nolib(struct Mask *mask); -struct Mask *BKE_mask_copy(struct Mask *mask); +struct Mask *BKE_mask_copy(struct Main *bmain, struct Mask *mask); void BKE_mask_free(struct Mask *mask); diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 539cf8a57d7..bcb2db759df 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -54,7 +54,7 @@ void BKE_material_init(struct Material *ma); void BKE_material_remap_object(struct Object *ob, const unsigned int *remap); void BKE_material_remap_object_calc(struct Object *ob_dst, struct Object *ob_src, short *remap_src_to_dst); struct Material *BKE_material_add(struct Main *bmain, const char *name); -struct Material *BKE_material_copy(struct Material *ma); +struct Material *BKE_material_copy(struct Main *bmain, struct Material *ma); struct Material *localize_material(struct Material *ma); struct Material *give_node_material(struct Material *ma); /* returns node material or self */ void BKE_material_make_local(struct Material *ma); diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index abb1259ca54..42704c1b2db 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -41,8 +41,7 @@ struct MetaElem; void BKE_mball_free(struct MetaBall *mb); void BKE_mball_init(struct MetaBall *mb); struct MetaBall *BKE_mball_add(struct Main *bmain, const char *name); -struct MetaBall *BKE_mball_copy(struct MetaBall *mb); -struct MetaBall *BKE_mball_copy_ex(struct Main *bmain, struct MetaBall *mb); +struct MetaBall *BKE_mball_copy(struct Main *bmain, struct MetaBall *mb); void BKE_mball_make_local(struct Main *bmain, struct MetaBall *mb); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 3d05af9a126..d3bb34d7a41 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -87,8 +87,7 @@ int BKE_mesh_edge_other_vert(const struct MEdge *e, int v); void BKE_mesh_free(struct Mesh *me); void BKE_mesh_init(struct Mesh *me); struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name); -struct Mesh *BKE_mesh_copy_ex(struct Main *bmain, struct Mesh *me); -struct Mesh *BKE_mesh_copy(struct Mesh *me); +struct Mesh *BKE_mesh_copy(struct Main *bmain, struct Mesh *me); void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd); void BKE_mesh_ensure_skin_customdata(struct Mesh *me); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index bf198c9b86b..c5d10441ebe 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -336,7 +336,7 @@ struct bNodeTree *ntreeAddTree(struct Main *bmain, const char *name, const char /* copy/free funcs, need to manage ID users */ void ntreeFreeTree(struct bNodeTree *ntree); struct bNodeTree *ntreeCopyTree_ex(struct bNodeTree *ntree, struct Main *bmain, const bool do_id_user); -struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree); +struct bNodeTree *ntreeCopyTree(struct Main *bmain, struct bNodeTree *ntree); void ntreeSwitchID_ex(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to, const bool do_id_user); void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); /* node->id user count */ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index a1f1bee2642..1f0dc5f1814 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -106,7 +106,7 @@ struct Object *BKE_object_lod_meshob_get(struct Object *ob, struct Scene *scene) struct Object *BKE_object_lod_matob_get(struct Object *ob, struct Scene *scene); struct Object *BKE_object_copy_ex(struct Main *bmain, struct Object *ob, bool copy_caches); -struct Object *BKE_object_copy(struct Object *ob); +struct Object *BKE_object_copy(struct Main *bmain, struct Object *ob); void BKE_object_make_local(struct Main *bmain, struct Object *ob); bool BKE_object_is_libdata(struct Object *ob); bool BKE_object_obdata_is_libdata(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 5daa94c4302..4f43037682a 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -323,7 +323,7 @@ struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct P struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name); void object_remove_particle_system(struct Scene *scene, struct Object *ob); struct ParticleSettings *psys_new_settings(const char *name, struct Main *main); -struct ParticleSettings *BKE_particlesettings_copy(struct ParticleSettings *part); +struct ParticleSettings *BKE_particlesettings_copy(struct Main *bmain, struct ParticleSettings *part); void BKE_particlesettings_make_local(struct ParticleSettings *part); void psys_reset(struct ParticleSystem *psys, int mode); diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index ccb7dc8e015..03af0b7d6c9 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -98,7 +98,7 @@ void BKE_scene_base_flag_from_objects(struct Scene *scene); void BKE_scene_set_background(struct Main *bmain, struct Scene *sce); struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name); -struct Scene *BKE_scene_copy(struct Scene *sce, int type); +struct Scene *BKE_scene_copy(struct Main *bmain, struct Scene *sce, int type); void BKE_scene_groups_relink(struct Scene *sce); struct Object *BKE_scene_camera_find(struct Scene *sc); diff --git a/source/blender/blenkernel/BKE_speaker.h b/source/blender/blenkernel/BKE_speaker.h index 5f30df1d6e3..1f633e9854b 100644 --- a/source/blender/blenkernel/BKE_speaker.h +++ b/source/blender/blenkernel/BKE_speaker.h @@ -33,7 +33,7 @@ struct Speaker; void BKE_speaker_init(struct Speaker *spk); void *BKE_speaker_add(struct Main *bmain, const char *name); -struct Speaker *BKE_speaker_copy(struct Speaker *spk); +struct Speaker *BKE_speaker_copy(struct Main *bmain, struct Speaker *spk); void BKE_speaker_make_local(struct Speaker *spk); void BKE_speaker_free(struct Speaker *spk); diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 95918b9ca0b..37bd25cf067 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -69,7 +69,7 @@ void colorband_update_sort(struct ColorBand *coba); void BKE_texture_free(struct Tex *tex); void BKE_texture_default(struct Tex *tex); -struct Tex *BKE_texture_copy(struct Tex *tex); +struct Tex *BKE_texture_copy(struct Main *bmain, struct Tex *tex); struct Tex *BKE_texture_add(struct Main *bmain, const char *name); struct Tex *BKE_texture_localize(struct Tex *tex); void BKE_texture_make_local(struct Tex *tex); diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index 0be61fe0229..197cebc423e 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -39,7 +39,7 @@ struct World; void BKE_world_free(struct World *sc); void BKE_world_init(struct World *wrld); struct World *add_world(struct Main *bmian, const char *name); -struct World *BKE_world_copy(struct World *wrld); +struct World *BKE_world_copy(struct Main *bmain, struct World *wrld); struct World *localize_world(struct World *wrld); void BKE_world_make_local(struct World *wrld); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 9d6b2a05681..5ac80ae1b7c 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -148,7 +148,7 @@ void BKE_action_make_local(bAction *act) id_clear_lib_data(bmain, &act->id); } else if (mlac.is_local && mlac.is_lib) { - mlac.act_new = BKE_action_copy(act); + mlac.act_new = BKE_action_copy(bmain, act); mlac.act_new->id.us = 0; BKE_id_lib_local_paths(bmain, act->id.lib, &mlac.act_new->id); @@ -176,7 +176,7 @@ void BKE_action_free(bAction *act) /* .................................. */ -bAction *BKE_action_copy(bAction *src) +bAction *BKE_action_copy(Main *bmain, bAction *src) { bAction *dst = NULL; bActionGroup *dgrp, *sgrp; @@ -184,7 +184,7 @@ bAction *BKE_action_copy(bAction *src) if (src == NULL) return NULL; - dst = BKE_libblock_copy(&src->id); + dst = BKE_libblock_copy(bmain, &src->id); /* duplicate the lists of groups and markers */ BLI_duplicatelist(&dst->groups, &src->groups); @@ -214,7 +214,7 @@ bAction *BKE_action_copy(bAction *src) } if (ID_IS_LINKED_DATABLOCK(src)) { - BKE_id_lib_local_paths(G.main, src->id.lib, &dst->id); + BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id); } return dst; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 10e7b019505..f478a19235c 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -268,8 +268,8 @@ AnimData *BKE_animdata_copy(AnimData *adt, const bool do_action) /* make a copy of action - at worst, user has to delete copies... */ if (do_action) { - dadt->action = BKE_action_copy(adt->action); - dadt->tmpact = BKE_action_copy(adt->tmpact); + dadt->action = BKE_action_copy(G.main, adt->action); + dadt->tmpact = BKE_action_copy(G.main, adt->tmpact); } else { id_us_plus((ID *)dadt->action); @@ -313,11 +313,11 @@ void BKE_animdata_copy_id_action(ID *id) if (adt) { if (adt->action) { id_us_min((ID *)adt->action); - adt->action = BKE_action_copy(adt->action); + adt->action = BKE_action_copy(G.main, adt->action); } if (adt->tmpact) { id_us_min((ID *)adt->tmpact); - adt->tmpact = BKE_action_copy(adt->tmpact); + adt->tmpact = BKE_action_copy(G.main, adt->tmpact); } } } @@ -341,8 +341,8 @@ void BKE_animdata_merge_copy(ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes a /* handle actions... */ if (action_mode == ADT_MERGECOPY_SRC_COPY) { /* make a copy of the actions */ - dst->action = BKE_action_copy(src->action); - dst->tmpact = BKE_action_copy(src->tmpact); + dst->action = BKE_action_copy(G.main, src->action); + dst->tmpact = BKE_action_copy(G.main, src->tmpact); } else if (action_mode == ADT_MERGECOPY_SRC_REF) { /* make a reference to it */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 572490f937c..4ed0196ba9d 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -168,7 +168,7 @@ void BKE_armature_make_local(bArmature *arm) id_clear_lib_data(bmain, &arm->id); } else if (is_local && is_lib) { - bArmature *arm_new = BKE_armature_copy(arm); + bArmature *arm_new = BKE_armature_copy(bmain, arm); arm_new->id.us = 0; /* Remap paths of new ID using old library as base. */ @@ -208,13 +208,13 @@ static void copy_bonechildren(Bone *newBone, Bone *oldBone, Bone *actBone, Bone } } -bArmature *BKE_armature_copy(bArmature *arm) +bArmature *BKE_armature_copy(Main *bmain, bArmature *arm) { bArmature *newArm; Bone *oldBone, *newBone; Bone *newActBone = NULL; - newArm = BKE_libblock_copy(&arm->id); + newArm = BKE_libblock_copy(bmain, &arm->id); BLI_duplicatelist(&newArm->bonebase, &arm->bonebase); /* Duplicate the childrens' lists */ @@ -232,7 +232,7 @@ bArmature *BKE_armature_copy(bArmature *arm) newArm->sketch = NULL; if (ID_IS_LINKED_DATABLOCK(arm)) { - BKE_id_lib_local_paths(G.main, arm->id.lib, &newArm->id); + BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id); } return newArm; diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 6d8dbcc688c..5505d3861d7 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -170,11 +170,11 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode) return NULL; } -Brush *BKE_brush_copy(Brush *brush) +Brush *BKE_brush_copy(Main *bmain, Brush *brush) { Brush *brushn; - brushn = BKE_libblock_copy(&brush->id); + brushn = BKE_libblock_copy(bmain, &brush->id); if (brush->mtex.tex) id_us_plus((ID *)brush->mtex.tex); @@ -196,7 +196,7 @@ Brush *BKE_brush_copy(Brush *brush) id_fake_user_set(&brush->id); if (ID_IS_LINKED_DATABLOCK(brush)) { - BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id); + BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id); } return brushn; @@ -261,7 +261,7 @@ void BKE_brush_make_local(Brush *brush) id_fake_user_set(&brush->id); } else if (is_local && is_lib) { - Brush *brush_new = BKE_brush_copy(brush); /* Ensures FAKE_USER is set */ + Brush *brush_new = BKE_brush_copy(bmain, brush); /* Ensures FAKE_USER is set */ id_us_min(&brush_new->id); /* Remove user added by standard BKE_libblock_copy(). */ /* Remap paths of new ID using old library as base. */ @@ -469,6 +469,7 @@ void BKE_brush_curve_preset(Brush *b, int preset) curvemapping_changed(b->curve, false); } +/* XXX Unused function. */ int BKE_brush_texture_set_nr(Brush *brush, int nr) { ID *idtest, *id = NULL; @@ -477,7 +478,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr) idtest = (ID *)BLI_findlink(&G.main->tex, nr - 1); if (idtest == NULL) { /* new tex */ - if (id) idtest = (ID *)BKE_texture_copy((Tex *)id); + if (id) idtest = (ID *)BKE_texture_copy(G.main, (Tex *)id); else idtest = (ID *)BKE_texture_add(G.main, "Tex"); id_us_min(idtest); } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 9fd2c2ddd14..41c67ef5365 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -91,16 +91,16 @@ void *BKE_camera_add(Main *bmain, const char *name) return cam; } -Camera *BKE_camera_copy(Camera *cam) +Camera *BKE_camera_copy(Main *bmain, Camera *cam) { Camera *camn; - camn = BKE_libblock_copy(&cam->id); + camn = BKE_libblock_copy(bmain, &cam->id); id_lib_extern((ID *)camn->dof_ob); if (ID_IS_LINKED_DATABLOCK(cam)) { - BKE_id_lib_local_paths(G.main, cam->id.lib, &camn->id); + BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id); } return camn; @@ -134,7 +134,7 @@ void BKE_camera_make_local(Camera *cam) id_clear_lib_data(bmain, &cam->id); } else if (is_local && is_lib) { - Camera *cam_new = BKE_camera_copy(cam); + Camera *cam_new = BKE_camera_copy(bmain, cam); cam_new->id.us = 0; diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 4dc0f1ccf8c..3a7be948760 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -174,12 +174,12 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) return cu; } -Curve *BKE_curve_copy_ex(Main *bmain, Curve *cu) +Curve *BKE_curve_copy(Main *bmain, Curve *cu) { Curve *cun; int a; - cun = BKE_libblock_copy_ex(bmain, &cu->id); + cun = BKE_libblock_copy(bmain, &cu->id); BLI_listbase_clear(&cun->nurb); BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); @@ -195,7 +195,7 @@ Curve *BKE_curve_copy_ex(Main *bmain, Curve *cu) cun->bb = MEM_dupallocN(cu->bb); if (cu->key) { - cun->key = BKE_key_copy_ex(bmain, cu->key); + cun->key = BKE_key_copy(bmain, cu->key); cun->key->from = (ID *)cun; } @@ -219,11 +219,6 @@ Curve *BKE_curve_copy_ex(Main *bmain, Curve *cu) return cun; } -Curve *BKE_curve_copy(Curve *cu) -{ - return BKE_curve_copy_ex(G.main, cu); -} - static int extern_local_curve_callback( void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) { @@ -263,7 +258,7 @@ void BKE_curve_make_local(Main *bmain, Curve *cu) extern_local_curve(cu); } else { - Curve *cu_new = BKE_curve_copy_ex(bmain, cu); + Curve *cu_new = BKE_curve_copy(bmain, cu); cu_new->id.us = 0; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index af1bcd0c545..ac4f566dc62 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -49,6 +49,7 @@ #include "BKE_global.h" #include "BKE_gpencil.h" #include "BKE_library.h" +#include "BKE_main.h" /* ************************************************** */ @@ -358,7 +359,7 @@ bGPDlayer *gpencil_layer_duplicate(bGPDlayer *src) } /* make a copy of a given gpencil datablock */ -bGPdata *gpencil_data_duplicate(bGPdata *src, bool internal_copy) +bGPdata *gpencil_data_duplicate(Main *bmain, bGPdata *src, bool internal_copy) { bGPDlayer *gpl, *gpld; bGPdata *dst; @@ -374,7 +375,7 @@ bGPdata *gpencil_data_duplicate(bGPdata *src, bool internal_copy) } else { /* make a copy when others use this */ - dst = BKE_libblock_copy(&src->id); + dst = BKE_libblock_copy(bmain, &src->id); } /* copy layers */ diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index ce7ef1f710a..99a83665db7 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -87,18 +87,18 @@ Group *BKE_group_add(Main *bmain, const char *name) return group; } -Group *BKE_group_copy(Group *group) +Group *BKE_group_copy(Main *bmain, Group *group) { Group *groupn; - groupn = BKE_libblock_copy(&group->id); + groupn = BKE_libblock_copy(bmain, &group->id); BLI_duplicatelist(&groupn->gobject, &group->gobject); /* Do not copy group's preview (same behavior as for objects). */ groupn->preview = NULL; if (ID_IS_LINKED_DATABLOCK(group)) { - BKE_id_lib_local_paths(G.main, group->id.lib, &groupn->id); + BKE_id_lib_local_paths(bmain, group->id.lib, &groupn->id); } return groupn; diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index ed8095444a4..2b7968eec1d 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -150,12 +150,12 @@ Key *BKE_key_add(ID *id) /* common function */ return key; } -Key *BKE_key_copy_ex(Main *bmain, Key *key) +Key *BKE_key_copy(Main *bmain, Key *key) { Key *keyn; KeyBlock *kbn, *kb; - keyn = BKE_libblock_copy_ex(bmain, &key->id); + keyn = BKE_libblock_copy(bmain, &key->id); BLI_duplicatelist(&keyn->block, &key->block); @@ -177,11 +177,6 @@ Key *BKE_key_copy_ex(Main *bmain, Key *key) return keyn; } -Key *BKE_key_copy(Key *key) -{ - return BKE_key_copy_ex(G.main, key); -} - Key *BKE_key_copy_nolib(Key *key) { Key *keyn; diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 43396834650..7ab71938cf2 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -114,12 +114,12 @@ Lamp *BKE_lamp_add(Main *bmain, const char *name) return la; } -Lamp *BKE_lamp_copy(Lamp *la) +Lamp *BKE_lamp_copy(Main *bmain, Lamp *la) { Lamp *lan; int a; - lan = BKE_libblock_copy(&la->id); + lan = BKE_libblock_copy(bmain, &la->id); for (a = 0; a < MAX_MTEX; a++) { if (lan->mtex[a]) { @@ -132,13 +132,13 @@ Lamp *BKE_lamp_copy(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); if (la->nodetree) - lan->nodetree = ntreeCopyTree(la->nodetree); + lan->nodetree = ntreeCopyTree(bmain, la->nodetree); if (la->preview) lan->preview = BKE_previewimg_copy(la->preview); if (ID_IS_LINKED_DATABLOCK(la)) { - BKE_id_lib_local_paths(G.main, la->id.lib, &lan->id); + BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id); } return lan; @@ -200,7 +200,7 @@ void BKE_lamp_make_local(Lamp *la) id_clear_lib_data(bmain, &la->id); } else if (is_local && is_lib) { - Lamp *la_new = BKE_lamp_copy(la); + Lamp *la_new = BKE_lamp_copy(bmain, la); la_new->id.us = 0; /* Remap paths of new ID using old library as base. */ diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index e85fad55532..88b0418938f 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -277,15 +277,15 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name) return lt; } -Lattice *BKE_lattice_copy_ex(Main *bmain, Lattice *lt) +Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt) { Lattice *ltn; - ltn = BKE_libblock_copy_ex(bmain, <->id); + ltn = BKE_libblock_copy(bmain, <->id); ltn->def = MEM_dupallocN(lt->def); if (lt->key) { - ltn->key = BKE_key_copy_ex(bmain, ltn->key); + ltn->key = BKE_key_copy(bmain, ltn->key); ltn->key->from = (ID *)ltn; } @@ -304,11 +304,6 @@ Lattice *BKE_lattice_copy_ex(Main *bmain, Lattice *lt) return ltn; } -Lattice *BKE_lattice_copy(Lattice *lt) -{ - return BKE_lattice_copy_ex(G.main, lt); -} - /** Free (or release) any data used by this lattice (does not free the lattice itself). */ void BKE_lattice_free(Lattice *lt) { @@ -358,7 +353,7 @@ void BKE_lattice_make_local(Main *bmain, Lattice *lt) /* No extern_local_lattice... */ } else { - Lattice *lt_new = BKE_lattice_copy_ex(bmain, lt); + Lattice *lt_new = BKE_lattice_copy(bmain, lt); lt_new->id.us = 0; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index fa63e7a5f84..f85765435f2 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -344,9 +344,11 @@ bool id_make_local(Main *bmain, ID *id, bool test) * Invokes the appropriate copy method for the block and returns the result in * newid, unless test. Returns true if the block can be copied. */ -bool id_copy(ID *id, ID **newid, bool test) +bool id_copy(Main *bmain, ID *id, ID **newid, bool test) { - if (!test) *newid = NULL; + if (!test) { + *newid = NULL; + } /* conventions: * - make shallow copy, only this ID block @@ -357,83 +359,83 @@ bool id_copy(ID *id, ID **newid, bool test) case ID_LI: return false; /* can't be copied from here */ case ID_OB: - if (!test) *newid = (ID *)BKE_object_copy((Object *)id); + if (!test) *newid = (ID *)BKE_object_copy(bmain, (Object *)id); return true; case ID_ME: - if (!test) *newid = (ID *)BKE_mesh_copy((Mesh *)id); + if (!test) *newid = (ID *)BKE_mesh_copy(bmain, (Mesh *)id); return true; case ID_CU: - if (!test) *newid = (ID *)BKE_curve_copy((Curve *)id); + if (!test) *newid = (ID *)BKE_curve_copy(bmain, (Curve *)id); return true; case ID_MB: - if (!test) *newid = (ID *)BKE_mball_copy((MetaBall *)id); + if (!test) *newid = (ID *)BKE_mball_copy(bmain, (MetaBall *)id); return true; case ID_MA: - if (!test) *newid = (ID *)BKE_material_copy((Material *)id); + if (!test) *newid = (ID *)BKE_material_copy(bmain, (Material *)id); return true; case ID_TE: - if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); + if (!test) *newid = (ID *)BKE_texture_copy(bmain, (Tex *)id); return true; case ID_IM: - if (!test) *newid = (ID *)BKE_image_copy(G.main, (Image *)id); + if (!test) *newid = (ID *)BKE_image_copy(bmain, (Image *)id); return true; case ID_LT: - if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); + if (!test) *newid = (ID *)BKE_lattice_copy(bmain, (Lattice *)id); return true; case ID_LA: - if (!test) *newid = (ID *)BKE_lamp_copy((Lamp *)id); + if (!test) *newid = (ID *)BKE_lamp_copy(bmain, (Lamp *)id); return true; case ID_SPK: - if (!test) *newid = (ID *)BKE_speaker_copy((Speaker *)id); + if (!test) *newid = (ID *)BKE_speaker_copy(bmain, (Speaker *)id); return true; case ID_CA: - if (!test) *newid = (ID *)BKE_camera_copy((Camera *)id); + if (!test) *newid = (ID *)BKE_camera_copy(bmain, (Camera *)id); return true; case ID_IP: return false; /* deprecated */ case ID_KE: - if (!test) *newid = (ID *)BKE_key_copy((Key *)id); + if (!test) *newid = (ID *)BKE_key_copy(bmain, (Key *)id); return true; case ID_WO: - if (!test) *newid = (ID *)BKE_world_copy((World *)id); + if (!test) *newid = (ID *)BKE_world_copy(bmain, (World *)id); return true; case ID_SCR: return false; /* can't be copied from here */ case ID_VF: return false; /* not implemented */ case ID_TXT: - if (!test) *newid = (ID *)BKE_text_copy(G.main, (Text *)id); + if (!test) *newid = (ID *)BKE_text_copy(bmain, (Text *)id); return true; case ID_SO: return false; /* not implemented */ case ID_GR: - if (!test) *newid = (ID *)BKE_group_copy((Group *)id); + if (!test) *newid = (ID *)BKE_group_copy(bmain, (Group *)id); return true; case ID_AR: - if (!test) *newid = (ID *)BKE_armature_copy((bArmature *)id); + if (!test) *newid = (ID *)BKE_armature_copy(bmain, (bArmature *)id); return true; case ID_AC: - if (!test) *newid = (ID *)BKE_action_copy((bAction *)id); + if (!test) *newid = (ID *)BKE_action_copy(bmain, (bAction *)id); return true; case ID_NT: - if (!test) *newid = (ID *)ntreeCopyTree((bNodeTree *)id); + if (!test) *newid = (ID *)ntreeCopyTree(bmain, (bNodeTree *)id); return true; case ID_BR: - if (!test) *newid = (ID *)BKE_brush_copy((Brush *)id); + if (!test) *newid = (ID *)BKE_brush_copy(bmain, (Brush *)id); return true; case ID_PA: - if (!test) *newid = (ID *)BKE_particlesettings_copy((ParticleSettings *)id); + if (!test) *newid = (ID *)BKE_particlesettings_copy(bmain, (ParticleSettings *)id); return true; case ID_WM: return false; /* can't be copied from here */ case ID_GD: - if (!test) *newid = (ID *)gpencil_data_duplicate((bGPdata *)id, false); + if (!test) *newid = (ID *)gpencil_data_duplicate(bmain, (bGPdata *)id, false); return true; case ID_MSK: - if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id); + if (!test) *newid = (ID *)BKE_mask_copy(bmain, (Mask *)id); return true; case ID_LS: - if (!test) *newid = (ID *)BKE_linestyle_copy(G.main, (FreestyleLineStyle *)id); + if (!test) *newid = (ID *)BKE_linestyle_copy(bmain, (FreestyleLineStyle *)id); return true; } @@ -448,7 +450,7 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) if (id) { /* if property isn't editable, we're going to have an extra block hanging around until we save */ if (RNA_property_editable(ptr, prop)) { - if (id_copy(id, &newid, false) && newid) { + if (id_copy(CTX_data_main(C), id, &newid, false) && newid) { /* copy animation actions too */ BKE_animdata_copy_id_action(id); /* us is 1 by convention, but RNA_property_pointer_set @@ -976,7 +978,7 @@ void BKE_libblock_copy_data(ID *id, const ID *id_from, const bool do_action) } /* used everywhere in blenkernel */ -void *BKE_libblock_copy_ex(Main *bmain, ID *id) +void *BKE_libblock_copy(Main *bmain, ID *id) { ID *idn; size_t idn_len; @@ -1028,11 +1030,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action) return idn; } -void *BKE_libblock_copy(ID *id) -{ - return BKE_libblock_copy_ex(G.main, id); -} - static int id_relink_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag) { ID *id = *id_pointer; diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 2985038bcae..591975b05fa 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -171,7 +171,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *l } } if (linestyle->nodetree) { - new_linestyle->nodetree = ntreeCopyTree(linestyle->nodetree); + new_linestyle->nodetree = ntreeCopyTree(bmain, linestyle->nodetree); } new_linestyle->r = linestyle->r; diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index dabdb4c81c6..f804a4c3919 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -848,11 +848,11 @@ Mask *BKE_mask_copy_nolib(Mask *mask) return mask_new; } -Mask *BKE_mask_copy(Mask *mask) +Mask *BKE_mask_copy(Main *bmain, Mask *mask) { Mask *mask_new; - mask_new = BKE_libblock_copy(&mask->id); + mask_new = BKE_libblock_copy(bmain, &mask->id); BLI_listbase_clear(&mask_new->masklayers); @@ -862,7 +862,7 @@ Mask *BKE_mask_copy(Mask *mask) id_fake_user_set(&mask->id); if (ID_IS_LINKED_DATABLOCK(mask)) { - BKE_id_lib_local_paths(G.main, mask->id.lib, &mask_new->id); + BKE_id_lib_local_paths(bmain, mask->id.lib, &mask_new->id); } return mask_new; diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 1b6fd300f67..467bf9bf580 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -217,12 +217,12 @@ Material *BKE_material_add(Main *bmain, const char *name) } /* XXX keep synced with next function */ -Material *BKE_material_copy(Material *ma) +Material *BKE_material_copy(Main *bmain, Material *ma) { Material *man; int a; - man = BKE_libblock_copy(&ma->id); + man = BKE_libblock_copy(bmain, &ma->id); id_lib_extern((ID *)man->group); @@ -240,13 +240,13 @@ Material *BKE_material_copy(Material *ma) if (ma->preview) man->preview = BKE_previewimg_copy(ma->preview); if (ma->nodetree) { - man->nodetree = ntreeCopyTree(ma->nodetree); + man->nodetree = ntreeCopyTree(bmain, ma->nodetree); } BLI_listbase_clear(&man->gpumaterial); if (ID_IS_LINKED_DATABLOCK(ma)) { - BKE_id_lib_local_paths(G.main, ma->id.lib, &man->id); + BKE_id_lib_local_paths(bmain, ma->id.lib, &man->id); } return man; @@ -376,7 +376,7 @@ void BKE_material_make_local(Material *ma) } /* Both user and local, so copy. */ else if (is_local && is_lib) { - Material *ma_new = BKE_material_copy(ma); + Material *ma_new = BKE_material_copy(bmain, ma); ma_new->id.us = 0; @@ -2161,7 +2161,7 @@ static void convert_tfacematerial(Main *main, Material *ma) } /* create a new material */ else { - mat_new = BKE_material_copy(ma); + mat_new = BKE_material_copy(main, ma); if (mat_new) { /* rename the material*/ BLI_strncpy(mat_new->id.name, idname, sizeof(mat_new->id.name)); diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index c6e6bb86659..0a29b2d53fd 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -102,12 +102,12 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name) return mb; } -MetaBall *BKE_mball_copy_ex(Main *bmain, MetaBall *mb) +MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb) { MetaBall *mbn; int a; - mbn = BKE_libblock_copy_ex(bmain, &mb->id); + mbn = BKE_libblock_copy(bmain, &mb->id); BLI_duplicatelist(&mbn->elems, &mb->elems); @@ -126,11 +126,6 @@ MetaBall *BKE_mball_copy_ex(Main *bmain, MetaBall *mb) return mbn; } -MetaBall *BKE_mball_copy(MetaBall *mb) -{ - return BKE_mball_copy_ex(G.main, mb); -} - static int extern_local_mball_callback( void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) { @@ -167,7 +162,7 @@ void BKE_mball_make_local(Main *bmain, MetaBall *mb) extern_local_mball(mb); } else { - MetaBall *mb_new = BKE_mball_copy_ex(bmain, mb); + MetaBall *mb_new = BKE_mball_copy(bmain, mb); mb_new->id.us = 0; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index b2ab83a7018..e737696b3af 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -493,7 +493,7 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name) return me; } -Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) +Mesh *BKE_mesh_copy(Main *bmain, Mesh *me) { Mesh *men; MTFace *tface; @@ -501,7 +501,7 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) int a, i; const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */ - men = BKE_libblock_copy_ex(bmain, &me->id); + men = BKE_libblock_copy(bmain, &me->id); men->mat = MEM_dupallocN(me->mat); for (a = 0; a < men->totcol; a++) { @@ -549,7 +549,7 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) men->bb = MEM_dupallocN(men->bb); if (me->key) { - men->key = BKE_key_copy_ex(bmain, me->key); + men->key = BKE_key_copy(bmain, me->key); men->key->from = (ID *)men; } @@ -560,11 +560,6 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me) return men; } -Mesh *BKE_mesh_copy(Mesh *me) -{ - return BKE_mesh_copy_ex(G.main, me); -} - BMesh *BKE_mesh_to_bmesh( Mesh *me, Object *ob, const bool add_key_index, const struct BMeshCreateParams *params) @@ -650,7 +645,7 @@ void BKE_mesh_make_local(Main *bmain, Mesh *me) expand_local_mesh(me); } else { - Mesh *me_new = BKE_mesh_copy_ex(bmain, me); + Mesh *me_new = BKE_mesh_copy(bmain, me); me_new->id.us = 0; @@ -2338,7 +2333,7 @@ Mesh *BKE_mesh_new_from_object( BKE_object_free_modifiers(tmpobj); /* copies the data */ - copycu = tmpobj->data = BKE_curve_copy_ex(bmain, (Curve *) ob->data); + copycu = tmpobj->data = BKE_curve_copy(bmain, (Curve *) ob->data); /* temporarily set edit so we get updates from edit mode, but * also because for text datablocks copying it while in edit @@ -2419,7 +2414,7 @@ Mesh *BKE_mesh_new_from_object( /* copies object and modifiers (but not the data) */ if (cage) { /* copies the data */ - tmpmesh = BKE_mesh_copy_ex(bmain, ob->data); + tmpmesh = BKE_mesh_copy(bmain, ob->data); /* if not getting the original caged mesh, get final derived mesh */ } else { diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 992042c8af2..c321bc92a71 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -183,7 +183,7 @@ NlaStrip *copy_nlastrip(NlaStrip *strip, const bool use_same_action) } else { /* use a copy of the action instead (user count shouldn't have changed yet) */ - strip_d->act = BKE_action_copy(strip_d->act); + strip_d->act = BKE_action_copy(G.main, strip_d->act); } } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index cf70159a329..aaba5dff7e4 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1205,7 +1205,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, Main *bmain, bool ski /* is ntree part of library? */ if (bmain && !skip_database && BLI_findindex(&bmain->nodetree, ntree) >= 0) { - newtree = BKE_libblock_copy(&ntree->id); + newtree = BKE_libblock_copy(bmain, &ntree->id); } else { newtree = BKE_libblock_copy_nolib(&ntree->id, true); @@ -1300,9 +1300,9 @@ bNodeTree *ntreeCopyTree_ex(bNodeTree *ntree, Main *bmain, const bool do_id_user { return ntreeCopyTree_internal(ntree, bmain, false, do_id_user, true, true); } -bNodeTree *ntreeCopyTree(bNodeTree *ntree) +bNodeTree *ntreeCopyTree(Main *bmain, bNodeTree *ntree) { - return ntreeCopyTree_ex(ntree, G.main, true); + return ntreeCopyTree_ex(ntree, bmain, true); } /* use when duplicating scenes */ @@ -1995,11 +1995,11 @@ void ntreeMakeLocal(bNodeTree *ntree, bool id_in_mainlist) } else if (local && lib) { /* this is the mixed case, we copy the tree and assign it to local users */ - bNodeTree *newtree = ntreeCopyTree(ntree); + bNodeTree *newtree = ntreeCopyTree(bmain, ntree); newtree->id.us = 0; - FOREACH_NODETREE(G.main, tntree, owner_id) { + FOREACH_NODETREE(bmain, tntree, owner_id) { bNode *node; /* find if group is in tree */ for (node = tntree->nodes.first; node; node = node->next) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 623c437fea5..4031afb8a78 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1094,7 +1094,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches) ModifierData *md; int a; - obn = BKE_libblock_copy_ex(bmain, &ob->id); + obn = BKE_libblock_copy(bmain, &ob->id); if (ob->totcol) { obn->mat = MEM_dupallocN(ob->mat); @@ -1181,9 +1181,9 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches) } /* copy objects, will re-initialize cached simulation data */ -Object *BKE_object_copy(Object *ob) +Object *BKE_object_copy(Main *bmain, Object *ob) { - return BKE_object_copy_ex(G.main, ob, false); + return BKE_object_copy_ex(bmain, ob, false); } static int extern_local_object_callback( @@ -1223,7 +1223,7 @@ void BKE_object_make_local(Main *bmain, Object *ob) extern_local_object(ob); } else { - Object *ob_new = BKE_object_copy_ex(bmain, ob, false); + Object *ob_new = BKE_object_copy(bmain, ob); ob_new->id.us = 0; ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 4136f866f6a..6e13ce87172 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3304,12 +3304,12 @@ void BKE_particlesettings_rough_curve_init(ParticleSettings *part) part->roughcurve = cumap; } -ParticleSettings *BKE_particlesettings_copy(ParticleSettings *part) +ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part) { ParticleSettings *partn; int a; - partn = BKE_libblock_copy(&part->id); + partn = BKE_libblock_copy(bmain, &part->id); partn->pd = MEM_dupallocN(part->pd); partn->pd2 = MEM_dupallocN(part->pd2); partn->effector_weights = MEM_dupallocN(part->effector_weights); @@ -3333,7 +3333,7 @@ ParticleSettings *BKE_particlesettings_copy(ParticleSettings *part) BLI_duplicatelist(&partn->dupliweights, &part->dupliweights); if (ID_IS_LINKED_DATABLOCK(part)) { - BKE_id_lib_local_paths(G.main, part->id.lib, &partn->id); + BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id); } return partn; @@ -3383,7 +3383,7 @@ void BKE_particlesettings_make_local(ParticleSettings *part) expand_local_particlesettings(part); } else if (is_local && is_lib) { - ParticleSettings *part_new = BKE_particlesettings_copy(part); + ParticleSettings *part_new = BKE_particlesettings_copy(bmain, part); part_new->id.us = 0; /* Remap paths of new ID using old library as base. */ diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 0e8efca04d0..c071aacc64b 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -150,7 +150,7 @@ static void remove_sequencer_fcurves(Scene *sce) } } -Scene *BKE_scene_copy(Scene *sce, int type) +Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) { Scene *scen; SceneRenderLayer *srl, *new_srl; @@ -161,7 +161,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) if (type == SCE_COPY_EMPTY) { ListBase rl, rv; /* XXX. main should become an arg */ - scen = BKE_scene_add(G.main, sce->id.name + 2); + scen = BKE_scene_add(bmain, sce->id.name + 2); rl = scen->r.layers; rv = scen->r.views; @@ -182,10 +182,10 @@ Scene *BKE_scene_copy(Scene *sce, int type) BKE_sound_destroy_scene(scen); } else { - scen = BKE_libblock_copy(&sce->id); + scen = BKE_libblock_copy(bmain, &sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); - BKE_main_id_clear_newpoins(G.main); + BKE_main_id_clear_newpoins(bmain); id_us_plus((ID *)scen->world); id_us_plus((ID *)scen->set); @@ -209,7 +209,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) if (sce->nodetree) { /* ID's are managed on both copy and switch */ - scen->nodetree = ntreeCopyTree(sce->nodetree); + scen->nodetree = ntreeCopyTree(bmain, sce->nodetree); ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); } @@ -237,7 +237,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) for (lineset = new_srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) { if (lineset->linestyle) { id_us_plus((ID *)lineset->linestyle); - lineset->linestyle = BKE_linestyle_copy(G.main, lineset->linestyle); + lineset->linestyle = BKE_linestyle_copy(bmain, lineset->linestyle); } } } @@ -320,7 +320,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) if (type == SCE_COPY_FULL) { if (scen->world) { id_us_plus((ID *)scen->world); - scen->world = BKE_world_copy(scen->world); + scen->world = BKE_world_copy(bmain, scen->world); BKE_animdata_copy_id_action((ID *)scen->world); } @@ -334,7 +334,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) /* grease pencil */ if (scen->gpd) { if (type == SCE_COPY_FULL) { - scen->gpd = gpencil_data_duplicate(scen->gpd, false); + scen->gpd = gpencil_data_duplicate(bmain, scen->gpd, false); } else if (type == SCE_COPY_EMPTY) { scen->gpd = NULL; diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 58214e4a8d9..4cce0851ebc 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -66,11 +66,11 @@ void *BKE_speaker_add(Main *bmain, const char *name) return spk; } -Speaker *BKE_speaker_copy(Speaker *spk) +Speaker *BKE_speaker_copy(Main *bmain, Speaker *spk) { Speaker *spkn; - spkn = BKE_libblock_copy(&spk->id); + spkn = BKE_libblock_copy(bmain, &spk->id); if (spkn->sound) id_us_plus(&spkn->sound->id); @@ -118,7 +118,7 @@ void BKE_speaker_make_local(Speaker *spk) extern_local_speaker(spk); } else if (is_local && is_lib) { - Speaker *spk_new = BKE_speaker_copy(spk); + Speaker *spk_new = BKE_speaker_copy(bmain, spk); spk_new->id.us = 0; /* Remap paths of new ID using old library as base. */ diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 2b713f980d5..6beaba1b41c 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -452,7 +452,7 @@ Text *BKE_text_copy(Main *bmain, Text *ta) Text *tan; TextLine *line, *tmp; - tan = BKE_libblock_copy(&ta->id); + tan = BKE_libblock_copy(bmain, &ta->id); /* file name can be NULL */ if (ta->name) { diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index a8657dd2cb0..877bc0c02b0 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -844,11 +844,11 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot) /* ------------------------------------------------------------------------- */ -Tex *BKE_texture_copy(Tex *tex) +Tex *BKE_texture_copy(Main *bmain, Tex *tex) { Tex *texn; - texn = BKE_libblock_copy(&tex->id); + texn = BKE_libblock_copy(bmain, &tex->id); if (BKE_texture_is_image_user(tex)) { id_us_plus((ID *)texn->ima); } @@ -867,11 +867,11 @@ Tex *BKE_texture_copy(Tex *tex) if (tex->nodetree->execdata) { ntreeTexEndExecTree(tex->nodetree->execdata); } - texn->nodetree = ntreeCopyTree(tex->nodetree); + texn->nodetree = ntreeCopyTree(bmain, tex->nodetree); } if (ID_IS_LINKED_DATABLOCK(tex)) { - BKE_id_lib_local_paths(G.main, tex->id.lib, &texn->id); + BKE_id_lib_local_paths(bmain, tex->id.lib, &texn->id); } return texn; @@ -1011,7 +1011,7 @@ void BKE_texture_make_local(Tex *tex) extern_local_texture(tex); } else if (is_local && is_lib) { - Tex *tex_new = BKE_texture_copy(tex); + Tex *tex_new = BKE_texture_copy(bmain, tex); tex_new->id.us = 0; diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index c6ab843b38a..cfd10e7ba35 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -117,12 +117,12 @@ World *add_world(Main *bmain, const char *name) return wrld; } -World *BKE_world_copy(World *wrld) +World *BKE_world_copy(Main *bmain, World *wrld) { World *wrldn; int a; - wrldn = BKE_libblock_copy(&wrld->id); + wrldn = BKE_libblock_copy(bmain, &wrld->id); for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { @@ -133,7 +133,7 @@ World *BKE_world_copy(World *wrld) } if (wrld->nodetree) { - wrldn->nodetree = ntreeCopyTree(wrld->nodetree); + wrldn->nodetree = ntreeCopyTree(bmain, wrld->nodetree); } if (wrld->preview) @@ -142,7 +142,7 @@ World *BKE_world_copy(World *wrld) BLI_listbase_clear(&wrldn->gpumaterial); if (ID_IS_LINKED_DATABLOCK(wrld)) { - BKE_id_lib_local_paths(G.main, wrld->id.lib, &wrldn->id); + BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrldn->id); } return wrldn; @@ -202,7 +202,7 @@ void BKE_world_make_local(World *wrld) id_clear_lib_data(bmain, &wrld->id); } else if (is_local && is_lib) { - World *wrld_new = BKE_world_copy(wrld); + World *wrld_new = BKE_world_copy(bmain, wrld); wrld_new->id.us = 0; /* Remap paths of new ID using old library as base. */ diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 3a709da78e1..f06f299d381 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -416,7 +416,7 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod { fprintf(stderr, "create under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL); - Object *obn = BKE_object_copy(source_ob); + Object *obn = BKE_object_copy(G.main, source_ob); DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); BKE_scene_base_add(sce, obn); diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 9e04f410333..72b48a32477 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1301,7 +1301,7 @@ static int separate_exec(bContext *C, wmOperator *op) DAG_relations_tag_update(bmain); newob = newbase->object; - newcu = newob->data = BKE_curve_copy_ex(bmain, oldcu); + newcu = newob->data = BKE_curve_copy(bmain, oldcu); newcu->editnurb = NULL; id_us_min(&oldcu->id); /* because new curve is a copy: reduce user count */ diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c index c39a3aa5cfc..f9b479ca03d 100644 --- a/source/blender/editors/gpencil/gpencil_undo.c +++ b/source/blender/editors/gpencil/gpencil_undo.c @@ -43,7 +43,9 @@ #include "BKE_blender_undo.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_gpencil.h" +#include "BKE_main.h" #include "ED_gpencil.h" @@ -151,7 +153,7 @@ void gpencil_undo_push(bGPdata *gpd) /* create new undo node */ undo_node = MEM_callocN(sizeof(bGPundonode), "gpencil undo node"); - undo_node->gpd = gpencil_data_duplicate(gpd, true); + undo_node->gpd = gpencil_data_duplicate(G.main, gpd, true); cur_node = undo_node; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 77dc822fd40..d91bd498225 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -475,7 +475,7 @@ static void template_ID( UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE)); if (/* test only */ - (id_copy(id, NULL, true) == false) || + (id_copy(CTX_data_main(C), id, NULL, true) == false) || (idfrom && idfrom->lib) || (!editable) || /* object in editmode - don't change data */ diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 1b5fc4e8a1c..b26989113d4 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -172,7 +172,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) */ if (key) { /* make a duplicate copy that will only be used here... (must remember to free it!) */ - nkey = BKE_key_copy_ex(bmain, key); + nkey = BKE_key_copy(bmain, key); /* for all keys in old block, clear data-arrays */ for (kb = key->block.first; kb; kb = kb->next) { diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 2ea39209781..cc628210e20 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1299,7 +1299,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base, for (dob = lb->first; dob; dob = dob->next) { Base *basen; - Object *ob = BKE_object_copy(dob->ob); + Object *ob = BKE_object_copy(bmain, dob->ob); /* font duplis can have a totcol without material, we get them from parent * should be implemented better... @@ -1520,7 +1520,7 @@ static int convert_poll(bContext *C) } /* Helper for convert_exec */ -static Base *duplibase_for_convert(Scene *scene, Base *base, Object *ob) +static Base *duplibase_for_convert(Main *bmain, Scene *scene, Base *base, Object *ob) { Object *obn; Base *basen; @@ -1529,7 +1529,7 @@ static Base *duplibase_for_convert(Scene *scene, Base *base, Object *ob) ob = base->object; } - obn = BKE_object_copy(ob); + obn = BKE_object_copy(bmain, ob); DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); basen = MEM_mallocN(sizeof(Base), "duplibase"); @@ -1609,7 +1609,7 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(scene, base, NULL); + basen = duplibase_for_convert(bmain, scene, base, NULL); newob = basen->object; /* decrement original mesh's usage count */ @@ -1617,7 +1617,7 @@ static int convert_exec(bContext *C, wmOperator *op) id_us_min(&me->id); /* make a new copy of the mesh */ - newob->data = BKE_mesh_copy(me); + newob->data = BKE_mesh_copy(bmain, me); } else { newob = ob; @@ -1634,7 +1634,7 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(scene, base, NULL); + basen = duplibase_for_convert(bmain, scene, base, NULL); newob = basen->object; /* decrement original mesh's usage count */ @@ -1642,7 +1642,7 @@ static int convert_exec(bContext *C, wmOperator *op) id_us_min(&me->id); /* make a new copy of the mesh */ - newob->data = BKE_mesh_copy(me); + newob->data = BKE_mesh_copy(bmain, me); } else { newob = ob; @@ -1666,14 +1666,14 @@ static int convert_exec(bContext *C, wmOperator *op) ob->flag |= OB_DONE; if (keep_original) { - basen = duplibase_for_convert(scene, base, NULL); + basen = duplibase_for_convert(bmain, scene, base, NULL); newob = basen->object; /* decrement original curve's usage count */ id_us_min(&((Curve *)newob->data)->id); /* make a new copy of the curve */ - newob->data = BKE_curve_copy_ex(bmain, ob->data); + newob->data = BKE_curve_copy(bmain, ob->data); } else { newob = ob; @@ -1737,14 +1737,14 @@ static int convert_exec(bContext *C, wmOperator *op) if (target == OB_MESH) { if (keep_original) { - basen = duplibase_for_convert(scene, base, NULL); + basen = duplibase_for_convert(bmain, scene, base, NULL); newob = basen->object; /* decrement original curve's usage count */ id_us_min(&((Curve *)newob->data)->id); /* make a new copy of the curve */ - newob->data = BKE_curve_copy_ex(bmain, ob->data); + newob->data = BKE_curve_copy(bmain, ob->data); } else { newob = ob; @@ -1772,7 +1772,7 @@ static int convert_exec(bContext *C, wmOperator *op) if (!(baseob->flag & OB_DONE)) { baseob->flag |= OB_DONE; - basen = duplibase_for_convert(scene, base, baseob); + basen = duplibase_for_convert(bmain, scene, base, baseob); newob = basen->object; mb = newob->data; @@ -1910,7 +1910,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base ; /* nothing? */ } else { - obn = BKE_object_copy(ob); + obn = BKE_object_copy(bmain, ob); DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); basen = MEM_mallocN(sizeof(Base), "duplibase"); @@ -1941,7 +1941,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (id) { ID_NEW_US(obn->mat[a]) else - obn->mat[a] = BKE_material_copy(obn->mat[a]); + obn->mat[a] = BKE_material_copy(bmain, obn->mat[a]); id_us_min(id); if (dupflag & USER_DUP_ACT) { @@ -1957,7 +1957,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (id) { ID_NEW_US(psys->part) else - psys->part = BKE_particlesettings_copy(psys->part); + psys->part = BKE_particlesettings_copy(bmain, psys->part); if (dupflag & USER_DUP_ACT) { BKE_animdata_copy_id_action(&psys->part->id); @@ -1976,7 +1976,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_MESH) { ID_NEW_US2(obn->data) else { - obn->data = BKE_mesh_copy(obn->data); + obn->data = BKE_mesh_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -1986,7 +1986,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_CURVE) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy_ex(bmain, obn->data); + obn->data = BKE_curve_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -1996,7 +1996,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_SURF) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy_ex(bmain, obn->data); + obn->data = BKE_curve_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2006,7 +2006,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_FONT) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy_ex(bmain, obn->data); + obn->data = BKE_curve_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2016,7 +2016,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_MBALL) { ID_NEW_US2(obn->data) else { - obn->data = BKE_mball_copy_ex(bmain, obn->data); + obn->data = BKE_mball_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2026,7 +2026,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_LAMP) { ID_NEW_US2(obn->data) else { - obn->data = BKE_lamp_copy(obn->data); + obn->data = BKE_lamp_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2039,7 +2039,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_ARM) { ID_NEW_US2(obn->data) else { - obn->data = BKE_armature_copy(obn->data); + obn->data = BKE_armature_copy(bmain, obn->data); BKE_pose_rebuild(obn, obn->data); didit = 1; } @@ -2050,7 +2050,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag != 0) { ID_NEW_US2(obn->data) else { - obn->data = BKE_lattice_copy_ex(bmain, obn->data); + obn->data = BKE_lattice_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2060,7 +2060,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag != 0) { ID_NEW_US2(obn->data) else { - obn->data = BKE_camera_copy(obn->data); + obn->data = BKE_camera_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2070,7 +2070,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag != 0) { ID_NEW_US2(obn->data) else { - obn->data = BKE_speaker_copy(obn->data); + obn->data = BKE_speaker_copy(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2109,7 +2109,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (id) { ID_NEW_US((*matarar)[a]) else - (*matarar)[a] = BKE_material_copy((*matarar)[a]); + (*matarar)[a] = BKE_material_copy(bmain, (*matarar)[a]); id_us_min(id); } } diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index bf2dc550067..6b16e19f790 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1751,7 +1751,7 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in if ((base->flag & flag) == flag) { if (!ID_IS_LINKED_DATABLOCK(ob) && ob->id.us > 1) { /* base gets copy of object */ - obn = BKE_object_copy(ob); + obn = BKE_object_copy(bmain, ob); base->object = obn; if (copy_groups) { @@ -1784,7 +1784,7 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in } if (all_duplicated) { - groupn = BKE_group_copy(group); + groupn = BKE_group_copy(bmain, group); for (go = groupn->gobject.first; go; go = go->next) go->ob = (Object *)go->ob->id.newid; @@ -1821,7 +1821,7 @@ void ED_object_single_user(Main *bmain, Scene *scene, Object *ob) single_object_users(bmain, scene, NULL, OB_DONE, copy_groups); } -static void new_id_matar(Material **matar, const int totcol) +static void new_id_matar(Main *bmain, Material **matar, const int totcol) { ID *id; int a; @@ -1835,7 +1835,7 @@ static void new_id_matar(Material **matar, const int totcol) id_us_min(id); } else if (id->us > 1) { - matar[a] = BKE_material_copy(matar[a]); + matar[a] = BKE_material_copy(bmain, matar[a]); id_us_min(id); id->newid = (ID *)matar[a]; } @@ -1865,7 +1865,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag) switch (ob->type) { case OB_LAMP: - ob->data = la = BKE_lamp_copy(ob->data); + ob->data = la = BKE_lamp_copy(bmain, ob->data); for (a = 0; a < MAX_MTEX; a++) { if (la->mtex[a]) { ID_NEW(la->mtex[a]->object); @@ -1873,37 +1873,37 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag) } break; case OB_CAMERA: - ob->data = BKE_camera_copy(ob->data); + ob->data = BKE_camera_copy(bmain, ob->data); break; case OB_MESH: - ob->data = me = BKE_mesh_copy(ob->data); + ob->data = me = BKE_mesh_copy(bmain, ob->data); if (me->key) BKE_animdata_copy_id_action((ID *)me->key); break; case OB_MBALL: - ob->data = BKE_mball_copy_ex(bmain, ob->data); + ob->data = BKE_mball_copy(bmain, ob->data); break; case OB_CURVE: case OB_SURF: case OB_FONT: - ob->data = cu = BKE_curve_copy_ex(bmain, ob->data); + ob->data = cu = BKE_curve_copy(bmain, ob->data); ID_NEW(cu->bevobj); ID_NEW(cu->taperobj); if (cu->key) BKE_animdata_copy_id_action((ID *)cu->key); break; case OB_LATTICE: - ob->data = lat = BKE_lattice_copy_ex(bmain, ob->data); + ob->data = lat = BKE_lattice_copy(bmain, ob->data); if (lat->key) BKE_animdata_copy_id_action((ID *)lat->key); break; case OB_ARMATURE: DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - ob->data = BKE_armature_copy(ob->data); + ob->data = BKE_armature_copy(bmain, ob->data); BKE_pose_rebuild(ob, ob->data); break; case OB_SPEAKER: - ob->data = BKE_speaker_copy(ob->data); + ob->data = BKE_speaker_copy(bmain, ob->data); break; default: if (G.debug & G_DEBUG) @@ -1945,7 +1945,7 @@ static void single_object_action_users(Scene *scene, const int flag) } } -static void single_mat_users(Scene *scene, const int flag, const bool do_textures) +static void single_mat_users(Main *bmain, Scene *scene, const int flag, const bool do_textures) { Object *ob; Base *base; @@ -1962,7 +1962,7 @@ static void single_mat_users(Scene *scene, const int flag, const bool do_texture /* do not test for LIB_TAG_NEW: this functions guaranteed delivers single_users! */ if (ma->id.us > 1) { - man = BKE_material_copy(ma); + man = BKE_material_copy(bmain, ma); BKE_animdata_copy_id_action(&man->id); man->id.us = 0; @@ -1973,7 +1973,7 @@ static void single_mat_users(Scene *scene, const int flag, const bool do_texture if (ma->mtex[b] && (tex = ma->mtex[b]->tex)) { if (tex->id.us > 1) { id_us_min(&tex->id); - tex = BKE_texture_copy(tex); + tex = BKE_texture_copy(bmain, tex); BKE_animdata_copy_id_action(&tex->id); man->mtex[b]->tex = tex; } @@ -1987,7 +1987,7 @@ static void single_mat_users(Scene *scene, const int flag, const bool do_texture } } -static void do_single_tex_user(Tex **from) +static void do_single_tex_user(Main *bmain, Tex **from) { Tex *tex, *texn; @@ -2000,7 +2000,7 @@ static void do_single_tex_user(Tex **from) id_us_min(&tex->id); } else if (tex->id.us > 1) { - texn = BKE_texture_copy(tex); + texn = BKE_texture_copy(bmain, tex); BKE_animdata_copy_id_action(&texn->id); tex->id.newid = (ID *)texn; id_us_min(&tex->id); @@ -2020,7 +2020,7 @@ static void single_tex_users_expand(Main *bmain) if (ma->id.tag & LIB_TAG_NEW) { for (b = 0; b < MAX_MTEX; b++) { if (ma->mtex[b] && ma->mtex[b]->tex) { - do_single_tex_user(&(ma->mtex[b]->tex)); + do_single_tex_user(bmain, &(ma->mtex[b]->tex)); } } } @@ -2030,7 +2030,7 @@ static void single_tex_users_expand(Main *bmain) if (la->id.tag & LIB_TAG_NEW) { for (b = 0; b < MAX_MTEX; b++) { if (la->mtex[b] && la->mtex[b]->tex) { - do_single_tex_user(&(la->mtex[b]->tex)); + do_single_tex_user(bmain, &(la->mtex[b]->tex)); } } } @@ -2040,7 +2040,7 @@ static void single_tex_users_expand(Main *bmain) if (wo->id.tag & LIB_TAG_NEW) { for (b = 0; b < MAX_MTEX; b++) { if (wo->mtex[b] && wo->mtex[b]->tex) { - do_single_tex_user(&(wo->mtex[b]->tex)); + do_single_tex_user(bmain, &(wo->mtex[b]->tex)); } } } @@ -2059,19 +2059,19 @@ static void single_mat_users_expand(Main *bmain) for (ob = bmain->object.first; ob; ob = ob->id.next) if (ob->id.tag & LIB_TAG_NEW) - new_id_matar(ob->mat, ob->totcol); + new_id_matar(bmain, ob->mat, ob->totcol); for (me = bmain->mesh.first; me; me = me->id.next) if (me->id.tag & LIB_TAG_NEW) - new_id_matar(me->mat, me->totcol); + new_id_matar(bmain, me->mat, me->totcol); for (cu = bmain->curve.first; cu; cu = cu->id.next) if (cu->id.tag & LIB_TAG_NEW) - new_id_matar(cu->mat, cu->totcol); + new_id_matar(bmain, cu->mat, cu->totcol); for (mb = bmain->mball.first; mb; mb = mb->id.next) if (mb->id.tag & LIB_TAG_NEW) - new_id_matar(mb->mat, mb->totcol); + new_id_matar(bmain, mb->mat, mb->totcol); /* material imats */ for (ma = bmain->mat.first; ma; ma = ma->id.next) @@ -2376,7 +2376,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op) } if (RNA_boolean_get(op->ptr, "material")) { - single_mat_users(scene, flag, RNA_boolean_get(op->ptr, "texture")); + single_mat_users(bmain, scene, flag, RNA_boolean_get(op->ptr, "texture")); } #if 0 /* can't do this separate from materials */ diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index d6c89b9c7a5..0dd00df6182 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -195,7 +195,7 @@ static int new_particle_settings_exec(bContext *C, wmOperator *UNUSED(op)) /* add or copy particle setting */ if (psys->part) - part= BKE_particlesettings_copy(psys->part); + part= BKE_particlesettings_copy(bmain, psys->part); else part= psys_new_settings("ParticleSettings", bmain); diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 1d20ecf2d99..c3f83138707 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -464,7 +464,7 @@ static int new_material_exec(bContext *C, wmOperator *UNUSED(op)) /* add or copy material */ if (ma) { - ma = BKE_material_copy(ma); + ma = BKE_material_copy(bmain, ma); } else { ma = BKE_material_add(bmain, DATA_("Material")); @@ -518,7 +518,7 @@ static int new_texture_exec(bContext *C, wmOperator *UNUSED(op)) /* add or copy texture */ if (tex) { - tex = BKE_texture_copy(tex); + tex = BKE_texture_copy(bmain, tex); } else { tex = BKE_texture_add(bmain, DATA_("Texture")); @@ -576,7 +576,7 @@ static int new_world_exec(bContext *C, wmOperator *UNUSED(op)) /* add or copy world */ if (wo) { - wo = BKE_world_copy(wo); + wo = BKE_world_copy(bmain, wo); } else { wo = add_world(bmain, DATA_("World")); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 04a8f0a3a51..6dbb5db53d0 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3955,7 +3955,7 @@ static int scene_new_exec(bContext *C, wmOperator *op) newscene = BKE_scene_add(bmain, DATA_("Scene")); } else { /* different kinds of copying */ - newscene = BKE_scene_copy(scene, type); + newscene = BKE_scene_copy(bmain, scene, type); /* these can't be handled in blenkernel currently, so do them here */ if (type == SCE_COPY_LINK_DATA) { diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index bf923415f01..f88b64129e7 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -69,7 +69,7 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op)) PaintMode mode = BKE_paintmode_get_active_from_context(C); if (br) - br = BKE_brush_copy(br); + br = BKE_brush_copy(bmain, br); else br = BKE_brush_add(bmain, "Brush", BKE_paint_object_mode_from_paint_mode(mode)); diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c index a3be7791f9a..6755a6316cc 100644 --- a/source/blender/editors/space_action/action_data.c +++ b/source/blender/editors/space_action/action_data.c @@ -121,7 +121,7 @@ static bAction *action_create_new(bContext *C, bAction *oldact) */ if (oldact && GS(oldact->id.name) == ID_AC) { /* make a copy of the existing action */ - action = BKE_action_copy(oldact); + action = BKE_action_copy(CTX_data_main(C), oldact); } else { /* just make a new (empty) action */ diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index a2159696394..3e7e8ccc3f4 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -1856,6 +1856,7 @@ void NLA_OT_action_sync_length(wmOperatorType *ot) static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op)) { + Main *bmain = CTX_data_main(C); bAnimContext ac; ListBase anim_data = {NULL, NULL}; @@ -1887,7 +1888,7 @@ static int nlaedit_make_single_user_exec(bContext *C, wmOperator *UNUSED(op)) /* multi-user? */ if (ID_REAL_USERS(strip->act) > 1) { /* make a new copy of the action for us to use (it will have 1 user already) */ - bAction *new_action = BKE_action_copy(strip->act); + bAction *new_action = BKE_action_copy(bmain, strip->act); /* decrement user count of our existing action */ id_us_min(&strip->act->id); @@ -1945,6 +1946,7 @@ static short bezt_apply_nlamapping(KeyframeEditData *ked, BezTriple *bezt) static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op)) { + Main *bmain = CTX_data_main(C); bAnimContext ac; ListBase anim_data = {NULL, NULL}; @@ -1974,7 +1976,7 @@ static int nlaedit_apply_scale_exec(bContext *C, wmOperator *UNUSED(op)) continue; if (strip->act->id.us > 1) { /* make a copy of the Action to work on */ - bAction *act = BKE_action_copy(strip->act); + bAction *act = BKE_action_copy(bmain, strip->act); /* set this as the new referenced action, decrementing the users of the old one */ id_us_min(&strip->act->id); diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 5c58e9b720c..cf6e2ac226e 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -255,7 +255,7 @@ static int node_group_ungroup(bNodeTree *ntree, bNode *gnode) bAction *waction; /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */ - waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action); + waction = wgroup->adt->action = BKE_action_copy(G.main, wgroup->adt->action); /* now perform the moving */ BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index dc6d30854a6..d67929b65fc 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -277,11 +277,11 @@ StructRNA *rna_PropertyGroup_refine(PointerRNA *ptr) return ptr->type; } -static ID *rna_ID_copy(ID *id) +static ID *rna_ID_copy(ID *id, Main *bmain) { ID *newid; - if (id_copy(id, &newid, false)) { + if (id_copy(bmain, id, &newid, false)) { if (newid) id_us_min(newid); return newid; } @@ -981,6 +981,7 @@ static void rna_def_ID(BlenderRNA *brna) /* functions */ func = RNA_def_function(srna, "copy", "rna_ID_copy"); RNA_def_function_ui_description(func, "Create a copy of this data-block (not supported for all data-blocks)"); + RNA_def_function_flag(func, FUNC_USE_MAIN); parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID"); RNA_def_function_return(func, parm); -- cgit v1.2.3