Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_access.c
| Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | |||||
| /* ID Properties */ | /* ID Properties */ | ||||
| static void rna_idproperty_touch(IDProperty *idprop) | static void rna_idproperty_touch(IDProperty *idprop) | ||||
| { | { | ||||
| /* so the property is seen as 'set' by rna */ | /* so the property is seen as 'set' by rna */ | ||||
| idprop->flag &= ~IDP_FLAG_GHOST; | idprop->flag &= ~IDP_FLAG_GHOST; | ||||
| } | } | ||||
| /* return a UI local ID prop definition for this prop */ | static IDProperty *rna_idproperty_ui_container(PropertyRNA *prop) | ||||
| static IDProperty *rna_idproperty_ui(PropertyRNA *prop) | |||||
| { | { | ||||
| IDProperty *idprop; | IDProperty *idprop; | ||||
| for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) { | for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) { | ||||
| if (STREQ(RNA_IDP_UI, idprop->name)) | if (STREQ(RNA_IDP_UI, idprop->name)) | ||||
| break; | break; | ||||
| } | } | ||||
| if (idprop == NULL) { | if (idprop == NULL) { | ||||
| for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) { | for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) { | ||||
| if (STREQ(RNA_IDP_UI, idprop->name)) | if (STREQ(RNA_IDP_UI, idprop->name)) | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| return idprop; | |||||
| } | |||||
| /* return a UI local ID prop definition for this prop */ | |||||
| static IDProperty *rna_idproperty_ui(PropertyRNA *prop) | |||||
| { | |||||
| IDProperty *idprop = rna_idproperty_ui_container(prop); | |||||
| if (idprop) { | if (idprop) { | ||||
| return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP); | return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP); | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* return or create a UI local ID prop definition for this prop */ | |||||
| static IDProperty *rna_idproperty_ui_ensure(PointerRNA *ptr, PropertyRNA *prop, bool create) | |||||
| { | |||||
| IDProperty *idprop = rna_idproperty_ui_container(prop); | |||||
| IDPropertyTemplate dummy = { 0 }; | |||||
| if (idprop == NULL && create) { | |||||
| IDProperty *props = RNA_struct_idprops(ptr, false); | |||||
| /* Sanity check: props is the actual container of this property. */ | |||||
| if (props != NULL && BLI_findindex(&props->data.group, prop) >= 0) { | |||||
| idprop = IDP_New(IDP_GROUP, &dummy, RNA_IDP_UI); | |||||
| if (!IDP_AddToGroup(props, idprop)) { | |||||
| IDP_FreeProperty(idprop); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| } | |||||
| if (idprop) { | |||||
| const char *name = ((IDProperty *)prop)->name; | |||||
| IDProperty *rv = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_GROUP); | |||||
| if (rv == NULL && create) { | |||||
| rv = IDP_New(IDP_GROUP, &dummy, name); | |||||
| if (!IDP_AddToGroup(idprop, rv)) { | |||||
| IDP_FreeProperty(rv); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| return rv; | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| static bool rna_idproperty_ui_set_default(PointerRNA *ptr, PropertyRNA *prop, const char type, IDPropertyTemplate *value) | |||||
| { | |||||
| BLI_assert(ELEM(type, IDP_INT, IDP_DOUBLE)); | |||||
| if (prop->magic == RNA_MAGIC) { | |||||
| return false; | |||||
| } | |||||
| /* attempt to get the local ID values */ | |||||
| IDProperty *idp_ui = rna_idproperty_ui_ensure(ptr, prop, value != NULL); | |||||
| if (idp_ui == NULL) { | |||||
| return (value == NULL); | |||||
| } | |||||
| IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", type); | |||||
| if (value == NULL) { | |||||
| if (item != NULL) { | |||||
| IDP_RemoveFromGroup(idp_ui, item); | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (item != NULL) { | |||||
| switch (type) { | |||||
| case IDP_INT: | |||||
| IDP_Int(item) = value->i; | |||||
| break; | |||||
| case IDP_DOUBLE: | |||||
| IDP_Double(item) = value->d; | |||||
| break; | |||||
| default: | |||||
| BLI_assert(false); | |||||
| return false; | |||||
| } | |||||
| } | |||||
| else { | |||||
| item = IDP_New(type, value, "default"); | |||||
| if (!IDP_AddToGroup(idp_ui, item)) { | |||||
| IDP_FreeProperty(item); | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create) | IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create) | ||||
| { | { | ||||
| StructRNA *type = ptr->type; | StructRNA *type = ptr->type; | ||||
| if (type && type->idproperties) { | if (type && type->idproperties) { | ||||
| return type->idproperties(ptr, create); | return type->idproperties(ptr, create); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,429 Lines • ▼ Show 20 Lines | else { | ||||
| RNA_property_int_set_array(ptr, prop, tmparray); | RNA_property_int_set_array(ptr, prop, tmparray); | ||||
| MEM_freeN(tmparray); | MEM_freeN(tmparray); | ||||
| } | } | ||||
| } | } | ||||
| int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | ||||
| { | { | ||||
| IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop); | IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop); | ||||
| if (prop->magic != RNA_MAGIC) { | |||||
| /* attempt to get the local ID values */ | |||||
| IDProperty *idp_ui = rna_idproperty_ui(prop); | |||||
| if (idp_ui) { | |||||
| IDProperty *item; | |||||
| item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_INT); | |||||
| return item ? IDP_Int(item) : iprop->defaultvalue; | |||||
| } | |||||
| } | |||||
| return iprop->defaultvalue; | return iprop->defaultvalue; | ||||
| } | } | ||||
| bool RNA_property_int_set_default(PointerRNA *ptr, PropertyRNA *prop, int value) | |||||
| { | |||||
| if (value != 0) { | |||||
| IDPropertyTemplate val = { .i = value }; | |||||
| return rna_idproperty_ui_set_default(ptr, prop, IDP_INT, &val); | |||||
| } | |||||
| else { | |||||
| return rna_idproperty_ui_set_default(ptr, prop, IDP_INT, NULL); | |||||
| } | |||||
| } | |||||
| void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values) | void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values) | ||||
| { | { | ||||
| IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop); | IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop); | ||||
| BLI_assert(RNA_property_type(prop) == PROP_INT); | BLI_assert(RNA_property_type(prop) == PROP_INT); | ||||
| BLI_assert(RNA_property_array_check(prop) != false); | BLI_assert(RNA_property_array_check(prop) != false); | ||||
| if (prop->arraydimension == 0) | if (prop->arraydimension == 0) | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | |||||
| float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop) | ||||
| { | { | ||||
| FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop); | FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop); | ||||
| BLI_assert(RNA_property_type(prop) == PROP_FLOAT); | BLI_assert(RNA_property_type(prop) == PROP_FLOAT); | ||||
| BLI_assert(RNA_property_array_check(prop) == false); | BLI_assert(RNA_property_array_check(prop) == false); | ||||
| if (prop->magic != RNA_MAGIC) { | |||||
| /* attempt to get the local ID values */ | |||||
| IDProperty *idp_ui = rna_idproperty_ui(prop); | |||||
| if (idp_ui) { | |||||
| IDProperty *item; | |||||
| item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_DOUBLE); | |||||
| return item ? IDP_Double(item) : fprop->defaultvalue; | |||||
| } | |||||
| } | |||||
| return fprop->defaultvalue; | return fprop->defaultvalue; | ||||
| } | } | ||||
| bool RNA_property_float_set_default(PointerRNA *ptr, PropertyRNA *prop, float value) | |||||
| { | |||||
| if (value != 0) { | |||||
| IDPropertyTemplate val = { .d = value }; | |||||
| return rna_idproperty_ui_set_default(ptr, prop, IDP_DOUBLE, &val); | |||||
| } | |||||
| else { | |||||
| return rna_idproperty_ui_set_default(ptr, prop, IDP_DOUBLE, NULL); | |||||
| } | |||||
| } | |||||
| void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values) | void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values) | ||||
| { | { | ||||
| FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop); | FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop); | ||||
| BLI_assert(RNA_property_type(prop) == PROP_FLOAT); | BLI_assert(RNA_property_type(prop) == PROP_FLOAT); | ||||
| BLI_assert(RNA_property_array_check(prop) != false); | BLI_assert(RNA_property_array_check(prop) != false); | ||||
| if (prop->arraydimension == 0) | if (prop->arraydimension == 0) | ||||
| ▲ Show 20 Lines • Show All 4,215 Lines • ▼ Show 20 Lines | switch (RNA_property_type(prop)) { | ||||
| } | } | ||||
| default: | default: | ||||
| /* FIXME: are there still any cases that haven't been handled? comment out "default" block to check :) */ | /* FIXME: are there still any cases that haven't been handled? comment out "default" block to check :) */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop) | |||||
| { | |||||
| if (!RNA_property_is_idprop(prop) || RNA_property_array_check(prop)) { | |||||
| return false; | |||||
| } | |||||
| /* get and set the default values as appropriate for the various types */ | |||||
| switch (RNA_property_type(prop)) { | |||||
| case PROP_INT: | |||||
| { | |||||
| int value = RNA_property_int_get(ptr, prop); | |||||
| return RNA_property_int_set_default(ptr, prop, value); | |||||
| } | |||||
| case PROP_FLOAT: | |||||
| { | |||||
| float value = RNA_property_float_get(ptr, prop); | |||||
| return RNA_property_float_set_default(ptr, prop, value); | |||||
| } | |||||
| default: | |||||
| return false; | |||||
| } | |||||
| } | |||||
| static bool rna_property_override_operation_apply( | static bool rna_property_override_operation_apply( | ||||
| Main *bmain, | Main *bmain, | ||||
| PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage, | PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage, | ||||
| PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage, | PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage, | ||||
| PointerRNA *ptr_item_local, PointerRNA *ptr_item_override, PointerRNA *ptr_item_storage, | PointerRNA *ptr_item_local, PointerRNA *ptr_item_override, PointerRNA *ptr_item_storage, | ||||
| IDOverrideStaticPropertyOperation *opop); | IDOverrideStaticPropertyOperation *opop); | ||||
| bool RNA_property_copy(Main *bmain, PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index) | bool RNA_property_copy(Main *bmain, PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index) | ||||
| ▲ Show 20 Lines • Show All 820 Lines • Show Last 20 Lines | |||||