[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39535] trunk/blender/source/blender/ editors/interface: store a pointer to the units system in the uiBlock since the button code was doing context lookups for the scene quite a lot .

Campbell Barton ideasman42 at gmail.com
Thu Aug 18 22:01:31 CEST 2011


Revision: 39535
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39535
Author:   campbellbarton
Date:     2011-08-18 20:01:30 +0000 (Thu, 18 Aug 2011)
Log Message:
-----------
store a pointer to the units system in the uiBlock since the button code was doing context lookups for the scene quite a lot.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2011-08-18 19:16:36 UTC (rev 39534)
+++ trunk/blender/source/blender/editors/interface/interface.c	2011-08-18 20:01:30 UTC (rev 39535)
@@ -1266,16 +1266,14 @@
 
 int ui_is_but_unit(uiBut *but)
 {
+	UnitSettings *unit= but->block->unit;
 	const int unit_type= uiButGetUnitType(but);
-	Scene *scene; /* avoid getting the scene on non unit buttons */
 
 	if(unit_type == PROP_UNIT_NONE)
 		return 0;
 
-	scene= CTX_data_scene((bContext *)but->block->evil_C);
-
 #if 1 // removed so angle buttons get correct snapping
-	if (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
+	if (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION)
 		return 0;
 #endif
 	
@@ -1283,7 +1281,7 @@
 	if (unit_type == PROP_UNIT_TIME)
 		return 0;
 
-	if (scene->unit.system == USER_UNIT_NONE) {
+	if (unit->system == USER_UNIT_NONE) {
 		if (unit_type != PROP_UNIT_ROTATION) {
 			return 0;
 		}
@@ -1482,19 +1480,20 @@
 
 static double ui_get_but_scale_unit(uiBut *but, double value)
 {
-	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+	UnitSettings *unit= but->block->unit;
 	int unit_type= uiButGetUnitType(but);
 
 	if(unit_type == PROP_UNIT_LENGTH) {
-		return value * (double)scene->unit.scale_length;
+		return value * (double)unit->scale_length;
 	}
 	else if(unit_type == PROP_UNIT_AREA) {
-		return value * pow(scene->unit.scale_length, 2);
+		return value * pow(unit->scale_length, 2);
 	}
 	else if(unit_type == PROP_UNIT_VOLUME) {
-		return value * pow(scene->unit.scale_length, 3);
+		return value * pow(unit->scale_length, 3);
 	}
 	else if(unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
+		Scene *scene= CTX_data_scene(but->block->evil_C);
 		return FRA2TIME(value);
 	}
 	else {
@@ -1506,14 +1505,14 @@
 void ui_convert_to_unit_alt_name(uiBut *but, char *str, int maxlen)
 {
 	if(ui_is_but_unit(but)) {
+		UnitSettings *unit= but->block->unit;
 		int unit_type= uiButGetUnitType(but);
 		char *orig_str;
-		Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
 		
 		orig_str= MEM_callocN(sizeof(char)*maxlen + 1, "textedit sub str");
 		memcpy(orig_str, str, maxlen);
 		
-		bUnit_ToUnitAltName(str, maxlen, orig_str, scene->unit.system, unit_type>>16);
+		bUnit_ToUnitAltName(str, maxlen, orig_str, unit->system, unit_type>>16);
 		
 		MEM_freeN(orig_str);
 	}
@@ -1521,27 +1520,26 @@
 
 static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double value, int pad)
 {
-	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
-	int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
+	UnitSettings *unit= but->block->unit;
+	int do_split= unit->flag & USER_UNIT_OPT_SPLIT;
 	int unit_type= uiButGetUnitType(but);
 	int precision= but->a2;
 
-	if(scene->unit.scale_length<0.0001f) scene->unit.scale_length= 1.0f; // XXX do_versions
+	if(unit->scale_length<0.0001f) unit->scale_length= 1.0f; // XXX do_versions
 
 	/* Sanity checks */
 	if(precision > PRECISION_FLOAT_MAX)	precision= PRECISION_FLOAT_MAX;
 	else if(precision==0)				precision= 2;
 
-	bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type>>16, do_split, pad);
+	bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, unit->system, unit_type>>16, do_split, pad);
 }
 
 static float ui_get_but_step_unit(uiBut *but, float step_default)
 {
-	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
 	int unit_type= uiButGetUnitType(but)>>16;
 	float step;
 
-	step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), scene->unit.system, unit_type);
+	step = bUnit_ClosestScalar(ui_get_but_scale_unit(but, step_default), but->block->unit->system, unit_type);
 
 	if(step > 0.0f) { /* -1 is an error value */
 		return (float)((double)step/ui_get_but_scale_unit(but, 1.0))*100.0f;
@@ -1629,12 +1627,11 @@
 {
 	char str_unit_convert[256];
 	const int unit_type= uiButGetUnitType(but);
-	Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
 
 	BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
 
 	/* ugly, use the draw string to get the value, this could cause problems if it includes some text which resolves to a unit */
-	bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), scene->unit.system, unit_type>>16);
+	bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr, ui_get_but_scale_unit(but, 1.0), but->block->unit->system, unit_type>>16);
 
 	return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
 }
@@ -1981,7 +1978,10 @@
 	block->active= 1;
 	block->dt= dt;
 	block->evil_C= (void*)C; // XXX
-	if (scn) block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT);
+	if (scn) {
+		block->color_profile= (scn->r.color_mgt_flag & R_COLOR_MANAGEMENT);
+		block->unit= &scn->unit;
+	}
 	BLI_strncpy(block->name, name, sizeof(block->name));
 
 	if(region)

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-08-18 19:16:36 UTC (rev 39534)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2011-08-18 20:01:30 UTC (rev 39535)
@@ -2310,13 +2310,13 @@
 		float fac= 1.0f;
 		
 		if(ui_is_but_unit(but)) {
-			Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
+			UnitSettings *unit= but->block->unit;
 			int unit_type= uiButGetUnitType(but)>>16;
 
-			if(bUnit_IsValid(scene->unit.system, unit_type)) {
-				fac= (float)bUnit_BaseScalar(scene->unit.system, unit_type);
+			if(bUnit_IsValid(unit->system, unit_type)) {
+				fac= (float)bUnit_BaseScalar(unit->system, unit_type);
 				if(ELEM3(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) {
-					fac /= scene->unit.scale_length;
+					fac /= unit->scale_length;
 				}
 			}
 		}

Modified: trunk/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_intern.h	2011-08-18 19:16:36 UTC (rev 39534)
+++ trunk/blender/source/blender/editors/interface/interface_intern.h	2011-08-18 20:01:30 UTC (rev 39535)
@@ -332,7 +332,9 @@
 	void *evil_C;				// XXX hack for dynamic operator enums
 
 	float _hsv[3];				// XXX, only access via ui_block_hsv_get()
-	char color_profile;				// color profile for correcting linear colors for display
+	char color_profile;			// color profile for correcting linear colors for display
+	struct UnitSettings *unit;	// unit system, used a lot for numeric buttons so include here rather then fetching through the scene every time.
+
 };
 
 typedef struct uiSafetyRct {




More information about the Bf-blender-cvs mailing list