Blender V2.61 - r43446
|
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 #include <stdlib.h> 00029 00030 #include "DNA_ID.h" 00031 00032 #include "RNA_access.h" 00033 #include "RNA_define.h" 00034 00035 #include "rna_internal.h" 00036 00037 EnumPropertyItem property_type_items[] = { 00038 {PROP_BOOLEAN, "BOOLEAN", 0, "Boolean", ""}, 00039 {PROP_INT, "INT", 0, "Integer", ""}, 00040 {PROP_FLOAT, "FLOAT", 0, "Float", ""}, 00041 {PROP_STRING, "STRING", 0, "String", ""}, 00042 {PROP_ENUM, "ENUM", 0, "Enumeration", ""}, 00043 {PROP_POINTER, "POINTER", 0, "Pointer", ""}, 00044 {PROP_COLLECTION, "COLLECTION", 0, "Collection", ""}, 00045 {0, NULL, 0, NULL, NULL}}; 00046 00047 EnumPropertyItem property_subtype_items[] = { 00048 {PROP_NONE, "NONE", 0, "None", ""}, 00049 00050 /* strings */ 00051 {PROP_FILEPATH, "FILEPATH", 0, "File Path", ""}, 00052 {PROP_DIRPATH, "DIRPATH", 0, "Directory Path", ""}, 00053 {PROP_FILENAME, "FILENAME", 0, "File Name", ""}, 00054 {PROP_TRANSLATE, "TRANSLATE", 0, "Translate", ""}, 00055 00056 /* numbers */ 00057 {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""}, 00058 {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""}, 00059 {PROP_FACTOR, "FACTOR", 0, "Factor", ""}, 00060 {PROP_ANGLE, "ANGLE", 0, "Angle", ""}, 00061 {PROP_TIME, "TIME", 0, "Time", ""}, 00062 {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""}, 00063 00064 /* number arrays */ 00065 {PROP_COLOR, "COLOR", 0, "Color", ""}, 00066 {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""}, 00067 {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""}, 00068 {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""}, 00069 {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, 00070 {PROP_MATRIX, "MATRIX", 0, "Matrix", ""}, 00071 {PROP_EULER, "EULER", 0, "Euler Angles", ""}, 00072 {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""}, 00073 {PROP_AXISANGLE, "AXISANGLE", 0, "Axis-Angle", ""}, 00074 {PROP_XYZ, "XYZ", 0, "XYZ", ""}, 00075 {PROP_XYZ_LENGTH, "XYZ_LENGTH", 0, "XYZ Length", ""}, 00076 {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color", ""}, 00077 {PROP_COORDS, "COORDS", 0, "Coordinates", ""}, 00078 00079 /* booleans */ 00080 {PROP_LAYER, "LAYER", 0, "Layer", ""}, 00081 {PROP_LAYER_MEMBER, "LAYER_MEMBER", 0, "Layer Member", ""}, 00082 {0, NULL, 0, NULL, NULL}}; 00083 00084 EnumPropertyItem property_unit_items[] = { 00085 {PROP_UNIT_NONE, "NONE", 0, "None", ""}, 00086 {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""}, 00087 {PROP_UNIT_AREA, "AREA", 0, "Area", ""}, 00088 {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""}, 00089 {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""}, 00090 {PROP_UNIT_TIME, "TIME", 0, "Time", ""}, 00091 {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""}, 00092 {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, 00093 {0, NULL, 0, NULL, NULL}}; 00094 00095 #ifdef RNA_RUNTIME 00096 #include "MEM_guardedalloc.h" 00097 #include "BLI_utildefines.h" 00098 #include "BLI_ghash.h" 00099 00100 /* Struct */ 00101 00102 static void rna_Struct_identifier_get(PointerRNA *ptr, char *value) 00103 { 00104 strcpy(value, ((StructRNA*)ptr->data)->identifier); 00105 } 00106 00107 static int rna_Struct_identifier_length(PointerRNA *ptr) 00108 { 00109 return strlen(((StructRNA*)ptr->data)->identifier); 00110 } 00111 00112 static void rna_Struct_description_get(PointerRNA *ptr, char *value) 00113 { 00114 strcpy(value, ((StructRNA*)ptr->data)->description); 00115 } 00116 00117 static int rna_Struct_description_length(PointerRNA *ptr) 00118 { 00119 return strlen(((StructRNA*)ptr->data)->description); 00120 } 00121 00122 static void rna_Struct_name_get(PointerRNA *ptr, char *value) 00123 { 00124 strcpy(value, ((StructRNA*)ptr->data)->name); 00125 } 00126 00127 static int rna_Struct_name_length(PointerRNA *ptr) 00128 { 00129 return strlen(((StructRNA*)ptr->data)->name); 00130 } 00131 00132 static PointerRNA rna_Struct_base_get(PointerRNA *ptr) 00133 { 00134 return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA*)ptr->data)->base); 00135 } 00136 00137 static PointerRNA rna_Struct_nested_get(PointerRNA *ptr) 00138 { 00139 return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA*)ptr->data)->nested); 00140 } 00141 00142 static PointerRNA rna_Struct_name_property_get(PointerRNA *ptr) 00143 { 00144 return rna_pointer_inherit_refine(ptr, &RNA_Property, ((StructRNA*)ptr->data)->nameproperty); 00145 } 00146 00147 /* Struct property iteration. This is quite complicated, the purpose is to 00148 * iterate over properties of all inheritance levels, and for each struct to 00149 * also iterator over id properties not known by RNA. */ 00150 00151 static int rna_idproperty_known(CollectionPropertyIterator *iter, void *data) 00152 { 00153 IDProperty *idprop= (IDProperty*)data; 00154 PropertyRNA *prop; 00155 StructRNA *ptype= iter->builtin_parent.type; 00156 00157 /* function to skip any id properties that are already known by RNA, 00158 * for the second loop where we go over unknown id properties */ 00159 do { 00160 for(prop= ptype->cont.properties.first; prop; prop=prop->next) 00161 if((prop->flag & PROP_BUILTIN) == 0 && strcmp(prop->identifier, idprop->name) == 0) 00162 return 1; 00163 } while((ptype=ptype->base)); 00164 00165 return 0; 00166 } 00167 00168 static int rna_property_builtin(CollectionPropertyIterator *UNUSED(iter), void *data) 00169 { 00170 PropertyRNA *prop= (PropertyRNA*)data; 00171 00172 /* function to skip builtin rna properties */ 00173 00174 return (prop->flag & PROP_BUILTIN); 00175 } 00176 00177 static int rna_function_builtin(CollectionPropertyIterator *UNUSED(iter), void *data) 00178 { 00179 FunctionRNA *func= (FunctionRNA*)data; 00180 00181 /* function to skip builtin rna functions */ 00182 00183 return (func->flag & FUNC_BUILTIN); 00184 } 00185 00186 static void rna_inheritance_next_level_restart(CollectionPropertyIterator *iter, IteratorSkipFunc skip, int funcs) 00187 { 00188 /* RNA struct inheritance */ 00189 while(!iter->valid && iter->level > 0) { 00190 StructRNA *srna; 00191 int i; 00192 00193 srna= (StructRNA*)iter->parent.data; 00194 iter->level--; 00195 for(i=iter->level; i>0; i--) 00196 srna= srna->base; 00197 00198 rna_iterator_listbase_end(iter); 00199 00200 if (funcs) 00201 rna_iterator_listbase_begin(iter, &srna->functions, skip); 00202 else 00203 rna_iterator_listbase_begin(iter, &srna->cont.properties, skip); 00204 } 00205 } 00206 00207 static void rna_inheritance_properties_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip) 00208 { 00209 rna_iterator_listbase_begin(iter, lb, skip); 00210 rna_inheritance_next_level_restart(iter, skip, 0); 00211 } 00212 00213 static void rna_inheritance_properties_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip) 00214 { 00215 rna_iterator_listbase_next(iter); 00216 rna_inheritance_next_level_restart(iter, skip, 0); 00217 } 00218 00219 static void rna_inheritance_functions_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip) 00220 { 00221 rna_iterator_listbase_begin(iter, lb, skip); 00222 rna_inheritance_next_level_restart(iter, skip, 1); 00223 } 00224 00225 static void rna_inheritance_functions_listbase_next(CollectionPropertyIterator *iter, IteratorSkipFunc skip) 00226 { 00227 rna_iterator_listbase_next(iter); 00228 rna_inheritance_next_level_restart(iter, skip, 1); 00229 } 00230 00231 static void rna_Struct_properties_next(CollectionPropertyIterator *iter) 00232 { 00233 ListBaseIterator *internal= iter->internal; 00234 IDProperty *group; 00235 00236 if(internal->flag) { 00237 /* id properties */ 00238 rna_iterator_listbase_next(iter); 00239 } 00240 else { 00241 /* regular properties */ 00242 rna_inheritance_properties_listbase_next(iter, rna_property_builtin); 00243 00244 /* try id properties */ 00245 if(!iter->valid) { 00246 group= RNA_struct_idprops(&iter->builtin_parent, 0); 00247 00248 if(group) { 00249 rna_iterator_listbase_end(iter); 00250 rna_iterator_listbase_begin(iter, &group->data.group, rna_idproperty_known); 00251 internal= iter->internal; 00252 internal->flag= 1; 00253 } 00254 } 00255 } 00256 } 00257 00258 static void rna_Struct_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00259 { 00260 StructRNA *srna; 00261 00262 /* here ptr->data should always be the same as iter->parent.type */ 00263 srna= (StructRNA *)ptr->data; 00264 00265 while(srna->base) { 00266 iter->level++; 00267 srna= srna->base; 00268 } 00269 00270 rna_inheritance_properties_listbase_begin(iter, &srna->cont.properties, rna_property_builtin); 00271 } 00272 00273 static PointerRNA rna_Struct_properties_get(CollectionPropertyIterator *iter) 00274 { 00275 ListBaseIterator *internal= iter->internal; 00276 00277 /* we return either PropertyRNA* or IDProperty*, the rna_access.c 00278 * functions can handle both as PropertyRNA* with some tricks */ 00279 return rna_pointer_inherit_refine(&iter->parent, &RNA_Property, internal->link); 00280 } 00281 00282 static void rna_Struct_functions_next(CollectionPropertyIterator *iter) 00283 { 00284 rna_inheritance_functions_listbase_next(iter, rna_function_builtin); 00285 } 00286 00287 static void rna_Struct_functions_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00288 { 00289 StructRNA *srna; 00290 00291 /* here ptr->data should always be the same as iter->parent.type */ 00292 srna= (StructRNA *)ptr->data; 00293 00294 while(srna->base) { 00295 iter->level++; 00296 srna= srna->base; 00297 } 00298 00299 rna_inheritance_functions_listbase_begin(iter, &srna->functions, rna_function_builtin); 00300 } 00301 00302 static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter) 00303 { 00304 ListBaseIterator *internal= iter->internal; 00305 00306 /* we return either PropertyRNA* or IDProperty*, the rna_access.c 00307 * functions can handle both as PropertyRNA* with some tricks */ 00308 return rna_pointer_inherit_refine(&iter->parent, &RNA_Function, internal->link); 00309 } 00310 00311 /* Builtin properties iterator re-uses the Struct properties iterator, only 00312 * difference is that we need to set the ptr data to the type of the struct 00313 * whose properties we want to iterate over. */ 00314 00315 void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00316 { 00317 PointerRNA newptr; 00318 00319 /* we create a new pointer with the type as the data */ 00320 newptr.type= &RNA_Struct; 00321 newptr.data= ptr->type; 00322 00323 if(ptr->type->flag & STRUCT_ID) 00324 newptr.id.data= ptr->data; 00325 else 00326 newptr.id.data= NULL; 00327 00328 iter->parent= newptr; 00329 iter->builtin_parent = *ptr; 00330 00331 rna_Struct_properties_begin(iter, &newptr); 00332 } 00333 00334 void rna_builtin_properties_next(CollectionPropertyIterator *iter) 00335 { 00336 rna_Struct_properties_next(iter); 00337 } 00338 00339 PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter) 00340 { 00341 return rna_Struct_properties_get(iter); 00342 } 00343 00344 int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) 00345 { 00346 StructRNA *srna; 00347 PropertyRNA *prop; 00348 PointerRNA propptr= {{NULL}}; 00349 00350 srna= ptr->type; 00351 00352 do { 00353 if(srna->cont.prophash) { 00354 prop= BLI_ghash_lookup(srna->cont.prophash, (void*)key); 00355 00356 if(prop) { 00357 propptr.type= &RNA_Property; 00358 propptr.data= prop; 00359 00360 *r_ptr= propptr; 00361 return TRUE; 00362 } 00363 } 00364 else { 00365 for(prop=srna->cont.properties.first; prop; prop=prop->next) { 00366 if(!(prop->flag & PROP_BUILTIN) && strcmp(prop->identifier, key)==0) { 00367 propptr.type= &RNA_Property; 00368 propptr.data= prop; 00369 00370 *r_ptr= propptr; 00371 return TRUE; 00372 } 00373 } 00374 } 00375 } while((srna=srna->base)); 00376 00377 /* this was used pre 2.5beta0, now ID property access uses python's 00378 * getitem style access 00379 * - ob["foo"] rather than ob.foo */ 00380 #if 0 00381 if(ptr->data) { 00382 IDProperty *group, *idp; 00383 00384 group= RNA_struct_idprops(ptr, 0); 00385 00386 if(group) { 00387 for(idp=group->data.group.first; idp; idp=idp->next) { 00388 if(strcmp(idp->name, key) == 0) { 00389 propptr.type= &RNA_Property; 00390 propptr.data= idp; 00391 00392 *r_ptr= propptr; 00393 return TRUE; 00394 } 00395 } 00396 } 00397 } 00398 #endif 00399 return FALSE; 00400 } 00401 00402 PointerRNA rna_builtin_type_get(PointerRNA *ptr) 00403 { 00404 return rna_pointer_inherit_refine(ptr, &RNA_Struct, ptr->type); 00405 } 00406 00407 /* Property */ 00408 00409 static StructRNA *rna_Property_refine(PointerRNA *ptr) 00410 { 00411 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00412 00413 rna_idproperty_check(&prop, ptr); /* XXX ptr? */ 00414 00415 switch(prop->type) { 00416 case PROP_BOOLEAN: return &RNA_BoolProperty; 00417 case PROP_INT: return &RNA_IntProperty; 00418 case PROP_FLOAT: return &RNA_FloatProperty; 00419 case PROP_STRING: return &RNA_StringProperty; 00420 case PROP_ENUM: return &RNA_EnumProperty; 00421 case PROP_POINTER: return &RNA_PointerProperty; 00422 case PROP_COLLECTION: return &RNA_CollectionProperty; 00423 default: return &RNA_Property; 00424 } 00425 } 00426 00427 static void rna_Property_identifier_get(PointerRNA *ptr, char *value) 00428 { 00429 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00430 rna_idproperty_check(&prop, ptr); 00431 strcpy(value, ((PropertyRNA*)prop)->identifier); 00432 } 00433 00434 static int rna_Property_identifier_length(PointerRNA *ptr) 00435 { 00436 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00437 rna_idproperty_check(&prop, ptr); 00438 return strlen(prop->identifier); 00439 } 00440 00441 static void rna_Property_name_get(PointerRNA *ptr, char *value) 00442 { 00443 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00444 rna_idproperty_check(&prop, ptr); 00445 strcpy(value, prop->name); 00446 } 00447 00448 static int rna_Property_name_length(PointerRNA *ptr) 00449 { 00450 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00451 rna_idproperty_check(&prop, ptr); 00452 return strlen(prop->name); 00453 } 00454 00455 static void rna_Property_description_get(PointerRNA *ptr, char *value) 00456 { 00457 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00458 rna_idproperty_check(&prop, ptr); 00459 strcpy(value, prop->description ? prop->description:""); 00460 } 00461 static int rna_Property_description_length(PointerRNA *ptr) 00462 { 00463 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00464 rna_idproperty_check(&prop, ptr); 00465 return prop->description ? strlen(prop->description) : 0; 00466 } 00467 00468 static void rna_Property_translation_context_get(PointerRNA *ptr, char *value) 00469 { 00470 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00471 rna_idproperty_check(&prop, ptr); 00472 strcpy(value, prop->translation_context ? prop->translation_context:""); 00473 } 00474 00475 static int rna_Property_translation_context_length(PointerRNA *ptr) 00476 { 00477 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00478 rna_idproperty_check(&prop, ptr); 00479 return prop->translation_context ? strlen(prop->translation_context) : 0; 00480 } 00481 00482 static int rna_Property_type_get(PointerRNA *ptr) 00483 { 00484 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00485 rna_idproperty_check(&prop, ptr); 00486 return prop->type; 00487 } 00488 00489 static int rna_Property_subtype_get(PointerRNA *ptr) 00490 { 00491 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00492 rna_idproperty_check(&prop, ptr); 00493 return prop->subtype; 00494 } 00495 00496 static PointerRNA rna_Property_srna_get(PointerRNA *ptr) 00497 { 00498 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00499 rna_idproperty_check(&prop, ptr); 00500 return rna_pointer_inherit_refine(ptr, &RNA_Struct, prop->srna); 00501 } 00502 00503 static int rna_Property_unit_get(PointerRNA *ptr) 00504 { 00505 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00506 rna_idproperty_check(&prop, ptr); 00507 return RNA_SUBTYPE_UNIT(prop->subtype); 00508 } 00509 00510 static int rna_Property_readonly_get(PointerRNA *ptr) 00511 { 00512 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00513 00514 /* dont use this becaure it will call functions that check the internal 00515 * data for introspection we only need to know if it can be edited so the 00516 * flag is better for this */ 00517 // return RNA_property_editable(ptr, prop); 00518 return prop->flag & PROP_EDITABLE ? 0:1; 00519 } 00520 00521 static int rna_Property_animatable_get(PointerRNA *ptr) 00522 { 00523 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00524 00525 return (prop->flag & PROP_ANIMATABLE) != 0; 00526 } 00527 00528 static int rna_Property_use_output_get(PointerRNA *ptr) 00529 { 00530 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00531 return prop->flag & PROP_OUTPUT ? 1:0; 00532 } 00533 00534 static int rna_Property_is_required_get(PointerRNA *ptr) 00535 { 00536 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00537 return prop->flag & PROP_REQUIRED ? 1:0; 00538 } 00539 00540 static int rna_Property_is_never_none_get(PointerRNA *ptr) 00541 { 00542 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00543 return prop->flag & PROP_NEVER_NULL ? 1:0; 00544 } 00545 00546 static int rna_Property_is_hidden_get(PointerRNA *ptr) 00547 { 00548 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00549 return prop->flag & PROP_HIDDEN ? 1:0; 00550 } 00551 00552 static int rna_Property_is_skip_save_get(PointerRNA *ptr) 00553 { 00554 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00555 return prop->flag & PROP_SKIP_SAVE ? 1:0; 00556 } 00557 00558 00559 static int rna_Property_is_enum_flag_get(PointerRNA *ptr) 00560 { 00561 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00562 return prop->flag & PROP_ENUM_FLAG ? 1:0; 00563 } 00564 00565 static int rna_Property_array_length_get(PointerRNA *ptr) 00566 { 00567 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00568 rna_idproperty_check(&prop, ptr); 00569 return prop->totarraylength; 00570 } 00571 00572 static int rna_Property_registered_get(PointerRNA *ptr) 00573 { 00574 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00575 return prop->flag & PROP_REGISTER; 00576 } 00577 00578 static int rna_Property_registered_optional_get(PointerRNA *ptr) 00579 { 00580 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00581 return prop->flag & PROP_REGISTER_OPTIONAL; 00582 } 00583 00584 static int rna_Property_runtime_get(PointerRNA *ptr) 00585 { 00586 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00587 return prop->flag & PROP_RUNTIME; 00588 } 00589 00590 00591 static int rna_BoolProperty_default_get(PointerRNA *ptr) 00592 { 00593 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00594 rna_idproperty_check(&prop, ptr); 00595 return ((BoolPropertyRNA*)prop)->defaultvalue; 00596 } 00597 00598 static int rna_IntProperty_default_get(PointerRNA *ptr) 00599 { 00600 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00601 rna_idproperty_check(&prop, ptr); 00602 return ((IntPropertyRNA*)prop)->defaultvalue; 00603 } 00604 /* int/float/bool */ 00605 static int rna_NumberProperty_default_array_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]) 00606 { 00607 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00608 rna_idproperty_check(&prop, ptr); 00609 00610 length[0]= prop->totarraylength; 00611 00612 return length[0]; 00613 } 00614 static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values) 00615 { 00616 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00617 IntPropertyRNA *nprop= (IntPropertyRNA*)prop; 00618 rna_idproperty_check(&prop, ptr); 00619 00620 if(nprop->defaultarray) { 00621 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int)); 00622 } 00623 else { 00624 int i; 00625 for(i=0; i < prop->totarraylength; i++) 00626 values[i]= nprop->defaultvalue; 00627 } 00628 } 00629 static void rna_BoolProperty_default_array_get(PointerRNA *ptr, int *values) 00630 { 00631 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00632 BoolPropertyRNA *nprop= (BoolPropertyRNA*)prop; 00633 rna_idproperty_check(&prop, ptr); 00634 00635 if(nprop->defaultarray) { 00636 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int)); 00637 } 00638 else { 00639 int i; 00640 for(i=0; i < prop->totarraylength; i++) 00641 values[i]= nprop->defaultvalue; 00642 } 00643 } 00644 static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values) 00645 { 00646 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00647 FloatPropertyRNA *nprop= (FloatPropertyRNA*)prop; 00648 rna_idproperty_check(&prop, ptr); 00649 00650 if(nprop->defaultarray) { 00651 memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(float)); 00652 } 00653 else { 00654 int i; 00655 for(i=0; i < prop->totarraylength; i++) 00656 values[i]= nprop->defaultvalue; 00657 } 00658 } 00659 00660 static int rna_IntProperty_hard_min_get(PointerRNA *ptr) 00661 { 00662 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00663 rna_idproperty_check(&prop, ptr); 00664 return ((IntPropertyRNA*)prop)->hardmin; 00665 } 00666 00667 static int rna_IntProperty_hard_max_get(PointerRNA *ptr) 00668 { 00669 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00670 rna_idproperty_check(&prop, ptr); 00671 return ((IntPropertyRNA*)prop)->hardmax; 00672 } 00673 00674 static int rna_IntProperty_soft_min_get(PointerRNA *ptr) 00675 { 00676 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00677 rna_idproperty_check(&prop, ptr); 00678 return ((IntPropertyRNA*)prop)->softmin; 00679 } 00680 00681 static int rna_IntProperty_soft_max_get(PointerRNA *ptr) 00682 { 00683 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00684 rna_idproperty_check(&prop, ptr); 00685 return ((IntPropertyRNA*)prop)->softmax; 00686 } 00687 00688 static int rna_IntProperty_step_get(PointerRNA *ptr) 00689 { 00690 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00691 rna_idproperty_check(&prop, ptr); 00692 return ((IntPropertyRNA*)prop)->step; 00693 } 00694 00695 static float rna_FloatProperty_default_get(PointerRNA *ptr) 00696 { 00697 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00698 rna_idproperty_check(&prop, ptr); 00699 return ((FloatPropertyRNA*)prop)->defaultvalue; 00700 } 00701 static float rna_FloatProperty_hard_min_get(PointerRNA *ptr) 00702 { 00703 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00704 rna_idproperty_check(&prop, ptr); 00705 return ((FloatPropertyRNA*)prop)->hardmin; 00706 } 00707 00708 static float rna_FloatProperty_hard_max_get(PointerRNA *ptr) 00709 { 00710 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00711 rna_idproperty_check(&prop, ptr); 00712 return ((FloatPropertyRNA*)prop)->hardmax; 00713 } 00714 00715 static float rna_FloatProperty_soft_min_get(PointerRNA *ptr) 00716 { 00717 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00718 rna_idproperty_check(&prop, ptr); 00719 return ((FloatPropertyRNA*)prop)->softmin; 00720 } 00721 00722 static float rna_FloatProperty_soft_max_get(PointerRNA *ptr) 00723 { 00724 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00725 rna_idproperty_check(&prop, ptr); 00726 return ((FloatPropertyRNA*)prop)->softmax; 00727 } 00728 00729 static float rna_FloatProperty_step_get(PointerRNA *ptr) 00730 { 00731 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00732 rna_idproperty_check(&prop, ptr); 00733 return ((FloatPropertyRNA*)prop)->step; 00734 } 00735 00736 static int rna_FloatProperty_precision_get(PointerRNA *ptr) 00737 { 00738 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00739 rna_idproperty_check(&prop, ptr); 00740 return ((FloatPropertyRNA*)prop)->precision; 00741 } 00742 00743 static void rna_StringProperty_default_get(PointerRNA *ptr, char *value) 00744 { 00745 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00746 rna_idproperty_check(&prop, ptr); 00747 strcpy(value, ((StringPropertyRNA*)prop)->defaultvalue); 00748 } 00749 static int rna_StringProperty_default_length(PointerRNA *ptr) 00750 { 00751 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00752 rna_idproperty_check(&prop, ptr); 00753 return strlen(((StringPropertyRNA*)prop)->defaultvalue); 00754 } 00755 00756 static int rna_StringProperty_max_length_get(PointerRNA *ptr) 00757 { 00758 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00759 rna_idproperty_check(&prop, ptr); 00760 return ((StringPropertyRNA*)prop)->maxlength; 00761 } 00762 00763 static EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop_parent, int *free) 00764 { 00765 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00766 EnumPropertyRNA *eprop; 00767 00768 rna_idproperty_check(&prop, ptr); 00769 eprop= (EnumPropertyRNA*)prop; 00770 00771 /* incompatible default attributes */ 00772 if ((prop_parent->flag & PROP_ENUM_FLAG) != (prop->flag & PROP_ENUM_FLAG)) { 00773 return NULL; 00774 } 00775 00776 if( (eprop->itemf == NULL) || 00777 (eprop->itemf == rna_EnumProperty_default_itemf) || 00778 (ptr->type == &RNA_EnumProperty) || 00779 (C == NULL)) 00780 { 00781 return eprop->item; 00782 } 00783 00784 return eprop->itemf(C, ptr, prop, free); 00785 } 00786 00787 /* XXX - not sure this is needed? */ 00788 static int rna_EnumProperty_default_get(PointerRNA *ptr) 00789 { 00790 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00791 rna_idproperty_check(&prop, ptr); 00792 return ((EnumPropertyRNA*)prop)->defaultvalue; 00793 } 00794 00795 static int rna_enum_check_separator(CollectionPropertyIterator *UNUSED(iter), void *data) 00796 { 00797 EnumPropertyItem *item= (EnumPropertyItem*)data; 00798 00799 return (item->identifier[0] == 0); 00800 } 00801 00802 static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00803 { 00804 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00805 // EnumPropertyRNA *eprop; // UNUSED 00806 EnumPropertyItem *item= NULL; 00807 int totitem, free= 0; 00808 00809 rna_idproperty_check(&prop, ptr); 00810 // eprop= (EnumPropertyRNA*)prop; 00811 00812 RNA_property_enum_items(NULL, ptr, prop, &item, &totitem, &free); 00813 rna_iterator_array_begin(iter, (void*)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator); 00814 } 00815 00816 static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value) 00817 { 00818 strcpy(value, ((EnumPropertyItem*)ptr->data)->identifier); 00819 } 00820 00821 static int rna_EnumPropertyItem_identifier_length(PointerRNA *ptr) 00822 { 00823 return strlen(((EnumPropertyItem*)ptr->data)->identifier); 00824 } 00825 00826 static void rna_EnumPropertyItem_name_get(PointerRNA *ptr, char *value) 00827 { 00828 strcpy(value, ((EnumPropertyItem*)ptr->data)->name); 00829 } 00830 00831 static int rna_EnumPropertyItem_name_length(PointerRNA *ptr) 00832 { 00833 return strlen(((EnumPropertyItem*)ptr->data)->name); 00834 } 00835 00836 static void rna_EnumPropertyItem_description_get(PointerRNA *ptr, char *value) 00837 { 00838 EnumPropertyItem *eprop= (EnumPropertyItem*)ptr->data; 00839 00840 if(eprop->description) 00841 strcpy(value, eprop->description); 00842 else 00843 value[0]= '\0'; 00844 } 00845 00846 static int rna_EnumPropertyItem_description_length(PointerRNA *ptr) 00847 { 00848 EnumPropertyItem *eprop= (EnumPropertyItem*)ptr->data; 00849 00850 if(eprop->description) 00851 return strlen(eprop->description); 00852 else 00853 return 0; 00854 } 00855 00856 static int rna_EnumPropertyItem_value_get(PointerRNA *ptr) 00857 { 00858 return ((EnumPropertyItem*)ptr->data)->value; 00859 } 00860 00861 static PointerRNA rna_PointerProperty_fixed_type_get(PointerRNA *ptr) 00862 { 00863 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00864 rna_idproperty_check(&prop, ptr); 00865 return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((PointerPropertyRNA*)prop)->type); 00866 } 00867 00868 static PointerRNA rna_CollectionProperty_fixed_type_get(PointerRNA *ptr) 00869 { 00870 PropertyRNA *prop= (PropertyRNA*)ptr->data; 00871 rna_idproperty_check(&prop, ptr); 00872 return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((CollectionPropertyRNA*)prop)->item_type); 00873 } 00874 00875 /* Function */ 00876 00877 static void rna_Function_identifier_get(PointerRNA *ptr, char *value) 00878 { 00879 strcpy(value, ((FunctionRNA*)ptr->data)->identifier); 00880 } 00881 00882 static int rna_Function_identifier_length(PointerRNA *ptr) 00883 { 00884 return strlen(((FunctionRNA*)ptr->data)->identifier); 00885 } 00886 00887 static void rna_Function_description_get(PointerRNA *ptr, char *value) 00888 { 00889 strcpy(value, ((FunctionRNA*)ptr->data)->description); 00890 } 00891 00892 static int rna_Function_description_length(PointerRNA *ptr) 00893 { 00894 return strlen(((FunctionRNA*)ptr->data)->description); 00895 } 00896 00897 static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00898 { 00899 rna_iterator_listbase_begin(iter, &((FunctionRNA*)ptr->data)->cont.properties, rna_property_builtin); 00900 } 00901 00902 static int rna_Function_registered_get(PointerRNA *ptr) 00903 { 00904 FunctionRNA *func= (FunctionRNA*)ptr->data; 00905 return func->flag & FUNC_REGISTER; 00906 } 00907 00908 static int rna_Function_registered_optional_get(PointerRNA *ptr) 00909 { 00910 FunctionRNA *func= (FunctionRNA*)ptr->data; 00911 return func->flag & FUNC_REGISTER_OPTIONAL; 00912 } 00913 00914 static int rna_Function_no_self_get(PointerRNA *ptr) 00915 { 00916 FunctionRNA *func= (FunctionRNA*)ptr->data; 00917 return !(func->flag & FUNC_NO_SELF); 00918 } 00919 00920 /* Blender RNA */ 00921 00922 static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00923 { 00924 rna_iterator_listbase_begin(iter, &((BlenderRNA*)ptr->data)->structs, NULL); 00925 } 00926 00927 /* optional, for faster lookups */ 00928 static int rna_BlenderRNA_structs_length(PointerRNA *ptr) 00929 { 00930 return BLI_countlist(&((BlenderRNA*)ptr->data)->structs); 00931 } 00932 static int rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) 00933 { 00934 StructRNA *srna= BLI_findlink(&((BlenderRNA*)ptr->data)->structs, index); 00935 00936 if(srna) { 00937 RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); 00938 return TRUE; 00939 } 00940 else { 00941 return FALSE; 00942 } 00943 } 00944 static int rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) 00945 { 00946 StructRNA *srna= ((BlenderRNA*)ptr->data)->structs.first; 00947 for(; srna; srna=srna->cont.next) { 00948 if(key[0] == srna->identifier[0] && strcmp(key, srna->identifier)==0) { 00949 RNA_pointer_create(NULL, &RNA_Struct, srna, r_ptr); 00950 return TRUE; 00951 } 00952 } 00953 00954 return FALSE; 00955 } 00956 00957 00958 #else 00959 00960 static void rna_def_struct(BlenderRNA *brna) 00961 { 00962 StructRNA *srna; 00963 PropertyRNA *prop; 00964 00965 srna= RNA_def_struct(brna, "Struct", NULL); 00966 RNA_def_struct_ui_text(srna, "Struct Definition", "RNA structure definition"); 00967 RNA_def_struct_ui_icon(srna, ICON_RNA); 00968 00969 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 00970 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00971 RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", NULL); 00972 RNA_def_property_ui_text(prop, "Name", "Human readable name"); 00973 00974 prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); 00975 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00976 RNA_def_property_string_funcs(prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", NULL); 00977 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting"); 00978 RNA_def_struct_name_property(srna, prop); 00979 00980 prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); 00981 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00982 RNA_def_property_string_funcs(prop, "rna_Struct_description_get", "rna_Struct_description_length", NULL); 00983 RNA_def_property_ui_text(prop, "Description", "Description of the Struct's purpose"); 00984 00985 prop= RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE); 00986 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00987 RNA_def_property_struct_type(prop, "Struct"); 00988 RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", NULL, NULL, NULL); 00989 RNA_def_property_ui_text(prop, "Base", "Struct definition this is derived from"); 00990 00991 prop= RNA_def_property(srna, "nested", PROP_POINTER, PROP_NONE); 00992 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00993 RNA_def_property_struct_type(prop, "Struct"); 00994 RNA_def_property_pointer_funcs(prop, "rna_Struct_nested_get", NULL, NULL, NULL); 00995 RNA_def_property_ui_text(prop, "Nested", "Struct in which this struct is always nested, and to which it logically belongs"); 00996 00997 prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE); 00998 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00999 RNA_def_property_struct_type(prop, "StringProperty"); 01000 RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", NULL, NULL, NULL); 01001 RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct"); 01002 01003 prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE); 01004 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01005 RNA_def_property_struct_type(prop, "Property"); 01006 RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", NULL, NULL, NULL, NULL); 01007 RNA_def_property_ui_text(prop, "Properties", "Properties in the struct"); 01008 01009 prop= RNA_def_property(srna, "functions", PROP_COLLECTION, PROP_NONE); 01010 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01011 RNA_def_property_struct_type(prop, "Function"); 01012 RNA_def_property_collection_funcs(prop, "rna_Struct_functions_begin", "rna_Struct_functions_next", "rna_iterator_listbase_end", "rna_Struct_functions_get", NULL, NULL, NULL, NULL); 01013 RNA_def_property_ui_text(prop, "Functions", ""); 01014 } 01015 01016 static void rna_def_property(BlenderRNA *brna) 01017 { 01018 StructRNA *srna; 01019 PropertyRNA *prop; 01020 static EnumPropertyItem subtype_items[] = { 01021 {PROP_NONE, "NONE", 0, "None", ""}, 01022 {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""}, 01023 {PROP_DIRPATH, "DIRECTORY_PATH", 0, "Directory Path", ""}, 01024 {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned Number", ""}, 01025 {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""}, 01026 {PROP_FACTOR, "FACTOR", 0, "Factor", ""}, 01027 {PROP_ANGLE, "ANGLE", 0, "Angle", ""}, 01028 {PROP_TIME, "TIME", 0, "Time", ""}, 01029 {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""}, 01030 {PROP_COLOR, "COLOR", 0, "Color", ""}, 01031 {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""}, 01032 {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""}, 01033 {PROP_MATRIX, "MATRIX", 0, "Matrix", ""}, 01034 {PROP_EULER, "EULER", 0, "Euler", ""}, 01035 {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""}, 01036 {PROP_XYZ, "XYZ", 0, "XYZ", ""}, 01037 {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Gamma Corrected Color", ""}, 01038 {PROP_COORDS, "COORDINATES", 0, "Vector Coordinates", ""}, 01039 {PROP_LAYER, "LAYER", 0, "Layer", ""}, 01040 {PROP_LAYER_MEMBER, "LAYER_MEMBERSHIP", 0, "Layer Membership", ""}, 01041 {0, NULL, 0, NULL, NULL}}; 01042 01043 srna= RNA_def_struct(brna, "Property", NULL); 01044 RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition"); 01045 RNA_def_struct_refine_func(srna, "rna_Property_refine"); 01046 RNA_def_struct_ui_icon(srna, ICON_RNA); 01047 01048 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 01049 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01050 RNA_def_property_string_funcs(prop, "rna_Property_name_get", "rna_Property_name_length", NULL); 01051 RNA_def_property_ui_text(prop, "Name", "Human readable name"); 01052 01053 prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); 01054 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01055 RNA_def_property_string_funcs(prop, "rna_Property_identifier_get", "rna_Property_identifier_length", NULL); 01056 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting"); 01057 RNA_def_struct_name_property(srna, prop); 01058 01059 prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); 01060 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01061 RNA_def_property_string_funcs(prop, "rna_Property_description_get", "rna_Property_description_length", NULL); 01062 RNA_def_property_ui_text(prop, "Description", "Description of the property for tooltips"); 01063 01064 prop= RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE); 01065 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01066 RNA_def_property_string_funcs(prop, "rna_Property_translation_context_get", "rna_Property_translation_context_length", NULL); 01067 RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the property"); 01068 01069 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); 01070 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01071 RNA_def_property_enum_items(prop, property_type_items); 01072 RNA_def_property_enum_funcs(prop, "rna_Property_type_get", NULL, NULL); 01073 RNA_def_property_ui_text(prop, "Type", "Data type of the property"); 01074 01075 prop= RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE); 01076 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01077 RNA_def_property_enum_items(prop, subtype_items); 01078 RNA_def_property_enum_funcs(prop, "rna_Property_subtype_get", NULL, NULL); 01079 RNA_def_property_ui_text(prop, "Subtype", "Semantic interpretation of the property"); 01080 01081 prop= RNA_def_property(srna, "srna", PROP_POINTER, PROP_NONE); 01082 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01083 RNA_def_property_struct_type(prop, "Struct"); 01084 RNA_def_property_pointer_funcs(prop, "rna_Property_srna_get", NULL, NULL, NULL); 01085 RNA_def_property_ui_text(prop, "Base", "Struct definition used for properties assigned to this item"); 01086 01087 prop= RNA_def_property(srna, "unit", PROP_ENUM, PROP_NONE); 01088 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01089 RNA_def_property_enum_items(prop, property_unit_items); 01090 RNA_def_property_enum_funcs(prop, "rna_Property_unit_get", NULL, NULL); 01091 RNA_def_property_ui_text(prop, "Unit", "Type of units for this property"); 01092 01093 prop= RNA_def_property(srna, "is_readonly", PROP_BOOLEAN, PROP_NONE); 01094 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01095 RNA_def_property_boolean_funcs(prop, "rna_Property_readonly_get", NULL); 01096 RNA_def_property_ui_text(prop, "Read Only", "Property is editable through RNA"); 01097 01098 prop= RNA_def_property(srna, "is_animatable", PROP_BOOLEAN, PROP_NONE); 01099 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01100 RNA_def_property_boolean_funcs(prop, "rna_Property_animatable_get", NULL); 01101 RNA_def_property_ui_text(prop, "Animatable", "Property is animatable through RNA"); 01102 01103 prop= RNA_def_property(srna, "is_required", PROP_BOOLEAN, PROP_NONE); 01104 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01105 RNA_def_property_boolean_funcs(prop, "rna_Property_is_required_get", NULL); 01106 RNA_def_property_ui_text(prop, "Required", "False when this property is an optional argument in an RNA function"); 01107 01108 prop= RNA_def_property(srna, "is_never_none", PROP_BOOLEAN, PROP_NONE); 01109 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01110 RNA_def_property_boolean_funcs(prop, "rna_Property_is_never_none_get", NULL); 01111 RNA_def_property_ui_text(prop, "Never None", "True when this value can't be set to None"); 01112 01113 prop= RNA_def_property(srna, "is_hidden", PROP_BOOLEAN, PROP_NONE); 01114 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01115 RNA_def_property_boolean_funcs(prop, "rna_Property_is_hidden_get", NULL); 01116 RNA_def_property_ui_text(prop, "Hidden", "True when the property is hidden"); 01117 01118 prop= RNA_def_property(srna, "is_skip_save", PROP_BOOLEAN, PROP_NONE); 01119 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01120 RNA_def_property_boolean_funcs(prop, "rna_Property_is_skip_save_get", NULL); 01121 RNA_def_property_ui_text(prop, "Skip Save", "True when the property is not saved in presets"); 01122 01123 prop= RNA_def_property(srna, "is_output", PROP_BOOLEAN, PROP_NONE); 01124 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01125 RNA_def_property_boolean_funcs(prop, "rna_Property_use_output_get", NULL); 01126 RNA_def_property_ui_text(prop, "Return", "True when this property is an output value from an RNA function"); 01127 01128 prop= RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE); 01129 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01130 RNA_def_property_boolean_funcs(prop, "rna_Property_registered_get", NULL); 01131 RNA_def_property_ui_text(prop, "Registered", "Property is registered as part of type registration"); 01132 01133 prop= RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE); 01134 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01135 RNA_def_property_boolean_funcs(prop, "rna_Property_registered_optional_get", NULL); 01136 RNA_def_property_ui_text(prop, "Registered Optionally", "Property is optionally registered as part of type registration"); 01137 01138 prop= RNA_def_property(srna, "is_runtime", PROP_BOOLEAN, PROP_NONE); 01139 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01140 RNA_def_property_boolean_funcs(prop, "rna_Property_runtime_get", NULL); 01141 RNA_def_property_ui_text(prop, "Runtime", "Property has been dynamically created at runtime"); 01142 01143 prop= RNA_def_property(srna, "is_enum_flag", PROP_BOOLEAN, PROP_NONE); 01144 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01145 RNA_def_property_boolean_funcs(prop, "rna_Property_is_enum_flag_get", NULL); 01146 RNA_def_property_ui_text(prop, "Enum Flag", "True when multiple enums "); 01147 } 01148 01149 static void rna_def_function(BlenderRNA *brna) 01150 { 01151 StructRNA *srna; 01152 PropertyRNA *prop; 01153 01154 srna= RNA_def_struct(brna, "Function", NULL); 01155 RNA_def_struct_ui_text(srna, "Function Definition", "RNA function definition"); 01156 RNA_def_struct_ui_icon(srna, ICON_RNA); 01157 01158 prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); 01159 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01160 RNA_def_property_string_funcs(prop, "rna_Function_identifier_get", "rna_Function_identifier_length", NULL); 01161 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting"); 01162 RNA_def_struct_name_property(srna, prop); 01163 01164 prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); 01165 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01166 RNA_def_property_string_funcs(prop, "rna_Function_description_get", "rna_Function_description_length", NULL); 01167 RNA_def_property_ui_text(prop, "Description", "Description of the Function's purpose"); 01168 01169 prop= RNA_def_property(srna, "parameters", PROP_COLLECTION, PROP_NONE); 01170 /*RNA_def_property_clear_flag(prop, PROP_EDITABLE);*/ 01171 RNA_def_property_struct_type(prop, "Property"); 01172 RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", NULL, NULL, NULL, NULL); 01173 RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function"); 01174 01175 prop= RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE); 01176 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01177 RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", NULL); 01178 RNA_def_property_ui_text(prop, "Registered", "Function is registered as callback as part of type registration"); 01179 01180 prop= RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE); 01181 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01182 RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", NULL); 01183 RNA_def_property_ui_text(prop, "Registered Optionally", "Function is optionally registered as callback part of type registration"); 01184 01185 prop= RNA_def_property(srna, "use_self", PROP_BOOLEAN, PROP_NONE); 01186 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01187 RNA_def_property_boolean_funcs(prop, "rna_Function_no_self_get", NULL); 01188 RNA_def_property_ui_text(prop, "No Self", "Function does not pass its self as an argument (becomes a class method in python)"); 01189 } 01190 01191 static void rna_def_number_property(StructRNA *srna, PropertyType type) 01192 { 01193 PropertyRNA *prop; 01194 01195 prop= RNA_def_property(srna, "default", type, PROP_NONE); 01196 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01197 RNA_def_property_ui_text(prop, "Default", "Default value for this number"); 01198 01199 switch(type) { 01200 case PROP_BOOLEAN: 01201 RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_get", NULL); 01202 break; 01203 case PROP_INT: 01204 RNA_def_property_int_funcs(prop, "rna_IntProperty_default_get", NULL, NULL); 01205 break; 01206 case PROP_FLOAT: 01207 RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_get", NULL, NULL); 01208 break; 01209 default: 01210 break; 01211 } 01212 01213 01214 prop= RNA_def_property(srna, "default_array", type, PROP_NONE); 01215 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01216 RNA_def_property_array(prop, RNA_MAX_ARRAY_DIMENSION); /* no fixed default length, important its not 0 though */ 01217 RNA_def_property_flag(prop, PROP_DYNAMIC); 01218 RNA_def_property_dynamic_array_funcs(prop, "rna_NumberProperty_default_array_get_length"); /* same for all types */ 01219 01220 switch(type) { 01221 case PROP_BOOLEAN: 01222 RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_array_get", NULL); 01223 break; 01224 case PROP_INT: 01225 RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", NULL, NULL); 01226 break; 01227 case PROP_FLOAT: 01228 RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", NULL, NULL); 01229 break; 01230 default: 01231 break; 01232 } 01233 RNA_def_property_ui_text(prop, "Default Array", "Default value for this array"); 01234 01235 01236 prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED); 01237 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01238 RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL, NULL); 01239 RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited"); 01240 01241 if(type == PROP_BOOLEAN) 01242 return; 01243 01244 prop= RNA_def_property(srna, "hard_min", type, PROP_NONE); 01245 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01246 if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_min_get", NULL, NULL); 01247 else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_min_get", NULL, NULL); 01248 RNA_def_property_ui_text(prop, "Hard Minimum", "Minimum value used by buttons"); 01249 01250 prop= RNA_def_property(srna, "hard_max", type, PROP_NONE); 01251 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01252 if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_max_get", NULL, NULL); 01253 else RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_max_get", NULL, NULL); 01254 RNA_def_property_ui_text(prop, "Hard Maximum", "Maximum value used by buttons"); 01255 01256 prop= RNA_def_property(srna, "soft_min", type, PROP_NONE); 01257 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01258 if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_min_get", NULL, NULL); 01259 else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_min_get", NULL, NULL); 01260 RNA_def_property_ui_text(prop, "Soft Minimum", "Minimum value used by buttons"); 01261 01262 prop= RNA_def_property(srna, "soft_max", type, PROP_NONE); 01263 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01264 if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_max_get", NULL, NULL); 01265 else RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_max_get", NULL, NULL); 01266 RNA_def_property_ui_text(prop, "Soft Maximum", "Maximum value used by buttons"); 01267 01268 prop= RNA_def_property(srna, "step", type, PROP_UNSIGNED); 01269 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01270 if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_step_get", NULL, NULL); 01271 else RNA_def_property_float_funcs(prop, "rna_FloatProperty_step_get", NULL, NULL); 01272 RNA_def_property_ui_text(prop, "Step", "Step size used by number buttons, for floats 1/100th of the step size"); 01273 01274 if(type == PROP_FLOAT) { 01275 prop= RNA_def_property(srna, "precision", PROP_INT, PROP_UNSIGNED); 01276 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01277 RNA_def_property_int_funcs(prop, "rna_FloatProperty_precision_get", NULL, NULL); 01278 RNA_def_property_ui_text(prop, "Precision", "Number of digits after the dot used by buttons"); 01279 } 01280 } 01281 01282 static void rna_def_string_property(StructRNA *srna) 01283 { 01284 PropertyRNA *prop; 01285 01286 prop= RNA_def_property(srna, "default", PROP_STRING, PROP_NONE); 01287 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01288 RNA_def_property_string_funcs(prop, "rna_StringProperty_default_get", "rna_StringProperty_default_length", NULL); 01289 RNA_def_property_ui_text(prop, "Default", "string default value"); 01290 01291 prop= RNA_def_property(srna, "length_max", PROP_INT, PROP_UNSIGNED); 01292 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01293 RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL, NULL); 01294 RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited"); 01295 } 01296 01297 static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) 01298 { 01299 PropertyRNA *prop; 01300 01301 /* the itemf func is used instead, keep blender happy */ 01302 static EnumPropertyItem default_dummy_items[] = { 01303 {PROP_NONE, "DUMMY", 0, "Dummy", ""}, 01304 {0, NULL, 0, NULL, NULL}}; 01305 01306 prop= RNA_def_property(srna, "default", PROP_ENUM, PROP_NONE); 01307 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01308 RNA_def_property_enum_items(prop, default_dummy_items); 01309 RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf"); 01310 RNA_def_property_ui_text(prop, "Default", "Default value for this enum"); 01311 01312 /* same 'default' but uses 'PROP_ENUM_FLAG' */ 01313 prop= RNA_def_property(srna, "default_flag", PROP_ENUM, PROP_NONE); 01314 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01315 RNA_def_property_flag(prop, PROP_ENUM_FLAG); 01316 RNA_def_property_enum_items(prop, default_dummy_items); 01317 RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf"); 01318 RNA_def_property_ui_text(prop, "Default", "Default value for this enum"); 01319 01320 prop= RNA_def_property(srna, "enum_items", PROP_COLLECTION, PROP_NONE); 01321 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01322 RNA_def_property_struct_type(prop, "EnumPropertyItem"); 01323 RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL); 01324 RNA_def_property_ui_text(prop, "Items", "Possible values for the property"); 01325 01326 srna= RNA_def_struct(brna, "EnumPropertyItem", NULL); 01327 RNA_def_struct_ui_text(srna, "Enum Item Definition", "Definition of a choice in an RNA enum property"); 01328 RNA_def_struct_ui_icon(srna, ICON_RNA); 01329 01330 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 01331 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01332 RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_name_get", "rna_EnumPropertyItem_name_length", NULL); 01333 RNA_def_property_ui_text(prop, "Name", "Human readable name"); 01334 01335 prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); 01336 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01337 RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_description_get", "rna_EnumPropertyItem_description_length", NULL); 01338 RNA_def_property_ui_text(prop, "Description", "Description of the item's purpose"); 01339 01340 prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); 01341 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01342 RNA_def_property_string_funcs(prop, "rna_EnumPropertyItem_identifier_get", "rna_EnumPropertyItem_identifier_length", NULL); 01343 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting"); 01344 RNA_def_struct_name_property(srna, prop); 01345 01346 prop= RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED); 01347 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01348 RNA_def_property_int_funcs(prop, "rna_EnumPropertyItem_value_get", NULL, NULL); 01349 RNA_def_property_ui_text(prop, "Value", "Value of the item"); 01350 } 01351 01352 static void rna_def_pointer_property(StructRNA *srna, PropertyType type) 01353 { 01354 PropertyRNA *prop; 01355 01356 prop= RNA_def_property(srna, "fixed_type", PROP_POINTER, PROP_NONE); 01357 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01358 RNA_def_property_struct_type(prop, "Struct"); 01359 if(type == PROP_POINTER) 01360 RNA_def_property_pointer_funcs(prop, "rna_PointerProperty_fixed_type_get", NULL, NULL, NULL); 01361 else 01362 RNA_def_property_pointer_funcs(prop, "rna_CollectionProperty_fixed_type_get", NULL, NULL, NULL); 01363 RNA_def_property_ui_text(prop, "Pointer Type", "Fixed pointer type, empty if variable type"); 01364 } 01365 01366 void RNA_def_rna(BlenderRNA *brna) 01367 { 01368 StructRNA *srna; 01369 PropertyRNA *prop; 01370 01371 /* Struct*/ 01372 rna_def_struct(brna); 01373 01374 /* Property */ 01375 rna_def_property(brna); 01376 01377 /* BoolProperty */ 01378 srna= RNA_def_struct(brna, "BoolProperty", "Property"); 01379 RNA_def_struct_ui_text(srna, "Boolean Definition", "RNA boolean property definition"); 01380 rna_def_number_property(srna, PROP_BOOLEAN); 01381 01382 /* IntProperty */ 01383 srna= RNA_def_struct(brna, "IntProperty", "Property"); 01384 RNA_def_struct_ui_text(srna, "Int Definition", "RNA integer number property definition"); 01385 rna_def_number_property(srna, PROP_INT); 01386 01387 /* FloatProperty */ 01388 srna= RNA_def_struct(brna, "FloatProperty", "Property"); 01389 RNA_def_struct_ui_text(srna, "Float Definition", "RNA floating pointer number property definition"); 01390 rna_def_number_property(srna, PROP_FLOAT); 01391 01392 /* StringProperty */ 01393 srna= RNA_def_struct(brna, "StringProperty", "Property"); 01394 RNA_def_struct_ui_text(srna, "String Definition", "RNA text string property definition"); 01395 rna_def_string_property(srna); 01396 01397 /* EnumProperty */ 01398 srna= RNA_def_struct(brna, "EnumProperty", "Property"); 01399 RNA_def_struct_ui_text(srna, "Enum Definition", "RNA enumeration property definition, to choose from a number of predefined options"); 01400 rna_def_enum_property(brna, srna); 01401 01402 /* PointerProperty */ 01403 srna= RNA_def_struct(brna, "PointerProperty", "Property"); 01404 RNA_def_struct_ui_text(srna, "Pointer Definition", "RNA pointer property to point to another RNA struct"); 01405 rna_def_pointer_property(srna, PROP_POINTER); 01406 01407 /* CollectionProperty */ 01408 srna= RNA_def_struct(brna, "CollectionProperty", "Property"); 01409 RNA_def_struct_ui_text(srna, "Collection Definition", "RNA collection property to define lists, arrays and mappings"); 01410 rna_def_pointer_property(srna, PROP_COLLECTION); 01411 01412 /* Function */ 01413 rna_def_function(brna); 01414 01415 /* Blender RNA */ 01416 srna= RNA_def_struct(brna, "BlenderRNA", NULL); 01417 RNA_def_struct_ui_text(srna, "Blender RNA", "Blender RNA structure definitions"); 01418 RNA_def_struct_ui_icon(srna, ICON_RNA); 01419 01420 prop= RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE); 01421 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 01422 RNA_def_property_struct_type(prop, "Struct"); 01423 RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 01424 /* included for speed, can be removed */ 01425 #if 0 01426 0,0,0,0); 01427 #else 01428 "rna_BlenderRNA_structs_length", "rna_BlenderRNA_structs_lookup_int", "rna_BlenderRNA_structs_lookup_string", NULL); 01429 #endif 01430 01431 RNA_def_property_ui_text(prop, "Structs", ""); 01432 } 01433 01434 #endif 01435