2011-02-18 13:05:18 +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-04-16 22:40:48 +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
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-08-07 09:50:34 +02:00
|
|
|
#pragma once
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-01 15:01:15 +00: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 11:51:13 +10:00
|
|
|
struct BlendLibReader;
|
|
|
|
struct BlendWriter;
|
|
|
|
struct ID;
|
|
|
|
struct IDProperty;
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2010-10-21 07:39:18 +00:00
|
|
|
typedef union IDPropertyTemplate {
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
struct {
|
|
|
|
const char *str;
|
|
|
|
int len;
|
|
|
|
char subtype;
|
|
|
|
} string;
|
|
|
|
struct ID *id;
|
|
|
|
struct {
|
|
|
|
int len;
|
|
|
|
char type;
|
|
|
|
} array;
|
|
|
|
struct {
|
|
|
|
int matvec_size;
|
|
|
|
const float *example;
|
|
|
|
} matrix_or_vector;
|
2006-11-17 04:46:48 +00:00
|
|
|
} IDPropertyTemplate;
|
|
|
|
|
2008-12-31 13:16:37 +00:00
|
|
|
/* ----------- Property Array Type ---------- */
|
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyIDPArray(const struct IDProperty *array,
|
|
|
|
const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2008-12-31 13:16:37 +00:00
|
|
|
|
|
|
|
/* shallow copies item */
|
2013-09-01 15:01:15 +00:00
|
|
|
void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL();
|
2019-04-17 06:17:24 +02:00
|
|
|
struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
2012-07-08 06:00:27 +00:00
|
|
|
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
|
2008-12-31 13:16:37 +00:00
|
|
|
void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
|
|
|
|
|
|
|
|
/* ----------- Numeric Array Type ----------- */
|
2006-11-17 04:46:48 +00:00
|
|
|
/*this function works for strings too!*/
|
|
|
|
void IDP_ResizeArray(struct IDProperty *prop, int newlen);
|
|
|
|
void IDP_FreeArray(struct IDProperty *prop);
|
|
|
|
|
|
|
|
/* ---------- String Type ------------ */
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *IDP_NewString(const char *st,
|
|
|
|
const char *name,
|
|
|
|
int maxlen) ATTR_WARN_UNUSED_RESULT
|
2019-04-17 06:17:24 +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' */
|
2013-09-01 15:01:15 +00:00
|
|
|
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 04:46:48 +00: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 12:30:03 +03:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
typedef void (*IDPWalkFunc)(void *userData, struct IDProperty *idp);
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_AssignID(struct IDProperty *prop, struct ID *id, const int flag);
|
2020-01-24 11:26:02 +01:00
|
|
|
|
2006-11-17 04:46:48 +00:00
|
|
|
/*-------- Group Functions -------*/
|
2007-05-22 04:41:21 +00:00
|
|
|
|
2011-04-08 09:31:13 +00:00
|
|
|
/** Sync values from one group to another, only where they match */
|
2013-12-12 21:57:37 +11:00
|
|
|
void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2019-04-17 06:17:24 +02:00
|
|
|
void IDP_SyncGroupTypes(struct IDProperty *dest,
|
|
|
|
const struct IDProperty *src,
|
|
|
|
const bool do_arraylen) ATTR_NONNULL();
|
2013-12-12 21:57:37 +11:00
|
|
|
void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2013-09-01 15:01:15 +00:00
|
|
|
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2019-04-17 06:17:24 +02:00
|
|
|
void IDP_ReplaceInGroup_ex(struct IDProperty *group,
|
|
|
|
struct IDProperty *prop,
|
|
|
|
struct IDProperty *prop_exist);
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_MergeGroup(struct IDProperty *dest, const struct IDProperty *src, const bool do_overwrite)
|
2019-04-17 06:17:24 +02:00
|
|
|
ATTR_NONNULL();
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_MergeGroup_ex(struct IDProperty *dest,
|
|
|
|
const struct IDProperty *src,
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool do_overwrite,
|
|
|
|
const int flag) ATTR_NONNULL();
|
2013-12-12 21:57:37 +11:00
|
|
|
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2019-04-17 06:17:24 +02:00
|
|
|
bool IDP_InsertToGroup(struct IDProperty *group,
|
|
|
|
struct IDProperty *previous,
|
|
|
|
struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
|
2013-10-16 05:29:28 +00:00
|
|
|
void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
|
|
|
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2006-12-01 03:04:36 +00:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *IDP_GetPropertyFromGroup(const struct IDProperty *prop,
|
|
|
|
const char *name) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_GetPropertyTypeFromGroup(const struct IDProperty *prop,
|
|
|
|
const char *name,
|
|
|
|
const char type) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
2006-11-17 04:46:48 +00:00
|
|
|
|
|
|
|
/*-------- Main Functions --------*/
|
2019-04-17 06:17:24 +02:00
|
|
|
struct IDProperty *IDP_GetProperties(struct ID *id,
|
|
|
|
const bool create_if_needed) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyProperty_ex(const struct IDProperty *prop,
|
|
|
|
const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_CopyPropertyContent(struct IDProperty *dst, struct IDProperty *src) ATTR_NONNULL();
|
2006-11-17 04:46:48 +00:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
bool IDP_EqualsProperties_ex(struct IDProperty *prop1,
|
|
|
|
struct IDProperty *prop2,
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool is_strict) ATTR_WARN_UNUSED_RESULT;
|
2012-10-31 20:29:32 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool IDP_EqualsProperties(struct IDProperty *prop1,
|
|
|
|
struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT;
|
2009-01-28 23:29:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
struct IDProperty *IDP_New(const char type,
|
|
|
|
const IDPropertyTemplate *val,
|
|
|
|
const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-04-08 09:31:13 +00:00
|
|
|
|
2019-05-16 14:17:11 +02:00
|
|
|
void IDP_FreePropertyContent_ex(struct IDProperty *prop, const bool do_id_user);
|
2019-05-16 14:11:11 +02:00
|
|
|
void IDP_FreePropertyContent(struct IDProperty *prop);
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_FreeProperty_ex(struct IDProperty *prop, const bool do_id_user);
|
2006-11-17 04:46:48 +00:00
|
|
|
void IDP_FreeProperty(struct IDProperty *prop);
|
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_ClearProperty(struct IDProperty *prop);
|
2013-01-02 23:10:14 +00:00
|
|
|
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_Reset(struct IDProperty *prop, const struct IDProperty *reference);
|
2018-01-24 15:00:01 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#define IDP_Int(prop) ((prop)->data.val)
|
|
|
|
#define IDP_Array(prop) ((prop)->data.pointer)
|
2014-08-01 21:59:42 +10:00
|
|
|
/* C11 const correctness for casts */
|
|
|
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_Float(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *: (*(float *)&(prop)->data.val), \
|
|
|
|
const struct IDProperty *: (*(const float *)&(prop)->data.val))
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_Double(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *: (*(double *)&(prop)->data.val), \
|
|
|
|
const struct IDProperty *: (*(const double *)&(prop)->data.val))
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_String(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *: ((char *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const char *) (prop)->data.pointer))
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_IDPArray(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *: ((struct IDProperty *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const struct IDProperty *) (prop)->data.pointer))
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_Id(prop) \
|
|
|
|
_Generic((prop), \
|
2020-12-15 10:47:58 +11:00
|
|
|
struct IDProperty *: ((ID *) (prop)->data.pointer), \
|
|
|
|
const struct IDProperty *: ((const ID *) (prop)->data.pointer))
|
2014-08-01 21:59:42 +10:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
# 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 10:47:58 +11:00
|
|
|
# define IDP_IDPArray(prop) ((struct IDProperty *)(prop)->data.pointer)
|
2019-04-17 06:17:24 +02:00
|
|
|
# define IDP_Id(prop) ((ID *)(prop)->data.pointer)
|
2014-08-01 21:59:42 +10:00
|
|
|
#endif
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2020-04-25 20:58:55 +02:00
|
|
|
/**
|
|
|
|
* Call a callback for each idproperty in the hierarchy under given root one (included).
|
|
|
|
*
|
|
|
|
*/
|
2020-12-15 10:47:58 +11:00
|
|
|
typedef void (*IDPForeachPropertyCallback)(struct IDProperty *id_property, void *user_data);
|
2020-04-25 20:58:55 +02:00
|
|
|
|
|
|
|
void IDP_foreach_property(struct IDProperty *id_property_root,
|
|
|
|
const int type_filter,
|
|
|
|
IDPForeachPropertyCallback callback,
|
|
|
|
void *user_data);
|
|
|
|
|
2018-05-05 14:27:54 +02:00
|
|
|
/* Format IDProperty as strings */
|
2019-04-17 06:17:24 +02:00
|
|
|
char *IDP_reprN(const struct IDProperty *prop, uint *r_len);
|
2020-12-15 10:47:58 +11:00
|
|
|
void IDP_repr_fn(const struct IDProperty *prop,
|
2019-04-17 06:17:24 +02:00
|
|
|
void (*str_append_fn)(void *user_data, const char *str, uint str_len),
|
|
|
|
void *user_data);
|
|
|
|
void IDP_print(const struct IDProperty *prop);
|
2012-10-31 20:29:32 +00: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 10:47:58 +11: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 10:47:58 +11: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
|
|
|
|
2018-01-24 15:00:01 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|