Blender  V2.59
rna_internal_types.h
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_internal_types.h 37335 2011-06-09 13:46:34Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Blender Foundation (2008).
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #ifndef RNA_INTERNAL_TYPES_H
00031 #define RNA_INTERNAL_TYPES_H
00032 
00033 #include "DNA_listBase.h"
00034 
00035 struct BlenderRNA;
00036 struct ContainerRNA;
00037 struct StructRNA;
00038 struct PropertyRNA;
00039 struct PointerRNA;
00040 struct FunctionRNA;
00041 struct ReportList;
00042 struct CollectionPropertyIterator;
00043 struct bContext;
00044 struct EnumProperty;
00045 struct IDProperty;
00046 struct GHash;
00047 struct Main;
00048 struct Scene;
00049 
00050 #ifdef UNIT_TEST
00051 #define RNA_MAX_ARRAY_LENGTH 64
00052 #else
00053 #define RNA_MAX_ARRAY_LENGTH 32
00054 #endif
00055 
00056 #define RNA_MAX_ARRAY_DIMENSION 3
00057 
00058 
00059 /* store local properties here */
00060 #define RNA_IDP_UI "_RNA_UI"
00061 
00062 /* Function Callbacks */
00063 
00064 typedef void (*UpdateFunc)(struct Main *main, struct Scene *scene, struct PointerRNA *ptr);
00065 typedef void (*ContextPropUpdateFunc)(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop);
00066 typedef void (*ContextUpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
00067 typedef int (*EditableFunc)(struct PointerRNA *ptr);
00068 typedef int (*ItemEditableFunc)(struct PointerRNA *ptr, int index);
00069 typedef struct IDProperty* (*IDPropertiesFunc)(struct PointerRNA *ptr, int create);
00070 typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr);
00071 typedef char *(*StructPathFunc)(struct PointerRNA *ptr);
00072 
00073 typedef int (*PropArrayLengthGetFunc)(struct PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]);
00074 typedef int (*PropBooleanGetFunc)(struct PointerRNA *ptr);
00075 typedef void (*PropBooleanSetFunc)(struct PointerRNA *ptr, int value);
00076 typedef void (*PropBooleanArrayGetFunc)(struct PointerRNA *ptr, int *values);
00077 typedef void (*PropBooleanArraySetFunc)(struct PointerRNA *ptr, const int *values);
00078 typedef int (*PropIntGetFunc)(struct PointerRNA *ptr);
00079 typedef void (*PropIntSetFunc)(struct PointerRNA *ptr, int value);
00080 typedef void (*PropIntArrayGetFunc)(struct PointerRNA *ptr, int *values);
00081 typedef void (*PropIntArraySetFunc)(struct PointerRNA *ptr, const int *values);
00082 typedef void (*PropIntRangeFunc)(struct PointerRNA *ptr, int *min, int *max);
00083 typedef float (*PropFloatGetFunc)(struct PointerRNA *ptr);
00084 typedef void (*PropFloatSetFunc)(struct PointerRNA *ptr, float value);
00085 typedef void (*PropFloatArrayGetFunc)(struct PointerRNA *ptr, float *values);
00086 typedef void (*PropFloatArraySetFunc)(struct PointerRNA *ptr, const float *values);
00087 typedef void (*PropFloatRangeFunc)(struct PointerRNA *ptr, float *min, float *max);
00088 typedef void (*PropStringGetFunc)(struct PointerRNA *ptr, char *value);
00089 typedef int (*PropStringLengthFunc)(struct PointerRNA *ptr);
00090 typedef void (*PropStringSetFunc)(struct PointerRNA *ptr, const char *value);
00091 typedef int (*PropEnumGetFunc)(struct PointerRNA *ptr);
00092 typedef void (*PropEnumSetFunc)(struct PointerRNA *ptr, int value);
00093 typedef EnumPropertyItem *(*PropEnumItemFunc)(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int *free);
00094 typedef PointerRNA (*PropPointerGetFunc)(struct PointerRNA *ptr);
00095 typedef StructRNA* (*PropPointerTypeFunc)(struct PointerRNA *ptr);
00096 typedef void (*PropPointerSetFunc)(struct PointerRNA *ptr, const PointerRNA value);
00097 typedef int (*PropPointerPollFunc)(struct PointerRNA *ptr, const PointerRNA value);
00098 typedef void (*PropCollectionBeginFunc)(struct CollectionPropertyIterator *iter, struct PointerRNA *ptr);
00099 typedef void (*PropCollectionNextFunc)(struct CollectionPropertyIterator *iter);
00100 typedef void (*PropCollectionEndFunc)(struct CollectionPropertyIterator *iter);
00101 typedef PointerRNA (*PropCollectionGetFunc)(struct CollectionPropertyIterator *iter);
00102 typedef int (*PropCollectionLengthFunc)(struct PointerRNA *ptr);
00103 typedef int (*PropCollectionLookupIntFunc)(struct PointerRNA *ptr, int key, struct PointerRNA *r_ptr);
00104 typedef int (*PropCollectionLookupStringFunc)(struct PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr);
00105 
00106 /* Container - generic abstracted container of RNA properties */
00107 typedef struct ContainerRNA {
00108         void *next, *prev;
00109 
00110         struct GHash *prophash;
00111         ListBase properties;
00112 } ContainerRNA;
00113 
00114 struct FunctionRNA {
00115         /* structs are containers of properties */
00116         ContainerRNA cont;
00117 
00118         /* unique identifier, keep after 'cont' */
00119         const char *identifier;
00120         /* various options */
00121         int flag;
00122 
00123         /* single line description, displayed in the tooltip for example */
00124         const char *description;
00125 
00126         /* callback to execute the function */
00127         CallFunc call;
00128 
00129         /* parameter for the return value
00130          * note: this is only the C return value, rna functions can have multiple return values */
00131         PropertyRNA *c_ret;
00132 };
00133 
00134 struct PropertyRNA {
00135         struct PropertyRNA *next, *prev;
00136 
00137         /* magic bytes to distinguish with IDProperty */
00138         int magic;
00139 
00140         /* unique identifier */
00141         const char *identifier;
00142         /* various options */
00143         int flag;
00144 
00145         /* user readable name */
00146         const char *name;
00147         /* single line description, displayed in the tooltip for example */
00148         const char *description;
00149         /* icon ID */
00150         int icon;
00151 
00152         /* property type as it appears to the outside */
00153         PropertyType type;
00154         /* subtype, 'interpretation' of the property */
00155         PropertySubType subtype;
00156         /* if non-NULL, overrides arraylength. Must not return 0? */
00157         PropArrayLengthGetFunc getlength;
00158         /* dimension of array */
00159         unsigned int arraydimension;
00160         /* array lengths lengths for all dimensions (when arraydimension > 0) */
00161         unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION];
00162         unsigned int totarraylength;
00163         
00164         /* callback for updates on change */
00165         UpdateFunc update;
00166         int noteflag;
00167 
00168         /* callback for testing if editable */
00169         EditableFunc editable;
00170         /* callback for testing if array-item editable (if applicable) */
00171         ItemEditableFunc itemeditable;
00172 
00173         /* raw access */
00174         int rawoffset;
00175         RawPropertyType rawtype;
00176 
00177         /* This is used for accessing props/functions of this property
00178          * any property can have this but should only be used for collections and arrays
00179          * since python will convert int/bool/pointer's */
00180         struct StructRNA *srna; /* attributes attached directly to this collection */
00181 
00182         /* python handle to hold all callbacks
00183          * (in a pointer array at the moment, may later be a tuple) */
00184         void *py_data;
00185 };
00186 
00187 /* Property Types */
00188 
00189 typedef struct BooleanPropertyRNA {
00190         PropertyRNA property;
00191 
00192         PropBooleanGetFunc get;
00193         PropBooleanSetFunc set;
00194 
00195         PropBooleanArrayGetFunc getarray;
00196         PropBooleanArraySetFunc setarray;
00197 
00198         int defaultvalue;
00199         const int *defaultarray;
00200 } BooleanPropertyRNA;
00201 
00202 typedef struct IntPropertyRNA {
00203         PropertyRNA property;
00204 
00205         PropIntGetFunc get;
00206         PropIntSetFunc set;
00207 
00208         PropIntArrayGetFunc getarray;
00209         PropIntArraySetFunc setarray;
00210 
00211         PropIntRangeFunc range;
00212 
00213         int softmin, softmax;
00214         int hardmin, hardmax;
00215         int step;
00216 
00217         int defaultvalue;
00218         const int *defaultarray;
00219 } IntPropertyRNA;
00220 
00221 typedef struct FloatPropertyRNA {
00222         PropertyRNA property;
00223 
00224         PropFloatGetFunc get;
00225         PropFloatSetFunc set;
00226 
00227         PropFloatArrayGetFunc getarray;
00228         PropFloatArraySetFunc setarray;
00229 
00230         PropFloatRangeFunc range;
00231 
00232         float softmin, softmax;
00233         float hardmin, hardmax;
00234         float step;
00235         int precision;
00236 
00237         float defaultvalue;
00238         const float *defaultarray;
00239 } FloatPropertyRNA;
00240 
00241 typedef struct StringPropertyRNA {
00242         PropertyRNA property;
00243 
00244         PropStringGetFunc get;
00245         PropStringLengthFunc length;
00246         PropStringSetFunc set;
00247 
00248         int maxlength;  /* includes string terminator! */
00249 
00250         const char *defaultvalue;
00251 } StringPropertyRNA;
00252 
00253 typedef struct EnumPropertyRNA {
00254         PropertyRNA property;
00255 
00256         PropEnumGetFunc get;
00257         PropEnumSetFunc set;
00258         PropEnumItemFunc itemf;
00259         void *py_data; /* store py callback here */
00260 
00261         EnumPropertyItem *item;
00262         int totitem;
00263 
00264         int defaultvalue;
00265 } EnumPropertyRNA;
00266 
00267 typedef struct PointerPropertyRNA {
00268         PropertyRNA property;
00269 
00270         PropPointerGetFunc get;
00271         PropPointerSetFunc set;
00272         PropPointerTypeFunc typef;
00273         PropPointerPollFunc poll; /* unlike operators, 'set' can still run if poll fails, used for filtering display */
00274 
00275         struct StructRNA *type;
00276 } PointerPropertyRNA;
00277 
00278 typedef struct CollectionPropertyRNA {
00279         PropertyRNA property;
00280 
00281         PropCollectionBeginFunc begin;
00282         PropCollectionNextFunc next;
00283         PropCollectionEndFunc end;                                              /* optional */
00284         PropCollectionGetFunc get;
00285         PropCollectionLengthFunc length;                                /* optional */
00286         PropCollectionLookupIntFunc lookupint;                  /* optional */
00287         PropCollectionLookupStringFunc lookupstring;    /* optional */
00288 
00289         struct StructRNA *item_type;                    /* the type of this item */
00290 } CollectionPropertyRNA;
00291 
00292 
00293 /* changes to this struct require updating rna_generate_struct in makesrna.c */
00294 struct StructRNA {
00295         /* structs are containers of properties */
00296         ContainerRNA cont;
00297 
00298         /* unique identifier, keep after 'cont' */
00299         const char *identifier;
00300 
00301         /* python type, this is a subtype of pyrna_struct_Type but used so each struct can have its own type
00302          * which is useful for subclassing RNA */
00303         void *py_type;
00304         void *blender_type;
00305         
00306         /* various options */
00307         int flag;
00308 
00309         /* user readable name */
00310         const char *name;
00311         /* single line description, displayed in the tooltip for example */
00312         const char *description;
00313         /* icon ID */
00314         int icon;
00315         
00316         /* property that defines the name */
00317         PropertyRNA *nameproperty;
00318 
00319         /* property to iterate over properties */
00320         PropertyRNA *iteratorproperty;
00321 
00322         /* struct this is derivedfrom */
00323         struct StructRNA *base;
00324 
00325         /* only use for nested structs, where both the parent and child access
00326          * the same C Struct but nesting is used for grouping properties.
00327          * The parent property is used so we know NULL checks are not needed,
00328          * and that this struct will never exist without its parent */
00329         struct StructRNA *nested;
00330 
00331         /* function to give the more specific type */
00332         StructRefineFunc refine; 
00333 
00334         /* function to find path to this struct in an ID */
00335         StructPathFunc path; 
00336 
00337         /* function to register/unregister subclasses */
00338         StructRegisterFunc reg; 
00339         StructUnregisterFunc unreg; 
00340         StructInstanceFunc instance;
00341 
00342         /* callback to get id properties */
00343         IDPropertiesFunc idproperties;
00344 
00345         /* functions of this struct */
00346         ListBase functions; 
00347 };
00348 
00349 /* Blender RNA
00350  *
00351  * Root RNA data structure that lists all struct types. */
00352 
00353 struct BlenderRNA {
00354         ListBase structs;
00355 };
00356 
00357 #define CONTAINER_RNA_ID(cont) (*(const char **)(((ContainerRNA *)(cont))+1))
00358 
00359 #endif /* RNA_INTERNAL_TYPES_H */