2011-02-18 14:05:18 +01:00
|
|
|
/*
|
2006-11-30 00:31:46 +01: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-04-17 00:40:48 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2006-11-30 00:31:46 +01: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 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-11-30 00:31:46 +01:00
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#pragma once
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 14:05:18 +01:00
|
|
|
*/
|
|
|
|
|
2013-09-01 17:01:15 +02:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2018-01-24 15:00:01 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-08-21 12:45:33 +02:00
|
|
|
struct BlendDataReader;
|
|
|
|
struct BlendExpander;
|
2020-09-30 03:51:13 +02:00
|
|
|
struct BlendLibReader;
|
|
|
|
struct BlendWriter;
|
|
|
|
struct ID;
|
|
|
|
struct IDProperty;
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
struct IDPropertyUIData;
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2010-10-21 09:39:18 +02:00
|
|
|
typedef union IDPropertyTemplate {
|
2006-11-17 05:46:48 +01:00
|
|
|
int i;
|
|
|
|
float f;
|
2008-07-24 21:22:17 +02:00
|
|
|
double d;
|
2011-11-15 10:12:10 +01:00
|
|
|
struct {
|
2015-01-01 13:26:03 +01:00
|
|
|
const char *str;
|
2014-12-12 16:17:52 +01:00
|
|
|
int len;
|
2011-11-15 10:12:10 +01:00
|
|
|
char subtype;
|
|
|
|
} string;
|
2006-11-17 05:46:48 +01:00
|
|
|
struct ID *id;
|
|
|
|
struct {
|
2014-12-12 16:17:52 +01:00
|
|
|
int len;
|
|
|
|
char type;
|
2006-11-17 05:46:48 +01:00
|
|
|
} array;
|
|
|
|
struct {
|
|
|
|
int matvec_size;
|
2015-01-01 13:26:03 +01:00
|
|
|
const float *example;
|
2006-11-17 05:46:48 +01:00
|
|
|
} matrix_or_vector;
|
|
|
|
} IDPropertyTemplate;
|
|
|
|
|
2008-12-31 14:16:37 +01:00
|
|
|
/* ----------- Property Array Type ---------- */
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \note as a start to move away from the stupid #IDP_New function,
|
|
|
|
* this type has its own allocation function.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyIDPArray(const struct IDProperty *array,
|
2022-01-07 01:38:08 +01:00
|
|
|
int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2008-12-31 14:16:37 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Shallow copies item.
|
|
|
|
*/
|
2013-09-01 17:01:15 +02:00
|
|
|
void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
2012-07-08 08:00:27 +02:00
|
|
|
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
|
2008-12-31 14:16:37 +01:00
|
|
|
void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
|
|
|
|
|
|
|
|
/* ----------- Numeric Array Type ----------- */
|
2021-12-07 07:19:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function works for strings too!
|
|
|
|
*/
|
2006-11-17 05:46:48 +01:00
|
|
|
void IDP_ResizeArray(struct IDProperty *prop, int newlen);
|
|
|
|
void IDP_FreeArray(struct IDProperty *prop);
|
|
|
|
|
|
|
|
/* ---------- String Type ------------ */
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \param st: The string to assign.
|
|
|
|
* \param name: The property name.
|
|
|
|
* \param maxlen: The size of the new string (including the \0 terminator).
|
|
|
|
* \return The new string property.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *IDP_NewString(const char *st,
|
|
|
|
const char *name,
|
|
|
|
int maxlen) ATTR_WARN_UNUSED_RESULT
|
2013-09-01 17:01:15 +02:00
|
|
|
ATTR_NONNULL(2 /* 'name 'arg */); /* maxlen excludes '\0' */
|
|
|
|
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen)
|
|
|
|
ATTR_NONNULL(); /* maxlen excludes '\0' */
|
|
|
|
void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL();
|
|
|
|
void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL();
|
|
|
|
void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
|
|
|
/*-------- ID Type -------*/
|
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 11:30:03 +02:00
|
|
|
|
2020-12-15 00:47:58 +01:00
|
|
|
typedef void (*IDPWalkFunc)(void *userData, struct IDProperty *idp);
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2022-01-07 01:38:08 +01:00
|
|
|
void IDP_AssignID(struct IDProperty *prop, struct ID *id, int flag);
|
2020-01-24 11:26:02 +01:00
|
|
|
|
2006-11-17 05:46:48 +01:00
|
|
|
/*-------- Group Functions -------*/
|
2007-05-22 06:41:21 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Sync values from one group to another when values name and types match,
|
|
|
|
* copy the values, else ignore.
|
|
|
|
*
|
|
|
|
* \note Use for syncing proxies.
|
|
|
|
*/
|
2013-12-12 11:57:37 +01:00
|
|
|
void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2022-01-07 01:38:08 +01:00
|
|
|
void IDP_SyncGroupTypes(struct IDProperty *dest, const struct IDProperty *src, bool do_arraylen)
|
|
|
|
ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Replaces all properties with the same name in a destination group from a source group.
|
|
|
|
*/
|
2013-12-12 11:57:37 +01:00
|
|
|
void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2013-09-01 17:01:15 +02:00
|
|
|
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Checks if a property with the same name as prop exists, and if so replaces it.
|
|
|
|
* Use this to preserve order!
|
|
|
|
*/
|
2014-11-10 17:10:58 +01:00
|
|
|
void IDP_ReplaceInGroup_ex(struct IDProperty *group,
|
|
|
|
struct IDProperty *prop,
|
|
|
|
struct IDProperty *prop_exist);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* If a property is missing in \a dest, add it.
|
|
|
|
* Do it recursively.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, bool do_overwrite)
|
2013-12-12 11:57:37 +01:00
|
|
|
ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* If a property is missing in \a dest, add it.
|
|
|
|
* Do it recursively.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_MergeGroup_ex(struct IDProperty *dest,
|
|
|
|
const struct IDProperty *src,
|
2022-01-07 01:38:08 +01:00
|
|
|
bool do_overwrite,
|
|
|
|
int flag) ATTR_NONNULL();
|
2021-12-07 07:19:15 +01: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
|
|
|
|
* (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-12-12 11:57:37 +01:00
|
|
|
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* This is the same as IDP_AddToGroup, only you pass an item
|
|
|
|
* in the group list to be inserted after.
|
|
|
|
*/
|
2013-12-12 11:57:37 +01:00
|
|
|
bool IDP_InsertToGroup(struct IDProperty *group,
|
|
|
|
struct IDProperty *previous,
|
2013-09-01 17:01:15 +02:00
|
|
|
struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \note this does not free the property!
|
|
|
|
*
|
|
|
|
* To free the property, you have to do:
|
|
|
|
* #IDP_FreeProperty(prop);
|
|
|
|
*/
|
2013-10-16 07:29:28 +02:00
|
|
|
void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Removes the property from the group and frees it.
|
|
|
|
*/
|
2013-10-16 07:29:28 +02:00
|
|
|
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2006-12-01 04:04:36 +01:00
|
|
|
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *IDP_GetPropertyFromGroup(const struct IDProperty *prop,
|
|
|
|
const char *name) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Same as above but ensure type match.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *IDP_GetPropertyTypeFromGroup(const struct IDProperty *prop,
|
|
|
|
const char *name,
|
2022-01-07 01:38:08 +01:00
|
|
|
char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
|
|
|
/*-------- Main Functions --------*/
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the Group property that contains the id properties for ID id.
|
|
|
|
*
|
|
|
|
* \param create_if_needed: Set 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.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
struct IDProperty *IDP_GetProperties(struct ID *id, bool create_if_needed) ATTR_WARN_UNUSED_RESULT
|
2013-12-12 11:57:37 +01:00
|
|
|
ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT
|
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
|
|
|
ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyProperty_ex(const struct IDProperty *prop,
|
2022-01-07 01:38:08 +01:00
|
|
|
int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Copy content from source #IDProperty into destination one,
|
|
|
|
* freeing destination property's content first.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \param is_strict: When false treat missing items as a match.
|
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
bool IDP_EqualsProperties_ex(struct IDProperty *prop1,
|
|
|
|
struct IDProperty *prop2,
|
2022-01-07 01:38:08 +01:00
|
|
|
bool is_strict) ATTR_WARN_UNUSED_RESULT;
|
2012-10-31 21:29:32 +01:00
|
|
|
|
2013-12-12 11:57:37 +01:00
|
|
|
bool IDP_EqualsProperties(struct IDProperty *prop1,
|
|
|
|
struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT;
|
2009-01-29 00:29:27 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Allocate a new ID.
|
|
|
|
*
|
|
|
|
* This function takes three arguments: the ID property type, a union which defines
|
|
|
|
* its initial value, and a name.
|
|
|
|
*
|
|
|
|
* The union is simple to use; see the top of BKE_idprop.h for its definition.
|
|
|
|
* An example of using this function:
|
|
|
|
*
|
|
|
|
* \code{.c}
|
|
|
|
* IDPropertyTemplate val;
|
|
|
|
* IDProperty *group, *idgroup, *color;
|
|
|
|
* group = IDP_New(IDP_GROUP, val, "group1"); // groups don't need a template.
|
|
|
|
*
|
|
|
|
* val.array.len = 4
|
|
|
|
* val.array.type = IDP_FLOAT;
|
|
|
|
* color = IDP_New(IDP_ARRAY, val, "color1");
|
|
|
|
*
|
|
|
|
* idgroup = IDP_GetProperties(some_id, 1);
|
|
|
|
* IDP_AddToGroup(idgroup, color);
|
|
|
|
* IDP_AddToGroup(idgroup, group);
|
|
|
|
* \endcode
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
struct IDProperty *IDP_New(char type,
|
2014-12-12 16:17:52 +01:00
|
|
|
const IDPropertyTemplate *val,
|
|
|
|
const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-04-08 11:31:13 +02:00
|
|
|
|
2021-12-07 07:19:15 +01: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.
|
|
|
|
*/
|
2022-01-07 01:38:08 +01:00
|
|
|
void IDP_FreePropertyContent_ex(struct IDProperty *prop, bool do_id_user);
|
2019-05-16 14:11:11 +02:00
|
|
|
void IDP_FreePropertyContent(struct IDProperty *prop);
|
2022-01-07 01:38:08 +01:00
|
|
|
void IDP_FreeProperty_ex(struct IDProperty *prop, bool do_id_user);
|
2006-11-17 05:46:48 +01:00
|
|
|
void IDP_FreeProperty(struct IDProperty *prop);
|
|
|
|
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_ClearProperty(struct IDProperty *prop);
|
2013-01-03 00:10:14 +01:00
|
|
|
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference);
|
2018-01-24 15:00:01 +01:00
|
|
|
|
2012-11-03 19:23:30 +01:00
|
|
|
#define IDP_Int(prop) ((prop)->data.val)
|
|
|
|
#define IDP_Array(prop) ((prop)->data.pointer)
|
2014-08-01 13:59:42 +02:00
|
|
|
/* C11 const correctness for casts */
|
|
|
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_Float(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *: (*(float *)&(prop)->data.val), \
|
|
|
|
const struct IDProperty *: (*(const float *)&(prop)->data.val))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_Double(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *: (*(double *)&(prop)->data.val), \
|
|
|
|
const struct IDProperty *: (*(const double *)&(prop)->data.val))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_String(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *: ((char *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const char *) (prop)->data.pointer))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_IDPArray(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *: ((struct IDProperty *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const struct IDProperty *) (prop)->data.pointer))
|
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 11:30:03 +02:00
|
|
|
# define IDP_Id(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty *: ((ID *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const ID *) (prop)->data.pointer))
|
2014-08-01 13:59:42 +02:00
|
|
|
#else
|
|
|
|
# define IDP_Float(prop) (*(float *)&(prop)->data.val)
|
|
|
|
# define IDP_Double(prop) (*(double *)&(prop)->data.val)
|
|
|
|
# define IDP_String(prop) ((char *)(prop)->data.pointer)
|
2020-12-15 00:47:58 +01:00
|
|
|
# define IDP_IDPArray(prop) ((struct IDProperty *)(prop)->data.pointer)
|
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 11:30:03 +02:00
|
|
|
# define IDP_Id(prop) ((ID *)(prop)->data.pointer)
|
2014-08-01 13:59:42 +02:00
|
|
|
#endif
|
2008-05-11 22:40:55 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return an int from an #IDProperty with a compatible type. This should be avoided, but
|
|
|
|
* it's sometimes necessary, for example when legacy files have incorrect property types.
|
|
|
|
*/
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
int IDP_coerce_to_int_or_zero(const struct IDProperty *prop);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return a float from an #IDProperty with a compatible type. This should be avoided, but
|
|
|
|
* it's sometimes necessary, for example when legacy files have incorrect property types.
|
|
|
|
*/
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
float IDP_coerce_to_float_or_zero(const struct IDProperty *prop);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return a double from an #IDProperty with a compatible type. This should be avoided, but
|
|
|
|
* it's sometimes necessary, for example when legacy files have incorrect property types.
|
|
|
|
*/
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
double IDP_coerce_to_double_or_zero(const struct IDProperty *prop);
|
|
|
|
|
2020-04-25 20:58:55 +02:00
|
|
|
/**
|
2021-12-07 07:19:15 +01:00
|
|
|
* Call a callback for each #IDproperty in the hierarchy under given root one (included).
|
2020-04-25 20:58:55 +02:00
|
|
|
*/
|
2020-12-15 00:47:58 +01:00
|
|
|
typedef void (*IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data);
|
2020-04-25 20:58:55 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Loop through all ID properties in hierarchy of given \a id_property_root included.
|
|
|
|
*
|
|
|
|
* \note Container types (groups and arrays) are processed after applying the callback on them.
|
|
|
|
*
|
|
|
|
* \param type_filter: If not 0, only apply callback on properties of matching types, see
|
|
|
|
* IDP_TYPE_FILTER_ enum in DNA_ID.h.
|
|
|
|
*/
|
2020-04-25 20:58:55 +02:00
|
|
|
void IDP_foreach_property(struct IDProperty *id_property_root,
|
2022-01-07 01:38:08 +01:00
|
|
|
int type_filter,
|
2020-04-25 20:58:55 +02:00
|
|
|
IDPForeachPropertyCallback callback,
|
|
|
|
void *user_data);
|
|
|
|
|
2018-05-05 14:27:54 +02:00
|
|
|
/* Format IDProperty as strings */
|
|
|
|
char *IDP_reprN(const struct IDProperty *prop, uint *r_len);
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_repr_fn(const struct IDProperty *prop,
|
2018-05-05 14:27:54 +02:00
|
|
|
void (*str_append_fn)(void *user_data, const char *str, uint str_len),
|
|
|
|
void *user_data);
|
2018-05-04 07:26:42 +02:00
|
|
|
void IDP_print(const struct IDProperty *prop);
|
2012-10-31 21:29:32 +01:00
|
|
|
|
2020-08-21 12:45:33 +02:00
|
|
|
void IDP_BlendWrite(struct BlendWriter *writer, const struct IDProperty *prop);
|
2020-08-28 13:18:24 +02:00
|
|
|
void IDP_BlendReadData_impl(struct BlendDataReader *reader,
|
2020-12-15 00:47:58 +01:00
|
|
|
struct IDProperty **prop,
|
2020-08-21 12:45:33 +02:00
|
|
|
const char *caller_func_id);
|
2020-08-28 13:18:24 +02:00
|
|
|
#define IDP_BlendDataRead(reader, prop) IDP_BlendReadData_impl(reader, prop, __func__)
|
2020-12-15 00:47:58 +01:00
|
|
|
void IDP_BlendReadLib(struct BlendLibReader *reader, struct IDProperty *prop);
|
|
|
|
void IDP_BlendReadExpand(struct BlendExpander *expander, struct IDProperty *prop);
|
2020-08-21 12:45:33 +02:00
|
|
|
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
typedef enum eIDPropertyUIDataType {
|
|
|
|
/** Other properties types that don't support RNA UI data. */
|
|
|
|
IDP_UI_DATA_TYPE_UNSUPPORTED = -1,
|
|
|
|
/** IDP_INT or IDP_ARRAY with subtype IDP_INT. */
|
|
|
|
IDP_UI_DATA_TYPE_INT = 0,
|
|
|
|
/** IDP_FLOAT and IDP_DOUBLE or IDP_ARRAY properties with a float or double subtypes. */
|
|
|
|
IDP_UI_DATA_TYPE_FLOAT = 1,
|
|
|
|
/** IDP_STRING properties. */
|
|
|
|
IDP_UI_DATA_TYPE_STRING = 2,
|
|
|
|
/** IDP_ID. */
|
|
|
|
IDP_UI_DATA_TYPE_ID = 3,
|
|
|
|
} eIDPropertyUIDataType;
|
|
|
|
|
|
|
|
bool IDP_ui_data_supported(const struct IDProperty *prop);
|
|
|
|
eIDPropertyUIDataType IDP_ui_data_type(const struct IDProperty *prop);
|
|
|
|
void IDP_ui_data_free(struct IDProperty *prop);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Free allocated pointers in the UI data that isn't shared with the UI data in the `other`
|
|
|
|
* argument. Useful for returning early on failure when updating UI data in place, or when
|
|
|
|
* replacing a subset of the UI data's allocated pointers.
|
|
|
|
*/
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 15:27:24 +02:00
|
|
|
void IDP_ui_data_free_unique_contents(struct IDPropertyUIData *ui_data,
|
|
|
|
eIDPropertyUIDataType type,
|
|
|
|
const struct IDPropertyUIData *other);
|
|
|
|
struct IDPropertyUIData *IDP_ui_data_ensure(struct IDProperty *prop);
|
|
|
|
struct IDPropertyUIData *IDP_ui_data_copy(const struct IDProperty *prop);
|
|
|
|
|
2018-01-24 15:00:01 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|