Blender V2.61 - r43446

rna_internal_types.h

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