Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-08-27 16:27:24 +0300
committerHans Goudey <h.goudey@me.com>2021-08-27 16:27:24 +0300
commit8b9a3b94fc148d197b137aa892855c60db2783e6 (patch)
tree0afd1a3538e76a029c0d6365f5bc06d681da92d9 /source/blender/blenloader
parent3f5e0f7d91e0e13870d98fe721a871e6be210489 (diff)
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is quite complicated. For every property, retrieving a single one of these values involves three string lookups. First for the "_RNA_UI" group property, then another for a group with the property's name, then for the data value name. Not only is this inefficient, it's hard to reason about, unintuitive, and not at all self-explanatory. This commit replaces that system with a UI data struct directly in the IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond storing the description, name, and RNA subtype, derived structs are used to store type specific UI data like min and max. Note that this means that addons using (abusing) the `_RNA_UI` custom property will have to be changed. A few places in the addons repository will be changed after this commit with D9919. **Before** Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group, then the subgroup for the original property, then specific UI data is accessed like any other IDProperty. ``` prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True) prop["min"] = 1.0 ``` **After** After, the `id_properties_ui` function for RNA structs returns a python object specifically for managing an IDProperty's UI data. ``` ui_data = idproperties_owner.id_properties_ui("prop_name") ui_data.update(min=1.0) ``` In addition to `update`, there are now other functions: - `as_dict`: Returns a dictionary of the property's UI data. - `clear`: Removes the property's UI data. - `update_from`: Copy UI data between properties, even if they have different owners. Differential Revision: https://developer.blender.org/D9697
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/versioning_300.c241
1 files changed, 241 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index aee6d798799..0253316dc3a 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -20,6 +20,10 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
#include "BLI_path_util.h"
@@ -46,10 +50,14 @@
#include "BKE_deform.h"
#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
+#include "BKE_idprop.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_node.h"
+#include "RNA_access.h"
+#include "RNA_enum_types.h"
+
#include "BLO_readfile.h"
#include "MEM_guardedalloc.h"
#include "readfile.h"
@@ -60,6 +68,238 @@
#include "versioning_common.h"
+static IDProperty *idproperty_find_ui_container(IDProperty *idprop_group)
+{
+ LISTBASE_FOREACH (IDProperty *, prop, &idprop_group->data.group) {
+ if (prop->type == IDP_GROUP && STREQ(prop->name, "_RNA_UI")) {
+ return prop;
+ }
+ }
+ return NULL;
+}
+
+static void version_idproperty_move_data_int(IDPropertyUIDataInt *ui_data,
+ const IDProperty *prop_ui_data)
+{
+ IDProperty *min = IDP_GetPropertyFromGroup(prop_ui_data, "min");
+ if (min != NULL) {
+ ui_data->min = ui_data->soft_min = IDP_coerce_to_int_or_zero(min);
+ }
+ IDProperty *max = IDP_GetPropertyFromGroup(prop_ui_data, "max");
+ if (max != NULL) {
+ ui_data->max = ui_data->soft_max = IDP_coerce_to_int_or_zero(max);
+ }
+ IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
+ if (soft_min != NULL) {
+ ui_data->soft_min = IDP_coerce_to_int_or_zero(soft_min);
+ ui_data->soft_min = MIN2(ui_data->soft_min, ui_data->min);
+ }
+ IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
+ if (soft_max != NULL) {
+ ui_data->soft_max = IDP_coerce_to_int_or_zero(soft_max);
+ ui_data->soft_max = MAX2(ui_data->soft_max, ui_data->max);
+ }
+ IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
+ if (step != NULL) {
+ ui_data->step = IDP_coerce_to_int_or_zero(soft_max);
+ }
+ IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
+ if (default_value != NULL) {
+ if (default_value->type == IDP_ARRAY) {
+ if (default_value->subtype == IDP_INT) {
+ ui_data->default_array = MEM_dupallocN(IDP_Array(default_value));
+ ui_data->default_array_len = default_value->len;
+ }
+ }
+ else if (default_value->type == IDP_INT) {
+ ui_data->default_value = IDP_coerce_to_int_or_zero(default_value);
+ }
+ }
+}
+
+static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data,
+ const IDProperty *prop_ui_data)
+{
+ IDProperty *min = IDP_GetPropertyFromGroup(prop_ui_data, "min");
+ if (min != NULL) {
+ ui_data->min = ui_data->soft_min = IDP_coerce_to_double_or_zero(min);
+ }
+ IDProperty *max = IDP_GetPropertyFromGroup(prop_ui_data, "max");
+ if (max != NULL) {
+ ui_data->max = ui_data->soft_max = IDP_coerce_to_double_or_zero(min);
+ }
+ IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
+ if (soft_min != NULL) {
+ ui_data->soft_min = IDP_coerce_to_double_or_zero(soft_min);
+ ui_data->soft_min = MAX2(ui_data->soft_min, ui_data->min);
+ }
+ IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
+ if (soft_max != NULL) {
+ ui_data->soft_max = IDP_coerce_to_double_or_zero(soft_max);
+ ui_data->soft_max = MIN2(ui_data->soft_max, ui_data->max);
+ }
+ IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
+ if (step != NULL) {
+ ui_data->step = IDP_coerce_to_float_or_zero(step);
+ }
+ IDProperty *precision = IDP_GetPropertyFromGroup(prop_ui_data, "precision");
+ if (precision != NULL) {
+ ui_data->precision = IDP_coerce_to_int_or_zero(precision);
+ }
+ IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
+ if (default_value != NULL) {
+ if (default_value->type == IDP_ARRAY) {
+ if (ELEM(default_value->subtype, IDP_FLOAT, IDP_DOUBLE)) {
+ ui_data->default_array = MEM_dupallocN(IDP_Array(default_value));
+ ui_data->default_array_len = default_value->len;
+ }
+ }
+ else if (ELEM(default_value->type, IDP_DOUBLE, IDP_FLOAT)) {
+ ui_data->default_value = IDP_coerce_to_double_or_zero(default_value);
+ }
+ }
+}
+
+static void version_idproperty_move_data_string(IDPropertyUIDataString *ui_data,
+ const IDProperty *prop_ui_data)
+{
+ IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default");
+ if (default_value != NULL && default_value->type == IDP_STRING) {
+ ui_data->default_value = BLI_strdup(IDP_String(default_value));
+ }
+}
+
+static void version_idproperty_ui_data(IDProperty *idprop_group)
+{
+ if (idprop_group == NULL) { /* NULL check here to reduce verbosity of calls to this function. */
+ return;
+ }
+
+ IDProperty *ui_container = idproperty_find_ui_container(idprop_group);
+ if (ui_container == NULL) {
+ return;
+ }
+
+ LISTBASE_FOREACH (IDProperty *, prop, &idprop_group->data.group) {
+ IDProperty *prop_ui_data = IDP_GetPropertyFromGroup(ui_container, prop->name);
+ if (prop_ui_data == NULL) {
+ continue;
+ }
+
+ if (!IDP_ui_data_supported(prop)) {
+ continue;
+ }
+
+ IDPropertyUIData *ui_data = IDP_ui_data_ensure(prop);
+
+ IDProperty *subtype = IDP_GetPropertyFromGroup(prop_ui_data, "subtype");
+ if (subtype != NULL && subtype->type == IDP_STRING) {
+ const char *subtype_string = IDP_String(subtype);
+ int result = PROP_NONE;
+ RNA_enum_value_from_id(rna_enum_property_subtype_items, subtype_string, &result);
+ ui_data->rna_subtype = result;
+ }
+
+ IDProperty *description = IDP_GetPropertyFromGroup(prop_ui_data, "description");
+ if (description != NULL && description->type == IDP_STRING) {
+ ui_data->description = BLI_strdup(IDP_String(description));
+ }
+
+ /* Type specific data. */
+ switch (IDP_ui_data_type(prop)) {
+ case IDP_UI_DATA_TYPE_STRING:
+ version_idproperty_move_data_string((IDPropertyUIDataString *)ui_data, prop_ui_data);
+ break;
+ case IDP_UI_DATA_TYPE_ID:
+ break;
+ case IDP_UI_DATA_TYPE_INT:
+ version_idproperty_move_data_int((IDPropertyUIDataInt *)ui_data, prop_ui_data);
+ break;
+ case IDP_UI_DATA_TYPE_FLOAT:
+ version_idproperty_move_data_float((IDPropertyUIDataFloat *)ui_data, prop_ui_data);
+ break;
+ case IDP_UI_DATA_TYPE_UNSUPPORTED:
+ BLI_assert_unreachable();
+ break;
+ }
+
+ IDP_FreeFromGroup(ui_container, prop_ui_data);
+ }
+
+ IDP_FreeFromGroup(idprop_group, ui_container);
+}
+
+static void do_versions_idproperty_bones_recursive(Bone *bone)
+{
+ version_idproperty_ui_data(bone->prop);
+ LISTBASE_FOREACH (Bone *, child_bone, &bone->childbase) {
+ do_versions_idproperty_bones_recursive(child_bone);
+ }
+}
+
+/**
+ * For every data block that supports them, initialize the new IDProperty UI data struct based on
+ * the old more complicated storage. Assumes only the top level of IDProperties below the parent
+ * group had UI data in a "_RNA_UI" group.
+ *
+ * \note The following IDProperty groups in DNA aren't exposed in the UI or are runtime-only, so
+ * they don't have UI data: wmOperator, bAddon, bUserMenuItem_Op, wmKeyMapItem, wmKeyConfigPref,
+ * uiList, FFMpegCodecData, View3DShading, bToolRef, TimeMarker, ViewLayer, bPoseChannel.
+ */
+static void do_versions_idproperty_ui_data(Main *bmain)
+{
+ /* ID data. */
+ ID *id;
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ IDProperty *idprop_group = IDP_GetProperties(id, false);
+ if (idprop_group == NULL) {
+ continue;
+ }
+ version_idproperty_ui_data(idprop_group);
+ }
+ FOREACH_MAIN_ID_END;
+
+ /* Bones. */
+ LISTBASE_FOREACH (bArmature *, armature, &bmain->armatures) {
+ LISTBASE_FOREACH (Bone *, bone, &armature->bonebase) {
+ do_versions_idproperty_bones_recursive(bone);
+ }
+ }
+
+ /* Nodes and node sockets. */
+ LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+ version_idproperty_ui_data(node->prop);
+ }
+ LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->inputs) {
+ version_idproperty_ui_data(socket->prop);
+ }
+ LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->outputs) {
+ version_idproperty_ui_data(socket->prop);
+ }
+ }
+
+ /* The UI data from exposed node modifier properties is just copied from the corresponding node
+ * group, but the copying only runs when necessary, so we still need to version UI data here. */
+ LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
+ LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
+ if (md->type == eModifierType_Nodes) {
+ NodesModifierData *nmd = (NodesModifierData *)md;
+ version_idproperty_ui_data(nmd->settings.properties);
+ }
+ }
+ }
+
+ /* Sequences. */
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+ if (scene->ed != NULL) {
+ LISTBASE_FOREACH (Sequence *, seq, &scene->ed->seqbase) {
+ version_idproperty_ui_data(seq->prop);
+ }
+ }
+ }
+}
+
static void sort_linked_ids(Main *bmain)
{
ListBase *lb;
@@ -252,6 +492,7 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
*/
{
/* Keep this block, even when empty. */
+ do_versions_idproperty_ui_data(bmain);
}
}