2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2006-11-29 23:31:46 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2006-11-29 23:31:46 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-11-29 23:31:46 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
2011-02-27 20:40:57 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-12-24 18:38:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2010-08-13 06:30:04 +00:00
|
|
|
#include <stddef.h>
|
2007-12-24 18:38:03 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-07-08 06:00:27 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
#include "BLI_listbase.h"
|
2014-04-24 16:46:54 +02:00
|
|
|
#include "BLI_math.h"
|
2012-07-08 06:00:27 +00:00
|
|
|
|
2006-11-17 04:46:48 +00:00
|
|
|
#include "BKE_idprop.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
2006-11-17 04:46:48 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2014-12-12 16:17:52 +01:00
|
|
|
#include "BLI_strict_flags.h"
|
|
|
|
|
|
2006-11-17 04:46:48 +00:00
|
|
|
/* IDPropertyTemplate is a union in DNA_ID.h */
|
2007-04-19 22:49:48 +00:00
|
|
|
|
2014-12-12 16:17:52 +01:00
|
|
|
/**
|
|
|
|
|
* if the new is 'IDP_ARRAY_REALLOC_LIMIT' items less,
|
|
|
|
|
* than #IDProperty.totallen, reallocate anyway.
|
|
|
|
|
*/
|
|
|
|
|
#define IDP_ARRAY_REALLOC_LIMIT 200
|
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
static CLG_LogRef LOG = {"bke.idprop"};
|
|
|
|
|
|
2007-04-19 22:49:48 +00:00
|
|
|
/*local size table.*/
|
2014-12-12 16:17:52 +01:00
|
|
|
static size_t idp_size_table[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
1, /*strings*/
|
|
|
|
|
sizeof(int),
|
|
|
|
|
sizeof(float),
|
|
|
|
|
sizeof(float) * 3, /*Vector type, deprecated*/
|
|
|
|
|
sizeof(float) * 16, /*Matrix type, deprecated*/
|
|
|
|
|
0, /*arrays don't have a fixed size*/
|
|
|
|
|
sizeof(ListBase), /*Group type*/
|
|
|
|
|
sizeof(void *),
|
|
|
|
|
sizeof(double),
|
2006-11-17 04:46:48 +00:00
|
|
|
};
|
|
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Array Functions */
|
|
|
|
|
|
|
|
|
|
/** \name IDP Array API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2014-08-01 21:59:42 +10:00
|
|
|
#define GETPROP(prop, i) &(IDP_IDPArray(prop)[i])
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2008-12-31 13:16:37 +00:00
|
|
|
/* --------- property array type -------------*/
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* \note as a start to move away from the stupid IDP_New function, this type
|
|
|
|
|
* has it's own allocation function.
|
|
|
|
|
*/
|
2008-12-31 13:16:37 +00:00
|
|
|
IDProperty *IDP_NewIDPArray(const char *name)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty prop array");
|
|
|
|
|
prop->type = IDP_IDPARRAY;
|
|
|
|
|
prop->len = 0;
|
|
|
|
|
BLI_strncpy(prop->name, name, MAX_IDPROP_NAME);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return prop;
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag)
|
2008-12-31 13:16:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* don't use MEM_dupallocN because this may be part of an array */
|
|
|
|
|
IDProperty *narray, *tmp;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BLI_assert(array->type == IDP_IDPARRAY);
|
|
|
|
|
|
|
|
|
|
narray = MEM_mallocN(sizeof(IDProperty), __func__);
|
|
|
|
|
*narray = *array;
|
|
|
|
|
|
|
|
|
|
narray->data.pointer = MEM_dupallocN(array->data.pointer);
|
|
|
|
|
for (i = 0; i < narray->len; i++) {
|
|
|
|
|
/* ok, the copy functions always allocate a new structure,
|
|
|
|
|
* which doesn't work here. instead, simply copy the
|
|
|
|
|
* contents of the new structure into the array cell,
|
|
|
|
|
* then free it. this makes for more maintainable
|
|
|
|
|
* code than simply reimplementing the copy functions
|
|
|
|
|
* in this loop.*/
|
|
|
|
|
tmp = IDP_CopyProperty_ex(GETPROP(narray, i), flag);
|
|
|
|
|
memcpy(GETPROP(narray, i), tmp, sizeof(IDProperty));
|
|
|
|
|
MEM_freeN(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return narray;
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user)
|
2008-12-31 13:16:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_IDPARRAY);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < prop->len; i++) {
|
2019-05-16 14:17:11 +02:00
|
|
|
IDP_FreePropertyContent_ex(GETPROP(prop, i), do_id_user);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2008-12-31 13:16:37 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop->data.pointer) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(prop->data.pointer);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-30 22:52:12 +02:00
|
|
|
/* shallow copies item */
|
2008-12-31 13:16:37 +00:00
|
|
|
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *old;
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_IDPARRAY);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (index >= prop->len || index < 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2017-03-30 22:52:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
old = GETPROP(prop, index);
|
|
|
|
|
if (item != old) {
|
2019-05-16 14:11:11 +02:00
|
|
|
IDP_FreePropertyContent(old);
|
2017-03-30 22:52:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(old, item, sizeof(IDProperty));
|
|
|
|
|
}
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IDProperty *IDP_GetIndexArray(IDProperty *prop, int index)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_IDPARRAY);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return GETPROP(prop, index);
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-08 06:00:27 +00:00
|
|
|
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
|
2008-12-31 13:16:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_IDPARRAY);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_ResizeIDPArray(prop, prop->len + 1);
|
|
|
|
|
IDP_SetIndexArray(prop, prop->len - 1, item);
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int newsize;
|
|
|
|
|
|
|
|
|
|
BLI_assert(prop->type == IDP_IDPARRAY);
|
|
|
|
|
|
|
|
|
|
/* first check if the array buffer size has room */
|
|
|
|
|
if (newlen <= prop->totallen) {
|
|
|
|
|
if (newlen < prop->len && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) {
|
|
|
|
|
int i;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = newlen; i < prop->len; i++) {
|
2019-05-16 14:11:11 +02:00
|
|
|
IDP_FreePropertyContent(GETPROP(prop, i));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
prop->len = newlen;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (newlen >= prop->len) {
|
|
|
|
|
prop->len = newlen;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* free trailing items */
|
|
|
|
|
if (newlen < prop->len) {
|
|
|
|
|
/* newlen is smaller */
|
|
|
|
|
int i;
|
|
|
|
|
for (i = newlen; i < prop->len; i++) {
|
2019-05-16 14:11:11 +02:00
|
|
|
IDP_FreePropertyContent(GETPROP(prop, i));
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* - Note: This code comes from python, here's the corresponding comment. - */
|
|
|
|
|
/* This over-allocates proportional to the list size, making room
|
|
|
|
|
* for additional growth. The over-allocation is mild, but is
|
|
|
|
|
* enough to give linear-time amortized behavior over a long
|
|
|
|
|
* sequence of appends() in the presence of a poorly-performing
|
|
|
|
|
* system realloc().
|
|
|
|
|
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
|
|
|
|
|
*/
|
|
|
|
|
newsize = newlen;
|
|
|
|
|
newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
|
|
|
|
|
prop->data.pointer = MEM_recallocN(prop->data.pointer, sizeof(IDProperty) * (size_t)newsize);
|
|
|
|
|
prop->len = newlen;
|
|
|
|
|
prop->totallen = newsize;
|
2008-12-31 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------- Numerical Array Type ----------- */
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr)
|
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop->subtype != IDP_GROUP) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (newlen >= prop->len) {
|
|
|
|
|
/* bigger */
|
|
|
|
|
IDProperty **array = newarr;
|
|
|
|
|
IDPropertyTemplate val;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
for (a = prop->len; a < newlen; a++) {
|
|
|
|
|
val.i = 0; /* silence MSVC warning about uninitialized var when debugging */
|
|
|
|
|
array[a] = IDP_New(IDP_GROUP, &val, "IDP_ResizeArray group");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* smaller */
|
|
|
|
|
IDProperty **array = prop->data.pointer;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
for (a = newlen; a < prop->len; a++) {
|
|
|
|
|
IDP_FreeProperty(array[a]);
|
|
|
|
|
}
|
|
|
|
|
}
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-17 04:46:48 +00:00
|
|
|
/*this function works for strings too!*/
|
|
|
|
|
void IDP_ResizeArray(IDProperty *prop, int newlen)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int newsize;
|
|
|
|
|
const bool is_grow = newlen >= prop->len;
|
|
|
|
|
|
|
|
|
|
/* first check if the array buffer size has room */
|
|
|
|
|
if (newlen <= prop->totallen && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) {
|
|
|
|
|
idp_resize_group_array(prop, newlen, prop->data.pointer);
|
|
|
|
|
prop->len = newlen;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* - Note: This code comes from python, here's the corresponding comment. - */
|
|
|
|
|
/* This over-allocates proportional to the list size, making room
|
|
|
|
|
* for additional growth. The over-allocation is mild, but is
|
|
|
|
|
* enough to give linear-time amortized behavior over a long
|
|
|
|
|
* sequence of appends() in the presence of a poorly-performing
|
|
|
|
|
* system realloc().
|
|
|
|
|
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
|
|
|
|
|
*/
|
|
|
|
|
newsize = newlen;
|
|
|
|
|
newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_grow == false) {
|
2019-04-17 06:17:24 +02:00
|
|
|
idp_resize_group_array(prop, newlen, prop->data.pointer);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
prop->data.pointer = MEM_recallocN(prop->data.pointer,
|
|
|
|
|
idp_size_table[(int)prop->subtype] * (size_t)newsize);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_grow == true) {
|
2019-04-17 06:17:24 +02:00
|
|
|
idp_resize_group_array(prop, newlen, prop->data.pointer);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
prop->len = newlen;
|
|
|
|
|
prop->totallen = newsize;
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
void IDP_FreeArray(IDProperty *prop)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop->data.pointer) {
|
|
|
|
|
idp_resize_group_array(prop, 0, NULL);
|
|
|
|
|
MEM_freeN(prop->data.pointer);
|
|
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static IDProperty *idp_generic_copy(const IDProperty *prop, const int UNUSED(flag))
|
2012-05-06 17:22:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *newp = MEM_callocN(sizeof(IDProperty), __func__);
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(newp->name, prop->name, MAX_IDPROP_NAME);
|
|
|
|
|
newp->type = prop->type;
|
|
|
|
|
newp->flag = prop->flag;
|
|
|
|
|
newp->data.val = prop->data.val;
|
|
|
|
|
newp->data.val2 = prop->data.val2;
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return newp;
|
2012-05-06 17:22:54 +00:00
|
|
|
}
|
2007-07-09 20:42:14 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static IDProperty *IDP_CopyArray(const IDProperty *prop, const int flag)
|
2007-07-09 20:42:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *newp = idp_generic_copy(prop, flag);
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop->data.pointer) {
|
|
|
|
|
newp->data.pointer = MEM_dupallocN(prop->data.pointer);
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop->type == IDP_GROUP) {
|
|
|
|
|
IDProperty **array = newp->data.pointer;
|
|
|
|
|
int a;
|
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
2008-12-26 20:38:52 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (a = 0; a < prop->len; a++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
array[a] = IDP_CopyProperty_ex(array[a], flag);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
newp->len = prop->len;
|
|
|
|
|
newp->subtype = prop->subtype;
|
|
|
|
|
newp->totallen = prop->totallen;
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return newp;
|
2007-07-09 20:42:14 +00:00
|
|
|
}
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* String Functions */
|
|
|
|
|
|
|
|
|
|
/** \name IDProperty String API
|
|
|
|
|
* \{ */
|
2013-09-05 04:26:08 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param st: The string to assign.
|
|
|
|
|
* \param name: The property name.
|
|
|
|
|
* \param maxlen: The size of the new string (including the \0 terminator).
|
2014-11-15 21:28:29 +01:00
|
|
|
* \return The new string property.
|
2013-09-05 04:26:08 +00:00
|
|
|
*/
|
2010-06-12 17:30:21 +00:00
|
|
|
IDProperty *IDP_NewString(const char *st, const char *name, int maxlen)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop = MEM_callocN(sizeof(IDProperty), "IDProperty string");
|
|
|
|
|
|
|
|
|
|
if (st == NULL) {
|
|
|
|
|
prop->data.pointer = MEM_mallocN(DEFAULT_ALLOC_FOR_NULL_STRINGS, "id property string 1");
|
|
|
|
|
*IDP_String(prop) = '\0';
|
|
|
|
|
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
|
|
|
|
|
prop->len = 1; /* NULL string, has len of 1 to account for null byte. */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* include null terminator '\0' */
|
|
|
|
|
int stlen = (int)strlen(st) + 1;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (maxlen > 0 && maxlen < stlen) {
|
2019-04-17 06:17:24 +02:00
|
|
|
stlen = maxlen;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
prop->data.pointer = MEM_mallocN((size_t)stlen, "id property string 2");
|
|
|
|
|
prop->len = prop->totallen = stlen;
|
|
|
|
|
BLI_strncpy(prop->data.pointer, st, (size_t)stlen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prop->type = IDP_STRING;
|
|
|
|
|
BLI_strncpy(prop->name, name, MAX_IDPROP_NAME);
|
|
|
|
|
|
|
|
|
|
return prop;
|
2010-06-12 17:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static IDProperty *IDP_CopyString(const IDProperty *prop, const int flag)
|
2007-07-09 20:42:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *newp;
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_STRING);
|
|
|
|
|
newp = idp_generic_copy(prop, flag);
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop->data.pointer) {
|
2019-04-17 06:17:24 +02:00
|
|
|
newp->data.pointer = MEM_dupallocN(prop->data.pointer);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
newp->len = prop->len;
|
|
|
|
|
newp->subtype = prop->subtype;
|
|
|
|
|
newp->totallen = prop->totallen;
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return newp;
|
2007-07-09 20:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
void IDP_AssignString(IDProperty *prop, const char *st, int maxlen)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int stlen;
|
|
|
|
|
|
|
|
|
|
BLI_assert(prop->type == IDP_STRING);
|
|
|
|
|
stlen = (int)strlen(st);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (maxlen > 0 && maxlen < stlen) {
|
2019-04-17 06:17:24 +02:00
|
|
|
stlen = maxlen;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (prop->subtype == IDP_STRING_SUB_BYTE) {
|
|
|
|
|
IDP_ResizeArray(prop, stlen);
|
|
|
|
|
memcpy(prop->data.pointer, st, (size_t)stlen);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
stlen++;
|
|
|
|
|
IDP_ResizeArray(prop, stlen);
|
|
|
|
|
BLI_strncpy(prop->data.pointer, st, (size_t)stlen);
|
|
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-19 02:14:18 +00:00
|
|
|
void IDP_ConcatStringC(IDProperty *prop, const char *st)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int newlen;
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_STRING);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
newlen = prop->len + (int)strlen(st);
|
|
|
|
|
/* we have to remember that prop->len includes the null byte for strings.
|
|
|
|
|
* so there's no need to add +1 to the resize function.*/
|
|
|
|
|
IDP_ResizeArray(prop, newlen);
|
|
|
|
|
strcat(prop->data.pointer, st);
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDP_ConcatString(IDProperty *str1, IDProperty *append)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int newlen;
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(append->type == IDP_STRING);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* since ->len for strings includes the NULL byte, we have to subtract one or
|
|
|
|
|
* we'll get an extra null byte after each concatenation operation.*/
|
|
|
|
|
newlen = str1->len + append->len - 1;
|
|
|
|
|
IDP_ResizeArray(str1, newlen);
|
|
|
|
|
strcat(str1->data.pointer, append->data.pointer);
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDP_FreeString(IDProperty *prop)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_STRING);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop->data.pointer) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(prop->data.pointer);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \} */
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
/* ID Type */
|
2006-11-17 04:46:48 +00:00
|
|
|
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
/** \name IDProperty ID API
|
2013-09-30 11:27:03 +00:00
|
|
|
* \{ */
|
2006-11-17 04:46:48 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static IDProperty *IDP_CopyID(const IDProperty *prop, const int flag)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *newp;
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_ID);
|
|
|
|
|
newp = idp_generic_copy(prop, flag);
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
newp->data.pointer = prop->data.pointer;
|
|
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
|
id_us_plus(IDP_Id(newp));
|
|
|
|
|
}
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return newp;
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Group Functions */
|
2007-05-22 04:41:21 +00:00
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \name IDProperty Group API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a property with the same name as prop exists, and if so replaces it.
|
|
|
|
|
*/
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
static IDProperty *IDP_CopyGroup(const IDProperty *prop, const int flag)
|
2007-07-09 20:42:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *newp, *link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_GROUP);
|
|
|
|
|
newp = idp_generic_copy(prop, flag);
|
|
|
|
|
newp->len = prop->len;
|
|
|
|
|
newp->subtype = prop->subtype;
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = prop->data.group.first; link; link = link->next) {
|
|
|
|
|
BLI_addtail(&newp->data.group, IDP_CopyProperty_ex(link, flag));
|
|
|
|
|
}
|
2007-07-09 20:42:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return newp;
|
2007-07-09 20:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 18:43:54 +00:00
|
|
|
/* use for syncing proxies.
|
|
|
|
|
* When values name and types match, copy the values, else ignore */
|
2013-12-12 21:57:37 +11:00
|
|
|
void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src)
|
2010-02-15 18:43:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *other, *prop;
|
|
|
|
|
|
|
|
|
|
BLI_assert(dest->type == IDP_GROUP);
|
|
|
|
|
BLI_assert(src->type == IDP_GROUP);
|
|
|
|
|
|
|
|
|
|
for (prop = src->data.group.first; prop; prop = prop->next) {
|
|
|
|
|
other = BLI_findstring(&dest->data.group, prop->name, offsetof(IDProperty, name));
|
|
|
|
|
if (other && prop->type == other->type) {
|
|
|
|
|
switch (prop->type) {
|
|
|
|
|
case IDP_INT:
|
|
|
|
|
case IDP_FLOAT:
|
|
|
|
|
case IDP_DOUBLE:
|
|
|
|
|
other->data = prop->data;
|
|
|
|
|
break;
|
|
|
|
|
case IDP_GROUP:
|
|
|
|
|
IDP_SyncGroupValues(other, prop);
|
|
|
|
|
break;
|
|
|
|
|
default: {
|
|
|
|
|
BLI_insertlinkreplace(&dest->data.group, other, IDP_CopyProperty(prop));
|
|
|
|
|
IDP_FreeProperty(other);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-15 18:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-13 00:28:35 +11:00
|
|
|
void IDP_SyncGroupTypes(IDProperty *dst, const IDProperty *src, const bool do_arraylen)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop_dst, *prop_dst_next;
|
|
|
|
|
const IDProperty *prop_src;
|
|
|
|
|
|
|
|
|
|
for (prop_dst = dst->data.group.first; prop_dst; prop_dst = prop_dst_next) {
|
|
|
|
|
prop_dst_next = prop_dst->next;
|
|
|
|
|
if ((prop_src = IDP_GetPropertyFromGroup((IDProperty *)src, prop_dst->name))) {
|
|
|
|
|
/* check of we should replace? */
|
|
|
|
|
if ((prop_dst->type != prop_src->type || prop_dst->subtype != prop_src->subtype) ||
|
|
|
|
|
(do_arraylen && ELEM(prop_dst->type, IDP_ARRAY, IDP_IDPARRAY) &&
|
|
|
|
|
(prop_src->len != prop_dst->len))) {
|
|
|
|
|
BLI_insertlinkreplace(&dst->data.group, prop_dst, IDP_CopyProperty(prop_src));
|
|
|
|
|
IDP_FreeProperty(prop_dst);
|
|
|
|
|
}
|
|
|
|
|
else if (prop_dst->type == IDP_GROUP) {
|
|
|
|
|
IDP_SyncGroupTypes(prop_dst, prop_src, do_arraylen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
IDP_FreeFromGroup(dst, prop_dst);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-13 00:28:35 +11:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* Replaces all properties with the same name in a destination group from a source group.
|
2012-03-03 20:19:11 +00:00
|
|
|
*/
|
2013-12-12 21:57:37 +11:00
|
|
|
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src)
|
2010-01-05 03:29:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *loop, *prop;
|
|
|
|
|
|
|
|
|
|
BLI_assert(dest->type == IDP_GROUP);
|
|
|
|
|
BLI_assert(src->type == IDP_GROUP);
|
|
|
|
|
|
|
|
|
|
for (prop = src->data.group.first; prop; prop = prop->next) {
|
|
|
|
|
for (loop = dest->data.group.first; loop; loop = loop->next) {
|
|
|
|
|
if (STREQ(loop->name, prop->name)) {
|
|
|
|
|
BLI_insertlinkreplace(&dest->data.group, loop, IDP_CopyProperty(prop));
|
|
|
|
|
IDP_FreeProperty(loop);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only add at end if not added yet */
|
|
|
|
|
if (loop == NULL) {
|
|
|
|
|
IDProperty *copy = IDP_CopyProperty(prop);
|
|
|
|
|
dest->len++;
|
|
|
|
|
BLI_addtail(&dest->data.group, copy);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-05 03:29:41 +00:00
|
|
|
}
|
2013-03-24 01:51:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a property with the same name as prop exists, and if so replaces it.
|
|
|
|
|
* Use this to preserve order!
|
2012-03-03 20:19:11 +00:00
|
|
|
*/
|
2014-11-10 17:10:58 +01:00
|
|
|
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist)
|
2007-05-22 04:41:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(group->type == IDP_GROUP);
|
|
|
|
|
BLI_assert(prop_exist == IDP_GetPropertyFromGroup(group, prop->name));
|
|
|
|
|
|
|
|
|
|
if (prop_exist != NULL) {
|
|
|
|
|
BLI_insertlinkreplace(&group->data.group, prop_exist, prop);
|
|
|
|
|
IDP_FreeProperty(prop_exist);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
group->len++;
|
|
|
|
|
BLI_addtail(&group->data.group, prop);
|
|
|
|
|
}
|
2007-05-22 04:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-10 17:10:58 +01:00
|
|
|
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop_exist = IDP_GetPropertyFromGroup(group, prop->name);
|
2014-11-10 17:10:58 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_ReplaceInGroup_ex(group, prop, prop_exist);
|
2014-11-10 17:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/**
|
2012-10-31 19:07:25 +00:00
|
|
|
* If a property is missing in \a dest, add it.
|
2017-05-03 11:37:24 +02:00
|
|
|
* Do it recursively.
|
2012-10-31 19:07:25 +00:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void IDP_MergeGroup_ex(IDProperty *dest,
|
|
|
|
|
const IDProperty *src,
|
|
|
|
|
const bool do_overwrite,
|
|
|
|
|
const int flag)
|
2012-10-31 19:07:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop;
|
|
|
|
|
|
|
|
|
|
BLI_assert(dest->type == IDP_GROUP);
|
|
|
|
|
BLI_assert(src->type == IDP_GROUP);
|
|
|
|
|
|
|
|
|
|
if (do_overwrite) {
|
|
|
|
|
for (prop = src->data.group.first; prop; prop = prop->next) {
|
|
|
|
|
if (prop->type == IDP_GROUP) {
|
|
|
|
|
IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop->name);
|
|
|
|
|
|
|
|
|
|
if (prop_exist != NULL) {
|
|
|
|
|
IDP_MergeGroup_ex(prop_exist, prop, do_overwrite, flag);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IDProperty *copy = IDP_CopyProperty_ex(prop, flag);
|
|
|
|
|
IDP_ReplaceInGroup(dest, copy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (prop = src->data.group.first; prop; prop = prop->next) {
|
|
|
|
|
IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop->name);
|
|
|
|
|
if (prop_exist != NULL) {
|
|
|
|
|
if (prop->type == IDP_GROUP) {
|
|
|
|
|
IDP_MergeGroup_ex(prop_exist, prop, do_overwrite, flag);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
IDProperty *copy = IDP_CopyProperty_ex(prop, flag);
|
|
|
|
|
dest->len++;
|
|
|
|
|
BLI_addtail(&dest->data.group, copy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-31 19:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-15 16:42:20 +02:00
|
|
|
/**
|
|
|
|
|
* If a property is missing in \a dest, add it.
|
|
|
|
|
* Do it recursively.
|
|
|
|
|
*/
|
|
|
|
|
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_MergeGroup_ex(dest, src, do_overwrite, 0);
|
2017-08-15 16:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* This function has a sanity check to make sure ID properties with the same name don't
|
|
|
|
|
* get added to the group.
|
|
|
|
|
*
|
|
|
|
|
* The sanity check just means the property is not added to the group if another property
|
|
|
|
|
* exists with the same name; the client code using ID properties then needs to detect this
|
2019-04-27 12:07:07 +10:00
|
|
|
* (the function that adds new properties to groups, #IDP_AddToGroup,
|
|
|
|
|
* returns false if a property can't be added to the group, and true if it can)
|
|
|
|
|
* and free the property.
|
2013-03-24 01:51:54 +00:00
|
|
|
*/
|
2013-12-12 21:57:37 +11:00
|
|
|
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(group->type == IDP_GROUP);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (IDP_GetPropertyFromGroup(group, prop->name) == NULL) {
|
|
|
|
|
group->len++;
|
|
|
|
|
BLI_addtail(&group->data.group, prop);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-11-17 08:19:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* This is the same as IDP_AddToGroup, only you pass an item
|
|
|
|
|
* in the group list to be inserted after.
|
|
|
|
|
*/
|
2013-12-12 21:57:37 +11:00
|
|
|
bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew)
|
2006-12-16 23:54:45 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(group->type == IDP_GROUP);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (IDP_GetPropertyFromGroup(group, pnew->name) == NULL) {
|
|
|
|
|
group->len++;
|
|
|
|
|
BLI_insertlinkafter(&group->data.group, previous, pnew);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-10-06 10:24:32 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2006-12-16 23:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* \note this does not free the property!!
|
|
|
|
|
*
|
|
|
|
|
* To free the property, you have to do:
|
2019-05-16 14:11:11 +02:00
|
|
|
* IDP_FreeProperty(prop);
|
2013-03-24 01:51:54 +00:00
|
|
|
*/
|
2013-10-16 05:29:28 +00:00
|
|
|
void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(group->type == IDP_GROUP);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
group->len--;
|
|
|
|
|
BLI_remlink(&group->data.group, prop);
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-16 05:29:28 +00:00
|
|
|
/**
|
|
|
|
|
* Removes the property from the group and frees it.
|
|
|
|
|
*/
|
|
|
|
|
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDP_RemoveFromGroup(group, prop);
|
|
|
|
|
IDP_FreeProperty(prop);
|
2013-10-16 05:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-18 20:01:35 +00:00
|
|
|
IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_GROUP);
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (IDProperty *)BLI_findstring(&prop->data.group, name, offsetof(IDProperty, name));
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
2013-03-24 01:51:54 +00:00
|
|
|
/** same as above but ensure type match */
|
2011-02-07 05:05:41 +00:00
|
|
|
IDProperty *IDP_GetPropertyTypeFromGroup(IDProperty *prop, const char *name, const char type)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *idprop = IDP_GetPropertyFromGroup(prop, name);
|
|
|
|
|
return (idprop && idprop->type == type) ? idprop : NULL;
|
2011-02-07 05:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-03 20:19:11 +00:00
|
|
|
/* Ok, the way things work, Groups free the ID Property structs of their children.
|
|
|
|
|
* This is because all ID Property freeing functions free only direct data (not the ID Property
|
|
|
|
|
* struct itself), but for Groups the child properties *are* considered
|
|
|
|
|
* direct data. */
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
static void IDP_FreeGroup(IDProperty *prop, const bool do_id_user)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *loop;
|
2013-09-30 11:27:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(prop->type == IDP_GROUP);
|
|
|
|
|
for (loop = prop->data.group.first; loop; loop = loop->next) {
|
2019-05-16 14:17:11 +02:00
|
|
|
IDP_FreePropertyContent_ex(loop, do_id_user);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
BLI_freelistN(&prop->data.group);
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \} */
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Main Functions */
|
|
|
|
|
|
|
|
|
|
/** \name IDProperty Main API
|
|
|
|
|
* \{ */
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
IDProperty *IDP_CopyProperty_ex(const IDProperty *prop, const int flag)
|
2007-07-09 20:42:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (prop->type) {
|
|
|
|
|
case IDP_GROUP:
|
|
|
|
|
return IDP_CopyGroup(prop, flag);
|
|
|
|
|
case IDP_STRING:
|
|
|
|
|
return IDP_CopyString(prop, flag);
|
|
|
|
|
case IDP_ID:
|
|
|
|
|
return IDP_CopyID(prop, flag);
|
|
|
|
|
case IDP_ARRAY:
|
|
|
|
|
return IDP_CopyArray(prop, flag);
|
|
|
|
|
case IDP_IDPARRAY:
|
|
|
|
|
return IDP_CopyIDPArray(prop, flag);
|
|
|
|
|
default:
|
|
|
|
|
return idp_generic_copy(prop, flag);
|
|
|
|
|
}
|
2007-07-09 20:42:14 +00:00
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
IDProperty *IDP_CopyProperty(const IDProperty *prop)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return IDP_CopyProperty_ex(prop, 0);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
/* Updates ID pointers after an object has been copied */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* TODO Nuke this once its only user has been correctly converted
|
|
|
|
|
* to use generic ID management from BKE_library! */
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
void IDP_RelinkProperty(struct IDProperty *prop)
|
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!prop) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
switch (prop->type) {
|
|
|
|
|
case IDP_GROUP: {
|
|
|
|
|
for (IDProperty *loop = prop->data.group.first; loop; loop = loop->next) {
|
|
|
|
|
IDP_RelinkProperty(loop);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IDP_IDPARRAY: {
|
|
|
|
|
IDProperty *idp_array = IDP_Array(prop);
|
|
|
|
|
for (int i = 0; i < prop->len; i++) {
|
|
|
|
|
IDP_RelinkProperty(&idp_array[i]);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IDP_ID: {
|
|
|
|
|
ID *id = IDP_Id(prop);
|
|
|
|
|
if (id && id->newid) {
|
|
|
|
|
id_us_min(IDP_Id(prop));
|
|
|
|
|
prop->data.pointer = id->newid;
|
|
|
|
|
id_us_plus(IDP_Id(prop));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break; /* Nothing to do for other IDProp types. */
|
|
|
|
|
}
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* Get the Group property that contains the id properties for ID id. Set create_if_needed
|
|
|
|
|
* to create the Group property and attach it to id if it doesn't exist; otherwise
|
|
|
|
|
* the function will return NULL if there's no Group property attached to the ID.
|
|
|
|
|
*/
|
2013-12-12 21:57:37 +11:00
|
|
|
IDProperty *IDP_GetProperties(ID *id, const bool create_if_needed)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (id->properties) {
|
|
|
|
|
return id->properties;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (create_if_needed) {
|
|
|
|
|
id->properties = MEM_callocN(sizeof(IDProperty), "IDProperty");
|
|
|
|
|
id->properties->type = IDP_GROUP;
|
|
|
|
|
/* don't overwrite the data's name and type
|
|
|
|
|
* some functions might need this if they
|
|
|
|
|
* don't have a real ID, should be named elsewhere - Campbell */
|
|
|
|
|
/* strcpy(id->name, "top_level_group");*/
|
|
|
|
|
}
|
|
|
|
|
return id->properties;
|
|
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-31 20:29:32 +00:00
|
|
|
/**
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param is_strict: When false treat missing items as a match */
|
2013-12-12 21:57:37 +11:00
|
|
|
bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is_strict)
|
2009-01-28 23:29:27 +00:00
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop1 == NULL && prop2 == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (prop1 == NULL || prop2 == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return is_strict ? false : true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (prop1->type != prop2->type) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
switch (prop1->type) {
|
|
|
|
|
case IDP_INT:
|
|
|
|
|
return (IDP_Int(prop1) == IDP_Int(prop2));
|
|
|
|
|
case IDP_FLOAT:
|
2014-08-11 20:58:42 +06:00
|
|
|
#if !defined(NDEBUG) && defined(WITH_PYTHON)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
|
float p1 = IDP_Float(prop1);
|
|
|
|
|
float p2 = IDP_Float(prop2);
|
|
|
|
|
if ((p1 != p2) && ((fabsf(p1 - p2) / max_ff(p1, p2)) < 0.001f)) {
|
|
|
|
|
printf(
|
|
|
|
|
"WARNING: Comparing two float properties that have nearly the same value (%f vs. "
|
|
|
|
|
"%f)\n",
|
|
|
|
|
p1,
|
|
|
|
|
p2);
|
|
|
|
|
printf(" p1: ");
|
|
|
|
|
IDP_print(prop1);
|
|
|
|
|
printf(" p2: ");
|
|
|
|
|
IDP_print(prop2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-24 16:46:54 +02:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
return (IDP_Float(prop1) == IDP_Float(prop2));
|
|
|
|
|
case IDP_DOUBLE:
|
|
|
|
|
return (IDP_Double(prop1) == IDP_Double(prop2));
|
|
|
|
|
case IDP_STRING: {
|
|
|
|
|
return (((prop1->len == prop2->len) &&
|
|
|
|
|
STREQLEN(IDP_String(prop1), IDP_String(prop2), (size_t)prop1->len)));
|
|
|
|
|
}
|
|
|
|
|
case IDP_ARRAY:
|
|
|
|
|
if (prop1->len == prop2->len && prop1->subtype == prop2->subtype) {
|
|
|
|
|
return (memcmp(IDP_Array(prop1),
|
|
|
|
|
IDP_Array(prop2),
|
|
|
|
|
idp_size_table[(int)prop1->subtype] * (size_t)prop1->len) == 0);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
case IDP_GROUP: {
|
|
|
|
|
IDProperty *link1, *link2;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (is_strict && prop1->len != prop2->len) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
for (link1 = prop1->data.group.first; link1; link1 = link1->next) {
|
|
|
|
|
link2 = IDP_GetPropertyFromGroup(prop2, link1->name);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!IDP_EqualsProperties_ex(link1, link2, is_strict)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case IDP_IDPARRAY: {
|
|
|
|
|
IDProperty *array1 = IDP_IDPArray(prop1);
|
|
|
|
|
IDProperty *array2 = IDP_IDPArray(prop2);
|
|
|
|
|
int i;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (prop1->len != prop2->len) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < prop1->len; i++) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!IDP_EqualsProperties_ex(&array1[i], &array2[i], is_strict)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
case IDP_ID:
|
|
|
|
|
return (IDP_Id(prop1) == IDP_Id(prop2));
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2009-01-28 23:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-12 21:57:37 +11:00
|
|
|
bool IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2)
|
2012-10-31 20:29:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return IDP_EqualsProperties_ex(prop1, prop2, true);
|
2012-10-31 20:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
|
|
|
|
* Allocate a new ID.
|
|
|
|
|
*
|
|
|
|
|
* This function takes three arguments: the ID property type, a union which defines
|
|
|
|
|
* it's initial value, and a name.
|
|
|
|
|
*
|
|
|
|
|
* The union is simple to use; see the top of this header file for its definition.
|
|
|
|
|
* An example of using this function:
|
|
|
|
|
*
|
2017-04-09 16:26:04 +10:00
|
|
|
* \code{.c}
|
|
|
|
|
* IDPropertyTemplate val;
|
|
|
|
|
* IDProperty *group, *idgroup, *color;
|
|
|
|
|
* group = IDP_New(IDP_GROUP, val, "group1"); //groups don't need a template.
|
2013-03-24 01:51:54 +00:00
|
|
|
*
|
2017-04-09 16:26:04 +10:00
|
|
|
* val.array.len = 4
|
|
|
|
|
* val.array.type = IDP_FLOAT;
|
|
|
|
|
* color = IDP_New(IDP_ARRAY, val, "color1");
|
2013-03-24 01:51:54 +00:00
|
|
|
*
|
2017-04-09 16:26:04 +10:00
|
|
|
* idgroup = IDP_GetProperties(some_id, 1);
|
|
|
|
|
* IDP_AddToGroup(idgroup, color);
|
|
|
|
|
* IDP_AddToGroup(idgroup, group);
|
|
|
|
|
* \endcode
|
2013-03-24 01:51:54 +00:00
|
|
|
*
|
|
|
|
|
* Note that you MUST either attach the id property to an id property group with
|
|
|
|
|
* IDP_AddToGroup or MEM_freeN the property, doing anything else might result in
|
|
|
|
|
* a memory leak.
|
|
|
|
|
*/
|
2014-12-12 16:17:52 +01:00
|
|
|
IDProperty *IDP_New(const char type, const IDPropertyTemplate *val, const char *name)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
IDProperty *prop = NULL;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case IDP_INT:
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty int");
|
|
|
|
|
prop->data.val = val->i;
|
|
|
|
|
break;
|
|
|
|
|
case IDP_FLOAT:
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty float");
|
|
|
|
|
*(float *)&prop->data.val = val->f;
|
|
|
|
|
break;
|
|
|
|
|
case IDP_DOUBLE:
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty double");
|
|
|
|
|
*(double *)&prop->data.val = val->d;
|
|
|
|
|
break;
|
|
|
|
|
case IDP_ARRAY: {
|
|
|
|
|
/* for now, we only support float and int and double arrays */
|
|
|
|
|
if ((val->array.type == IDP_FLOAT) || (val->array.type == IDP_INT) ||
|
|
|
|
|
(val->array.type == IDP_DOUBLE) || (val->array.type == IDP_GROUP)) {
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
|
|
|
|
|
prop->subtype = val->array.type;
|
|
|
|
|
if (val->array.len) {
|
|
|
|
|
prop->data.pointer = MEM_callocN(
|
|
|
|
|
idp_size_table[val->array.type] * (size_t)val->array.len, "id property array");
|
|
|
|
|
}
|
|
|
|
|
prop->len = prop->totallen = val->array.len;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
CLOG_ERROR(&LOG, "bad array type.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
case IDP_STRING: {
|
|
|
|
|
const char *st = val->string.str;
|
|
|
|
|
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty string");
|
|
|
|
|
if (val->string.subtype == IDP_STRING_SUB_BYTE) {
|
|
|
|
|
/* note, intentionally not null terminated */
|
|
|
|
|
if (st == NULL) {
|
|
|
|
|
prop->data.pointer = MEM_mallocN(DEFAULT_ALLOC_FOR_NULL_STRINGS, "id property string 1");
|
|
|
|
|
*IDP_String(prop) = '\0';
|
|
|
|
|
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
|
|
|
|
|
prop->len = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
prop->data.pointer = MEM_mallocN((size_t)val->string.len, "id property string 2");
|
|
|
|
|
prop->len = prop->totallen = val->string.len;
|
|
|
|
|
memcpy(prop->data.pointer, st, (size_t)val->string.len);
|
|
|
|
|
}
|
|
|
|
|
prop->subtype = IDP_STRING_SUB_BYTE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (st == NULL || val->string.len <= 1) {
|
|
|
|
|
prop->data.pointer = MEM_mallocN(DEFAULT_ALLOC_FOR_NULL_STRINGS, "id property string 1");
|
|
|
|
|
*IDP_String(prop) = '\0';
|
|
|
|
|
prop->totallen = DEFAULT_ALLOC_FOR_NULL_STRINGS;
|
|
|
|
|
/* NULL string, has len of 1 to account for null byte. */
|
|
|
|
|
prop->len = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert((int)val->string.len <= (int)strlen(st) + 1);
|
|
|
|
|
prop->data.pointer = MEM_mallocN((size_t)val->string.len, "id property string 3");
|
|
|
|
|
memcpy(prop->data.pointer, st, (size_t)val->string.len - 1);
|
|
|
|
|
IDP_String(prop)[val->string.len - 1] = '\0';
|
|
|
|
|
prop->len = prop->totallen = val->string.len;
|
|
|
|
|
}
|
|
|
|
|
prop->subtype = IDP_STRING_SUB_UTF8;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IDP_GROUP: {
|
|
|
|
|
/* Values are set properly by calloc. */
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty group");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IDP_ID: {
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty datablock");
|
|
|
|
|
prop->data.pointer = (void *)val->id;
|
|
|
|
|
prop->type = IDP_ID;
|
|
|
|
|
id_us_plus(IDP_Id(prop));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prop->type = type;
|
|
|
|
|
BLI_strncpy(prop->name, name, MAX_IDPROP_NAME);
|
|
|
|
|
|
|
|
|
|
return prop;
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-24 01:51:54 +00:00
|
|
|
/**
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
* \note This will free allocated data, all child properties of arrays and groups, and unlink IDs!
|
|
|
|
|
* But it does not free the actual IDProperty struct itself.
|
2013-03-24 01:51:54 +00:00
|
|
|
*/
|
2019-05-16 14:17:11 +02:00
|
|
|
void IDP_FreePropertyContent_ex(IDProperty *prop, const bool do_id_user)
|
2006-11-17 04:46:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (prop->type) {
|
|
|
|
|
case IDP_ARRAY:
|
|
|
|
|
IDP_FreeArray(prop);
|
|
|
|
|
break;
|
|
|
|
|
case IDP_STRING:
|
|
|
|
|
IDP_FreeString(prop);
|
|
|
|
|
break;
|
|
|
|
|
case IDP_GROUP:
|
|
|
|
|
IDP_FreeGroup(prop, do_id_user);
|
|
|
|
|
break;
|
|
|
|
|
case IDP_IDPARRAY:
|
|
|
|
|
IDP_FreeIDPArray(prop, do_id_user);
|
|
|
|
|
break;
|
|
|
|
|
case IDP_ID:
|
|
|
|
|
if (do_id_user) {
|
|
|
|
|
id_us_min(IDP_Id(prop));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-11-17 04:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 14:11:11 +02:00
|
|
|
void IDP_FreePropertyContent(IDProperty *prop)
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
{
|
2019-05-16 14:17:11 +02:00
|
|
|
IDP_FreePropertyContent_ex(prop, true);
|
Datablock ID Properties
The absence of datablock properties "will certainly be resolved soon as the need for them is becoming obvious" said the [[http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.67/Python_Nodes|Python Nodes release notes]]. So this patch allows Python scripts to create ID Properties which reference datablocks.
This functionality is implemented for `PointerProperty` and now such properties can be created with Python.
In addition to the standard update callback, `PointerProperty` can have a `poll` callback (standard RNA) which is useful for search menus. For details see the test included in this patch.
Original author: @artfunkel
Alexander (Blend4Web Team)
Reviewers: brecht, artfunkel, mont29, campbellbarton
Reviewed By: mont29, campbellbarton
Subscribers: jta, sergey, campbellbarton, wisaac, poseidon4o, mont29, homyachetser, Evgeny_Rodygin, AlexKowel, yurikovelenov, fjuhec, sharlybg, cardboard, duarteframos, blueprintrandom, a.romanov, BYOB, disnel, aditiapratama, bliblubli, dfelinto, lukastoenne
Maniphest Tasks: T37754
Differential Revision: https://developer.blender.org/D113
2017-04-13 12:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 14:11:11 +02:00
|
|
|
void IDP_FreeProperty(IDProperty *prop)
|
|
|
|
|
{
|
|
|
|
|
IDP_FreePropertyContent(prop);
|
|
|
|
|
MEM_freeN(prop);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-02 23:10:14 +00:00
|
|
|
void IDP_ClearProperty(IDProperty *prop)
|
|
|
|
|
{
|
2019-05-16 14:11:11 +02:00
|
|
|
IDP_FreePropertyContent(prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
prop->data.pointer = NULL;
|
|
|
|
|
prop->len = prop->totallen = 0;
|
2013-01-02 23:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-24 15:00:01 +01:00
|
|
|
void IDP_Reset(IDProperty *prop, const IDProperty *reference)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (prop == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
IDP_ClearProperty(prop);
|
|
|
|
|
if (reference != NULL) {
|
|
|
|
|
IDP_MergeGroup(prop, reference, true);
|
|
|
|
|
}
|
2018-01-24 15:00:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-30 11:27:03 +00:00
|
|
|
/** \} */
|