fix for own mistake in recent commit: [#27000] Spotlight spot shape size, lamp object data - numerical entries are interpreted as radians though displayed in degrees in SVN 36199

now apply units after python evaluation for unit buttons.
This commit is contained in:
Campbell Barton 2011-04-18 03:27:15 +00:00
parent 66bf6487df
commit ea5baccbf8

@ -1541,6 +1541,52 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen)
}
}
#ifdef WITH_PYTHON
static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char *str, double *value)
{
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);
return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1);
}
static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value)
{
int ok= FALSE;
if(str[0] != '\0') {
int is_unit_but= ui_is_but_unit(but);
/* only enable verbose if we won't run again with units */
if(BPY_button_exec(C, str, value, is_unit_but==FALSE) != -1) {
/* if the value parsed ok without unit conversion this button may still need a unit multiplier */
if(is_unit_but) {
char str_new[128];
BLI_snprintf(str_new, sizeof(str_new), "%f", *value);
ok= ui_set_but_string_eval_num_unit(C, but, str_new, value);
}
else {
ok= TRUE; /* parse normal string via py (no unit conversion needed) */
}
}
else if(is_unit_but) {
/* parse failed, this is a unit but so run replacements and parse again */
ok= ui_set_but_string_eval_num_unit(C, but, str, value);
}
}
return ok;
}
#endif // WITH_PYTHON
int ui_set_but_string(bContext *C, uiBut *but, const char *str)
{
if(but->rnaprop && ELEM3(but->type, TEX, IDPOIN, SEARCH_MENU)) {
@ -1601,32 +1647,7 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str)
double value;
#ifdef WITH_PYTHON
int ok= FALSE;
if(str[0] != '\0') {
int is_unit_but= ui_is_but_unit(but);
/* only enable verbose if we won't run again with units */
if(BPY_button_exec(C, str, &value, is_unit_but==FALSE) != -1) {
ok= TRUE; /* parse normal string via py (no unit conversion needed) */
}
else if(is_unit_but) {
/* parse failed, this is a unit but so run replacements and parse again */
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);
if(BPY_button_exec(C, str_unit_convert, &value, TRUE) != -1) {
ok= TRUE;
}
}
}
if(ok == FALSE) {
if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) {
return 0;
}
#else