[Bf-blender-cvs] [543a34a0212] blender2.8: RNA: convenience method for orientation name & icon

Campbell Barton noreply at git.blender.org
Wed Dec 19 11:42:20 CET 2018


Commit: 543a34a0212411271054ced45fae416b1982156a
Author: Campbell Barton
Date:   Wed Dec 19 21:40:06 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB543a34a0212411271054ced45fae416b1982156a

RNA: convenience method for orientation name & icon

Avoids RNA introspection at draw time
which is relatively slow (approx 5x).

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/makesrna/intern/rna_scene.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 8f3132f690f..fa58fed6102 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -123,14 +123,7 @@ class VIEW3D_HT_header(Header):
         if object_mode in {'OBJECT', 'EDIT', 'POSE', 'EDIT_GPENCIL'}:
             orient_slot = scene.transform_orientation_slots[0]
             custom_orientation = orient_slot.custom_orientation
-
-            if custom_orientation is None:
-                trans_orientation = bpy.types.TransformOrientationSlot.bl_rna.properties["type"].enum_items[orient_slot.type]
-                trans_icon = getattr(trans_orientation, "icon", 'BLANK1')
-                trans_name = getattr(trans_orientation, "name", "Orientation")
-            else:
-                trans_icon = 'OBJECT_ORIGIN'
-                trans_name = getattr(custom_orientation, "name", "Orientation")
+            trans_name, trans_icon = orient_slot.ui_info()
 
             row = layout.row(align=True)
 
@@ -139,7 +132,7 @@ class VIEW3D_HT_header(Header):
             sub.popover(
                 panel="VIEW3D_PT_transform_orientations",
                 text=trans_name,
-                icon=trans_icon,
+                icon_value=trans_icon,
             )
 
         # Snap
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 58bde163442..3a8cfbff3a1 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -1567,7 +1567,7 @@ static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNU
 		RE_FreePersistentData();
 }
 
-/* Scene.orientation_slots */
+/* Scene.transform_orientation_slots */
 static void rna_Scene_transform_orientation_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
 	Scene *scene = (Scene *)ptr->id.data;
@@ -2036,6 +2036,26 @@ const EnumPropertyItem *rna_TransformOrientation_itemf(
 	return item;
 }
 
+void rna_TransformOrientationSlot_ui_info(
+        ID *scene_id, TransformOrientationSlot *orient_slot,
+        char *r_name, int *r_icon_value)
+{
+	Scene *scene = (Scene *)scene_id;
+
+	if (orient_slot->type < V3D_MANIP_CUSTOM) {
+		const EnumPropertyItem *items = rna_enum_transform_orientation_items;
+		const int i = RNA_enum_from_value(items, orient_slot->type);
+		strcpy(r_name, items[i].name);
+		*r_icon_value = items[i].icon;
+	}
+	else {
+		TransformOrientation *orientation = BKE_scene_transform_orientation_find(
+		        scene, orient_slot->index_custom);
+		strcpy(r_name, orientation->name);
+		*r_icon_value = ICON_OBJECT_ORIGIN;
+	}
+}
+
 static const EnumPropertyItem *get_unit_enum_items(int system, int type, bool *r_free)
 {
 	const void *usys;
@@ -2221,6 +2241,20 @@ static void rna_def_transform_orientation_slot(BlenderRNA *brna)
 	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SELECT);
 	RNA_def_property_ui_text(prop, "Use", "Disable to unlink the orientation from the scene-setting");
 	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	/* UI access only (avoid slow RNA introspection). */
+	func = RNA_def_function(srna, "ui_info", "rna_TransformOrientationSlot_ui_info");
+	RNA_def_function_ui_description(func, "");
+	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+	parm = RNA_def_string(func, "name", NULL, sizeof(((TransformOrientation *)NULL)->name), "name", "");
+	RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
+	RNA_def_function_output(func, parm);
+	parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_NONE);
+	RNA_def_property_ui_text(parm, "", "");
+	RNA_def_function_output(func, parm);
 }



More information about the Bf-blender-cvs mailing list