Blender  V3.3
rna_access.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <ctype.h>
8 #include <stddef.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "DNA_ID.h"
15 #include "DNA_constraint_types.h"
16 #include "DNA_modifier_types.h"
17 #include "DNA_scene_types.h"
19 
20 #include "BLI_alloca.h"
21 #include "BLI_blenlib.h"
22 #include "BLI_dynstr.h"
23 #include "BLI_ghash.h"
24 #include "BLI_math.h"
25 #include "BLI_threads.h"
26 #include "BLI_utildefines.h"
27 
28 #include "BLF_api.h"
29 #include "BLT_translation.h"
30 
31 #include "BKE_anim_data.h"
32 #include "BKE_collection.h"
33 #include "BKE_context.h"
34 #include "BKE_fcurve.h"
35 #include "BKE_global.h"
36 #include "BKE_idprop.h"
37 #include "BKE_idtype.h"
38 #include "BKE_lib_override.h"
39 #include "BKE_main.h"
40 #include "BKE_node.h"
41 #include "BKE_report.h"
42 
43 #include "DEG_depsgraph.h"
44 #include "DEG_depsgraph_build.h"
45 
46 #include "RNA_access.h"
47 #include "RNA_define.h"
48 #include "RNA_enum_types.h"
49 #include "RNA_path.h"
50 
51 #include "WM_api.h"
52 #include "WM_message.h"
53 
54 /* flush updates */
55 #include "DNA_object_types.h"
56 #include "WM_types.h"
57 
58 #include "rna_access_internal.h"
59 #include "rna_internal.h"
60 
62 
63 /* Init/Exit */
64 
65 void RNA_init(void)
66 {
67  StructRNA *srna;
68  PropertyRNA *prop;
69 
72 
73  for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
74  if (!srna->cont.prophash) {
75  srna->cont.prophash = BLI_ghash_str_new("RNA_init gh");
76 
77  for (prop = srna->cont.properties.first; prop; prop = prop->next) {
78  if (!(prop->flag_internal & PROP_INTERN_BUILTIN)) {
79  BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop);
80  }
81  }
82  }
84  BLI_ghash_insert(BLENDER_RNA.structs_map, (void *)srna->identifier, srna);
86  }
87 }
88 
89 void RNA_exit(void)
90 {
91  StructRNA *srna;
92 
93  for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
94  if (srna->cont.prophash) {
96  srna->cont.prophash = NULL;
97  }
98  }
99 
101 }
102 
103 /* Pointer */
104 
106 {
107  r_ptr->owner_id = NULL;
108  r_ptr->type = &RNA_BlendData;
109  r_ptr->data = main;
110 }
111 
113 {
114  StructRNA *type, *idtype = NULL;
115 
116  if (id) {
117  PointerRNA tmp = {NULL};
118  tmp.data = id;
119  idtype = rna_ID_refine(&tmp);
120 
121  while (idtype->refine) {
122  type = idtype->refine(&tmp);
123 
124  if (type == idtype) {
125  break;
126  }
127  idtype = type;
128  }
129  }
130 
131  r_ptr->owner_id = id;
132  r_ptr->type = idtype;
133  r_ptr->data = id;
134 }
135 
136 void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
137 {
138 #if 0 /* UNUSED */
139  StructRNA *idtype = NULL;
140 
141  if (id) {
142  PointerRNA tmp = {0};
143  tmp.data = id;
144  idtype = rna_ID_refine(&tmp);
145  }
146 #endif
147 
148  r_ptr->owner_id = id;
149  r_ptr->type = type;
150  r_ptr->data = data;
151 
152  if (data) {
153  while (r_ptr->type && r_ptr->type->refine) {
154  StructRNA *rtype = r_ptr->type->refine(r_ptr);
155 
156  if (rtype == r_ptr->type) {
157  break;
158  }
159  r_ptr->type = rtype;
160  }
161  }
162 }
163 
165 {
166  return (ptr->data == NULL) || (ptr->owner_id == NULL) || (ptr->type == NULL);
167 }
168 
170 {
171  if (type && type->flag & STRUCT_ID) {
172  ptr->owner_id = ptr->data;
173  }
174  else {
175  ptr->owner_id = parent->owner_id;
176  }
177 }
178 
180 {
181  r_ptr->owner_id = NULL;
182  r_ptr->type = &RNA_BlenderRNA;
183  r_ptr->data = &BLENDER_RNA;
184 }
185 
187 {
188  if (data) {
190  result.data = data;
191  result.type = type;
193 
194  while (result.type->refine) {
195  type = result.type->refine(&result);
196 
197  if (type == result.type) {
198  break;
199  }
200  result.type = type;
201  }
202  return result;
203  }
204  return PointerRNA_NULL;
205 }
206 
208 {
209 #if 0 /* works but this case if covered by more general code below. */
210  if (RNA_struct_is_ID(ptr->type)) {
211  /* simple case */
213  }
214  else
215 #endif
216  {
217  StructRNA *base;
218  PointerRNA t_ptr;
219  *r_ptr = *ptr; /* initialize as the same in case can't recast */
220 
221  for (base = ptr->type->base; base; base = base->base) {
222  t_ptr = rna_pointer_inherit_refine(ptr, base, ptr->data);
223  if (t_ptr.type && t_ptr.type != ptr->type) {
224  *r_ptr = t_ptr;
225  }
226  }
227  }
228 }
229 
230 /* ID Properties */
231 
233 {
234  /* so the property is seen as 'set' by rna */
235  idprop->flag &= ~IDP_FLAG_GHOST;
236 }
237 
239 {
240  StructRNA *type = ptr->type;
241  if (type == NULL) {
242  return NULL;
243  }
244  if (type->idproperties == NULL) {
245  return NULL;
246  }
247 
248  return type->idproperties(ptr);
249 }
250 
252 {
253  IDProperty **property_ptr = RNA_struct_idprops_p(ptr);
254  if (property_ptr == NULL) {
255  return NULL;
256  }
257 
258  if (create && *property_ptr == NULL) {
259  IDPropertyTemplate val = {0};
260  *property_ptr = IDP_New(IDP_GROUP, &val, __func__);
261  }
262 
263  return *property_ptr;
264 }
265 
267 {
268  return (srna && srna->idproperties);
269 }
270 
272 {
273  IDProperty *group = RNA_struct_idprops(ptr, 0);
274 
275  if (group) {
276  if (group->type == IDP_GROUP) {
277  return IDP_GetPropertyFromGroup(group, name);
278  }
279  /* Not sure why that happens sometimes, with nested properties... */
280  /* Seems to be actually array prop, name is usually "0"... To be sorted out later. */
281 #if 0
282  printf(
283  "Got unexpected IDProp container when trying to retrieve %s: %d\n", name, group->type);
284 #endif
285  }
286 
287  return NULL;
288 }
289 
290 static void rna_idproperty_free(PointerRNA *ptr, const char *name)
291 {
292  IDProperty *group = RNA_struct_idprops(ptr, 0);
293 
294  if (group) {
295  IDProperty *idprop = IDP_GetPropertyFromGroup(group, name);
296  if (idprop) {
297  IDP_FreeFromGroup(group, idprop);
298  }
299  }
300 }
301 
303 {
304  if (prop->magic == RNA_MAGIC) {
305  int arraylen[RNA_MAX_ARRAY_DIMENSION];
306  return (prop->getlength && ptr->data) ? prop->getlength(ptr, arraylen) :
307  (int)prop->totarraylength;
308  }
309  IDProperty *idprop = (IDProperty *)prop;
310 
311  if (idprop->type == IDP_ARRAY) {
312  return idprop->len;
313  }
314  return 0;
315 }
316 
318 {
319  if (prop->magic == RNA_MAGIC) {
320  return (prop->getlength || prop->totarraylength);
321  }
322  IDProperty *idprop = (IDProperty *)prop;
323 
324  return (idprop->type == IDP_ARRAY);
325 }
326 
328  PropertyRNA *prop,
329  int length[])
330 {
331  if (prop->magic == RNA_MAGIC) {
332  if (prop->getlength) {
333  prop->getlength(ptr, length);
334  }
335  else {
336  memcpy(length, prop->arraylength, prop->arraydimension * sizeof(int));
337  }
338  }
339  else {
340  IDProperty *idprop = (IDProperty *)prop;
341 
342  if (idprop->type == IDP_ARRAY) {
343  length[0] = idprop->len;
344  }
345  else {
346  length[0] = 0;
347  }
348  }
349 }
350 
352 {
353  /* this verifies if the idproperty actually matches the property
354  * description and otherwise removes it. this is to ensure that
355  * rna property access is type safe, e.g. if you defined the rna
356  * to have a certain array length you can count on that staying so */
357 
358  switch (idprop->type) {
359  case IDP_IDPARRAY:
360  if (prop->type != PROP_COLLECTION) {
361  return false;
362  }
363  break;
364  case IDP_ARRAY:
365  if (rna_ensure_property_array_length(ptr, prop) != idprop->len) {
366  return false;
367  }
368 
369  if (idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT) {
370  return false;
371  }
372  if (idprop->subtype == IDP_INT && !ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
373  return false;
374  }
375 
376  break;
377  case IDP_INT:
378  if (!ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
379  return false;
380  }
381  break;
382  case IDP_FLOAT:
383  case IDP_DOUBLE:
384  if (prop->type != PROP_FLOAT) {
385  return false;
386  }
387  break;
388  case IDP_STRING:
389  if (prop->type != PROP_STRING) {
390  return false;
391  }
392  break;
393  case IDP_GROUP:
394  case IDP_ID:
395  if (prop->type != PROP_POINTER) {
396  return false;
397  }
398  break;
399  default:
400  return false;
401  }
402 
403  return true;
404 }
405 
407  &rna_PropertyGroupItem_string,
408  &rna_PropertyGroupItem_int,
409  &rna_PropertyGroupItem_float,
410  NULL,
411  NULL,
412  NULL,
413  &rna_PropertyGroupItem_group,
414  &rna_PropertyGroupItem_id,
415  &rna_PropertyGroupItem_double,
416  &rna_PropertyGroupItem_idp_array,
417 };
418 
420  NULL,
421  &rna_PropertyGroupItem_int_array,
422  &rna_PropertyGroupItem_float_array,
423  NULL,
424  NULL,
425  NULL,
426  &rna_PropertyGroupItem_collection,
427  NULL,
428  &rna_PropertyGroupItem_double_array,
429 };
430 
432  PointerRNA *ptr,
433  PropertyRNAOrID *r_prop_rna_or_id)
434 {
435  /* This is quite a hack, but avoids some complexity in the API. we
436  * pass IDProperty structs as PropertyRNA pointers to the outside.
437  * We store some bytes in PropertyRNA structs that allows us to
438  * distinguish it from IDProperty structs. If it is an ID property,
439  * we look up an IDP PropertyRNA based on the type, and set the data
440  * pointer to the IDProperty. */
441  memset(r_prop_rna_or_id, 0, sizeof(*r_prop_rna_or_id));
442 
443  r_prop_rna_or_id->ptr = *ptr;
444  r_prop_rna_or_id->rawprop = prop;
445 
446  if (prop->magic == RNA_MAGIC) {
447  r_prop_rna_or_id->rnaprop = prop;
448  r_prop_rna_or_id->identifier = prop->identifier;
449 
450  r_prop_rna_or_id->is_array = prop->getlength || prop->totarraylength;
451  if (r_prop_rna_or_id->is_array) {
452  int arraylen[RNA_MAX_ARRAY_DIMENSION];
453  r_prop_rna_or_id->array_len = (prop->getlength && ptr->data) ?
454  (uint)prop->getlength(ptr, arraylen) :
455  prop->totarraylength;
456  }
457 
458  if (prop->flag & PROP_IDPROPERTY) {
459  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
460 
461  if (idprop != NULL && !rna_idproperty_verify_valid(ptr, prop, idprop)) {
462  IDProperty *group = RNA_struct_idprops(ptr, 0);
463 
464  IDP_FreeFromGroup(group, idprop);
465  idprop = NULL;
466  }
467 
468  r_prop_rna_or_id->idprop = idprop;
469  r_prop_rna_or_id->is_set = idprop != NULL && (idprop->flag & IDP_FLAG_GHOST) == 0;
470  }
471  else {
472  /* Full static RNA properties are always set. */
473  r_prop_rna_or_id->is_set = true;
474  }
475  }
476  else {
477  IDProperty *idprop = (IDProperty *)prop;
478  /* Given prop may come from the custom properties of another data, ensure we get the one from
479  * given data ptr. */
480  IDProperty *idprop_evaluated = rna_idproperty_find(ptr, idprop->name);
481  if (idprop_evaluated != NULL && idprop->type != idprop_evaluated->type) {
482  idprop_evaluated = NULL;
483  }
484 
485  r_prop_rna_or_id->idprop = idprop_evaluated;
486  r_prop_rna_or_id->is_idprop = true;
487  /* Full IDProperties are always set, if it exists. */
488  r_prop_rna_or_id->is_set = (idprop_evaluated != NULL);
489 
490  r_prop_rna_or_id->identifier = idprop->name;
491  if (idprop->type == IDP_ARRAY) {
492  r_prop_rna_or_id->rnaprop = arraytypemap[(int)(idprop->subtype)];
493  r_prop_rna_or_id->is_array = true;
494  r_prop_rna_or_id->array_len = idprop_evaluated != NULL ? (uint)idprop_evaluated->len : 0;
495  }
496  else {
497  r_prop_rna_or_id->rnaprop = typemap[(int)(idprop->type)];
498  }
499  }
500 }
501 
503 {
504  PropertyRNAOrID prop_rna_or_id;
505 
506  rna_property_rna_or_id_get(*prop, ptr, &prop_rna_or_id);
507 
508  *prop = prop_rna_or_id.rnaprop;
509  return prop_rna_or_id.idprop;
510 }
511 
513 {
514  PropertyRNAOrID prop_rna_or_id;
515 
516  rna_property_rna_or_id_get(*prop, ptr, &prop_rna_or_id);
517 
518  *prop = prop_rna_or_id.rnaprop;
519  return (prop_rna_or_id.is_idprop || prop_rna_or_id.idprop != NULL) ?
520  (PropertyRNA *)prop_rna_or_id.idprop :
521  prop_rna_or_id.rnaprop;
522 }
523 
525 {
526  /* the quick version if we don't need the idproperty */
527 
528  if (prop->magic == RNA_MAGIC) {
529  return prop;
530  }
531 
532  {
533  IDProperty *idprop = (IDProperty *)prop;
534 
535  if (idprop->type == IDP_ARRAY) {
536  return arraytypemap[(int)(idprop->subtype)];
537  }
538  return typemap[(int)(idprop->type)];
539  }
540 }
541 
542 static const char *rna_ensure_property_identifier(const PropertyRNA *prop)
543 {
544  if (prop->magic == RNA_MAGIC) {
545  return prop->identifier;
546  }
547  return ((const IDProperty *)prop)->name;
548 }
549 
550 static const char *rna_ensure_property_description(const PropertyRNA *prop)
551 {
552  if (prop->magic == RNA_MAGIC) {
553  return prop->description;
554  }
555 
556  const IDProperty *idprop = (const IDProperty *)prop;
557  if (idprop->ui_data) {
558  const IDPropertyUIData *ui_data = idprop->ui_data;
559  return ui_data->description;
560  }
561 
562  return "";
563 }
564 
565 static const char *rna_ensure_property_name(const PropertyRNA *prop)
566 {
567  const char *name;
568 
569  if (prop->magic == RNA_MAGIC) {
570  name = prop->name;
571  }
572  else {
573  name = ((const IDProperty *)prop)->name;
574  }
575 
576  return name;
577 }
578 
579 /* Structs */
580 
581 StructRNA *RNA_struct_find(const char *identifier)
582 {
583  return BLI_ghash_lookup(BLENDER_RNA.structs_map, identifier);
584 }
585 
587 {
588  return type->identifier;
589 }
590 
591 const char *RNA_struct_ui_name(const StructRNA *type)
592 {
593  return CTX_IFACE_(type->translation_context, type->name);
594 }
595 
597 {
598  return type->name;
599 }
600 
602 {
603  if (type) {
604  return type->icon;
605  }
606  return ICON_DOT;
607 }
608 
610 {
611  return TIP_(type->description);
612 }
613 
615 {
616  return type->description;
617 }
618 
620 {
621  return type->translation_context;
622 }
623 
625 {
626  return type->nameproperty;
627 }
628 
630 {
631  return type->prop_tag_defines;
632 }
633 
635 {
636  return type->iteratorproperty;
637 }
638 
640 {
641  return type->base;
642 }
643 
644 const StructRNA *RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
645 {
646  while (type) {
647  if (type->base == parent_type) {
648  return type;
649  }
650  type = type->base;
651  }
652  return NULL;
653 }
654 
656 {
657  return (type->flag & STRUCT_ID) != 0;
658 }
659 
661 {
662  return (type->flag & STRUCT_UNDO) != 0;
663 }
664 
666 {
667  return (type->flag & STRUCT_NO_IDPROPERTIES) == 0;
668 }
669 
671 {
673 }
674 
676 {
677  return (type->flag & (STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES | STRUCT_ID)) != 0;
678 }
679 
680 bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
681 {
682  IDProperty *group = RNA_struct_idprops(ptr, 0);
683 
684  if (group) {
685  IDProperty *idp = IDP_GetPropertyFromGroup(group, identifier);
686  if (idp) {
687  IDP_FreeFromGroup(group, idp);
688 
689  return true;
690  }
691  }
692  return false;
693 }
694 
695 bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
696 {
697  const StructRNA *base;
698 
699  if (srna == &RNA_AnyType) {
700  return true;
701  }
702 
703  if (!type) {
704  return false;
705  }
706 
707  /* ptr->type is always maximally refined */
708  for (base = type; base; base = base->base) {
709  if (base == srna) {
710  return true;
711  }
712  }
713 
714  return false;
715 }
716 
718 {
719  if (identifier[0] == '[' && identifier[1] == '"') {
720  /* id prop lookup, not so common */
721  PropertyRNA *r_prop = NULL;
722  PointerRNA r_ptr; /* only support single level props */
723  if (RNA_path_resolve_property(ptr, identifier, &r_ptr, &r_prop) && (r_ptr.type == ptr->type) &&
724  (r_ptr.data == ptr->data)) {
725  return r_prop;
726  }
727  }
728  else {
729  /* most common case */
731  PointerRNA propptr;
732 
733  if (RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr)) {
734  return propptr.data;
735  }
736  }
737 
738  return NULL;
739 }
740 
741 /* Find the property which uses the given nested struct */
743 {
744  PropertyRNA *prop = NULL;
745 
746  RNA_STRUCT_BEGIN (ptr, iprop) {
747  /* This assumes that there can only be one user of this nested struct */
748  if (RNA_property_pointer_type(ptr, iprop) == srna) {
749  prop = iprop;
750  break;
751  }
752  }
753  RNA_PROP_END;
754 
755  return prop;
756 }
757 
759 {
760  /* NOTE: prop_test could be freed memory, only use for comparison. */
761 
762  /* validate the RNA is ok */
763  PropertyRNA *iterprop;
764  bool found = false;
765 
767 
768  RNA_PROP_BEGIN (ptr, itemptr, iterprop) {
769  /* PropertyRNA *prop = itemptr.data; */
770  if (prop_test == (PropertyRNA *)itemptr.data) {
771  found = true;
772  break;
773  }
774  }
775  RNA_PROP_END;
776 
777  return found;
778 }
779 
781 {
782  PointerRNA struct_ptr;
783  unsigned int counter = 0;
784 
785  RNA_pointer_create(NULL, srna, NULL, &struct_ptr);
786 
787  RNA_STRUCT_BEGIN (&struct_ptr, prop) {
788  counter++;
789  UNUSED_VARS(prop);
790  }
792 
793  return counter;
794 }
795 
797 {
798  return &srna->cont.properties;
799 }
800 
802 {
803  return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier));
804 }
805 
806 PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
807 {
808  for (; srna; srna = srna->base) {
809  PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, identifier);
810  if (prop != NULL) {
811  return prop;
812  }
813  }
814  return NULL;
815 }
816 
817 FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier)
818 {
819 #if 1
820  FunctionRNA *func;
821  for (; srna; srna = srna->base) {
823  &srna->functions, identifier, offsetof(FunctionRNA, identifier));
824  if (func) {
825  return func;
826  }
827  }
828  return NULL;
829 
830  /* functional but slow */
831 #else
832  PointerRNA tptr;
833  PropertyRNA *iterprop;
834  FunctionRNA *func;
835 
836  RNA_pointer_create(NULL, &RNA_Struct, srna, &tptr);
837  iterprop = RNA_struct_find_property(&tptr, "functions");
838 
839  func = NULL;
840 
841  RNA_PROP_BEGIN (&tptr, funcptr, iterprop) {
842  if (STREQ(identifier, RNA_function_identifier(funcptr.data))) {
843  func = funcptr.data;
844  break;
845  }
846  }
847  RNA_PROP_END;
848 
849  return func;
850 #endif
851 }
852 
854 {
855  return &srna->functions;
856 }
857 
859 {
860  return type->reg;
861 }
862 
864 {
865  do {
866  if (type->unreg) {
867  return type->unreg;
868  }
869  } while ((type = type->base));
870 
871  return NULL;
872 }
873 
875 {
876  StructRNA *type = ptr->type;
877 
878  do {
879  if (type->instance) {
880  return type->instance(ptr);
881  }
882  } while ((type = type->base));
883 
884  return NULL;
885 }
886 
888 {
889  return srna->py_type;
890 }
891 
892 void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
893 {
894  srna->py_type = py_type;
895 }
896 
898 {
899  return srna->blender_type;
900 }
901 
902 void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
903 {
904  srna->blender_type = blender_type;
905 }
906 
907 char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
908 {
909  PropertyRNA *nameprop;
910 
911  if (ptr->data && (nameprop = RNA_struct_name_property(ptr->type))) {
912  return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
913  }
914 
915  return NULL;
916 }
917 
918 bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
919 {
920  const StructRNA *srna_exists = RNA_struct_find(identifier);
921  if (UNLIKELY(srna_exists != NULL)) {
922  /* Use comprehensive string construction since this is such a rare occurrence
923  * and information here may cut down time troubleshooting. */
924  DynStr *dynstr = BLI_dynstr_new();
925  BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier);
926  BLI_dynstr_append(dynstr, srna_exists->identifier);
927  int i = 0;
928  if (srna_exists->base) {
929  for (const StructRNA *base = srna_exists->base; base; base = base->base) {
930  BLI_dynstr_append(dynstr, "(");
931  BLI_dynstr_append(dynstr, base->identifier);
932  i += 1;
933  }
934  while (i--) {
935  BLI_dynstr_append(dynstr, ")");
936  }
937  }
938  BLI_dynstr_append(dynstr, "'.");
939  char *result = BLI_dynstr_get_cstring(dynstr);
940  BLI_dynstr_free(dynstr);
941  BKE_report(reports, RPT_ERROR, result);
942  MEM_freeN(result);
943  return false;
944  }
945  return true;
946 }
947 
949  const char *identifier,
950  const char *sep)
951 {
952  const int len_sep = strlen(sep);
953  const int len_id = strlen(identifier);
954  const char *p = strstr(identifier, sep);
955  /* TODO: make error, for now warning until add-ons update. */
956 #if 1
957  const int report_level = RPT_WARNING;
958  const bool failure = true;
959 #else
960  const int report_level = RPT_ERROR;
961  const bool failure = false;
962 #endif
963  if (p == NULL || p == identifier || p + len_sep >= identifier + len_id) {
964  BKE_reportf(reports,
965  report_level,
966  "'%s' does not contain '%s' with prefix and suffix",
967  identifier,
968  sep);
969  return failure;
970  }
971 
972  const char *c, *start, *end, *last;
973  start = identifier;
974  end = p;
975  last = end - 1;
976  for (c = start; c != end; c++) {
977  if (((*c >= 'A' && *c <= 'Z') || ((c != start) && (*c >= '0' && *c <= '9')) ||
978  ((c != start) && (c != last) && (*c == '_'))) == 0) {
979  BKE_reportf(
980  reports, report_level, "'%s' doesn't have upper case alpha-numeric prefix", identifier);
981  return failure;
982  }
983  }
984 
985  start = p + len_sep;
986  end = identifier + len_id;
987  last = end - 1;
988  for (c = start; c != end; c++) {
989  if (((*c >= 'A' && *c <= 'Z') || (*c >= 'a' && *c <= 'z') || (*c >= '0' && *c <= '9') ||
990  ((c != start) && (c != last) && (*c == '_'))) == 0) {
991  BKE_reportf(reports, report_level, "'%s' doesn't have an alpha-numeric suffix", identifier);
992  return failure;
993  }
994  }
995  return true;
996 }
997 
998 /* Property Information */
999 
1000 const char *RNA_property_identifier(const PropertyRNA *prop)
1001 {
1002  return rna_ensure_property_identifier(prop);
1003 }
1004 
1006 {
1007  return TIP_(rna_ensure_property_description(prop));
1008 }
1009 
1011 {
1012  return rna_ensure_property(prop)->type;
1013 }
1014 
1016 {
1017  PropertyRNA *rna_prop = rna_ensure_property(prop);
1018 
1019  /* For custom properties, find and parse the 'subtype' metadata field. */
1020  if (prop->magic != RNA_MAGIC) {
1021  IDProperty *idprop = (IDProperty *)prop;
1022 
1023  if (idprop->ui_data) {
1024  IDPropertyUIData *ui_data = idprop->ui_data;
1025  return (PropertySubType)ui_data->rna_subtype;
1026  }
1027  }
1028 
1029  return rna_prop->subtype;
1030 }
1031 
1033 {
1034  return RNA_SUBTYPE_UNIT(RNA_property_subtype(prop));
1035 }
1036 
1038 {
1039  PropertyRNA *rna_prop = rna_ensure_property(prop);
1040 
1041  switch (rna_prop->type) {
1042  case PROP_INT: {
1043  IntPropertyRNA *iprop = (IntPropertyRNA *)rna_prop;
1044  return iprop->ui_scale_type;
1045  }
1046  case PROP_FLOAT: {
1047  FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_prop;
1048  return fprop->ui_scale_type;
1049  }
1050  default:
1051  return PROP_SCALE_LINEAR;
1052  }
1053 }
1054 
1056 {
1057  return rna_ensure_property(prop)->flag;
1058 }
1059 
1061 {
1062  return rna_ensure_property(prop)->tags;
1063 }
1064 
1066 {
1067  return (rna_ensure_property(prop)->flag_internal & PROP_INTERN_BUILTIN) != 0;
1068 }
1069 
1071 {
1072  return prop->py_data;
1073 }
1074 
1076 {
1077  return rna_ensure_property_array_length(ptr, prop);
1078 }
1079 
1081 {
1082  return rna_ensure_property_array_check(prop);
1083 }
1084 
1086 {
1087  PropertyRNA *rprop = rna_ensure_property(prop);
1088 
1089  if (length) {
1091  }
1092 
1093  return rprop->arraydimension;
1094 }
1095 
1097 {
1099 
1101 
1102  return len[dim];
1103 }
1104 
1106 {
1107  const char *vectoritem = "XYZW";
1108  const char *quatitem = "WXYZ";
1109  const char *coloritem = "RGBA";
1110  PropertySubType subtype = RNA_property_subtype(prop);
1111 
1112  BLI_assert(index >= 0);
1113 
1114  /* get string to use for array index */
1115  if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1116  return quatitem[index];
1117  }
1118  if ((index < 4) && ELEM(subtype,
1121  PROP_XYZ,
1123  PROP_EULER,
1124  PROP_VELOCITY,
1126  PROP_COORDS)) {
1127  return vectoritem[index];
1128  }
1129  if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1130  return coloritem[index];
1131  }
1132 
1133  return '\0';
1134 }
1135 
1137 {
1138  /* Don't use custom property subtypes in RNA path lookup. */
1139  PropertySubType subtype = rna_ensure_property(prop)->subtype;
1140 
1141  /* get index based on string name/alias */
1142  /* maybe a function to find char index in string would be better than all the switches */
1143  if (ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1144  switch (name) {
1145  case 'w':
1146  return 0;
1147  case 'x':
1148  return 1;
1149  case 'y':
1150  return 2;
1151  case 'z':
1152  return 3;
1153  }
1154  }
1155  else if (ELEM(subtype,
1158  PROP_XYZ,
1160  PROP_EULER,
1161  PROP_VELOCITY,
1162  PROP_ACCELERATION)) {
1163  switch (name) {
1164  case 'x':
1165  return 0;
1166  case 'y':
1167  return 1;
1168  case 'z':
1169  return 2;
1170  case 'w':
1171  return 3;
1172  }
1173  }
1174  else if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1175  switch (name) {
1176  case 'r':
1177  return 0;
1178  case 'g':
1179  return 1;
1180  case 'b':
1181  return 2;
1182  case 'a':
1183  return 3;
1184  }
1185  }
1186 
1187  return -1;
1188 }
1189 
1190 void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
1191 {
1193  int softmin, softmax;
1194 
1195  if (prop->magic != RNA_MAGIC) {
1196  const IDProperty *idprop = (IDProperty *)prop;
1197  if (idprop->ui_data) {
1198  IDPropertyUIDataInt *ui_data = (IDPropertyUIDataInt *)idprop->ui_data;
1199  *hardmin = ui_data->min;
1200  *hardmax = ui_data->max;
1201  }
1202  else {
1203  *hardmin = INT_MIN;
1204  *hardmax = INT_MAX;
1205  }
1206  return;
1207  }
1208 
1209  if (iprop->range) {
1210  *hardmin = INT_MIN;
1211  *hardmax = INT_MAX;
1212 
1213  iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1214  }
1215  else if (iprop->range_ex) {
1216  *hardmin = INT_MIN;
1217  *hardmax = INT_MAX;
1218 
1219  iprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1220  }
1221  else {
1222  *hardmin = iprop->hardmin;
1223  *hardmax = iprop->hardmax;
1224  }
1225 }
1226 
1228  PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
1229 {
1231  int hardmin, hardmax;
1232 
1233  if (prop->magic != RNA_MAGIC) {
1234  const IDProperty *idprop = (IDProperty *)prop;
1235  if (idprop->ui_data) {
1236  IDPropertyUIDataInt *ui_data_int = (IDPropertyUIDataInt *)idprop->ui_data;
1237  *softmin = ui_data_int->soft_min;
1238  *softmax = ui_data_int->soft_max;
1239  *step = ui_data_int->step;
1240  }
1241  else {
1242  *softmin = INT_MIN;
1243  *softmax = INT_MAX;
1244  *step = 1;
1245  }
1246  return;
1247  }
1248 
1249  *softmin = iprop->softmin;
1250  *softmax = iprop->softmax;
1251 
1252  if (iprop->range) {
1253  hardmin = INT_MIN;
1254  hardmax = INT_MAX;
1255 
1256  iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1257 
1258  *softmin = max_ii(*softmin, hardmin);
1259  *softmax = min_ii(*softmax, hardmax);
1260  }
1261  else if (iprop->range_ex) {
1262  hardmin = INT_MIN;
1263  hardmax = INT_MAX;
1264 
1265  iprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1266 
1267  *softmin = max_ii(*softmin, hardmin);
1268  *softmax = min_ii(*softmax, hardmax);
1269  }
1270 
1271  *step = iprop->step;
1272 }
1273 
1274 void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
1275 {
1277  float softmin, softmax;
1278 
1279  if (prop->magic != RNA_MAGIC) {
1280  const IDProperty *idprop = (IDProperty *)prop;
1281  if (idprop->ui_data) {
1282  IDPropertyUIDataFloat *ui_data = (IDPropertyUIDataFloat *)idprop->ui_data;
1283  *hardmin = (float)ui_data->min;
1284  *hardmax = (float)ui_data->max;
1285  }
1286  else {
1287  *hardmin = -FLT_MAX;
1288  *hardmax = FLT_MAX;
1289  }
1290  return;
1291  }
1292 
1293  if (fprop->range) {
1294  *hardmin = -FLT_MAX;
1295  *hardmax = FLT_MAX;
1296 
1297  fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1298  }
1299  else if (fprop->range_ex) {
1300  *hardmin = -FLT_MAX;
1301  *hardmax = FLT_MAX;
1302 
1303  fprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1304  }
1305  else {
1306  *hardmin = fprop->hardmin;
1307  *hardmax = fprop->hardmax;
1308  }
1309 }
1310 
1312  PropertyRNA *prop,
1313  float *softmin,
1314  float *softmax,
1315  float *step,
1316  float *precision)
1317 {
1319  float hardmin, hardmax;
1320 
1321  if (prop->magic != RNA_MAGIC) {
1322  const IDProperty *idprop = (IDProperty *)prop;
1323  if (idprop->ui_data) {
1324  IDPropertyUIDataFloat *ui_data = (IDPropertyUIDataFloat *)idprop->ui_data;
1325  *softmin = (float)ui_data->soft_min;
1326  *softmax = (float)ui_data->soft_max;
1327  *step = ui_data->step;
1328  *precision = (float)ui_data->precision;
1329  }
1330  else {
1331  *softmin = -FLT_MAX;
1332  *softmax = FLT_MAX;
1333  *step = 1.0f;
1334  *precision = 3.0f;
1335  }
1336  return;
1337  }
1338 
1339  *softmin = fprop->softmin;
1340  *softmax = fprop->softmax;
1341 
1342  if (fprop->range) {
1343  hardmin = -FLT_MAX;
1344  hardmax = FLT_MAX;
1345 
1346  fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1347 
1348  *softmin = max_ff(*softmin, hardmin);
1349  *softmax = min_ff(*softmax, hardmax);
1350  }
1351  else if (fprop->range_ex) {
1352  hardmin = -FLT_MAX;
1353  hardmax = FLT_MAX;
1354 
1355  fprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1356 
1357  *softmin = max_ff(*softmin, hardmin);
1358  *softmax = min_ff(*softmax, hardmax);
1359  }
1360 
1361  *step = fprop->step;
1362  *precision = (float)fprop->precision;
1363 }
1364 
1366 {
1367  float min, max;
1368 
1369  RNA_property_float_range(ptr, prop, &min, &max);
1370 
1371  if (*value < min) {
1372  *value = min;
1373  return -1;
1374  }
1375  if (*value > max) {
1376  *value = max;
1377  return 1;
1378  }
1379  return 0;
1380 }
1381 
1383 {
1384  int min, max;
1385 
1386  RNA_property_int_range(ptr, prop, &min, &max);
1387 
1388  if (*value < min) {
1389  *value = min;
1390  return -1;
1391  }
1392  if (*value > max) {
1393  *value = max;
1394  return 1;
1395  }
1396  return 0;
1397 }
1398 
1400 {
1402  return sprop->maxlength;
1403 }
1404 
1406 {
1407  prop = rna_ensure_property(prop);
1408 
1409  if (prop->type == PROP_POINTER) {
1410  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1411 
1412  if (pprop->type_fn) {
1413  return pprop->type_fn(ptr);
1414  }
1415  if (pprop->type) {
1416  return pprop->type;
1417  }
1418  }
1419  else if (prop->type == PROP_COLLECTION) {
1421 
1422  if (cprop->item_type) {
1423  return cprop->item_type;
1424  }
1425  }
1426  /* ignore other types, rna_struct_find_nested calls with unchecked props */
1427 
1428  return &RNA_UnknownType;
1429 }
1430 
1432 {
1433  prop = rna_ensure_property(prop);
1434 
1435  if (prop->type == PROP_POINTER) {
1436  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1437 
1438  if (pprop->poll) {
1439  if (rna_idproperty_check(&prop, ptr)) {
1440  return ((PropPointerPollFuncPy)pprop->poll)(ptr, *value, prop);
1441  }
1442  return pprop->poll(ptr, *value);
1443  }
1444 
1445  return 1;
1446  }
1447 
1448  printf("%s: %s is not a pointer property.\n", __func__, prop->identifier);
1449  return 0;
1450 }
1451 
1453  PointerRNA *ptr,
1454  PropertyRNA *prop,
1455  const bool use_static,
1456  const EnumPropertyItem **r_item,
1457  int *r_totitem,
1458  bool *r_free)
1459 {
1461 
1462  *r_free = false;
1463 
1464  if (!use_static && (eprop->item_fn != NULL)) {
1465  const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
1467  (ptr->owner_id == NULL));
1468  if (C != NULL || no_context) {
1469  const EnumPropertyItem *item;
1470 
1471  item = eprop->item_fn(no_context ? NULL : C, ptr, prop, r_free);
1472 
1473  /* any callbacks returning NULL should be fixed */
1474  BLI_assert(item != NULL);
1475 
1476  if (r_totitem) {
1477  int tot;
1478  for (tot = 0; item[tot].identifier; tot++) {
1479  /* pass */
1480  }
1481  *r_totitem = tot;
1482  }
1483 
1484  *r_item = item;
1485  return;
1486  }
1487  }
1488 
1489  *r_item = eprop->item;
1490  if (r_totitem) {
1491  *r_totitem = eprop->totitem;
1492  }
1493 }
1494 
1496  PointerRNA *ptr,
1497  PropertyRNA *prop,
1498  const EnumPropertyItem **r_item,
1499  int *r_totitem,
1500  bool *r_free)
1501 {
1502  RNA_property_enum_items_ex(C, ptr, prop, false, r_item, r_totitem, r_free);
1503 }
1504 
1505 #ifdef WITH_INTERNATIONAL
1506 static void property_enum_translate(PropertyRNA *prop,
1507  EnumPropertyItem **r_item,
1508  const int *totitem,
1509  bool *r_free)
1510 {
1511  if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
1512  int i;
1513 
1514  /* NOTE: Only do those tests once, and then use BLT_pgettext. */
1515  bool do_iface = BLT_translate_iface();
1516  bool do_tooltip = BLT_translate_tooltips();
1517  EnumPropertyItem *nitem;
1518 
1519  if (!(do_iface || do_tooltip)) {
1520  return;
1521  }
1522 
1523  if (*r_free) {
1524  nitem = *r_item;
1525  }
1526  else {
1527  const EnumPropertyItem *item = *r_item;
1528  int tot;
1529 
1530  if (totitem) {
1531  tot = *totitem;
1532  }
1533  else {
1534  /* count */
1535  for (tot = 0; item[tot].identifier; tot++) {
1536  /* pass */
1537  }
1538  }
1539 
1540  nitem = MEM_mallocN(sizeof(EnumPropertyItem) * (tot + 1), "enum_items_gettexted");
1541  memcpy(nitem, item, sizeof(EnumPropertyItem) * (tot + 1));
1542 
1543  *r_free = true;
1544  }
1545 
1546  for (i = 0; nitem[i].identifier; i++) {
1547  if (nitem[i].name && do_iface) {
1548  nitem[i].name = BLT_pgettext(prop->translation_context, nitem[i].name);
1549  }
1550  if (nitem[i].description && do_tooltip) {
1551  nitem[i].description = BLT_pgettext(NULL, nitem[i].description);
1552  }
1553  }
1554 
1555  *r_item = nitem;
1556  }
1557 }
1558 #endif
1559 
1561  PointerRNA *ptr,
1562  PropertyRNA *prop,
1563  const EnumPropertyItem **r_item,
1564  int *r_totitem,
1565  bool *r_free)
1566 {
1567  RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
1568 
1569 #ifdef WITH_INTERNATIONAL
1570  /* Normally dropping 'const' is _not_ ok, in this case it's only modified if we own the memory
1571  * so allow the exception (callers are creating new arrays in this case). */
1572  property_enum_translate(prop, (EnumPropertyItem **)r_item, r_totitem, r_free);
1573 #endif
1574 }
1575 
1577  PointerRNA *ptr,
1578  PropertyRNA *prop,
1579  const EnumPropertyItem **r_item,
1580  int *r_totitem,
1581  bool *r_free)
1582 {
1584  int mem_size = sizeof(EnumPropertyItem) * (eprop->totitem + 1);
1585  /* first return all items */
1586  EnumPropertyItem *item_array = MEM_mallocN(mem_size, "enum_gettext_all");
1587  *r_free = true;
1588  memcpy(item_array, eprop->item, mem_size);
1589 
1590  if (r_totitem) {
1591  *r_totitem = eprop->totitem;
1592  }
1593 
1594  if (eprop->item_fn != NULL) {
1595  const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
1597  (ptr->owner_id == NULL));
1598  if (C != NULL || no_context) {
1599  const EnumPropertyItem *item;
1600  int i;
1601  bool free = false;
1602 
1603  item = eprop->item_fn(no_context ? NULL : NULL, ptr, prop, &free);
1604 
1605  /* any callbacks returning NULL should be fixed */
1606  BLI_assert(item != NULL);
1607 
1608  for (i = 0; i < eprop->totitem; i++) {
1609  bool exists = false;
1610  int i_fixed;
1611 
1612  /* Items that do not exist on list are returned,
1613  * but have their names/identifiers NULL'ed out. */
1614  for (i_fixed = 0; item[i_fixed].identifier; i_fixed++) {
1615  if (STREQ(item[i_fixed].identifier, item_array[i].identifier)) {
1616  exists = true;
1617  break;
1618  }
1619  }
1620 
1621  if (!exists) {
1622  item_array[i].name = NULL;
1623  item_array[i].identifier = "";
1624  }
1625  }
1626 
1627  if (free) {
1628  MEM_freeN((void *)item);
1629  }
1630  }
1631  }
1632 
1633 #ifdef WITH_INTERNATIONAL
1634  property_enum_translate(prop, &item_array, r_totitem, r_free);
1635 #endif
1636  *r_item = item_array;
1637 }
1638 
1640  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
1641 {
1642  const EnumPropertyItem *item;
1643  bool free;
1644  bool found;
1645 
1646  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1647 
1648  if (item) {
1649  const int i = RNA_enum_from_identifier(item, identifier);
1650  if (i != -1) {
1651  *r_value = item[i].value;
1652  found = true;
1653  }
1654  else {
1655  found = false;
1656  }
1657 
1658  if (free) {
1659  MEM_freeN((void *)item);
1660  }
1661  }
1662  else {
1663  found = false;
1664  }
1665  return found;
1666 }
1667 
1668 bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
1669 {
1670  const int i = RNA_enum_from_value(item, value);
1671  if (i != -1) {
1672  *r_identifier = item[i].identifier;
1673  return true;
1674  }
1675  return false;
1676 }
1677 
1679  const int value,
1680  const char **r_identifier)
1681 {
1682  int index = 0;
1683  for (; item->identifier; item++) {
1684  if (item->identifier[0] && item->value & value) {
1685  r_identifier[index++] = item->identifier;
1686  }
1687  }
1688  r_identifier[index] = NULL;
1689  return index;
1690 }
1691 
1692 bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
1693 {
1694  const int i = RNA_enum_from_value(item, value);
1695  if (i != -1) {
1696  *r_name = item[i].name;
1697  return true;
1698  }
1699  return false;
1700 }
1701 
1703  const int value,
1704  const char **r_description)
1705 {
1706  const int i = RNA_enum_from_value(item, value);
1707  if (i != -1) {
1708  *r_description = item[i].description;
1709  return true;
1710  }
1711  return false;
1712 }
1713 
1714 int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
1715 {
1716  int i = 0;
1717  for (; item->identifier; item++, i++) {
1718  if (item->identifier[0] && STREQ(item->identifier, identifier)) {
1719  return i;
1720  }
1721  }
1722  return -1;
1723 }
1724 
1725 int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
1726 {
1727  int i = 0;
1728  for (; item->identifier; item++, i++) {
1729  if (item->identifier[0] && STREQ(item->name, name)) {
1730  return i;
1731  }
1732  }
1733  return -1;
1734 }
1735 
1736 int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
1737 {
1738  int i = 0;
1739  for (; item->identifier; item++, i++) {
1740  if (item->identifier[0] && item->value == value) {
1741  return i;
1742  }
1743  }
1744  return -1;
1745 }
1746 
1747 unsigned int RNA_enum_items_count(const EnumPropertyItem *item)
1748 {
1749  unsigned int i = 0;
1750 
1751  while (item->identifier) {
1752  item++;
1753  i++;
1754  }
1755 
1756  return i;
1757 }
1758 
1760  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
1761 {
1762  const EnumPropertyItem *item = NULL;
1763  bool free;
1764 
1765  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1766  if (item) {
1767  bool result;
1768  result = RNA_enum_identifier(item, value, identifier);
1769  if (free) {
1770  MEM_freeN((void *)item);
1771  }
1772  return result;
1773  }
1774  return false;
1775 }
1776 
1778  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
1779 {
1780  const EnumPropertyItem *item = NULL;
1781  bool free;
1782 
1783  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1784  if (item) {
1785  bool result;
1786  result = RNA_enum_name(item, value, name);
1787  if (free) {
1788  MEM_freeN((void *)item);
1789  }
1790 
1791  return result;
1792  }
1793  return false;
1794 }
1795 
1797  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
1798 {
1799  bool result;
1800 
1801  result = RNA_property_enum_name(C, ptr, prop, value, name);
1802 
1803  if (result) {
1804  if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
1805  if (BLT_translate_iface()) {
1806  *name = BLT_pgettext(prop->translation_context, *name);
1807  }
1808  }
1809  }
1810 
1811  return result;
1812 }
1813 
1815  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
1816 {
1817  const EnumPropertyItem *item = NULL;
1818  bool free;
1819 
1820  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1821  if (item) {
1822  const int i = RNA_enum_from_value(item, value);
1823  bool result;
1824 
1825  if (i != -1) {
1826  *r_item = item[i];
1827  result = true;
1828  }
1829  else {
1830  result = false;
1831  }
1832 
1833  if (free) {
1834  MEM_freeN((void *)item);
1835  }
1836 
1837  return result;
1838  }
1839  return false;
1840 }
1841 
1843  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
1844 {
1845  const bool result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item);
1846 
1847  if (result && !(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
1848  if (BLT_translate_iface()) {
1849  r_item->name = BLT_pgettext(prop->translation_context, r_item->name);
1850  }
1851  }
1852 
1853  return result;
1854 }
1855 
1857  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
1858 {
1859  const EnumPropertyItem *item = NULL;
1860  bool free;
1861 
1862  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1863  if (item) {
1864  int result;
1865  result = RNA_enum_bitflag_identifiers(item, value, identifier);
1866  if (free) {
1867  MEM_freeN((void *)item);
1868  }
1869 
1870  return result;
1871  }
1872  return 0;
1873 }
1874 
1875 const char *RNA_property_ui_name(const PropertyRNA *prop)
1876 {
1878 }
1879 
1880 const char *RNA_property_ui_name_raw(const PropertyRNA *prop)
1881 {
1882  return rna_ensure_property_name(prop);
1883 }
1884 
1886 {
1887  return TIP_(rna_ensure_property_description(prop));
1888 }
1889 
1891 {
1892  return rna_ensure_property_description(prop);
1893 }
1894 
1896 {
1898 }
1899 
1901 {
1902  return rna_ensure_property((PropertyRNA *)prop)->icon;
1903 }
1904 
1906  PropertyRNA *prop_orig,
1907  const int index,
1908  const char **r_info)
1909 {
1910  ID *id = ptr->owner_id;
1911 
1912  PropertyRNA *prop = rna_ensure_property(prop_orig);
1913 
1914  const char *info = "";
1915  const int flag = (prop->itemeditable != NULL && index >= 0) ?
1916  prop->itemeditable(ptr, index) :
1917  (prop->editable != NULL ? prop->editable(ptr, &info) : prop->flag);
1918  if (r_info != NULL) {
1919  *r_info = info;
1920  }
1921 
1922  /* Early return if the property itself is not editable. */
1923  if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER) != 0) {
1924  if (r_info != NULL && (*r_info)[0] == '\0') {
1925  *r_info = N_("This property is for internal use only and can't be edited");
1926  }
1927  return false;
1928  }
1929 
1930  /* If there is no owning ID, the property is editable at this point. */
1931  if (id == NULL) {
1932  return true;
1933  }
1934 
1935  /* Handle linked or liboverride ID cases. */
1936  const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0;
1937  if (ID_IS_LINKED(id)) {
1938  if (is_linked_prop_exception) {
1939  return true;
1940  }
1941  if (r_info != NULL && (*r_info)[0] == '\0') {
1942  *r_info = N_("Can't edit this property from a linked data-block");
1943  }
1944  return false;
1945  }
1946  if (ID_IS_OVERRIDE_LIBRARY(id)) {
1947  const bool is_liboverride_system = BKE_lib_override_library_is_system_defined(G_MAIN, id);
1948  if (!RNA_property_overridable_get(ptr, prop_orig)) {
1949  if (r_info != NULL && (*r_info)[0] == '\0') {
1950  *r_info = N_("Can't edit this property from an override data-block");
1951  }
1952  return false;
1953  }
1954  if (is_liboverride_system && !is_linked_prop_exception) {
1955  if (r_info != NULL && (*r_info)[0] == '\0') {
1956  *r_info = N_("Can't edit this property from a system override data-block");
1957  }
1958  return false;
1959  }
1960  }
1961 
1962  /* At this point, property is owned by a local ID and therefore fully editable. */
1963  return true;
1964 }
1965 
1967 {
1968  return rna_property_editable_do(ptr, prop, -1, NULL);
1969 }
1970 
1971 bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
1972 {
1973  return rna_property_editable_do(ptr, prop, -1, r_info);
1974 }
1975 
1977 {
1978  int flag;
1979  const char *dummy_info;
1980 
1981  prop = rna_ensure_property(prop);
1982  flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
1983  return (flag & PROP_EDITABLE) != 0;
1984 }
1985 
1987 {
1988  BLI_assert(index >= 0);
1989 
1990  return rna_property_editable_do(ptr, prop, index, NULL);
1991 }
1992 
1994 {
1995  /* check that base ID-block can support animation data */
1997  return false;
1998  }
1999 
2000  prop = rna_ensure_property(prop);
2001 
2002  if (!(prop->flag & PROP_ANIMATABLE)) {
2003  return false;
2004  }
2005 
2006  return (prop->flag & PROP_EDITABLE) != 0;
2007 }
2008 
2010 {
2011  int len = 1, index;
2012  bool driven, special;
2013 
2014  if (!prop) {
2015  return false;
2016  }
2017 
2018  if (RNA_property_array_check(prop)) {
2020  }
2021 
2022  for (index = 0; index < len; index++) {
2023  if (BKE_fcurve_find_by_rna(ptr, prop, index, NULL, NULL, &driven, &special)) {
2024  return true;
2025  }
2026  }
2027 
2028  return false;
2029 }
2031 {
2032  char *path = RNA_path_from_ID_to_property(ptr, prop);
2033  bool ret = false;
2034 
2035  if (path) {
2036  PointerRNA id_ptr;
2037  PointerRNA r_ptr;
2038  PropertyRNA *r_prop;
2039 
2040  RNA_id_pointer_create(ptr->owner_id, &id_ptr);
2041  if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == true) {
2042  ret = (prop == r_prop);
2043  }
2044  MEM_freeN(path);
2045  }
2046 
2047  return ret;
2048 }
2049 
2051  bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
2052 {
2053  const bool is_rna = (prop->magic == RNA_MAGIC);
2054  prop = rna_ensure_property(prop);
2055 
2056  if (is_rna) {
2057  if (prop->update) {
2058  /* ideally no context would be needed for update, but there's some
2059  * parts of the code that need it still, so we have this exception */
2060  if (prop->flag & PROP_CONTEXT_UPDATE) {
2061  if (C) {
2063  ((ContextPropUpdateFunc)prop->update)(C, ptr, prop);
2064  }
2065  else {
2066  ((ContextUpdateFunc)prop->update)(C, ptr);
2067  }
2068  }
2069  }
2070  else {
2071  prop->update(bmain, scene, ptr);
2072  }
2073  }
2074 
2075 #if 1
2076  /* TODO(campbell): Should eventually be replaced entirely by message bus (below)
2077  * for now keep since COW, bugs are hard to track when we have other missing updates. */
2078  if (prop->noteflag) {
2080  }
2081 #endif
2082 
2083  /* if C is NULL, we're updating from animation.
2084  * avoid slow-down from f-curves by not publishing (for now). */
2085  if (C != NULL) {
2086  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
2087  /* we could add NULL check, for now don't */
2088  WM_msg_publish_rna(mbus, ptr, prop);
2089  }
2090  if (ptr->owner_id != NULL && ((prop->flag & PROP_NO_DEG_UPDATE) == 0)) {
2091  const short id_type = GS(ptr->owner_id->name);
2092  if (ID_TYPE_IS_COW(id_type)) {
2094  }
2095  }
2096  /* End message bus. */
2097  }
2098 
2099  if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
2100 
2101  /* Disclaimer: this logic is not applied consistently, causing some confusing behavior.
2102  *
2103  * - When animated (which skips update functions).
2104  * - When ID-properties are edited via Python (since RNA properties aren't used in this case).
2105  *
2106  * Adding updates will add a lot of overhead in the case of animation.
2107  * For Python it may cause unexpected slow-downs for developers using ID-properties
2108  * for data storage. Further, the root ID isn't available with nested data-structures.
2109  *
2110  * So editing custom properties only causes updates in the UI,
2111  * keep this exception because it happens to be useful for driving settings.
2112  * Python developers on the other hand will need to manually 'update_tag', see: T74000. */
2115 
2116  /* When updating an ID pointer property, tag depsgraph for update. */
2118  DEG_relations_tag_update(bmain);
2119  }
2120 
2122  /* Not nice as well, but the only way to make sure material preview
2123  * is updated with custom nodes.
2124  */
2125  if ((prop->flag & PROP_IDPROPERTY) != 0 && (ptr->owner_id != NULL) &&
2126  (GS(ptr->owner_id->name) == ID_NT)) {
2128  }
2129  }
2130 }
2131 
2133 {
2134  /* NOTE: must keep in sync with #rna_property_update. */
2135  return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
2136 }
2137 
2139 {
2141 }
2142 
2144 {
2145  BLI_assert(bmain != NULL);
2146  rna_property_update(NULL, bmain, scene, ptr, prop);
2147 }
2148 
2149 /* ---------------------------------------------------------------------- */
2150 
2151 /* Property Data */
2152 
2154 {
2155  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2156  IDProperty *idprop;
2157  bool value;
2158 
2160  BLI_assert(RNA_property_array_check(prop) == false);
2161 
2162  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2163  value = IDP_Int(idprop) != 0;
2164  }
2165  else if (bprop->get) {
2166  value = bprop->get(ptr);
2167  }
2168  else if (bprop->get_ex) {
2169  value = bprop->get_ex(ptr, prop);
2170  }
2171  else {
2172  value = bprop->defaultvalue;
2173  }
2174 
2175  BLI_assert(ELEM(value, false, true));
2176 
2177  return value;
2178 }
2179 
2181 {
2182  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2183  IDProperty *idprop;
2184 
2186  BLI_assert(RNA_property_array_check(prop) == false);
2187  BLI_assert(ELEM(value, false, true));
2188 
2189  /* just in case other values are passed */
2190  BLI_assert(ELEM(value, true, false));
2191 
2192  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2193  IDP_Int(idprop) = (int)value;
2194  rna_idproperty_touch(idprop);
2195  }
2196  else if (bprop->set) {
2197  bprop->set(ptr, value);
2198  }
2199  else if (bprop->set_ex) {
2200  bprop->set_ex(ptr, prop, value);
2201  }
2202  else if (prop->flag & PROP_EDITABLE) {
2203  IDPropertyTemplate val = {0};
2204  IDProperty *group;
2205 
2206  val.i = value;
2207 
2208  group = RNA_struct_idprops(ptr, 1);
2209  if (group) {
2210  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
2211  }
2212  }
2213 }
2214 
2216  const bool *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
2217 {
2218  if (defarr && defarr_length > 0) {
2219  defarr_length = MIN2(defarr_length, out_length);
2220  memcpy(r_values, defarr, sizeof(bool) * defarr_length);
2221  }
2222  else {
2223  defarr_length = 0;
2224  }
2225 
2226  for (int i = defarr_length; i < out_length; i++) {
2227  r_values[i] = defvalue;
2228  }
2229 }
2230 
2232  BoolPropertyRNA *bprop,
2233  bool *r_values)
2234 {
2235  int length = bprop->property.totarraylength;
2236  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)bprop);
2237 
2239  bprop->defaultarray, length, bprop->defaultvalue, out_length, r_values);
2240 }
2241 
2243 {
2244  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2245  IDProperty *idprop;
2246 
2248  BLI_assert(RNA_property_array_check(prop) != false);
2249 
2250  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2251  if (prop->arraydimension == 0) {
2252  values[0] = RNA_property_boolean_get(ptr, prop);
2253  }
2254  else {
2255  int *values_src = IDP_Array(idprop);
2256  for (uint i = 0; i < idprop->len; i++) {
2257  values[i] = (bool)values_src[i];
2258  }
2259  }
2260  }
2261  else if (prop->arraydimension == 0) {
2262  values[0] = RNA_property_boolean_get(ptr, prop);
2263  }
2264  else if (bprop->getarray) {
2265  bprop->getarray(ptr, values);
2266  }
2267  else if (bprop->getarray_ex) {
2268  bprop->getarray_ex(ptr, prop, values);
2269  }
2270  else {
2272  }
2273 }
2274 
2276 {
2277  bool tmp[RNA_MAX_ARRAY_LENGTH];
2279  bool value;
2280 
2282  BLI_assert(RNA_property_array_check(prop) != false);
2283  BLI_assert(index >= 0);
2284  BLI_assert(index < len);
2285 
2286  if (len <= RNA_MAX_ARRAY_LENGTH) {
2287  RNA_property_boolean_get_array(ptr, prop, tmp);
2288  value = tmp[index];
2289  }
2290  else {
2291  bool *tmparray;
2292 
2293  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2294  RNA_property_boolean_get_array(ptr, prop, tmparray);
2295  value = tmparray[index];
2296  MEM_freeN(tmparray);
2297  }
2298 
2299  BLI_assert(ELEM(value, false, true));
2300 
2301  return value;
2302 }
2303 
2305 {
2306  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2307  IDProperty *idprop;
2308 
2310  BLI_assert(RNA_property_array_check(prop) != false);
2311 
2312  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2313  if (prop->arraydimension == 0) {
2314  IDP_Int(idprop) = values[0];
2315  }
2316  else {
2317  int *values_dst = IDP_Array(idprop);
2318  for (uint i = 0; i < idprop->len; i++) {
2319  values_dst[i] = (int)values[i];
2320  }
2321  }
2322  rna_idproperty_touch(idprop);
2323  }
2324  else if (prop->arraydimension == 0) {
2325  RNA_property_boolean_set(ptr, prop, values[0]);
2326  }
2327  else if (bprop->setarray) {
2328  bprop->setarray(ptr, values);
2329  }
2330  else if (bprop->setarray_ex) {
2331  bprop->setarray_ex(ptr, prop, values);
2332  }
2333  else if (prop->flag & PROP_EDITABLE) {
2334  IDPropertyTemplate val = {0};
2335  IDProperty *group;
2336 
2337  val.array.len = prop->totarraylength;
2338  val.array.type = IDP_INT;
2339 
2340  group = RNA_struct_idprops(ptr, 1);
2341  if (group) {
2342  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
2343  IDP_AddToGroup(group, idprop);
2344  int *values_dst = IDP_Array(idprop);
2345  for (uint i = 0; i < idprop->len; i++) {
2346  values_dst[i] = (int)values[i];
2347  }
2348  }
2349  }
2350 }
2351 
2352 void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
2353 {
2354  bool tmp[RNA_MAX_ARRAY_LENGTH];
2356 
2358  BLI_assert(RNA_property_array_check(prop) != false);
2359  BLI_assert(index >= 0);
2360  BLI_assert(index < len);
2361  BLI_assert(ELEM(value, false, true));
2362 
2363  if (len <= RNA_MAX_ARRAY_LENGTH) {
2364  RNA_property_boolean_get_array(ptr, prop, tmp);
2365  tmp[index] = value;
2366  RNA_property_boolean_set_array(ptr, prop, tmp);
2367  }
2368  else {
2369  bool *tmparray;
2370 
2371  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2372  RNA_property_boolean_get_array(ptr, prop, tmparray);
2373  tmparray[index] = value;
2374  RNA_property_boolean_set_array(ptr, prop, tmparray);
2375  MEM_freeN(tmparray);
2376  }
2377 }
2378 
2380 {
2382 
2384  BLI_assert(RNA_property_array_check(prop) == false);
2385  BLI_assert(ELEM(bprop->defaultvalue, false, true));
2386 
2387  return bprop->defaultvalue;
2388 }
2389 
2391 {
2393 
2395  BLI_assert(RNA_property_array_check(prop) != false);
2396 
2397  if (prop->arraydimension == 0) {
2398  values[0] = bprop->defaultvalue;
2399  }
2400  else {
2402  }
2403 }
2404 
2406 {
2407  bool tmp[RNA_MAX_ARRAY_LENGTH];
2409 
2411  BLI_assert(RNA_property_array_check(prop) != false);
2412  BLI_assert(index >= 0);
2413  BLI_assert(index < len);
2414 
2415  if (len <= RNA_MAX_ARRAY_LENGTH) {
2417  return tmp[index];
2418  }
2419  bool *tmparray, value;
2420 
2421  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2423  value = tmparray[index];
2424  MEM_freeN(tmparray);
2425 
2426  return value;
2427 }
2428 
2430 {
2431  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2432  IDProperty *idprop;
2433 
2435  BLI_assert(RNA_property_array_check(prop) == false);
2436 
2437  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2438  return IDP_Int(idprop);
2439  }
2440  if (iprop->get) {
2441  return iprop->get(ptr);
2442  }
2443  if (iprop->get_ex) {
2444  return iprop->get_ex(ptr, prop);
2445  }
2446  return iprop->defaultvalue;
2447 }
2448 
2450 {
2451  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2452  IDProperty *idprop;
2453 
2455  BLI_assert(RNA_property_array_check(prop) == false);
2456  /* useful to check on bad values but set function should clamp */
2457  // BLI_assert(RNA_property_int_clamp(ptr, prop, &value) == 0);
2458 
2459  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2460  RNA_property_int_clamp(ptr, prop, &value);
2461  IDP_Int(idprop) = value;
2462  rna_idproperty_touch(idprop);
2463  }
2464  else if (iprop->set) {
2465  iprop->set(ptr, value);
2466  }
2467  else if (iprop->set_ex) {
2468  iprop->set_ex(ptr, prop, value);
2469  }
2470  else if (prop->flag & PROP_EDITABLE) {
2471  IDPropertyTemplate val = {0};
2472  IDProperty *group;
2473 
2474  RNA_property_int_clamp(ptr, prop, &value);
2475 
2476  val.i = value;
2477 
2478  group = RNA_struct_idprops(ptr, 1);
2479  if (group) {
2480  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
2481  }
2482  }
2483 }
2484 
2486  const int *defarr, int defarr_length, int defvalue, int out_length, int *r_values)
2487 {
2488  if (defarr && defarr_length > 0) {
2489  defarr_length = MIN2(defarr_length, out_length);
2490  memcpy(r_values, defarr, sizeof(int) * defarr_length);
2491  }
2492  else {
2493  defarr_length = 0;
2494  }
2495 
2496  for (int i = defarr_length; i < out_length; i++) {
2497  r_values[i] = defvalue;
2498  }
2499 }
2500 
2502  IntPropertyRNA *iprop,
2503  int *r_values)
2504 {
2505  int length = iprop->property.totarraylength;
2506  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)iprop);
2507 
2509  iprop->defaultarray, length, iprop->defaultvalue, out_length, r_values);
2510 }
2511 
2513 {
2514  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2515  IDProperty *idprop;
2516 
2518  BLI_assert(RNA_property_array_check(prop) != false);
2519 
2520  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2521  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2522  (prop->flag & PROP_IDPROPERTY));
2523  if (prop->arraydimension == 0) {
2524  values[0] = RNA_property_int_get(ptr, prop);
2525  }
2526  else {
2527  memcpy(values, IDP_Array(idprop), sizeof(int) * idprop->len);
2528  }
2529  }
2530  else if (prop->arraydimension == 0) {
2531  values[0] = RNA_property_int_get(ptr, prop);
2532  }
2533  else if (iprop->getarray) {
2534  iprop->getarray(ptr, values);
2535  }
2536  else if (iprop->getarray_ex) {
2537  iprop->getarray_ex(ptr, prop, values);
2538  }
2539  else {
2541  }
2542 }
2543 
2545 {
2546  const int array_len = RNA_property_array_length(ptr, prop);
2547 
2548  if (array_len <= 0) {
2549  values[0] = 0;
2550  values[1] = 0;
2551  }
2552  else if (array_len == 1) {
2553  RNA_property_int_get_array(ptr, prop, values);
2554  values[1] = values[0];
2555  }
2556  else {
2557  int arr_stack[32];
2558  int *arr;
2559  int i;
2560 
2561  if (array_len > 32) {
2562  arr = MEM_mallocN(sizeof(int) * array_len, __func__);
2563  }
2564  else {
2565  arr = arr_stack;
2566  }
2567 
2568  RNA_property_int_get_array(ptr, prop, arr);
2569  values[0] = values[1] = arr[0];
2570  for (i = 1; i < array_len; i++) {
2571  values[0] = MIN2(values[0], arr[i]);
2572  values[1] = MAX2(values[1], arr[i]);
2573  }
2574 
2575  if (arr != arr_stack) {
2576  MEM_freeN(arr);
2577  }
2578  }
2579 }
2580 
2582 {
2583  int tmp[RNA_MAX_ARRAY_LENGTH];
2585 
2587  BLI_assert(RNA_property_array_check(prop) != false);
2588  BLI_assert(index >= 0);
2589  BLI_assert(index < len);
2590 
2591  if (len <= RNA_MAX_ARRAY_LENGTH) {
2592  RNA_property_int_get_array(ptr, prop, tmp);
2593  return tmp[index];
2594  }
2595  int *tmparray, value;
2596 
2597  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2598  RNA_property_int_get_array(ptr, prop, tmparray);
2599  value = tmparray[index];
2600  MEM_freeN(tmparray);
2601 
2602  return value;
2603 }
2604 
2605 void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
2606 {
2607  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2608  IDProperty *idprop;
2609 
2611  BLI_assert(RNA_property_array_check(prop) != false);
2612 
2613  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2614  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2615  (prop->flag & PROP_IDPROPERTY));
2616  if (prop->arraydimension == 0) {
2617  IDP_Int(idprop) = values[0];
2618  }
2619  else {
2620  memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
2621  }
2622 
2623  rna_idproperty_touch(idprop);
2624  }
2625  else if (prop->arraydimension == 0) {
2626  RNA_property_int_set(ptr, prop, values[0]);
2627  }
2628  else if (iprop->setarray) {
2629  iprop->setarray(ptr, values);
2630  }
2631  else if (iprop->setarray_ex) {
2632  iprop->setarray_ex(ptr, prop, values);
2633  }
2634  else if (prop->flag & PROP_EDITABLE) {
2635  IDPropertyTemplate val = {0};
2636  IDProperty *group;
2637 
2638  /* TODO: RNA_property_int_clamp_array(ptr, prop, &value); */
2639 
2640  val.array.len = prop->totarraylength;
2641  val.array.type = IDP_INT;
2642 
2643  group = RNA_struct_idprops(ptr, 1);
2644  if (group) {
2645  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
2646  IDP_AddToGroup(group, idprop);
2647  memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
2648  }
2649  }
2650 }
2651 
2652 void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
2653 {
2654  int tmp[RNA_MAX_ARRAY_LENGTH];
2656 
2658  BLI_assert(RNA_property_array_check(prop) != false);
2659  BLI_assert(index >= 0);
2660  BLI_assert(index < len);
2661 
2662  if (len <= RNA_MAX_ARRAY_LENGTH) {
2663  RNA_property_int_get_array(ptr, prop, tmp);
2664  tmp[index] = value;
2665  RNA_property_int_set_array(ptr, prop, tmp);
2666  }
2667  else {
2668  int *tmparray;
2669 
2670  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2671  RNA_property_int_get_array(ptr, prop, tmparray);
2672  tmparray[index] = value;
2673  RNA_property_int_set_array(ptr, prop, tmparray);
2674  MEM_freeN(tmparray);
2675  }
2676 }
2677 
2679 {
2681 
2682  if (prop->magic != RNA_MAGIC) {
2683  const IDProperty *idprop = (const IDProperty *)prop;
2684  if (idprop->ui_data) {
2685  const IDPropertyUIDataInt *ui_data = (const IDPropertyUIDataInt *)idprop->ui_data;
2686  return ui_data->default_value;
2687  }
2688  }
2689 
2690  return iprop->defaultvalue;
2691 }
2692 
2694 {
2695  if (prop->magic == RNA_MAGIC) {
2696  return false;
2697  }
2698 
2699  IDProperty *idprop = (IDProperty *)prop;
2700  BLI_assert(idprop->type == IDP_INT);
2701 
2703  ui_data->default_value = value;
2704  return true;
2705 }
2706 
2708 {
2710 
2712  BLI_assert(RNA_property_array_check(prop) != false);
2713 
2714  if (prop->magic != RNA_MAGIC) {
2716 
2717  const IDProperty *idprop = (const IDProperty *)prop;
2718  if (idprop->ui_data) {
2719  BLI_assert(idprop->type == IDP_ARRAY);
2720  BLI_assert(idprop->subtype == IDP_INT);
2721  const IDPropertyUIDataInt *ui_data = (const IDPropertyUIDataInt *)idprop->ui_data;
2722  if (ui_data->default_array) {
2724  ui_data->default_array_len,
2725  ui_data->default_value,
2726  length,
2727  values);
2728  }
2729  else {
2731  NULL, 0, ui_data->default_value, length, values);
2732  }
2733  }
2734  }
2735  else if (prop->arraydimension == 0) {
2736  values[0] = iprop->defaultvalue;
2737  }
2738  else {
2740  }
2741 }
2742 
2744 {
2745  int tmp[RNA_MAX_ARRAY_LENGTH];
2747 
2749  BLI_assert(RNA_property_array_check(prop) != false);
2750  BLI_assert(index >= 0);
2751  BLI_assert(index < len);
2752 
2753  if (len <= RNA_MAX_ARRAY_LENGTH) {
2755  return tmp[index];
2756  }
2757  int *tmparray, value;
2758 
2759  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2760  RNA_property_int_get_default_array(ptr, prop, tmparray);
2761  value = tmparray[index];
2762  MEM_freeN(tmparray);
2763 
2764  return value;
2765 }
2766 
2768 {
2769  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2770  IDProperty *idprop;
2771 
2773  BLI_assert(RNA_property_array_check(prop) == false);
2774 
2775  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2776  if (idprop->type == IDP_FLOAT) {
2777  return IDP_Float(idprop);
2778  }
2779  return (float)IDP_Double(idprop);
2780  }
2781  if (fprop->get) {
2782  return fprop->get(ptr);
2783  }
2784  if (fprop->get_ex) {
2785  return fprop->get_ex(ptr, prop);
2786  }
2787  return fprop->defaultvalue;
2788 }
2789 
2791 {
2792  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2793  IDProperty *idprop;
2794 
2796  BLI_assert(RNA_property_array_check(prop) == false);
2797  /* useful to check on bad values but set function should clamp */
2798  // BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0);
2799 
2800  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2801  RNA_property_float_clamp(ptr, prop, &value);
2802  if (idprop->type == IDP_FLOAT) {
2803  IDP_Float(idprop) = value;
2804  }
2805  else {
2806  IDP_Double(idprop) = value;
2807  }
2808 
2809  rna_idproperty_touch(idprop);
2810  }
2811  else if (fprop->set) {
2812  fprop->set(ptr, value);
2813  }
2814  else if (fprop->set_ex) {
2815  fprop->set_ex(ptr, prop, value);
2816  }
2817  else if (prop->flag & PROP_EDITABLE) {
2818  IDPropertyTemplate val = {0};
2819  IDProperty *group;
2820 
2821  RNA_property_float_clamp(ptr, prop, &value);
2822 
2823  val.f = value;
2824 
2825  group = RNA_struct_idprops(ptr, 1);
2826  if (group) {
2827  IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier));
2828  }
2829  }
2830 }
2831 
2833  const float *defarr, int defarr_length, float defvalue, int out_length, float *r_values)
2834 {
2835  if (defarr && defarr_length > 0) {
2836  defarr_length = MIN2(defarr_length, out_length);
2837  memcpy(r_values, defarr, sizeof(float) * defarr_length);
2838  }
2839  else {
2840  defarr_length = 0;
2841  }
2842 
2843  for (int i = defarr_length; i < out_length; i++) {
2844  r_values[i] = defvalue;
2845  }
2846 }
2847 
2851 static void rna_property_float_fill_default_array_values_double(const double *default_array,
2852  const int default_array_len,
2853  const double default_value,
2854  const int out_length,
2855  float *r_values)
2856 {
2857  const int array_copy_len = MIN2(out_length, default_array_len);
2858 
2859  for (int i = 0; i < array_copy_len; i++) {
2860  r_values[i] = (float)default_array[i];
2861  }
2862 
2863  for (int i = array_copy_len; i < out_length; i++) {
2864  r_values[i] = (float)default_value;
2865  }
2866 }
2867 
2869  FloatPropertyRNA *fprop,
2870  float *r_values)
2871 {
2872  int length = fprop->property.totarraylength;
2873  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)fprop);
2874 
2876  fprop->defaultarray, length, fprop->defaultvalue, out_length, r_values);
2877 }
2878 
2880 {
2881  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2882  IDProperty *idprop;
2883  int i;
2884 
2886  BLI_assert(RNA_property_array_check(prop) != false);
2887 
2888  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2889  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2890  (prop->flag & PROP_IDPROPERTY));
2891  if (prop->arraydimension == 0) {
2892  values[0] = RNA_property_float_get(ptr, prop);
2893  }
2894  else if (idprop->subtype == IDP_FLOAT) {
2895  memcpy(values, IDP_Array(idprop), sizeof(float) * idprop->len);
2896  }
2897  else {
2898  for (i = 0; i < idprop->len; i++) {
2899  values[i] = (float)(((double *)IDP_Array(idprop))[i]);
2900  }
2901  }
2902  }
2903  else if (prop->arraydimension == 0) {
2904  values[0] = RNA_property_float_get(ptr, prop);
2905  }
2906  else if (fprop->getarray) {
2907  fprop->getarray(ptr, values);
2908  }
2909  else if (fprop->getarray_ex) {
2910  fprop->getarray_ex(ptr, prop, values);
2911  }
2912  else {
2914  }
2915 }
2916 
2918 {
2919  const int array_len = RNA_property_array_length(ptr, prop);
2920 
2921  if (array_len <= 0) {
2922  values[0] = 0.0f;
2923  values[1] = 0.0f;
2924  }
2925  else if (array_len == 1) {
2926  RNA_property_float_get_array(ptr, prop, values);
2927  values[1] = values[0];
2928  }
2929  else {
2930  float arr_stack[32];
2931  float *arr;
2932  int i;
2933 
2934  if (array_len > 32) {
2935  arr = MEM_mallocN(sizeof(float) * array_len, __func__);
2936  }
2937  else {
2938  arr = arr_stack;
2939  }
2940 
2941  RNA_property_float_get_array(ptr, prop, arr);
2942  values[0] = values[1] = arr[0];
2943  for (i = 1; i < array_len; i++) {
2944  values[0] = MIN2(values[0], arr[i]);
2945  values[1] = MAX2(values[1], arr[i]);
2946  }
2947 
2948  if (arr != arr_stack) {
2949  MEM_freeN(arr);
2950  }
2951  }
2952 }
2953 
2955 {
2956  float tmp[RNA_MAX_ARRAY_LENGTH];
2958 
2960  BLI_assert(RNA_property_array_check(prop) != false);
2961  BLI_assert(index >= 0);
2962  BLI_assert(index < len);
2963 
2964  if (len <= RNA_MAX_ARRAY_LENGTH) {
2965  RNA_property_float_get_array(ptr, prop, tmp);
2966  return tmp[index];
2967  }
2968  float *tmparray, value;
2969 
2970  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
2971  RNA_property_float_get_array(ptr, prop, tmparray);
2972  value = tmparray[index];
2973  MEM_freeN(tmparray);
2974 
2975  return value;
2976 }
2977 
2978 void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
2979 {
2980  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2981  IDProperty *idprop;
2982  int i;
2983 
2985  BLI_assert(RNA_property_array_check(prop) != false);
2986 
2987  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2988  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2989  (prop->flag & PROP_IDPROPERTY));
2990  if (prop->arraydimension == 0) {
2991  if (idprop->type == IDP_FLOAT) {
2992  IDP_Float(idprop) = values[0];
2993  }
2994  else {
2995  IDP_Double(idprop) = values[0];
2996  }
2997  }
2998  else if (idprop->subtype == IDP_FLOAT) {
2999  memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
3000  }
3001  else {
3002  for (i = 0; i < idprop->len; i++) {
3003  ((double *)IDP_Array(idprop))[i] = values[i];
3004  }
3005  }
3006 
3007  rna_idproperty_touch(idprop);
3008  }
3009  else if (prop->arraydimension == 0) {
3010  RNA_property_float_set(ptr, prop, values[0]);
3011  }
3012  else if (fprop->setarray) {
3013  fprop->setarray(ptr, values);
3014  }
3015  else if (fprop->setarray_ex) {
3016  fprop->setarray_ex(ptr, prop, values);
3017  }
3018  else if (prop->flag & PROP_EDITABLE) {
3019  IDPropertyTemplate val = {0};
3020  IDProperty *group;
3021 
3022  /* TODO: RNA_property_float_clamp_array(ptr, prop, &value); */
3023 
3024  val.array.len = prop->totarraylength;
3025  val.array.type = IDP_FLOAT;
3026 
3027  group = RNA_struct_idprops(ptr, 1);
3028  if (group) {
3029  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
3030  IDP_AddToGroup(group, idprop);
3031  memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
3032  }
3033  }
3034 }
3035 
3036 void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
3037 {
3038  float tmp[RNA_MAX_ARRAY_LENGTH];
3040 
3042  BLI_assert(RNA_property_array_check(prop) != false);
3043  BLI_assert(index >= 0);
3044  BLI_assert(index < len);
3045 
3046  if (len <= RNA_MAX_ARRAY_LENGTH) {
3047  RNA_property_float_get_array(ptr, prop, tmp);
3048  tmp[index] = value;
3049  RNA_property_float_set_array(ptr, prop, tmp);
3050  }
3051  else {
3052  float *tmparray;
3053 
3054  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
3055  RNA_property_float_get_array(ptr, prop, tmparray);
3056  tmparray[index] = value;
3057  RNA_property_float_set_array(ptr, prop, tmparray);
3058  MEM_freeN(tmparray);
3059  }
3060 }
3061 
3063 {
3065 
3067  BLI_assert(RNA_property_array_check(prop) == false);
3068 
3069  if (prop->magic != RNA_MAGIC) {
3070  const IDProperty *idprop = (const IDProperty *)prop;
3071  if (idprop->ui_data) {
3072  BLI_assert(ELEM(idprop->type, IDP_FLOAT, IDP_DOUBLE));
3073  const IDPropertyUIDataFloat *ui_data = (const IDPropertyUIDataFloat *)idprop->ui_data;
3074  return (float)ui_data->default_value;
3075  }
3076  }
3077 
3078  return fprop->defaultvalue;
3079 }
3080 
3082 {
3083  if (prop->magic == RNA_MAGIC) {
3084  return false;
3085  }
3086 
3087  IDProperty *idprop = (IDProperty *)prop;
3088  BLI_assert(idprop->type == IDP_FLOAT);
3089 
3091  ui_data->default_value = (double)value;
3092  return true;
3093 }
3094 
3096 {
3098 
3100  BLI_assert(RNA_property_array_check(prop) != false);
3101 
3102  if (prop->magic != RNA_MAGIC) {
3104 
3105  const IDProperty *idprop = (const IDProperty *)prop;
3106  if (idprop->ui_data) {
3107  BLI_assert(idprop->type == IDP_ARRAY);
3109  const IDPropertyUIDataFloat *ui_data = (const IDPropertyUIDataFloat *)idprop->ui_data;
3111  ui_data->default_array_len,
3112  ui_data->default_value,
3113  length,
3114  values);
3115  }
3116  }
3117  else if (prop->arraydimension == 0) {
3118  values[0] = fprop->defaultvalue;
3119  }
3120  else {
3122  }
3123 }
3124 
3126 {
3127  float tmp[RNA_MAX_ARRAY_LENGTH];
3129 
3131  BLI_assert(RNA_property_array_check(prop) != false);
3132  BLI_assert(index >= 0);
3133  BLI_assert(index < len);
3134 
3135  if (len <= RNA_MAX_ARRAY_LENGTH) {
3137  return tmp[index];
3138  }
3139  float *tmparray, value;
3140 
3141  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
3142  RNA_property_float_get_default_array(ptr, prop, tmparray);
3143  value = tmparray[index];
3144  MEM_freeN(tmparray);
3145 
3146  return value;
3147 }
3148 
3150 {
3151  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3152  IDProperty *idprop;
3153 
3155 
3156  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3157  /* editing bytes is not 100% supported
3158  * since they can contain NIL chars */
3159  if (idprop->subtype == IDP_STRING_SUB_BYTE) {
3160  memcpy(value, IDP_String(idprop), idprop->len);
3161  value[idprop->len] = '\0';
3162  }
3163  else {
3164  memcpy(value, IDP_String(idprop), idprop->len);
3165  }
3166  }
3167  else if (sprop->get) {
3168  sprop->get(ptr, value);
3169  }
3170  else if (sprop->get_ex) {
3171  sprop->get_ex(ptr, prop, value);
3172  }
3173  else {
3174  strcpy(value, sprop->defaultvalue);
3175  }
3176 }
3177 
3179  PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
3180 {
3181  char *buf;
3182  int length;
3183 
3185 
3187 
3188  if (length + 1 < fixedlen) {
3189  buf = fixedbuf;
3190  }
3191  else {
3192  buf = MEM_mallocN(sizeof(char) * (length + 1), __func__);
3193  }
3194 
3195 #ifndef NDEBUG
3196  /* safety check to ensure the string is actually set */
3197  buf[length] = 255;
3198 #endif
3199 
3200  RNA_property_string_get(ptr, prop, buf);
3201 
3202 #ifndef NDEBUG
3203  BLI_assert(buf[length] == '\0');
3204 #endif
3205 
3206  if (r_len) {
3207  *r_len = length;
3208  }
3209 
3210  return buf;
3211 }
3212 
3214 {
3215  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3216  IDProperty *idprop;
3217 
3219 
3220  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3221  if (idprop->subtype == IDP_STRING_SUB_BYTE) {
3222  return idprop->len;
3223  }
3224 #ifndef NDEBUG
3225  /* these _must_ stay in sync */
3226  BLI_assert(strlen(IDP_String(idprop)) == idprop->len - 1);
3227 #endif
3228  return idprop->len - 1;
3229  }
3230  if (sprop->length) {
3231  return sprop->length(ptr);
3232  }
3233  if (sprop->length_ex) {
3234  return sprop->length_ex(ptr, prop);
3235  }
3236  return strlen(sprop->defaultvalue);
3237 }
3238 
3239 void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
3240 {
3241  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3242  IDProperty *idprop;
3243 
3245 
3246  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3247  /* both IDP_STRING_SUB_BYTE / IDP_STRING_SUB_UTF8 */
3248  IDP_AssignString(idprop, value, RNA_property_string_maxlength(prop) - 1);
3249  rna_idproperty_touch(idprop);
3250  }
3251  else if (sprop->set) {
3252  sprop->set(ptr, value); /* set function needs to clamp itself */
3253  }
3254  else if (sprop->set_ex) {
3255  sprop->set_ex(ptr, prop, value); /* set function needs to clamp itself */
3256  }
3257  else if (prop->flag & PROP_EDITABLE) {
3258  IDProperty *group;
3259 
3260  group = RNA_struct_idprops(ptr, 1);
3261  if (group) {
3262  IDP_AddToGroup(group,
3264  }
3265  }
3266 }
3267 
3268 void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
3269 {
3270  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3271  IDProperty *idprop;
3272 
3275 
3276  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3277  IDP_ResizeArray(idprop, len);
3278  memcpy(idprop->data.pointer, value, (size_t)len);
3279 
3280  rna_idproperty_touch(idprop);
3281  }
3282  else if (sprop->set) {
3283  /* XXX, should take length argument (currently not used). */
3284  sprop->set(ptr, value); /* set function needs to clamp itself */
3285  }
3286  else if (sprop->set_ex) {
3287  /* XXX, should take length argument (currently not used). */
3288  sprop->set_ex(ptr, prop, value); /* set function needs to clamp itself */
3289  }
3290  else if (prop->flag & PROP_EDITABLE) {
3291  IDProperty *group;
3292 
3293  group = RNA_struct_idprops(ptr, 1);
3294  if (group) {
3295  IDPropertyTemplate val = {0};
3296  val.string.str = value;
3297  val.string.len = len;
3299  IDP_AddToGroup(group, IDP_New(IDP_STRING, &val, prop->identifier));
3300  }
3301  }
3302 }
3303 
3304 void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int max_len)
3305 {
3307 
3308  if (prop->magic != RNA_MAGIC) {
3309  const IDProperty *idprop = (const IDProperty *)prop;
3310  if (idprop->ui_data) {
3311  BLI_assert(idprop->type == IDP_STRING);
3312  const IDPropertyUIDataString *ui_data = (const IDPropertyUIDataString *)idprop->ui_data;
3313  BLI_strncpy(value, ui_data->default_value, max_len);
3314  return;
3315  }
3316 
3317  strcpy(value, "");
3318  return;
3319  }
3320 
3322 
3323  strcpy(value, sprop->defaultvalue);
3324 }
3325 
3327  PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
3328 {
3329  char *buf;
3330  int length;
3331 
3333 
3335 
3336  if (length + 1 < fixedlen) {
3337  buf = fixedbuf;
3338  }
3339  else {
3340  buf = MEM_callocN(sizeof(char) * (length + 1), __func__);
3341  }
3342 
3343  RNA_property_string_get_default(prop, buf, length + 1);
3344 
3345  if (r_len) {
3346  *r_len = length;
3347  }
3348 
3349  return buf;
3350 }
3351 
3353 {
3355 
3356  if (prop->magic != RNA_MAGIC) {
3357  const IDProperty *idprop = (const IDProperty *)prop;
3358  if (idprop->ui_data) {
3359  BLI_assert(idprop->type == IDP_STRING);
3360  const IDPropertyUIDataString *ui_data = (const IDPropertyUIDataString *)idprop->ui_data;
3361  if (ui_data->default_value != NULL) {
3362  return strlen(ui_data->default_value);
3363  }
3364  }
3365 
3366  return 0;
3367  }
3368 
3370 
3371  return strlen(sprop->defaultvalue);
3372 }
3373 
3375 {
3377  if (prop->magic != RNA_MAGIC) {
3378  return false;
3379  }
3381  if (sprop->search) {
3383  }
3384  else {
3385  BLI_assert(sprop->search_flag == 0);
3386  }
3387  return sprop->search_flag;
3388 }
3389 
3391  PointerRNA *ptr,
3392  PropertyRNA *prop,
3393  const char *edit_text,
3395  void *visit_user_data)
3396 {
3399  sprop->search(C, ptr, prop, edit_text, visit_fn, visit_user_data);
3400 }
3401 
3403 {
3404  EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3405  IDProperty *idprop;
3406 
3408 
3409  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3410  return IDP_Int(idprop);
3411  }
3412  if (eprop->get) {
3413  return eprop->get(ptr);
3414  }
3415  if (eprop->get_ex) {
3416  return eprop->get_ex(ptr, prop);
3417  }
3418  return eprop->defaultvalue;
3419 }
3420 
3422 {
3423  EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3424  IDProperty *idprop;
3425 
3427 
3428  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3429  IDP_Int(idprop) = value;
3430  rna_idproperty_touch(idprop);
3431  }
3432  else if (eprop->set) {
3433  eprop->set(ptr, value);
3434  }
3435  else if (eprop->set_ex) {
3436  eprop->set_ex(ptr, prop, value);
3437  }
3438  else if (prop->flag & PROP_EDITABLE) {
3439  IDPropertyTemplate val = {0};
3440  IDProperty *group;
3441 
3442  val.i = value;
3443 
3444  group = RNA_struct_idprops(ptr, 1);
3445  if (group) {
3446  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
3447  }
3448  }
3449 }
3450 
3452 {
3454 
3456 
3457  return eprop->defaultvalue;
3458 }
3459 
3461  const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
3462 {
3463  const EnumPropertyItem *item_array;
3464  int totitem;
3465  bool free;
3466  int result_value = from_value;
3467  int i, i_init;
3468  int single_step = (step < 0) ? -1 : 1;
3469  int step_tot = 0;
3470 
3471  RNA_property_enum_items((bContext *)C, ptr, prop, &item_array, &totitem, &free);
3472  i = RNA_enum_from_value(item_array, from_value);
3473  i_init = i;
3474 
3475  do {
3476  i = mod_i(i + single_step, totitem);
3477  if (item_array[i].identifier[0]) {
3478  step_tot += single_step;
3479  }
3480  } while ((i != i_init) && (step_tot != step));
3481 
3482  if (i != i_init) {
3483  result_value = item_array[i].value;
3484  }
3485 
3486  if (free) {
3487  MEM_freeN((void *)item_array);
3488  }
3489 
3490  return result_value;
3491 }
3492 
3494 {
3495  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3496  IDProperty *idprop;
3497 
3499 
3501 
3502  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3503  pprop = (PointerPropertyRNA *)prop;
3504 
3505  if (RNA_struct_is_ID(pprop->type)) {
3506  return rna_pointer_inherit_refine(ptr, pprop->type, IDP_Id(idprop));
3507  }
3508 
3509  /* for groups, data is idprop itself */
3510  if (pprop->type_fn) {
3511  return rna_pointer_inherit_refine(ptr, pprop->type_fn(ptr), idprop);
3512  }
3513  return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
3514  }
3515  if (pprop->get) {
3516  return pprop->get(ptr);
3517  }
3518  if (prop->flag & PROP_IDPROPERTY) {
3519  /* NOTE: While creating/writing data in an accessor is really bad design-wise, this is
3520  * currently very difficult to avoid in that case. So a global mutex is used to keep ensuring
3521  * thread safety. */
3522  BLI_mutex_lock(&lock);
3523  /* NOTE: We do not need to check again for existence of the pointer after locking here, since
3524  * this is also done in #RNA_property_pointer_add itself. */
3527  return RNA_property_pointer_get(ptr, prop);
3528  }
3529  return PointerRNA_NULL;
3530 }
3531 
3533  PropertyRNA *prop,
3534  PointerRNA ptr_value,
3535  ReportList *reports)
3536 {
3537  /* Detect IDProperty and retrieve the actual PropertyRNA pointer before cast. */
3538  IDProperty *idprop = rna_idproperty_check(&prop, ptr);
3539 
3540  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3542 
3543  /* Check types. */
3544  if (pprop->set != NULL) {
3545  /* Assigning to a real RNA property. */
3546  if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, pprop->type)) {
3547  BKE_reportf(reports,
3548  RPT_ERROR,
3549  "%s: expected %s type, not %s",
3550  __func__,
3551  pprop->type->identifier,
3552  ptr_value.type->identifier);
3553  return;
3554  }
3555  }
3556  else {
3557  /* Assigning to an IDProperty disguised as RNA one. */
3558  if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, &RNA_ID)) {
3559  BKE_reportf(reports,
3560  RPT_ERROR,
3561  "%s: expected ID type, not %s",
3562  __func__,
3563  ptr_value.type->identifier);
3564  return;
3565  }
3566  }
3567 
3568  /* We got an existing IDProperty. */
3569  if (idprop != NULL) {
3570  /* Not-yet-defined ID IDProps have an IDP_GROUP type, not an IDP_ID one - because of reasons?
3571  * XXX This has to be investigated fully - there might be a good reason for it, but off hands
3572  * this seems really weird... */
3573  if (idprop->type == IDP_ID) {
3574  IDP_AssignID(idprop, ptr_value.data, 0);
3575  rna_idproperty_touch(idprop);
3576  }
3577  else {
3578  BLI_assert(idprop->type == IDP_GROUP);
3579 
3580  IDPropertyTemplate val = {.id = ptr_value.data};
3581  IDProperty *group = RNA_struct_idprops(ptr, true);
3582  BLI_assert(group != NULL);
3583 
3584  IDP_ReplaceInGroup_ex(group, IDP_New(IDP_ID, &val, idprop->name), idprop);
3585  }
3586  }
3587  /* RNA property. */
3588  else if (pprop->set) {
3589  if (!((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
3590  !((prop->flag & PROP_ID_SELF_CHECK) && ptr->owner_id == ptr_value.owner_id)) {
3591  pprop->set(ptr, ptr_value, reports);
3592  }
3593  }
3594  /* IDProperty disguised as RNA property (and not yet defined in ptr). */
3595  else if (prop->flag & PROP_EDITABLE) {
3596  IDPropertyTemplate val = {0};
3597  IDProperty *group;
3598 
3599  val.id = ptr_value.data;
3600 
3601  group = RNA_struct_idprops(ptr, true);
3602  if (group) {
3603  IDP_ReplaceInGroup(group, IDP_New(IDP_ID, &val, prop->identifier));
3604  }
3605  }
3606 }
3607 
3609 {
3610  // PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3611 
3612  // BLI_assert(RNA_property_type(prop) == PROP_POINTER);
3613 
3614  return PointerRNA_NULL; /* FIXME: there has to be a way... */
3615 }
3616 
3618 {
3619  // IDProperty *idprop;
3620 
3622 
3623  if ((/*idprop=*/rna_idproperty_check(&prop, ptr))) {
3624  /* already exists */
3625  }
3626  else if (prop->flag & PROP_IDPROPERTY) {
3627  IDPropertyTemplate val = {0};
3628  IDProperty *group;
3629 
3630  val.i = 0;
3631 
3632  group = RNA_struct_idprops(ptr, 1);
3633  if (group) {
3634  IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier));
3635  }
3636  }
3637  else {
3638  printf("%s %s.%s: only supported for id properties.\n",
3639  __func__,
3640  ptr->type->identifier,
3641  prop->identifier);
3642  }
3643 }
3644 
3646 {
3647  IDProperty *idprop, *group;
3648 
3650 
3651  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3652  group = RNA_struct_idprops(ptr, 0);
3653 
3654  if (group) {
3655  IDP_FreeFromGroup(group, idprop);
3656  }
3657  }
3658  else {
3659  printf("%s %s.%s: only supported for id properties.\n",
3660  __func__,
3661  ptr->type->identifier,
3662  prop->identifier);
3663  }
3664 }
3665 
3667 {
3669 
3670  iter->ptr.data = rna_iterator_array_get(iter);
3671  iter->ptr.type = cprop->item_type;
3672  rna_pointer_inherit_id(cprop->item_type, &iter->parent, &iter->ptr);
3673 }
3674 
3676  PropertyRNA *prop,
3678 {
3679  IDProperty *idprop;
3680 
3682 
3683  memset(iter, 0, sizeof(*iter));
3684 
3685  if ((idprop = rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
3686  iter->parent = *ptr;
3687  iter->prop = prop;
3688 
3689  if (idprop) {
3691  iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL);
3692  }
3693  else {
3694  rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL);
3695  }
3696 
3697  if (iter->valid) {
3699  }
3700 
3701  iter->idprop = 1;
3702  }
3703  else {
3705  cprop->begin(iter, ptr);
3706  }
3707 }
3708 
3710 {
3712 
3713  if (iter->idprop) {
3715 
3716  if (iter->valid) {
3718  }
3719  }
3720  else {
3721  cprop->next(iter);
3722  }
3723 }
3724 
3726 {
3728  int i;
3729 
3730  if (num > 1 && (iter->idprop || (cprop->property.flag_internal & PROP_INTERN_RAW_ARRAY))) {
3731  /* fast skip for array */
3732  ArrayIterator *internal = &iter->internal.array;
3733 
3734  if (!internal->skip) {
3735  internal->ptr += internal->itemsize * (num - 1);
3736  iter->valid = (internal->ptr < internal->endptr);
3737  if (iter->valid) {
3739  }
3740  return;
3741  }
3742  }
3743 
3744  /* slow iteration otherwise */
3745  for (i = 0; i < num && iter->valid; i++) {
3747  }
3748 }
3749 
3751 {
3753 
3754  if (iter->idprop) {
3755  rna_iterator_array_end(iter);
3756  }
3757  else {
3758  cprop->end(iter);
3759  }
3760 }
3761 
3763 {
3765  IDProperty *idprop;
3766 
3768 
3769  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3770  return idprop->len;
3771  }
3772  if (cprop->length) {
3773  return cprop->length(ptr);
3774  }
3776  int length = 0;
3777 
3778  RNA_property_collection_begin(ptr, prop, &iter);
3779  for (; iter.valid; RNA_property_collection_next(&iter)) {
3780  length++;
3781  }
3783 
3784  return length;
3785 }
3786 
3788 {
3791  RNA_property_collection_begin(ptr, prop, &iter);
3792  bool test = iter.valid;
3794  return !test;
3795 }
3796 
3797 /* This helper checks whether given collection property itself is editable (we only currently
3798  * support a limited set of operations, insertion of new items, and re-ordering of those new items
3799  * exclusively). */
3801  PropertyRNA *prop,
3802  bool *r_is_liboverride)
3803 {
3804  ID *id = ptr->owner_id;
3805  if (id == NULL) {
3806  *r_is_liboverride = false;
3807  return true;
3808  }
3809 
3810  const bool is_liboverride = *r_is_liboverride = ID_IS_OVERRIDE_LIBRARY(id);
3811 
3812  if (!is_liboverride) {
3813  /* We return True also for linked data, as it allows tricks like py scripts 'overriding' data
3814  * of those. */
3815  return true;
3816  }
3817 
3818  if (!RNA_property_overridable_get(ptr, prop)) {
3819  return false;
3820  }
3821 
3822  if (prop->magic != RNA_MAGIC || (prop->flag & PROP_IDPROPERTY) == 0) {
3823  /* Insertion and such not supported for pure IDProperties for now, nor for pure RNA/DNA ones.
3824  */
3825  return false;
3826  }
3827  if ((prop->flag_override & PROPOVERRIDE_LIBRARY_INSERTION) == 0) {
3828  return false;
3829  }
3830 
3831  /* No more checks to do, this collections is overridable. */
3832  return true;
3833 }
3834 
3836 {
3837  IDProperty *idprop;
3838  /* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
3839 
3841 
3842  bool is_liboverride;
3843  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
3844  if (r_ptr) {
3845  memset(r_ptr, 0, sizeof(*r_ptr));
3846  }
3847  return;
3848  }
3849 
3850  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3851  IDPropertyTemplate val = {0};
3852  IDProperty *item;
3853 
3854  item = IDP_New(IDP_GROUP, &val, "");
3855  if (is_liboverride) {
3857  }
3858  IDP_AppendArray(idprop, item);
3859  /* IDP_AppendArray does a shallow copy (memcpy), only free memory. */
3860  // IDP_FreePropertyContent(item);
3861  MEM_freeN(item);
3862  rna_idproperty_touch(idprop);
3863  }
3864  else if (prop->flag & PROP_IDPROPERTY) {
3865  IDProperty *group, *item;
3866  IDPropertyTemplate val = {0};
3867 
3868  group = RNA_struct_idprops(ptr, 1);
3869  if (group) {
3870  idprop = IDP_NewIDPArray(prop->identifier);
3871  IDP_AddToGroup(group, idprop);
3872 
3873  item = IDP_New(IDP_GROUP, &val, "");
3874  if (is_liboverride) {
3876  }
3877  IDP_AppendArray(idprop, item);
3878  /* IDP_AppendArray does a shallow copy (memcpy), only free memory */
3879  /* IDP_FreePropertyContent(item); */
3880  MEM_freeN(item);
3881  }
3882  }
3883 
3884  /* py api calls directly */
3885 #if 0
3886  else if (cprop->add) {
3887  if (!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
3889  RNA_parameter_list_create(&params, ptr, cprop->add);
3890  RNA_function_call(NULL, NULL, ptr, cprop->add, &params);
3892  }
3893  }
3894 # if 0
3895  else {
3896  printf("%s %s.%s: not implemented for this property.\n",
3897  __func__,
3898  ptr->type->identifier,
3899  prop->identifier);
3900  }
3901 # endif
3902 #endif
3903 
3904  if (r_ptr) {
3905  if (idprop) {
3907 
3908  r_ptr->data = IDP_GetIndexArray(idprop, idprop->len - 1);
3909  r_ptr->type = cprop->item_type;
3910  rna_pointer_inherit_id(NULL, ptr, r_ptr);
3911  }
3912  else {
3913  memset(r_ptr, 0, sizeof(*r_ptr));
3914  }
3915  }
3916 }
3917 
3919 {
3920  IDProperty *idprop;
3921  /* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
3922 
3924 
3925  bool is_liboverride;
3926  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
3927  return false;
3928  }
3929 
3930  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3931  IDProperty tmp, *array;
3932  int len;
3933 
3934  len = idprop->len;
3935  array = IDP_IDPArray(idprop);
3936 
3937  if (key >= 0 && key < len) {
3938  if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
3939  /* We can only remove items that we actually inserted in the local override. */
3940  return false;
3941  }
3942 
3943  if (key + 1 < len) {
3944  /* move element to be removed to the back */
3945  memcpy(&tmp, &array[key], sizeof(IDProperty));
3946  memmove(array + key, array + key + 1, sizeof(IDProperty) * (len - (key + 1)));
3947  memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
3948  }
3949 
3950  IDP_ResizeIDPArray(idprop, len - 1);
3951  }
3952 
3953  return true;
3954  }
3955  if (prop->flag & PROP_IDPROPERTY) {
3956  return true;
3957  }
3958 
3959  /* py api calls directly */
3960 #if 0
3961  else if (cprop->remove) {
3962  if (!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
3964  RNA_parameter_list_create(&params, ptr, cprop->remove);
3965  RNA_function_call(NULL, NULL, ptr, cprop->remove, &params);
3967  }
3968 
3969  return false;
3970  }
3971 # if 0
3972  else {
3973  printf("%s %s.%s: only supported for id properties.\n",
3974  __func__,
3975  ptr->type->identifier,
3976  prop->identifier);
3977  }
3978 # endif
3979 #endif
3980  return false;
3981 }
3982 
3984 {
3985  IDProperty *idprop;
3986 
3988 
3989  bool is_liboverride;
3990  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
3991  return false;
3992  }
3993 
3994  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3995  IDProperty tmp, *array;
3996  int len;
3997 
3998  len = idprop->len;
3999  array = IDP_IDPArray(idprop);
4000 
4001  if (key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
4002  if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
4003  /* We can only move items that we actually inserted in the local override. */
4004  return false;
4005  }
4006 
4007  memcpy(&tmp, &array[key], sizeof(IDProperty));
4008  if (pos < key) {
4009  memmove(array + pos + 1, array + pos, sizeof(IDProperty) * (key - pos));
4010  }
4011  else {
4012  memmove(array + key, array + key + 1, sizeof(IDProperty) * (pos - key));
4013  }
4014  memcpy(&array[pos], &tmp, sizeof(IDProperty));
4015  }
4016 
4017  return true;
4018  }
4019  if (prop->flag & PROP_IDPROPERTY) {
4020  return true;
4021  }
4022 
4023  return false;
4024 }
4025 
4027 {
4028  IDProperty *idprop;
4029 
4031 
4032  bool is_liboverride;
4033  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
4034  return;
4035  }
4036 
4037  if ((idprop = rna_idproperty_check(&prop, ptr))) {
4038  if (is_liboverride) {
4039  /* We can only move items that we actually inserted in the local override. */
4040  int len = idprop->len;
4041  IDProperty tmp, *array = IDP_IDPArray(idprop);
4042  for (int i = 0; i < len; i++) {
4043  if ((array[i].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) != 0) {
4044  memcpy(&tmp, &array[i], sizeof(IDProperty));
4045  memmove(array + i, array + i + 1, sizeof(IDProperty) * (len - (i + 1)));
4046  memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
4047  IDP_ResizeIDPArray(idprop, --len);
4048  i--;
4049  }
4050  }
4051  }
4052  else {
4053  IDP_ResizeIDPArray(idprop, 0);
4054  }
4055  rna_idproperty_touch(idprop);
4056  }
4057 }
4058 
4060  PropertyRNA *prop,
4061  const PointerRNA *t_ptr)
4062 {
4064  int index = 0;
4065 
4067 
4068  RNA_property_collection_begin(ptr, prop, &iter);
4069  for (index = 0; iter.valid; RNA_property_collection_next(&iter), index++) {
4070  if (iter.ptr.data == t_ptr->data) {
4071  break;
4072  }
4073  }
4075 
4076  /* did we find it? */
4077  if (iter.valid) {
4078  return index;
4079  }
4080  return -1;
4081 }
4082 
4084 {
4087  return cprop->lookupint != NULL;
4088 }
4089 
4091 {
4094  return cprop->lookupstring != NULL;
4095 }
4096 
4098  PropertyRNA *prop,
4099  int key,
4100  PointerRNA *r_ptr)
4101 {
4103 
4105 
4106  if (cprop->lookupint) {
4107  /* we have a callback defined, use it */
4108  return cprop->lookupint(ptr, key, r_ptr);
4109  }
4110  /* no callback defined, just iterate and find the nth item */
4112  int i;
4113 
4114  RNA_property_collection_begin(ptr, prop, &iter);
4115  for (i = 0; iter.valid; RNA_property_collection_next(&iter), i++) {
4116  if (i == key) {
4117  *r_ptr = iter.ptr;
4118  break;
4119  }
4120  }
4122 
4123  if (!iter.valid) {
4124  memset(r_ptr, 0, sizeof(*r_ptr));
4125  }
4126 
4127  return iter.valid;
4128 }
4129 
4131  PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
4132 {
4134 
4136 
4137  if (cprop->lookupstring) {
4138  /* we have a callback defined, use it */
4139  return cprop->lookupstring(ptr, key, r_ptr);
4140  }
4141  /* no callback defined, compare with name properties if they exist */
4143  PropertyRNA *nameprop;
4144  char name[256], *nameptr;
4145  int found = 0;
4146  int keylen = strlen(key);
4147  int namelen;
4148  int index = 0;
4149 
4150  RNA_property_collection_begin(ptr, prop, &iter);
4151  for (; iter.valid; RNA_property_collection_next(&iter), index++) {
4152  if (iter.ptr.data && iter.ptr.type->nameproperty) {
4153  nameprop = iter.ptr.type->nameproperty;
4154 
4155  nameptr = RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen);
4156 
4157  if ((keylen == namelen) && STREQ(nameptr, key)) {
4158  *r_ptr = iter.ptr;
4159  found = 1;
4160  }
4161 
4162  if ((char *)&name != nameptr) {
4163  MEM_freeN(nameptr);
4164  }
4165 
4166  if (found) {
4167  break;
4168  }
4169  }
4170  }
4172 
4173  if (!iter.valid) {
4174  memset(r_ptr, 0, sizeof(*r_ptr));
4175  *r_index = -1;
4176  }
4177  else {
4178  *r_index = index;
4179  }
4180 
4181  return iter.valid;
4182 }
4183 
4185  PropertyRNA *prop,
4186  const char *key,
4187  PointerRNA *r_ptr)
4188 {
4189  int index;
4190  return RNA_property_collection_lookup_string_index(ptr, prop, key, r_ptr, &index);
4191 }
4192 
4194  PropertyRNA *prop,
4195  const int key,
4196  const PointerRNA *assign_ptr)
4197 {
4199 
4201 
4202  if (cprop->assignint) {
4203  /* we have a callback defined, use it */
4204  return cprop->assignint(ptr, key, assign_ptr);
4205  }
4206 
4207  return 0;
4208 }
4209 
4211 {
4213 
4214  *r_ptr = *ptr;
4215  return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1 : 0);
4216 }
4217 
4219  PropertyRNA *prop,
4220  PropertyRNA *itemprop,
4221  RawArray *array)
4222 {
4224  ArrayIterator *internal;
4225  char *arrayp;
4226 
4228 
4229  if (!(prop->flag_internal & PROP_INTERN_RAW_ARRAY) ||
4230  !(itemprop->flag_internal & PROP_INTERN_RAW_ACCESS)) {
4231  return 0;
4232  }
4233 
4234  RNA_property_collection_begin(ptr, prop, &iter);
4235 
4236  if (iter.valid) {
4237  /* get data from array iterator and item property */
4238  internal = &iter.internal.array;
4239  arrayp = (iter.valid) ? iter.ptr.data : NULL;
4240 
4241  if (internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
4242  /* we might skip some items, so it's not a proper array */
4244  return 0;
4245  }
4246 
4247  array->array = arrayp + itemprop->rawoffset;
4248  array->stride = internal->itemsize;
4249  array->len = ((char *)internal->endptr - arrayp) / internal->itemsize;
4250  array->type = itemprop->rawtype;
4251  }
4252  else {
4253  memset(array, 0, sizeof(RawArray));
4254  }
4255 
4257 
4258  return 1;
4259 }
4260 
4261 #define RAW_GET(dtype, var, raw, a) \
4262  { \
4263  switch (raw.type) { \
4264  case PROP_RAW_CHAR: \
4265  var = (dtype)((char *)raw.array)[a]; \
4266  break; \
4267  case PROP_RAW_SHORT: \
4268  var = (dtype)((short *)raw.array)[a]; \
4269  break; \
4270  case PROP_RAW_INT: \
4271  var = (dtype)((int *)raw.array)[a]; \
4272  break; \
4273  case PROP_RAW_BOOLEAN: \
4274  var = (dtype)((bool *)raw.array)[a]; \
4275  break; \
4276  case PROP_RAW_FLOAT: \
4277  var = (dtype)((float *)raw.array)[a]; \
4278  break; \
4279  case PROP_RAW_DOUBLE: \
4280  var = (dtype)((double *)raw.array)[a]; \
4281  break; \
4282  default: \
4283  var = (dtype)0; \
4284  } \
4285  } \
4286  (void)0
4287 
4288 #define RAW_SET(dtype, raw, a, var) \
4289  { \
4290  switch (raw.type) { \
4291  case PROP_RAW_CHAR: \
4292  ((char *)raw.array)[a] = (char)var; \
4293  break; \
4294  case PROP_RAW_SHORT: \
4295  ((short *)raw.array)[a] = (short)var; \
4296  break; \
4297  case PROP_RAW_INT: \
4298  ((int *)raw.array)[a] = (int)var; \
4299  break; \
4300  case PROP_RAW_BOOLEAN: \
4301  ((bool *)raw.array)[a] = (bool)var; \
4302  break; \
4303  case PROP_RAW_FLOAT: \
4304  ((float *)raw.array)[a] = (float)var; \
4305  break; \
4306  case PROP_RAW_DOUBLE: \
4307  ((double *)raw.array)[a] = (double)var; \
4308  break; \
4309  default: \
4310  break; \
4311  } \
4312  } \
4313  (void)0
4314 
4316 {
4317  switch (type) {
4318  case PROP_RAW_CHAR:
4319  return sizeof(char);
4320  case PROP_RAW_SHORT:
4321  return sizeof(short);
4322  case PROP_RAW_INT:
4323  return sizeof(int);
4324  case PROP_RAW_BOOLEAN:
4325  return sizeof(bool);
4326  case PROP_RAW_FLOAT:
4327  return sizeof(float);
4328  case PROP_RAW_DOUBLE:
4329  return sizeof(double);
4330  default:
4331  return 0;
4332  }
4333 }
4334 
4336 {
4337  int i, len[RNA_MAX_ARRAY_DIMENSION];
4338  const int dim = RNA_property_array_dimension(ptr, prop, len);
4339  int size;
4340 
4341  if (dim == 0) {
4342  return 0;
4343  }
4344 
4345  for (size = 1, i = 0; i < dim; i++) {
4346  size *= len[i];
4347  }
4348 
4349  return size;
4350 }
4351 
4352 static int rna_raw_access(ReportList *reports,
4353  PointerRNA *ptr,
4354  PropertyRNA *prop,
4355  const char *propname,
4356  void *inarray,
4357  RawPropertyType intype,
4358  int inlen,
4359  int set)
4360 {
4361  StructRNA *ptype;
4362  PointerRNA itemptr_base;
4363  PropertyRNA *itemprop, *iprop;
4364  PropertyType itemtype = 0;
4365  RawArray in;
4366  int itemlen = 0;
4367 
4368  /* initialize in array, stride assumed 0 in following code */
4369  in.array = inarray;
4370  in.type = intype;
4371  in.len = inlen;
4372  in.stride = 0;
4373 
4374  ptype = RNA_property_pointer_type(ptr, prop);
4375 
4376  /* try to get item property pointer */
4377  RNA_pointer_create(NULL, ptype, NULL, &itemptr_base);
4378  itemprop = RNA_struct_find_property(&itemptr_base, propname);
4379 
4380  if (itemprop) {
4381  /* we have item property pointer */
4382  RawArray out;
4383 
4384  /* check type */
4385  itemtype = RNA_property_type(itemprop);
4386 
4387  if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
4388  BKE_report(reports, RPT_ERROR, "Only boolean, int float and enum properties supported");
4389  return 0;
4390  }
4391 
4392  /* check item array */
4393  itemlen = RNA_property_array_length(&itemptr_base, itemprop);
4394 
4395  /* dynamic array? need to get length per item */
4396  if (itemprop->getlength) {
4397  itemprop = NULL;
4398  }
4399  /* try to access as raw array */
4400  else if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
4401  int arraylen = (itemlen == 0) ? 1 : itemlen;
4402  if (in.len != arraylen * out.len) {
4403  BKE_reportf(reports,
4404  RPT_ERROR,
4405  "Array length mismatch (expected %d, got %d)",
4406  out.len * arraylen,
4407  in.len);
4408  return 0;
4409  }
4410 
4411  /* matching raw types */
4412  if (out.type == in.type) {
4413  void *inp = in.array;
4414  void *outp = out.array;
4415  int a, size;
4416 
4417  size = RNA_raw_type_sizeof(out.type) * arraylen;
4418 
4419  for (a = 0; a < out.len; a++) {
4420  if (set) {
4421  memcpy(outp, inp, size);
4422  }
4423  else {
4424  memcpy(inp, outp, size);
4425  }
4426 
4427  inp = (char *)inp + size;
4428  outp = (char *)outp + out.stride;
4429  }
4430 
4431  return 1;
4432  }
4433 
4434  /* Could also be faster with non-matching types,
4435  * for now we just do slower loop. */
4436  }
4437  BLI_assert_msg(itemlen == 0 || itemtype != PROP_ENUM,
4438  "Enum array properties should not exist");
4439  }
4440 
4441  {
4442  void *tmparray = NULL;
4443  int tmplen = 0;
4444  int err = 0, j, a = 0;
4445  int needconv = 1;
4446 
4447  if (((itemtype == PROP_INT) && (in.type == PROP_RAW_INT)) ||
4448  ((itemtype == PROP_BOOLEAN) && (in.type == PROP_RAW_BOOLEAN)) ||
4449  ((itemtype == PROP_FLOAT) && (in.type == PROP_RAW_FLOAT))) {
4450  /* avoid creating temporary buffer if the data type match */
4451  needconv = 0;
4452  }
4453  /* no item property pointer, can still be id property, or
4454  * property of a type derived from the collection pointer type */
4455  RNA_PROP_BEGIN (ptr, itemptr, prop) {
4456  if (itemptr.data) {
4457  if (itemprop) {
4458  /* we got the property already */
4459  iprop = itemprop;
4460  }
4461  else {
4462  /* not yet, look it up and verify if it is valid */
4463  iprop = RNA_struct_find_property(&itemptr, propname);
4464 
4465  if (iprop) {
4466  itemlen = rna_property_array_length_all_dimensions(&itemptr, iprop);
4467  itemtype = RNA_property_type(iprop);
4468  }
4469  else {
4470  BKE_reportf(reports, RPT_ERROR, "Property named '%s' not found", propname);
4471  err = 1;
4472  break;
4473  }
4474 
4475  if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
4476  BKE_report(
4477  reports, RPT_ERROR, "Only boolean, int, float and enum properties supported");
4478  err = 1;
4479  break;
4480  }
4481  BLI_assert_msg(itemlen == 0 || itemtype != PROP_ENUM,
4482  "Enum array properties should not exist");
4483  }
4484 
4485  /* editable check */
4486  if (!set || RNA_property_editable(&itemptr, iprop)) {
4487  if (a + itemlen > in.len) {
4488  BKE_reportf(
4489  reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
4490  err = 1;
4491  break;
4492  }
4493 
4494  if (itemlen == 0) {
4495  /* handle conversions */
4496  if (set) {
4497  switch (itemtype) {
4498  case PROP_BOOLEAN: {
4499  int b;
4500  RAW_GET(bool, b, in, a);
4501  RNA_property_boolean_set(&itemptr, iprop, b);
4502  break;
4503  }
4504  case PROP_INT: {
4505  int i;
4506  RAW_GET(int, i, in, a);
4507  RNA_property_int_set(&itemptr, iprop, i);
4508  break;
4509  }
4510  case PROP_FLOAT: {
4511  float f;
4512  RAW_GET(float, f, in, a);
4513  RNA_property_float_set(&itemptr, iprop, f);
4514  break;
4515  }
4516  case PROP_ENUM: {
4517  int i;
4518  RAW_GET(int, i, in, a);
4519  RNA_property_enum_set(&itemptr, iprop, i);
4520  break;
4521  }
4522  default:
4524  break;
4525  }
4526  }
4527  else {
4528  switch (itemtype) {
4529  case PROP_BOOLEAN: {
4530  int b = RNA_property_boolean_get(&itemptr, iprop);
4531  RAW_SET(bool, in, a, b);
4532  break;
4533  }
4534  case PROP_INT: {
4535  int i = RNA_property_int_get(&itemptr, iprop);
4536  RAW_SET(int, in, a, i);
4537  break;
4538  }
4539  case PROP_FLOAT: {
4540  float f = RNA_property_float_get(&itemptr, iprop);
4541  RAW_SET(float, in, a, f);
4542  break;
4543  }
4544  case PROP_ENUM: {
4545  int i = RNA_property_enum_get(&itemptr, iprop);
4546  RAW_SET(int, in, a, i);
4547  break;
4548  }
4549  default:
4551  break;
4552  }
4553  }
4554  a++;
4555  }
4556  else if (needconv == 1) {
4557  /* allocate temporary array if needed */
4558  if (tmparray && tmplen != itemlen) {
4559  MEM_freeN(tmparray);
4560  tmparray = NULL;
4561  }
4562  if (!tmparray) {
4563  tmparray = MEM_callocN(sizeof(float) * itemlen, "RNA tmparray");
4564  tmplen = itemlen;
4565  }
4566 
4567  /* handle conversions */
4568  if (set) {
4569  switch (itemtype) {
4570  case PROP_BOOLEAN: {
4571  for (j = 0; j < itemlen; j++, a++) {
4572  RAW_GET(bool, ((bool *)tmparray)[j], in, a);
4573  }
4574  RNA_property_boolean_set_array(&itemptr, iprop, tmparray);
4575  break;
4576  }
4577  case PROP_INT: {
4578  for (j = 0; j < itemlen; j++, a++) {
4579  RAW_GET(int, ((int *)tmparray)[j], in, a);
4580  }
4581  RNA_property_int_set_array(&itemptr, iprop, tmparray);
4582  break;
4583  }
4584  case PROP_FLOAT: {
4585  for (j = 0; j < itemlen; j++, a++) {
4586  RAW_GET(float, ((float *)tmparray)[j], in, a);
4587  }
4588  RNA_property_float_set_array(&itemptr, iprop, tmparray);
4589  break;
4590  }
4591  default:
4593  break;
4594  }
4595  }
4596  else {
4597  switch (itemtype) {
4598  case PROP_BOOLEAN: {
4599  RNA_property_boolean_get_array(&itemptr, iprop, tmparray);
4600  for (j = 0; j < itemlen; j++, a++) {
4601  RAW_SET(int, in, a, ((bool *)tmparray)[j]);
4602  }
4603  break;
4604  }
4605  case PROP_INT: {
4606  RNA_property_int_get_array(&itemptr, iprop, tmparray);
4607  for (j = 0; j < itemlen; j++, a++) {
4608  RAW_SET(int, in, a, ((int *)tmparray)[j]);
4609  }
4610  break;
4611  }
4612  case PROP_FLOAT: {
4613  RNA_property_float_get_array(&itemptr, iprop, tmparray);
4614  for (j = 0; j < itemlen; j++, a++) {
4615  RAW_SET(float, in, a, ((float *)tmparray)[j]);
4616  }
4617  break;
4618  }
4619  default:
4621  break;
4622  }
4623  }
4624  }
4625  else {
4626  if (set) {
4627  switch (itemtype) {
4628  case PROP_BOOLEAN: {
4629  RNA_property_boolean_set_array(&itemptr, iprop, &((bool *)in.array)[a]);
4630  a += itemlen;
4631  break;
4632  }
4633  case PROP_INT: {
4634  RNA_property_int_set_array(&itemptr, iprop, &((int *)in.array)[a]);
4635  a += itemlen;
4636  break;
4637  }
4638  case PROP_FLOAT: {
4639  RNA_property_float_set_array(&itemptr, iprop, &((float *)in.array)[a]);
4640  a += itemlen;
4641  break;
4642  }
4643  default:
4645  break;
4646  }
4647  }
4648  else {
4649  switch (itemtype) {
4650  case PROP_BOOLEAN: {
4651  RNA_property_boolean_get_array(&itemptr, iprop, &((bool *)in.array)[a]);
4652  a += itemlen;
4653  break;
4654  }
4655  case PROP_INT: {
4656  RNA_property_int_get_array(&itemptr, iprop, &((int *)in.array)[a]);
4657  a += itemlen;
4658  break;
4659  }
4660  case PROP_FLOAT: {
4661  RNA_property_float_get_array(&itemptr, iprop, &((float *)in.array)[a]);
4662  a += itemlen;
4663  break;
4664  }
4665  default:
4667  break;
4668  }
4669  }
4670  }
4671  }
4672  }
4673  }
4674  RNA_PROP_END;
4675 
4676  if (tmparray) {
4677  MEM_freeN(tmparray);
4678  }
4679 
4680  return !err;
4681  }
4682 }
4683 
4685 {
4686  if (prop->rawtype == PROP_RAW_UNSET) {
4687  /* this property has no raw access,
4688  * yet we try to provide a raw type to help building the array. */
4689  switch (prop->type) {
4690  case PROP_BOOLEAN:
4691  return PROP_RAW_BOOLEAN;
4692  case PROP_INT:
4693  return PROP_RAW_INT;
4694  case PROP_FLOAT:
4695  return PROP_RAW_FLOAT;
4696  case PROP_ENUM:
4697  return PROP_RAW_INT;
4698  default:
4699  break;
4700  }
4701  }
4702  return prop->rawtype;
4703 }
4704 
4706  PointerRNA *ptr,
4707  PropertyRNA *prop,
4708  const char *propname,
4709  void *array,
4711  int len)
4712 {
4713  return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0);
4714 }
4715 
4717  PointerRNA *ptr,
4718  PropertyRNA *prop,
4719  const char *propname,
4720  void *array,
4722  int len)
4723 {
4724  return rna_raw_access(reports, ptr, prop, propname, array, type, len, 1);
4725 }
4726 
4727 /* Standard iterator functions */
4728 
4730  ListBase *lb,
4731  IteratorSkipFunc skip)
4732 {
4733  ListBaseIterator *internal = &iter->internal.listbase;
4734 
4735  internal->link = (lb) ? lb->first : NULL;
4736  internal->skip = skip;
4737 
4738  iter->valid = (internal->link != NULL);
4739 
4740  if (skip && iter->valid && skip(iter, internal->link)) {
4742  }
4743 }
4744 
4746 {
4747  ListBaseIterator *internal = &iter->internal.listbase;
4748 
4749  if (internal->skip) {
4750  do {
4751  internal->link = internal->link->next;
4752  iter->valid = (internal->link != NULL);
4753  } while (iter->valid && internal->skip(iter, internal->link));
4754  }
4755  else {
4756  internal->link = internal->link->next;
4757  iter->valid = (internal->link != NULL);
4758  }
4759 }
4760 
4762 {
4763  ListBaseIterator *internal = &iter->internal.listbase;
4764 
4765  return internal->link;
4766 }
4767 
4769 {
4770 }
4771 
4773  StructRNA *type,
4774  struct ListBase *lb,
4775  int index)
4776 {
4777  void *data = BLI_findlink(lb, index);
4779 }
4780 
4782  void *ptr,
4783  int itemsize,
4784  int length,
4785  bool free_ptr,
4786  IteratorSkipFunc skip)
4787 {
4788  ArrayIterator *internal;
4789 
4790  if (ptr == NULL) {
4791  length = 0;
4792  }
4793  else if (length == 0) {
4794  ptr = NULL;
4795  itemsize = 0;
4796  }
4797 
4798  internal = &iter->internal.array;
4799  internal->ptr = ptr;
4800  internal->free_ptr = free_ptr ? ptr : NULL;
4801  internal->endptr = ((char *)ptr) + length * itemsize;
4802  internal->itemsize = itemsize;
4803  internal->skip = skip;
4804  internal->length = length;
4805 
4806  iter->valid = (internal->ptr != internal->endptr);
4807 
4808  if (skip && iter->valid && skip(iter, internal->ptr)) {
4810  }
4811 }
4812 
4814 {
4815  ArrayIterator *internal = &iter->internal.array;
4816 
4817  if (internal->skip) {
4818  do {
4819  internal->ptr += internal->itemsize;
4820  iter->valid = (internal->ptr != internal->endptr);
4821  } while (iter->valid && internal->skip(iter, internal->ptr));
4822  }
4823  else {
4824  internal->ptr += internal->itemsize;
4825  iter->valid = (internal->ptr != internal->endptr);
4826  }
4827 }
4828 
4830 {
4831  ArrayIterator *internal = &iter->internal.array;
4832 
4833  return internal->ptr;
4834 }
4835 
4837 {
4838  ArrayIterator *internal = &iter->internal.array;
4839 
4840  /* for ** arrays */
4841  return *(void **)(internal->ptr);
4842 }
4843 
4845 {
4846  ArrayIterator *internal = &iter->internal.array;
4847 
4848  MEM_SAFE_FREE(internal->free_ptr);
4849 }
4850 
4852  PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
4853 {
4854  if (index < 0 || index >= length) {
4855  return PointerRNA_NULL;
4856  }
4857 
4858  return rna_pointer_inherit_refine(ptr, type, ((char *)data) + index * itemsize);
4859 }
4860 
4861 /* Quick name based property access */
4862 
4863 bool RNA_boolean_get(PointerRNA *ptr, const char *name)
4864 {
4865  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4866 
4867  if (prop) {
4868  return RNA_property_boolean_get(ptr, prop);
4869  }
4870  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4871  return 0;
4872 }
4873 
4874 void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
4875 {
4876  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4877 
4878  if (prop) {
4879  RNA_property_boolean_set(ptr, prop, value);
4880  }
4881  else {
4882  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4883  }
4884 }
4885 
4886 void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
4887 {
4888  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4889 
4890  if (prop) {
4891  RNA_property_boolean_get_array(ptr, prop, values);
4892  }
4893  else {
4894  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4895  }
4896 }
4897 
4898 void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
4899 {
4900  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4901 
4902  if (prop) {
4903  RNA_property_boolean_set_array(ptr, prop, values);
4904  }
4905  else {
4906  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4907  }
4908 }
4909 
4910 int RNA_int_get(PointerRNA *ptr, const char *name)
4911 {
4912  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4913 
4914  if (prop) {
4915  return RNA_property_int_get(ptr, prop);
4916  }
4917  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4918  return 0;
4919 }
4920 
4921 void RNA_int_set(PointerRNA *ptr, const char *name, int value)
4922 {
4923  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4924 
4925  if (prop) {
4926  RNA_property_int_set(ptr, prop, value);
4927  }
4928  else {
4929  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4930  }
4931 }
4932 
4933 void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
4934 {
4935  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4936 
4937  if (prop) {
4938  RNA_property_int_get_array(ptr, prop, values);
4939  }
4940  else {
4941  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4942  }
4943 }
4944 
4945 void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
4946 {
4947  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4948 
4949  if (prop) {
4950  RNA_property_int_set_array(ptr, prop, values);
4951  }
4952  else {
4953  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4954  }
4955 }
4956 
4957 float RNA_float_get(PointerRNA *ptr, const char *name)
4958 {
4959  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4960 
4961  if (prop) {
4962  return RNA_property_float_get(ptr, prop);
4963  }
4964  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4965  return 0;
4966 }
4967 
4968 void RNA_float_set(PointerRNA *ptr, const char *name, float value)
4969 {
4970  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4971 
4972  if (prop) {
4973  RNA_property_float_set(ptr, prop, value);
4974  }
4975  else {
4976  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4977  }
4978 }
4979 
4980 void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
4981 {
4982  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4983 
4984  if (prop) {
4985  RNA_property_float_get_array(ptr, prop, values);
4986  }
4987  else {
4988  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
4989  }
4990 }
4991 
4992 void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
4993 {
4994  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
4995 
4996  if (prop) {
4997  RNA_property_float_set_array(ptr, prop, values);
4998  }
4999  else {
5000  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5001  }
5002 }
5003 
5004 int RNA_enum_get(PointerRNA *ptr, const char *name)
5005 {
5006  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5007 
5008  if (prop) {
5009  return RNA_property_enum_get(ptr, prop);
5010  }
5011  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5012  return 0;
5013 }
5014 
5015 void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
5016 {
5017  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5018 
5019  if (prop) {
5020  RNA_property_enum_set(ptr, prop, value);
5021  }
5022  else {
5023  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5024  }
5025 }
5026 
5027 void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
5028 {
5029  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5030 
5031  if (prop) {
5032  int value;
5033  if (RNA_property_enum_value(C, ptr, prop, id, &value)) {
5034  RNA_property_enum_set(ptr, prop, value);
5035  }
5036  else {
5037  printf("%s: %s.%s has no enum id '%s'.\n", __func__, ptr->type->identifier, name, id);
5038  }
5039  }
5040  else {
5041  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5042  }
5043 }
5044 
5045 bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
5046 {
5047  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5048  const EnumPropertyItem *item;
5049  bool free;
5050 
5051  if (prop) {
5052  int i;
5053  bool cmp = false;
5054 
5055  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
5056  i = RNA_enum_from_identifier(item, enumname);
5057  if (i != -1) {
5058  cmp = (item[i].value == RNA_property_enum_get(ptr, prop));
5059  }
5060 
5061  if (free) {
5062  MEM_freeN((void *)item);
5063  }
5064 
5065  if (i != -1) {
5066  return cmp;
5067  }
5068 
5069  printf("%s: %s.%s item %s not found.\n", __func__, ptr->type->identifier, name, enumname);
5070  return false;
5071  }
5072  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5073  return false;
5074 }
5075 
5076 bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
5077 {
5078  const int i = RNA_enum_from_identifier(item, identifier);
5079  if (i != -1) {
5080  *r_value = item[i].value;
5081  return true;
5082  }
5083  return false;
5084 }
5085 
5086 bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
5087 {
5088  const int i = RNA_enum_from_value(item, value);
5089  if (i != -1) {
5090  *r_identifier = item[i].identifier;
5091  return true;
5092  }
5093  return false;
5094 }
5095 
5096 bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
5097 {
5098  const int i = RNA_enum_from_value(item, value);
5099  if (i != -1) {
5100  *r_icon = item[i].icon;
5101  return true;
5102  }
5103  return false;
5104 }
5105 
5106 bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
5107 {
5108  const int i = RNA_enum_from_value(item, value);
5109  if (i != -1) {
5110  *r_name = item[i].name;
5111  return true;
5112  }
5113  return false;
5114 }
5115 
5116 void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
5117 {
5118  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5119 
5120  if (prop) {
5121  RNA_property_string_get(ptr, prop, value);
5122  }
5123  else {
5124  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5125  value[0] = '\0';
5126  }
5127 }
5128 
5130  PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
5131 {
5132  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5133 
5134  if (prop) {
5135  return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, r_len);
5136  }
5137  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5138  if (r_len != NULL) {
5139  *r_len = 0;
5140  }
5141  return NULL;
5142 }
5143 
5144 int RNA_string_length(PointerRNA *ptr, const char *name)
5145 {
5146  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5147 
5148  if (prop) {
5149  return RNA_property_string_length(ptr, prop);
5150  }
5151  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5152  return 0;
5153 }
5154 
5155 void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
5156 {
5157  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5158 
5159  if (prop) {
5160  RNA_property_string_set(ptr, prop, value);
5161  }
5162  else {
5163  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5164  }
5165 }
5166 
5168 {
5169  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5170 
5171  if (prop) {
5172  return RNA_property_pointer_get(ptr, prop);
5173  }
5174  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5175 
5176  return PointerRNA_NULL;
5177 }
5178 
5179 void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
5180 {
5181  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5182 
5183  if (prop) {
5184  RNA_property_pointer_set(ptr, prop, ptr_value, NULL);
5185  }
5186  else {
5187  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5188  }
5189 }
5190 
5191 void RNA_pointer_add(PointerRNA *ptr, const char *name)
5192 {
5193  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5194 
5195  if (prop) {
5197  }
5198  else {
5199  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5200  }
5201 }
5202 
5204 {
5205  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5206 
5207  if (prop) {
5208  RNA_property_collection_begin(ptr, prop, iter);
5209  }
5210  else {
5211  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5212  }
5213 }
5214 
5215 void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
5216 {
5217  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5218 
5219  if (prop) {
5220  RNA_property_collection_add(ptr, prop, r_value);
5221  }
5222  else {
5223  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5224  }
5225 }
5226 
5227 void RNA_collection_clear(PointerRNA *ptr, const char *name)
5228 {
5229  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5230 
5231  if (prop) {
5233  }
5234  else {
5235  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5236  }
5237 }
5238 
5239 int RNA_collection_length(PointerRNA *ptr, const char *name)
5240 {
5241  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5242 
5243  if (prop) {
5244  return RNA_property_collection_length(ptr, prop);
5245  }
5246  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5247  return 0;
5248 }
5249 
5250 bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
5251 {
5252  PropertyRNA *prop = RNA_struct_find_property(ptr, name);
5253 
5254  if (prop) {
5255  return RNA_property_collection_is_empty(ptr, prop);
5256  }
5257  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5258  return false;
5259 }
5260 
5261 bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
5262 {
5263  prop = rna_ensure_property(prop);
5264  if (prop->flag & PROP_IDPROPERTY) {
5265  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
5266  return ((idprop != NULL) && (use_ghost == false || !(idprop->flag & IDP_FLAG_GHOST)));
5267  }
5268  return true;
5269 }
5270 
5272 {
5273  prop = rna_ensure_property(prop);
5274  if (prop->flag & PROP_IDPROPERTY) {
5275  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
5276  return ((idprop != NULL) && !(idprop->flag & IDP_FLAG_GHOST));
5277  }
5278  return true;
5279 }
5280 
5282 {
5283  prop = rna_ensure_property(prop);
5284  if (prop->flag & PROP_IDPROPERTY) {
5286  }
5287 }
5288 
5289 bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
5290 {
5291  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
5292 
5293  if (prop) {
5294  return RNA_property_is_set_ex(ptr, prop, use_ghost);
5295  }
5296  /* python raises an error */
5297  // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5298  return 0;
5299 }
5300 
5301 bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
5302 {
5303  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
5304 
5305  if (prop) {
5306  return RNA_property_is_set(ptr, prop);
5307  }
5308  /* python raises an error */
5309  // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
5310  return 0;
5311 }
5312 
5313 void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
5314 {
5315  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
5316 
5317  if (prop) {
5318  RNA_property_unset(ptr, prop);
5319  }
5320 }
5321 
5323 {
5324  return (prop->magic != RNA_MAGIC);
5325 }
5326 
5328 {
5329  const int flag = RNA_property_flag(prop);
5330  if (RNA_property_type(prop) == PROP_STRING) {
5331  return (flag & PROP_NEVER_UNLINK) == 0;
5332  }
5333  return (flag & (PROP_NEVER_UNLINK | PROP_NEVER_NULL)) == 0;
5334 }
5335 
5337 {
5338  DynStr *dynstr = BLI_dynstr_new();
5339  char *cstring;
5340 
5341  const char *propname;
5342  int first_time = 1;
5343 
5344  BLI_dynstr_append(dynstr, "{");
5345 
5346  RNA_STRUCT_BEGIN (ptr, prop) {
5347  propname = RNA_property_identifier(prop);
5348 
5349  if (STREQ(propname, "rna_type")) {
5350  continue;
5351  }
5352 
5353  if (first_time == 0) {
5354  BLI_dynstr_append(dynstr, ", ");
5355  }
5356  first_time = 0;
5357 
5358  cstring = RNA_property_as_string(C, ptr, prop, -1, INT_MAX);
5359  BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
5360  MEM_freeN(cstring);
5361  }
5363 
5364  BLI_dynstr_append(dynstr, "}");
5365 
5366  cstring = BLI_dynstr_get_cstring(dynstr);
5367  BLI_dynstr_free(dynstr);
5368  return cstring;
5369 }
5370 
5372 {
5373  if (ptr->type == NULL || ptr->owner_id == NULL) {
5374  return BLI_strdup("None");
5375  }
5376  if (RNA_struct_is_ID(ptr->type)) {
5377  return RNA_path_full_ID_py(bmain, ptr->owner_id);
5378  }
5379  return RNA_path_full_struct_py(bmain, ptr);
5380 }
5381 
5383  PointerRNA *ptr,
5384  PropertyRNA *prop_ptr,
5385  PointerRNA *ptr_prop)
5386 {
5387  IDProperty *prop;
5388  if (ptr_prop->data == NULL) {
5389  return BLI_strdup("None");
5390  }
5391  if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) {
5392  return RNA_pointer_as_string_id(C, ptr_prop);
5393  }
5394  return rna_pointer_as_string__bldata(CTX_data_main(C), ptr_prop);
5395 }
5396 
5398  PointerRNA *ptr,
5399  const bool as_function,
5400  const bool all_args,
5401  const bool nested_args,
5402  const int max_prop_length,
5403  PropertyRNA *iterprop)
5404 {
5405  const char *arg_name = NULL;
5406 
5407  PropertyRNA *prop;
5408 
5409  DynStr *dynstr = BLI_dynstr_new();
5410  char *cstring, *buf;
5411  bool first_iter = true;
5412  int flag, flag_parameter;
5413 
5414  RNA_PROP_BEGIN (ptr, propptr, iterprop) {
5415  prop = propptr.data;
5416 
5417  flag = RNA_property_flag(prop);
5418  flag_parameter = RNA_parameter_flag(prop);
5419 
5420  if (as_function && (flag_parameter & PARM_OUTPUT)) {
5421  continue;
5422  }
5423 
5424  arg_name = RNA_property_identifier(prop);
5425 
5426  if (STREQ(arg_name, "rna_type")) {
5427  continue;
5428  }
5429 
5430  if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) {
5431  continue;
5432  }
5433 
5434  if (as_function && (prop->flag_parameter & PARM_REQUIRED)) {
5435  /* required args don't have useful defaults */
5436  BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name);
5437  first_iter = false;
5438  }
5439  else {
5440  bool ok = true;
5441 
5442  if (all_args == true) {
5443  /* pass */
5444  }
5445  else if (RNA_struct_idprops_check(ptr->type)) {
5446  ok = RNA_property_is_set(ptr, prop);
5447  }
5448 
5449  if (ok) {
5450  if (as_function && RNA_property_type(prop) == PROP_POINTER) {
5451  /* don't expand pointers for functions */
5452  if (flag & PROP_NEVER_NULL) {
5453  /* we can't really do the right thing here. arg=arg?, hrmf! */
5454  buf = BLI_strdup(arg_name);
5455  }
5456  else {
5457  buf = BLI_strdup("None");
5458  }
5459  }
5460  else {
5461  buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length);
5462  }
5463 
5464  BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s" : ", %s=%s", arg_name, buf);
5465  first_iter = false;
5466  MEM_freeN(buf);
5467  }
5468  }
5469  }
5470  RNA_PROP_END;
5471 
5472  cstring = BLI_dynstr_get_cstring(dynstr);
5473  BLI_dynstr_free(dynstr);
5474  return cstring;
5475 }
5476 
5478  PointerRNA *ptr,
5479  const bool as_function,
5480  const bool all_args,
5481  const bool nested_args,
5482  const int max_prop_length)
5483 {
5484  PropertyRNA *iterprop;
5485 
5486  iterprop = RNA_struct_iterator_property(ptr->type);
5487 
5489  C, ptr, as_function, all_args, nested_args, max_prop_length, iterprop);
5490 }
5491 
5493  FunctionRNA *func,
5494  const bool as_function,
5495  const bool all_args,
5496  const int max_prop_length)
5497 {
5498  PointerRNA funcptr;
5499  PropertyRNA *iterprop;
5500 
5501  RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
5502 
5503  iterprop = RNA_struct_find_property(&funcptr, "parameters");
5504 
5506 
5508  C, &funcptr, as_function, all_args, true, max_prop_length, iterprop);
5509 }
5510 
5511 static const char *bool_as_py_string(const int var)
5512 {
5513  return var ? "True" : "False";
5514 }
5515 
5517  int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
5518 {
5519  void *buf_ret = NULL;
5520  switch (type) {
5521  case PROP_BOOLEAN: {
5522  bool *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
5523  RNA_property_boolean_get_array(ptr, prop, buf);
5524  *r_buf_end = buf + len;
5525  break;
5526  }
5527  case PROP_INT: {
5528  int *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
5529  RNA_property_int_get_array(ptr, prop, buf);
5530  *r_buf_end = buf + len;
5531  break;
5532  }
5533  case PROP_FLOAT: {
5534  float *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
5535  RNA_property_float_get_array(ptr, prop, buf);
5536  *r_buf_end = buf + len;
5537  break;
5538  }
5539  default:
5541  }
5542  return buf_ret;
5543 }
5544 
5545 static void rna_array_as_string_elem(int type, void **buf_p, int len, DynStr *dynstr)
5546 {
5547  /* This will print a comma separated string of the array elements from
5548  * buf start to len. We will add a comma if len == 1 to preserve tuples. */
5549  const int end = len - 1;
5550  switch (type) {
5551  case PROP_BOOLEAN: {
5552  bool *buf = *buf_p;
5553  for (int i = 0; i < len; i++, buf++) {
5554  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%s, " : "%s", bool_as_py_string(*buf));
5555  }
5556  *buf_p = buf;
5557  break;
5558  }
5559  case PROP_INT: {
5560  int *buf = *buf_p;
5561  for (int i = 0; i < len; i++, buf++) {
5562  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%d, " : "%d", *buf);
5563  }
5564  *buf_p = buf;
5565  break;
5566  }
5567  case PROP_FLOAT: {
5568  float *buf = *buf_p;
5569  for (int i = 0; i < len; i++, buf++) {
5570  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%g, " : "%g", *buf);
5571  }
5572  *buf_p = buf;
5573  break;
5574  }
5575  default:
5577  }
5578 }
5579 
5581  int type, void **buf_p, int totdim, const int *dim_size, DynStr *dynstr)
5582 {
5583  BLI_dynstr_append(dynstr, "(");
5584  if (totdim > 1) {
5585  totdim--;
5586  const int end = dim_size[totdim] - 1;
5587  for (int i = 0; i <= end; i++) {
5588  rna_array_as_string_recursive(type, buf_p, totdim, dim_size, dynstr);
5589  if (i < end || !end) {
5590  BLI_dynstr_append(dynstr, ", ");
5591  }
5592  }
5593  }
5594  else {
5595  rna_array_as_string_elem(type, buf_p, dim_size[0], dynstr);
5596  }
5597  BLI_dynstr_append(dynstr, ")");
5598 }
5599 
5601  int type, int len, PointerRNA *ptr, PropertyRNA *prop, DynStr *dynstr)
5602 {
5603  void *buf_end;
5604  void *buf = rna_array_as_string_alloc(type, len, ptr, prop, &buf_end);
5605  void *buf_step = buf;
5606  int totdim, dim_size[RNA_MAX_ARRAY_DIMENSION];
5607 
5608  totdim = RNA_property_array_dimension(ptr, prop, dim_size);
5609 
5610  rna_array_as_string_recursive(type, &buf_step, totdim, dim_size, dynstr);
5611  BLI_assert(buf_step == buf_end);
5612  MEM_freeN(buf);
5613 }
5614 
5616  bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
5617 {
5618  int type = RNA_property_type(prop);
5619  int len = RNA_property_array_length(ptr, prop);
5620 
5621  DynStr *dynstr = BLI_dynstr_new();
5622  char *cstring;
5623 
5624  /* see if we can coerce into a python type - PropertyType */
5625  switch (type) {
5626  case PROP_BOOLEAN:
5627  if (len == 0) {
5629  }
5630  else {
5631  if (index != -1) {
5632  BLI_dynstr_append(dynstr,
5634  }
5635  else {
5636  rna_array_as_string(type, len, ptr, prop, dynstr);
5637  }
5638  }
5639  break;
5640  case PROP_INT:
5641  if (len == 0) {
5642  BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
5643  }
5644  else {
5645  if (index != -1) {
5646  BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get_index(ptr, prop, index));
5647  }
5648  else {
5649  rna_array_as_string(type, len, ptr, prop, dynstr);
5650  }
5651  }
5652  break;
5653  case PROP_FLOAT:
5654  if (len == 0) {
5655  BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
5656  }
5657  else {
5658  if (index != -1) {
5659  BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get_index(ptr, prop, index));
5660  }
5661  else {
5662  rna_array_as_string(type, len, ptr, prop, dynstr);
5663  }
5664  }
5665  break;
5666  case PROP_STRING: {
5667  char *buf_esc;
5668  char *buf;
5669  int length;
5670 
5672  buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_property_as_string");
5673  buf_esc = MEM_mallocN(sizeof(char) * (length * 2 + 1), "RNA_property_as_string esc");
5674  RNA_property_string_get(ptr, prop, buf);
5675  BLI_str_escape(buf_esc, buf, length * 2 + 1);
5676  MEM_freeN(buf);
5677  BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
5678  MEM_freeN(buf_esc);
5679  break;
5680  }
5681  case PROP_ENUM: {
5682  /* string arrays don't exist */
5683  const char *identifier;
5684  int val = RNA_property_enum_get(ptr, prop);
5685 
5686  if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
5687  /* represent as a python set */
5688  if (val) {
5689  const EnumPropertyItem *item_array;
5690  bool free;
5691 
5692  BLI_dynstr_append(dynstr, "{");
5693 
5694  RNA_property_enum_items(C, ptr, prop, &item_array, NULL, &free);
5695  if (item_array) {
5696  const EnumPropertyItem *item = item_array;
5697  bool is_first = true;
5698  for (; item->identifier; item++) {
5699  if (item->identifier[0] && item->value & val) {
5700  BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier);
5701  is_first = false;
5702  }
5703  }
5704 
5705  if (free) {
5706  MEM_freeN((void *)item_array);
5707  }
5708  }
5709 
5710  BLI_dynstr_append(dynstr, "}");
5711  }
5712  else {
5713  /* annoying exception, don't confuse with dictionary syntax above: {} */
5714  BLI_dynstr_append(dynstr, "set()");
5715  }
5716  }
5717  else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
5718  BLI_dynstr_appendf(dynstr, "'%s'", identifier);
5719  }
5720  else {
5721  BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
5722  }
5723  break;
5724  }
5725  case PROP_POINTER: {
5726  PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
5727  cstring = RNA_pointer_as_string(C, ptr, prop, &tptr);
5728  BLI_dynstr_append(dynstr, cstring);
5729  MEM_freeN(cstring);
5730  break;
5731  }
5732  case PROP_COLLECTION: {
5733  int i = 0;
5734  CollectionPropertyIterator collect_iter;
5735  BLI_dynstr_append(dynstr, "[");
5736 
5737  for (RNA_property_collection_begin(ptr, prop, &collect_iter);
5738  (i < max_prop_length) && collect_iter.valid;
5739  RNA_property_collection_next(&collect_iter), i++) {
5740  PointerRNA itemptr = collect_iter.ptr;
5741 
5742  if (i != 0) {
5743  BLI_dynstr_append(dynstr, ", ");
5744  }
5745 
5746  /* now get every prop of the collection */
5747  cstring = RNA_pointer_as_string(C, ptr, prop, &itemptr);
5748  BLI_dynstr_append(dynstr, cstring);
5749  MEM_freeN(cstring);
5750  }
5751 
5752  RNA_property_collection_end(&collect_iter);
5753  BLI_dynstr_append(dynstr, "]");
5754  break;
5755  }
5756  default:
5757  BLI_dynstr_append(dynstr, "'<UNKNOWN TYPE>'"); /* TODO */
5758  break;
5759  }
5760 
5761  cstring = BLI_dynstr_get_cstring(dynstr);
5762  BLI_dynstr_free(dynstr);
5763  return cstring;
5764 }
5765 
5766 /* Function */
5767 
5769 {
5770  return func->identifier;
5771 }
5772 
5774 {
5775  return TIP_(func->description);
5776 }
5777 
5779 {
5780  return func->description;
5781 }
5782 
5784 {
5785  return func->flag;
5786 }
5787 
5789 {
5790  return func->call != NULL;
5791 }
5792 
5794 {
5795  return BLI_findlink(&func->cont.properties, index);
5796 }
5797 
5799  FunctionRNA *func,
5800  const char *identifier)
5801 {
5802  PropertyRNA *parm;
5803 
5804  parm = func->cont.properties.first;
5805  for (; parm; parm = parm->next) {
5806  if (STREQ(RNA_property_identifier(parm), identifier)) {
5807  break;
5808  }
5809  }
5810 
5811  return parm;
5812 }
5813 
5815 {
5816  return &func->cont.properties;
5817 }
5818 
5819 /* Utility */
5820 
5822 {
5823  return (int)rna_ensure_property(prop)->flag_parameter;
5824 }
5825 
5827  PointerRNA *UNUSED(ptr),
5828  FunctionRNA *func)
5829 {
5830  PropertyRNA *parm;
5831  PointerRNA null_ptr = PointerRNA_NULL;
5832  void *data;
5833  int alloc_size = 0, size;
5834 
5835  parms->arg_count = 0;
5836  parms->ret_count = 0;
5837 
5838  /* allocate data */
5839  for (parm = func->cont.properties.first; parm; parm = parm->next) {
5840  alloc_size += rna_parameter_size_pad(rna_parameter_size(parm));
5841 
5842  if (parm->flag_parameter & PARM_OUTPUT) {
5843  parms->ret_count++;
5844  }
5845  else {
5846  parms->arg_count++;
5847  }
5848  }
5849 
5850  parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create");
5851  parms->func = func;
5852  parms->alloc_size = alloc_size;
5853 
5854  /* set default values */
5855  data = parms->data;
5856 
5857  for (parm = func->cont.properties.first; parm; parm = parm->next) {
5858  size = rna_parameter_size(parm);
5859 
5860  /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */
5861  if (parm->flag & PROP_DYNAMIC) {
5862  ParameterDynAlloc *data_alloc = data;
5863  data_alloc->array_tot = 0;
5864  data_alloc->array = NULL;
5865  }
5866 
5867  if (!(parm->flag_parameter & PARM_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
5868  switch (parm->type) {
5869  case PROP_BOOLEAN:
5870  if (parm->arraydimension) {
5872  &null_ptr, (BoolPropertyRNA *)parm, data);
5873  }
5874  else {
5875  memcpy(data, &((BoolPropertyRNA *)parm)->defaultvalue, size);
5876  }
5877  break;
5878  case PROP_INT:
5879  if (parm->arraydimension) {
5881  }
5882  else {
5883  memcpy(data, &((IntPropertyRNA *)parm)->defaultvalue, size);
5884  }
5885  break;
5886  case PROP_FLOAT:
5887  if (parm->arraydimension) {
5889  }
5890  else {
5891  memcpy(data, &((FloatPropertyRNA *)parm)->defaultvalue, size);
5892  }
5893  break;
5894  case PROP_ENUM:
5895  memcpy(data, &((EnumPropertyRNA *)parm)->defaultvalue, size);
5896  break;
5897  case PROP_STRING: {
5898  const char *defvalue = ((StringPropertyRNA *)parm)->defaultvalue;
5899  if (defvalue && defvalue[0]) {
5900  /* causes bug T29988, possibly this is only correct for thick wrapped
5901  * need to look further into it - campbell */
5902 #if 0
5903  BLI_strncpy(data, defvalue, size);
5904 #else
5905  memcpy(data, &defvalue, size);
5906 #endif
5907  }
5908  break;
5909  }
5910  case PROP_POINTER:
5911  case PROP_COLLECTION:
5912  break;
5913  }
5914  }
5915 
5916  data = ((char *)data) + rna_parameter_size_pad(size);
5917  }
5918 
5919  return parms;
5920 }
5921 
5923 {
5924  PropertyRNA *parm;
5925  int tot;
5926 
5927  parm = parms->func->cont.properties.first;
5928  for (tot = 0; parm; parm = parm->next) {
5929  if (parm->type == PROP_COLLECTION) {
5930  BLI_freelistN((ListBase *)((char *)parms->data + tot));
5931  }
5932  else if (parm->flag & PROP_DYNAMIC) {
5933  /* for dynamic arrays and strings, data is a pointer to an array */
5934  ParameterDynAlloc *data_alloc = (void *)(((char *)parms->data) + tot);
5935  if (data_alloc->array) {
5936  MEM_freeN(data_alloc->array);
5937  }
5938  }
5939 
5941  }
5942 
5943  MEM_freeN(parms->data);
5944  parms->data = NULL;
5945 
5946  parms->func = NULL;
5947 }
5948 
5950 {
5951  return parms->alloc_size;
5952 }
5953 
5955 {
5956  return parms->arg_count;
5957 }
5958 
5960 {
5961  return parms->ret_count;
5962 }
5963 
5965 {
5966  /* may be useful but unused now */
5967  // RNA_pointer_create(NULL, &RNA_Function, parms->func, &iter->funcptr); /* UNUSED */
5968 
5969  iter->parms = parms;
5970  iter->parm = parms->func->cont.properties.first;
5971  iter->valid = iter->parm != NULL;
5972  iter->offset = 0;
5973 
5974  if (iter->valid) {
5975  iter->size = rna_parameter_size(iter->parm);
5976  iter->data = (((char *)iter->parms->data)); /* +iter->offset, always 0 */
5977  }
5978 }
5979 
5981 {
5982  iter->offset += rna_parameter_size_pad(iter->size);
5983  iter->parm = iter->parm->next;
5984  iter->valid = iter->parm != NULL;
5985 
5986  if (iter->valid) {
5987  iter->size = rna_parameter_size(iter->parm);
5988  iter->data = (((char *)iter->parms->data) + iter->offset);
5989  }
5990 }
5991 
5993 {
5994  /* nothing to do */
5995 }
5996 
5997 void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **value)
5998 {
5999  ParameterIterator iter;
6000 
6001  RNA_parameter_list_begin(parms, &iter);
6002 
6003  for (; iter.valid; RNA_parameter_list_next(&iter)) {
6004  if (iter.parm == parm) {
6005  break;
6006  }
6007  }
6008 
6009  if (iter.valid) {
6010  if (parm->flag & PROP_DYNAMIC) {
6011  /* for dynamic arrays and strings, data is a pointer to an array */
6012  ParameterDynAlloc *data_alloc = iter.data;
6013  *value = data_alloc->array;
6014  }
6015  else {
6016  *value = iter.data;
6017  }
6018  }
6019  else {
6020  *value = NULL;
6021  }
6022 
6023  RNA_parameter_list_end(&iter);
6024 }
6025 
6026 void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **value)
6027 {
6028  PropertyRNA *parm;
6029 
6030  parm = parms->func->cont.properties.first;
6031  for (; parm; parm = parm->next) {
6032  if (STREQ(RNA_property_identifier(parm), identifier)) {
6033  break;
6034  }
6035  }
6036 
6037  if (parm) {
6038  RNA_parameter_get(parms, parm, value);
6039  }
6040 }
6041 
6042 void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
6043 {
6044  ParameterIterator iter;
6045 
6046  RNA_parameter_list_begin(parms, &iter);
6047 
6048  for (; iter.valid; RNA_parameter_list_next(&iter)) {
6049  if (iter.parm == parm) {
6050  break;
6051  }
6052  }
6053 
6054  if (iter.valid) {
6055  if (parm->flag & PROP_DYNAMIC) {
6056  /* for dynamic arrays and strings, data is a pointer to an array */
6057  ParameterDynAlloc *data_alloc = iter.data;
6058  size_t size = 0;
6059  switch (parm->type) {
6060  case PROP_STRING:
6061  size = sizeof(char);
6062  break;
6063  case PROP_INT:
6064  case PROP_BOOLEAN:
6065  size = sizeof(int);
6066  break;
6067  case PROP_FLOAT:
6068  size = sizeof(float);
6069  break;
6070  default:
6071  break;
6072  }
6073  size *= data_alloc->array_tot;
6074  if (data_alloc->array) {
6075  MEM_freeN(data_alloc->array);
6076  }
6077  data_alloc->array = MEM_mallocN(size, __func__);
6078  memcpy(data_alloc->array, value, size);
6079  }
6080  else {
6081  memcpy(iter.data, value, iter.size);
6082  }
6083  }
6084 
6085  RNA_parameter_list_end(&iter);
6086 }
6087 
6088 void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
6089 {
6090  PropertyRNA *parm;
6091 
6092  parm = parms->func->cont.properties.first;
6093  for (; parm; parm = parm->next) {
6094  if (STREQ(RNA_property_identifier(parm), identifier)) {
6095  break;
6096  }
6097  }
6098 
6099  if (parm) {
6100  RNA_parameter_set(parms, parm, value);
6101  }
6102 }
6103 
6105 {
6106  ParameterIterator iter;
6107  int len = 0;
6108 
6109  RNA_parameter_list_begin(parms, &iter);
6110 
6111  for (; iter.valid; RNA_parameter_list_next(&iter)) {
6112  if (iter.parm == parm) {
6113  break;
6114  }
6115  }
6116 
6117  if (iter.valid) {
6118  len = RNA_parameter_dynamic_length_get_data(parms, parm, iter.data);
6119  }
6120 
6121  RNA_parameter_list_end(&iter);
6122 
6123  return len;
6124 }
6125 
6127 {
6128  ParameterIterator iter;
6129 
6130  RNA_parameter_list_begin(parms, &iter);
6131 
6132  for (; iter.valid; RNA_parameter_list_next(&iter)) {
6133  if (iter.parm == parm) {
6134  break;
6135  }
6136  }
6137 
6138  if (iter.valid) {
6140  }
6141 
6142  RNA_parameter_list_end(&iter);
6143 }
6144 
6146  PropertyRNA *parm,
6147  void *data)
6148 {
6149  if (parm->flag & PROP_DYNAMIC) {
6150  return (int)((ParameterDynAlloc *)data)->array_tot;
6151  }
6152  return 0;
6153 }
6154 
6156  PropertyRNA *parm,
6157  void *data,
6158  int length)
6159 {
6160  if (parm->flag & PROP_DYNAMIC) {
6161  ((ParameterDynAlloc *)data)->array_tot = (intptr_t)length;
6162  }
6163 }
6164 
6166  bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
6167 {
6168  if (func->call) {
6169  func->call(C, reports, ptr, parms);
6170 
6171  return 0;
6172  }
6173 
6174  return -1;
6175 }
6176 
6178  ReportList *reports,
6179  PointerRNA *ptr,
6180  const char *identifier,
6181  ParameterList *parms)
6182 {
6183  FunctionRNA *func;
6184 
6185  func = RNA_struct_find_function(ptr->type, identifier);
6186 
6187  if (func) {
6188  return RNA_function_call(C, reports, ptr, func, parms);
6189  }
6190 
6191  return -1;
6192 }
6193 
6195  bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...)
6196 {
6197  va_list args;
6198  int ret;
6199 
6200  va_start(args, format);
6201 
6202  ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
6203 
6204  va_end(args);
6205 
6206  return ret;
6207 }
6208 
6210  ReportList *reports,
6211  PointerRNA *ptr,
6212  const char *identifier,
6213  const char *format,
6214  ...)
6215 {
6216  FunctionRNA *func;
6217 
6218  func = RNA_struct_find_function(ptr->type, identifier);
6219 
6220  if (func) {
6221  va_list args;
6222  int ret;
6223 
6224  va_start(args, format);
6225 
6226  ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
6227 
6228  va_end(args);
6229 
6230  return ret;
6231  }
6232 
6233  return -1;
6234 }
6235 
6236 static int rna_function_format_array_length(const char *format, int ofs, int flen)
6237 {
6238  char lenbuf[16];
6239  int idx = 0;
6240 
6241  if (format[ofs++] == '[') {
6242  for (; ofs < flen && format[ofs] != ']' && idx < sizeof(lenbuf) - 1; idx++, ofs++) {
6243  lenbuf[idx] = format[ofs];
6244  }
6245  }
6246 
6247  if (ofs < flen && format[ofs + 1] == ']') {
6248  /* XXX put better error reporting for (ofs >= flen) or idx over lenbuf capacity */
6249  lenbuf[idx] = '\0';
6250  return atoi(lenbuf);
6251  }
6252 
6253  return 0;
6254 }
6255 
6257  PropertyRNA *prop,
6259  char ftype,
6260  int len,
6261  void *dest,
6262  const void *src,
6263  StructRNA *srna,
6264  const char *tid,
6265  const char *fid,
6266  const char *pid)
6267 {
6268  /* ptr is always a function pointer, prop always a parameter */
6269 
6270  switch (type) {
6271  case PROP_BOOLEAN: {
6272  if (ftype != 'b') {
6273  fprintf(
6274  stderr, "%s.%s: wrong type for parameter %s, a boolean was expected\n", tid, fid, pid);
6275  return -1;
6276  }
6277 
6278  if (len == 0) {
6279  *((bool *)dest) = *((bool *)src);
6280  }
6281  else {
6282  memcpy(dest, src, len * sizeof(bool));
6283  }
6284 
6285  break;
6286  }
6287  case PROP_INT: {
6288  if (ftype != 'i') {
6289  fprintf(stderr,
6290  "%s.%s: wrong type for parameter %s, an integer was expected\n",
6291  tid,
6292  fid,
6293  pid);
6294  return -1;
6295  }
6296 
6297  if (len == 0) {
6298  *((int *)dest) = *((int *)src);
6299  }
6300  else {
6301  memcpy(dest, src, len * sizeof(int));
6302  }
6303 
6304  break;
6305  }
6306  case PROP_FLOAT: {
6307  if (ftype != 'f') {
6308  fprintf(
6309  stderr, "%s.%s: wrong type for parameter %s, a float was expected\n", tid, fid, pid);
6310  return -1;
6311  }
6312 
6313  if (len == 0) {
6314  *((float *)dest) = *((float *)src);
6315  }
6316  else {
6317  memcpy(dest, src, len * sizeof(float));
6318  }
6319 
6320  break;
6321  }
6322  case PROP_STRING: {
6323  if (ftype != 's') {
6324  fprintf(
6325  stderr, "%s.%s: wrong type for parameter %s, a string was expected\n", tid, fid, pid);
6326  return -1;
6327  }
6328 
6329  *((char **)dest) = *((char **)src);
6330 
6331  break;
6332  }
6333  case PROP_ENUM: {
6334  if (ftype != 'e') {
6335  fprintf(
6336  stderr, "%s.%s: wrong type for parameter %s, an enum was expected\n", tid, fid, pid);
6337  return -1;
6338  }
6339 
6340  *((int *)dest) = *((int *)src);
6341 
6342  break;
6343  }
6344  case PROP_POINTER: {
6345  StructRNA *ptype;
6346 
6347  if (ftype != 'O') {
6348  fprintf(
6349  stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid);
6350  return -1;
6351  }
6352 
6353  ptype = RNA_property_pointer_type(ptr, prop);
6354 
6355  if (prop->flag_parameter & PARM_RNAPTR) {
6356  *((PointerRNA *)dest) = *((PointerRNA *)src);
6357  break;
6358  }
6359 
6360  if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
6361  fprintf(stderr,
6362  "%s.%s: wrong type for parameter %s, "
6363  "an object of type %s was expected, passed an object of type %s\n",
6364  tid,
6365  fid,
6366  pid,
6367  RNA_struct_identifier(ptype),
6368  RNA_struct_identifier(srna));
6369  return -1;
6370  }
6371 
6372  *((void **)dest) = *((void **)src);
6373 
6374  break;
6375  }
6376  case PROP_COLLECTION: {
6377  StructRNA *ptype;
6378  ListBase *lb, *clb;
6379  Link *link;
6380  CollectionPointerLink *clink;
6381 
6382  if (ftype != 'C') {
6383  fprintf(stderr,
6384  "%s.%s: wrong type for parameter %s, a collection was expected\n",
6385  tid,
6386  fid,
6387  pid);
6388  return -1;
6389  }
6390 
6391  lb = (ListBase *)src;
6392  clb = (ListBase *)dest;
6393  ptype = RNA_property_pointer_type(ptr, prop);
6394 
6395  if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
6396  fprintf(stderr,
6397  "%s.%s: wrong type for parameter %s, "
6398  "a collection of objects of type %s was expected, "
6399  "passed a collection of objects of type %s\n",
6400  tid,
6401  fid,
6402  pid,
6403  RNA_struct_identifier(ptype),
6404  RNA_struct_identifier(srna));
6405  return -1;
6406  }
6407 
6408  for (link = lb->first; link; link = link->next) {
6409  clink = MEM_callocN(sizeof(CollectionPointerLink), "CCollectionPointerLink");
6410  RNA_pointer_create(NULL, srna, link, &clink->ptr);
6411  BLI_addtail(clb, clink);
6412  }
6413 
6414  break;
6415  }
6416  default: {
6417  if (len == 0) {
6418  fprintf(stderr, "%s.%s: unknown type for parameter %s\n", tid, fid, pid);
6419  }
6420  else {
6421  fprintf(stderr, "%s.%s: unknown array type for parameter %s\n", tid, fid, pid);
6422  }
6423 
6424  return -1;
6425  }
6426  }
6427 
6428  return 0;
6429 }
6430 
6432  ReportList *reports,
6433  PointerRNA *ptr,
6434  FunctionRNA *func,
6435  const char *format,
6436  va_list args)
6437 {
6438  PointerRNA funcptr;
6439  ParameterList parms;
6440  ParameterIterator iter;
6441  PropertyRNA *pret, *parm;
6443  int i, ofs, flen, flag_parameter, len, alen, err = 0;
6444  const char *tid, *fid, *pid = NULL;
6445  char ftype;
6446  void **retdata = NULL;
6447 
6448  RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
6449 
6450  tid = RNA_struct_identifier(ptr->type);
6451  fid = RNA_function_identifier(func);
6452  pret = func->c_ret;
6453  flen = strlen(format);
6454 
6455  RNA_parameter_list_create(&parms, ptr, func);
6456  RNA_parameter_list_begin(&parms, &iter);
6457 
6458  for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
6459  parm = iter.parm;
6460  flag_parameter = RNA_parameter_flag(parm);
6461 
6462  if (parm == pret) {
6463  retdata = iter.data;
6464  continue;
6465  }
6466  if (flag_parameter & PARM_OUTPUT) {
6467  continue;
6468  }
6469 
6470  pid = RNA_property_identifier(parm);
6471 
6472  if (ofs >= flen || format[ofs] == 'N') {
6473  if (parm->flag_parameter & PARM_REQUIRED) {
6474  err = -1;
6475  fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid);
6476  break;
6477  }
6478  ofs++;
6479  continue;
6480  }
6481 
6482  type = RNA_property_type(parm);
6483  ftype = format[ofs++];
6484  len = RNA_property_array_length(&funcptr, parm);
6485  alen = rna_function_format_array_length(format, ofs, flen);
6486 
6487  if (len != alen) {
6488  err = -1;
6489  fprintf(stderr,
6490  "%s.%s: for parameter %s, "
6491  "was expecting an array of %i elements, "
6492  "passed %i elements instead\n",
6493  tid,
6494  fid,
6495  pid,
6496  len,
6497  alen);
6498  break;
6499  }
6500 
6501  switch (type) {
6502  case PROP_BOOLEAN:
6503  case PROP_INT:
6504  case PROP_ENUM: {
6505  int arg = va_arg(args, int);
6507  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
6508  break;
6509  }
6510  case PROP_FLOAT: {
6511  double arg = va_arg(args, double);
6513  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
6514  break;
6515  }
6516  case PROP_STRING: {
6517  const char *arg = va_arg(args, char *);
6519  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
6520  break;
6521  }
6522  case PROP_POINTER: {
6523  StructRNA *srna = va_arg(args, StructRNA *);
6524  void *arg = va_arg(args, void *);
6526  &funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
6527  break;
6528  }
6529  case PROP_COLLECTION: {
6530  StructRNA *srna = va_arg(args, StructRNA *);
6531  ListBase *arg = va_arg(args, ListBase *);
6533  &funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
6534  break;
6535  }
6536  default: {
6537  /* handle errors */
6539  &funcptr, parm, type, ftype, len, iter.data, NULL, NULL, tid, fid, pid);
6540  break;
6541  }
6542  }
6543 
6544  if (err != 0) {
6545  break;
6546  }
6547  }
6548 
6549  if (err == 0) {
6550  err = RNA_function_call(C, reports, ptr, func, &parms);
6551  }
6552 
6553  /* XXX throw error when more parameters than those needed are passed or leave silent? */
6554  if (err == 0 && pret && ofs < flen && format[ofs++] == 'R') {
6555  parm = pret;
6556 
6557  type = RNA_property_type(parm);
6558  ftype = format[ofs++];
6559  len = RNA_property_array_length(&funcptr, parm);
6560  alen = rna_function_format_array_length(format, ofs, flen);
6561 
6562  if (len != alen) {
6563  err = -1;
6564  fprintf(stderr,
6565  "%s.%s: for return parameter %s, "
6566  "was expecting an array of %i elements, passed %i elements instead\n",
6567  tid,
6568  fid,
6569  pid,
6570  len,
6571  alen);
6572  }
6573  else {
6574  switch (type) {
6575  case PROP_BOOLEAN:
6576  case PROP_INT:
6577  case PROP_ENUM: {
6578  int *arg = va_arg(args, int *);
6580  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
6581  break;
6582  }
6583  case PROP_FLOAT: {
6584  float *arg = va_arg(args, float *);
6586  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
6587  break;
6588  }
6589  case PROP_STRING: {
6590  char **arg = va_arg(args, char **);
6592  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
6593  break;
6594  }
6595  case PROP_POINTER: {
6596  StructRNA *srna = va_arg(args, StructRNA *);
6597  void **arg = va_arg(args, void **);
6599  &funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
6600  break;
6601  }
6602  case PROP_COLLECTION: {
6603  StructRNA *srna = va_arg(args, StructRNA *);
6604  ListBase **arg = va_arg(args, ListBase **);
6606  &funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
6607  break;
6608  }
6609  default: {
6610  /* handle errors */
6612  &funcptr, parm, type, ftype, len, NULL, NULL, NULL, tid, fid, pid);
6613  break;
6614  }
6615  }
6616  }
6617  }
6618 
6619  RNA_parameter_list_end(&iter);
6620  RNA_parameter_list_free(&parms);
6621 
6622  return err;
6623 }
6624 
6626  ReportList *reports,
6627  PointerRNA *ptr,
6628  const char *identifier,
6629  const char *format,
6630  va_list args)
6631 {
6632  FunctionRNA *func;
6633 
6634  func = RNA_struct_find_function(ptr->type, identifier);
6635 
6636  if (func) {
6637  return RNA_function_call_direct_va(C, reports, ptr, func, format, args);
6638  }
6639 
6640  return 0;
6641 }
6642 
6644  const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
6645 {
6646  return rna_translate_ui_text(text, text_ctxt, type, prop, translate);
6647 }
6648 
6650 {
6651  int len;
6652 
6653  /* get the length of the array to work with */
6655 
6656  /* get and set the default values as appropriate for the various types */
6657  switch (RNA_property_type(prop)) {
6658  case PROP_BOOLEAN:
6659  if (len) {
6660  if (index == -1) {
6661  bool *tmparray = MEM_callocN(sizeof(bool) * len, "reset_defaults - boolean");
6662 
6664  RNA_property_boolean_set_array(ptr, prop, tmparray);
6665 
6666  MEM_freeN(tmparray);
6667  }
6668  else {
6669  int value = RNA_property_boolean_get_default_index(ptr, prop, index);
6670  RNA_property_boolean_set_index(ptr, prop, index, value);
6671  }
6672  }
6673  else {
6674  int value = RNA_property_boolean_get_default(ptr, prop);
6675  RNA_property_boolean_set(ptr, prop, value);
6676  }
6677  return true;
6678  case PROP_INT:
6679  if (len) {
6680  if (index == -1) {
6681  int *tmparray = MEM_callocN(sizeof(int) * len, "reset_defaults - int");
6682 
6683  RNA_property_int_get_default_array(ptr, prop, tmparray);
6684  RNA_property_int_set_array(ptr, prop, tmparray);
6685 
6686  MEM_freeN(tmparray);
6687  }
6688  else {
6689  int value = RNA_property_int_get_default_index(ptr, prop, index);
6690  RNA_property_int_set_index(ptr, prop, index, value);
6691  }
6692  }
6693  else {
6694  int value = RNA_property_int_get_default(ptr, prop);
6695  RNA_property_int_set(ptr, prop, value);
6696  }
6697  return true;
6698  case PROP_FLOAT:
6699  if (len) {
6700  if (index == -1) {
6701  float *tmparray = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
6702 
6703  RNA_property_float_get_default_array(ptr, prop, tmparray);
6704  RNA_property_float_set_array(ptr, prop, tmparray);
6705 
6706  MEM_freeN(tmparray);
6707  }
6708  else {
6709  float value = RNA_property_float_get_default_index(ptr, prop, index);
6710  RNA_property_float_set_index(ptr, prop, index, value);
6711  }
6712  }
6713  else {
6714  float value = RNA_property_float_get_default(ptr, prop);
6715  RNA_property_float_set(ptr, prop, value);
6716  }
6717  return true;
6718  case PROP_ENUM: {
6719  int value = RNA_property_enum_get_default(ptr, prop);
6720  RNA_property_enum_set(ptr, prop, value);
6721  return true;
6722  }
6723 
6724  case PROP_STRING: {
6725  char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0, NULL);
6726  RNA_property_string_set(ptr, prop, value);
6727  MEM_freeN(value);
6728  return true;
6729  }
6730 
6731  case PROP_POINTER: {
6733  RNA_property_pointer_set(ptr, prop, value, NULL);
6734  return true;
6735  }
6736 
6737  default:
6738  /* FIXME: are there still any cases that haven't been handled?
6739  * comment out "default" block to check :) */
6740  return false;
6741  }
6742 }
6743 
6745 {
6746  if (!RNA_property_is_idprop(prop) || RNA_property_array_check(prop)) {
6747  return false;
6748  }
6749 
6750  /* get and set the default values as appropriate for the various types */
6751  switch (RNA_property_type(prop)) {
6752  case PROP_INT: {
6753  int value = RNA_property_int_get(ptr, prop);
6754  return RNA_property_int_set_default(prop, value);
6755  }
6756 
6757  case PROP_FLOAT: {
6758  float value = RNA_property_float_get(ptr, prop);
6759  return RNA_property_float_set_default(prop, value);
6760  }
6761 
6762  default:
6763  return false;
6764  }
6765 }
6766 
6767 void _RNA_warning(const char *format, ...)
6768 {
6769  va_list args;
6770 
6771  va_start(args, format);
6772  vprintf(format, args);
6773  va_end(args);
6774 
6775  /* gcc macro adds '\n', but can't use for other compilers */
6776 #ifndef __GNUC__
6777  fputc('\n', stdout);
6778 #endif
6779 
6780 #ifdef WITH_PYTHON
6781  {
6782  extern void PyC_LineSpit(void);
6783  PyC_LineSpit();
6784  }
6785 #endif
6786 }
6787 
6789  struct PropertyRNA *prop,
6790  const int prop_index,
6791  PathResolvedRNA *r_anim_rna)
6792 {
6793  int array_len = RNA_property_array_length(ptr, prop);
6794 
6795  if ((array_len == 0) || (prop_index < array_len)) {
6796  r_anim_rna->ptr = *ptr;
6797  r_anim_rna->prop = prop;
6798  r_anim_rna->prop_index = array_len ? prop_index : -1;
6799 
6800  return true;
6801  }
6802  return false;
6803 }
6804 
6805 static char rna_struct_state_owner[64];
6806 void RNA_struct_state_owner_set(const char *name)
6807 {
6808  if (name) {
6810  }
6811  else {
6812  rna_struct_state_owner[0] = '\0';
6813  }
6814 }
6815 
6817 {
6818  if (rna_struct_state_owner[0]) {
6819  return rna_struct_state_owner;
6820  }
6821  return NULL;
6822 }
typedef float(TangentPoint)[2]
bool id_can_have_animdata(const struct ID *id)
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:770
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct FCurve * BKE_fcurve_find_by_rna(struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, struct AnimData **r_adt, struct bAction **r_action, bool *r_driven, bool *r_special)
Definition: fcurve.c:380
#define G_MAIN
Definition: BKE_global.h:267
#define IDP_Float(prop)
Definition: BKE_idprop.h:269
#define IDP_IDPArray(prop)
Definition: BKE_idprop.h:272
void IDP_AssignID(struct IDProperty *prop, struct ID *id, int flag)
Definition: idprop.c:452
#define IDP_Int(prop)
Definition: BKE_idprop.h:244
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item)
Definition: idprop.c:133
struct IDPropertyUIData * IDP_ui_data_ensure(struct IDProperty *prop)
Definition: idprop.c:1519
#define IDP_Id(prop)
Definition: BKE_idprop.h:273
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:578
struct IDProperty * IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:126
struct IDProperty * IDP_New(char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:887
struct IDProperty * IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:63
void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist)
Definition: idprop.c:563
struct IDProperty * IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition: idprop.c:339
#define IDP_String(prop)
Definition: BKE_idprop.h:271
void IDP_ResizeIDPArray(struct IDProperty *prop, int len)
Definition: idprop.c:141
#define IDP_Double(prop)
Definition: BKE_idprop.h:270
void IDP_ResizeArray(struct IDProperty *prop, int newlen)
Definition: idprop.c:211
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:631
struct IDProperty * IDP_GetPropertyFromGroup(const struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL()
Definition: idprop.c:383
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:666
#define IDP_Array(prop)
Definition: BKE_idprop.h:245
bool BKE_lib_override_library_is_system_defined(const struct Main *bmain, const struct ID *id)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:256
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:281
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:75
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
void * BLI_findstring_ptr(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
MINLINE int mod_i(int i, int n)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL()
Definition: string.c:250
unsigned int uint
Definition: BLI_sys_types.h:67
#define BLI_MUTEX_INITIALIZER
Definition: BLI_threads.h:83
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
#define UNUSED_VARS(...)
#define UNUSED(x)
#define MAX2(a, b)
#define UNLIKELY(x)
#define ELEM(...)
#define MIN2(a, b)
#define STREQ(a, b)
bool BLT_translate_iface(void)
bool BLT_translate_tooltips(void)
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
const char * BLT_pgettext(const char *msgctxt, const char *msgid)
typedef double(DMatrix)[4][4]
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
ID and Library types, which are fundamental for sdna.
@ IDP_STRING_SUB_BYTE
Definition: DNA_ID.h:165
#define ID_TYPE_IS_COW(_id_type)
Definition: DNA_ID.h:601
@ IDP_DOUBLE
Definition: DNA_ID.h:143
@ IDP_FLOAT
Definition: DNA_ID.h:138
@ IDP_STRING
Definition: DNA_ID.h:136
@ IDP_IDPARRAY
Definition: DNA_ID.h:144
@ IDP_INT
Definition: DNA_ID.h:137
@ IDP_GROUP
Definition: DNA_ID.h:141
@ IDP_ARRAY
Definition: DNA_ID.h:140
@ IDP_ID
Definition: DNA_ID.h:142
@ ID_RECALC_PARAMETERS
Definition: DNA_ID.h:854
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ IDP_FLAG_GHOST
Definition: DNA_ID.h:181
@ IDP_FLAG_OVERRIDELIBRARY_LOCAL
Definition: DNA_ID.h:177
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
#define IDP_NUMTYPES
Definition: DNA_ID.h:146
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
@ ID_NT
Definition: DNA_ID_enums.h:68
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
#define RNA_PROP_END
Definition: RNA_access.h:563
#define RNA_STRUCT_BEGIN(sptr, prop)
Definition: RNA_access.h:569
#define RNA_STRUCT_END
Definition: RNA_access.h:589
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
Definition: RNA_access.h:556
#define RNA_MAX_ARRAY_LENGTH
Definition: RNA_define.h:25
#define RNA_MAX_ARRAY_DIMENSION
Definition: RNA_define.h:28
@ PARM_RNAPTR
Definition: RNA_types.h:354
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ PARM_OUTPUT
Definition: RNA_types.h:353
struct StructRNA *(* StructRegisterFunc)(struct Main *bmain, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
Definition: RNA_types.h:738
PropertyScaleType
Definition: RNA_types.h:96
@ PROP_SCALE_LINEAR
Definition: RNA_types.h:98
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:662
@ STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID
Definition: RNA_types.h:729
@ STRUCT_PUBLIC_NAMESPACE
Definition: RNA_types.h:721
@ STRUCT_ID
Definition: RNA_types.h:705
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition: RNA_types.h:717
@ STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES
Definition: RNA_types.h:719
@ STRUCT_NO_IDPROPERTIES
Definition: RNA_types.h:715
@ STRUCT_UNDO
Definition: RNA_types.h:708
eStringPropertySearchFlag
Definition: RNA_types.h:547
@ PROP_STRING_SEARCH_SUPPORTED
Definition: RNA_types.h:552
void(* StringPropertySearchVisitFunc)(void *visit_user_data, const StringPropertySearchVisitParams *params)
Definition: RNA_types.h:568
PropertyType
Definition: RNA_types.h:58
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_INT
Definition: RNA_types.h:60
@ PROP_STRING
Definition: RNA_types.h:62
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROP_COLLECTION
Definition: RNA_types.h:65
PropertyUnit
Definition: RNA_types.h:69
struct EnumPropertyItem EnumPropertyItem
#define RNA_SUBTYPE_UNIT(subtype)
Definition: RNA_types.h:111
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition: RNA_types.h:337
void(* StructUnregisterFunc)(struct Main *bmain, struct StructRNA *type)
Definition: RNA_types.h:746
RawPropertyType
Definition: RNA_types.h:431
@ PROP_RAW_INT
Definition: RNA_types.h:433
@ PROP_RAW_UNSET
Definition: RNA_types.h:432
@ PROP_RAW_BOOLEAN
Definition: RNA_types.h:436
@ PROP_RAW_CHAR
Definition: RNA_types.h:435
@ PROP_RAW_FLOAT
Definition: RNA_types.h:438
@ PROP_RAW_DOUBLE
Definition: RNA_types.h:437
@ PROP_RAW_SHORT
Definition: RNA_types.h:434
@ PROP_DYNAMIC
Definition: RNA_types.h:290
@ PROP_CONTEXT_UPDATE
Definition: RNA_types.h:269
@ PROP_ANIMATABLE
Definition: RNA_types.h:202
@ PROP_NEVER_UNLINK
Definition: RNA_types.h:246
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_ENUM_FLAG
Definition: RNA_types.h:266
@ PROP_LIB_EXCEPTION
Definition: RNA_types.h:195
@ PROP_CONTEXT_PROPERTY_UPDATE
Definition: RNA_types.h:270
@ PROP_ENUM_NO_CONTEXT
Definition: RNA_types.h:292
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_NO_DEG_UPDATE
Definition: RNA_types.h:301
@ PROP_ENUM_NO_TRANSLATE
Definition: RNA_types.h:294
@ PROP_REGISTER
Definition: RNA_types.h:273
@ PROP_ID_SELF_CHECK
Definition: RNA_types.h:232
@ PROP_IDPROPERTY
Definition: RNA_types.h:288
int(* IteratorSkipFunc)(struct CollectionPropertyIterator *iter, void *data)
Definition: RNA_types.h:367
PropertySubType
Definition: RNA_types.h:125
@ PROP_DIRECTION
Definition: RNA_types.h:155
@ PROP_XYZ
Definition: RNA_types.h:162
@ PROP_ACCELERATION
Definition: RNA_types.h:157
@ PROP_BYTESTRING
Definition: RNA_types.h:133
@ PROP_COLOR
Definition: RNA_types.h:153
@ PROP_AXISANGLE
Definition: RNA_types.h:161
@ PROP_EULER
Definition: RNA_types.h:159
@ PROP_COORDS
Definition: RNA_types.h:167
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:165
@ PROP_TRANSLATION
Definition: RNA_types.h:154
@ PROP_XYZ_LENGTH
Definition: RNA_types.h:163
@ PROP_QUATERNION
Definition: RNA_types.h:160
@ PROP_VELOCITY
Definition: RNA_types.h:156
#define C
Definition: RandGen.cpp:25
#define ND_SHADING
Definition: WM_types.h:425
#define NC_WINDOW
Definition: WM_types.h:325
#define NC_MATERIAL
Definition: WM_types.h:330
volatile int lock
int main(int argc, char *argv[])
return(oflags[bm->toolflag_index].f &oflag) !=0
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
Scene scene
SyclQueue void void * src
SyclQueue void * dest
int len
Definition: draw_manager.c:108
uint pos
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define GS(x)
Definition: iris.c:225
ccl_gpu_kernel_postfix ccl_global int * counter
format
Definition: logImageCore.h:38
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
T length(const vec_base< T, Size > &a)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void PyC_LineSpit(void)
return ret
StructUnregisterFunc RNA_struct_unregister(StructRNA *type)
Definition: rna_access.c:863
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2767
bool RNA_property_collection_lookup_int_has_fn(PropertyRNA *prop)
Definition: rna_access.c:4083
void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
Definition: rna_access.c:4898
bool RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
Definition: rna_access.c:1639
StructRegisterFunc RNA_struct_register(StructRNA *type)
Definition: rna_access.c:858
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format,...)
Definition: rna_access.c:6209
bool RNA_property_enum_item_from_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
Definition: rna_access.c:1814
const char * RNA_struct_identifier(const StructRNA *type)
Definition: rna_access.c:586
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3095
bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1966
int RNA_enum_bitflag_identifiers(const EnumPropertyItem *item, const int value, const char **r_identifier)
Definition: rna_access.c:1678
static void rna_property_float_fill_default_array_values_double(const double *default_array, const int default_array_len, const double default_value, const int out_length, float *r_values)
Definition: rna_access.c:2851
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
Definition: rna_access.c:4945
const char * RNA_function_identifier(FunctionRNA *func)
Definition: rna_access.c:5768
void RNA_property_string_search(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, StringPropertySearchVisitFunc visit_fn, void *visit_user_data)
Definition: rna_access.c:3390
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
Definition: rna_access.c:2352
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:2449
IDProperty ** RNA_struct_idprops_p(PointerRNA *ptr)
Definition: rna_access.c:238
FunctionRNA * RNA_struct_find_function(StructRNA *srna, const char *identifier)
Definition: rna_access.c:817
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
Definition: rna_access.c:1227
const char * RNA_property_description(PropertyRNA *prop)
Definition: rna_access.c:1005
bool RNA_property_update_check(PropertyRNA *prop)
Definition: rna_access.c:2132
bool RNA_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:1080
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:695
int RNA_property_collection_lookup_string_index(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
Definition: rna_access.c:4130
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args)
Definition: rna_access.c:6431
bool RNA_property_is_unlink(PropertyRNA *prop)
Definition: rna_access.c:5327
void rna_property_rna_or_id_get(PropertyRNA *prop, PointerRNA *ptr, PropertyRNAOrID *r_prop_rna_or_id)
Definition: rna_access.c:431
const struct ListBase * RNA_struct_type_properties(StructRNA *srna)
Definition: rna_access.c:796
static void rna_property_int_fill_default_array_values(const int *defarr, int defarr_length, int defvalue, int out_length, int *r_values)
Definition: rna_access.c:2485
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:2879
bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6744
PropertyRNA * rna_ensure_property(PropertyRNA *prop)
Definition: rna_access.c:524
int RNA_function_call_direct_va_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format, va_list args)
Definition: rna_access.c:6625
PropertyScaleType RNA_property_ui_scale(PropertyRNA *prop)
Definition: rna_access.c:1037
void RNA_struct_state_owner_set(const char *name)
Definition: rna_access.c:6806
bool RNA_property_int_set_default(PropertyRNA *prop, int value)
Definition: rna_access.c:2693
void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
Definition: rna_access.c:892
void rna_iterator_array_end(CollectionPropertyIterator *iter)
Definition: rna_access.c:4844
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Definition: rna_access.c:4933
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2030
bool RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2405
IDProperty * rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
Definition: rna_access.c:502
static void rna_property_int_get_default_array_values(PointerRNA *ptr, IntPropertyRNA *iprop, int *r_values)
Definition: rna_access.c:2501
bool RNA_property_float_set_default(PropertyRNA *prop, float value)
Definition: rna_access.c:3081
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:5155
static void rna_property_float_get_default_array_values(PointerRNA *ptr, FloatPropertyRNA *fprop, float *r_values)
Definition: rna_access.c:2868
static void rna_idproperty_free(PointerRNA *ptr, const char *name)
Definition: rna_access.c:290
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5167
void RNA_init(void)
Definition: rna_access.c:65
int RNA_collection_length(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5239
int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
Definition: rna_access.c:1725
int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
Definition: rna_access.c:1382
int RNA_parameter_dynamic_length_get_data(ParameterList *UNUSED(parms), PropertyRNA *parm, void *data)
Definition: rna_access.c:6145
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
Definition: rna_access.c:1365
void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **value)
Definition: rna_access.c:6026
void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
Definition: rna_access.c:5179
char * RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
Definition: rna_access.c:5615
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:112
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
Definition: rna_access.c:4886
bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
Definition: rna_access.c:918
bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
Definition: rna_access.c:5045
void ** RNA_struct_instance(PointerRNA *ptr)
Definition: rna_access.c:874
void RNA_property_string_get_default(PropertyRNA *prop, char *value, const int max_len)
Definition: rna_access.c:3304
bool RNA_struct_is_ID(const StructRNA *type)
Definition: rna_access.c:655
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2581
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1000
const char * RNA_property_ui_description_raw(const PropertyRNA *prop)
Definition: rna_access.c:1890
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
Definition: rna_access.c:1311
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
Definition: rna_access.c:3036
static void rna_array_as_string_recursive(int type, void **buf_p, int totdim, const int *dim_size, DynStr *dynstr)
Definition: rna_access.c:5580
PropertyRNA * rna_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
Definition: rna_access.c:742
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
Definition: rna_access.c:5076
char * RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length)
Definition: rna_access.c:5477
static void rna_property_boolean_get_default_array_values(PointerRNA *ptr, BoolPropertyRNA *bprop, bool *r_values)
Definition: rna_access.c:2231
eStringPropertySearchFlag RNA_property_string_search_flag(PropertyRNA *prop)
Definition: rna_access.c:3374
bool RNA_property_collection_is_empty(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3787
bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1993
PropertyUnit RNA_property_unit(PropertyRNA *prop)
Definition: rna_access.c:1032
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
Definition: rna_access.c:902
int RNA_function_defined(FunctionRNA *func)
Definition: rna_access.c:5788
int RNA_property_ui_icon(const PropertyRNA *prop)
Definition: rna_access.c:1900
ParameterList * RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func)
Definition: rna_access.c:5826
int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, const PointerRNA *t_ptr)
Definition: rna_access.c:4059
void RNA_collection_clear(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5227
bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:6649
void RNA_parameter_dynamic_length_set(ParameterList *parms, PropertyRNA *parm, int length)
Definition: rna_access.c:6126
int RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
Definition: rna_access.c:4193
static const char * rna_ensure_property_name(const PropertyRNA *prop)
Definition: rna_access.c:565
const char * RNA_struct_ui_description(const StructRNA *type)
Definition: rna_access.c:609
void RNA_blender_rna_pointer_create(PointerRNA *r_ptr)
Definition: rna_access.c:179
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:907
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5250
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2954
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
Definition: rna_access.c:3532
void _RNA_warning(const char *format,...)
Definition: rna_access.c:6767
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:4874
void RNA_parameter_dynamic_length_set_data(ParameterList *UNUSED(parms), PropertyRNA *parm, void *data, int length)
Definition: rna_access.c:6155
void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num)
Definition: rna_access.c:3725
#define RAW_GET(dtype, var, raw, a)
Definition: rna_access.c:4261
float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:3125
void RNA_pointer_add(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5191
int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
Definition: rna_access.c:1714
int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *array, RawPropertyType type, int len)
Definition: rna_access.c:4705
bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
Definition: rna_access.c:5261
static void * rna_array_as_string_alloc(int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
Definition: rna_access.c:5516
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
Definition: rna_access.c:6042
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
Definition: rna_access.c:5289
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
Definition: rna_access.c:1856
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5271
const char * RNA_struct_ui_name(const StructRNA *type)
Definition: rna_access.c:591
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
Definition: rna_access.c:3675
bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
Definition: rna_access.c:5096
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
Definition: rna_access.c:1274
void rna_iterator_listbase_end(CollectionPropertyIterator *UNUSED(iter))
Definition: rna_access.c:4768
PropertyRNA * RNA_struct_type_find_property_no_base(StructRNA *srna, const char *identifier)
Definition: rna_access.c:801
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2242
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1010
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:61
const char * RNA_function_ui_description_raw(FunctionRNA *func)
Definition: rna_access.c:5778
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3617
static PropertyRNA * arraytypemap[IDP_NUMTYPES]
Definition: rna_access.c:419
PropertyRNA * rna_ensure_property_realdata(PropertyRNA **prop, PointerRNA *ptr)
Definition: rna_access.c:512
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:4921
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3421
void * RNA_struct_blender_type_get(StructRNA *srna)
Definition: rna_access.c:897
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3493
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
Definition: rna_access.c:4097
char RNA_property_array_item_char(PropertyRNA *prop, int index)
Definition: rna_access.c:1105
int RNA_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
Definition: rna_access.c:3460
void RNA_parameter_list_free(ParameterList *parms)
Definition: rna_access.c:5922
bool RNA_property_enum_name_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
Definition: rna_access.c:1796
bool RNA_struct_contains_property(PointerRNA *ptr, PropertyRNA *prop_test)
Definition: rna_access.c:758
bool RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2379
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:4980
void rna_idproperty_touch(IDProperty *idprop)
Definition: rna_access.c:232
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2138
static char * rna_pointer_as_string__bldata(Main *bmain, PointerRNA *ptr)
Definition: rna_access.c:5371
static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, PropertyType type, char ftype, int len, void *dest, const void *src, StructRNA *srna, const char *tid, const char *fid, const char *pid)
Definition: rna_access.c:6256
unsigned int RNA_struct_count_properties(StructRNA *srna)
Definition: rna_access.c:780
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
Definition: rna_access.c:4729
int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2743
char * RNA_pointer_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop)
Definition: rna_access.c:5382
PointerRNA rna_array_lookup_int(PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
Definition: rna_access.c:4851
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2153
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:3178
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
Definition: rna_access.c:2917
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2390
bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
Definition: rna_access.c:675
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
Definition: rna_access.c:2652
static const char * rna_ensure_property_description(const PropertyRNA *prop)
Definition: rna_access.c:550
static const char * bool_as_py_string(const int var)
Definition: rna_access.c:5511
unsigned int RNA_enum_items_count(const EnumPropertyItem *item)
Definition: rna_access.c:1747
static int rna_property_array_length_all_dimensions(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:4335
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
Definition: rna_access.c:1560
bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
Definition: rna_access.c:5086
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, bool free_ptr, IteratorSkipFunc skip)
Definition: rna_access.c:4781
void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr)
Definition: rna_access.c:207
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2429
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3451
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
Definition: rna_access.c:251
void RNA_property_collection_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:3709
static void rna_array_as_string(int type, int len, PointerRNA *ptr, PropertyRNA *prop, DynStr *dynstr)
Definition: rna_access.c:5600
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index)
Definition: rna_access.c:4772
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
Definition: rna_access.c:5215
void RNA_parameter_list_next(ParameterIterator *iter)
Definition: rna_access.c:5980
static char rna_struct_state_owner[64]
Definition: rna_access.c:6805
void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
Definition: rna_access.c:5027
const char * RNA_property_translation_context(const PropertyRNA *prop)
Definition: rna_access.c:1895
bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1976
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
Definition: rna_access.c:4184
const char * RNA_struct_ui_name_raw(const StructRNA *type)
Definition: rna_access.c:596
static bool rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop)
Definition: rna_access.c:351
static const char * rna_ensure_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:542
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:5116
static void rna_property_float_fill_default_array_values(const float *defarr, int defarr_length, float defvalue, int out_length, float *r_values)
Definition: rna_access.c:2832
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4910
static void rna_ensure_property_multi_array_length(const PointerRNA *ptr, PropertyRNA *prop, int length[])
Definition: rna_access.c:327
PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
Definition: rna_access.c:3608
int RNA_property_array_dimension(const PointerRNA *ptr, PropertyRNA *prop, int length[])
Definition: rna_access.c:1085
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
Definition: rna_access.c:5106
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:806
void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **value)
Definition: rna_access.c:5997
StructRNA * RNA_struct_find(const char *identifier)
Definition: rna_access.c:581
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
Definition: rna_access.c:3149
void RNA_parameter_list_end(ParameterIterator *UNUSED(iter))
Definition: rna_access.c:5992
int RNA_function_flag(FunctionRNA *func)
Definition: rna_access.c:5783
PropertyRNA * RNA_function_get_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, int index)
Definition: rna_access.c:5793
bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
Definition: rna_access.c:1971
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1405
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2143
void * rna_iterator_array_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4829
bool RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value)
Definition: rna_access.c:1431
int RNA_property_flag(PropertyRNA *prop)
Definition: rna_access.c:1055
RawPropertyType RNA_property_raw_type(PropertyRNA *prop)
Definition: rna_access.c:4684
int RNA_struct_ui_icon(const StructRNA *type)
Definition: rna_access.c:601
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2180
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
bool RNA_property_builtin(PropertyRNA *prop)
Definition: rna_access.c:1065
int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3352
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
Definition: rna_access.c:2544
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:4745
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
Definition: rna_access.c:1759
static void rna_array_as_string_elem(int type, void **buf_p, int len, DynStr *dynstr)
Definition: rna_access.c:5545
int RNA_parameter_list_arg_count(const ParameterList *parms)
Definition: rna_access.c:5954
bool RNA_struct_idprops_register_check(const StructRNA *type)
Definition: rna_access.c:665
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
Definition: rna_access.c:6088
void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
Definition: rna_access.c:3268
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
Definition: rna_access.c:4968
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2678
int RNA_string_length(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5144
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:186
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:5129
static PropertyRNA * typemap[IDP_NUMTYPES]
Definition: rna_access.c:406
const EnumPropertyItem * RNA_struct_property_tag_defines(const StructRNA *type)
Definition: rna_access.c:629
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
Definition: rna_access.c:624
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
Definition: rna_access.c:4218
bool RNA_property_enum_item_from_value_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
Definition: rna_access.c:1842
bool RNA_struct_undo_check(const StructRNA *type)
Definition: rna_access.c:660
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
Definition: rna_access.c:5203
void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5313
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
Definition: rna_access.c:3835
bool RNA_pointer_is_null(const PointerRNA *ptr)
Definition: rna_access.c:164
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1075
bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **r_description)
Definition: rna_access.c:1702
static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:302
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1692
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms)
Definition: rna_access.c:6177
bool RNA_property_is_idprop(const PropertyRNA *prop)
Definition: rna_access.c:5322
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2050
int RNA_property_string_maxlength(PropertyRNA *prop)
Definition: rna_access.c:1399
void RNA_property_enum_items_gettexted_all(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
Definition: rna_access.c:1576
bool RNA_struct_idprops_datablock_allowed(const StructRNA *type)
Definition: rna_access.c:670
const ListBase * RNA_function_defined_parameters(FunctionRNA *func)
Definition: rna_access.c:5814
void RNA_exit(void)
Definition: rna_access.c:89
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:2978
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
Definition: rna_access.c:2605
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2707
static bool property_collection_liboverride_editable(PointerRNA *ptr, PropertyRNA *prop, bool *r_is_liboverride)
Definition: rna_access.c:3800
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3402
void rna_iterator_array_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:4813
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
Definition: rna_access.c:2790
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2512
bool RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int key, int pos)
Definition: rna_access.c:3983
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
Definition: rna_access.c:1736
char * RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr)
Definition: rna_access.c:5336
PropertySubType RNA_property_subtype(PropertyRNA *prop)
Definition: rna_access.c:1015
const char * RNA_struct_translation_context(const StructRNA *type)
Definition: rna_access.c:619
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:5301
int RNA_parameter_list_ret_count(const ParameterList *parms)
Definition: rna_access.c:5959
void * RNA_struct_py_type_get(StructRNA *srna)
Definition: rna_access.c:887
IDProperty * rna_idproperty_find(PointerRNA *ptr, const char *name)
Definition: rna_access.c:271
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
Definition: rna_access.c:1190
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format,...)
Definition: rna_access.c:6194
bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:680
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_function_call(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
Definition: rna_access.c:6165
int RNA_parameter_dynamic_length_get(ParameterList *parms, PropertyRNA *parm)
Definition: rna_access.c:6104
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
Definition: rna_access.c:1495
static void rna_pointer_inherit_id(StructRNA *type, PointerRNA *parent, PointerRNA *ptr)
Definition: rna_access.c:169
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:4026
PropertyRNA * RNA_function_find_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, const char *identifier)
Definition: rna_access.c:5798
int RNA_property_tags(PropertyRNA *prop)
Definition: rna_access.c:1060
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
Definition: rna_access.c:1668
static bool rna_ensure_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:317
bool RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
Definition: rna_access.c:4210
void RNA_property_collection_end(CollectionPropertyIterator *iter)
Definition: rna_access.c:3750
bool RNA_property_collection_lookup_string_has_fn(PropertyRNA *prop)
Definition: rna_access.c:4090
bool RNA_struct_idprops_check(StructRNA *srna)
Definition: rna_access.c:266
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:5015
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:4992
int RNA_property_array_item_index(PropertyRNA *prop, char name)
Definition: rna_access.c:1136
static void rna_property_boolean_fill_default_array_values(const bool *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
Definition: rna_access.c:2215
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2275
const ListBase * RNA_struct_type_functions(StructRNA *srna)
Definition: rna_access.c:853
char * RNA_property_string_get_default_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:3326
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
Definition: rna_access.c:948
bool RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
Definition: rna_access.c:3918
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
bool RNA_path_resolved_create(PointerRNA *ptr, struct PropertyRNA *prop, const int prop_index, PathResolvedRNA *r_anim_rna)
Definition: rna_access.c:6788
void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr)
Definition: rna_access.c:105
const char * RNA_struct_state_owner_get(void)
Definition: rna_access.c:6816
#define RAW_SET(dtype, raw, a, var)
Definition: rna_access.c:4288
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:5281
char * RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, const bool as_function, const bool all_args, const int max_prop_length)
Definition: rna_access.c:5492
void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter)
Definition: rna_access.c:5964
void * rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4836
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3645
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
Definition: rna_access.c:634
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3213
void RNA_property_enum_items_ex(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const bool use_static, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
Definition: rna_access.c:1452
bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, const int index)
Definition: rna_access.c:1986
const char * RNA_translate_ui_text(const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
Definition: rna_access.c:6643
int RNA_parameter_list_size(const ParameterList *parms)
Definition: rna_access.c:5949
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3062
int RNA_parameter_flag(PropertyRNA *prop)
Definition: rna_access.c:5821
int RNA_raw_type_sizeof(RawPropertyType type)
Definition: rna_access.c:4315
const char * RNA_function_ui_description(FunctionRNA *func)
Definition: rna_access.c:5773
int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *array, RawPropertyType type, int len)
Definition: rna_access.c:4716
bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2009
void * rna_iterator_listbase_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4761
const char * RNA_property_ui_name_raw(const PropertyRNA *prop)
Definition: rna_access.c:1880
const char * RNA_struct_ui_description_raw(const StructRNA *type)
Definition: rna_access.c:614
const char * RNA_property_ui_description(const PropertyRNA *prop)
Definition: rna_access.c:1885
const StructRNA * RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
Definition: rna_access.c:644
char * RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length, PropertyRNA *iterprop)
Definition: rna_access.c:5397
int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
Definition: rna_access.c:1096
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *inarray, RawPropertyType intype, int inlen, int set)
Definition: rna_access.c:4352
static bool rna_property_editable_do(PointerRNA *ptr, PropertyRNA *prop_orig, const int index, const char **r_info)
Definition: rna_access.c:1905
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3762
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
Definition: rna_access.c:2304
void * RNA_property_py_data_get(PropertyRNA *prop)
Definition: rna_access.c:1070
const char * RNA_property_ui_name(const PropertyRNA *prop)
Definition: rna_access.c:1875
StructRNA * RNA_struct_base(StructRNA *type)
Definition: rna_access.c:639
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
Definition: rna_access.c:3239
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
Definition: rna_access.c:1777
static int rna_function_format_array_length(const char *format, int ofs, int flen)
Definition: rna_access.c:6236
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
Definition: rna_access.c:3666
bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_free(BlenderRNA *brna)
Definition: rna_define.c:828
int rna_parameter_size(PropertyRNA *parm)
Definition: rna_define.c:4352
int rna_parameter_size_pad(const int size)
Definition: rna_define.c:4424
const char * rna_translate_ui_text(const char *text, const char *text_ctxt, struct StructRNA *type, struct PropertyRNA *prop, bool translate)
struct StructRNA * rna_ID_refine(struct PointerRNA *ptr)
BlenderRNA BLENDER_RNA
#define RNA_MAGIC
Definition: rna_internal.h:21
void(* ContextUpdateFunc)(struct bContext *C, struct PointerRNA *ptr)
void(* ContextPropUpdateFunc)(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop)
@ PROP_INTERN_BUILTIN
@ PROP_INTERN_RAW_ACCESS
@ PROP_INTERN_RAW_ARRAY
bool(* PropPointerPollFuncPy)(struct PointerRNA *ptr, const PointerRNA value, const PropertyRNA *prop)
char * RNA_path_full_struct_py(Main *bmain, const PointerRNA *ptr)
Definition: rna_path.cc:1217
char * RNA_path_full_ID_py(Main *bmain, ID *id)
Definition: rna_path.cc:1182
char * RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_path.cc:1127
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_path.cc:531
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_path.cc:503
#define min(a, b)
Definition: sort.c:35
_W64 int intptr_t
Definition: stdint.h:118
char * ptr
Definition: RNA_types.h:376
struct GHash * structs_map
unsigned int structs_len
PropBooleanArraySetFuncEx setarray_ex
PropBooleanArrayGetFuncEx getarray_ex
PropBooleanArraySetFunc setarray
const bool * defaultarray
PropBooleanSetFunc set
PropBooleanGetFunc get
PropBooleanSetFuncEx set_ex
PropBooleanGetFuncEx get_ex
PropBooleanArrayGetFunc getarray
ListBaseIterator listbase
Definition: RNA_types.h:409
union CollectionPropertyIterator::@1147 internal
struct PropertyRNA * prop
Definition: RNA_types.h:406
PropCollectionNextFunc next
PropCollectionLookupStringFunc lookupstring
PropCollectionLengthFunc length
struct StructRNA * item_type
PropCollectionLookupIntFunc lookupint
PropCollectionBeginFunc begin
PropCollectionAssignIntFunc assignint
PropCollectionEndFunc end
struct GHash * prophash
const char * identifier
Definition: RNA_types.h:461
const char * name
Definition: RNA_types.h:465
const char * description
Definition: RNA_types.h:467
const EnumPropertyItem * item
PropEnumSetFuncEx set_ex
PropEnumGetFunc get
PropEnumItemFunc item_fn
PropEnumGetFuncEx get_ex
PropEnumSetFunc set
PropFloatSetFuncEx set_ex
PropertyScaleType ui_scale_type
PropFloatGetFunc get
PropFloatRangeFuncEx range_ex
PropFloatArrayGetFuncEx getarray_ex
PropFloatArraySetFuncEx setarray_ex
PropFloatArrayGetFunc getarray
PropFloatSetFunc set
const float * defaultarray
PropFloatRangeFunc range
PropFloatArraySetFunc setarray
PropFloatGetFuncEx get_ex
const char * identifier
PropertyRNA * c_ret
ContainerRNA cont
const char * description
void * pointer
Definition: DNA_ID.h:100
double * default_array
Definition: DNA_ID.h:74
double default_value
Definition: DNA_ID.h:85
int default_array_len
Definition: DNA_ID.h:60
int * default_array
Definition: DNA_ID.h:59
char * default_value
Definition: DNA_ID.h:91
char * description
Definition: DNA_ID.h:49
int rna_subtype
Definition: DNA_ID.h:51
short flag
Definition: DNA_ID.h:109
int len
Definition: DNA_ID.h:121
IDPropertyUIData * ui_data
Definition: DNA_ID.h:128
char name[64]
Definition: DNA_ID.h:111
IDPropertyData data
Definition: DNA_ID.h:117
char subtype
Definition: DNA_ID.h:108
char type
Definition: DNA_ID.h:108
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378
PropIntRangeFuncEx range_ex
PropIntGetFunc get
PropIntArrayGetFunc getarray
const int * defaultarray
PropIntArrayGetFuncEx getarray_ex
PropIntRangeFunc range
PropIntArraySetFunc setarray
PropIntGetFuncEx get_ex
PropIntSetFunc set
PropertyRNA property
PropIntArraySetFuncEx setarray_ex
PropertyScaleType ui_scale_type
PropIntSetFuncEx set_ex
struct Link * link
Definition: RNA_types.h:370
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
intptr_t array_tot
Definition: RNA_types.h:626
PropertyRNA * parm
Definition: RNA_types.h:619
struct ParameterList * parms
Definition: RNA_types.h:614
void * data
Definition: RNA_types.h:602
struct FunctionRNA * func
Definition: RNA_types.h:605
struct PropertyRNA * prop
Definition: RNA_types.h:51
struct PointerRNA ptr
Definition: RNA_types.h:50
PropPointerTypeFunc type_fn
struct StructRNA * type
PropPointerGetFunc get
PropPointerPollFunc poll
PropPointerSetFunc set
struct StructRNA * type
Definition: RNA_types.h:37
void * data
Definition: RNA_types.h:38
struct ID * owner_id
Definition: RNA_types.h:36
const char * identifier
PropertyRNA * rawprop
PropertyRNA * rnaprop
ItemEditableFunc itemeditable
PropArrayLengthGetFunc getlength
const char * translation_context
unsigned int arraydimension
struct PropertyRNA * next
EditableFunc editable
PropertySubType subtype
unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION]
const char * description
const char * name
unsigned int totarraylength
const char * identifier
RawPropertyType rawtype
PropertyType type
UpdateFunc update
RawPropertyType type
Definition: RNA_types.h:443
int len
Definition: RNA_types.h:444
void * array
Definition: RNA_types.h:442
int stride
Definition: RNA_types.h:445
PropStringSetFunc set
const char * defaultvalue
PropStringLengthFuncEx length_ex
PropStringLengthFunc length
PropStringGetFuncEx get_ex
PropStringSetFuncEx set_ex
PropStringGetFunc get
StringPropertySearchFunc search
eStringPropertySearchFlag search_flag
const char * identifier
ContainerRNA cont
PropertyRNA * nameproperty
IDPropertiesFunc idproperties
struct StructRNA * base
ListBase functions
StructRefineFunc refine
float max
struct IDPropertyTemplate::@27 array
const char * str
Definition: BKE_idprop.h:29
struct ID * id
Definition: BKE_idprop.h:33
struct IDPropertyTemplate::@26 string
#define N_(msgid)
static FT_Error err
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480
void WM_msg_publish_rna(struct wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)