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