Blender  V2.93
rna_access.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <ctype.h>
22 #include <stddef.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "DNA_ID.h"
29 #include "DNA_constraint_types.h"
30 #include "DNA_modifier_types.h"
31 #include "DNA_scene_types.h"
33 
34 #include "BLI_alloca.h"
35 #include "BLI_blenlib.h"
36 #include "BLI_dynstr.h"
37 #include "BLI_ghash.h"
38 #include "BLI_math.h"
39 #include "BLI_utildefines.h"
40 
41 #include "BLF_api.h"
42 #include "BLT_translation.h"
43 
44 #include "BKE_anim_data.h"
45 #include "BKE_collection.h"
46 #include "BKE_context.h"
47 #include "BKE_fcurve.h"
48 #include "BKE_idprop.h"
49 #include "BKE_idtype.h"
50 #include "BKE_main.h"
51 #include "BKE_node.h"
52 #include "BKE_report.h"
53 
54 #include "DEG_depsgraph.h"
55 #include "DEG_depsgraph_build.h"
56 
57 #include "RNA_access.h"
58 #include "RNA_define.h"
59 #include "RNA_enum_types.h"
60 
61 #include "WM_api.h"
62 #include "WM_message.h"
63 
64 /* flush updates */
65 #include "DNA_object_types.h"
66 #include "WM_types.h"
67 
68 #include "rna_access_internal.h"
69 #include "rna_internal.h"
70 
72 
73 /* Init/Exit */
74 
75 void RNA_init(void)
76 {
77  StructRNA *srna;
78  PropertyRNA *prop;
79 
82 
83  for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
84  if (!srna->cont.prophash) {
85  srna->cont.prophash = BLI_ghash_str_new("RNA_init gh");
86 
87  for (prop = srna->cont.properties.first; prop; prop = prop->next) {
88  if (!(prop->flag_internal & PROP_INTERN_BUILTIN)) {
89  BLI_ghash_insert(srna->cont.prophash, (void *)prop->identifier, prop);
90  }
91  }
92  }
94  BLI_ghash_insert(BLENDER_RNA.structs_map, (void *)srna->identifier, srna);
96  }
97 }
98 
99 void RNA_exit(void)
100 {
101  StructRNA *srna;
102 
103  for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) {
104  if (srna->cont.prophash) {
106  srna->cont.prophash = NULL;
107  }
108  }
109 
111 }
112 
113 /* Pointer */
114 
116 {
117  r_ptr->owner_id = NULL;
118  r_ptr->type = &RNA_BlendData;
119  r_ptr->data = main;
120 }
121 
123 {
124  StructRNA *type, *idtype = NULL;
125 
126  if (id) {
127  PointerRNA tmp = {NULL};
128  tmp.data = id;
129  idtype = rna_ID_refine(&tmp);
130 
131  while (idtype->refine) {
132  type = idtype->refine(&tmp);
133 
134  if (type == idtype) {
135  break;
136  }
137  idtype = type;
138  }
139  }
140 
141  r_ptr->owner_id = id;
142  r_ptr->type = idtype;
143  r_ptr->data = id;
144 }
145 
146 void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
147 {
148 #if 0 /* UNUSED */
149  StructRNA *idtype = NULL;
150 
151  if (id) {
152  PointerRNA tmp = {0};
153  tmp.data = id;
154  idtype = rna_ID_refine(&tmp);
155  }
156 #endif
157 
158  r_ptr->owner_id = id;
159  r_ptr->type = type;
160  r_ptr->data = data;
161 
162  if (data) {
163  while (r_ptr->type && r_ptr->type->refine) {
164  StructRNA *rtype = r_ptr->type->refine(r_ptr);
165 
166  if (rtype == r_ptr->type) {
167  break;
168  }
169  r_ptr->type = rtype;
170  }
171  }
172 }
173 
175 {
176  return !((ptr->data != NULL) && (ptr->owner_id != NULL) && (ptr->type != NULL));
177 }
178 
180 {
181  if (type && type->flag & STRUCT_ID) {
182  ptr->owner_id = ptr->data;
183  }
184  else {
185  ptr->owner_id = parent->owner_id;
186  }
187 }
188 
190 {
191  r_ptr->owner_id = NULL;
192  r_ptr->type = &RNA_BlenderRNA;
193  r_ptr->data = &BLENDER_RNA;
194 }
195 
197 {
198  if (data) {
200  result.data = data;
201  result.type = type;
203 
204  while (result.type->refine) {
205  type = result.type->refine(&result);
206 
207  if (type == result.type) {
208  break;
209  }
210  result.type = type;
211  }
212  return result;
213  }
214  return PointerRNA_NULL;
215 }
216 
218 {
219 #if 0 /* works but this case if covered by more general code below. */
220  if (RNA_struct_is_ID(ptr->type)) {
221  /* simple case */
223  }
224  else
225 #endif
226  {
227  StructRNA *base;
228  PointerRNA t_ptr;
229  *r_ptr = *ptr; /* initialize as the same in case cant recast */
230 
231  for (base = ptr->type->base; base; base = base->base) {
232  t_ptr = rna_pointer_inherit_refine(ptr, base, ptr->data);
233  if (t_ptr.type && t_ptr.type != ptr->type) {
234  *r_ptr = t_ptr;
235  }
236  }
237  }
238 }
239 
240 /* ID Properties */
241 
243 {
244  /* so the property is seen as 'set' by rna */
245  idprop->flag &= ~IDP_FLAG_GHOST;
246 }
247 
249 {
250  IDProperty *idprop;
251 
252  for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) {
253  if (STREQ(RNA_IDP_UI, idprop->name)) {
254  break;
255  }
256  }
257 
258  if (idprop == NULL) {
259  for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) {
260  if (STREQ(RNA_IDP_UI, idprop->name)) {
261  break;
262  }
263  }
264  }
265 
266  return idprop;
267 }
268 
269 /* return a UI local ID prop definition for this prop */
270 static const IDProperty *rna_idproperty_ui(const PropertyRNA *prop)
271 {
273 
274  if (idprop) {
275  return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP);
276  }
277 
278  return NULL;
279 }
280 
281 /* return or create a UI local ID prop definition for this prop */
283 {
284  IDProperty *idprop = rna_idproperty_ui_container(prop);
285  IDPropertyTemplate dummy = {0};
286 
287  if (idprop == NULL && create) {
288  IDProperty *props = RNA_struct_idprops(ptr, false);
289 
290  /* Sanity check: props is the actual container of this property. */
291  if (props != NULL && BLI_findindex(&props->data.group, prop) >= 0) {
292  idprop = IDP_New(IDP_GROUP, &dummy, RNA_IDP_UI);
293 
294  if (!IDP_AddToGroup(props, idprop)) {
295  IDP_FreePropertyContent(idprop);
296  return NULL;
297  }
298  }
299  }
300 
301  if (idprop) {
302  const char *name = ((IDProperty *)prop)->name;
304 
305  if (rv == NULL && create) {
306  rv = IDP_New(IDP_GROUP, &dummy, name);
307 
308  if (!IDP_AddToGroup(idprop, rv)) {
310  return NULL;
311  }
312  }
313 
314  return rv;
315  }
316 
317  return NULL;
318 }
319 
321  PropertyRNA *prop,
322  const char type,
323  IDPropertyTemplate *value)
324 {
326 
327  if (prop->magic == RNA_MAGIC) {
328  return false;
329  }
330 
331  /* attempt to get the local ID values */
332  IDProperty *idp_ui = rna_idproperty_ui_ensure(ptr, prop, value != NULL);
333 
334  if (idp_ui == NULL) {
335  return (value == NULL);
336  }
337 
338  IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", type);
339 
340  if (value == NULL) {
341  if (item != NULL) {
342  IDP_RemoveFromGroup(idp_ui, item);
343  }
344  }
345  else {
346  if (item != NULL) {
347  switch (type) {
348  case IDP_INT:
349  IDP_Int(item) = value->i;
350  break;
351  case IDP_DOUBLE:
352  IDP_Double(item) = value->d;
353  break;
354  default:
355  BLI_assert(false);
356  return false;
357  }
358  }
359  else {
360  item = IDP_New(type, value, "default");
361 
362  if (!IDP_AddToGroup(idp_ui, item)) {
364  return false;
365  }
366  }
367  }
368 
369  return true;
370 }
371 
373 {
374  StructRNA *type = ptr->type;
375 
376  if (type && type->idproperties) {
377  return type->idproperties(ptr, create);
378  }
379 
380  return NULL;
381 }
382 
384 {
385  return (srna && srna->idproperties);
386 }
387 
389 {
390  IDProperty *group = RNA_struct_idprops(ptr, 0);
391 
392  if (group) {
393  if (group->type == IDP_GROUP) {
394  return IDP_GetPropertyFromGroup(group, name);
395  }
396  /* Not sure why that happens sometimes, with nested properties... */
397  /* Seems to be actually array prop, name is usually "0"... To be sorted out later. */
398 #if 0
399  printf(
400  "Got unexpected IDProp container when trying to retrieve %s: %d\n", name, group->type);
401 #endif
402  }
403 
404  return NULL;
405 }
406 
407 static void rna_idproperty_free(PointerRNA *ptr, const char *name)
408 {
409  IDProperty *group = RNA_struct_idprops(ptr, 0);
410 
411  if (group) {
412  IDProperty *idprop = IDP_GetPropertyFromGroup(group, name);
413  if (idprop) {
414  IDP_FreeFromGroup(group, idprop);
415  }
416  }
417 }
418 
420 {
421  if (prop->magic == RNA_MAGIC) {
422  int arraylen[RNA_MAX_ARRAY_DIMENSION];
423  return (prop->getlength && ptr->data) ? prop->getlength(ptr, arraylen) : prop->totarraylength;
424  }
425  IDProperty *idprop = (IDProperty *)prop;
426 
427  if (idprop->type == IDP_ARRAY) {
428  return idprop->len;
429  }
430  return 0;
431 }
432 
434 {
435  if (prop->magic == RNA_MAGIC) {
436  return (prop->getlength || prop->totarraylength);
437  }
438  IDProperty *idprop = (IDProperty *)prop;
439 
440  return (idprop->type == IDP_ARRAY);
441 }
442 
444  PropertyRNA *prop,
445  int length[])
446 {
447  if (prop->magic == RNA_MAGIC) {
448  if (prop->getlength) {
449  prop->getlength(ptr, length);
450  }
451  else {
452  memcpy(length, prop->arraylength, prop->arraydimension * sizeof(int));
453  }
454  }
455  else {
456  IDProperty *idprop = (IDProperty *)prop;
457 
458  if (idprop->type == IDP_ARRAY) {
459  length[0] = idprop->len;
460  }
461  else {
462  length[0] = 0;
463  }
464  }
465 }
466 
468 {
469  /* this verifies if the idproperty actually matches the property
470  * description and otherwise removes it. this is to ensure that
471  * rna property access is type safe, e.g. if you defined the rna
472  * to have a certain array length you can count on that staying so */
473 
474  switch (idprop->type) {
475  case IDP_IDPARRAY:
476  if (prop->type != PROP_COLLECTION) {
477  return false;
478  }
479  break;
480  case IDP_ARRAY:
481  if (rna_ensure_property_array_length(ptr, prop) != idprop->len) {
482  return false;
483  }
484 
485  if (idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT) {
486  return false;
487  }
488  if (idprop->subtype == IDP_INT && !ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
489  return false;
490  }
491 
492  break;
493  case IDP_INT:
494  if (!ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
495  return false;
496  }
497  break;
498  case IDP_FLOAT:
499  case IDP_DOUBLE:
500  if (prop->type != PROP_FLOAT) {
501  return false;
502  }
503  break;
504  case IDP_STRING:
505  if (prop->type != PROP_STRING) {
506  return false;
507  }
508  break;
509  case IDP_GROUP:
510  case IDP_ID:
511  if (prop->type != PROP_POINTER) {
512  return false;
513  }
514  break;
515  default:
516  return false;
517  }
518 
519  return true;
520 }
521 
526  NULL,
527  NULL,
528  NULL,
533 };
534 
536  NULL,
539  NULL,
540  NULL,
541  NULL,
543  NULL,
545 };
546 
547 /* This function initializes a PropertyRNAOrID with all required info, from a given PropertyRNA
548  * and PointerRNA data. It deals properly with the three cases (static RNA, runtime RNA, and
549  * IDProperty).
550  * WARNING: given `ptr` PointerRNA is assumed to be a valid data one here, calling code is
551  * responsible to ensure that.
552  */
554  PointerRNA *ptr,
555  PropertyRNAOrID *r_prop_rna_or_id)
556 {
557  /* This is quite a hack, but avoids some complexity in the API. we
558  * pass IDProperty structs as PropertyRNA pointers to the outside.
559  * We store some bytes in PropertyRNA structs that allows us to
560  * distinguish it from IDProperty structs. If it is an ID property,
561  * we look up an IDP PropertyRNA based on the type, and set the data
562  * pointer to the IDProperty. */
563  memset(r_prop_rna_or_id, 0, sizeof(*r_prop_rna_or_id));
564 
565  r_prop_rna_or_id->ptr = *ptr;
566  r_prop_rna_or_id->rawprop = prop;
567 
568  if (prop->magic == RNA_MAGIC) {
569  r_prop_rna_or_id->rnaprop = prop;
570  r_prop_rna_or_id->identifier = prop->identifier;
571 
572  r_prop_rna_or_id->is_array = prop->getlength || prop->totarraylength;
573  if (r_prop_rna_or_id->is_array) {
574  int arraylen[RNA_MAX_ARRAY_DIMENSION];
575  r_prop_rna_or_id->array_len = (prop->getlength && ptr->data) ?
576  (uint)prop->getlength(ptr, arraylen) :
577  prop->totarraylength;
578  }
579 
580  if (prop->flag & PROP_IDPROPERTY) {
581  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
582 
583  if (idprop != NULL && !rna_idproperty_verify_valid(ptr, prop, idprop)) {
584  IDProperty *group = RNA_struct_idprops(ptr, 0);
585 
586  IDP_FreeFromGroup(group, idprop);
587  idprop = NULL;
588  }
589 
590  r_prop_rna_or_id->idprop = idprop;
591  r_prop_rna_or_id->is_set = idprop != NULL && (idprop->flag & IDP_FLAG_GHOST) == 0;
592  }
593  else {
594  /* Full static RNA properties are always set. */
595  r_prop_rna_or_id->is_set = true;
596  }
597  }
598  else {
599  IDProperty *idprop = (IDProperty *)prop;
600  /* Given prop may come from the custom properties of another data, ensure we get the one from
601  * given data ptr. */
602  IDProperty *idprop_evaluated = rna_idproperty_find(ptr, idprop->name);
603  if (idprop_evaluated != NULL && idprop->type != idprop_evaluated->type) {
604  idprop_evaluated = NULL;
605  }
606 
607  r_prop_rna_or_id->idprop = idprop_evaluated;
608  r_prop_rna_or_id->is_idprop = true;
609  /* Full IDProperties are always set, if it exists. */
610  r_prop_rna_or_id->is_set = (idprop_evaluated != NULL);
611 
612  r_prop_rna_or_id->identifier = idprop->name;
613  if (idprop->type == IDP_ARRAY) {
614  r_prop_rna_or_id->rnaprop = arraytypemap[(int)(idprop->subtype)];
615  r_prop_rna_or_id->is_array = true;
616  r_prop_rna_or_id->array_len = idprop_evaluated != NULL ? (uint)idprop_evaluated->len : 0;
617  }
618  else {
619  r_prop_rna_or_id->rnaprop = typemap[(int)(idprop->type)];
620  }
621  }
622 }
623 
624 /* This function only returns an IDProperty,
625  * or NULL (in case IDProp could not be found, or prop is a real RNA property). */
627 {
628  PropertyRNAOrID prop_rna_or_id;
629 
630  rna_property_rna_or_id_get(*prop, ptr, &prop_rna_or_id);
631 
632  *prop = prop_rna_or_id.rnaprop;
633  return prop_rna_or_id.idprop;
634 }
635 
636 /* This function always return the valid, real data pointer, be it a regular RNA property one,
637  * or an IDProperty one. */
639 {
640  PropertyRNAOrID prop_rna_or_id;
641 
642  rna_property_rna_or_id_get(*prop, ptr, &prop_rna_or_id);
643 
644  *prop = prop_rna_or_id.rnaprop;
645  return (prop_rna_or_id.is_idprop || prop_rna_or_id.idprop != NULL) ?
646  (PropertyRNA *)prop_rna_or_id.idprop :
647  prop_rna_or_id.rnaprop;
648 }
649 
651 {
652  /* the quick version if we don't need the idproperty */
653 
654  if (prop->magic == RNA_MAGIC) {
655  return prop;
656  }
657 
658  {
659  IDProperty *idprop = (IDProperty *)prop;
660 
661  if (idprop->type == IDP_ARRAY) {
662  return arraytypemap[(int)(idprop->subtype)];
663  }
664  return typemap[(int)(idprop->type)];
665  }
666 }
667 
668 static const char *rna_ensure_property_identifier(const PropertyRNA *prop)
669 {
670  if (prop->magic == RNA_MAGIC) {
671  return prop->identifier;
672  }
673  return ((const IDProperty *)prop)->name;
674 }
675 
676 static const char *rna_ensure_property_description(const PropertyRNA *prop)
677 {
678  const char *description = NULL;
679 
680  if (prop->magic == RNA_MAGIC) {
681  description = prop->description;
682  }
683  else {
684  /* attempt to get the local ID values */
685  const IDProperty *idp_ui = rna_idproperty_ui(prop);
686 
687  if (idp_ui) {
688  IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "description", IDP_STRING);
689  if (item) {
690  description = IDP_String(item);
691  }
692  }
693 
694  if (description == NULL) {
695  description = ((IDProperty *)prop)->name; /* XXX - not correct */
696  }
697  }
698 
699  return description;
700 }
701 
702 static const char *rna_ensure_property_name(const PropertyRNA *prop)
703 {
704  const char *name;
705 
706  if (prop->magic == RNA_MAGIC) {
707  name = prop->name;
708  }
709  else {
710  name = ((const IDProperty *)prop)->name;
711  }
712 
713  return name;
714 }
715 
716 /* Structs */
717 
718 StructRNA *RNA_struct_find(const char *identifier)
719 {
720  return BLI_ghash_lookup(BLENDER_RNA.structs_map, identifier);
721 }
722 
724 {
725  return type->identifier;
726 }
727 
728 const char *RNA_struct_ui_name(const StructRNA *type)
729 {
730  return CTX_IFACE_(type->translation_context, type->name);
731 }
732 
734 {
735  return type->name;
736 }
737 
739 {
740  if (type) {
741  return type->icon;
742  }
743  return ICON_DOT;
744 }
745 
747 {
748  return TIP_(type->description);
749 }
750 
752 {
753  return type->description;
754 }
755 
757 {
758  return type->translation_context;
759 }
760 
762 {
763  return type->nameproperty;
764 }
765 
767 {
768  return type->prop_tag_defines;
769 }
770 
772 {
773  return type->iteratorproperty;
774 }
775 
777 {
778  return type->base;
779 }
780 
786 const StructRNA *RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
787 {
788  while (type) {
789  if (type->base == parent_type) {
790  return type;
791  }
792  type = type->base;
793  }
794  return NULL;
795 }
796 
798 {
799  return (type->flag & STRUCT_ID) != 0;
800 }
801 
803 {
804  return (type->flag & STRUCT_UNDO) != 0;
805 }
806 
808 {
809  return (type->flag & STRUCT_NO_IDPROPERTIES) == 0;
810 }
811 
813 {
815 }
816 
824 {
825  return (type->flag & (STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES | STRUCT_ID)) != 0;
826 }
827 
828 /* remove an id-property */
829 bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
830 {
831  IDProperty *group = RNA_struct_idprops(ptr, 0);
832 
833  if (group) {
834  IDProperty *idp = IDP_GetPropertyFromGroup(group, identifier);
835  if (idp) {
836  IDP_FreeFromGroup(group, idp);
837 
838  return true;
839  }
840  }
841  return false;
842 }
843 
844 bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
845 {
846  const StructRNA *base;
847 
848  if (srna == &RNA_AnyType) {
849  return true;
850  }
851 
852  if (!type) {
853  return false;
854  }
855 
856  /* ptr->type is always maximally refined */
857  for (base = type; base; base = base->base) {
858  if (base == srna) {
859  return true;
860  }
861  }
862 
863  return false;
864 }
865 
867 {
868  if (identifier[0] == '[' && identifier[1] == '"') { /* " (dummy comment to avoid confusing some
869  * function lists in text editors) */
870  /* id prop lookup, not so common */
871  PropertyRNA *r_prop = NULL;
872  PointerRNA r_ptr; /* only support single level props */
873  if (RNA_path_resolve_property(ptr, identifier, &r_ptr, &r_prop) && (r_ptr.type == ptr->type) &&
874  (r_ptr.data == ptr->data)) {
875  return r_prop;
876  }
877  }
878  else {
879  /* most common case */
881  PointerRNA propptr;
882 
883  if (RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr)) {
884  return propptr.data;
885  }
886  }
887 
888  return NULL;
889 }
890 
891 /* Find the property which uses the given nested struct */
893 {
894  PropertyRNA *prop = NULL;
895 
896  RNA_STRUCT_BEGIN (ptr, iprop) {
897  /* This assumes that there can only be one user of this nested struct */
898  if (RNA_property_pointer_type(ptr, iprop) == srna) {
899  prop = iprop;
900  break;
901  }
902  }
903  RNA_PROP_END;
904 
905  return prop;
906 }
907 
909 {
910  /* note, prop_test could be freed memory, only use for comparison */
911 
912  /* validate the RNA is ok */
913  PropertyRNA *iterprop;
914  bool found = false;
915 
917 
918  RNA_PROP_BEGIN (ptr, itemptr, iterprop) {
919  /* PropertyRNA *prop = itemptr.data; */
920  if (prop_test == (PropertyRNA *)itemptr.data) {
921  found = true;
922  break;
923  }
924  }
925  RNA_PROP_END;
926 
927  return found;
928 }
929 
931 {
932  PointerRNA struct_ptr;
933  unsigned int counter = 0;
934 
935  RNA_pointer_create(NULL, srna, NULL, &struct_ptr);
936 
937  RNA_STRUCT_BEGIN (&struct_ptr, prop) {
938  counter++;
939  UNUSED_VARS(prop);
940  }
942 
943  return counter;
944 }
945 
946 /* Low level direct access to type->properties,
947  * note this ignores parent classes so should be used with care. */
949 {
950  return &srna->cont.properties;
951 }
952 
953 PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
954 {
955  return BLI_findstring_ptr(&srna->cont.properties, identifier, offsetof(PropertyRNA, identifier));
956 }
957 
958 FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier)
959 {
960 #if 1
961  FunctionRNA *func;
962  StructRNA *type;
963  for (type = srna; type; type = type->base) {
965  &type->functions, identifier, offsetof(FunctionRNA, identifier));
966  if (func) {
967  return func;
968  }
969  }
970  return NULL;
971 
972  /* functional but slow */
973 #else
974  PointerRNA tptr;
975  PropertyRNA *iterprop;
976  FunctionRNA *func;
977 
978  RNA_pointer_create(NULL, &RNA_Struct, srna, &tptr);
979  iterprop = RNA_struct_find_property(&tptr, "functions");
980 
981  func = NULL;
982 
983  RNA_PROP_BEGIN (&tptr, funcptr, iterprop) {
984  if (STREQ(identifier, RNA_function_identifier(funcptr.data))) {
985  func = funcptr.data;
986  break;
987  }
988  }
989  RNA_PROP_END;
990 
991  return func;
992 #endif
993 }
994 
996 {
997  return &srna->functions;
998 }
999 
1001 {
1002  return type->reg;
1003 }
1004 
1006 {
1007  do {
1008  if (type->unreg) {
1009  return type->unreg;
1010  }
1011  } while ((type = type->base));
1012 
1013  return NULL;
1014 }
1015 
1017 {
1018  StructRNA *type = ptr->type;
1019 
1020  do {
1021  if (type->instance) {
1022  return type->instance(ptr);
1023  }
1024  } while ((type = type->base));
1025 
1026  return NULL;
1027 }
1028 
1030 {
1031  return srna->py_type;
1032 }
1033 
1034 void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
1035 {
1036  srna->py_type = py_type;
1037 }
1038 
1040 {
1041  return srna->blender_type;
1042 }
1043 
1044 void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
1045 {
1046  srna->blender_type = blender_type;
1047 }
1048 
1049 char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
1050 {
1051  PropertyRNA *nameprop;
1052 
1053  if (ptr->data && (nameprop = RNA_struct_name_property(ptr->type))) {
1054  return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
1055  }
1056 
1057  return NULL;
1058 }
1059 
1063 bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
1064 {
1065  const StructRNA *srna_exists = RNA_struct_find(identifier);
1066  if (UNLIKELY(srna_exists != NULL)) {
1067  /* Use comprehensive string construction since this is such a rare occurrence
1068  * and information here may cut down time troubleshooting. */
1069  DynStr *dynstr = BLI_dynstr_new();
1070  BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier);
1071  BLI_dynstr_append(dynstr, srna_exists->identifier);
1072  int i = 0;
1073  if (srna_exists->base) {
1074  for (const StructRNA *base = srna_exists->base; base; base = base->base) {
1075  BLI_dynstr_append(dynstr, "(");
1076  BLI_dynstr_append(dynstr, base->identifier);
1077  i += 1;
1078  }
1079  while (i--) {
1080  BLI_dynstr_append(dynstr, ")");
1081  }
1082  }
1083  BLI_dynstr_append(dynstr, "'.");
1084  char *result = BLI_dynstr_get_cstring(dynstr);
1085  BLI_dynstr_free(dynstr);
1086  BKE_report(reports, RPT_ERROR, result);
1087  MEM_freeN(result);
1088  return false;
1089  }
1090  return true;
1091 }
1092 
1094  const char *identifier,
1095  const char *sep)
1096 {
1097  const int len_sep = strlen(sep);
1098  const int len_id = strlen(identifier);
1099  const char *p = strstr(identifier, sep);
1100  /* TODO: make error, for now warning until add-ons update. */
1101 #if 1
1102  const int report_level = RPT_WARNING;
1103  const bool failure = true;
1104 #else
1105  const int report_level = RPT_ERROR;
1106  const bool failure = false;
1107 #endif
1108  if (p == NULL || p == identifier || p + len_sep >= identifier + len_id) {
1109  BKE_reportf(reports,
1110  report_level,
1111  "'%s' does not contain '%s' with prefix and suffix",
1112  identifier,
1113  sep);
1114  return failure;
1115  }
1116 
1117  const char *c, *start, *end, *last;
1118  start = identifier;
1119  end = p;
1120  last = end - 1;
1121  for (c = start; c != end; c++) {
1122  if (((*c >= 'A' && *c <= 'Z') || ((c != start) && (*c >= '0' && *c <= '9')) ||
1123  ((c != start) && (c != last) && (*c == '_'))) == 0) {
1124  BKE_reportf(
1125  reports, report_level, "'%s' doesn't have upper case alpha-numeric prefix", identifier);
1126  return failure;
1127  }
1128  }
1129 
1130  start = p + len_sep;
1131  end = identifier + len_id;
1132  last = end - 1;
1133  for (c = start; c != end; c++) {
1134  if (((*c >= 'A' && *c <= 'Z') || (*c >= 'a' && *c <= 'z') || (*c >= '0' && *c <= '9') ||
1135  ((c != start) && (c != last) && (*c == '_'))) == 0) {
1136  BKE_reportf(reports, report_level, "'%s' doesn't have an alpha-numeric suffix", identifier);
1137  return failure;
1138  }
1139  }
1140  return true;
1141 }
1142 
1143 /* Property Information */
1144 
1145 const char *RNA_property_identifier(const PropertyRNA *prop)
1146 {
1147  return rna_ensure_property_identifier(prop);
1148 }
1149 
1151 {
1152  return TIP_(rna_ensure_property_description(prop));
1153 }
1154 
1156 {
1157  return rna_ensure_property(prop)->type;
1158 }
1159 
1161 {
1162  PropertyRNA *rna_prop = rna_ensure_property(prop);
1163 
1164  /* For custom properties, find and parse the 'subtype' metadata field. */
1165  if (prop->magic != RNA_MAGIC) {
1166  IDProperty *idprop = (IDProperty *)prop;
1167 
1168  if (ELEM(idprop->type, IDP_INT, IDP_FLOAT, IDP_DOUBLE) ||
1169  ((idprop->type == IDP_ARRAY) && ELEM(idprop->subtype, IDP_INT, IDP_FLOAT, IDP_DOUBLE))) {
1170  const IDProperty *idp_ui = rna_idproperty_ui(prop);
1171 
1172  if (idp_ui) {
1173  IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "subtype", IDP_STRING);
1174 
1175  if (item) {
1176  int result = PROP_NONE;
1178  return (PropertySubType)result;
1179  }
1180  }
1181  }
1182  }
1183 
1184  return rna_prop->subtype;
1185 }
1186 
1188 {
1189  return RNA_SUBTYPE_UNIT(RNA_property_subtype(prop));
1190 }
1191 
1193 {
1194  return rna_ensure_property(prop)->flag;
1195 }
1196 
1204 {
1205  return rna_ensure_property(prop)->tags;
1206 }
1207 
1209 {
1210  return (rna_ensure_property(prop)->flag_internal & PROP_INTERN_BUILTIN) != 0;
1211 }
1212 
1214 {
1215  return prop->py_data;
1216 }
1217 
1219 {
1220  return rna_ensure_property_array_length(ptr, prop);
1221 }
1222 
1224 {
1225  return rna_ensure_property_array_check(prop);
1226 }
1227 
1228 /* used by BPY to make an array from the python object */
1230 {
1231  PropertyRNA *rprop = rna_ensure_property(prop);
1232 
1233  if (length) {
1235  }
1236 
1237  return rprop->arraydimension;
1238 }
1239 
1240 /* Return the size of Nth dimension. */
1242 {
1244 
1246 
1247  return len[dim];
1248 }
1249 
1251 {
1252  const char *vectoritem = "XYZW";
1253  const char *quatitem = "WXYZ";
1254  const char *coloritem = "RGBA";
1255  PropertySubType subtype = RNA_property_subtype(prop);
1256 
1257  BLI_assert(index >= 0);
1258 
1259  /* get string to use for array index */
1260  if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1261  return quatitem[index];
1262  }
1263  if ((index < 4) && ELEM(subtype,
1266  PROP_XYZ,
1268  PROP_EULER,
1269  PROP_VELOCITY,
1271  PROP_COORDS)) {
1272  return vectoritem[index];
1273  }
1274  if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1275  return coloritem[index];
1276  }
1277 
1278  return '\0';
1279 }
1280 
1282 {
1283  /* Don't use custom property subtypes in RNA path lookup. */
1284  PropertySubType subtype = rna_ensure_property(prop)->subtype;
1285 
1286  /* get index based on string name/alias */
1287  /* maybe a function to find char index in string would be better than all the switches */
1288  if (ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1289  switch (name) {
1290  case 'w':
1291  return 0;
1292  case 'x':
1293  return 1;
1294  case 'y':
1295  return 2;
1296  case 'z':
1297  return 3;
1298  }
1299  }
1300  else if (ELEM(subtype,
1303  PROP_XYZ,
1305  PROP_EULER,
1306  PROP_VELOCITY,
1307  PROP_ACCELERATION)) {
1308  switch (name) {
1309  case 'x':
1310  return 0;
1311  case 'y':
1312  return 1;
1313  case 'z':
1314  return 2;
1315  case 'w':
1316  return 3;
1317  }
1318  }
1319  else if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1320  switch (name) {
1321  case 'r':
1322  return 0;
1323  case 'g':
1324  return 1;
1325  case 'b':
1326  return 2;
1327  case 'a':
1328  return 3;
1329  }
1330  }
1331 
1332  return -1;
1333 }
1334 
1335 void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
1336 {
1338  int softmin, softmax;
1339 
1340  if (prop->magic != RNA_MAGIC) {
1341  /* attempt to get the local ID values */
1342  const IDProperty *idp_ui = rna_idproperty_ui(prop);
1343 
1344  if (idp_ui) {
1345  IDProperty *item;
1346 
1347  item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_INT);
1348  *hardmin = item ? IDP_Int(item) : INT_MIN;
1349 
1350  item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_INT);
1351  *hardmax = item ? IDP_Int(item) : INT_MAX;
1352 
1353  return;
1354  }
1355  }
1356 
1357  if (iprop->range) {
1358  *hardmin = INT_MIN;
1359  *hardmax = INT_MAX;
1360 
1361  iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1362  }
1363  else if (iprop->range_ex) {
1364  *hardmin = INT_MIN;
1365  *hardmax = INT_MAX;
1366 
1367  iprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1368  }
1369  else {
1370  *hardmin = iprop->hardmin;
1371  *hardmax = iprop->hardmax;
1372  }
1373 }
1374 
1376  PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
1377 {
1379  int hardmin, hardmax;
1380 
1381  if (prop->magic != RNA_MAGIC) {
1382  /* attempt to get the local ID values */
1383  const IDProperty *idp_ui = rna_idproperty_ui(prop);
1384 
1385  if (idp_ui) {
1386  IDProperty *item;
1387 
1388  item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_INT);
1389  *softmin = item ? IDP_Int(item) : INT_MIN;
1390 
1391  item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_INT);
1392  *softmax = item ? IDP_Int(item) : INT_MAX;
1393 
1394  item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_INT);
1395  *step = item ? IDP_Int(item) : 1;
1396 
1397  return;
1398  }
1399  }
1400 
1401  *softmin = iprop->softmin;
1402  *softmax = iprop->softmax;
1403 
1404  if (iprop->range) {
1405  hardmin = INT_MIN;
1406  hardmax = INT_MAX;
1407 
1408  iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1409 
1410  *softmin = max_ii(*softmin, hardmin);
1411  *softmax = min_ii(*softmax, hardmax);
1412  }
1413  else if (iprop->range_ex) {
1414  hardmin = INT_MIN;
1415  hardmax = INT_MAX;
1416 
1417  iprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1418 
1419  *softmin = max_ii(*softmin, hardmin);
1420  *softmax = min_ii(*softmax, hardmax);
1421  }
1422 
1423  *step = iprop->step;
1424 }
1425 
1426 void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
1427 {
1429  float softmin, softmax;
1430 
1431  if (prop->magic != RNA_MAGIC) {
1432  /* attempt to get the local ID values */
1433  const IDProperty *idp_ui = rna_idproperty_ui(prop);
1434 
1435  if (idp_ui) {
1436  IDProperty *item;
1437 
1438  item = IDP_GetPropertyTypeFromGroup(idp_ui, "min", IDP_DOUBLE);
1439  *hardmin = item ? (float)IDP_Double(item) : -FLT_MAX;
1440 
1441  item = IDP_GetPropertyTypeFromGroup(idp_ui, "max", IDP_DOUBLE);
1442  *hardmax = item ? (float)IDP_Double(item) : FLT_MAX;
1443 
1444  return;
1445  }
1446  }
1447 
1448  if (fprop->range) {
1449  *hardmin = -FLT_MAX;
1450  *hardmax = FLT_MAX;
1451 
1452  fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1453  }
1454  else if (fprop->range_ex) {
1455  *hardmin = -FLT_MAX;
1456  *hardmax = FLT_MAX;
1457 
1458  fprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1459  }
1460  else {
1461  *hardmin = fprop->hardmin;
1462  *hardmax = fprop->hardmax;
1463  }
1464 }
1465 
1467  PropertyRNA *prop,
1468  float *softmin,
1469  float *softmax,
1470  float *step,
1471  float *precision)
1472 {
1474  float hardmin, hardmax;
1475 
1476  if (prop->magic != RNA_MAGIC) {
1477  /* attempt to get the local ID values */
1478  const IDProperty *idp_ui = rna_idproperty_ui(prop);
1479 
1480  if (idp_ui) {
1481  IDProperty *item;
1482 
1483  item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_DOUBLE);
1484  *softmin = item ? (float)IDP_Double(item) : -FLT_MAX;
1485 
1486  item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_DOUBLE);
1487  *softmax = item ? (float)IDP_Double(item) : FLT_MAX;
1488 
1489  item = IDP_GetPropertyTypeFromGroup(idp_ui, "step", IDP_DOUBLE);
1490  *step = item ? (float)IDP_Double(item) : 1.0f;
1491 
1492  item = IDP_GetPropertyTypeFromGroup(idp_ui, "precision", IDP_DOUBLE);
1493  *precision = item ? (float)IDP_Double(item) : 3.0f;
1494 
1495  return;
1496  }
1497  }
1498 
1499  *softmin = fprop->softmin;
1500  *softmax = fprop->softmax;
1501 
1502  if (fprop->range) {
1503  hardmin = -FLT_MAX;
1504  hardmax = FLT_MAX;
1505 
1506  fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1507 
1508  *softmin = max_ff(*softmin, hardmin);
1509  *softmax = min_ff(*softmax, hardmax);
1510  }
1511  else if (fprop->range_ex) {
1512  hardmin = -FLT_MAX;
1513  hardmax = FLT_MAX;
1514 
1515  fprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1516 
1517  *softmin = max_ff(*softmin, hardmin);
1518  *softmax = min_ff(*softmax, hardmax);
1519  }
1520 
1521  *step = fprop->step;
1522  *precision = (float)fprop->precision;
1523 }
1524 
1526 {
1527  float min, max;
1528 
1529  RNA_property_float_range(ptr, prop, &min, &max);
1530 
1531  if (*value < min) {
1532  *value = min;
1533  return -1;
1534  }
1535  if (*value > max) {
1536  *value = max;
1537  return 1;
1538  }
1539  return 0;
1540 }
1541 
1543 {
1544  int min, max;
1545 
1546  RNA_property_int_range(ptr, prop, &min, &max);
1547 
1548  if (*value < min) {
1549  *value = min;
1550  return -1;
1551  }
1552  if (*value > max) {
1553  *value = max;
1554  return 1;
1555  }
1556  return 0;
1557 }
1558 
1559 /* this is the max length including \0 terminator.
1560  * '0' used when their is no maximum */
1562 {
1564  return sprop->maxlength;
1565 }
1566 
1568 {
1569  prop = rna_ensure_property(prop);
1570 
1571  if (prop->type == PROP_POINTER) {
1572  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1573 
1574  if (pprop->type_fn) {
1575  return pprop->type_fn(ptr);
1576  }
1577  if (pprop->type) {
1578  return pprop->type;
1579  }
1580  }
1581  else if (prop->type == PROP_COLLECTION) {
1583 
1584  if (cprop->item_type) {
1585  return cprop->item_type;
1586  }
1587  }
1588  /* ignore other types, RNA_struct_find_nested calls with unchecked props */
1589 
1590  return &RNA_UnknownType;
1591 }
1592 
1594 {
1595  prop = rna_ensure_property(prop);
1596 
1597  if (prop->type == PROP_POINTER) {
1598  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1599 
1600  if (pprop->poll) {
1601  if (rna_idproperty_check(&prop, ptr)) {
1602  return ((PropPointerPollFuncPy)pprop->poll)(ptr, *value, prop);
1603  }
1604  return pprop->poll(ptr, *value);
1605  }
1606 
1607  return 1;
1608  }
1609 
1610  printf("%s: %s is not a pointer property.\n", __func__, prop->identifier);
1611  return 0;
1612 }
1613 
1615  PointerRNA *ptr,
1616  PropertyRNA *prop,
1617  const bool use_static,
1618  const EnumPropertyItem **r_item,
1619  int *r_totitem,
1620  bool *r_free)
1621 {
1623 
1624  *r_free = false;
1625 
1626  if (!use_static && (eprop->item_fn != NULL)) {
1627  const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
1629  (ptr->owner_id == NULL));
1630  if (C != NULL || no_context) {
1631  const EnumPropertyItem *item;
1632 
1633  item = eprop->item_fn(no_context ? NULL : C, ptr, prop, r_free);
1634 
1635  /* any callbacks returning NULL should be fixed */
1636  BLI_assert(item != NULL);
1637 
1638  if (r_totitem) {
1639  int tot;
1640  for (tot = 0; item[tot].identifier; tot++) {
1641  /* pass */
1642  }
1643  *r_totitem = tot;
1644  }
1645 
1646  *r_item = item;
1647  return;
1648  }
1649  }
1650 
1651  *r_item = eprop->item;
1652  if (r_totitem) {
1653  *r_totitem = eprop->totitem;
1654  }
1655 }
1656 
1658  PointerRNA *ptr,
1659  PropertyRNA *prop,
1660  const EnumPropertyItem **r_item,
1661  int *r_totitem,
1662  bool *r_free)
1663 {
1664  RNA_property_enum_items_ex(C, ptr, prop, false, r_item, r_totitem, r_free);
1665 }
1666 
1667 #ifdef WITH_INTERNATIONAL
1668 static void property_enum_translate(PropertyRNA *prop,
1669  EnumPropertyItem **r_item,
1670  const int *totitem,
1671  bool *r_free)
1672 {
1673  if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
1674  int i;
1675 
1676  /* Note: Only do those tests once, and then use BLT_pgettext. */
1677  bool do_iface = BLT_translate_iface();
1678  bool do_tooltip = BLT_translate_tooltips();
1679  EnumPropertyItem *nitem;
1680 
1681  if (!(do_iface || do_tooltip)) {
1682  return;
1683  }
1684 
1685  if (*r_free) {
1686  nitem = *r_item;
1687  }
1688  else {
1689  const EnumPropertyItem *item = *r_item;
1690  int tot;
1691 
1692  if (totitem) {
1693  tot = *totitem;
1694  }
1695  else {
1696  /* count */
1697  for (tot = 0; item[tot].identifier; tot++) {
1698  /* pass */
1699  }
1700  }
1701 
1702  nitem = MEM_mallocN(sizeof(EnumPropertyItem) * (tot + 1), "enum_items_gettexted");
1703  memcpy(nitem, item, sizeof(EnumPropertyItem) * (tot + 1));
1704 
1705  *r_free = true;
1706  }
1707 
1708  for (i = 0; nitem[i].identifier; i++) {
1709  if (nitem[i].name && do_iface) {
1710  nitem[i].name = BLT_pgettext(prop->translation_context, nitem[i].name);
1711  }
1712  if (nitem[i].description && do_tooltip) {
1713  nitem[i].description = BLT_pgettext(NULL, nitem[i].description);
1714  }
1715  }
1716 
1717  *r_item = nitem;
1718  }
1719 }
1720 #endif
1721 
1723  PointerRNA *ptr,
1724  PropertyRNA *prop,
1725  const EnumPropertyItem **r_item,
1726  int *r_totitem,
1727  bool *r_free)
1728 {
1729  RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
1730 
1731 #ifdef WITH_INTERNATIONAL
1732  /* Normally dropping 'const' is _not_ ok, in this case it's only modified if we own the memory
1733  * so allow the exception (callers are creating new arrays in this case). */
1734  property_enum_translate(prop, (EnumPropertyItem **)r_item, r_totitem, r_free);
1735 #endif
1736 }
1737 
1739  PointerRNA *ptr,
1740  PropertyRNA *prop,
1741  const EnumPropertyItem **r_item,
1742  int *r_totitem,
1743  bool *r_free)
1744 {
1746  int mem_size = sizeof(EnumPropertyItem) * (eprop->totitem + 1);
1747  /* first return all items */
1748  EnumPropertyItem *item_array = MEM_mallocN(mem_size, "enum_gettext_all");
1749  *r_free = true;
1750  memcpy(item_array, eprop->item, mem_size);
1751 
1752  if (r_totitem) {
1753  *r_totitem = eprop->totitem;
1754  }
1755 
1756  if (eprop->item_fn != NULL) {
1757  const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
1759  (ptr->owner_id == NULL));
1760  if (C != NULL || no_context) {
1761  const EnumPropertyItem *item;
1762  int i;
1763  bool free = false;
1764 
1765  item = eprop->item_fn(no_context ? NULL : NULL, ptr, prop, &free);
1766 
1767  /* any callbacks returning NULL should be fixed */
1768  BLI_assert(item != NULL);
1769 
1770  for (i = 0; i < eprop->totitem; i++) {
1771  bool exists = false;
1772  int i_fixed;
1773 
1774  /* Items that do not exist on list are returned,
1775  * but have their names/identifiers NULL'ed out. */
1776  for (i_fixed = 0; item[i_fixed].identifier; i_fixed++) {
1777  if (STREQ(item[i_fixed].identifier, item_array[i].identifier)) {
1778  exists = true;
1779  break;
1780  }
1781  }
1782 
1783  if (!exists) {
1784  item_array[i].name = NULL;
1785  item_array[i].identifier = "";
1786  }
1787  }
1788 
1789  if (free) {
1790  MEM_freeN((void *)item);
1791  }
1792  }
1793  }
1794 
1795 #ifdef WITH_INTERNATIONAL
1796  property_enum_translate(prop, &item_array, r_totitem, r_free);
1797 #endif
1798  *r_item = item_array;
1799 }
1800 
1802  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
1803 {
1804  const EnumPropertyItem *item;
1805  bool free;
1806  bool found;
1807 
1808  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1809 
1810  if (item) {
1811  const int i = RNA_enum_from_identifier(item, identifier);
1812  if (i != -1) {
1813  *r_value = item[i].value;
1814  found = true;
1815  }
1816  else {
1817  found = false;
1818  }
1819 
1820  if (free) {
1821  MEM_freeN((void *)item);
1822  }
1823  }
1824  else {
1825  found = false;
1826  }
1827  return found;
1828 }
1829 
1830 bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
1831 {
1832  const int i = RNA_enum_from_value(item, value);
1833  if (i != -1) {
1834  *r_identifier = item[i].identifier;
1835  return true;
1836  }
1837  return false;
1838 }
1839 
1841  const int value,
1842  const char **r_identifier)
1843 {
1844  int index = 0;
1845  for (; item->identifier; item++) {
1846  if (item->identifier[0] && item->value & value) {
1847  r_identifier[index++] = item->identifier;
1848  }
1849  }
1850  r_identifier[index] = NULL;
1851  return index;
1852 }
1853 
1854 bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
1855 {
1856  const int i = RNA_enum_from_value(item, value);
1857  if (i != -1) {
1858  *r_name = item[i].name;
1859  return true;
1860  }
1861  return false;
1862 }
1863 
1865  const int value,
1866  const char **r_description)
1867 {
1868  const int i = RNA_enum_from_value(item, value);
1869  if (i != -1) {
1870  *r_description = item[i].description;
1871  return true;
1872  }
1873  return false;
1874 }
1875 
1876 int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
1877 {
1878  int i = 0;
1879  for (; item->identifier; item++, i++) {
1880  if (item->identifier[0] && STREQ(item->identifier, identifier)) {
1881  return i;
1882  }
1883  }
1884  return -1;
1885 }
1886 
1891 int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
1892 {
1893  int i = 0;
1894  for (; item->identifier; item++, i++) {
1895  if (item->identifier[0] && STREQ(item->name, name)) {
1896  return i;
1897  }
1898  }
1899  return -1;
1900 }
1901 
1902 int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
1903 {
1904  int i = 0;
1905  for (; item->identifier; item++, i++) {
1906  if (item->identifier[0] && item->value == value) {
1907  return i;
1908  }
1909  }
1910  return -1;
1911 }
1912 
1913 unsigned int RNA_enum_items_count(const EnumPropertyItem *item)
1914 {
1915  unsigned int i = 0;
1916 
1917  while (item->identifier) {
1918  item++;
1919  i++;
1920  }
1921 
1922  return i;
1923 }
1924 
1926  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
1927 {
1928  const EnumPropertyItem *item = NULL;
1929  bool free;
1930 
1931  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1932  if (item) {
1933  bool result;
1934  result = RNA_enum_identifier(item, value, identifier);
1935  if (free) {
1936  MEM_freeN((void *)item);
1937  }
1938  return result;
1939  }
1940  return false;
1941 }
1942 
1944  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
1945 {
1946  const EnumPropertyItem *item = NULL;
1947  bool free;
1948 
1949  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1950  if (item) {
1951  bool result;
1952  result = RNA_enum_name(item, value, name);
1953  if (free) {
1954  MEM_freeN((void *)item);
1955  }
1956 
1957  return result;
1958  }
1959  return false;
1960 }
1961 
1963  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
1964 {
1965  bool result;
1966 
1967  result = RNA_property_enum_name(C, ptr, prop, value, name);
1968 
1969  if (result) {
1970  if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
1971  if (BLT_translate_iface()) {
1972  *name = BLT_pgettext(prop->translation_context, *name);
1973  }
1974  }
1975  }
1976 
1977  return result;
1978 }
1979 
1981  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
1982 {
1983  const EnumPropertyItem *item = NULL;
1984  bool free;
1985 
1986  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
1987  if (item) {
1988  const int i = RNA_enum_from_value(item, value);
1989  bool result;
1990 
1991  if (i != -1) {
1992  *r_item = item[i];
1993  result = true;
1994  }
1995  else {
1996  result = false;
1997  }
1998 
1999  if (free) {
2000  MEM_freeN((void *)item);
2001  }
2002 
2003  return result;
2004  }
2005  return false;
2006 }
2007 
2009  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
2010 {
2011  bool result;
2012 
2013  result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item);
2014 
2015  if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
2016  if (BLT_translate_iface()) {
2017  r_item->name = BLT_pgettext(prop->translation_context, r_item->name);
2018  }
2019  }
2020 
2021  return result;
2022 }
2023 
2025  bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
2026 {
2027  const EnumPropertyItem *item = NULL;
2028  bool free;
2029 
2030  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
2031  if (item) {
2032  int result;
2033  result = RNA_enum_bitflag_identifiers(item, value, identifier);
2034  if (free) {
2035  MEM_freeN((void *)item);
2036  }
2037 
2038  return result;
2039  }
2040  return 0;
2041 }
2042 
2043 const char *RNA_property_ui_name(const PropertyRNA *prop)
2044 {
2046 }
2047 
2048 const char *RNA_property_ui_name_raw(const PropertyRNA *prop)
2049 {
2050  return rna_ensure_property_name(prop);
2051 }
2052 
2054 {
2055  return TIP_(rna_ensure_property_description(prop));
2056 }
2057 
2059 {
2060  return rna_ensure_property_description(prop);
2061 }
2062 
2064 {
2066 }
2067 
2069 {
2070  return rna_ensure_property((PropertyRNA *)prop)->icon;
2071 }
2072 
2074 {
2075  ID *id = ptr->owner_id;
2076  int flag;
2077  const char *dummy_info;
2078 
2079  PropertyRNA *prop = rna_ensure_property(prop_orig);
2080  flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
2081 
2082  return (
2083  (flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 &&
2084  (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
2085  (!ID_IS_OVERRIDE_LIBRARY(id) || RNA_property_overridable_get(ptr, prop_orig)))));
2086 }
2087 
2092 bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
2093 {
2094  ID *id = ptr->owner_id;
2095  int flag;
2096 
2097  PropertyRNA *prop_type = rna_ensure_property(prop);
2098  *r_info = "";
2099 
2100  /* get flag */
2101  if (prop_type->editable) {
2102  flag = prop_type->editable(ptr, r_info);
2103  }
2104  else {
2105  flag = prop_type->flag;
2106  if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER)) {
2107  *r_info = N_("This property is for internal use only and can't be edited");
2108  }
2109  }
2110 
2111  /* property from linked data-block */
2112  if (id) {
2113  if (ID_IS_LINKED(id) && (prop_type->flag & PROP_LIB_EXCEPTION) == 0) {
2114  if (!(*r_info)[0]) {
2115  *r_info = N_("Can't edit this property from a linked data-block");
2116  }
2117  return false;
2118  }
2119  if (ID_IS_OVERRIDE_LIBRARY(id)) {
2120  if (!RNA_property_overridable_get(ptr, prop)) {
2121  if (!(*r_info)[0]) {
2122  *r_info = N_("Can't edit this property from an override data-block");
2123  }
2124  return false;
2125  }
2126  }
2127  }
2128 
2129  return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0);
2130 }
2131 
2133 {
2134  int flag;
2135  const char *dummy_info;
2136 
2137  prop = rna_ensure_property(prop);
2138  flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
2139  return (flag & PROP_EDITABLE) != 0;
2140 }
2141 
2142 /* same as RNA_property_editable(), except this checks individual items in an array */
2144 {
2145  ID *id;
2146  int flag;
2147 
2148  BLI_assert(index >= 0);
2149 
2150  prop = rna_ensure_property(prop);
2151 
2152  flag = prop->flag;
2153 
2154  if (prop->editable) {
2155  const char *dummy_info;
2156  flag &= prop->editable(ptr, &dummy_info);
2157  }
2158 
2159  if (prop->itemeditable) {
2160  flag &= prop->itemeditable(ptr, index);
2161  }
2162 
2163  id = ptr->owner_id;
2164 
2165  return (flag & PROP_EDITABLE) && (!id || !ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION));
2166 }
2167 
2169 {
2170  /* check that base ID-block can support animation data */
2172  return false;
2173  }
2174 
2175  prop = rna_ensure_property(prop);
2176 
2177  if (!(prop->flag & PROP_ANIMATABLE)) {
2178  return false;
2179  }
2180 
2181  return (prop->flag & PROP_EDITABLE) != 0;
2182 }
2183 
2185 {
2186  int len = 1, index;
2187  bool driven, special;
2188 
2189  if (!prop) {
2190  return false;
2191  }
2192 
2193  if (RNA_property_array_check(prop)) {
2195  }
2196 
2197  for (index = 0; index < len; index++) {
2198  if (BKE_fcurve_find_by_rna(ptr, prop, index, NULL, NULL, &driven, &special)) {
2199  return true;
2200  }
2201  }
2202 
2203  return false;
2204 }
2205 /* this function is to check if its possible to create a valid path from the ID
2206  * its slow so don't call in a loop */
2208 {
2209  char *path = RNA_path_from_ID_to_property(ptr, prop);
2210  bool ret = false;
2211 
2212  if (path) {
2213  PointerRNA id_ptr;
2214  PointerRNA r_ptr;
2215  PropertyRNA *r_prop;
2216 
2217  RNA_id_pointer_create(ptr->owner_id, &id_ptr);
2218  if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == true) {
2219  ret = (prop == r_prop);
2220  }
2221  MEM_freeN(path);
2222  }
2223 
2224  return ret;
2225 }
2226 
2228  bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
2229 {
2230  const bool is_rna = (prop->magic == RNA_MAGIC);
2231  prop = rna_ensure_property(prop);
2232 
2233  if (is_rna) {
2234  if (prop->update) {
2235  /* ideally no context would be needed for update, but there's some
2236  * parts of the code that need it still, so we have this exception */
2237  if (prop->flag & PROP_CONTEXT_UPDATE) {
2238  if (C) {
2240  ((ContextPropUpdateFunc)prop->update)(C, ptr, prop);
2241  }
2242  else {
2243  ((ContextUpdateFunc)prop->update)(C, ptr);
2244  }
2245  }
2246  }
2247  else {
2248  prop->update(bmain, scene, ptr);
2249  }
2250  }
2251 
2252 #if 1
2253  /* TODO(campbell): Should eventually be replaced entirely by message bus (below)
2254  * for now keep since COW, bugs are hard to track when we have other missing updates. */
2255  if (prop->noteflag) {
2257  }
2258 #endif
2259 
2260  /* if C is NULL, we're updating from animation.
2261  * avoid slow-down from f-curves by not publishing (for now). */
2262  if (C != NULL) {
2263  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
2264  /* we could add NULL check, for now don't */
2265  WM_msg_publish_rna(mbus, ptr, prop);
2266  }
2267  if (ptr->owner_id != NULL && ((prop->flag & PROP_NO_DEG_UPDATE) == 0)) {
2268  const short id_type = GS(ptr->owner_id->name);
2269  if (ID_TYPE_IS_COW(id_type)) {
2271  }
2272  }
2273  /* End message bus. */
2274  }
2275 
2276  if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
2277 
2278  /* Disclaimer: this logic is not applied consistently, causing some confusing behavior.
2279  *
2280  * - When animated (which skips update functions).
2281  * - When ID-properties are edited via Python (since RNA properties aren't used in this case).
2282  *
2283  * Adding updates will add a lot of overhead in the case of animation.
2284  * For Python it may cause unexpected slow-downs for developers using ID-properties
2285  * for data storage. Further, the root ID isn't available with nested data-structures.
2286  *
2287  * So editing custom properties only causes updates in the UI,
2288  * keep this exception because it happens to be useful for driving settings.
2289  * Python developers on the other hand will need to manually 'update_tag', see: T74000. */
2292 
2293  /* When updating an ID pointer property, tag depsgraph for update. */
2295  DEG_relations_tag_update(bmain);
2296  }
2297 
2299  /* Not nice as well, but the only way to make sure material preview
2300  * is updated with custom nodes.
2301  */
2302  if ((prop->flag & PROP_IDPROPERTY) != 0 && (ptr->owner_id != NULL) &&
2303  (GS(ptr->owner_id->name) == ID_NT)) {
2305  }
2306  }
2307 }
2308 
2309 /* must keep in sync with 'rna_property_update'
2310  * note, its possible this returns a false positive in the case of PROP_CONTEXT_UPDATE
2311  * but this isn't likely to be a performance problem. */
2313 {
2314  return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
2315 }
2316 
2318 {
2320 }
2321 
2323 {
2324  rna_property_update(NULL, bmain, scene, ptr, prop);
2325 }
2326 
2327 /* ---------------------------------------------------------------------- */
2328 
2329 /* Property Data */
2330 
2332 {
2333  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2334  IDProperty *idprop;
2335  bool value;
2336 
2338  BLI_assert(RNA_property_array_check(prop) == false);
2339 
2340  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2341  value = IDP_Int(idprop) != 0;
2342  }
2343  else if (bprop->get) {
2344  value = bprop->get(ptr);
2345  }
2346  else if (bprop->get_ex) {
2347  value = bprop->get_ex(ptr, prop);
2348  }
2349  else {
2350  value = bprop->defaultvalue;
2351  }
2352 
2353  BLI_assert(ELEM(value, false, true));
2354 
2355  return value;
2356 }
2357 
2359 {
2360  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2361  IDProperty *idprop;
2362 
2364  BLI_assert(RNA_property_array_check(prop) == false);
2365  BLI_assert(ELEM(value, false, true));
2366 
2367  /* just in case other values are passed */
2368  BLI_assert(ELEM(value, true, false));
2369 
2370  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2371  IDP_Int(idprop) = (int)value;
2372  rna_idproperty_touch(idprop);
2373  }
2374  else if (bprop->set) {
2375  bprop->set(ptr, value);
2376  }
2377  else if (bprop->set_ex) {
2378  bprop->set_ex(ptr, prop, value);
2379  }
2380  else if (prop->flag & PROP_EDITABLE) {
2381  IDPropertyTemplate val = {0};
2382  IDProperty *group;
2383 
2384  val.i = value;
2385 
2386  group = RNA_struct_idprops(ptr, 1);
2387  if (group) {
2388  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
2389  }
2390  }
2391 }
2392 
2394  const bool *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
2395 {
2396  if (defarr && defarr_length > 0) {
2397  defarr_length = MIN2(defarr_length, out_length);
2398  memcpy(r_values, defarr, sizeof(bool) * defarr_length);
2399  }
2400  else {
2401  defarr_length = 0;
2402  }
2403 
2404  for (int i = defarr_length; i < out_length; i++) {
2405  r_values[i] = defvalue;
2406  }
2407 }
2408 
2410  BoolPropertyRNA *bprop,
2411  bool *r_values)
2412 {
2413  int length = bprop->property.totarraylength;
2414  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)bprop);
2415 
2417  bprop->defaultarray, length, bprop->defaultvalue, out_length, r_values);
2418 }
2419 
2421 {
2422  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2423  IDProperty *idprop;
2424 
2426  BLI_assert(RNA_property_array_check(prop) != false);
2427 
2428  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2429  if (prop->arraydimension == 0) {
2430  values[0] = RNA_property_boolean_get(ptr, prop);
2431  }
2432  else {
2433  int *values_src = IDP_Array(idprop);
2434  for (uint i = 0; i < idprop->len; i++) {
2435  values[i] = (bool)values_src[i];
2436  }
2437  }
2438  }
2439  else if (prop->arraydimension == 0) {
2440  values[0] = RNA_property_boolean_get(ptr, prop);
2441  }
2442  else if (bprop->getarray) {
2443  bprop->getarray(ptr, values);
2444  }
2445  else if (bprop->getarray_ex) {
2446  bprop->getarray_ex(ptr, prop, values);
2447  }
2448  else {
2450  }
2451 }
2452 
2454 {
2455  bool tmp[RNA_MAX_ARRAY_LENGTH];
2457  bool value;
2458 
2460  BLI_assert(RNA_property_array_check(prop) != false);
2461  BLI_assert(index >= 0);
2462  BLI_assert(index < len);
2463 
2464  if (len <= RNA_MAX_ARRAY_LENGTH) {
2465  RNA_property_boolean_get_array(ptr, prop, tmp);
2466  value = tmp[index];
2467  }
2468  else {
2469  bool *tmparray;
2470 
2471  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2472  RNA_property_boolean_get_array(ptr, prop, tmparray);
2473  value = tmparray[index];
2474  MEM_freeN(tmparray);
2475  }
2476 
2477  BLI_assert(ELEM(value, false, true));
2478 
2479  return value;
2480 }
2481 
2483 {
2484  BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2485  IDProperty *idprop;
2486 
2488  BLI_assert(RNA_property_array_check(prop) != false);
2489 
2490  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2491  if (prop->arraydimension == 0) {
2492  IDP_Int(idprop) = values[0];
2493  }
2494  else {
2495  int *values_dst = IDP_Array(idprop);
2496  for (uint i = 0; i < idprop->len; i++) {
2497  values_dst[i] = (int)values[i];
2498  }
2499  }
2500  rna_idproperty_touch(idprop);
2501  }
2502  else if (prop->arraydimension == 0) {
2503  RNA_property_boolean_set(ptr, prop, values[0]);
2504  }
2505  else if (bprop->setarray) {
2506  bprop->setarray(ptr, values);
2507  }
2508  else if (bprop->setarray_ex) {
2509  bprop->setarray_ex(ptr, prop, values);
2510  }
2511  else if (prop->flag & PROP_EDITABLE) {
2512  IDPropertyTemplate val = {0};
2513  IDProperty *group;
2514 
2515  val.array.len = prop->totarraylength;
2516  val.array.type = IDP_INT;
2517 
2518  group = RNA_struct_idprops(ptr, 1);
2519  if (group) {
2520  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
2521  IDP_AddToGroup(group, idprop);
2522  int *values_dst = IDP_Array(idprop);
2523  for (uint i = 0; i < idprop->len; i++) {
2524  values_dst[i] = (int)values[i];
2525  }
2526  }
2527  }
2528 }
2529 
2530 void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
2531 {
2532  bool tmp[RNA_MAX_ARRAY_LENGTH];
2534 
2536  BLI_assert(RNA_property_array_check(prop) != false);
2537  BLI_assert(index >= 0);
2538  BLI_assert(index < len);
2539  BLI_assert(ELEM(value, false, true));
2540 
2541  if (len <= RNA_MAX_ARRAY_LENGTH) {
2542  RNA_property_boolean_get_array(ptr, prop, tmp);
2543  tmp[index] = value;
2544  RNA_property_boolean_set_array(ptr, prop, tmp);
2545  }
2546  else {
2547  bool *tmparray;
2548 
2549  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2550  RNA_property_boolean_get_array(ptr, prop, tmparray);
2551  tmparray[index] = value;
2552  RNA_property_boolean_set_array(ptr, prop, tmparray);
2553  MEM_freeN(tmparray);
2554  }
2555 }
2556 
2558 {
2560 
2562  BLI_assert(RNA_property_array_check(prop) == false);
2563  BLI_assert(ELEM(bprop->defaultvalue, false, true));
2564 
2565  return bprop->defaultvalue;
2566 }
2567 
2569 {
2571 
2573  BLI_assert(RNA_property_array_check(prop) != false);
2574 
2575  if (prop->arraydimension == 0) {
2576  values[0] = bprop->defaultvalue;
2577  }
2578  else {
2580  }
2581 }
2582 
2584 {
2585  bool tmp[RNA_MAX_ARRAY_LENGTH];
2587 
2589  BLI_assert(RNA_property_array_check(prop) != false);
2590  BLI_assert(index >= 0);
2591  BLI_assert(index < len);
2592 
2593  if (len <= RNA_MAX_ARRAY_LENGTH) {
2595  return tmp[index];
2596  }
2597  bool *tmparray, value;
2598 
2599  tmparray = MEM_mallocN(sizeof(bool) * len, __func__);
2601  value = tmparray[index];
2602  MEM_freeN(tmparray);
2603 
2604  return value;
2605 }
2606 
2608 {
2609  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2610  IDProperty *idprop;
2611 
2613  BLI_assert(RNA_property_array_check(prop) == false);
2614 
2615  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2616  return IDP_Int(idprop);
2617  }
2618  if (iprop->get) {
2619  return iprop->get(ptr);
2620  }
2621  if (iprop->get_ex) {
2622  return iprop->get_ex(ptr, prop);
2623  }
2624  return iprop->defaultvalue;
2625 }
2626 
2628 {
2629  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2630  IDProperty *idprop;
2631 
2633  BLI_assert(RNA_property_array_check(prop) == false);
2634  /* useful to check on bad values but set function should clamp */
2635  /* BLI_assert(RNA_property_int_clamp(ptr, prop, &value) == 0); */
2636 
2637  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2638  RNA_property_int_clamp(ptr, prop, &value);
2639  IDP_Int(idprop) = value;
2640  rna_idproperty_touch(idprop);
2641  }
2642  else if (iprop->set) {
2643  iprop->set(ptr, value);
2644  }
2645  else if (iprop->set_ex) {
2646  iprop->set_ex(ptr, prop, value);
2647  }
2648  else if (prop->flag & PROP_EDITABLE) {
2649  IDPropertyTemplate val = {0};
2650  IDProperty *group;
2651 
2652  RNA_property_int_clamp(ptr, prop, &value);
2653 
2654  val.i = value;
2655 
2656  group = RNA_struct_idprops(ptr, 1);
2657  if (group) {
2658  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
2659  }
2660  }
2661 }
2662 
2664  const int *defarr, int defarr_length, int defvalue, int out_length, int *r_values)
2665 {
2666  if (defarr && defarr_length > 0) {
2667  defarr_length = MIN2(defarr_length, out_length);
2668  memcpy(r_values, defarr, sizeof(int) * defarr_length);
2669  }
2670  else {
2671  defarr_length = 0;
2672  }
2673 
2674  for (int i = defarr_length; i < out_length; i++) {
2675  r_values[i] = defvalue;
2676  }
2677 }
2678 
2680  IntPropertyRNA *iprop,
2681  int *r_values)
2682 {
2683  int length = iprop->property.totarraylength;
2684  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)iprop);
2685 
2687  iprop->defaultarray, length, iprop->defaultvalue, out_length, r_values);
2688 }
2689 
2691 {
2692  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2693  IDProperty *idprop;
2694 
2696  BLI_assert(RNA_property_array_check(prop) != false);
2697 
2698  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2699  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2700  (prop->flag & PROP_IDPROPERTY));
2701  if (prop->arraydimension == 0) {
2702  values[0] = RNA_property_int_get(ptr, prop);
2703  }
2704  else {
2705  memcpy(values, IDP_Array(idprop), sizeof(int) * idprop->len);
2706  }
2707  }
2708  else if (prop->arraydimension == 0) {
2709  values[0] = RNA_property_int_get(ptr, prop);
2710  }
2711  else if (iprop->getarray) {
2712  iprop->getarray(ptr, values);
2713  }
2714  else if (iprop->getarray_ex) {
2715  iprop->getarray_ex(ptr, prop, values);
2716  }
2717  else {
2719  }
2720 }
2721 
2723 {
2724  const int array_len = RNA_property_array_length(ptr, prop);
2725 
2726  if (array_len <= 0) {
2727  values[0] = 0;
2728  values[1] = 0;
2729  }
2730  else if (array_len == 1) {
2731  RNA_property_int_get_array(ptr, prop, values);
2732  values[1] = values[0];
2733  }
2734  else {
2735  int arr_stack[32];
2736  int *arr;
2737  int i;
2738 
2739  if (array_len > 32) {
2740  arr = MEM_mallocN(sizeof(int) * array_len, __func__);
2741  }
2742  else {
2743  arr = arr_stack;
2744  }
2745 
2746  RNA_property_int_get_array(ptr, prop, arr);
2747  values[0] = values[1] = arr[0];
2748  for (i = 1; i < array_len; i++) {
2749  values[0] = MIN2(values[0], arr[i]);
2750  values[1] = MAX2(values[1], arr[i]);
2751  }
2752 
2753  if (arr != arr_stack) {
2754  MEM_freeN(arr);
2755  }
2756  }
2757 }
2758 
2760 {
2761  int tmp[RNA_MAX_ARRAY_LENGTH];
2763 
2765  BLI_assert(RNA_property_array_check(prop) != false);
2766  BLI_assert(index >= 0);
2767  BLI_assert(index < len);
2768 
2769  if (len <= RNA_MAX_ARRAY_LENGTH) {
2770  RNA_property_int_get_array(ptr, prop, tmp);
2771  return tmp[index];
2772  }
2773  int *tmparray, value;
2774 
2775  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2776  RNA_property_int_get_array(ptr, prop, tmparray);
2777  value = tmparray[index];
2778  MEM_freeN(tmparray);
2779 
2780  return value;
2781 }
2782 
2783 void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
2784 {
2785  IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2786  IDProperty *idprop;
2787 
2789  BLI_assert(RNA_property_array_check(prop) != false);
2790 
2791  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2792  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
2793  (prop->flag & PROP_IDPROPERTY));
2794  if (prop->arraydimension == 0) {
2795  IDP_Int(idprop) = values[0];
2796  }
2797  else {
2798  memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
2799  }
2800 
2801  rna_idproperty_touch(idprop);
2802  }
2803  else if (prop->arraydimension == 0) {
2804  RNA_property_int_set(ptr, prop, values[0]);
2805  }
2806  else if (iprop->setarray) {
2807  iprop->setarray(ptr, values);
2808  }
2809  else if (iprop->setarray_ex) {
2810  iprop->setarray_ex(ptr, prop, values);
2811  }
2812  else if (prop->flag & PROP_EDITABLE) {
2813  IDPropertyTemplate val = {0};
2814  IDProperty *group;
2815 
2816  /* TODO: RNA_property_int_clamp_array(ptr, prop, &value); */
2817 
2818  val.array.len = prop->totarraylength;
2819  val.array.type = IDP_INT;
2820 
2821  group = RNA_struct_idprops(ptr, 1);
2822  if (group) {
2823  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
2824  IDP_AddToGroup(group, idprop);
2825  memcpy(IDP_Array(idprop), values, sizeof(int) * idprop->len);
2826  }
2827  }
2828 }
2829 
2830 void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
2831 {
2832  int tmp[RNA_MAX_ARRAY_LENGTH];
2834 
2836  BLI_assert(RNA_property_array_check(prop) != false);
2837  BLI_assert(index >= 0);
2838  BLI_assert(index < len);
2839 
2840  if (len <= RNA_MAX_ARRAY_LENGTH) {
2841  RNA_property_int_get_array(ptr, prop, tmp);
2842  tmp[index] = value;
2843  RNA_property_int_set_array(ptr, prop, tmp);
2844  }
2845  else {
2846  int *tmparray;
2847 
2848  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2849  RNA_property_int_get_array(ptr, prop, tmparray);
2850  tmparray[index] = value;
2851  RNA_property_int_set_array(ptr, prop, tmparray);
2852  MEM_freeN(tmparray);
2853  }
2854 }
2855 
2857 {
2859 
2860  if (prop->magic != RNA_MAGIC) {
2861  /* attempt to get the local ID values */
2862  const IDProperty *idp_ui = rna_idproperty_ui(prop);
2863 
2864  if (idp_ui) {
2865  IDProperty *item;
2866 
2867  item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_INT);
2868  return item ? IDP_Int(item) : iprop->defaultvalue;
2869  }
2870  }
2871 
2872  return iprop->defaultvalue;
2873 }
2874 
2876 {
2877  if (value != 0) {
2878  IDPropertyTemplate val = {
2879  .i = value,
2880  };
2881  return rna_idproperty_ui_set_default(ptr, prop, IDP_INT, &val);
2882  }
2884 }
2885 
2887 {
2889 
2891  BLI_assert(RNA_property_array_check(prop) != false);
2892 
2893  if (prop->magic != RNA_MAGIC) {
2895 
2896  const IDProperty *idp_ui = rna_idproperty_ui(prop);
2897  IDProperty *item = idp_ui ? IDP_GetPropertyFromGroup(idp_ui, "default") : NULL;
2898 
2899  int defval = (item && item->type == IDP_INT) ? IDP_Int(item) : iprop->defaultvalue;
2900 
2901  if (item && item->type == IDP_ARRAY && item->subtype == IDP_INT) {
2903  IDP_Array(item), item->len, defval, length, values);
2904  }
2905  else {
2907  }
2908  }
2909  else if (prop->arraydimension == 0) {
2910  values[0] = iprop->defaultvalue;
2911  }
2912  else {
2914  }
2915 }
2916 
2918 {
2919  int tmp[RNA_MAX_ARRAY_LENGTH];
2921 
2923  BLI_assert(RNA_property_array_check(prop) != false);
2924  BLI_assert(index >= 0);
2925  BLI_assert(index < len);
2926 
2927  if (len <= RNA_MAX_ARRAY_LENGTH) {
2929  return tmp[index];
2930  }
2931  int *tmparray, value;
2932 
2933  tmparray = MEM_mallocN(sizeof(int) * len, __func__);
2934  RNA_property_int_get_default_array(ptr, prop, tmparray);
2935  value = tmparray[index];
2936  MEM_freeN(tmparray);
2937 
2938  return value;
2939 }
2940 
2942 {
2943  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2944  IDProperty *idprop;
2945 
2947  BLI_assert(RNA_property_array_check(prop) == false);
2948 
2949  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2950  if (idprop->type == IDP_FLOAT) {
2951  return IDP_Float(idprop);
2952  }
2953  return (float)IDP_Double(idprop);
2954  }
2955  if (fprop->get) {
2956  return fprop->get(ptr);
2957  }
2958  if (fprop->get_ex) {
2959  return fprop->get_ex(ptr, prop);
2960  }
2961  return fprop->defaultvalue;
2962 }
2963 
2965 {
2966  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2967  IDProperty *idprop;
2968 
2970  BLI_assert(RNA_property_array_check(prop) == false);
2971  /* useful to check on bad values but set function should clamp */
2972  /* BLI_assert(RNA_property_float_clamp(ptr, prop, &value) == 0); */
2973 
2974  if ((idprop = rna_idproperty_check(&prop, ptr))) {
2975  RNA_property_float_clamp(ptr, prop, &value);
2976  if (idprop->type == IDP_FLOAT) {
2977  IDP_Float(idprop) = value;
2978  }
2979  else {
2980  IDP_Double(idprop) = value;
2981  }
2982 
2983  rna_idproperty_touch(idprop);
2984  }
2985  else if (fprop->set) {
2986  fprop->set(ptr, value);
2987  }
2988  else if (fprop->set_ex) {
2989  fprop->set_ex(ptr, prop, value);
2990  }
2991  else if (prop->flag & PROP_EDITABLE) {
2992  IDPropertyTemplate val = {0};
2993  IDProperty *group;
2994 
2995  RNA_property_float_clamp(ptr, prop, &value);
2996 
2997  val.f = value;
2998 
2999  group = RNA_struct_idprops(ptr, 1);
3000  if (group) {
3001  IDP_AddToGroup(group, IDP_New(IDP_FLOAT, &val, prop->identifier));
3002  }
3003  }
3004 }
3005 
3007  const float *defarr, int defarr_length, float defvalue, int out_length, float *r_values)
3008 {
3009  if (defarr && defarr_length > 0) {
3010  defarr_length = MIN2(defarr_length, out_length);
3011  memcpy(r_values, defarr, sizeof(float) * defarr_length);
3012  }
3013  else {
3014  defarr_length = 0;
3015  }
3016 
3017  for (int i = defarr_length; i < out_length; i++) {
3018  r_values[i] = defvalue;
3019  }
3020 }
3021 
3023  FloatPropertyRNA *fprop,
3024  float *r_values)
3025 {
3026  int length = fprop->property.totarraylength;
3027  int out_length = RNA_property_array_length(ptr, (PropertyRNA *)fprop);
3028 
3030  fprop->defaultarray, length, fprop->defaultvalue, out_length, r_values);
3031 }
3032 
3034 {
3035  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
3036  IDProperty *idprop;
3037  int i;
3038 
3040  BLI_assert(RNA_property_array_check(prop) != false);
3041 
3042  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3043  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
3044  (prop->flag & PROP_IDPROPERTY));
3045  if (prop->arraydimension == 0) {
3046  values[0] = RNA_property_float_get(ptr, prop);
3047  }
3048  else if (idprop->subtype == IDP_FLOAT) {
3049  memcpy(values, IDP_Array(idprop), sizeof(float) * idprop->len);
3050  }
3051  else {
3052  for (i = 0; i < idprop->len; i++) {
3053  values[i] = (float)(((double *)IDP_Array(idprop))[i]);
3054  }
3055  }
3056  }
3057  else if (prop->arraydimension == 0) {
3058  values[0] = RNA_property_float_get(ptr, prop);
3059  }
3060  else if (fprop->getarray) {
3061  fprop->getarray(ptr, values);
3062  }
3063  else if (fprop->getarray_ex) {
3064  fprop->getarray_ex(ptr, prop, values);
3065  }
3066  else {
3068  }
3069 }
3070 
3072 {
3073  const int array_len = RNA_property_array_length(ptr, prop);
3074 
3075  if (array_len <= 0) {
3076  values[0] = 0.0f;
3077  values[1] = 0.0f;
3078  }
3079  else if (array_len == 1) {
3080  RNA_property_float_get_array(ptr, prop, values);
3081  values[1] = values[0];
3082  }
3083  else {
3084  float arr_stack[32];
3085  float *arr;
3086  int i;
3087 
3088  if (array_len > 32) {
3089  arr = MEM_mallocN(sizeof(float) * array_len, __func__);
3090  }
3091  else {
3092  arr = arr_stack;
3093  }
3094 
3095  RNA_property_float_get_array(ptr, prop, arr);
3096  values[0] = values[1] = arr[0];
3097  for (i = 1; i < array_len; i++) {
3098  values[0] = MIN2(values[0], arr[i]);
3099  values[1] = MAX2(values[1], arr[i]);
3100  }
3101 
3102  if (arr != arr_stack) {
3103  MEM_freeN(arr);
3104  }
3105  }
3106 }
3107 
3109 {
3110  float tmp[RNA_MAX_ARRAY_LENGTH];
3112 
3114  BLI_assert(RNA_property_array_check(prop) != false);
3115  BLI_assert(index >= 0);
3116  BLI_assert(index < len);
3117 
3118  if (len <= RNA_MAX_ARRAY_LENGTH) {
3119  RNA_property_float_get_array(ptr, prop, tmp);
3120  return tmp[index];
3121  }
3122  float *tmparray, value;
3123 
3124  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
3125  RNA_property_float_get_array(ptr, prop, tmparray);
3126  value = tmparray[index];
3127  MEM_freeN(tmparray);
3128 
3129  return value;
3130 }
3131 
3132 void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
3133 {
3134  FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
3135  IDProperty *idprop;
3136  int i;
3137 
3139  BLI_assert(RNA_property_array_check(prop) != false);
3140 
3141  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3142  BLI_assert(idprop->len == RNA_property_array_length(ptr, prop) ||
3143  (prop->flag & PROP_IDPROPERTY));
3144  if (prop->arraydimension == 0) {
3145  if (idprop->type == IDP_FLOAT) {
3146  IDP_Float(idprop) = values[0];
3147  }
3148  else {
3149  IDP_Double(idprop) = values[0];
3150  }
3151  }
3152  else if (idprop->subtype == IDP_FLOAT) {
3153  memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
3154  }
3155  else {
3156  for (i = 0; i < idprop->len; i++) {
3157  ((double *)IDP_Array(idprop))[i] = values[i];
3158  }
3159  }
3160 
3161  rna_idproperty_touch(idprop);
3162  }
3163  else if (prop->arraydimension == 0) {
3164  RNA_property_float_set(ptr, prop, values[0]);
3165  }
3166  else if (fprop->setarray) {
3167  fprop->setarray(ptr, values);
3168  }
3169  else if (fprop->setarray_ex) {
3170  fprop->setarray_ex(ptr, prop, values);
3171  }
3172  else if (prop->flag & PROP_EDITABLE) {
3173  IDPropertyTemplate val = {0};
3174  IDProperty *group;
3175 
3176  /* TODO: RNA_property_float_clamp_array(ptr, prop, &value); */
3177 
3178  val.array.len = prop->totarraylength;
3179  val.array.type = IDP_FLOAT;
3180 
3181  group = RNA_struct_idprops(ptr, 1);
3182  if (group) {
3183  idprop = IDP_New(IDP_ARRAY, &val, prop->identifier);
3184  IDP_AddToGroup(group, idprop);
3185  memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
3186  }
3187  }
3188 }
3189 
3190 void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
3191 {
3192  float tmp[RNA_MAX_ARRAY_LENGTH];
3194 
3196  BLI_assert(RNA_property_array_check(prop) != false);
3197  BLI_assert(index >= 0);
3198  BLI_assert(index < len);
3199 
3200  if (len <= RNA_MAX_ARRAY_LENGTH) {
3201  RNA_property_float_get_array(ptr, prop, tmp);
3202  tmp[index] = value;
3203  RNA_property_float_set_array(ptr, prop, tmp);
3204  }
3205  else {
3206  float *tmparray;
3207 
3208  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
3209  RNA_property_float_get_array(ptr, prop, tmparray);
3210  tmparray[index] = value;
3211  RNA_property_float_set_array(ptr, prop, tmparray);
3212  MEM_freeN(tmparray);
3213  }
3214 }
3215 
3217 {
3219 
3221  BLI_assert(RNA_property_array_check(prop) == false);
3222 
3223  if (prop->magic != RNA_MAGIC) {
3224  /* attempt to get the local ID values */
3225  const IDProperty *idp_ui = rna_idproperty_ui(prop);
3226 
3227  if (idp_ui) {
3228  IDProperty *item;
3229 
3230  item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_DOUBLE);
3231  return item ? IDP_Double(item) : fprop->defaultvalue;
3232  }
3233  }
3234 
3235  return fprop->defaultvalue;
3236 }
3237 
3239 {
3240  if (value != 0) {
3241  IDPropertyTemplate val = {
3242  .d = value,
3243  };
3244  return rna_idproperty_ui_set_default(ptr, prop, IDP_DOUBLE, &val);
3245  }
3247 }
3248 
3250 {
3252 
3254  BLI_assert(RNA_property_array_check(prop) != false);
3255 
3256  if (prop->magic != RNA_MAGIC) {
3258 
3259  const IDProperty *idp_ui = rna_idproperty_ui(prop);
3260  IDProperty *item = idp_ui ? IDP_GetPropertyFromGroup(idp_ui, "default") : NULL;
3261 
3262  float defval = (item && item->type == IDP_DOUBLE) ? IDP_Double(item) : fprop->defaultvalue;
3263 
3264  if (item && item->type == IDP_ARRAY && item->subtype == IDP_DOUBLE) {
3265  double *defarr = IDP_Array(item);
3266  for (int i = 0; i < length; i++) {
3267  values[i] = (i < item->len) ? (float)defarr[i] : defval;
3268  }
3269  }
3270  else if (item && item->type == IDP_ARRAY && item->subtype == IDP_FLOAT) {
3272  IDP_Array(item), item->len, defval, length, values);
3273  }
3274  else {
3276  }
3277  }
3278  else if (prop->arraydimension == 0) {
3279  values[0] = fprop->defaultvalue;
3280  }
3281  else {
3283  }
3284 }
3285 
3287 {
3288  float tmp[RNA_MAX_ARRAY_LENGTH];
3290 
3292  BLI_assert(RNA_property_array_check(prop) != false);
3293  BLI_assert(index >= 0);
3294  BLI_assert(index < len);
3295 
3296  if (len <= RNA_MAX_ARRAY_LENGTH) {
3298  return tmp[index];
3299  }
3300  float *tmparray, value;
3301 
3302  tmparray = MEM_mallocN(sizeof(float) * len, __func__);
3303  RNA_property_float_get_default_array(ptr, prop, tmparray);
3304  value = tmparray[index];
3305  MEM_freeN(tmparray);
3306 
3307  return value;
3308 }
3309 
3311 {
3312  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3313  IDProperty *idprop;
3314 
3316 
3317  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3318  /* editing bytes is not 100% supported
3319  * since they can contain NIL chars */
3320  if (idprop->subtype == IDP_STRING_SUB_BYTE) {
3321  memcpy(value, IDP_String(idprop), idprop->len);
3322  value[idprop->len] = '\0';
3323  }
3324  else {
3325  memcpy(value, IDP_String(idprop), idprop->len);
3326  }
3327  }
3328  else if (sprop->get) {
3329  sprop->get(ptr, value);
3330  }
3331  else if (sprop->get_ex) {
3332  sprop->get_ex(ptr, prop, value);
3333  }
3334  else {
3335  strcpy(value, sprop->defaultvalue);
3336  }
3337 }
3338 
3340  PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
3341 {
3342  char *buf;
3343  int length;
3344 
3346 
3348 
3349  if (length + 1 < fixedlen) {
3350  buf = fixedbuf;
3351  }
3352  else {
3353  buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
3354  }
3355 
3356 #ifndef NDEBUG
3357  /* safety check to ensure the string is actually set */
3358  buf[length] = 255;
3359 #endif
3360 
3361  RNA_property_string_get(ptr, prop, buf);
3362 
3363 #ifndef NDEBUG
3364  BLI_assert(buf[length] == '\0');
3365 #endif
3366 
3367  if (r_len) {
3368  *r_len = length;
3369  }
3370 
3371  return buf;
3372 }
3373 
3374 /* this is the length without \0 terminator */
3376 {
3377  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3378  IDProperty *idprop;
3379 
3381 
3382  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3383  if (idprop->subtype == IDP_STRING_SUB_BYTE) {
3384  return idprop->len;
3385  }
3386 #ifndef NDEBUG
3387  /* these _must_ stay in sync */
3388  BLI_assert(strlen(IDP_String(idprop)) == idprop->len - 1);
3389 #endif
3390  return idprop->len - 1;
3391  }
3392  if (sprop->length) {
3393  return sprop->length(ptr);
3394  }
3395  if (sprop->length_ex) {
3396  return sprop->length_ex(ptr, prop);
3397  }
3398  return strlen(sprop->defaultvalue);
3399 }
3400 
3401 void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
3402 {
3403  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3404  IDProperty *idprop;
3405 
3407 
3408  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3409  /* both IDP_STRING_SUB_BYTE / IDP_STRING_SUB_UTF8 */
3410  IDP_AssignString(idprop, value, RNA_property_string_maxlength(prop) - 1);
3411  rna_idproperty_touch(idprop);
3412  }
3413  else if (sprop->set) {
3414  sprop->set(ptr, value); /* set function needs to clamp its self */
3415  }
3416  else if (sprop->set_ex) {
3417  sprop->set_ex(ptr, prop, value); /* set function needs to clamp its self */
3418  }
3419  else if (prop->flag & PROP_EDITABLE) {
3420  IDProperty *group;
3421 
3422  group = RNA_struct_idprops(ptr, 1);
3423  if (group) {
3424  IDP_AddToGroup(group,
3426  }
3427  }
3428 }
3429 
3430 void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
3431 {
3432  StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3433  IDProperty *idprop;
3434 
3437 
3438  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3439  IDP_ResizeArray(idprop, len);
3440  memcpy(idprop->data.pointer, value, (size_t)len);
3441 
3442  rna_idproperty_touch(idprop);
3443  }
3444  else if (sprop->set) {
3445  /* XXX, should take length argument (currently not used). */
3446  sprop->set(ptr, value); /* set function needs to clamp its self */
3447  }
3448  else if (sprop->set_ex) {
3449  /* XXX, should take length argument (currently not used). */
3450  sprop->set_ex(ptr, prop, value); /* set function needs to clamp its self */
3451  }
3452  else if (prop->flag & PROP_EDITABLE) {
3453  IDProperty *group;
3454 
3455  group = RNA_struct_idprops(ptr, 1);
3456  if (group) {
3457  IDPropertyTemplate val = {0};
3458  val.string.str = value;
3459  val.string.len = len;
3461  IDP_AddToGroup(group, IDP_New(IDP_STRING, &val, prop->identifier));
3462  }
3463  }
3464 }
3465 
3467 {
3469 
3470  if (prop->magic != RNA_MAGIC) {
3471  /* attempt to get the local ID values */
3472  const IDProperty *idp_ui = rna_idproperty_ui(prop);
3473 
3474  if (idp_ui) {
3475  IDProperty *item;
3476 
3477  item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_STRING);
3478  if (item) {
3479  strcpy(value, IDP_String(item));
3480  return;
3481  }
3482  }
3483 
3484  strcpy(value, "");
3485  return;
3486  }
3487 
3489 
3490  strcpy(value, sprop->defaultvalue);
3491 }
3492 
3494  PropertyRNA *prop,
3495  char *fixedbuf,
3496  int fixedlen)
3497 {
3498  char *buf;
3499  int length;
3500 
3502 
3504 
3505  if (length + 1 < fixedlen) {
3506  buf = fixedbuf;
3507  }
3508  else {
3509  buf = MEM_callocN(sizeof(char) * (length + 1), "RNA_string_get_alloc");
3510  }
3511 
3513 
3514  return buf;
3515 }
3516 
3517 /* this is the length without \0 terminator */
3519 {
3521 
3522  if (prop->magic != RNA_MAGIC) {
3523  /* attempt to get the local ID values */
3524  const IDProperty *idp_ui = rna_idproperty_ui(prop);
3525 
3526  if (idp_ui) {
3527  IDProperty *item;
3528 
3529  item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_STRING);
3530  if (item) {
3531  return strlen(IDP_String(item));
3532  }
3533  }
3534 
3535  return 0;
3536  }
3537 
3539 
3540  return strlen(sprop->defaultvalue);
3541 }
3542 
3544 {
3545  EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3546  IDProperty *idprop;
3547 
3549 
3550  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3551  return IDP_Int(idprop);
3552  }
3553  if (eprop->get) {
3554  return eprop->get(ptr);
3555  }
3556  if (eprop->get_ex) {
3557  return eprop->get_ex(ptr, prop);
3558  }
3559  return eprop->defaultvalue;
3560 }
3561 
3563 {
3564  EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3565  IDProperty *idprop;
3566 
3568 
3569  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3570  IDP_Int(idprop) = value;
3571  rna_idproperty_touch(idprop);
3572  }
3573  else if (eprop->set) {
3574  eprop->set(ptr, value);
3575  }
3576  else if (eprop->set_ex) {
3577  eprop->set_ex(ptr, prop, value);
3578  }
3579  else if (prop->flag & PROP_EDITABLE) {
3580  IDPropertyTemplate val = {0};
3581  IDProperty *group;
3582 
3583  val.i = value;
3584 
3585  group = RNA_struct_idprops(ptr, 1);
3586  if (group) {
3587  IDP_AddToGroup(group, IDP_New(IDP_INT, &val, prop->identifier));
3588  }
3589  }
3590 }
3591 
3593 {
3595 
3597 
3598  return eprop->defaultvalue;
3599 }
3600 
3609  const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
3610 {
3611  const EnumPropertyItem *item_array;
3612  int totitem;
3613  bool free;
3614  int result_value = from_value;
3615  int i, i_init;
3616  int single_step = (step < 0) ? -1 : 1;
3617  int step_tot = 0;
3618 
3619  RNA_property_enum_items((bContext *)C, ptr, prop, &item_array, &totitem, &free);
3620  i = RNA_enum_from_value(item_array, from_value);
3621  i_init = i;
3622 
3623  do {
3624  i = mod_i(i + single_step, totitem);
3625  if (item_array[i].identifier[0]) {
3626  step_tot += single_step;
3627  }
3628  } while ((i != i_init) && (step_tot != step));
3629 
3630  if (i != i_init) {
3631  result_value = item_array[i].value;
3632  }
3633 
3634  if (free) {
3635  MEM_freeN((void *)item_array);
3636  }
3637 
3638  return result_value;
3639 }
3640 
3642 {
3643  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3644  IDProperty *idprop;
3645 
3647 
3648  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3649  pprop = (PointerPropertyRNA *)prop;
3650 
3651  if (RNA_struct_is_ID(pprop->type)) {
3652  return rna_pointer_inherit_refine(ptr, pprop->type, IDP_Id(idprop));
3653  }
3654 
3655  /* for groups, data is idprop itself */
3656  if (pprop->type_fn) {
3657  return rna_pointer_inherit_refine(ptr, pprop->type_fn(ptr), idprop);
3658  }
3659  return rna_pointer_inherit_refine(ptr, pprop->type, idprop);
3660  }
3661  if (pprop->get) {
3662  return pprop->get(ptr);
3663  }
3664  if (prop->flag & PROP_IDPROPERTY) {
3665  /* XXX temporary hack to add it automatically, reading should
3666  * never do any write ops, to ensure thread safety etc .. */
3668  return RNA_property_pointer_get(ptr, prop);
3669  }
3670  return PointerRNA_NULL;
3671 }
3672 
3674  PropertyRNA *prop,
3675  PointerRNA ptr_value,
3676  ReportList *reports)
3677 {
3678  /* Detect IDProperty and retrieve the actual PropertyRNA pointer before cast. */
3679  IDProperty *idprop = rna_idproperty_check(&prop, ptr);
3680 
3681  PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3683 
3684  /* Check types. */
3685  if (pprop->set != NULL) {
3686  /* Assigning to a real RNA property. */
3687  if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, pprop->type)) {
3688  BKE_reportf(reports,
3689  RPT_ERROR,
3690  "%s: expected %s type, not %s",
3691  __func__,
3692  pprop->type->identifier,
3693  ptr_value.type->identifier);
3694  return;
3695  }
3696  }
3697  else {
3698  /* Assigning to an IDProperty disguised as RNA one. */
3699  if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, &RNA_ID)) {
3700  BKE_reportf(reports,
3701  RPT_ERROR,
3702  "%s: expected ID type, not %s",
3703  __func__,
3704  ptr_value.type->identifier);
3705  return;
3706  }
3707  }
3708 
3709  /* We got an existing IDProperty. */
3710  if (idprop != NULL) {
3711  /* Not-yet-defined ID IDProps have an IDP_GROUP type, not an IDP_ID one - because of reasons?
3712  * XXX This has to be investigated fully - there might be a good reason for it, but off hands
3713  * this seems really weird... */
3714  if (idprop->type == IDP_ID) {
3715  IDP_AssignID(idprop, ptr_value.data, 0);
3716  rna_idproperty_touch(idprop);
3717  }
3718  else {
3719  BLI_assert(idprop->type == IDP_GROUP);
3720 
3721  IDPropertyTemplate val = {.id = ptr_value.data};
3722  IDProperty *group = RNA_struct_idprops(ptr, true);
3723  BLI_assert(group != NULL);
3724 
3725  IDP_ReplaceInGroup_ex(group, IDP_New(IDP_ID, &val, idprop->name), idprop);
3726  }
3727  }
3728  /* RNA property. */
3729  else if (pprop->set) {
3730  if (!((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
3731  !((prop->flag & PROP_ID_SELF_CHECK) && ptr->owner_id == ptr_value.owner_id)) {
3732  pprop->set(ptr, ptr_value, reports);
3733  }
3734  }
3735  /* IDProperty disguised as RNA property (and not yet defined in ptr). */
3736  else if (prop->flag & PROP_EDITABLE) {
3737  IDPropertyTemplate val = {0};
3738  IDProperty *group;
3739 
3740  val.id = ptr_value.data;
3741 
3742  group = RNA_struct_idprops(ptr, true);
3743  if (group) {
3744  IDP_ReplaceInGroup(group, IDP_New(IDP_ID, &val, prop->identifier));
3745  }
3746  }
3747 }
3748 
3750 {
3751  /*PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; */
3752 
3753  /* BLI_assert(RNA_property_type(prop) == PROP_POINTER); */
3754 
3755  return PointerRNA_NULL; /* FIXME: there has to be a way... */
3756 }
3757 
3759 {
3760  /*IDProperty *idprop;*/
3761 
3763 
3764  if ((/*idprop=*/rna_idproperty_check(&prop, ptr))) {
3765  /* already exists */
3766  }
3767  else if (prop->flag & PROP_IDPROPERTY) {
3768  IDPropertyTemplate val = {0};
3769  IDProperty *group;
3770 
3771  val.i = 0;
3772 
3773  group = RNA_struct_idprops(ptr, 1);
3774  if (group) {
3775  IDP_AddToGroup(group, IDP_New(IDP_GROUP, &val, prop->identifier));
3776  }
3777  }
3778  else {
3779  printf("%s %s.%s: only supported for id properties.\n",
3780  __func__,
3781  ptr->type->identifier,
3782  prop->identifier);
3783  }
3784 }
3785 
3787 {
3788  IDProperty *idprop, *group;
3789 
3791 
3792  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3793  group = RNA_struct_idprops(ptr, 0);
3794 
3795  if (group) {
3796  IDP_FreeFromGroup(group, idprop);
3797  }
3798  }
3799  else {
3800  printf("%s %s.%s: only supported for id properties.\n",
3801  __func__,
3802  ptr->type->identifier,
3803  prop->identifier);
3804  }
3805 }
3806 
3808 {
3810 
3811  iter->ptr.data = rna_iterator_array_get(iter);
3812  iter->ptr.type = cprop->item_type;
3813  rna_pointer_inherit_id(cprop->item_type, &iter->parent, &iter->ptr);
3814 }
3815 
3817  PropertyRNA *prop,
3819 {
3820  IDProperty *idprop;
3821 
3823 
3824  memset(iter, 0, sizeof(*iter));
3825 
3826  if ((idprop = rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
3827  iter->parent = *ptr;
3828  iter->prop = prop;
3829 
3830  if (idprop) {
3832  iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL);
3833  }
3834  else {
3835  rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL);
3836  }
3837 
3838  if (iter->valid) {
3840  }
3841 
3842  iter->idprop = 1;
3843  }
3844  else {
3846  cprop->begin(iter, ptr);
3847  }
3848 }
3849 
3851 {
3853 
3854  if (iter->idprop) {
3856 
3857  if (iter->valid) {
3859  }
3860  }
3861  else {
3862  cprop->next(iter);
3863  }
3864 }
3865 
3867 {
3869  int i;
3870 
3871  if (num > 1 && (iter->idprop || (cprop->property.flag_internal & PROP_INTERN_RAW_ARRAY))) {
3872  /* fast skip for array */
3873  ArrayIterator *internal = &iter->internal.array;
3874 
3875  if (!internal->skip) {
3876  internal->ptr += internal->itemsize * (num - 1);
3877  iter->valid = (internal->ptr < internal->endptr);
3878  if (iter->valid) {
3880  }
3881  return;
3882  }
3883  }
3884 
3885  /* slow iteration otherwise */
3886  for (i = 0; i < num && iter->valid; i++) {
3888  }
3889 }
3890 
3892 {
3894 
3895  if (iter->idprop) {
3896  rna_iterator_array_end(iter);
3897  }
3898  else {
3899  cprop->end(iter);
3900  }
3901 }
3902 
3904 {
3906  IDProperty *idprop;
3907 
3909 
3910  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3911  return idprop->len;
3912  }
3913  if (cprop->length) {
3914  return cprop->length(ptr);
3915  }
3917  int length = 0;
3918 
3919  RNA_property_collection_begin(ptr, prop, &iter);
3920  for (; iter.valid; RNA_property_collection_next(&iter)) {
3921  length++;
3922  }
3924 
3925  return length;
3926 }
3927 
3928 /* This helper checks whether given collection property itself is editable (we only currently
3929  * support a limited set of operations, insertion of new items, and re-ordering of those new items
3930  * exclusively). */
3932  PropertyRNA *prop,
3933  bool *r_is_liboverride)
3934 {
3935  ID *id = ptr->owner_id;
3936  if (id == NULL) {
3937  *r_is_liboverride = false;
3938  return true;
3939  }
3940 
3941  const bool is_liboverride = *r_is_liboverride = ID_IS_OVERRIDE_LIBRARY(id);
3942 
3943  if (!is_liboverride) {
3944  /* We return True also for linked data, as it allows tricks like py scripts 'overriding' data
3945  * of those.*/
3946  return true;
3947  }
3948 
3949  if (!RNA_property_overridable_get(ptr, prop)) {
3950  return false;
3951  }
3952 
3953  if (prop->magic != RNA_MAGIC || (prop->flag & PROP_IDPROPERTY) == 0) {
3954  /* Insertion and such not supported for pure IDProperties for now, nor for pure RNA/DNA ones.
3955  */
3956  return false;
3957  }
3958  if ((prop->flag_override & PROPOVERRIDE_LIBRARY_INSERTION) == 0) {
3959  return false;
3960  }
3961 
3962  /* No more checks to do, this collections is overridable. */
3963  return true;
3964 }
3965 
3967 {
3968  IDProperty *idprop;
3969  /* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
3970 
3972 
3973  bool is_liboverride;
3974  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
3975  if (r_ptr) {
3976  memset(r_ptr, 0, sizeof(*r_ptr));
3977  }
3978  return;
3979  }
3980 
3981  if ((idprop = rna_idproperty_check(&prop, ptr))) {
3982  IDPropertyTemplate val = {0};
3983  IDProperty *item;
3984 
3985  item = IDP_New(IDP_GROUP, &val, "");
3986  if (is_liboverride) {
3988  }
3989  IDP_AppendArray(idprop, item);
3990  /* IDP_AppendArray does a shallow copy (memcpy), only free memory */
3991  /* IDP_FreePropertyContent(item); */
3992  MEM_freeN(item);
3993  rna_idproperty_touch(idprop);
3994  }
3995  else if (prop->flag & PROP_IDPROPERTY) {
3996  IDProperty *group, *item;
3997  IDPropertyTemplate val = {0};
3998 
3999  group = RNA_struct_idprops(ptr, 1);
4000  if (group) {
4001  idprop = IDP_NewIDPArray(prop->identifier);
4002  IDP_AddToGroup(group, idprop);
4003 
4004  item = IDP_New(IDP_GROUP, &val, "");
4005  if (is_liboverride) {
4007  }
4008  IDP_AppendArray(idprop, item);
4009  /* IDP_AppendArray does a shallow copy (memcpy), only free memory */
4010  /* IDP_FreePropertyContent(item); */
4011  MEM_freeN(item);
4012  }
4013  }
4014 
4015  /* py api calls directly */
4016 #if 0
4017  else if (cprop->add) {
4018  if (!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
4020  RNA_parameter_list_create(&params, ptr, cprop->add);
4021  RNA_function_call(NULL, NULL, ptr, cprop->add, &params);
4023  }
4024  }
4025 # if 0
4026  else {
4027  printf("%s %s.%s: not implemented for this property.\n",
4028  __func__,
4029  ptr->type->identifier,
4030  prop->identifier);
4031  }
4032 # endif
4033 #endif
4034 
4035  if (r_ptr) {
4036  if (idprop) {
4038 
4039  r_ptr->data = IDP_GetIndexArray(idprop, idprop->len - 1);
4040  r_ptr->type = cprop->item_type;
4041  rna_pointer_inherit_id(NULL, ptr, r_ptr);
4042  }
4043  else {
4044  memset(r_ptr, 0, sizeof(*r_ptr));
4045  }
4046  }
4047 }
4048 
4050 {
4051  IDProperty *idprop;
4052  /* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */
4053 
4055 
4056  bool is_liboverride;
4057  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
4058  return false;
4059  }
4060 
4061  if ((idprop = rna_idproperty_check(&prop, ptr))) {
4062  IDProperty tmp, *array;
4063  int len;
4064 
4065  len = idprop->len;
4066  array = IDP_IDPArray(idprop);
4067 
4068  if (key >= 0 && key < len) {
4069  if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
4070  /* We can only remove items that we actually inserted in the local override. */
4071  return false;
4072  }
4073 
4074  if (key + 1 < len) {
4075  /* move element to be removed to the back */
4076  memcpy(&tmp, &array[key], sizeof(IDProperty));
4077  memmove(array + key, array + key + 1, sizeof(IDProperty) * (len - (key + 1)));
4078  memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
4079  }
4080 
4081  IDP_ResizeIDPArray(idprop, len - 1);
4082  }
4083 
4084  return true;
4085  }
4086  if (prop->flag & PROP_IDPROPERTY) {
4087  return true;
4088  }
4089 
4090  /* py api calls directly */
4091 #if 0
4092  else if (cprop->remove) {
4093  if (!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
4095  RNA_parameter_list_create(&params, ptr, cprop->remove);
4096  RNA_function_call(NULL, NULL, ptr, cprop->remove, &params);
4098  }
4099 
4100  return false;
4101  }
4102 # if 0
4103  else {
4104  printf("%s %s.%s: only supported for id properties.\n",
4105  __func__,
4106  ptr->type->identifier,
4107  prop->identifier);
4108  }
4109 # endif
4110 #endif
4111  return false;
4112 }
4113 
4115 {
4116  IDProperty *idprop;
4117 
4119 
4120  bool is_liboverride;
4121  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
4122  return false;
4123  }
4124 
4125  if ((idprop = rna_idproperty_check(&prop, ptr))) {
4126  IDProperty tmp, *array;
4127  int len;
4128 
4129  len = idprop->len;
4130  array = IDP_IDPArray(idprop);
4131 
4132  if (key >= 0 && key < len && pos >= 0 && pos < len && key != pos) {
4133  if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
4134  /* We can only move items that we actually inserted in the local override. */
4135  return false;
4136  }
4137 
4138  memcpy(&tmp, &array[key], sizeof(IDProperty));
4139  if (pos < key) {
4140  memmove(array + pos + 1, array + pos, sizeof(IDProperty) * (key - pos));
4141  }
4142  else {
4143  memmove(array + key, array + key + 1, sizeof(IDProperty) * (pos - key));
4144  }
4145  memcpy(&array[pos], &tmp, sizeof(IDProperty));
4146  }
4147 
4148  return true;
4149  }
4150  if (prop->flag & PROP_IDPROPERTY) {
4151  return true;
4152  }
4153 
4154  return false;
4155 }
4156 
4158 {
4159  IDProperty *idprop;
4160 
4162 
4163  bool is_liboverride;
4164  if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
4165  return;
4166  }
4167 
4168  if ((idprop = rna_idproperty_check(&prop, ptr))) {
4169  if (is_liboverride) {
4170  /* We can only move items that we actually inserted in the local override. */
4171  int len = idprop->len;
4172  IDProperty tmp, *array = IDP_IDPArray(idprop);
4173  for (int i = 0; i < len; i++) {
4174  if ((array[i].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) != 0) {
4175  memcpy(&tmp, &array[i], sizeof(IDProperty));
4176  memmove(array + i, array + i + 1, sizeof(IDProperty) * (len - (i + 1)));
4177  memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
4178  IDP_ResizeIDPArray(idprop, --len);
4179  i--;
4180  }
4181  }
4182  }
4183  else {
4184  IDP_ResizeIDPArray(idprop, 0);
4185  }
4186  rna_idproperty_touch(idprop);
4187  }
4188 }
4189 
4191 {
4193  int index = 0;
4194 
4196 
4197  RNA_property_collection_begin(ptr, prop, &iter);
4198  for (index = 0; iter.valid; RNA_property_collection_next(&iter), index++) {
4199  if (iter.ptr.data == t_ptr->data) {
4200  break;
4201  }
4202  }
4204 
4205  /* did we find it? */
4206  if (iter.valid) {
4207  return index;
4208  }
4209  return -1;
4210 }
4211 
4213  PropertyRNA *prop,
4214  int key,
4215  PointerRNA *r_ptr)
4216 {
4218 
4220 
4221  if (cprop->lookupint) {
4222  /* we have a callback defined, use it */
4223  return cprop->lookupint(ptr, key, r_ptr);
4224  }
4225  /* no callback defined, just iterate and find the nth item */
4227  int i;
4228 
4229  RNA_property_collection_begin(ptr, prop, &iter);
4230  for (i = 0; iter.valid; RNA_property_collection_next(&iter), i++) {
4231  if (i == key) {
4232  *r_ptr = iter.ptr;
4233  break;
4234  }
4235  }
4237 
4238  if (!iter.valid) {
4239  memset(r_ptr, 0, sizeof(*r_ptr));
4240  }
4241 
4242  return iter.valid;
4243 }
4244 
4246  PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
4247 {
4249 
4251 
4252  if (cprop->lookupstring) {
4253  /* we have a callback defined, use it */
4254  return cprop->lookupstring(ptr, key, r_ptr);
4255  }
4256  /* no callback defined, compare with name properties if they exist */
4258  PropertyRNA *nameprop;
4259  char name[256], *nameptr;
4260  int found = 0;
4261  int keylen = strlen(key);
4262  int namelen;
4263  int index = 0;
4264 
4265  RNA_property_collection_begin(ptr, prop, &iter);
4266  for (; iter.valid; RNA_property_collection_next(&iter), index++) {
4267  if (iter.ptr.data && iter.ptr.type->nameproperty) {
4268  nameprop = iter.ptr.type->nameproperty;
4269 
4270  nameptr = RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen);
4271 
4272  if ((keylen == namelen) && STREQ(nameptr, key)) {
4273  *r_ptr = iter.ptr;
4274  found = 1;
4275  }
4276 
4277  if ((char *)&name != nameptr) {
4278  MEM_freeN(nameptr);
4279  }
4280 
4281  if (found) {
4282  break;
4283  }
4284  }
4285  }
4287 
4288  if (!iter.valid) {
4289  memset(r_ptr, 0, sizeof(*r_ptr));
4290  *r_index = -1;
4291  }
4292  else {
4293  *r_index = index;
4294  }
4295 
4296  return iter.valid;
4297 }
4298 
4300  PropertyRNA *prop,
4301  const char *key,
4302  PointerRNA *r_ptr)
4303 {
4304  int index;
4305  return RNA_property_collection_lookup_string_index(ptr, prop, key, r_ptr, &index);
4306 }
4307 
4308 /* zero return is an assignment error */
4310  PropertyRNA *prop,
4311  const int key,
4312  const PointerRNA *assign_ptr)
4313 {
4315 
4317 
4318  if (cprop->assignint) {
4319  /* we have a callback defined, use it */
4320  return cprop->assignint(ptr, key, assign_ptr);
4321  }
4322 
4323  return 0;
4324 }
4325 
4327 {
4329 
4330  *r_ptr = *ptr;
4331  return ((r_ptr->type = rna_ensure_property(prop)->srna) ? 1 : 0);
4332 }
4333 
4335  PropertyRNA *prop,
4336  PropertyRNA *itemprop,
4337  RawArray *array)
4338 {
4340  ArrayIterator *internal;
4341  char *arrayp;
4342 
4344 
4345  if (!(prop->flag_internal & PROP_INTERN_RAW_ARRAY) ||
4346  !(itemprop->flag_internal & PROP_INTERN_RAW_ACCESS)) {
4347  return 0;
4348  }
4349 
4350  RNA_property_collection_begin(ptr, prop, &iter);
4351 
4352  if (iter.valid) {
4353  /* get data from array iterator and item property */
4354  internal = &iter.internal.array;
4355  arrayp = (iter.valid) ? iter.ptr.data : NULL;
4356 
4357  if (internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
4358  /* we might skip some items, so it's not a proper array */
4360  return 0;
4361  }
4362 
4363  array->array = arrayp + itemprop->rawoffset;
4364  array->stride = internal->itemsize;
4365  array->len = ((char *)internal->endptr - arrayp) / internal->itemsize;
4366  array->type = itemprop->rawtype;
4367  }
4368  else {
4369  memset(array, 0, sizeof(RawArray));
4370  }
4371 
4373 
4374  return 1;
4375 }
4376 
4377 #define RAW_GET(dtype, var, raw, a) \
4378  { \
4379  switch (raw.type) { \
4380  case PROP_RAW_CHAR: \
4381  var = (dtype)((char *)raw.array)[a]; \
4382  break; \
4383  case PROP_RAW_SHORT: \
4384  var = (dtype)((short *)raw.array)[a]; \
4385  break; \
4386  case PROP_RAW_INT: \
4387  var = (dtype)((int *)raw.array)[a]; \
4388  break; \
4389  case PROP_RAW_BOOLEAN: \
4390  var = (dtype)((bool *)raw.array)[a]; \
4391  break; \
4392  case PROP_RAW_FLOAT: \
4393  var = (dtype)((float *)raw.array)[a]; \
4394  break; \
4395  case PROP_RAW_DOUBLE: \
4396  var = (dtype)((double *)raw.array)[a]; \
4397  break; \
4398  default: \
4399  var = (dtype)0; \
4400  } \
4401  } \
4402  (void)0
4403 
4404 #define RAW_SET(dtype, raw, a, var) \
4405  { \
4406  switch (raw.type) { \
4407  case PROP_RAW_CHAR: \
4408  ((char *)raw.array)[a] = (char)var; \
4409  break; \
4410  case PROP_RAW_SHORT: \
4411  ((short *)raw.array)[a] = (short)var; \
4412  break; \
4413  case PROP_RAW_INT: \
4414  ((int *)raw.array)[a] = (int)var; \
4415  break; \
4416  case PROP_RAW_BOOLEAN: \
4417  ((bool *)raw.array)[a] = (bool)var; \
4418  break; \
4419  case PROP_RAW_FLOAT: \
4420  ((float *)raw.array)[a] = (float)var; \
4421  break; \
4422  case PROP_RAW_DOUBLE: \
4423  ((double *)raw.array)[a] = (double)var; \
4424  break; \
4425  default: \
4426  break; \
4427  } \
4428  } \
4429  (void)0
4430 
4432 {
4433  switch (type) {
4434  case PROP_RAW_CHAR:
4435  return sizeof(char);
4436  case PROP_RAW_SHORT:
4437  return sizeof(short);
4438  case PROP_RAW_INT:
4439  return sizeof(int);
4440  case PROP_RAW_BOOLEAN:
4441  return sizeof(bool);
4442  case PROP_RAW_FLOAT:
4443  return sizeof(float);
4444  case PROP_RAW_DOUBLE:
4445  return sizeof(double);
4446  default:
4447  return 0;
4448  }
4449 }
4450 
4452 {
4453  int i, len[RNA_MAX_ARRAY_DIMENSION];
4454  const int dim = RNA_property_array_dimension(ptr, prop, len);
4455  int size;
4456 
4457  if (dim == 0) {
4458  return 0;
4459  }
4460 
4461  for (size = 1, i = 0; i < dim; i++) {
4462  size *= len[i];
4463  }
4464 
4465  return size;
4466 }
4467 
4468 static int rna_raw_access(ReportList *reports,
4469  PointerRNA *ptr,
4470  PropertyRNA *prop,
4471  const char *propname,
4472  void *inarray,
4473  RawPropertyType intype,
4474  int inlen,
4475  int set)
4476 {
4477  StructRNA *ptype;
4478  PointerRNA itemptr_base;
4479  PropertyRNA *itemprop, *iprop;
4480  PropertyType itemtype = 0;
4481  RawArray in;
4482  int itemlen = 0;
4483 
4484  /* initialize in array, stride assumed 0 in following code */
4485  in.array = inarray;
4486  in.type = intype;
4487  in.len = inlen;
4488  in.stride = 0;
4489 
4490  ptype = RNA_property_pointer_type(ptr, prop);
4491 
4492  /* try to get item property pointer */
4493  RNA_pointer_create(NULL, ptype, NULL, &itemptr_base);
4494  itemprop = RNA_struct_find_property(&itemptr_base, propname);
4495 
4496  if (itemprop) {
4497  /* we have item property pointer */
4498  RawArray out;
4499 
4500  /* check type */
4501  itemtype = RNA_property_type(itemprop);
4502 
4503  if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
4504  BKE_report(reports, RPT_ERROR, "Only boolean, int float and enum properties supported");
4505  return 0;
4506  }
4507 
4508  /* check item array */
4509  itemlen = RNA_property_array_length(&itemptr_base, itemprop);
4510 
4511  /* dynamic array? need to get length per item */
4512  if (itemprop->getlength) {
4513  itemprop = NULL;
4514  }
4515  /* try to access as raw array */
4516  else if (RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) {
4517  int arraylen = (itemlen == 0) ? 1 : itemlen;
4518  if (in.len != arraylen * out.len) {
4519  BKE_reportf(reports,
4520  RPT_ERROR,
4521  "Array length mismatch (expected %d, got %d)",
4522  out.len * arraylen,
4523  in.len);
4524  return 0;
4525  }
4526 
4527  /* matching raw types */
4528  if (out.type == in.type) {
4529  void *inp = in.array;
4530  void *outp = out.array;
4531  int a, size;
4532 
4533  size = RNA_raw_type_sizeof(out.type) * arraylen;
4534 
4535  for (a = 0; a < out.len; a++) {
4536  if (set) {
4537  memcpy(outp, inp, size);
4538  }
4539  else {
4540  memcpy(inp, outp, size);
4541  }
4542 
4543  inp = (char *)inp + size;
4544  outp = (char *)outp + out.stride;
4545  }
4546 
4547  return 1;
4548  }
4549 
4550  /* could also be faster with non-matching types,
4551  * for now we just do slower loop .. */
4552  }
4553  }
4554 
4555  {
4556  void *tmparray = NULL;
4557  int tmplen = 0;
4558  int err = 0, j, a = 0;
4559  int needconv = 1;
4560 
4561  if (((itemtype == PROP_INT) && (in.type == PROP_RAW_INT)) ||
4562  ((itemtype == PROP_BOOLEAN) && (in.type == PROP_RAW_BOOLEAN)) ||
4563  ((itemtype == PROP_FLOAT) && (in.type == PROP_RAW_FLOAT))) {
4564  /* avoid creating temporary buffer if the data type match */
4565  needconv = 0;
4566  }
4567  /* no item property pointer, can still be id property, or
4568  * property of a type derived from the collection pointer type */
4569  RNA_PROP_BEGIN (ptr, itemptr, prop) {
4570  if (itemptr.data) {
4571  if (itemprop) {
4572  /* we got the property already */
4573  iprop = itemprop;
4574  }
4575  else {
4576  /* not yet, look it up and verify if it is valid */
4577  iprop = RNA_struct_find_property(&itemptr, propname);
4578 
4579  if (iprop) {
4580  itemlen = rna_property_array_length_all_dimensions(&itemptr, iprop);
4581  itemtype = RNA_property_type(iprop);
4582  }
4583  else {
4584  BKE_reportf(reports, RPT_ERROR, "Property named '%s' not found", propname);
4585  err = 1;
4586  break;
4587  }
4588 
4589  if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
4590  BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported");
4591  err = 1;
4592  break;
4593  }
4594  }
4595 
4596  /* editable check */
4597  if (!set || RNA_property_editable(&itemptr, iprop)) {
4598  if (a + itemlen > in.len) {
4599  BKE_reportf(
4600  reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
4601  err = 1;
4602  break;
4603  }
4604 
4605  if (itemlen == 0) {
4606  /* handle conversions */
4607  if (set) {
4608  switch (itemtype) {
4609  case PROP_BOOLEAN: {
4610  int b;
4611  RAW_GET(bool, b, in, a);
4612  RNA_property_boolean_set(&itemptr, iprop, b);
4613  break;
4614  }
4615  case PROP_INT: {
4616  int i;
4617  RAW_GET(int, i, in, a);
4618  RNA_property_int_set(&itemptr, iprop, i);
4619  break;
4620  }
4621  case PROP_FLOAT: {
4622  float f;
4623  RAW_GET(float, f, in, a);
4624  RNA_property_float_set(&itemptr, iprop, f);
4625  break;
4626  }
4627  default:
4628  break;
4629  }
4630  }
4631  else {
4632  switch (itemtype) {
4633  case PROP_BOOLEAN: {
4634  int b = RNA_property_boolean_get(&itemptr, iprop);
4635  RAW_SET(bool, in, a, b);
4636  break;
4637  }
4638  case PROP_INT: {
4639  int i = RNA_property_int_get(&itemptr, iprop);
4640  RAW_SET(int, in, a, i);
4641  break;
4642  }
4643  case PROP_FLOAT: {
4644  float f = RNA_property_float_get(&itemptr, iprop);
4645  RAW_SET(float, in, a, f);
4646  break;
4647  }
4648  default:
4649  break;
4650  }
4651  }
4652  a++;
4653  }
4654  else if (needconv == 1) {
4655  /* allocate temporary array if needed */
4656  if (tmparray && tmplen != itemlen) {
4657  MEM_freeN(tmparray);
4658  tmparray = NULL;
4659  }
4660  if (!tmparray) {
4661  tmparray = MEM_callocN(sizeof(float) * itemlen, "RNA tmparray");
4662  tmplen = itemlen;
4663  }
4664 
4665  /* handle conversions */
4666  if (set) {
4667  switch (itemtype) {
4668  case PROP_BOOLEAN: {
4669  for (j = 0; j < itemlen; j++, a++) {
4670  RAW_GET(bool, ((bool *)tmparray)[j], in, a);
4671  }
4672  RNA_property_boolean_set_array(&itemptr, iprop, tmparray);
4673  break;
4674  }
4675  case PROP_INT: {
4676  for (j = 0; j < itemlen; j++, a++) {
4677  RAW_GET(int, ((int *)tmparray)[j], in, a);
4678  }
4679  RNA_property_int_set_array(&itemptr, iprop, tmparray);
4680  break;
4681  }
4682  case PROP_FLOAT: {
4683  for (j = 0; j < itemlen; j++, a++) {
4684  RAW_GET(float, ((float *)tmparray)[j], in, a);
4685  }
4686  RNA_property_float_set_array(&itemptr, iprop, tmparray);
4687  break;
4688  }
4689  default:
4690  break;
4691  }
4692  }
4693  else {
4694  switch (itemtype) {
4695  case PROP_BOOLEAN: {
4696  RNA_property_boolean_get_array(&itemptr, iprop, tmparray);
4697  for (j = 0; j < itemlen; j++, a++) {
4698  RAW_SET(int, in, a, ((bool *)tmparray)[j]);
4699  }
4700  break;
4701  }
4702  case PROP_INT: {
4703  RNA_property_int_get_array(&itemptr, iprop, tmparray);
4704  for (j = 0; j < itemlen; j++, a++) {
4705  RAW_SET(int, in, a, ((int *)tmparray)[j]);
4706  }
4707  break;
4708  }
4709  case PROP_FLOAT: {
4710  RNA_property_float_get_array(&itemptr, iprop, tmparray);
4711  for (j = 0; j < itemlen; j++, a++) {
4712  RAW_SET(float, in, a, ((float *)tmparray)[j]);
4713  }
4714  break;
4715  }
4716  default:
4717  break;
4718  }
4719  }
4720  }
4721  else {
4722  if (set) {
4723  switch (itemtype) {
4724  case PROP_BOOLEAN: {
4725  RNA_property_boolean_set_array(&itemptr, iprop, &((bool *)in.array)[a]);
4726  a += itemlen;
4727  break;
4728  }
4729  case PROP_INT: {
4730  RNA_property_int_set_array(&itemptr, iprop, &((int *)in.array)[a]);
4731  a += itemlen;
4732  break;
4733  }
4734  case PROP_FLOAT: {
4735  RNA_property_float_set_array(&itemptr, iprop, &((float *)in.array)[a]);
4736  a += itemlen;
4737  break;
4738  }
4739  default:
4740  break;
4741  }
4742  }
4743  else {
4744  switch (itemtype) {
4745  case PROP_BOOLEAN: {
4746  RNA_property_boolean_get_array(&itemptr, iprop, &((bool *)in.array)[a]);
4747  a += itemlen;
4748  break;
4749  }
4750  case PROP_INT: {
4751  RNA_property_int_get_array(&itemptr, iprop, &((int *)in.array)[a]);
4752  a += itemlen;
4753  break;
4754  }
4755  case PROP_FLOAT: {
4756  RNA_property_float_get_array(&itemptr, iprop, &((float *)in.array)[a]);
4757  a += itemlen;
4758  break;
4759  }
4760  default:
4761  break;
4762  }
4763  }
4764  }
4765  }
4766  }
4767  }
4768  RNA_PROP_END;
4769 
4770  if (tmparray) {
4771  MEM_freeN(tmparray);
4772  }
4773 
4774  return !err;
4775  }
4776 }
4777 
4779 {
4780  if (prop->rawtype == PROP_RAW_UNSET) {
4781  /* this property has no raw access,
4782  * yet we try to provide a raw type to help building the array. */
4783  switch (prop->type) {
4784  case PROP_BOOLEAN:
4785  return PROP_RAW_BOOLEAN;
4786  case PROP_INT:
4787  return PROP_RAW_INT;
4788  case PROP_FLOAT:
4789  return PROP_RAW_FLOAT;
4790  case PROP_ENUM:
4791  return PROP_RAW_INT;
4792  default:
4793  break;
4794  }
4795  }
4796  return prop->rawtype;
4797 }
4798 
4800  PointerRNA *ptr,
4801  PropertyRNA *prop,
4802  const char *propname,
4803  void *array,
4805  int len)
4806 {
4807  return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0);
4808 }
4809 
4811  PointerRNA *ptr,
4812  PropertyRNA *prop,
4813  const char *propname,
4814  void *array,
4816  int len)
4817 {
4818  return rna_raw_access(reports, ptr, prop, propname, array, type, len, 1);
4819 }
4820 
4821 /* Standard iterator functions */
4822 
4824  ListBase *lb,
4825  IteratorSkipFunc skip)
4826 {
4827  ListBaseIterator *internal = &iter->internal.listbase;
4828 
4829  internal->link = (lb) ? lb->first : NULL;
4830  internal->skip = skip;
4831 
4832  iter->valid = (internal->link != NULL);
4833 
4834  if (skip && iter->valid && skip(iter, internal->link)) {
4836  }
4837 }
4838 
4840 {
4841  ListBaseIterator *internal = &iter->internal.listbase;
4842 
4843  if (internal->skip) {
4844  do {
4845  internal->link = internal->link->next;
4846  iter->valid = (internal->link != NULL);
4847  } while (iter->valid && internal->skip(iter, internal->link));
4848  }
4849  else {
4850  internal->link = internal->link->next;
4851  iter->valid = (internal->link != NULL);
4852  }
4853 }
4854 
4856 {
4857  ListBaseIterator *internal = &iter->internal.listbase;
4858 
4859  return internal->link;
4860 }
4861 
4863 {
4864 }
4865 
4867  StructRNA *type,
4868  struct ListBase *lb,
4869  int index)
4870 {
4871  void *data = BLI_findlink(lb, index);
4873 }
4874 
4876  void *ptr,
4877  int itemsize,
4878  int length,
4879  bool free_ptr,
4880  IteratorSkipFunc skip)
4881 {
4882  ArrayIterator *internal;
4883 
4884  if (ptr == NULL) {
4885  length = 0;
4886  }
4887  else if (length == 0) {
4888  ptr = NULL;
4889  itemsize = 0;
4890  }
4891 
4892  internal = &iter->internal.array;
4893  internal->ptr = ptr;
4894  internal->free_ptr = free_ptr ? ptr : NULL;
4895  internal->endptr = ((char *)ptr) + length * itemsize;
4896  internal->itemsize = itemsize;
4897  internal->skip = skip;
4898  internal->length = length;
4899 
4900  iter->valid = (internal->ptr != internal->endptr);
4901 
4902  if (skip && iter->valid && skip(iter, internal->ptr)) {
4904  }
4905 }
4906 
4908 {
4909  ArrayIterator *internal = &iter->internal.array;
4910 
4911  if (internal->skip) {
4912  do {
4913  internal->ptr += internal->itemsize;
4914  iter->valid = (internal->ptr != internal->endptr);
4915  } while (iter->valid && internal->skip(iter, internal->ptr));
4916  }
4917  else {
4918  internal->ptr += internal->itemsize;
4919  iter->valid = (internal->ptr != internal->endptr);
4920  }
4921 }
4922 
4924 {
4925  ArrayIterator *internal = &iter->internal.array;
4926 
4927  return internal->ptr;
4928 }
4929 
4931 {
4932  ArrayIterator *internal = &iter->internal.array;
4933 
4934  /* for ** arrays */
4935  return *(void **)(internal->ptr);
4936 }
4937 
4939 {
4940  ArrayIterator *internal = &iter->internal.array;
4941 
4942  if (internal->free_ptr) {
4943  MEM_freeN(internal->free_ptr);
4944  internal->free_ptr = NULL;
4945  }
4946 }
4947 
4949  PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
4950 {
4951  if (index < 0 || index >= length) {
4952  return PointerRNA_NULL;
4953  }
4954 
4955  return rna_pointer_inherit_refine(ptr, type, ((char *)data) + index * itemsize);
4956 }
4957 
4958 /* RNA Path - Experiment */
4959 
4960 static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int bracket)
4961 {
4962  const char *p;
4963  int len = 0;
4964 
4965  if (bracket) {
4966  /* get data between [], check escaping quotes and back-slashes with #BLI_str_unescape. */
4967  if (**path == '[') {
4968  (*path)++;
4969  }
4970  else {
4971  return NULL;
4972  }
4973 
4974  p = *path;
4975 
4976  /* 2 kinds of look-ups now, quoted or unquoted. */
4977  if (*p != '"') {
4978  while (*p && (*p != ']')) {
4979  len++;
4980  p++;
4981  }
4982  }
4983  else {
4984  const char *p_end = BLI_str_escape_find_quote(p + 1);
4985  if (p_end == NULL) {
4986  /* No Matching quote. */
4987  return NULL;
4988  }
4989  /* Skip the last quoted char to get the `]`. */
4990  p_end += 1;
4991 
4992  len += (p_end - p);
4993  p = p_end;
4994  }
4995 
4996  if (*p != ']') {
4997  return NULL;
4998  }
4999  }
5000  else {
5001  /* get data until . or [ */
5002  p = *path;
5003 
5004  while (*p && *p != '.' && *p != '[') {
5005  len++;
5006  p++;
5007  }
5008  }
5009 
5010  /* empty, return */
5011  if (len == 0) {
5012  return NULL;
5013  }
5014 
5015  /* Try to use fixed buffer if possible. */
5016  char *buf = (len + 1 < fixedlen) ? fixedbuf : MEM_mallocN(sizeof(char) * (len + 1), __func__);
5017 
5018  /* copy string, taking into account escaped ] */
5019  if (bracket) {
5020  BLI_str_unescape(buf, *path, len);
5021  p = (*path) + len;
5022  }
5023  else {
5024  memcpy(buf, *path, sizeof(char) * len);
5025  buf[len] = '\0';
5026  }
5027 
5028  /* set path to start of next token */
5029  if (*p == ']') {
5030  p++;
5031  }
5032  if (*p == '.') {
5033  p++;
5034  }
5035  *path = p;
5036 
5037  return buf;
5038 }
5039 
5040 static int rna_token_strip_quotes(char *token)
5041 {
5042  if (token[0] == '"') {
5043  int len = strlen(token);
5044  if (len >= 2 && token[len - 1] == '"') {
5045  /* strip away "" */
5046  token[len - 1] = '\0';
5047  return 1;
5048  }
5049  }
5050  return 0;
5051 }
5052 
5053 static bool rna_path_parse_collection_key(const char **path,
5054  PointerRNA *ptr,
5055  PropertyRNA *prop,
5056  PointerRNA *r_nextptr)
5057 {
5058  char fixedbuf[256];
5059  int intkey;
5060 
5061  *r_nextptr = *ptr;
5062 
5063  /* end of path, ok */
5064  if (!(**path)) {
5065  return true;
5066  }
5067 
5068  if (**path == '[') {
5069  char *token;
5070 
5071  /* resolve the lookup with [] brackets */
5072  token = rna_path_token(path, fixedbuf, sizeof(fixedbuf), 1);
5073 
5074  if (!token) {
5075  return false;
5076  }
5077 
5078  /* check for "" to see if it is a string */
5079  if (rna_token_strip_quotes(token)) {
5080  if (RNA_property_collection_lookup_string(ptr, prop, token + 1, r_nextptr)) {
5081  /* pass */
5082  }
5083  else {
5084  r_nextptr->data = NULL;
5085  }
5086  }
5087  else {
5088  /* otherwise do int lookup */
5089  intkey = atoi(token);
5090  if (intkey == 0 && (token[0] != '0' || token[1] != '\0')) {
5091  return false; /* we can be sure the fixedbuf was used in this case */
5092  }
5093  if (RNA_property_collection_lookup_int(ptr, prop, intkey, r_nextptr)) {
5094  /* pass */
5095  }
5096  else {
5097  r_nextptr->data = NULL;
5098  }
5099  }
5100 
5101  if (token != fixedbuf) {
5102  MEM_freeN(token);
5103  }
5104  }
5105  else {
5106  if (RNA_property_collection_type_get(ptr, prop, r_nextptr)) {
5107  /* pass */
5108  }
5109  else {
5110  /* ensure we quit on invalid values */
5111  r_nextptr->data = NULL;
5112  }
5113  }
5114 
5115  return true;
5116 }
5117 
5118 static bool rna_path_parse_array_index(const char **path,
5119  PointerRNA *ptr,
5120  PropertyRNA *prop,
5121  int *r_index)
5122 {
5123  char fixedbuf[256];
5124  int index_arr[RNA_MAX_ARRAY_DIMENSION] = {0};
5126  const int dim = RNA_property_array_dimension(ptr, prop, len);
5127  int i;
5128 
5129  *r_index = -1;
5130 
5131  /* end of path, ok */
5132  if (!(**path)) {
5133  return true;
5134  }
5135 
5136  for (i = 0; i < dim; i++) {
5137  int temp_index = -1;
5138  char *token;
5139 
5140  /* multi index resolve */
5141  if (**path == '[') {
5142  token = rna_path_token(path, fixedbuf, sizeof(fixedbuf), 1);
5143 
5144  if (token == NULL) {
5145  /* invalid syntax blah[] */
5146  return false;
5147  }
5148  /* check for "" to see if it is a string */
5149  if (rna_token_strip_quotes(token)) {
5150  temp_index = RNA_property_array_item_index(prop, *(token + 1));
5151  }
5152  else {
5153  /* otherwise do int lookup */
5154  temp_index = atoi(token);
5155 
5156  if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) {
5157  if (token != fixedbuf) {
5158  MEM_freeN(token);
5159  }
5160 
5161  return false;
5162  }
5163  }
5164  }
5165  else if (dim == 1) {
5166  /* location.x || scale.X, single dimension arrays only */
5167  token = rna_path_token(path, fixedbuf, sizeof(fixedbuf), 0);
5168  if (token == NULL) {
5169  /* invalid syntax blah.. */
5170  return false;
5171  }
5172  temp_index = RNA_property_array_item_index(prop, *token);
5173  }
5174  else {
5175  /* just to avoid uninitialized pointer use */
5176  token = fixedbuf;
5177  }
5178 
5179  if (token != fixedbuf) {
5180  MEM_freeN(token);
5181  }
5182 
5183  /* out of range */
5184  if (temp_index < 0 || temp_index >= len[i]) {
5185  return false;
5186  }
5187 
5188  index_arr[i] = temp_index;
5189  /* end multi index resolve */
5190  }
5191 
5192  /* arrays always contain numbers so further values are not valid */
5193  if (**path) {
5194  return false;
5195  }
5196 
5197  /* flatten index over all dimensions */
5198  {
5199  int totdim = 1;
5200  int flat_index = 0;
5201 
5202  for (i = dim - 1; i >= 0; i--) {
5203  flat_index += index_arr[i] * totdim;
5204  totdim *= len[i];
5205  }
5206 
5207  *r_index = flat_index;
5208  }
5209  return true;
5210 }
5211 
5234  const char *path,
5235  PointerRNA *r_ptr,
5236  PropertyRNA **r_prop,
5237  int *r_index,
5238  PointerRNA *r_item_ptr,
5239  ListBase *r_elements,
5240  const bool eval_pointer)
5241 {
5242  BLI_assert(r_item_ptr == NULL || !eval_pointer);
5243  PropertyRNA *prop;
5244  PointerRNA curptr, nextptr;
5245  PropertyElemRNA *prop_elem = NULL;
5246  int index = -1;
5247  char fixedbuf[256];
5248  int type;
5249  const bool do_item_ptr = r_item_ptr != NULL && !eval_pointer;
5250 
5251  if (do_item_ptr) {
5252  RNA_POINTER_INVALIDATE(&nextptr);
5253  }
5254 
5255  prop = NULL;
5256  curptr = *ptr;
5257 
5258  if (path == NULL || *path == '\0') {
5259  return false;
5260  }
5261 
5262  while (*path) {
5263  if (do_item_ptr) {
5264  RNA_POINTER_INVALIDATE(&nextptr);
5265  }
5266 
5267  int use_id_prop = (*path == '[') ? 1 : 0;
5268  char *token;
5269  /* custom property lookup ?
5270  * C.object["someprop"]
5271  */
5272 
5273  if (!curptr.data) {
5274  return false;
5275  }
5276 
5277  /* look up property name in current struct */
5278  token = rna_path_token(&path, fixedbuf, sizeof(fixedbuf), use_id_prop);
5279 
5280  if (!token) {
5281  return false;
5282  }
5283 
5284  prop = NULL;
5285  if (use_id_prop) { /* look up property name in current struct */
5286  IDProperty *group = RNA_struct_idprops(&curptr, 0);
5287  if (group && rna_token_strip_quotes(token)) {
5288  prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token + 1);
5289  }
5290  }
5291  else {
5292  prop = RNA_struct_find_property(&curptr, token);
5293  }
5294 
5295  if (token != fixedbuf) {
5296  MEM_freeN(token);
5297  }
5298 
5299  if (!prop) {
5300  return false;
5301  }
5302 
5303  if (r_elements) {
5304  prop_elem = MEM_mallocN(sizeof(PropertyElemRNA), __func__);
5305  prop_elem->ptr = curptr;
5306  prop_elem->prop = prop;
5307  prop_elem->index = -1; /* index will be added later, if needed. */
5308  BLI_addtail(r_elements, prop_elem);
5309  }
5310 
5311  type = RNA_property_type(prop);
5312 
5313  /* now look up the value of this property if it is a pointer or
5314  * collection, otherwise return the property rna so that the
5315  * caller can read the value of the property itself */
5316  switch (type) {
5317  case PROP_POINTER: {
5318  /* resolve pointer if further path elements follow
5319  * or explicitly requested
5320  */
5321  if (do_item_ptr || eval_pointer || *path != '\0') {
5322  nextptr = RNA_property_pointer_get(&curptr, prop);
5323  }
5324 
5325  if (eval_pointer || *path != '\0') {
5326  curptr = nextptr;
5327  prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
5328  index = -1;
5329  }
5330  break;
5331  }
5332  case PROP_COLLECTION: {
5333  /* Resolve pointer if further path elements follow.
5334  * Note that if path is empty, rna_path_parse_collection_key will do nothing anyway,
5335  * so do_item_ptr is of no use in that case.
5336  */
5337  if (*path) {
5338  if (!rna_path_parse_collection_key(&path, &curptr, prop, &nextptr)) {
5339  return false;
5340  }
5341 
5342  if (eval_pointer || *path != '\0') {
5343  curptr = nextptr;
5344  prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */
5345  index = -1;
5346  }
5347  }
5348  break;
5349  }
5350  default:
5351  if (r_index || prop_elem) {
5352  if (!rna_path_parse_array_index(&path, &curptr, prop, &index)) {
5353  return false;
5354  }
5355 
5356  if (prop_elem) {
5357  prop_elem->index = index;
5358  }
5359  }
5360  break;
5361  }
5362  }
5363 
5364  if (r_ptr) {
5365  *r_ptr = curptr;
5366  }
5367  if (r_prop) {
5368  *r_prop = prop;
5369  }
5370  if (r_index) {
5371  *r_index = index;
5372  }
5373  if (r_item_ptr && do_item_ptr) {
5374  *r_item_ptr = nextptr;
5375  }
5376 
5377  if (prop_elem && (prop_elem->ptr.data != curptr.data || prop_elem->prop != prop ||
5378  prop_elem->index != index)) {
5379  prop_elem = MEM_mallocN(sizeof(PropertyElemRNA), __func__);
5380  prop_elem->ptr = curptr;
5381  prop_elem->prop = prop;
5382  prop_elem->index = index;
5383  BLI_addtail(r_elements, prop_elem);
5384  }
5385 
5386  return true;
5387 }
5388 
5400 bool RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
5401 {
5402  if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, NULL, NULL, true)) {
5403  return false;
5404  }
5405 
5406  return r_ptr->data != NULL;
5407 }
5408 
5417  PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
5418 {
5419  if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, NULL, NULL, true)) {
5420  return false;
5421  }
5422 
5423  return r_ptr->data != NULL;
5424 }
5425 
5435  const char *path,
5436  PointerRNA *r_ptr,
5437  PropertyRNA **r_prop)
5438 {
5439  if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, NULL, NULL, false)) {
5440  return false;
5441  }
5442 
5443  return r_ptr->data != NULL && *r_prop != NULL;
5444 }
5445 
5455  PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
5456 {
5457  if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, NULL, NULL, false)) {
5458  return false;
5459  }
5460 
5461  return r_ptr->data != NULL && *r_prop != NULL;
5462 }
5463 
5477  const char *path,
5478  PointerRNA *r_ptr,
5479  PropertyRNA **r_prop,
5480  PointerRNA *r_item_ptr)
5481 {
5482  if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, r_item_ptr, NULL, false)) {
5483  return false;
5484  }
5485 
5486  return r_ptr->data != NULL && *r_prop != NULL;
5487 }
5488 
5503  const char *path,
5504  PointerRNA *r_ptr,
5505  PropertyRNA **r_prop,
5506  int *r_index,
5507  PointerRNA *r_item_ptr)
5508 {
5509  if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, r_item_ptr, NULL, false)) {
5510  return false;
5511  }
5512 
5513  return r_ptr->data != NULL && *r_prop != NULL;
5514 }
5524 bool RNA_path_resolve_elements(PointerRNA *ptr, const char *path, ListBase *r_elements)
5525 {
5526  return rna_path_parse(ptr, path, NULL, NULL, NULL, NULL, r_elements, false);
5527 }
5528 
5530  const char *path, PointerRNA *UNUSED(ptr), PropertyRNA *prop, int intkey, const char *strkey)
5531 {
5532  DynStr *dynstr;
5533  char *result;
5534 
5535  dynstr = BLI_dynstr_new();
5536 
5537  /* add .identifier */
5538  if (path) {
5539  BLI_dynstr_append(dynstr, path);
5540  if (*path) {
5541  BLI_dynstr_append(dynstr, ".");
5542  }
5543  }
5544 
5546 
5547  if (RNA_property_type(prop) == PROP_COLLECTION) {
5548  /* add ["strkey"] or [intkey] */
5549  BLI_dynstr_append(dynstr, "[");
5550 
5551  if (strkey) {
5552  const int strkey_esc_max_size = (strlen(strkey) * 2) + 1;
5553  char *strkey_esc = BLI_array_alloca(strkey_esc, strkey_esc_max_size);
5554  BLI_str_escape(strkey_esc, strkey, strkey_esc_max_size);
5555  BLI_dynstr_append(dynstr, "\"");
5556  BLI_dynstr_append(dynstr, strkey_esc);
5557  BLI_dynstr_append(dynstr, "\"");
5558  }
5559  else {
5560  char appendstr[128];
5561  BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey);
5562  BLI_dynstr_append(dynstr, appendstr);
5563  }
5564 
5565  BLI_dynstr_append(dynstr, "]");
5566  }
5567 
5568  result = BLI_dynstr_get_cstring(dynstr);
5569  BLI_dynstr_free(dynstr);
5570 
5571  return result;
5572 }
5573 
5574 char *RNA_path_back(const char *path)
5575 {
5576  char fixedbuf[256];
5577  const char *previous, *current;
5578  char *result;
5579  int i;
5580 
5581  if (!path) {
5582  return NULL;
5583  }
5584 
5585  previous = NULL;
5586  current = path;
5587 
5588  /* parse token by token until the end, then we back up to the previous
5589  * position and strip of the next token to get the path one step back */
5590  while (*current) {
5591  char *token;
5592 
5593  token = rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 0);
5594 
5595  if (!token) {
5596  return NULL;
5597  }
5598  if (token != fixedbuf) {
5599  MEM_freeN(token);
5600  }
5601 
5602  /* in case of collection we also need to strip off [] */
5603  token = rna_path_token(&current, fixedbuf, sizeof(fixedbuf), 1);
5604  if (token && token != fixedbuf) {
5605  MEM_freeN(token);
5606  }
5607 
5608  if (!*current) {
5609  break;
5610  }
5611 
5612  previous = current;
5613  }
5614 
5615  if (!previous) {
5616  return NULL;
5617  }
5618 
5619  /* copy and strip off last token */
5620  i = previous - path;
5621  result = BLI_strdup(path);
5622 
5623  if (i > 0 && result[i - 1] == '.') {
5624  i--;
5625  }
5626  result[i] = 0;
5627 
5628  return result;
5629 }
5630 
5631 /* generic path search func
5632  * if its needed this could also reference the IDProperty direct */
5633 typedef struct IDP_Chain {
5634  struct IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */
5635 
5636  const char *name;
5637  int index;
5638 
5640 
5641 static char *rna_idp_path_create(IDP_Chain *child_link)
5642 {
5643  DynStr *dynstr = BLI_dynstr_new();
5644  char *path;
5645  bool is_first = true;
5646 
5647  int tot = 0;
5648  IDP_Chain *link = child_link;
5649 
5650  /* reverse the list */
5651  IDP_Chain *link_prev;
5652  link_prev = NULL;
5653  while (link) {
5654  IDP_Chain *link_next = link->up;
5655  link->up = link_prev;
5656  link_prev = link;
5657  link = link_next;
5658  tot++;
5659  }
5660 
5661  for (link = link_prev; link; link = link->up) {
5662  /* pass */
5663  if (link->index >= 0) {
5664  BLI_dynstr_appendf(dynstr, is_first ? "%s[%d]" : ".%s[%d]", link->name, link->index);
5665  }
5666  else {
5667  BLI_dynstr_appendf(dynstr, is_first ? "%s" : ".%s", link->name);
5668  }
5669 
5670  is_first = false;
5671  }
5672 
5673  path = BLI_dynstr_get_cstring(dynstr);
5674  BLI_dynstr_free(dynstr);
5675 
5676  if (*path == '\0') {
5677  MEM_freeN(path);
5678  path = NULL;
5679  }
5680 
5681  return path;
5682 }
5683 
5685  IDProperty *haystack,
5686  IDProperty *needle,
5687  IDP_Chain *parent_link)
5688 {
5689  char *path = NULL;
5690  IDP_Chain link;
5691 
5692  IDProperty *iter;
5693  int i;
5694 
5695  BLI_assert(haystack->type == IDP_GROUP);
5696 
5697  link.up = parent_link;
5698  /* Always set both name and index, else a stale value might get used. */
5699  link.name = NULL;
5700  link.index = -1;
5701 
5702  for (i = 0, iter = haystack->data.group.first; iter; iter = iter->next, i++) {
5703  if (needle == iter) { /* found! */
5704  link.name = iter->name;
5705  link.index = -1;
5706  path = rna_idp_path_create(&link);
5707  break;
5708  }
5709 
5710  /* Early out in case the IDProperty type cannot contain RNA properties. */
5711  if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) {
5712  continue;
5713  }
5714 
5715  /* Ensure this is RNA. */
5716  /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name
5717  * collides with an actual fully static RNA property of the same struct (which would then not
5718  * be flagged with `PROP_IDPROPERTY`).
5719  *
5720  * That case must be ignored here, we only want to deal with runtime RNA properties stored in
5721  * IDProps.
5722  *
5723  * See T84091. */
5724  PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
5725  if (prop == NULL || (prop->flag & PROP_IDPROPERTY) == 0) {
5726  continue;
5727  }
5728 
5729  if (iter->type == IDP_GROUP) {
5730  if (prop->type == PROP_POINTER) {
5731  PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop);
5732  BLI_assert(!RNA_pointer_is_null(&child_ptr));
5733  link.name = iter->name;
5734  link.index = -1;
5735  if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) {
5736  break;
5737  }
5738  }
5739  }
5740  else if (iter->type == IDP_IDPARRAY) {
5741  if (prop->type == PROP_COLLECTION) {
5742  IDProperty *array = IDP_IDPArray(iter);
5743  if (needle >= array && needle < (iter->len + array)) { /* found! */
5744  link.name = iter->name;
5745  link.index = (int)(needle - array);
5746  path = rna_idp_path_create(&link);
5747  break;
5748  }
5749  int j;
5750  link.name = iter->name;
5751  for (j = 0; j < iter->len; j++, array++) {
5752  PointerRNA child_ptr;
5753  if (RNA_property_collection_lookup_int(ptr, prop, j, &child_ptr)) {
5754  BLI_assert(!RNA_pointer_is_null(&child_ptr));
5755  link.index = j;
5756  if ((path = rna_idp_path(&child_ptr, array, needle, &link))) {
5757  break;
5758  }
5759  }
5760  }
5761  if (path) {
5762  break;
5763  }
5764  }
5765  }
5766  }
5767 
5768  return path;
5769 }
5770 
5782 {
5783  IDProperty *haystack = RNA_struct_idprops(ptr, false);
5784 
5785  if (haystack) { /* can fail when called on bones */
5786  return rna_idp_path(ptr, haystack, needle, NULL);
5787  }
5788  return NULL;
5789 }
5790 
5792 {
5793  PointerRNA id_ptr;
5794 
5795  BLI_assert(ptr->owner_id != NULL);
5796 
5797  /* TODO, Support Bones/PoseBones. no pointers stored to the bones from here, only the ID.
5798  * See example in T25746.
5799  * Unless this is added only way to find this is to also search
5800  * all bones and pose bones of an armature or object.
5801  */
5802  RNA_id_pointer_create(ptr->owner_id, &id_ptr);
5803 
5804  return RNA_path_from_struct_to_idproperty(&id_ptr, ptr->data);
5805 }
5806 
5814 ID *RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path)
5815 {
5816  if (r_path) {
5817  *r_path = "";
5818  }
5819 
5820  if ((id == NULL) || (id->flag & LIB_EMBEDDED_DATA) == 0) {
5821  return id;
5822  }
5823 
5824  const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
5825  if (r_path) {
5826  switch (GS(id->name)) {
5827  case ID_NT:
5828  *r_path = "node_tree";
5829  break;
5830  case ID_GR:
5831  *r_path = "collection";
5832  break;
5833  default:
5834  BLI_assert(!"Missing handling of embedded id type.");
5835  }
5836  }
5837 
5838  if (id_type->owner_get == NULL) {
5839  BLI_assert(!"Missing handling of embedded id type.");
5840  return id;
5841  }
5842  return id_type->owner_get(bmain, id);
5843 }
5844 
5845 static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real_id)
5846 {
5847  if (r_real_id != NULL) {
5848  *r_real_id = NULL;
5849  }
5850 
5851  const char *prefix;
5852  ID *real_id = RNA_find_real_ID_and_path(bmain, id, &prefix);
5853 
5854  if (r_real_id != NULL) {
5855  *r_real_id = real_id;
5856  }
5857 
5858  if (path != NULL) {
5859  char *new_path = NULL;
5860 
5861  if (real_id) {
5862  if (prefix[0]) {
5863  new_path = BLI_sprintfN("%s%s%s", prefix, path[0] == '[' ? "" : ".", path);
5864  }
5865  else {
5866  return path;
5867  }
5868  }
5869 
5870  MEM_freeN(path);
5871  return new_path;
5872  }
5873  return prefix[0] != '\0' ? BLI_strdup(prefix) : NULL;
5874 }
5875 
5877 {
5878  char *ptrpath = NULL;
5879 
5880  if (!ptr->owner_id || !ptr->data) {
5881  return NULL;
5882  }
5883 
5884  if (!RNA_struct_is_ID(ptr->type)) {
5885  if (ptr->type->path) {
5886  /* if type has a path to some ID, use it */
5887  ptrpath = ptr->type->path(ptr);
5888  }
5889  else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) {
5890  PointerRNA parentptr;
5891  PropertyRNA *userprop;
5892 
5893  /* find the property in the struct we're nested in that references this struct, and
5894  * use its identifier as the first part of the path used...
5895  */
5896  RNA_id_pointer_create(ptr->owner_id, &parentptr);
5897  userprop = RNA_struct_find_nested(&parentptr, ptr->type);
5898 
5899  if (userprop) {
5900  ptrpath = BLI_strdup(RNA_property_identifier(userprop));
5901  }
5902  else {
5903  return NULL; /* can't do anything about this case yet... */
5904  }
5905  }
5906  else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) {
5907  /* special case, easier to deal with here than in ptr->type->path() */
5909  }
5910  else {
5911  return NULL;
5912  }
5913  }
5914 
5915  return ptrpath;
5916 }
5917 
5918 char *RNA_path_from_real_ID_to_struct(Main *bmain, PointerRNA *ptr, struct ID **r_real)
5919 {
5920  char *path = RNA_path_from_ID_to_struct(ptr);
5921 
5922  /* NULL path is valid in that case, when given struct is an ID one... */
5923  return rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real);
5924 }
5925 
5927  const int totdims,
5928  const int index_dim,
5929  int index,
5930  int r_index_multi[RNA_MAX_ARRAY_LENGTH])
5931 {
5932  int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1];
5933  int i = totdims - 1;
5934  dimsize_step[i + 1] = 1;
5935  dimsize_step[i] = dimsize[i];
5936  while (--i != -1) {
5937  dimsize_step[i] = dimsize[i] * dimsize_step[i + 1];
5938  }
5939  while (++i != index_dim) {
5940  int index_round = index / dimsize_step[i + 1];
5941  r_index_multi[i] = index_round;
5942  index -= (index_round * dimsize_step[i + 1]);
5943  }
5944  BLI_assert(index == 0);
5945 }
5946 
5948  PropertyRNA *prop,
5949  int index_dim,
5950  int index,
5951  char *index_str,
5952  int index_str_len)
5953 {
5954  int dimsize[RNA_MAX_ARRAY_LENGTH];
5955  int totdims = RNA_property_array_dimension(ptr, prop, dimsize);
5956  int index_multi[RNA_MAX_ARRAY_LENGTH];
5957 
5958  rna_path_array_multi_from_flat_index(dimsize, totdims, index_dim, index, index_multi);
5959 
5960  for (int i = 0, offset = 0; (i < index_dim) && (offset < index_str_len); i++) {
5961  offset += BLI_snprintf_rlen(
5962  &index_str[offset], index_str_len - offset, "[%d]", index_multi[i]);
5963  }
5964 }
5965 
5972  PropertyRNA *prop,
5973  int index_dim,
5974  int index)
5975 {
5976  const bool is_rna = (prop->magic == RNA_MAGIC);
5977  const char *propname;
5978  char *ptrpath, *path;
5979 
5980  if (!ptr->owner_id || !ptr->data) {
5981  return NULL;
5982  }
5983 
5984  /* path from ID to the struct holding this property */
5985  ptrpath = RNA_path_from_ID_to_struct(ptr);
5986 
5987  propname = RNA_property_identifier(prop);
5988 
5989  /* support indexing w/ multi-dimensional arrays */
5990  char index_str[RNA_MAX_ARRAY_LENGTH * 12 + 1];
5991  if (index_dim == 0) {
5992  index_str[0] = '\0';
5993  }
5994  else {
5996  ptr, prop, index_dim, index, index_str, sizeof(index_str));
5997  }
5998 
5999  if (ptrpath) {
6000  if (is_rna) {
6001  path = BLI_sprintfN("%s.%s%s", ptrpath, propname, index_str);
6002  }
6003  else {
6004  char propname_esc[MAX_IDPROP_NAME * 2];
6005  BLI_str_escape(propname_esc, propname, sizeof(propname_esc));
6006  path = BLI_sprintfN("%s[\"%s\"]%s", ptrpath, propname_esc, index_str);
6007  }
6008  MEM_freeN(ptrpath);
6009  }
6010  else if (RNA_struct_is_ID(ptr->type)) {
6011  if (is_rna) {
6012  path = BLI_sprintfN("%s%s", propname, index_str);
6013  }
6014  else {
6015  char propname_esc[MAX_IDPROP_NAME * 2];
6016  BLI_str_escape(propname_esc, propname, sizeof(propname_esc));
6017  path = BLI_sprintfN("[\"%s\"]%s", propname_esc, index_str);
6018  }
6019  }
6020  else {
6021  path = NULL;
6022  }
6023 
6024  return path;
6025 }
6026 
6028 {
6029  return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1);
6030 }
6031 
6033  Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real_id)
6034 {
6035  char *path = RNA_path_from_ID_to_property_index(ptr, prop, index_dim, index);
6036 
6037  /* NULL path is always an error here, in that case do not return the 'fake ID from real ID' part
6038  * of the path either. */
6039  return path != NULL ? rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real_id) : NULL;
6040 }
6041 
6047  PropertyRNA *prop,
6048  const StructRNA *type)
6049 {
6050  /* Try to recursively find an "type"'d ancestor,
6051  * to handle situations where path from ID is not enough. */
6052  PointerRNA idptr;
6053  ListBase path_elems = {NULL};
6054  char *path = NULL;
6055  char *full_path = RNA_path_from_ID_to_property(ptr, prop);
6056 
6057  if (full_path == NULL) {
6058  return NULL;
6059  }
6060 
6062 
6063  if (RNA_path_resolve_elements(&idptr, full_path, &path_elems)) {
6064  PropertyElemRNA *prop_elem;
6065 
6066  for (prop_elem = path_elems.last; prop_elem; prop_elem = prop_elem->prev) {
6067  if (RNA_struct_is_a(prop_elem->ptr.type, type)) {
6068  char *ref_path = RNA_path_from_ID_to_struct(&prop_elem->ptr);
6069  if (ref_path) {
6070  path = BLI_strdup(full_path + strlen(ref_path) + 1); /* +1 for the linking '.' */
6071  MEM_freeN(ref_path);
6072  }
6073  break;
6074  }
6075  }
6076 
6077  BLI_freelistN(&path_elems);
6078  }
6079 
6080  MEM_freeN(full_path);
6081  return path;
6082 }
6083 
6088 char *RNA_path_full_ID_py(Main *bmain, ID *id)
6089 {
6090  const char *path;
6091  ID *id_real = RNA_find_real_ID_and_path(bmain, id, &path);
6092 
6093  if (id_real) {
6094  id = id_real;
6095  }
6096  else {
6097  path = "";
6098  }
6099 
6100  char id_esc[(sizeof(id->name) - 2) * 2];
6101 
6102  BLI_str_escape(id_esc, id->name + 2, sizeof(id_esc));
6103 
6104  return BLI_sprintfN("bpy.data.%s[\"%s\"]%s%s",
6106  id_esc,
6107  path[0] ? "." : "",
6108  path);
6109 }
6110 
6116 {
6117  char *id_path;
6118  char *data_path;
6119 
6120  char *ret;
6121 
6122  if (!ptr->owner_id) {
6123  return NULL;
6124  }
6125 
6126  /* never fails */
6127  id_path = RNA_path_full_ID_py(bmain, ptr->owner_id);
6128 
6129  data_path = RNA_path_from_ID_to_struct(ptr);
6130 
6131  /* XXX data_path may be NULL (see T36788),
6132  * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */
6133  ret = BLI_sprintfN("%s.%s", id_path, data_path);
6134 
6135  if (data_path) {
6136  MEM_freeN(data_path);
6137  }
6138  MEM_freeN(id_path);
6139 
6140  return ret;
6141 }
6142 
6148  Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback)
6149 {
6150  char *id_path;
6151  const char *data_delim;
6152  const char *data_path;
6153  bool data_path_free;
6154 
6155  char *ret;
6156 
6157  if (!ptr->owner_id) {
6158  return NULL;
6159  }
6160 
6161  /* never fails */
6162  id_path = RNA_path_full_ID_py(bmain, ptr->owner_id);
6163 
6164  data_path = RNA_path_from_ID_to_property(ptr, prop);
6165  if (data_path) {
6166  data_delim = (data_path[0] == '[') ? "" : ".";
6167  data_path_free = true;
6168  }
6169  else {
6170  if (use_fallback) {
6171  /* Fuzzy fallback. Be explicit in our ignorance. */
6172  data_path = RNA_property_identifier(prop);
6173  data_delim = " ... ";
6174  }
6175  else {
6176  data_delim = ".";
6177  }
6178  data_path_free = false;
6179  }
6180 
6181  if ((index == -1) || (RNA_property_array_check(prop) == false)) {
6182  ret = BLI_sprintfN("%s%s%s", id_path, data_delim, data_path);
6183  }
6184  else {
6185  ret = BLI_sprintfN("%s%s%s[%d]", id_path, data_delim, data_path, index);
6186  }
6187  MEM_freeN(id_path);
6188  if (data_path_free) {
6189  MEM_freeN((void *)data_path);
6190  }
6191 
6192  return ret;
6193 }
6194 
6196 {
6197  return RNA_path_full_property_py_ex(bmain, ptr, prop, index, false);
6198 }
6199 
6205 {
6206  char *data_path;
6207 
6208  char *ret;
6209 
6210  if (!ptr->owner_id) {
6211  return NULL;
6212  }
6213 
6214  data_path = RNA_path_from_ID_to_property(ptr, prop);
6215 
6216  if (data_path == NULL) {
6217  /* this may not be an ID at all, check for simple when pointer owns property.
6218  * TODO, more complex nested case */
6219  if (!RNA_struct_is_ID(ptr->type)) {
6220  const char *prop_identifier = RNA_property_identifier(prop);
6221  if (RNA_struct_find_property(ptr, prop_identifier) == prop) {
6222  data_path = BLI_strdup(prop_identifier);
6223  }
6224  }
6225  }
6226 
6227  if ((index == -1) || (RNA_property_array_check(prop) == false)) {
6228  ret = BLI_sprintfN("%s", data_path);
6229  }
6230  else {
6231  ret = BLI_sprintfN("%s[%d]", data_path, index);
6232  }
6233 
6234  if (data_path) {
6235  MEM_freeN(data_path);
6236  }
6237 
6238  return ret;
6239 }
6240 
6246 {
6247  char *ret;
6248 
6249  if ((index == -1) || (RNA_property_array_check(prop) == false)) {
6250  ret = BLI_sprintfN("%s", RNA_property_identifier(prop));
6251  }
6252  else {
6253  ret = BLI_sprintfN("%s[%d]", RNA_property_identifier(prop), index);
6254  }
6255 
6256  return ret;
6257 }
6258 
6259 /* Quick name based property access */
6260 
6261 bool RNA_boolean_get(PointerRNA *ptr, const char *name)
6262 {
6264 
6265  if (prop) {
6266  return RNA_property_boolean_get(ptr, prop);
6267  }
6268  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6269  return 0;
6270 }
6271 
6272 void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
6273 {
6275 
6276  if (prop) {
6277  RNA_property_boolean_set(ptr, prop, value);
6278  }
6279  else {
6280  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6281  }
6282 }
6283 
6284 void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
6285 {
6287 
6288  if (prop) {
6289  RNA_property_boolean_get_array(ptr, prop, values);
6290  }
6291  else {
6292  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6293  }
6294 }
6295 
6296 void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
6297 {
6299 
6300  if (prop) {
6301  RNA_property_boolean_set_array(ptr, prop, values);
6302  }
6303  else {
6304  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6305  }
6306 }
6307 
6308 int RNA_int_get(PointerRNA *ptr, const char *name)
6309 {
6311 
6312  if (prop) {
6313  return RNA_property_int_get(ptr, prop);
6314  }
6315  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6316  return 0;
6317 }
6318 
6319 void RNA_int_set(PointerRNA *ptr, const char *name, int value)
6320 {
6322 
6323  if (prop) {
6324  RNA_property_int_set(ptr, prop, value);
6325  }
6326  else {
6327  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6328  }
6329 }
6330 
6331 void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
6332 {
6334 
6335  if (prop) {
6336  RNA_property_int_get_array(ptr, prop, values);
6337  }
6338  else {
6339  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6340  }
6341 }
6342 
6343 void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
6344 {
6346 
6347  if (prop) {
6348  RNA_property_int_set_array(ptr, prop, values);
6349  }
6350  else {
6351  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6352  }
6353 }
6354 
6355 float RNA_float_get(PointerRNA *ptr, const char *name)
6356 {
6358 
6359  if (prop) {
6360  return RNA_property_float_get(ptr, prop);
6361  }
6362  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6363  return 0;
6364 }
6365 
6366 void RNA_float_set(PointerRNA *ptr, const char *name, float value)
6367 {
6369 
6370  if (prop) {
6371  RNA_property_float_set(ptr, prop, value);
6372  }
6373  else {
6374  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6375  }
6376 }
6377 
6378 void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
6379 {
6381 
6382  if (prop) {
6383  RNA_property_float_get_array(ptr, prop, values);
6384  }
6385  else {
6386  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6387  }
6388 }
6389 
6390 void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
6391 {
6393 
6394  if (prop) {
6395  RNA_property_float_set_array(ptr, prop, values);
6396  }
6397  else {
6398  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6399  }
6400 }
6401 
6402 int RNA_enum_get(PointerRNA *ptr, const char *name)
6403 {
6405 
6406  if (prop) {
6407  return RNA_property_enum_get(ptr, prop);
6408  }
6409  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6410  return 0;
6411 }
6412 
6413 void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
6414 {
6416 
6417  if (prop) {
6418  RNA_property_enum_set(ptr, prop, value);
6419  }
6420  else {
6421  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6422  }
6423 }
6424 
6425 void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
6426 {
6428 
6429  if (prop) {
6430  int value;
6431  if (RNA_property_enum_value(C, ptr, prop, id, &value)) {
6432  RNA_property_enum_set(ptr, prop, value);
6433  }
6434  else {
6435  printf("%s: %s.%s has no enum id '%s'.\n", __func__, ptr->type->identifier, name, id);
6436  }
6437  }
6438  else {
6439  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6440  }
6441 }
6442 
6443 bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
6444 {
6446  const EnumPropertyItem *item;
6447  bool free;
6448 
6449  if (prop) {
6450  int i;
6451  bool cmp = false;
6452 
6453  RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
6454  i = RNA_enum_from_identifier(item, enumname);
6455  if (i != -1) {
6456  cmp = (item[i].value == RNA_property_enum_get(ptr, prop));
6457  }
6458 
6459  if (free) {
6460  MEM_freeN((void *)item);
6461  }
6462 
6463  if (i != -1) {
6464  return cmp;
6465  }
6466 
6467  printf("%s: %s.%s item %s not found.\n", __func__, ptr->type->identifier, name, enumname);
6468  return false;
6469  }
6470  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6471  return false;
6472 }
6473 
6474 bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
6475 {
6476  const int i = RNA_enum_from_identifier(item, identifier);
6477  if (i != -1) {
6478  *r_value = item[i].value;
6479  return true;
6480  }
6481  return false;
6482 }
6483 
6484 bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
6485 {
6486  const int i = RNA_enum_from_value(item, value);
6487  if (i != -1) {
6488  *r_identifier = item[i].identifier;
6489  return true;
6490  }
6491  return false;
6492 }
6493 
6494 bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
6495 {
6496  const int i = RNA_enum_from_value(item, value);
6497  if (i != -1) {
6498  *r_icon = item[i].icon;
6499  return true;
6500  }
6501  return false;
6502 }
6503 
6504 bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
6505 {
6506  const int i = RNA_enum_from_value(item, value);
6507  if (i != -1) {
6508  *r_name = item[i].name;
6509  return true;
6510  }
6511  return false;
6512 }
6513 
6514 void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
6515 {
6517 
6518  if (prop) {
6519  RNA_property_string_get(ptr, prop, value);
6520  }
6521  else {
6522  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6523  value[0] = '\0';
6524  }
6525 }
6526 
6527 char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
6528 {
6530 
6531  if (prop) {
6532  /* TODO, pass length */
6533  return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, NULL);
6534  }
6535  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6536  return NULL;
6537 }
6538 
6540 {
6542 
6543  if (prop) {
6544  return RNA_property_string_length(ptr, prop);
6545  }
6546  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6547  return 0;
6548 }
6549 
6550 void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
6551 {
6553 
6554  if (prop) {
6555  RNA_property_string_set(ptr, prop, value);
6556  }
6557  else {
6558  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6559  }
6560 }
6561 
6563 {
6565 
6566  if (prop) {
6567  return RNA_property_pointer_get(ptr, prop);
6568  }
6569  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6570 
6571  return PointerRNA_NULL;
6572 }
6573 
6574 void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
6575 {
6577 
6578  if (prop) {
6579  RNA_property_pointer_set(ptr, prop, ptr_value, NULL);
6580  }
6581  else {
6582  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6583  }
6584 }
6585 
6586 void RNA_pointer_add(PointerRNA *ptr, const char *name)
6587 {
6589 
6590  if (prop) {
6592  }
6593  else {
6594  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6595  }
6596 }
6597 
6599 {
6601 
6602  if (prop) {
6603  RNA_property_collection_begin(ptr, prop, iter);
6604  }
6605  else {
6606  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6607  }
6608 }
6609 
6610 void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
6611 {
6613 
6614  if (prop) {
6615  RNA_property_collection_add(ptr, prop, r_value);
6616  }
6617  else {
6618  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6619  }
6620 }
6621 
6623 {
6625 
6626  if (prop) {
6628  }
6629  else {
6630  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6631  }
6632 }
6633 
6635 {
6637 
6638  if (prop) {
6639  return RNA_property_collection_length(ptr, prop);
6640  }
6641  printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
6642  return 0;
6643 }
6644 
6645 bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
6646 {
6647  prop = rna_ensure_property(prop);
6648  if (prop->flag & PROP_IDPROPERTY) {
6649  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
6650  return ((idprop != NULL) && (use_ghost == false || !(idprop->flag & IDP_FLAG_GHOST)));
6651  }
6652  return true;
6653 }
6654 
6656 {
6657  prop = rna_ensure_property(prop);
6658  if (prop->flag & PROP_IDPROPERTY) {
6659  IDProperty *idprop = rna_idproperty_find(ptr, prop->identifier);
6660  return ((idprop != NULL) && !(idprop->flag & IDP_FLAG_GHOST));
6661  }
6662  return true;
6663 }
6664 
6666 {
6667  prop = rna_ensure_property(prop);
6668  if (prop->flag & PROP_IDPROPERTY) {
6670  }
6671 }
6672 
6673 bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
6674 {
6675  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
6676 
6677  if (prop) {
6678  return RNA_property_is_set_ex(ptr, prop, use_ghost);
6679  }
6680  /* python raises an error */
6681  /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
6682  return 0;
6683 }
6684 
6685 bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
6686 {
6687  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
6688 
6689  if (prop) {
6690  return RNA_property_is_set(ptr, prop);
6691  }
6692  /* python raises an error */
6693  /* printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name); */
6694  return 0;
6695 }
6696 
6697 void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
6698 {
6699  PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
6700 
6701  if (prop) {
6702  RNA_property_unset(ptr, prop);
6703  }
6704 }
6705 
6707 {
6708  return (prop->magic != RNA_MAGIC);
6709 }
6710 
6711 /* mainly for the UI */
6713 {
6714  const int flag = RNA_property_flag(prop);
6715  if (RNA_property_type(prop) == PROP_STRING) {
6716  return (flag & PROP_NEVER_UNLINK) == 0;
6717  }
6718  return (flag & (PROP_NEVER_UNLINK | PROP_NEVER_NULL)) == 0;
6719 }
6720 
6721 /* string representation of a property, python
6722  * compatible but can be used for display too,
6723  * context may be NULL */
6725 {
6726  DynStr *dynstr = BLI_dynstr_new();
6727  char *cstring;
6728 
6729  const char *propname;
6730  int first_time = 1;
6731 
6732  BLI_dynstr_append(dynstr, "{");
6733 
6734  RNA_STRUCT_BEGIN (ptr, prop) {
6735  propname = RNA_property_identifier(prop);
6736 
6737  if (STREQ(propname, "rna_type")) {
6738  continue;
6739  }
6740 
6741  if (first_time == 0) {
6742  BLI_dynstr_append(dynstr, ", ");
6743  }
6744  first_time = 0;
6745 
6746  cstring = RNA_property_as_string(C, ptr, prop, -1, INT_MAX);
6747  BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
6748  MEM_freeN(cstring);
6749  }
6751 
6752  BLI_dynstr_append(dynstr, "}");
6753 
6754  cstring = BLI_dynstr_get_cstring(dynstr);
6755  BLI_dynstr_free(dynstr);
6756  return cstring;
6757 }
6758 
6760 {
6761  if (ptr->type == NULL || ptr->owner_id == NULL) {
6762  return BLI_strdup("None");
6763  }
6764  if (RNA_struct_is_ID(ptr->type)) {
6765  return RNA_path_full_ID_py(bmain, ptr->owner_id);
6766  }
6767  return RNA_path_full_struct_py(bmain, ptr);
6768 }
6769 
6771  PointerRNA *ptr,
6772  PropertyRNA *prop_ptr,
6773  PointerRNA *ptr_prop)
6774 {
6775  IDProperty *prop;
6776  if (ptr_prop->data == NULL) {
6777  return BLI_strdup("None");
6778  }
6779  if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) {
6780  return RNA_pointer_as_string_id(C, ptr_prop);
6781  }
6782  return rna_pointer_as_string__bldata(CTX_data_main(C), ptr_prop);
6783 }
6784 
6785 /* context can be NULL */
6787  PointerRNA *ptr,
6788  const bool as_function,
6789  const bool all_args,
6790  const bool nested_args,
6791  const int max_prop_length,
6792  PropertyRNA *iterprop)
6793 {
6794  const char *arg_name = NULL;
6795 
6796  PropertyRNA *prop;
6797 
6798  DynStr *dynstr = BLI_dynstr_new();
6799  char *cstring, *buf;
6800  bool first_iter = true;
6801  int flag, flag_parameter;
6802 
6803  RNA_PROP_BEGIN (ptr, propptr, iterprop) {
6804  prop = propptr.data;
6805 
6806  flag = RNA_property_flag(prop);
6807  flag_parameter = RNA_parameter_flag(prop);
6808 
6809  if (as_function && (flag_parameter & PARM_OUTPUT)) {
6810  continue;
6811  }
6812 
6813  arg_name = RNA_property_identifier(prop);
6814 
6815  if (STREQ(arg_name, "rna_type")) {
6816  continue;
6817  }
6818 
6819  if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) {
6820  continue;
6821  }
6822 
6823  if (as_function && (prop->flag_parameter & PARM_REQUIRED)) {
6824  /* required args don't have useful defaults */
6825  BLI_dynstr_appendf(dynstr, first_iter ? "%s" : ", %s", arg_name);
6826  first_iter = false;
6827  }
6828  else {
6829  bool ok = true;
6830 
6831  if (all_args == true) {
6832  /* pass */
6833  }
6834  else if (RNA_struct_idprops_check(ptr->type)) {
6835  ok = RNA_property_is_set(ptr, prop);
6836  }
6837 
6838  if (ok) {
6839  if (as_function && RNA_property_type(prop) == PROP_POINTER) {
6840  /* don't expand pointers for functions */
6841  if (flag & PROP_NEVER_NULL) {
6842  /* we cant really do the right thing here. arg=arg?, hrmf! */
6843  buf = BLI_strdup(arg_name);
6844  }
6845  else {
6846  buf = BLI_strdup("None");
6847  }
6848  }
6849  else {
6850  buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length);
6851  }
6852 
6853  BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s" : ", %s=%s", arg_name, buf);
6854  first_iter = false;
6855  MEM_freeN(buf);
6856  }
6857  }
6858  }
6859  RNA_PROP_END;
6860 
6861  cstring = BLI_dynstr_get_cstring(dynstr);
6862  BLI_dynstr_free(dynstr);
6863  return cstring;
6864 }
6865 
6867  PointerRNA *ptr,
6868  const bool as_function,
6869  const bool all_args,
6870  const bool nested_args,
6871  const int max_prop_length)
6872 {
6873  PropertyRNA *iterprop;
6874 
6875  iterprop = RNA_struct_iterator_property(ptr->type);
6876 
6878  C, ptr, as_function, all_args, nested_args, max_prop_length, iterprop);
6879 }
6880 
6882  FunctionRNA *func,
6883  const bool as_function,
6884  const bool all_args,
6885  const int max_prop_length)
6886 {
6887  PointerRNA funcptr;
6888  PropertyRNA *iterprop;
6889 
6890  RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
6891 
6892  iterprop = RNA_struct_find_property(&funcptr, "parameters");
6893 
6895 
6897  C, &funcptr, as_function, all_args, true, max_prop_length, iterprop);
6898 }
6899 
6900 static const char *bool_as_py_string(const int var)
6901 {
6902  return var ? "True" : "False";
6903 }
6904 
6906  int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
6907 {
6908  void *buf_ret = NULL;
6909  if (type == PROP_BOOLEAN) {
6910  bool *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
6911  RNA_property_boolean_get_array(ptr, prop, buf);
6912  *r_buf_end = buf + len;
6913  }
6914  else if (type == PROP_INT) {
6915  int *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
6916  RNA_property_int_get_array(ptr, prop, buf);
6917  *r_buf_end = buf + len;
6918  }
6919  else if (type == PROP_FLOAT) {
6920  float *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__);
6921  RNA_property_float_get_array(ptr, prop, buf);
6922  *r_buf_end = buf + len;
6923  }
6924  else {
6925  BLI_assert(0);
6926  }
6927  return buf_ret;
6928 }
6929 
6930 static void rna_array_as_string_elem(int type, void **buf_p, int len, DynStr *dynstr)
6931 {
6932  /* This will print a comma separated string of the array elements from
6933  * buf start to len. We will add a comma if len == 1 to preserve tuples. */
6934  const int end = len - 1;
6935  if (type == PROP_BOOLEAN) {
6936  bool *buf = *buf_p;
6937  for (int i = 0; i < len; i++, buf++) {
6938  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%s, " : "%s", bool_as_py_string(*buf));
6939  }
6940  *buf_p = buf;
6941  }
6942  else if (type == PROP_INT) {
6943  int *buf = *buf_p;
6944  for (int i = 0; i < len; i++, buf++) {
6945  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%d, " : "%d", *buf);
6946  }
6947  *buf_p = buf;
6948  }
6949  else if (type == PROP_FLOAT) {
6950  float *buf = *buf_p;
6951  for (int i = 0; i < len; i++, buf++) {
6952  BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%g, " : "%g", *buf);
6953  }
6954  *buf_p = buf;
6955  }
6956  else {
6957  BLI_assert(0);
6958  }
6959 }
6960 
6962  int type, void **buf_p, int totdim, const int *dim_size, DynStr *dynstr)
6963 {
6964  BLI_dynstr_append(dynstr, "(");
6965  if (totdim > 1) {
6966  totdim--;
6967  const int end = dim_size[totdim] - 1;
6968  for (int i = 0; i <= end; i++) {
6969  rna_array_as_string_recursive(type, buf_p, totdim, dim_size, dynstr);
6970  if (i < end || !end) {
6971  BLI_dynstr_append(dynstr, ", ");
6972  }
6973  }
6974  }
6975  else {
6976  rna_array_as_string_elem(type, buf_p, dim_size[0], dynstr);
6977  }
6978  BLI_dynstr_append(dynstr, ")");
6979 }
6980 
6982  int type, int len, PointerRNA *ptr, PropertyRNA *prop, DynStr *dynstr)
6983 {
6984  void *buf_end;
6985  void *buf = rna_array_as_string_alloc(type, len, ptr, prop, &buf_end);
6986  void *buf_step = buf;
6987  int totdim, dim_size[RNA_MAX_ARRAY_DIMENSION];
6988 
6989  totdim = RNA_property_array_dimension(ptr, prop, dim_size);
6990 
6991  rna_array_as_string_recursive(type, &buf_step, totdim, dim_size, dynstr);
6992  BLI_assert(buf_step == buf_end);
6993  MEM_freeN(buf);
6994 }
6995 
6997  bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
6998 {
6999  int type = RNA_property_type(prop);
7000  int len = RNA_property_array_length(ptr, prop);
7001 
7002  DynStr *dynstr = BLI_dynstr_new();
7003  char *cstring;
7004 
7005  /* see if we can coerce into a python type - PropertyType */
7006  switch (type) {
7007  case PROP_BOOLEAN:
7008  if (len == 0) {
7010  }
7011  else {
7012  if (index != -1) {
7013  BLI_dynstr_append(dynstr,
7015  }
7016  else {
7017  rna_array_as_string(type, len, ptr, prop, dynstr);
7018  }
7019  }
7020  break;
7021  case PROP_INT:
7022  if (len == 0) {
7023  BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get(ptr, prop));
7024  }
7025  else {
7026  if (index != -1) {
7027  BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get_index(ptr, prop, index));
7028  }
7029  else {
7030  rna_array_as_string(type, len, ptr, prop, dynstr);
7031  }
7032  }
7033  break;
7034  case PROP_FLOAT:
7035  if (len == 0) {
7036  BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get(ptr, prop));
7037  }
7038  else {
7039  if (index != -1) {
7041  }
7042  else {
7043  rna_array_as_string(type, len, ptr, prop, dynstr);
7044  }
7045  }
7046  break;
7047  case PROP_STRING: {
7048  char *buf_esc;
7049  char *buf;
7050  int length;
7051 
7053  buf = MEM_mallocN(sizeof(char) * (length + 1), "RNA_property_as_string");
7054  buf_esc = MEM_mallocN(sizeof(char) * (length * 2 + 1), "RNA_property_as_string esc");
7055  RNA_property_string_get(ptr, prop, buf);
7056  BLI_str_escape(buf_esc, buf, length * 2 + 1);
7057  MEM_freeN(buf);
7058  BLI_dynstr_appendf(dynstr, "\"%s\"", buf_esc);
7059  MEM_freeN(buf_esc);
7060  break;
7061  }
7062  case PROP_ENUM: {
7063  /* string arrays don't exist */
7064  const char *identifier;
7065  int val = RNA_property_enum_get(ptr, prop);
7066 
7067  if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
7068  /* represent as a python set */
7069  if (val) {
7070  const EnumPropertyItem *item_array;
7071  bool free;
7072 
7073  BLI_dynstr_append(dynstr, "{");
7074 
7075  RNA_property_enum_items(C, ptr, prop, &item_array, NULL, &free);
7076  if (item_array) {
7077  const EnumPropertyItem *item = item_array;
7078  bool is_first = true;
7079  for (; item->identifier; item++) {
7080  if (item->identifier[0] && item->value & val) {
7081  BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier);
7082  is_first = false;
7083  }
7084  }
7085 
7086  if (free) {
7087  MEM_freeN((void *)item_array);
7088  }
7089  }
7090 
7091  BLI_dynstr_append(dynstr, "}");
7092  }
7093  else {
7094  /* annoying exception, don't confuse with dictionary syntax above: {} */
7095  BLI_dynstr_append(dynstr, "set()");
7096  }
7097  }
7098  else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
7099  BLI_dynstr_appendf(dynstr, "'%s'", identifier);
7100  }
7101  else {
7102  BLI_dynstr_append(dynstr, "'<UNKNOWN ENUM>'");
7103  }
7104  break;
7105  }
7106  case PROP_POINTER: {
7107  PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
7108  cstring = RNA_pointer_as_string(C, ptr, prop, &tptr);
7109  BLI_dynstr_append(dynstr, cstring);
7110  MEM_freeN(cstring);
7111  break;
7112  }
7113  case PROP_COLLECTION: {
7114  int i = 0;
7115  CollectionPropertyIterator collect_iter;
7116  BLI_dynstr_append(dynstr, "[");
7117 
7118  for (RNA_property_collection_begin(ptr, prop, &collect_iter);
7119  (i < max_prop_length) && collect_iter.valid;
7120  RNA_property_collection_next(&collect_iter), i++) {
7121  PointerRNA itemptr = collect_iter.ptr;
7122 
7123  if (i != 0) {
7124  BLI_dynstr_append(dynstr, ", ");
7125  }
7126 
7127  /* now get every prop of the collection */
7128  cstring = RNA_pointer_as_string(C, ptr, prop, &itemptr);
7129  BLI_dynstr_append(dynstr, cstring);
7130  MEM_freeN(cstring);
7131  }
7132 
7133  RNA_property_collection_end(&collect_iter);
7134  BLI_dynstr_append(dynstr, "]");
7135  break;
7136  }
7137  default:
7138  BLI_dynstr_append(dynstr, "'<UNKNOWN TYPE>'"); /* TODO */
7139  break;
7140  }
7141 
7142  cstring = BLI_dynstr_get_cstring(dynstr);
7143  BLI_dynstr_free(dynstr);
7144  return cstring;
7145 }
7146 
7147 /* Function */
7148 
7150 {
7151  return func->identifier;
7152 }
7153 
7155 {
7156  return TIP_(func->description);
7157 }
7158 
7160 {
7161  return func->description;
7162 }
7163 
7165 {
7166  return func->flag;
7167 }
7168 
7170 {
7171  return func->call != NULL;
7172 }
7173 
7175 {
7176  return BLI_findlink(&func->cont.properties, index);
7177 }
7178 
7180  FunctionRNA *func,
7181  const char *identifier)
7182 {
7183  PropertyRNA *parm;
7184 
7185  parm = func->cont.properties.first;
7186  for (; parm; parm = parm->next) {
7187  if (STREQ(RNA_property_identifier(parm), identifier)) {
7188  break;
7189  }
7190  }
7191 
7192  return parm;
7193 }
7194 
7196 {
7197  return &func->cont.properties;
7198 }
7199 
7200 /* Utility */
7201 
7203 {
7204  return (int)rna_ensure_property(prop)->flag_parameter;
7205 }
7206 
7208  PointerRNA *UNUSED(ptr),
7209  FunctionRNA *func)
7210 {
7211  PropertyRNA *parm;
7212  PointerRNA null_ptr = PointerRNA_NULL;
7213  void *data;
7214  int alloc_size = 0, size;
7215 
7216  parms->arg_count = 0;
7217  parms->ret_count = 0;
7218 
7219  /* allocate data */
7220  for (parm = func->cont.properties.first; parm; parm = parm->next) {
7221  alloc_size += rna_parameter_size(parm);
7222 
7223  if (parm->flag_parameter & PARM_OUTPUT) {
7224  parms->ret_count++;
7225  }
7226  else {
7227  parms->arg_count++;
7228  }
7229  }
7230 
7231  parms->data = MEM_callocN(alloc_size, "RNA_parameter_list_create");
7232  parms->func = func;
7233  parms->alloc_size = alloc_size;
7234 
7235  /* set default values */
7236  data = parms->data;
7237 
7238  for (parm = func->cont.properties.first; parm; parm = parm->next) {
7239  size = rna_parameter_size(parm);
7240 
7241  /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */
7242  if (parm->flag & PROP_DYNAMIC) {
7243  ParameterDynAlloc *data_alloc = data;
7244  data_alloc->array_tot = 0;
7245  data_alloc->array = NULL;
7246  }
7247 
7248  if (!(parm->flag_parameter & PARM_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
7249  switch (parm->type) {
7250  case PROP_BOOLEAN:
7251  if (parm->arraydimension) {
7253  &null_ptr, (BoolPropertyRNA *)parm, data);
7254  }
7255  else {
7256  memcpy(data, &((BoolPropertyRNA *)parm)->defaultvalue, size);
7257  }
7258  break;
7259  case PROP_INT:
7260  if (parm->arraydimension) {
7262  }
7263  else {
7264  memcpy(data, &((IntPropertyRNA *)parm)->defaultvalue, size);
7265  }
7266  break;
7267  case PROP_FLOAT:
7268  if (parm->arraydimension) {
7270  }
7271  else {
7272  memcpy(data, &((FloatPropertyRNA *)parm)->defaultvalue, size);
7273  }
7274  break;
7275  case PROP_ENUM:
7276  memcpy(data, &((EnumPropertyRNA *)parm)->defaultvalue, size);
7277  break;
7278  case PROP_STRING: {
7279  const char *defvalue = ((StringPropertyRNA *)parm)->defaultvalue;
7280  if (defvalue && defvalue[0]) {
7281  /* causes bug T29988, possibly this is only correct for thick wrapped
7282  * need to look further into it - campbell */
7283 #if 0
7284  BLI_strncpy(data, defvalue, size);
7285 #else
7286  memcpy(data, &defvalue, size);
7287 #endif
7288  }
7289  break;
7290  }
7291  case PROP_POINTER:
7292  case PROP_COLLECTION:
7293  break;
7294  }
7295  }
7296 
7297  data = ((char *)data) + rna_parameter_size(parm);
7298  }
7299 
7300  return parms;
7301 }
7302 
7304 {
7305  PropertyRNA *parm;
7306  int tot;
7307 
7308  parm = parms->func->cont.properties.first;
7309  for (tot = 0; parm; parm = parm->next) {
7310  if (parm->type == PROP_COLLECTION) {
7311  BLI_freelistN((ListBase *)((char *)parms->data + tot));
7312  }
7313  else if (parm->flag & PROP_DYNAMIC) {
7314  /* for dynamic arrays and strings, data is a pointer to an array */
7315  ParameterDynAlloc *data_alloc = (void *)(((char *)parms->data) + tot);
7316  if (data_alloc->array) {
7317  MEM_freeN(data_alloc->array);
7318  }
7319  }
7320 
7321  tot += rna_parameter_size(parm);
7322  }
7323 
7324  MEM_freeN(parms->data);
7325  parms->data = NULL;
7326 
7327  parms->func = NULL;
7328 }
7329 
7331 {
7332  return parms->alloc_size;
7333 }
7334 
7336 {
7337  return parms->arg_count;
7338 }
7339 
7341 {
7342  return parms->ret_count;
7343 }
7344 
7346 {
7347  /* may be useful but unused now */
7348  /* RNA_pointer_create(NULL, &RNA_Function, parms->func, &iter->funcptr); */ /*UNUSED*/
7349 
7350  iter->parms = parms;
7351  iter->parm = parms->func->cont.properties.first;
7352  iter->valid = iter->parm != NULL;
7353  iter->offset = 0;
7354 
7355  if (iter->valid) {
7356  iter->size = rna_parameter_size(iter->parm);
7357  iter->data = (((char *)iter->parms->data)); /* +iter->offset, always 0 */
7358  }
7359 }
7360 
7362 {
7363  iter->offset += iter->size;
7364  iter->parm = iter->parm->next;
7365  iter->valid = iter->parm != NULL;
7366 
7367  if (iter->valid) {
7368  iter->size = rna_parameter_size(iter->parm);
7369  iter->data = (((char *)iter->parms->data) + iter->offset);
7370  }
7371 }
7372 
7374 {
7375  /* nothing to do */
7376 }
7377 
7378 void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **value)
7379 {
7380  ParameterIterator iter;
7381 
7382  RNA_parameter_list_begin(parms, &iter);
7383 
7384  for (; iter.valid; RNA_parameter_list_next(&iter)) {
7385  if (iter.parm == parm) {
7386  break;
7387  }
7388  }
7389 
7390  if (iter.valid) {
7391  if (parm->flag & PROP_DYNAMIC) {
7392  /* for dynamic arrays and strings, data is a pointer to an array */
7393  ParameterDynAlloc *data_alloc = iter.data;
7394  *value = data_alloc->array;
7395  }
7396  else {
7397  *value = iter.data;
7398  }
7399  }
7400  else {
7401  *value = NULL;
7402  }
7403 
7404  RNA_parameter_list_end(&iter);
7405 }
7406 
7407 void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **value)
7408 {
7409  PropertyRNA *parm;
7410 
7411  parm = parms->func->cont.properties.first;
7412  for (; parm; parm = parm->next) {
7413  if (STREQ(RNA_property_identifier(parm), identifier)) {
7414  break;
7415  }
7416  }
7417 
7418  if (parm) {
7419  RNA_parameter_get(parms, parm, value);
7420  }
7421 }
7422 
7423 void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
7424 {
7425  ParameterIterator iter;
7426 
7427  RNA_parameter_list_begin(parms, &iter);
7428 
7429  for (; iter.valid; RNA_parameter_list_next(&iter)) {
7430  if (iter.parm == parm) {
7431  break;
7432  }
7433  }
7434 
7435  if (iter.valid) {
7436  if (parm->flag & PROP_DYNAMIC) {
7437  /* for dynamic arrays and strings, data is a pointer to an array */
7438  ParameterDynAlloc *data_alloc = iter.data;
7439  size_t size = 0;
7440  switch (parm->type) {
7441  case PROP_STRING:
7442  size = sizeof(char);
7443  break;
7444  case PROP_INT:
7445  case PROP_BOOLEAN:
7446  size = sizeof(int);
7447  break;
7448  case PROP_FLOAT:
7449  size = sizeof(float);
7450  break;
7451  default:
7452  break;
7453  }
7454  size *= data_alloc->array_tot;
7455  if (data_alloc->array) {
7456  MEM_freeN(data_alloc->array);
7457  }
7458  data_alloc->array = MEM_mallocN(size, __func__);
7459  memcpy(data_alloc->array, value, size);
7460  }
7461  else {
7462  memcpy(iter.data, value, iter.size);
7463  }
7464  }
7465 
7466  RNA_parameter_list_end(&iter);
7467 }
7468 
7469 void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
7470 {
7471  PropertyRNA *parm;
7472 
7473  parm = parms->func->cont.properties.first;
7474  for (; parm; parm = parm->next) {
7475  if (STREQ(RNA_property_identifier(parm), identifier)) {
7476  break;
7477  }
7478  }
7479 
7480  if (parm) {
7481  RNA_parameter_set(parms, parm, value);
7482  }
7483 }
7484 
7486 {
7487  ParameterIterator iter;
7488  int len = 0;
7489 
7490  RNA_parameter_list_begin(parms, &iter);
7491 
7492  for (; iter.valid; RNA_parameter_list_next(&iter)) {
7493  if (iter.parm == parm) {
7494  break;
7495  }
7496  }
7497 
7498  if (iter.valid) {
7499  len = RNA_parameter_dynamic_length_get_data(parms, parm, iter.data);
7500  }
7501 
7502  RNA_parameter_list_end(&iter);
7503 
7504  return len;
7505 }
7506 
7508 {
7509  ParameterIterator iter;
7510 
7511  RNA_parameter_list_begin(parms, &iter);
7512 
7513  for (; iter.valid; RNA_parameter_list_next(&iter)) {
7514  if (iter.parm == parm) {
7515  break;
7516  }
7517  }
7518 
7519  if (iter.valid) {
7521  }
7522 
7523  RNA_parameter_list_end(&iter);
7524 }
7525 
7527  PropertyRNA *parm,
7528  void *data)
7529 {
7530  if (parm->flag & PROP_DYNAMIC) {
7531  return (int)((ParameterDynAlloc *)data)->array_tot;
7532  }
7533  return 0;
7534 }
7535 
7537  PropertyRNA *parm,
7538  void *data,
7539  int length)
7540 {
7541  if (parm->flag & PROP_DYNAMIC) {
7542  ((ParameterDynAlloc *)data)->array_tot = (intptr_t)length;
7543  }
7544 }
7545 
7547  bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
7548 {
7549  if (func->call) {
7550  func->call(C, reports, ptr, parms);
7551 
7552  return 0;
7553  }
7554 
7555  return -1;
7556 }
7557 
7559  ReportList *reports,
7560  PointerRNA *ptr,
7561  const char *identifier,
7562  ParameterList *parms)
7563 {
7564  FunctionRNA *func;
7565 
7566  func = RNA_struct_find_function(ptr->type, identifier);
7567 
7568  if (func) {
7569  return RNA_function_call(C, reports, ptr, func, parms);
7570  }
7571 
7572  return -1;
7573 }
7574 
7576  bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, ...)
7577 {
7578  va_list args;
7579  int ret;
7580 
7581  va_start(args, format);
7582 
7583  ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
7584 
7585  va_end(args);
7586 
7587  return ret;
7588 }
7589 
7591  ReportList *reports,
7592  PointerRNA *ptr,
7593  const char *identifier,
7594  const char *format,
7595  ...)
7596 {
7597  FunctionRNA *func;
7598 
7599  func = RNA_struct_find_function(ptr->type, identifier);
7600 
7601  if (func) {
7602  va_list args;
7603  int ret;
7604 
7605  va_start(args, format);
7606 
7607  ret = RNA_function_call_direct_va(C, reports, ptr, func, format, args);
7608 
7609  va_end(args);
7610 
7611  return ret;
7612  }
7613 
7614  return -1;
7615 }
7616 
7617 static int rna_function_format_array_length(const char *format, int ofs, int flen)
7618 {
7619  char lenbuf[16];
7620  int idx = 0;
7621 
7622  if (format[ofs++] == '[') {
7623  for (; ofs < flen && format[ofs] != ']' && idx < sizeof(lenbuf) - 1; idx++, ofs++) {
7624  lenbuf[idx] = format[ofs];
7625  }
7626  }
7627 
7628  if (ofs < flen && format[ofs + 1] == ']') {
7629  /* XXX put better error reporting for (ofs >= flen) or idx over lenbuf capacity */
7630  lenbuf[idx] = '\0';
7631  return atoi(lenbuf);
7632  }
7633 
7634  return 0;
7635 }
7636 
7638  PropertyRNA *prop,
7640  char ftype,
7641  int len,
7642  void *dest,
7643  const void *src,
7644  StructRNA *srna,
7645  const char *tid,
7646  const char *fid,
7647  const char *pid)
7648 {
7649  /* ptr is always a function pointer, prop always a parameter */
7650 
7651  switch (type) {
7652  case PROP_BOOLEAN: {
7653  if (ftype != 'b') {
7654  fprintf(
7655  stderr, "%s.%s: wrong type for parameter %s, a boolean was expected\n", tid, fid, pid);
7656  return -1;
7657  }
7658 
7659  if (len == 0) {
7660  *((bool *)dest) = *((bool *)src);
7661  }
7662  else {
7663  memcpy(dest, src, len * sizeof(bool));
7664  }
7665 
7666  break;
7667  }
7668  case PROP_INT: {
7669  if (ftype != 'i') {
7670  fprintf(stderr,
7671  "%s.%s: wrong type for parameter %s, an integer was expected\n",
7672  tid,
7673  fid,
7674  pid);
7675  return -1;
7676  }
7677 
7678  if (len == 0) {
7679  *((int *)dest) = *((int *)src);
7680  }
7681  else {
7682  memcpy(dest, src, len * sizeof(int));
7683  }
7684 
7685  break;
7686  }
7687  case PROP_FLOAT: {
7688  if (ftype != 'f') {
7689  fprintf(
7690  stderr, "%s.%s: wrong type for parameter %s, a float was expected\n", tid, fid, pid);
7691  return -1;
7692  }
7693 
7694  if (len == 0) {
7695  *((float *)dest) = *((float *)src);
7696  }
7697  else {
7698  memcpy(dest, src, len * sizeof(float));
7699  }
7700 
7701  break;
7702  }
7703  case PROP_STRING: {
7704  if (ftype != 's') {
7705  fprintf(
7706  stderr, "%s.%s: wrong type for parameter %s, a string was expected\n", tid, fid, pid);
7707  return -1;
7708  }
7709 
7710  *((char **)dest) = *((char **)src);
7711 
7712  break;
7713  }
7714  case PROP_ENUM: {
7715  if (ftype != 'e') {
7716  fprintf(
7717  stderr, "%s.%s: wrong type for parameter %s, an enum was expected\n", tid, fid, pid);
7718  return -1;
7719  }
7720 
7721  *((int *)dest) = *((int *)src);
7722 
7723  break;
7724  }
7725  case PROP_POINTER: {
7726  StructRNA *ptype;
7727 
7728  if (ftype != 'O') {
7729  fprintf(
7730  stderr, "%s.%s: wrong type for parameter %s, an object was expected\n", tid, fid, pid);
7731  return -1;
7732  }
7733 
7734  ptype = RNA_property_pointer_type(ptr, prop);
7735 
7736  if (prop->flag_parameter & PARM_RNAPTR) {
7737  *((PointerRNA *)dest) = *((PointerRNA *)src);
7738  break;
7739  }
7740 
7741  if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
7742  fprintf(stderr,
7743  "%s.%s: wrong type for parameter %s, "
7744  "an object of type %s was expected, passed an object of type %s\n",
7745  tid,
7746  fid,
7747  pid,
7748  RNA_struct_identifier(ptype),
7749  RNA_struct_identifier(srna));
7750  return -1;
7751  }
7752 
7753  *((void **)dest) = *((void **)src);
7754 
7755  break;
7756  }
7757  case PROP_COLLECTION: {
7758  StructRNA *ptype;
7759  ListBase *lb, *clb;
7760  Link *link;
7761  CollectionPointerLink *clink;
7762 
7763  if (ftype != 'C') {
7764  fprintf(stderr,
7765  "%s.%s: wrong type for parameter %s, a collection was expected\n",
7766  tid,
7767  fid,
7768  pid);
7769  return -1;
7770  }
7771 
7772  lb = (ListBase *)src;
7773  clb = (ListBase *)dest;
7774  ptype = RNA_property_pointer_type(ptr, prop);
7775 
7776  if (ptype != srna && !RNA_struct_is_a(srna, ptype)) {
7777  fprintf(stderr,
7778  "%s.%s: wrong type for parameter %s, "
7779  "a collection of objects of type %s was expected, "
7780  "passed a collection of objects of type %s\n",
7781  tid,
7782  fid,
7783  pid,
7784  RNA_struct_identifier(ptype),
7785  RNA_struct_identifier(srna));
7786  return -1;
7787  }
7788 
7789  for (link = lb->first; link; link = link->next) {
7790  clink = MEM_callocN(sizeof(CollectionPointerLink), "CCollectionPointerLink");
7791  RNA_pointer_create(NULL, srna, link, &clink->ptr);
7792  BLI_addtail(clb, clink);
7793  }
7794 
7795  break;
7796  }
7797  default: {
7798  if (len == 0) {
7799  fprintf(stderr, "%s.%s: unknown type for parameter %s\n", tid, fid, pid);
7800  }
7801  else {
7802  fprintf(stderr, "%s.%s: unknown array type for parameter %s\n", tid, fid, pid);
7803  }
7804 
7805  return -1;
7806  }
7807  }
7808 
7809  return 0;
7810 }
7811 
7813  ReportList *reports,
7814  PointerRNA *ptr,
7815  FunctionRNA *func,
7816  const char *format,
7817  va_list args)
7818 {
7819  PointerRNA funcptr;
7820  ParameterList parms;
7821  ParameterIterator iter;
7822  PropertyRNA *pret, *parm;
7824  int i, ofs, flen, flag_parameter, len, alen, err = 0;
7825  const char *tid, *fid, *pid = NULL;
7826  char ftype;
7827  void **retdata = NULL;
7828 
7829  RNA_pointer_create(NULL, &RNA_Function, func, &funcptr);
7830 
7831  tid = RNA_struct_identifier(ptr->type);
7832  fid = RNA_function_identifier(func);
7833  pret = func->c_ret;
7834  flen = strlen(format);
7835 
7836  RNA_parameter_list_create(&parms, ptr, func);
7837  RNA_parameter_list_begin(&parms, &iter);
7838 
7839  for (i = 0, ofs = 0; iter.valid; RNA_parameter_list_next(&iter), i++) {
7840  parm = iter.parm;
7841  flag_parameter = RNA_parameter_flag(parm);
7842 
7843  if (parm == pret) {
7844  retdata = iter.data;
7845  continue;
7846  }
7847  if (flag_parameter & PARM_OUTPUT) {
7848  continue;
7849  }
7850 
7851  pid = RNA_property_identifier(parm);
7852 
7853  if (ofs >= flen || format[ofs] == 'N') {
7854  if (parm->flag_parameter & PARM_REQUIRED) {
7855  err = -1;
7856  fprintf(stderr, "%s.%s: missing required parameter %s\n", tid, fid, pid);
7857  break;
7858  }
7859  ofs++;
7860  continue;
7861  }
7862 
7863  type = RNA_property_type(parm);
7864  ftype = format[ofs++];
7865  len = RNA_property_array_length(&funcptr, parm);
7866  alen = rna_function_format_array_length(format, ofs, flen);
7867 
7868  if (len != alen) {
7869  err = -1;
7870  fprintf(stderr,
7871  "%s.%s: for parameter %s, "
7872  "was expecting an array of %i elements, "
7873  "passed %i elements instead\n",
7874  tid,
7875  fid,
7876  pid,
7877  len,
7878  alen);
7879  break;
7880  }
7881 
7882  switch (type) {
7883  case PROP_BOOLEAN:
7884  case PROP_INT:
7885  case PROP_ENUM: {
7886  int arg = va_arg(args, int);
7888  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
7889  break;
7890  }
7891  case PROP_FLOAT: {
7892  double arg = va_arg(args, double);
7894  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
7895  break;
7896  }
7897  case PROP_STRING: {
7898  const char *arg = va_arg(args, char *);
7900  &funcptr, parm, type, ftype, len, iter.data, &arg, NULL, tid, fid, pid);
7901  break;
7902  }
7903  case PROP_POINTER: {
7904  StructRNA *srna = va_arg(args, StructRNA *);
7905  void *arg = va_arg(args, void *);
7907  &funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
7908  break;
7909  }
7910  case PROP_COLLECTION: {
7911  StructRNA *srna = va_arg(args, StructRNA *);
7912  ListBase *arg = va_arg(args, ListBase *);
7914  &funcptr, parm, type, ftype, len, iter.data, &arg, srna, tid, fid, pid);
7915  break;
7916  }
7917  default: {
7918  /* handle errors */
7920  &funcptr, parm, type, ftype, len, iter.data, NULL, NULL, tid, fid, pid);
7921  break;
7922  }
7923  }
7924 
7925  if (err != 0) {
7926  break;
7927  }
7928  }
7929 
7930  if (err == 0) {
7931  err = RNA_function_call(C, reports, ptr, func, &parms);
7932  }
7933 
7934  /* XXX throw error when more parameters than those needed are passed or leave silent? */
7935  if (err == 0 && pret && ofs < flen && format[ofs++] == 'R') {
7936  parm = pret;
7937 
7938  type = RNA_property_type(parm);
7939  ftype = format[ofs++];
7940  len = RNA_property_array_length(&funcptr, parm);
7941  alen = rna_function_format_array_length(format, ofs, flen);
7942 
7943  if (len != alen) {
7944  err = -1;
7945  fprintf(stderr,
7946  "%s.%s: for return parameter %s, "
7947  "was expecting an array of %i elements, passed %i elements instead\n",
7948  tid,
7949  fid,
7950  pid,
7951  len,
7952  alen);
7953  }
7954  else {
7955  switch (type) {
7956  case PROP_BOOLEAN:
7957  case PROP_INT:
7958  case PROP_ENUM: {
7959  int *arg = va_arg(args, int *);
7961  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
7962  break;
7963  }
7964  case PROP_FLOAT: {
7965  float *arg = va_arg(args, float *);
7967  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
7968  break;
7969  }
7970  case PROP_STRING: {
7971  char **arg = va_arg(args, char **);
7973  &funcptr, parm, type, ftype, len, arg, retdata, NULL, tid, fid, pid);
7974  break;
7975  }
7976  case PROP_POINTER: {
7977  StructRNA *srna = va_arg(args, StructRNA *);
7978  void **arg = va_arg(args, void **);
7980  &funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
7981  break;
7982  }
7983  case PROP_COLLECTION: {
7984  StructRNA *srna = va_arg(args, StructRNA *);
7985  ListBase **arg = va_arg(args, ListBase **);
7987  &funcptr, parm, type, ftype, len, arg, retdata, srna, tid, fid, pid);
7988  break;
7989  }
7990  default: {
7991  /* handle errors */
7993  &funcptr, parm, type, ftype, len, NULL, NULL, NULL, tid, fid, pid);
7994  break;
7995  }
7996  }
7997  }
7998  }
7999 
8000  RNA_parameter_list_end(&iter);
8001  RNA_parameter_list_free(&parms);
8002 
8003  return err;
8004 }
8005 
8007  ReportList *reports,
8008  PointerRNA *ptr,
8009  const char *identifier,
8010  const char *format,
8011  va_list args)
8012 {
8013  FunctionRNA *func;
8014 
8015  func = RNA_struct_find_function(ptr->type, identifier);
8016 
8017  if (func) {
8018  return RNA_function_call_direct_va(C, reports, ptr, func, format, args);
8019  }
8020 
8021  return 0;
8022 }
8023 
8025  const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
8026 {
8027  return rna_translate_ui_text(text, text_ctxt, type, prop, translate);
8028 }
8029 
8031 {
8032  int len;
8033 
8034  /* get the length of the array to work with */
8036 
8037  /* get and set the default values as appropriate for the various types */
8038  switch (RNA_property_type(prop)) {
8039  case PROP_BOOLEAN:
8040  if (len) {
8041  if (index == -1) {
8042  bool *tmparray = MEM_callocN(sizeof(bool) * len, "reset_defaults - boolean");
8043 
8045  RNA_property_boolean_set_array(ptr, prop, tmparray);
8046 
8047  MEM_freeN(tmparray);
8048  }
8049  else {
8050  int value = RNA_property_boolean_get_default_index(ptr, prop, index);
8051  RNA_property_boolean_set_index(ptr, prop, index, value);
8052  }
8053  }
8054  else {
8055  int value = RNA_property_boolean_get_default(ptr, prop);
8056  RNA_property_boolean_set(ptr, prop, value);
8057  }
8058  return true;
8059  case PROP_INT:
8060  if (len) {
8061  if (index == -1) {
8062  int *tmparray = MEM_callocN(sizeof(int) * len, "reset_defaults - int");
8063 
8064  RNA_property_int_get_default_array(ptr, prop, tmparray);
8065  RNA_property_int_set_array(ptr, prop, tmparray);
8066 
8067  MEM_freeN(tmparray);
8068  }
8069  else {
8070  int value = RNA_property_int_get_default_index(ptr, prop, index);
8071  RNA_property_int_set_index(ptr, prop, index, value);
8072  }
8073  }
8074  else {
8075  int value = RNA_property_int_get_default(ptr, prop);
8076  RNA_property_int_set(ptr, prop, value);
8077  }
8078  return true;
8079  case PROP_FLOAT:
8080  if (len) {
8081  if (index == -1) {
8082  float *tmparray = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
8083 
8084  RNA_property_float_get_default_array(ptr, prop, tmparray);
8085  RNA_property_float_set_array(ptr, prop, tmparray);
8086 
8087  MEM_freeN(tmparray);
8088  }
8089  else {
8090  float value = RNA_property_float_get_default_index(ptr, prop, index);
8091  RNA_property_float_set_index(ptr, prop, index, value);
8092  }
8093  }
8094  else {
8095  float value = RNA_property_float_get_default(ptr, prop);
8096  RNA_property_float_set(ptr, prop, value);
8097  }
8098  return true;
8099  case PROP_ENUM: {
8100  int value = RNA_property_enum_get_default(ptr, prop);
8101  RNA_property_enum_set(ptr, prop, value);
8102  return true;
8103  }
8104 
8105  case PROP_STRING: {
8106  char *value = RNA_property_string_get_default_alloc(ptr, prop, NULL, 0);
8107  RNA_property_string_set(ptr, prop, value);
8108  MEM_freeN(value);
8109  return true;
8110  }
8111 
8112  case PROP_POINTER: {
8114  RNA_property_pointer_set(ptr, prop, value, NULL);
8115  return true;
8116  }
8117 
8118  default:
8119  /* FIXME: are there still any cases that haven't been handled?
8120  * comment out "default" block to check :) */
8121  return false;
8122  }
8123 }
8124 
8126 {
8127  if (!RNA_property_is_idprop(prop) || RNA_property_array_check(prop)) {
8128  return false;
8129  }
8130 
8131  /* get and set the default values as appropriate for the various types */
8132  switch (RNA_property_type(prop)) {
8133  case PROP_INT: {
8134  int value = RNA_property_int_get(ptr, prop);
8135  return RNA_property_int_set_default(ptr, prop, value);
8136  }
8137 
8138  case PROP_FLOAT: {
8139  float value = RNA_property_float_get(ptr, prop);
8140  return RNA_property_float_set_default(ptr, prop, value);
8141  }
8142 
8143  default:
8144  return false;
8145  }
8146 }
8147 
8148 /* use RNA_warning macro which includes __func__ suffix */
8149 void _RNA_warning(const char *format, ...)
8150 {
8151  va_list args;
8152 
8153  va_start(args, format);
8154  vprintf(format, args);
8155  va_end(args);
8156 
8157  /* gcc macro adds '\n', but cant use for other compilers */
8158 #ifndef __GNUC__
8159  fputc('\n', stdout);
8160 #endif
8161 
8162 #ifdef WITH_PYTHON
8163  {
8164  extern void PyC_LineSpit(void);
8165  PyC_LineSpit();
8166  }
8167 #endif
8168 }
8169 
8171  struct PropertyRNA *prop,
8172  const int prop_index,
8173  PathResolvedRNA *r_anim_rna)
8174 {
8175  int array_len = RNA_property_array_length(ptr, prop);
8176 
8177  if ((array_len == 0) || (prop_index < array_len)) {
8178  r_anim_rna->ptr = *ptr;
8179  r_anim_rna->prop = prop;
8180  r_anim_rna->prop_index = array_len ? prop_index : -1;
8181 
8182  return true;
8183  }
8184  return false;
8185 }
8186 
8187 static char rna_struct_state_owner[64];
8189 {
8190  if (name) {
8192  }
8193  else {
8194  rna_struct_state_owner[0] = '\0';
8195  }
8196 }
8197 
8199 {
8200  if (rna_struct_state_owner[0]) {
8201  return rna_struct_state_owner;
8202  }
8203  return NULL;
8204 }
typedef float(TangentPoint)[2]
bool id_can_have_animdata(const struct ID *id)
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:746
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
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:378
#define IDP_Float(prop)
Definition: BKE_idprop.h:179
#define IDP_IDPArray(prop)
Definition: BKE_idprop.h:182
#define IDP_Int(prop)
Definition: BKE_idprop.h:154
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item)
Definition: idprop.c:153
void IDP_FreePropertyContent(struct IDProperty *prop)
Definition: idprop.c:1029
struct IDProperty * IDP_GetPropertyTypeFromGroup(const struct IDProperty *prop, const char *name, const char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define IDP_Id(prop)
Definition: BKE_idprop.h:183
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:572
void IDP_AssignID(struct IDProperty *prop, struct ID *id, const int flag)
Definition: idprop.c:437
struct IDProperty * IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:146
struct IDProperty * IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:82
bool void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:679
void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist)
Definition: idprop.c:557
struct IDProperty * IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition: idprop.c:325
#define IDP_String(prop)
Definition: BKE_idprop.h:181
void IDP_ResizeIDPArray(struct IDProperty *prop, int len)
Definition: idprop.c:161
#define IDP_Double(prop)
Definition: BKE_idprop.h:180
void IDP_ResizeArray(struct IDProperty *prop, int newlen)
Definition: idprop.c:232
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:643
struct IDProperty * IDP_GetPropertyFromGroup(const struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
struct IDProperty * IDP_New(const char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:907
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL()
Definition: idprop.c:369
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
Definition: idprop.c:690
#define IDP_Array(prop)
Definition: BKE_idprop.h:155
const char * BKE_idtype_idcode_to_name_plural(const short idcode)
Definition: idtype.c:182
const struct IDTypeInfo * BKE_idtype_get_info_from_id(const struct ID *id)
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_array_alloca(arr, realsize)
Definition: BLI_alloca.h:36
#define BLI_assert(a)
Definition: BLI_assert.h:58
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
void * BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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)
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL()
Definition: string.c:333
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy) ATTR_NONNULL()
Definition: string.c:375
const char * BLI_str_escape_find_quote(const char *str) ATTR_NONNULL()
Definition: string.c:410
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
#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)
#define N_(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.
#define ID_TYPE_IS_COW(_id_type)
Definition: DNA_ID.h:454
@ ID_RECALC_PARAMETERS
Definition: DNA_ID.h:668
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
@ IDP_DOUBLE
Definition: DNA_ID.h:103
@ IDP_FLOAT
Definition: DNA_ID.h:99
@ IDP_STRING
Definition: DNA_ID.h:97
@ IDP_IDPARRAY
Definition: DNA_ID.h:104
@ IDP_INT
Definition: DNA_ID.h:98
@ IDP_NUMTYPES
Definition: DNA_ID.h:105
@ IDP_GROUP
Definition: DNA_ID.h:101
@ IDP_ARRAY
Definition: DNA_ID.h:100
@ IDP_ID
Definition: DNA_ID.h:102
@ LIB_EMBEDDED_DATA
Definition: DNA_ID.h:482
#define MAX_IDPROP_NAME
Definition: DNA_ID.h:92
@ IDP_STRING_SUB_BYTE
Definition: DNA_ID.h:125
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:445
@ IDP_FLAG_GHOST
Definition: DNA_ID.h:141
@ IDP_FLAG_OVERRIDELIBRARY_LOCAL
Definition: DNA_ID.h:137
@ ID_NT
Definition: DNA_ID_enums.h:80
@ ID_GR
Definition: DNA_ID_enums.h:77
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 RNA_PROP_END
Definition: RNA_access.h:1268
#define RNA_STRUCT_BEGIN(sptr, prop)
Definition: RNA_access.h:1274
StructRNA RNA_Struct
#define RNA_STRUCT_END
Definition: RNA_access.h:1294
StructRNA RNA_Function
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
StructRNA RNA_BlenderRNA
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
Definition: RNA_access.h:1261
StructRNA RNA_ID
StructRNA RNA_UnknownType
StructRNA RNA_AnyType
StructRNA RNA_BlendData
#define RNA_MAX_ARRAY_LENGTH
Definition: RNA_define.h:39
#define RNA_MAX_ARRAY_DIMENSION
Definition: RNA_define.h:42
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ PARM_OUTPUT
Definition: RNA_types.h:338
struct StructRNA *(* StructRegisterFunc)(struct Main *bmain, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
Definition: RNA_types.h:653
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:577
@ STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID
Definition: RNA_types.h:644
@ STRUCT_PUBLIC_NAMESPACE
Definition: RNA_types.h:636
@ STRUCT_ID
Definition: RNA_types.h:620
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition: RNA_types.h:632
@ STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES
Definition: RNA_types.h:634
@ STRUCT_NO_IDPROPERTIES
Definition: RNA_types.h:630
@ STRUCT_UNDO
Definition: RNA_types.h:623
PropertyType
Definition: RNA_types.h:72
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
PropertyUnit
Definition: RNA_types.h:83
struct EnumPropertyItem EnumPropertyItem
#define RNA_SUBTYPE_UNIT(subtype)
Definition: RNA_types.h:98
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition: RNA_types.h:322
void(* StructUnregisterFunc)(struct Main *bmain, struct StructRNA *type)
Definition: RNA_types.h:661
RawPropertyType
Definition: RNA_types.h:416
@ PROP_RAW_INT
Definition: RNA_types.h:418
@ PROP_RAW_UNSET
Definition: RNA_types.h:417
@ PROP_RAW_BOOLEAN
Definition: RNA_types.h:421
@ PROP_RAW_CHAR
Definition: RNA_types.h:420
@ PROP_RAW_FLOAT
Definition: RNA_types.h:423
@ PROP_RAW_DOUBLE
Definition: RNA_types.h:422
@ PROP_RAW_SHORT
Definition: RNA_types.h:419
@ PROP_DYNAMIC
Definition: RNA_types.h:275
@ PROP_CONTEXT_UPDATE
Definition: RNA_types.h:254
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_NEVER_UNLINK
Definition: RNA_types.h:232
@ PROP_EDITABLE
Definition: RNA_types.h:175
@ PROP_ENUM_FLAG
Definition: RNA_types.h:251
@ PROP_LIB_EXCEPTION
Definition: RNA_types.h:181
@ PROP_CONTEXT_PROPERTY_UPDATE
Definition: RNA_types.h:255
@ PROP_ENUM_NO_CONTEXT
Definition: RNA_types.h:277
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_NO_DEG_UPDATE
Definition: RNA_types.h:286
@ PROP_ENUM_NO_TRANSLATE
Definition: RNA_types.h:279
@ PROP_REGISTER
Definition: RNA_types.h:258
@ PROP_ID_SELF_CHECK
Definition: RNA_types.h:218
@ PROP_IDPROPERTY
Definition: RNA_types.h:273
int(* IteratorSkipFunc)(struct CollectionPropertyIterator *iter, void *data)
Definition: RNA_types.h:352
PropertySubType
Definition: RNA_types.h:112
@ PROP_DIRECTION
Definition: RNA_types.h:141
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_ACCELERATION
Definition: RNA_types.h:143
@ PROP_BYTESTRING
Definition: RNA_types.h:120
@ PROP_COLOR
Definition: RNA_types.h:139
@ PROP_AXISANGLE
Definition: RNA_types.h:147
@ PROP_EULER
Definition: RNA_types.h:145
@ PROP_COORDS
Definition: RNA_types.h:153
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_COLOR_GAMMA
Definition: RNA_types.h:151
@ PROP_TRANSLATION
Definition: RNA_types.h:140
@ PROP_XYZ_LENGTH
Definition: RNA_types.h:149
@ PROP_QUATERNION
Definition: RNA_types.h:146
@ PROP_VELOCITY
Definition: RNA_types.h:142
#define C
Definition: RandGen.cpp:39
#define ND_SHADING
Definition: WM_types.h:377
#define NC_WINDOW
Definition: WM_types.h:277
#define NC_MATERIAL
Definition: WM_types.h:281
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
array()
Definition: util_array.h:39
Scene scene
static FT_Error err
Definition: freetypefont.c:52
uint pos
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define GS(x)
Definition: iris.c:241
format
Definition: logImageCore.h:47
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static ulong * next
int main(int argc, char **argv)
Definition: msgfmt.c:457
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
void PyC_LineSpit(void)
return ret
static const IDProperty * rna_idproperty_ui(const PropertyRNA *prop)
Definition: rna_access.c:270
StructUnregisterFunc RNA_struct_unregister(StructRNA *type)
Definition: rna_access.c:1005
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2941
void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
Definition: rna_access.c:6296
static bool rna_path_parse_array_index(const char **path, PointerRNA *ptr, PropertyRNA *prop, int *r_index)
Definition: rna_access.c:5118
bool RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
Definition: rna_access.c:1801
StructRegisterFunc RNA_struct_register(StructRNA *type)
Definition: rna_access.c:1000
int RNA_function_call_direct_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, const char *format,...)
Definition: rna_access.c:7590
bool RNA_property_enum_item_from_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
Definition: rna_access.c:1980
const char * RNA_struct_identifier(const StructRNA *type)
Definition: rna_access.c:723
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3249
static IDProperty * rna_idproperty_ui_ensure(PointerRNA *ptr, PropertyRNA *prop, bool create)
Definition: rna_access.c:282
char * RNA_path_resolve_from_type_to_property(PointerRNA *ptr, PropertyRNA *prop, const StructRNA *type)
Definition: rna_access.c:6046
int RNA_enum_bitflag_identifiers(const EnumPropertyItem *item, const int value, const char **r_identifier)
Definition: rna_access.c:1840
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
Definition: rna_access.c:6343
const char * RNA_function_identifier(FunctionRNA *func)
Definition: rna_access.c:7149
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
Definition: rna_access.c:2530
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:2627
FunctionRNA * RNA_struct_find_function(StructRNA *srna, const char *identifier)
Definition: rna_access.c:958
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
Definition: rna_access.c:1375
const char * RNA_property_description(PropertyRNA *prop)
Definition: rna_access.c:1150
bool RNA_property_update_check(PropertyRNA *prop)
Definition: rna_access.c:2312
bool RNA_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:1223
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:844
int RNA_property_collection_lookup_string_index(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
Definition: rna_access.c:4245
bool RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition: rna_access.c:5416
int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format, va_list args)
Definition: rna_access.c:7812
bool RNA_property_is_unlink(PropertyRNA *prop)
Definition: rna_access.c:6712
void rna_property_rna_or_id_get(PropertyRNA *prop, PointerRNA *ptr, PropertyRNAOrID *r_prop_rna_or_id)
Definition: rna_access.c:553
const struct ListBase * RNA_struct_type_properties(StructRNA *srna)
Definition: rna_access.c:948
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:2663
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3033
bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:8125
PropertyRNA * rna_ensure_property(PropertyRNA *prop)
Definition: rna_access.c:650
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:8006
void RNA_struct_state_owner_set(const char *name)
Definition: rna_access.c:8188
void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
Definition: rna_access.c:1034
void rna_iterator_array_end(CollectionPropertyIterator *iter)
Definition: rna_access.c:4938
bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2168
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Definition: rna_access.c:6331
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2207
bool RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2583
IDProperty * rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
Definition: rna_access.c:626
static void rna_property_int_get_default_array_values(PointerRNA *ptr, IntPropertyRNA *iprop, int *r_values)
Definition: rna_access.c:2679
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:6550
static void rna_property_float_get_default_array_values(PointerRNA *ptr, FloatPropertyRNA *fprop, float *r_values)
Definition: rna_access.c:3022
static void rna_idproperty_free(PointerRNA *ptr, const char *name)
Definition: rna_access.c:407
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6562
void RNA_init(void)
Definition: rna_access.c:75
int RNA_collection_length(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6634
int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
Definition: rna_access.c:1891
int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
Definition: rna_access.c:1542
int RNA_parameter_dynamic_length_get_data(ParameterList *UNUSED(parms), PropertyRNA *parm, void *data)
Definition: rna_access.c:7526
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
Definition: rna_access.c:1525
void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **value)
Definition: rna_access.c:7407
void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
Definition: rna_access.c:6574
char * RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
Definition: rna_access.c:6996
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
Definition: rna_access.c:6284
bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
Definition: rna_access.c:1063
bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
Definition: rna_access.c:6443
void ** RNA_struct_instance(PointerRNA *ptr)
Definition: rna_access.c:1016
bool RNA_struct_is_ID(const StructRNA *type)
Definition: rna_access.c:797
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2759
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1145
const char * RNA_property_ui_description_raw(const PropertyRNA *prop)
Definition: rna_access.c:2058
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
Definition: rna_access.c:1466
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
Definition: rna_access.c:3190
static void rna_array_as_string_recursive(int type, void **buf_p, int totdim, const int *dim_size, DynStr *dynstr)
Definition: rna_access.c:6961
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
Definition: rna_access.c:6474
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:6866
static void rna_property_boolean_get_default_array_values(PointerRNA *ptr, BoolPropertyRNA *bprop, bool *r_values)
Definition: rna_access.c:2409
bool RNA_path_resolve_elements(PointerRNA *ptr, const char *path, ListBase *r_elements)
Definition: rna_access.c:5524
PropertyUnit RNA_property_unit(PropertyRNA *prop)
Definition: rna_access.c:1187
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
Definition: rna_access.c:1044
int RNA_function_defined(FunctionRNA *func)
Definition: rna_access.c:7169
int RNA_property_ui_icon(const PropertyRNA *prop)
Definition: rna_access.c:2068
ParameterList * RNA_parameter_list_create(ParameterList *parms, PointerRNA *UNUSED(ptr), FunctionRNA *func)
Definition: rna_access.c:7207
void RNA_collection_clear(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6622
bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:8030
void RNA_parameter_dynamic_length_set(ParameterList *parms, PropertyRNA *parm, int length)
Definition: rna_access.c:7507
int RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
Definition: rna_access.c:4309
int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[])
Definition: rna_access.c:1229
static const char * rna_ensure_property_name(const PropertyRNA *prop)
Definition: rna_access.c:702
const char * RNA_struct_ui_description(const StructRNA *type)
Definition: rna_access.c:746
void RNA_blender_rna_pointer_create(PointerRNA *r_ptr)
Definition: rna_access.c:189
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:1049
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:3108
int RNA_parameter_list_arg_count(ParameterList *parms)
Definition: rna_access.c:7335
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
Definition: rna_access.c:3673
char * RNA_path_back(const char *path)
Definition: rna_access.c:5574
void _RNA_warning(const char *format,...)
Definition: rna_access.c:8149
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
void RNA_parameter_dynamic_length_set_data(ParameterList *UNUSED(parms), PropertyRNA *parm, void *data, int length)
Definition: rna_access.c:7536
void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num)
Definition: rna_access.c:3866
#define RAW_GET(dtype, var, raw, a)
Definition: rna_access.c:4377
float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:3286
void RNA_pointer_add(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6586
int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
Definition: rna_access.c:1876
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:4799
bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
Definition: rna_access.c:6645
static void * rna_array_as_string_alloc(int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
Definition: rna_access.c:6905
int RNA_parameter_list_ret_count(ParameterList *parms)
Definition: rna_access.c:7340
bool RNA_property_float_set_default(PointerRNA *ptr, PropertyRNA *prop, float value)
Definition: rna_access.c:3238
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
Definition: rna_access.c:7423
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
Definition: rna_access.c:6673
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
Definition: rna_access.c:2024
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6655
const char * RNA_struct_ui_name(const StructRNA *type)
Definition: rna_access.c:728
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
Definition: rna_access.c:3816
bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
Definition: rna_access.c:6494
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
Definition: rna_access.c:1426
void rna_iterator_listbase_end(CollectionPropertyIterator *UNUSED(iter))
Definition: rna_access.c:4862
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2420
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1155
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
const char * RNA_function_ui_description_raw(FunctionRNA *func)
Definition: rna_access.c:7159
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3758
static PropertyRNA * arraytypemap[IDP_NUMTYPES]
Definition: rna_access.c:535
PropertyRNA * rna_ensure_property_realdata(PropertyRNA **prop, PointerRNA *ptr)
Definition: rna_access.c:638
char * RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:6204
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3562
void * RNA_struct_blender_type_get(StructRNA *srna)
Definition: rna_access.c:1039
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3641
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
Definition: rna_access.c:4212
char RNA_property_array_item_char(PropertyRNA *prop, int index)
Definition: rna_access.c:1250
int RNA_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
Definition: rna_access.c:3608
void RNA_parameter_list_free(ParameterList *parms)
Definition: rna_access.c:7303
bool RNA_property_enum_name_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
Definition: rna_access.c:1962
bool RNA_struct_contains_property(PointerRNA *ptr, PropertyRNA *prop_test)
Definition: rna_access.c:908
bool RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2557
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
void rna_idproperty_touch(IDProperty *idprop)
Definition: rna_access.c:242
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2317
static char * rna_pointer_as_string__bldata(Main *bmain, PointerRNA *ptr)
Definition: rna_access.c:6759
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:7637
unsigned int RNA_struct_count_properties(StructRNA *srna)
Definition: rna_access.c:930
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
Definition: rna_access.c:4823
int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2917
char * RNA_pointer_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop)
Definition: rna_access.c:6770
char * RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6027
static int rna_token_strip_quotes(char *token)
Definition: rna_access.c:5040
PointerRNA rna_array_lookup_int(PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
Definition: rna_access.c:4948
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:3339
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
Definition: rna_access.c:3071
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2568
bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
Definition: rna_access.c:823
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
Definition: rna_access.c:2830
static const char * rna_ensure_property_description(const PropertyRNA *prop)
Definition: rna_access.c:676
static const char * bool_as_py_string(const int var)
Definition: rna_access.c:6900
bool RNA_path_resolve_property_and_item_pointer_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index, PointerRNA *r_item_ptr)
Definition: rna_access.c:5502
unsigned int RNA_enum_items_count(const EnumPropertyItem *item)
Definition: rna_access.c:1913
static int rna_property_array_length_all_dimensions(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:4451
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:1722
bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
Definition: rna_access.c:6484
void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, bool free_ptr, IteratorSkipFunc skip)
Definition: rna_access.c:4875
char * RNA_path_from_struct_to_idproperty(PointerRNA *ptr, IDProperty *needle)
Definition: rna_access.c:5781
void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr)
Definition: rna_access.c:217
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2607
int RNA_property_enum_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3592
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
Definition: rna_access.c:372
ID * RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path)
Definition: rna_access.c:5814
void RNA_property_collection_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:3850
static void rna_array_as_string(int type, int len, PointerRNA *ptr, PropertyRNA *prop, DynStr *dynstr)
Definition: rna_access.c:6981
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index)
Definition: rna_access.c:4866
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
Definition: rna_access.c:6610
void RNA_parameter_list_next(ParameterIterator *iter)
Definition: rna_access.c:7361
static char rna_struct_state_owner[64]
Definition: rna_access.c:8187
char * RNA_path_append(const char *path, PointerRNA *UNUSED(ptr), PropertyRNA *prop, int intkey, const char *strkey)
Definition: rna_access.c:5529
void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
Definition: rna_access.c:6425
const char * RNA_property_translation_context(const PropertyRNA *prop)
Definition: rna_access.c:2063
bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2132
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
Definition: rna_access.c:4299
const char * RNA_struct_ui_name_raw(const StructRNA *type)
Definition: rna_access.c:733
static bool rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop)
Definition: rna_access.c:467
static const char * rna_ensure_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:668
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
Definition: rna_access.c:6514
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:3006
bool RNA_property_int_set_default(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:2875
int RNA_int_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6308
char * RNA_path_from_real_ID_to_struct(Main *bmain, PointerRNA *ptr, struct ID **r_real)
Definition: rna_access.c:5918
PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop))
Definition: rna_access.c:3749
char * RNA_path_full_ID_py(Main *bmain, ID *id)
Definition: rna_access.c:6088
static char * rna_path_token(const char **path, char *fixedbuf, int fixedlen, int bracket)
Definition: rna_access.c:4960
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
Definition: rna_access.c:6504
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
Definition: rna_access.c:953
char * RNA_path_full_property_py_ex(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback)
Definition: rna_access.c:6147
static bool rna_idproperty_ui_set_default(PointerRNA *ptr, PropertyRNA *prop, const char type, IDPropertyTemplate *value)
Definition: rna_access.c:320
void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **value)
Definition: rna_access.c:7378
StructRNA * RNA_struct_find(const char *identifier)
Definition: rna_access.c:718
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
Definition: rna_access.c:3310
void RNA_parameter_list_end(ParameterIterator *UNUSED(iter))
Definition: rna_access.c:7373
int RNA_function_flag(FunctionRNA *func)
Definition: rna_access.c:7164
PropertyRNA * RNA_function_get_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, int index)
Definition: rna_access.c:7174
static char * rna_idp_path_create(IDP_Chain *child_link)
Definition: rna_access.c:5641
bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
Definition: rna_access.c:2092
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1567
char * RNA_path_from_real_ID_to_property_index(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real_id)
Definition: rna_access.c:6032
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2322
char * RNA_path_from_ID_to_property_index(PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index)
Definition: rna_access.c:5971
void * rna_iterator_array_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4923
void RNA_property_string_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop, char *value)
Definition: rna_access.c:3466
bool RNA_path_resolve_property_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
Definition: rna_access.c:5454
bool RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value)
Definition: rna_access.c:1593
int RNA_property_flag(PropertyRNA *prop)
Definition: rna_access.c:1192
RawPropertyType RNA_property_raw_type(PropertyRNA *prop)
Definition: rna_access.c:4778
int RNA_struct_ui_icon(const StructRNA *type)
Definition: rna_access.c:738
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Definition: rna_access.c:2358
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
bool RNA_property_builtin(PropertyRNA *prop)
Definition: rna_access.c:1208
int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3518
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
Definition: rna_access.c:2722
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:4839
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
Definition: rna_access.c:1925
char * RNA_path_full_property_py(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:6195
static void rna_array_as_string_elem(int type, void **buf_p, int len, DynStr *dynstr)
Definition: rna_access.c:6930
static bool rna_path_parse_collection_key(const char **path, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_nextptr)
Definition: rna_access.c:5053
bool RNA_struct_idprops_register_check(const StructRNA *type)
Definition: rna_access.c:807
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
Definition: rna_access.c:7469
void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
Definition: rna_access.c:3430
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
Definition: rna_access.c:6366
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:2856
int RNA_string_length(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6539
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
static PropertyRNA * typemap[IDP_NUMTYPES]
Definition: rna_access.c:522
const EnumPropertyItem * RNA_struct_property_tag_defines(const StructRNA *type)
Definition: rna_access.c:766
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
Definition: rna_access.c:761
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array)
Definition: rna_access.c:4334
bool RNA_property_enum_item_from_value_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
Definition: rna_access.c:2008
bool RNA_struct_undo_check(const StructRNA *type)
Definition: rna_access.c:802
bool RNA_path_resolve_property_and_item_pointer(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, PointerRNA *r_item_ptr)
Definition: rna_access.c:5476
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
Definition: rna_access.c:6598
char * RNA_path_property_py(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int index)
Definition: rna_access.c:6245
void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6697
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
Definition: rna_access.c:3966
bool RNA_pointer_is_null(const PointerRNA *ptr)
Definition: rna_access.c:174
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **r_description)
Definition: rna_access.c:1864
static char * rna_path_from_ID_to_idpgroup(PointerRNA *ptr)
Definition: rna_access.c:5791
static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:419
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1854
int RNA_function_call_lookup(bContext *C, ReportList *reports, PointerRNA *ptr, const char *identifier, ParameterList *parms)
Definition: rna_access.c:7558
bool RNA_property_is_idprop(const PropertyRNA *prop)
Definition: rna_access.c:6706
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2227
int RNA_property_string_maxlength(PropertyRNA *prop)
Definition: rna_access.c:1561
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:1738
bool RNA_struct_idprops_datablock_allowed(const StructRNA *type)
Definition: rna_access.c:812
const ListBase * RNA_function_defined_parameters(FunctionRNA *func)
Definition: rna_access.c:7195
void RNA_exit(void)
Definition: rna_access.c:99
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
Definition: rna_access.c:3132
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
Definition: rna_access.c:2783
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2886
static bool property_collection_liboverride_editable(PointerRNA *ptr, PropertyRNA *prop, bool *r_is_liboverride)
Definition: rna_access.c:3931
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
void rna_iterator_array_next(CollectionPropertyIterator *iter)
Definition: rna_access.c:4907
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
Definition: rna_access.c:2964
static bool rna_path_parse(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index, PointerRNA *r_item_ptr, ListBase *r_elements, const bool eval_pointer)
Definition: rna_access.c:5233
static char * rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real_id)
Definition: rna_access.c:5845
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2690
bool RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int key, int pos)
Definition: rna_access.c:4114
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
Definition: rna_access.c:1902
char * RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr)
Definition: rna_access.c:6724
PropertySubType RNA_property_subtype(PropertyRNA *prop)
Definition: rna_access.c:1160
const char * RNA_struct_translation_context(const StructRNA *type)
Definition: rna_access.c:756
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:6685
void * RNA_struct_py_type_get(StructRNA *srna)
Definition: rna_access.c:1029
bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2143
IDProperty * rna_idproperty_find(PointerRNA *ptr, const char *name)
Definition: rna_access.c:388
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
Definition: rna_access.c:1335
int RNA_function_call_direct(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, const char *format,...)
Definition: rna_access.c:7575
bool RNA_path_resolve_property(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5434
bool RNA_struct_idprops_unset(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:829
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_function_call(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
Definition: rna_access.c:7546
struct IDP_Chain IDP_Chain
int RNA_parameter_dynamic_length_get(ParameterList *parms, PropertyRNA *parm)
Definition: rna_access.c:7485
static void rna_path_array_multi_string_from_flat_index(PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, char *index_str, int index_str_len)
Definition: rna_access.c:5947
static void rna_ensure_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int length[])
Definition: rna_access.c:443
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:1657
int RNA_parameter_list_size(ParameterList *parms)
Definition: rna_access.c:7330
static PropertyRNA * RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
Definition: rna_access.c:892
static void rna_pointer_inherit_id(StructRNA *type, PointerRNA *parent, PointerRNA *ptr)
Definition: rna_access.c:179
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:4157
PropertyRNA * RNA_function_find_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *func, const char *identifier)
Definition: rna_access.c:7179
static char * rna_idp_path(PointerRNA *ptr, IDProperty *haystack, IDProperty *needle, IDP_Chain *parent_link)
Definition: rna_access.c:5684
int RNA_property_tags(PropertyRNA *prop)
Definition: rna_access.c:1203
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
Definition: rna_access.c:1830
static IDProperty * rna_idproperty_ui_container(PropertyRNA *prop)
Definition: rna_access.c:248
char * RNA_path_full_struct_py(Main *bmain, struct PointerRNA *ptr)
Definition: rna_access.c:6115
static bool rna_ensure_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:433
bool RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
Definition: rna_access.c:4326
void RNA_property_collection_end(CollectionPropertyIterator *iter)
Definition: rna_access.c:3891
bool RNA_struct_idprops_check(StructRNA *srna)
Definition: rna_access.c:383
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:6390
int RNA_property_array_item_index(PropertyRNA *prop, char name)
Definition: rna_access.c:1281
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:2393
bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig)
Definition: rna_access.c:2073
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
Definition: rna_access.c:2453
const ListBase * RNA_struct_type_functions(StructRNA *srna)
Definition: rna_access.c:995
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
Definition: rna_access.c:1093
bool RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
Definition: rna_access.c:4049
char * RNA_property_string_get_default_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen)
Definition: rna_access.c:3493
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
bool RNA_path_resolved_create(PointerRNA *ptr, struct PropertyRNA *prop, const int prop_index, PathResolvedRNA *r_anim_rna)
Definition: rna_access.c:8170
void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr)
Definition: rna_access.c:115
const char * RNA_struct_state_owner_get(void)
Definition: rna_access.c:8198
char * RNA_path_from_ID_to_struct(PointerRNA *ptr)
Definition: rna_access.c:5876
#define RAW_SET(dtype, raw, a, var)
Definition: rna_access.c:4404
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6665
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:6881
void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter)
Definition: rna_access.c:7345
void * rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4930
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3786
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
Definition: rna_access.c:771
bool RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5400
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3375
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:1614
int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *t_ptr)
Definition: rna_access.c:4190
const char * RNA_translate_ui_text(const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
Definition: rna_access.c:8024
float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
Definition: rna_access.c:3216
int RNA_parameter_flag(PropertyRNA *prop)
Definition: rna_access.c:7202
int RNA_raw_type_sizeof(RawPropertyType type)
Definition: rna_access.c:4431
const char * RNA_function_ui_description(FunctionRNA *func)
Definition: rna_access.c:7154
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:4810
bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2184
void * rna_iterator_listbase_get(CollectionPropertyIterator *iter)
Definition: rna_access.c:4855
const char * RNA_property_ui_name_raw(const PropertyRNA *prop)
Definition: rna_access.c:2048
const char * RNA_struct_ui_description_raw(const StructRNA *type)
Definition: rna_access.c:751
const char * RNA_property_ui_description(const PropertyRNA *prop)
Definition: rna_access.c:2053
const StructRNA * RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
Definition: rna_access.c:786
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:6786
int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
Definition: rna_access.c:1241
static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], const int totdims, const int index_dim, int index, int r_index_multi[RNA_MAX_ARRAY_LENGTH])
Definition: rna_access.c:5926
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:4468
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3903
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
Definition: rna_access.c:2482
void * RNA_property_py_data_get(PropertyRNA *prop)
Definition: rna_access.c:1213
const char * RNA_property_ui_name(const PropertyRNA *prop)
Definition: rna_access.c:2043
StructRNA * RNA_struct_base(StructRNA *type)
Definition: rna_access.c:776
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
Definition: rna_access.c:3401
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name)
Definition: rna_access.c:1943
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen)
Definition: rna_access.c:6527
static int rna_function_format_array_length(const char *format, int ofs, int flen)
Definition: rna_access.c:7617
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
Definition: rna_access.c:3807
bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_free(BlenderRNA *brna)
Definition: rna_define.c:846
int rna_parameter_size(PropertyRNA *parm)
Definition: rna_define.c:4342
FloatPropertyRNA rna_PropertyGroupItem_double_array
IntPropertyRNA rna_PropertyGroupItem_int_array
CollectionPropertyRNA rna_PropertyGroupItem_collection
CollectionPropertyRNA rna_PropertyGroupItem_idp_array
const char * rna_translate_ui_text(const char *text, const char *text_ctxt, struct StructRNA *type, struct PropertyRNA *prop, bool translate)
FloatPropertyRNA rna_PropertyGroupItem_double
PointerPropertyRNA rna_PropertyGroupItem_id
struct StructRNA * rna_ID_refine(struct PointerRNA *ptr)
BlenderRNA BLENDER_RNA
StringPropertyRNA rna_PropertyGroupItem_string
PointerPropertyRNA rna_PropertyGroupItem_group
IntPropertyRNA rna_PropertyGroupItem_int
StructRNA RNA_PropertyGroup
FloatPropertyRNA rna_PropertyGroupItem_float_array
FloatPropertyRNA rna_PropertyGroupItem_float
#define RNA_MAGIC
Definition: rna_internal.h:31
#define RNA_IDP_UI
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)
const EnumPropertyItem rna_enum_property_subtype_items[]
Definition: rna_rna.c:68
#define min(a, b)
Definition: sort.c:51
_W64 int intptr_t
Definition: stdint.h:121
char * ptr
Definition: RNA_types.h:361
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
union CollectionPropertyIterator::@1099 internal
ListBaseIterator listbase
Definition: RNA_types.h:394
struct PropertyRNA * prop
Definition: RNA_types.h:391
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:446
const char * name
Definition: RNA_types.h:450
const char * description
Definition: RNA_types.h:452
const EnumPropertyItem * item
PropEnumSetFuncEx set_ex
PropEnumGetFunc get
PropEnumItemFunc item_fn
PropEnumGetFuncEx get_ex
PropEnumSetFunc set
PropFloatSetFuncEx set_ex
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
struct IDP_Chain * up
Definition: rna_access.c:5634
const char * name
Definition: rna_access.c:5636
ListBase group
Definition: DNA_ID.h:64
void * pointer
Definition: DNA_ID.h:63
short flag
Definition: DNA_ID.h:72
int len
Definition: DNA_ID.h:84
struct IDProperty * next
Definition: DNA_ID.h:70
char name[64]
Definition: DNA_ID.h:74
IDPropertyData data
Definition: DNA_ID.h:80
struct IDProperty * prev
Definition: DNA_ID.h:70
char subtype
Definition: DNA_ID.h:71
char type
Definition: DNA_ID.h:71
IDTypeEmbeddedOwnerGetFunction owner_get
Definition: BKE_idtype.h:189
Definition: DNA_ID.h:273
short flag
Definition: DNA_ID.h:288
char name[66]
Definition: DNA_ID.h:283
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
PropIntSetFuncEx set_ex
struct Link * link
Definition: RNA_types.h:355
void * last
Definition: DNA_listBase.h:47
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
intptr_t array_tot
Definition: RNA_types.h:541
PropertyRNA * parm
Definition: RNA_types.h:534
struct ParameterList * parms
Definition: RNA_types.h:529
void * data
Definition: RNA_types.h:517
struct FunctionRNA * func
Definition: RNA_types.h:520
struct PropertyRNA * prop
Definition: RNA_types.h:65
struct PointerRNA ptr
Definition: RNA_types.h:64
PropPointerTypeFunc type_fn
struct StructRNA * type
PropPointerGetFunc get
PropPointerPollFunc poll
PropPointerSetFunc set
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
PointerRNA ptr
Definition: RNA_access.h:1147
PropertyRNA * prop
Definition: RNA_access.h:1148
PropertyElemRNA * prev
Definition: RNA_access.h:1146
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:428
int len
Definition: RNA_types.h:429
void * array
Definition: RNA_types.h:427
int stride
Definition: RNA_types.h:430
PropStringSetFunc set
const char * defaultvalue
PropStringLengthFuncEx length_ex
PropStringLengthFunc length
PropStringGetFuncEx get_ex
PropStringSetFuncEx set_ex
PropStringGetFunc get
const char * identifier
ContainerRNA cont
struct StructRNA * nested
PropertyRNA * nameproperty
IDPropertiesFunc idproperties
struct StructRNA * base
ListBase functions
StructRefineFunc refine
StructPathFunc path
float max
const char * str
Definition: BKE_idprop.h:41
struct IDPropertyTemplate::@28 array
struct ID * id
Definition: BKE_idprop.h:45
struct IDPropertyTemplate::@27 string
uint len
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
void WM_msg_publish_rna(struct wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)