Static overrides API: add functions to create overrides from several datablocks at once.
This simplifies remapping task, since you don't have to ensure your overrides are created in the correct dependency order. Uses famous LIB_TAG_DOIT to mark IDs to be overridden.
This commit is contained in:
parent
436eea2d93
commit
72ec6dbb0b
|
@ -43,7 +43,8 @@ void BKE_override_static_copy(struct ID *dst_id, const struct ID *src_id);
|
|||
void BKE_override_static_clear(struct IDOverrideStatic *override);
|
||||
void BKE_override_static_free(struct IDOverrideStatic **override);
|
||||
|
||||
struct ID *BKE_override_static_create_from(struct Main *bmain, struct ID *reference_id);
|
||||
struct ID *BKE_override_static_create_from_id(struct Main *bmain, struct ID *reference_id);
|
||||
bool BKE_override_static_create_from_tag(struct Main *bmain);
|
||||
|
||||
struct IDOverrideStaticProperty *BKE_override_static_property_find(struct IDOverrideStatic *override, const char *rna_path);
|
||||
struct IDOverrideStaticProperty *BKE_override_static_property_get(struct IDOverrideStatic *override, const char *rna_path, bool *r_created);
|
||||
|
|
|
@ -152,12 +152,8 @@ void BKE_override_static_free(struct IDOverrideStatic **override)
|
|||
*override = NULL;
|
||||
}
|
||||
|
||||
/** Create an overriden local copy of linked reference. */
|
||||
ID *BKE_override_static_create_from(Main *bmain, ID *reference_id)
|
||||
static ID *override_static_create_from(Main *bmain, ID *reference_id)
|
||||
{
|
||||
BLI_assert(reference_id != NULL);
|
||||
BLI_assert(reference_id->lib != NULL);
|
||||
|
||||
ID *local_id;
|
||||
|
||||
if (!id_copy(bmain, reference_id, (ID **)&local_id, false)) {
|
||||
|
@ -168,12 +164,63 @@ ID *BKE_override_static_create_from(Main *bmain, ID *reference_id)
|
|||
BKE_override_static_init(local_id, reference_id);
|
||||
local_id->flag |= LIB_OVERRIDE_STATIC_AUTO;
|
||||
|
||||
return local_id;
|
||||
}
|
||||
|
||||
|
||||
/** Create an overriden local copy of linked reference. */
|
||||
ID *BKE_override_static_create_from_id(Main *bmain, ID *reference_id)
|
||||
{
|
||||
BLI_assert(reference_id != NULL);
|
||||
BLI_assert(reference_id->lib != NULL);
|
||||
|
||||
ID *local_id = override_static_create_from(bmain, reference_id);
|
||||
|
||||
/* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */
|
||||
BKE_libblock_remap(bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE);
|
||||
|
||||
return local_id;
|
||||
}
|
||||
|
||||
/** Create overriden local copies of all tagged data-blocks in given Main.
|
||||
*
|
||||
* \note Set id->newid of overridden libs with newly created overrides, caller is responsible to clean those pointers
|
||||
* before/after usage as needed.
|
||||
*
|
||||
* \return \a true on success, \a false otherwise.
|
||||
*/
|
||||
bool BKE_override_static_create_from_tag(Main *bmain)
|
||||
{
|
||||
ListBase *lbarray[MAX_LIBARRAY];
|
||||
int a;
|
||||
bool ret = true;
|
||||
|
||||
const int num_types = a = set_listbasepointers(bmain, lbarray);
|
||||
while (a--) {
|
||||
for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) {
|
||||
if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL) {
|
||||
if ((reference_id->newid = override_static_create_from(bmain, reference_id)) == NULL) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */
|
||||
a = num_types;
|
||||
while (a--) {
|
||||
for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) {
|
||||
if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL && reference_id->newid != NULL) {
|
||||
ID *local_id = reference_id->newid;
|
||||
BKE_libblock_remap(bmain, reference_id, local_id,
|
||||
ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find override property from given RNA path, if it exists.
|
||||
*/
|
||||
|
|
|
@ -460,7 +460,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
|
|||
if (id) {
|
||||
Main *bmain = CTX_data_main(C);
|
||||
if (CTX_wm_window(C)->eventstate->shift) {
|
||||
ID *override_id = BKE_override_static_create_from(bmain, id);
|
||||
ID *override_id = BKE_override_static_create_from_id(bmain, id);
|
||||
if (override_id != NULL) {
|
||||
BKE_main_id_clear_newpoins(bmain);
|
||||
|
||||
|
|
|
@ -2340,7 +2340,7 @@ static int make_override_exec(bContext *C, wmOperator *UNUSED(op))
|
|||
Main *bmain = CTX_data_main(C);
|
||||
Object *locobj, *refobj = CTX_data_active_object(C);
|
||||
|
||||
locobj = (Object *)BKE_override_static_create_from(bmain, &refobj->id);
|
||||
locobj = (Object *)BKE_override_static_create_from_id(bmain, &refobj->id);
|
||||
UNUSED_VARS(locobj);
|
||||
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
|
|
|
@ -461,7 +461,7 @@ static void id_static_override_cb(
|
|||
{
|
||||
if (ID_IS_LINKED(tselem->id) && (tselem->id->tag & LIB_TAG_EXTERN)) {
|
||||
Main *bmain = CTX_data_main(C);
|
||||
ID *override_id = BKE_override_static_create_from(bmain, tselem->id);
|
||||
ID *override_id = BKE_override_static_create_from_id(bmain, tselem->id);
|
||||
if (override_id != NULL) {
|
||||
BKE_main_id_clear_newpoins(bmain);
|
||||
}
|
||||
|
|
|
@ -318,7 +318,7 @@ static ID *rna_ID_override_create(ID *id, Main *bmain)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return BKE_override_static_create_from(bmain, id);
|
||||
return BKE_override_static_create_from_id(bmain, id);
|
||||
}
|
||||
|
||||
static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
|
||||
|
|
Loading…
Reference in New Issue