Cleanup: Collection: Move to IDTypeInfo, and remove unused BKE API.
Note: we still need BKE_collection_free since we call it from scene.c.
This commit is contained in:
parent
69d4aec55f
commit
17f08cff6a
|
@ -56,11 +56,6 @@ bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bo
|
|||
struct Collection *BKE_collection_copy(struct Main *bmain,
|
||||
struct Collection *parent,
|
||||
struct Collection *collection);
|
||||
void BKE_collection_copy_data(struct Main *bmain,
|
||||
struct Collection *collection_dst,
|
||||
const struct Collection *collection_src,
|
||||
const int flag);
|
||||
void BKE_collection_make_local(struct Main *bmain, struct Collection *collection, const int flags);
|
||||
|
||||
struct Collection *BKE_collection_duplicate(struct Main *bmain,
|
||||
struct Collection *parent,
|
||||
|
|
|
@ -144,7 +144,7 @@ extern IDTypeInfo IDType_ID_SCR;
|
|||
// extern IDTypeInfo IDType_ID_TXT;
|
||||
// extern IDTypeInfo IDType_ID_SPK;
|
||||
// extern IDTypeInfo IDType_ID_SO;
|
||||
// extern IDTypeInfo IDType_ID_GR;
|
||||
extern IDTypeInfo IDType_ID_GR;
|
||||
// extern IDTypeInfo IDType_ID_AR;
|
||||
// extern IDTypeInfo IDType_ID_AC;
|
||||
extern IDTypeInfo IDType_ID_NT;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "BKE_collection.h"
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_idprop.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
@ -70,6 +71,79 @@ static CollectionParent *collection_find_parent(Collection *child, Collection *c
|
|||
|
||||
static bool collection_find_child_recursive(Collection *parent, Collection *collection);
|
||||
|
||||
/****************************** Collection Datablock ************************/
|
||||
|
||||
/**
|
||||
* Only copy internal data of Collection ID from source
|
||||
* to already allocated/initialized destination.
|
||||
* You probably never want to use that directly,
|
||||
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
||||
*
|
||||
* WARNING! This function will not handle ID user count!
|
||||
*
|
||||
* \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
|
||||
*/
|
||||
static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
||||
{
|
||||
Collection *collection_dst = (Collection *)id_dst;
|
||||
const Collection *collection_src = (const Collection *)id_src;
|
||||
|
||||
BLI_assert(((collection_src->flag & COLLECTION_IS_MASTER) != 0) ==
|
||||
((collection_src->id.flag & LIB_PRIVATE_DATA) != 0));
|
||||
|
||||
/* Do not copy collection's preview (same behavior as for objects). */
|
||||
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */
|
||||
BKE_previewimg_id_copy(&collection_dst->id, &collection_src->id);
|
||||
}
|
||||
else {
|
||||
collection_dst->preview = NULL;
|
||||
}
|
||||
|
||||
collection_dst->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
|
||||
BLI_listbase_clear(&collection_dst->object_cache);
|
||||
|
||||
BLI_listbase_clear(&collection_dst->gobject);
|
||||
BLI_listbase_clear(&collection_dst->children);
|
||||
BLI_listbase_clear(&collection_dst->parents);
|
||||
|
||||
for (CollectionChild *child = collection_src->children.first; child; child = child->next) {
|
||||
collection_child_add(collection_dst, child->collection, flag, false);
|
||||
}
|
||||
for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) {
|
||||
collection_object_add(bmain, collection_dst, cob->ob, flag, false);
|
||||
}
|
||||
}
|
||||
|
||||
static void collection_free_data(ID *id)
|
||||
{
|
||||
Collection *collection = (Collection *)id;
|
||||
|
||||
/* No animdata here. */
|
||||
BKE_previewimg_free(&collection->preview);
|
||||
|
||||
BLI_freelistN(&collection->gobject);
|
||||
BLI_freelistN(&collection->children);
|
||||
BLI_freelistN(&collection->parents);
|
||||
|
||||
BKE_collection_object_cache_free(collection);
|
||||
}
|
||||
|
||||
IDTypeInfo IDType_ID_GR = {
|
||||
.id_code = ID_GR,
|
||||
.id_filter = FILTER_ID_GR,
|
||||
.main_listbase_index = INDEX_ID_GR,
|
||||
.struct_size = sizeof(Collection),
|
||||
.name = "Collection",
|
||||
.name_plural = "collections",
|
||||
.translation_context = BLT_I18NCONTEXT_ID_COLLECTION,
|
||||
.flags = 0,
|
||||
|
||||
.init_data = NULL,
|
||||
.copy_data = collection_copy_data,
|
||||
.free_data = collection_free_data,
|
||||
.make_local = NULL,
|
||||
};
|
||||
|
||||
/***************************** Add Collection *******************************/
|
||||
|
||||
/* Add new collection, without view layer syncing. */
|
||||
|
@ -117,14 +191,7 @@ Collection *BKE_collection_add(Main *bmain, Collection *collection_parent, const
|
|||
/** Free (or release) any data used by this collection (does not free the collection itself). */
|
||||
void BKE_collection_free(Collection *collection)
|
||||
{
|
||||
/* No animdata here. */
|
||||
BKE_previewimg_free(&collection->preview);
|
||||
|
||||
BLI_freelistN(&collection->gobject);
|
||||
BLI_freelistN(&collection->children);
|
||||
BLI_freelistN(&collection->parents);
|
||||
|
||||
BKE_collection_object_cache_free(collection);
|
||||
collection_free_data(&collection->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,48 +254,6 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
|
|||
}
|
||||
|
||||
/***************************** Collection Copy *******************************/
|
||||
|
||||
/**
|
||||
* Only copy internal data of Collection ID from source
|
||||
* to already allocated/initialized destination.
|
||||
* You probably never want to use that directly,
|
||||
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
||||
*
|
||||
* WARNING! This function will not handle ID user count!
|
||||
*
|
||||
* \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
|
||||
*/
|
||||
void BKE_collection_copy_data(Main *bmain,
|
||||
Collection *collection_dst,
|
||||
const Collection *collection_src,
|
||||
const int flag)
|
||||
{
|
||||
BLI_assert(((collection_src->flag & COLLECTION_IS_MASTER) != 0) ==
|
||||
((collection_src->id.flag & LIB_PRIVATE_DATA) != 0));
|
||||
|
||||
/* Do not copy collection's preview (same behavior as for objects). */
|
||||
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */
|
||||
BKE_previewimg_id_copy(&collection_dst->id, &collection_src->id);
|
||||
}
|
||||
else {
|
||||
collection_dst->preview = NULL;
|
||||
}
|
||||
|
||||
collection_dst->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
|
||||
BLI_listbase_clear(&collection_dst->object_cache);
|
||||
|
||||
BLI_listbase_clear(&collection_dst->gobject);
|
||||
BLI_listbase_clear(&collection_dst->children);
|
||||
BLI_listbase_clear(&collection_dst->parents);
|
||||
|
||||
for (CollectionChild *child = collection_src->children.first; child; child = child->next) {
|
||||
collection_child_add(collection_dst, child->collection, flag, false);
|
||||
}
|
||||
for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) {
|
||||
collection_object_add(bmain, collection_dst, cob->ob, flag, false);
|
||||
}
|
||||
}
|
||||
|
||||
static Collection *collection_duplicate_recursive(Main *bmain,
|
||||
Collection *parent,
|
||||
Collection *collection_old,
|
||||
|
@ -369,11 +394,6 @@ Collection *BKE_collection_duplicate(Main *bmain,
|
|||
return collection_new;
|
||||
}
|
||||
|
||||
void BKE_collection_make_local(Main *bmain, Collection *collection, const int flags)
|
||||
{
|
||||
BKE_lib_id_make_local_generic(bmain, &collection->id, flags);
|
||||
}
|
||||
|
||||
/********************************* Naming *******************************/
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@ static void id_type_init(void)
|
|||
// INIT_TYPE(ID_TXT);
|
||||
// INIT_TYPE(ID_SPK);
|
||||
// INIT_TYPE(ID_SO);
|
||||
// INIT_TYPE(ID_GR);
|
||||
INIT_TYPE(ID_GR);
|
||||
// INIT_TYPE(ID_AR);
|
||||
// INIT_TYPE(ID_AC);
|
||||
INIT_TYPE(ID_NT);
|
||||
|
|
|
@ -540,9 +540,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
|
|||
}
|
||||
return true;
|
||||
case ID_GR:
|
||||
if (!test) {
|
||||
BKE_collection_make_local(bmain, (Collection *)id, flags);
|
||||
}
|
||||
BLI_assert(0);
|
||||
return true;
|
||||
case ID_AR:
|
||||
if (!test) {
|
||||
|
@ -762,7 +760,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
|
|||
BKE_text_copy_data(bmain, (Text *)*r_newid, (Text *)id, flag);
|
||||
break;
|
||||
case ID_GR:
|
||||
BKE_collection_copy_data(bmain, (Collection *)*r_newid, (Collection *)id, flag);
|
||||
BLI_assert(0);
|
||||
break;
|
||||
case ID_AR:
|
||||
BKE_armature_copy_data(bmain, (bArmature *)*r_newid, (bArmature *)id, flag);
|
||||
|
|
|
@ -200,7 +200,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
|
|||
BKE_sound_free((bSound *)id);
|
||||
break;
|
||||
case ID_GR:
|
||||
BKE_collection_free((Collection *)id);
|
||||
BLI_assert(0);
|
||||
break;
|
||||
case ID_AR:
|
||||
BKE_armature_free((bArmature *)id);
|
||||
|
|
Loading…
Reference in New Issue