Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/library.c
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_idcode.h" | #include "BKE_idcode.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_override.h" | |||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_library_remap.h" | #include "BKE_library_remap.h" | ||||
| #include "BKE_linestyle.h" | #include "BKE_linestyle.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_mask.h" | #include "BKE_mask.h" | ||||
| ▲ Show 20 Lines • Show All 569 Lines • ▼ Show 20 Lines | |||||
| * Invokes the appropriate copy method for the block and returns the result in | * Invokes the appropriate copy method for the block and returns the result in | ||||
| * newid, unless test. Returns true if the block can be copied. | * newid, unless test. Returns true if the block can be copied. | ||||
| */ | */ | ||||
| bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) | bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) | ||||
| { | { | ||||
| return BKE_id_copy_ex(bmain, id, newid, 0, test); | return BKE_id_copy_ex(bmain, id, newid, 0, test); | ||||
| } | } | ||||
| /** Does a mere memory swap over the whole IDs data (including type-specific memory). | |||||
| * \note Most internal ID data itself is not swapped (only IDProperties are). */ | |||||
| void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b) | |||||
| { | |||||
| BLI_assert(GS(id_a->name) == GS(id_b->name)); | |||||
| const ID id_a_back = *id_a; | |||||
| const ID id_b_back = *id_b; | |||||
| #define CASE_SWAP(_gs, _type) \ | |||||
| case _gs: \ | |||||
| SWAP(_type, *(_type *)id_a, *(_type *)id_b); \ | |||||
| break | |||||
| switch ((ID_Type)GS(id_a->name)) { | |||||
| CASE_SWAP(ID_SCE, Scene); | |||||
| CASE_SWAP(ID_LI, Library); | |||||
| CASE_SWAP(ID_OB, Object); | |||||
| CASE_SWAP(ID_ME, Mesh); | |||||
| CASE_SWAP(ID_CU, Curve); | |||||
| CASE_SWAP(ID_MB, MetaBall); | |||||
| CASE_SWAP(ID_MA, Material); | |||||
| CASE_SWAP(ID_TE, Tex); | |||||
| CASE_SWAP(ID_IM, Image); | |||||
| CASE_SWAP(ID_LT, Lattice); | |||||
| CASE_SWAP(ID_LA, Lamp); | |||||
| CASE_SWAP(ID_LP, LightProbe); | |||||
| CASE_SWAP(ID_CA, Camera); | |||||
| CASE_SWAP(ID_KE, Key); | |||||
| CASE_SWAP(ID_WO, World); | |||||
| CASE_SWAP(ID_SCR, bScreen); | |||||
| CASE_SWAP(ID_VF, VFont); | |||||
| CASE_SWAP(ID_TXT, Text); | |||||
| CASE_SWAP(ID_SPK, Speaker); | |||||
| CASE_SWAP(ID_SO, bSound); | |||||
| CASE_SWAP(ID_GR, Group); | |||||
| CASE_SWAP(ID_AR, bArmature); | |||||
| CASE_SWAP(ID_AC, bAction); | |||||
| CASE_SWAP(ID_NT, bNodeTree); | |||||
| CASE_SWAP(ID_BR, Brush); | |||||
| CASE_SWAP(ID_PA, ParticleSettings); | |||||
| CASE_SWAP(ID_WM, wmWindowManager); | |||||
| CASE_SWAP(ID_WS, WorkSpace); | |||||
| CASE_SWAP(ID_GD, bGPdata); | |||||
| CASE_SWAP(ID_MC, MovieClip); | |||||
| CASE_SWAP(ID_MSK, Mask); | |||||
| CASE_SWAP(ID_LS, FreestyleLineStyle); | |||||
| CASE_SWAP(ID_PAL, Palette); | |||||
| CASE_SWAP(ID_PC, PaintCurve); | |||||
| CASE_SWAP(ID_CF, CacheFile); | |||||
| case ID_IP: | |||||
| break; /* Deprecated. */ | |||||
| } | |||||
| #undef CASE_SWAP | |||||
| /* Restore original ID's internal data. */ | |||||
| *id_a = id_a_back; | |||||
| *id_b = id_b_back; | |||||
| /* Exception: IDProperties. */ | |||||
| id_a->properties = id_b_back.properties; | |||||
| id_b->properties = id_a_back.properties; | |||||
| /* Swap will have broken internal references to itself, restore them. */ | |||||
| BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, false); | |||||
| BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, false); | |||||
| } | |||||
| /** Does *not* set ID->newid pointer. */ | /** Does *not* set ID->newid pointer. */ | ||||
| bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) | bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| ID *newid = NULL; | ID *newid = NULL; | ||||
| PointerRNA idptr; | PointerRNA idptr; | ||||
| if (id) { | if (id) { | ||||
| /* if property isn't editable, we're going to have an extra block hanging around until we save */ | /* if property isn't editable, we're going to have an extra block hanging around until we save */ | ||||
| ▲ Show 20 Lines • Show All 637 Lines • ▼ Show 20 Lines | if ((int)id_len - (int)id_offset > 0) { /* signed to allow neg result */ /* XXX ????? */ | ||||
| memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset); | memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset); | ||||
| } | } | ||||
| if (id->properties) { | if (id->properties) { | ||||
| new_id->properties = IDP_CopyProperty_ex(id->properties, flag); | new_id->properties = IDP_CopyProperty_ex(id->properties, flag); | ||||
| } | } | ||||
| /* XXX Again... We need a way to control what we copy in a much more refined way. | |||||
| * We cannot always copy this, some internal copying will die on it! */ | |||||
| /* For now, upper level code will have to do that itself when required. */ | |||||
| #if 0 | |||||
| if (id->override != NULL) { | |||||
| BKE_override_copy(new_id, id); | |||||
| } | |||||
| #endif | |||||
| /* the duplicate should get a copy of the animdata */ | /* the duplicate should get a copy of the animdata */ | ||||
| id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0); | id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0); | ||||
| if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0) { | if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0) { | ||||
| DEG_id_type_tag(bmain, GS(new_id->name)); | DEG_id_type_tag(bmain, GS(new_id->name)); | ||||
| } | } | ||||
| *r_newid = new_id; | *r_newid = new_id; | ||||
| ▲ Show 20 Lines • Show All 1,064 Lines • Show Last 20 Lines | |||||